Changeset 15 for trunk/module-newcamd.c
- Timestamp:
- 04/05/09 01:32:24 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-newcamd.c
r8 r15 365 365 // index+strlen(passwdcrypt)+1); 366 366 network_message_send(handle, 0, buf, index+strlen(passwdcrypt)+1, key, 367 COMMTYPE_CLIENT, 0 );367 COMMTYPE_CLIENT, 0x8888); 368 368 369 369 // 3.1 Get login answer … … 403 403 // 404 404 reader[ridx].caid[0] = (ushort)((buf[4+2]<<8) | buf[5+2]); 405 cs_log("server %s:%d caid: %04X", 406 reader[ridx].device, reader[ridx].r_port, reader[ridx].caid[0]); 405 memcpy(&reader[ridx].hexserial, buf+6+2, 8); 406 cs_log("Newcamd Server: %s:%d - UserID: %i", reader[ridx].device, reader[ridx].r_port, buf[3+2]); 407 cs_log("CAID: %04X - UA: %02X%02X%02X%02X%02X%02X%02X%02X - Provider # %i", reader[ridx].caid[0], reader[ridx].hexserial[0], reader[ridx].hexserial[1], reader[ridx].hexserial[2], reader[ridx].hexserial[3], reader[ridx].hexserial[4], reader[ridx].hexserial[5], reader[ridx].hexserial[6], reader[ridx].hexserial[7], buf[14+2]); 407 408 reader[ridx].nprov = buf[14+2]; 408 409 for( i=0; i<reader[ridx].nprov; i++ ) 410 { 411 reader[ridx].prid[i][0] = buf[15+2+11*i]; 412 reader[ridx].prid[i][1] = buf[16+2+11*i]; 413 reader[ridx].prid[i][2] = buf[17+2+11*i]; 414 cs_log("provider #%d: %02X%02X%02X", 415 i, 416 reader[ridx].prid[i][0], 417 reader[ridx].prid[i][1], 418 reader[ridx].prid[i][2]); 409 memset(reader[ridx].prid, 0xff, sizeof(reader[ridx].prid)); 410 for (i=0; i < reader[ridx].nprov; i++) { 411 reader[ridx].availkeys[i][0] = 1; 412 reader[ridx].prid[i][0] = 0; 413 reader[ridx].prid[i][1] = buf[15+2+11*i]; 414 reader[ridx].prid[i][2] = buf[16+2+11*i]; 415 reader[ridx].prid[i][3] = buf[17+2+11*i]; 416 memcpy(&reader[ridx].sa[i], buf+22+2+11*i, 4); // the 4 first bytes are not read 417 cs_log("Provider ID: %02X%02X%02X - SA: %02X%02X%02X%02X", reader[ridx].prid[i][1], reader[ridx].prid[i][2], reader[ridx].prid[i][3], reader[ridx].sa[i][0], reader[ridx].sa[i][1], reader[ridx].sa[i][2], reader[ridx].sa[i][3]); 419 418 } 420 419 memcpy(reader[ridx].ncd_skey, key, 16); … … 471 470 if( rc==-1 ) 472 471 if (rs > 0) 473 472 cs_log("packet to small (%d bytes)", rs); 474 473 else 475 474 cs_log("Connection closed to %s", remote_txt()); … … 494 493 495 494 filt.caid = reader[au].caid[0]; 495 if (filt.caid == 0) filt.caid = client[cs_idx].ftab.filts[0].caid; 496 496 filt.nprids = 0; 497 497 memset(&filt.prids, 0, sizeof(filt.prids)); … … 504 504 { 505 505 for( j=found=0; (!found)&&(j<filt.nprids); j++ ) 506 if( pufilt->prids[i]==filt.prids[j] ) 507 found=1; 506 if (pufilt->prids[i] == filt.prids[j]) found=1; 508 507 if( !found ) 509 508 filt.prids[filt.nprids++] = pufilt->prids[i]; … … 575 574 if( !client[cs_idx].ftab.nfilts ) 576 575 { 577 filt.nprids = psfilt->nprids; 578 for( i=0; i<filt.nprids; i++ ) 579 filt.prids[i] = psfilt->prids[i]; // use server PROVID(s) 576 int r,f, add; 577 for (i=0; i<psfilt->nprids; i++) { 578 // use server PROVID(s) (and only those which are in user's groups) 579 add = 0; 580 for (r=0; !add && r<CS_MAXREADER; r++) { 581 if (reader[r].grp & client[cs_idx].grp) { 582 if (!reader[r].ftab.nfilts) { 583 if (reader[r].typ & R_IS_NETWORK) add = 1; 584 for (j=0; !add && j<reader[r].nprov; j++) 585 if (b2i(3, &reader[r].prid[j][1]) == psfilt->prids[i]) add = 1; 586 } else { 587 for (j=0; !add && j<reader[r].ftab.nfilts; j++) { 588 ulong rcaid = reader[r].ftab.filts[j].caid; 589 if (!rcaid || rcaid == filt.caid) { 590 for (k=0; !add && k<reader[r].ftab.filts[j].nprids; k++) 591 if (reader[r].ftab.filts[j].prids[k] == psfilt->prids[i]) add = 1; 592 } 593 } 594 } 595 } 596 } 597 if (add) filt.prids[filt.nprids++] = psfilt->prids[i]; 598 } 580 599 return filt; 581 600 } 582 601 583 602 // search in client IDENT 584 for( i=0; i<psfilt->nprids; i++ )585 {586 cs_debug("search server provid #%d: %06X", i, psfilt->prids[i]);587 603 for( j=0; j<client[cs_idx].ftab.nfilts; j++ ) 588 604 { … … 591 607 if( !ucaid || ucaid==filt.caid ) 592 608 { 609 for (i=0; i<psfilt->nprids; i++) 610 { 611 cs_debug("search server provid #%d: %06X", i, psfilt->prids[i]); 593 612 if( client[cs_idx].ftab.filts[j].nprids ) 594 613 { 595 614 for( k=0; k<client[cs_idx].ftab.filts[j].nprids; k++ ) 596 if ( psfilt->prids[i]==client[cs_idx].ftab.filts[j].prids[k])615 if (client[cs_idx].ftab.filts[j].prids[k] == psfilt->prids[i]) 597 616 filt.prids[filt.nprids++]=client[cs_idx].ftab.filts[j].prids[k]; 617 } else { 618 filt.prids[filt.nprids++] = psfilt->prids[i]; 619 // allow server PROVID(s) if no PROVID(s) specified in IDENT 598 620 } 599 else {600 filt.nprids = psfilt->nprids;601 for( k=0; k<filt.nprids; k++ )602 filt.prids[k] = psfilt->prids[k]; // use server PROVID(s)603 }604 goto end;605 621 } 606 622 } … … 612 628 //cs_disconnect_client(); 613 629 } 614 end: 630 615 631 return filt; 616 632 } … … 658 674 { 659 675 cs_debug("account->usr=%s", account->usr); 660 if( (ok=(!strcmp(usr, account->usr))) ) 661 { 676 if (strcmp(usr, account->usr) == 0) { 662 677 passwdcrypt = (uint8*)__md5_crypt(account->pwd, "$1$abcdefgh$"); 663 678 cs_debug("account->pwd=%s", passwdcrypt); 664 if( !strcmp(pwd, passwdcrypt) ) 665 { 679 if (strcmp(pwd, passwdcrypt) == 0) { 666 680 client[cs_idx].crypted=1; 667 if (cs_auth_client(account, NULL)) 668 { 669 if(req) { free(req); req=0;} 670 cs_exit(0); 671 } 681 cs_auth_client(account, NULL); 682 cs_log("user %s authenticated successfully (using client %02X%02X)", usr, mbuf[0], mbuf[1]); 683 ok = 1; 672 684 break; 685 } else { 686 cs_log("user %s is providing a wrong password (using client %02X%02X)", usr, mbuf[0], mbuf[1]); 673 687 } 674 else 688 } 689 } 690 if (!ok && !account) { 691 cs_log("user %s is trying to connect but doesnt exist ! (using client %02X%02X)", usr, mbuf[0], mbuf[1]); 692 usr = 0; 693 } 694 695 if (ok) 696 { 697 au = client[cs_idx].au; 698 if (au != -1) { 699 if (cfg->ncd_ptab.ports[client[cs_idx].port_idx].ftab.filts[0].caid != reader[au].caid[0] 700 && cfg->ncd_ptab.ports[client[cs_idx].port_idx].ftab.filts[0].caid != reader[au].ftab.filts[0].caid) { 701 // AU wont be used on this port -> disable AU 702 au = -1; 703 } 704 else if (reader[au].card_system <= 0 && !(reader[au].typ & R_IS_CASCADING)) 705 { 706 // Init for AU enabled card not finished, reject Client 675 707 ok=0; 676 } 677 } 678 679 if (ok) 680 { 681 au = client[cs_idx].au; 682 683 if( au!=-1) 684 { 685 if (reader[au].card_system <= 0) 686 { 687 // Init for AU enabled card not finished, reject Client 688 ok = 0; 689 au = -2; // Flag zur Logausgabe 690 } 691 } 692 } 693 708 au = -2; // Flag zur Logausgabe 709 } 710 } 711 } 712 694 713 network_cmd_no_data_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, 695 714 (ok)?MSG_CLIENT_2_SERVER_LOGIN_ACK:MSG_CLIENT_2_SERVER_LOGIN_NAK, … … 715 734 } 716 735 717 client[cs_idx].ftab.filts[0] = mk_user_ftab(); 718 736 client[cs_idx].ftab.filts[0] = mk_user_ftab(); 719 737 pufilt = &client[cs_idx].ftab.filts[0]; 720 738 739 if (au != -1) { 740 unsigned char equal = 1; 741 721 742 // remember user filter 722 743 memcpy(&pufilt_noau, pufilt, sizeof(FILTER)); 723 744 724 if( au!=-1) 725 { 726 unsigned char equal = 1; 727 728 client[cs_idx].ftab.filts[0] = mk_user_au_ftab(au); 729 pufilt = &client[cs_idx].ftab.filts[0]; 730 745 client[cs_idx].ftab.filts[0] = mk_user_au_ftab(au); 746 pufilt = &client[cs_idx].ftab.filts[0]; 747 731 748 // check if user filter CAID and PROVID is the same as CAID and PROVID of the AU reader 732 749 733 if ((pufilt->caid != pufilt_noau.caid)) 734 { 735 cs_log("CAID server: %04X, CAID card: %04X, not equal, AU disabled",pufilt_noau.caid,pufilt->caid); 736 equal = 0; 750 if ((pufilt->caid != pufilt_noau.caid)) { 751 // cs_log("CAID server: %04X, CAID card: %04X, not equal, AU disabled",pufilt_noau.caid,pufilt->caid); 752 // equal = 0; 737 753 } 738 754 … … 741 757 if (pufilt->prids[j] != pufilt_noau.prids[j]) 742 758 { 743 cs_log("PROVID%d server: %04X, PROVID%d card: %04X, not equal, AU disabled",j,pufilt_noau.prids[j],j,pufilt->prids[j]);744 759 // cs_log("PROVID%d server: %04X, PROVID%d card: %04X, not equal, AU disabled",j,pufilt_noau.prids[j],j,pufilt->prids[j]); 760 //weird// equal = 0; 745 761 } 746 762 } … … 763 779 // if a non-AU-client sends an EMM-request it will be thrown away 764 780 // (see function "newcamd_process_emm") 765 / *781 //mbuf[3] = 1; 766 782 if( au!=-1 ) 767 783 mbuf[3] = 1; 768 784 else 769 785 mbuf[3] = cs_idx+10; // Unique user number 770 */771 mbuf[3] = 1;772 786 773 787 mbuf[4] = (uchar)(pufilt->caid>>8); 774 788 mbuf[5] = (uchar)(pufilt->caid); 775 mbuf[6] = 0x00; 776 mbuf[7] = 0x00; 777 if( au!=-1 ) 778 { 789 if (au != -1) { 779 790 if (((pufilt->caid >= 0x1700) && (pufilt->caid <= 0x1799)) || // Betacrypt 780 791 ((pufilt->caid >= 0x0600) && (pufilt->caid <= 0x0699))) // Irdeto 781 792 { 782 // only 4 Bytes Hexserial for newcamd clients (Hex Base + Hex Serial) 783 // first 2 Byte always 00 784 mbuf[8]=0x00; //serial only 4 bytes 785 mbuf[9]=0x00; //serial only 4 bytes 786 // 1 Byte Hex Base (see reader-irdeto.c how this is stored in "reader[au].hexserial") 787 mbuf[10]=reader[au].hexserial[3]; 788 // 3 Bytes Hex Serial (see reader-irdeto.c how this is stored in "reader[au].hexserial") 789 mbuf[11]=reader[au].hexserial[0]; 790 mbuf[12]=reader[au].hexserial[1]; 791 mbuf[13]=reader[au].hexserial[2]; 792 } 793 else 794 { 795 mbuf[8] = reader[au].hexserial[0];//So this is right! 796 mbuf[9] = reader[au].hexserial[1]; 797 mbuf[10] = reader[au].hexserial[2]; 798 mbuf[11] = reader[au].hexserial[3]; 799 mbuf[12] = reader[au].hexserial[4]; 800 mbuf[13] = reader[au].hexserial[5]; 801 } 802 803 } 804 else 805 { 793 // only 4 Bytes Hexserial for newcamd clients (Hex Base + Hex Serial) 794 // first 2 Byte always 00 795 mbuf[6]=0x00; //serial only 4 bytes 796 mbuf[7]=0x00; //serial only 4 bytes 797 mbuf[8]=0x00; //serial only 4 bytes 798 mbuf[9]=0x00; //serial only 4 bytes 799 // 1 Byte Hex Base (see reader-irdeto.c how this is stored in "reader[au].hexserial") 800 mbuf[10]=reader[au].hexserial[3]; 801 // 3 Bytes Hex Serial (see reader-irdeto.c how this is stored in "reader[au].hexserial") 802 mbuf[11]=reader[au].hexserial[0]; 803 mbuf[12]=reader[au].hexserial[1]; 804 mbuf[13]=reader[au].hexserial[2]; 805 } else if (((pufilt->caid >> 8) == 0x05) || ((pufilt->caid >> 8) == 0x0D)) { 806 mbuf[6] = 0x00; 807 mbuf[7] = 0x00; 808 mbuf[8] = 0x00; 809 mbuf[9] = reader[au].hexserial[0]; 810 mbuf[10] = reader[au].hexserial[1]; 811 mbuf[11] = reader[au].hexserial[2]; 812 mbuf[12] = reader[au].hexserial[3]; 813 mbuf[13] = reader[au].hexserial[4]; 814 } else { 815 mbuf[6] = reader[au].hexserial[0]; 816 mbuf[7] = reader[au].hexserial[1]; 817 mbuf[8] = reader[au].hexserial[2]; 818 mbuf[9] = reader[au].hexserial[3]; 819 mbuf[10] = reader[au].hexserial[4]; 820 mbuf[11] = reader[au].hexserial[5]; 821 mbuf[12] = reader[au].hexserial[6]; 822 mbuf[13] = reader[au].hexserial[7]; 823 } 824 } else { 806 825 client[cs_idx].au = -1; 826 mbuf[6] = 0x00; 827 mbuf[7] = 0x00; 828 mbuf[8] = 0x00; 829 mbuf[9] = 0x00; 830 mbuf[10] = 0x00; 831 mbuf[11] = 0x00; 832 mbuf[12] = 0x00; 833 mbuf[13] = 0x00; 807 834 // send "faked" Hexserial to client 835 /* 808 836 if (((pufilt->caid >= 0x1700) && (pufilt->caid <= 0x1799)) || // Betacrypt 809 837 ((pufilt->caid >= 0x0600) && (pufilt->caid <= 0x0699))) // Irdeto 810 { 811 mbuf[8] = 0x00; 812 mbuf[9] = 0x00; 813 mbuf[10] = fast_rnd(); 814 mbuf[11] = fast_rnd(); 815 mbuf[12] = fast_rnd(); 816 mbuf[13] = fast_rnd(); 817 } 818 else 819 { 820 mbuf[8] = fast_rnd(); 821 mbuf[9] = fast_rnd(); 822 mbuf[10] = fast_rnd(); 823 mbuf[11] = fast_rnd(); 824 mbuf[12] = fast_rnd(); 825 mbuf[13] = fast_rnd(); 826 } 838 { 839 mbuf[6] = 0x00; 840 mbuf[7] = 0x00; 841 mbuf[8] = 0x00; 842 mbuf[9] = 0x00; 843 mbuf[10] = fast_rnd(); 844 mbuf[11] = fast_rnd(); 845 mbuf[12] = fast_rnd(); 846 mbuf[13] = fast_rnd(); 847 } else { 848 mbuf[6] = fast_rnd(); 849 mbuf[7] = fast_rnd(); 850 mbuf[8] = fast_rnd(); 851 mbuf[9] = fast_rnd(); 852 mbuf[10] = fast_rnd(); 853 mbuf[11] = fast_rnd(); 854 mbuf[12] = fast_rnd(); 855 mbuf[13] = fast_rnd(); 856 } 857 */ 827 858 } 828 859 mbuf[14] = pufilt->nprids; … … 831 862 if ((pufilt->caid >= 0x0600) && (pufilt->caid <= 0x0699)) // Irdeto 832 863 { 833 mbuf[15+11*j] = 0; 834 mbuf[16+11*j] = 0; 835 mbuf[17+11*j] = j; 836 } 837 else 838 { 839 mbuf[15+11*j] = (uchar)(pufilt->prids[j]>>16); 840 mbuf[16+11*j] = (uchar)(pufilt->prids[j]>>8); 841 mbuf[17+11*j] = (uchar)(pufilt->prids[j]); 842 } 864 mbuf[15+11*j] = 0; 865 mbuf[16+11*j] = 0; 866 mbuf[17+11*j] = j; 867 } else { 868 mbuf[15+11*j] = (uchar)(pufilt->prids[j]>>16); 869 mbuf[16+11*j] = (uchar)(pufilt->prids[j]>>8); 870 mbuf[17+11*j] = (uchar)(pufilt->prids[j]); 871 } 843 872 mbuf[18+11*j] = 0x00; 844 873 mbuf[19+11*j] = 0x00; … … 857 886 if( rprid==pufilt->prids[j] ) 858 887 { 859 if ((pufilt->caid >= 0x0600) && (pufilt->caid <= 0x0699)) // Irdeto 860 { 861 mbuf[22+11*j] = reader[au].prid[k][0]; 862 mbuf[23+11*j] = reader[au].prid[k][1]; 863 mbuf[24+11*j] = reader[au].prid[k][2]; 864 mbuf[25+11*j] = reader[au].prid[k][3]; 865 } 866 else 867 { 868 mbuf[22+11*j] = reader[au].sa[k][0]; 869 mbuf[23+11*j] = reader[au].sa[k][1]; 870 mbuf[24+11*j] = reader[au].sa[k][2]; 871 mbuf[25+11*j] = reader[au].sa[k][3]; 872 } 888 if ((pufilt->caid >= 0x0600) && (pufilt->caid <= 0x0699)) // Irdeto 889 { 890 mbuf[22+11*j] = reader[au].prid[k][0]; 891 mbuf[23+11*j] = reader[au].prid[k][1]; 892 mbuf[24+11*j] = reader[au].prid[k][2]; 893 mbuf[25+11*j] = reader[au].prid[k][3]; 894 } else { 895 mbuf[22+11*j] = reader[au].sa[k][0]; 896 mbuf[23+11*j] = reader[au].sa[k][1]; 897 mbuf[24+11*j] = reader[au].sa[k][2]; 898 mbuf[25+11*j] = reader[au].sa[k][3]; 899 } 873 900 found=1; 874 901 break; … … 883 910 mbuf[25+11*j] = 0x00; 884 911 } 885 } 886 else 887 { 888 if ((pufilt->caid >= 0x0600) && (pufilt->caid <= 0x0699)) // Irdeto 889 { 912 } else { 913 if ((pufilt->caid >= 0x0600) && (pufilt->caid <= 0x0699)) // Irdeto 914 { 890 915 mbuf[22+11*j] = 0x00; 891 916 mbuf[23+11*j] = (uchar)(pufilt->prids[j]>>16); 892 917 mbuf[24+11*j] = (uchar)(pufilt->prids[j]>>8); 893 918 mbuf[25+11*j] = (uchar)(pufilt->prids[j]); 894 } 895 else 896 { 897 mbuf[22+11*j] = 0x00; 898 mbuf[23+11*j] = 0x00; 899 mbuf[24+11*j] = 0x00; 900 mbuf[25+11*j] = 0x00; 901 } 919 } else { 920 mbuf[22+11*j] = 0x00; 921 mbuf[23+11*j] = 0x00; 922 mbuf[24+11*j] = 0x00; 923 mbuf[25+11*j] = 0x00; 924 } 902 925 } 903 926 len+=11; … … 913 936 else 914 937 { 915 if (au < -1)916 917 918 cs_auth_client(0, usr ? "login failure" : "nouser");938 if (au == -2) 939 cs_auth_client(0, "Init for AU enabled card not finished"); 940 else 941 cs_auth_client(0, usr ? "login failure" : "no such user"); 919 942 if(req) { free(req); req=0;} 920 943 cs_exit(0); … … 979 1002 memset(&epg, 0, sizeof(epg)); 980 1003 au=client[cs_idx].au; 981 1004 982 1005 // if client is not allowed to do AU just send back the OK-answer to 983 1006 // the client and do nothing else with the received data 984 1007 if ((au>=0) && (au<=CS_MAXREADER)) 985 1008 { 986 epg.l=buf[2]+3; 987 caid = client[cs_idx].ftab.filts[0].caid; 988 epg.caid[0] = (uchar)(caid>>8); 989 epg.caid[1] = (uchar)(caid); 990 if( caid == 0x0500 ) 991 { 992 ushort emm_head; 993 994 emm_head = (buf[0]<<8) | buf[1]; 995 switch( emm_head ) 996 { 997 case 0x8e70: // EMM-S 998 memcpy(epg.hexserial+1, buf+3, 4); 999 epg.hexserial[4]=reader[au].hexserial[4]; 1000 break; 1001 case 0x8870: // EMM-U 1002 case 0x8c70: // confidential ? 1003 default: 1004 cs_log("unsupported emm type: %04X", emm_head); 1005 ok=0; 1006 } 1007 if( !ok ) cs_log("only EMM-S supported"); 1008 } 1009 else 1010 memcpy(epg.hexserial, reader[au].hexserial, 8); // dummy 1011 1012 memcpy(epg.emm, buf, epg.l); 1013 if( ok ) 1014 do_emm(&epg); 1015 } 1009 epg.l=buf[2]+3; 1010 caid = client[cs_idx].ftab.filts[0].caid; 1011 epg.caid[0] = (uchar)(caid>>8); 1012 epg.caid[1] = (uchar)(caid); 1013 /* if (caid == 0x0500) 1014 { 1015 ushort emm_head; 1016 1017 emm_head = (buf[0]<<8) | buf[1]; 1018 switch( emm_head ) 1019 { 1020 case 0x8e70: // EMM-S 1021 memcpy(epg.hexserial+1, buf+3, 4); 1022 epg.hexserial[4]=reader[au].hexserial[4]; 1023 break; 1024 case 0x8870: // EMM-U 1025 case 0x8c70: // confidential ? 1026 default: 1027 cs_log("unsupported emm type: %04X", emm_head); 1028 ok=0; 1029 } 1030 if( !ok ) cs_log("only EMM-S supported"); 1031 } 1032 else*/ 1033 memcpy(epg.hexserial, reader[au].hexserial, 8); // dummy 1034 1035 memcpy(epg.emm, buf, epg.l); 1036 if( ok ) 1037 do_emm(&epg); 1038 } 1039 1016 1040 // Should always send an answer to client (also if au is disabled), 1017 1041 // some clients will disconnect if they get no answer
Note:
See TracChangeset
for help on using the changeset viewer.