Changeset 8531
- Timestamp:
- 03/10/13 19:02:26 (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/globals.h
r8526 r8531 1007 1007 uchar lastserial[8]; 1008 1008 1009 //monitor1010 int8_t auth;1011 1012 1009 // Failban value set bitwise - compared with BAN_ 1013 1010 int32_t failban; … … 1024 1021 uchar pand_md5_key[16]; 1025 1022 #endif 1023 1024 void *module_data; // private module data 1026 1025 1027 1026 struct s_client *next; //make client a linked list -
trunk/module-monitor.c
r8530 r8531 16 16 extern char *loghistptr; 17 17 18 struct monitor_data { 19 bool auth; 20 uint8_t ucrc[4]; 21 struct aes_keys aes_keys; 22 }; 23 18 24 static int8_t monitor_check_ip(void) 19 25 { 20 26 int32_t ok=0; 21 27 struct s_client *cur_cl = cur_client(); 22 23 if (cur_cl->auth) return 0; 28 struct monitor_data *module_data = cur_cl->module_data; 29 30 if (module_data->auth) return 0; 24 31 ok = check_ip(cfg.mon_allowed, cur_cl->ip); 25 32 if (!ok) … … 35 42 struct s_auth *account; 36 43 struct s_client *cur_cl = cur_client(); 37 38 if (cur_cl->auth) return 0; 44 struct monitor_data *module_data = cur_cl->module_data; 45 46 if (module_data->auth) return 0; 39 47 if ((!usr) || (!pwd)) 40 48 { … … 42 50 return -1; 43 51 } 44 for (account=cfg.account, cur_cl->auth=0; (account) && (!cur_cl->auth);) 45 { 46 if (account->monlvl) 47 cur_cl->auth = streq(usr, account->usr) && streq(pwd, account->pwd); 48 if (!cur_cl->auth) 49 account=account->next; 50 } 51 if (!cur_cl->auth) 52 for (account = cfg.account; account; account = account->next) { 53 if (account->monlvl && streq(usr, account->usr) && streq(pwd, account->pwd)) { 54 module_data->auth = 1; 55 break; 56 } 57 } 58 if (!module_data->auth) 52 59 { 53 60 cs_auth_client(cur_cl, (struct s_auth *)0, "invalid account"); … … 64 71 struct s_auth *account; 65 72 struct s_client *cur_cl = cur_client(); 73 struct monitor_data *module_data = cur_cl->module_data; 66 74 unsigned char md5tmp[MD5_DIGEST_LENGTH]; 67 75 68 if ( cur_cl->auth)69 { 70 int32_t s=memcmp( cur_cl->ucrc, ucrc, 4);76 if (module_data->auth) 77 { 78 int32_t s=memcmp(module_data->ucrc, ucrc, 4); 71 79 if (s) 72 80 cs_log("wrong user-crc or garbage !?"); … … 75 83 cur_cl->crypted=1; 76 84 crc=(ucrc[0]<<24) | (ucrc[1]<<16) | (ucrc[2]<<8) | ucrc[3]; 77 for (account=cfg.account; (account) && (! cur_cl->auth); account=account->next)85 for (account=cfg.account; (account) && (!module_data->auth); account=account->next) 78 86 if ((account->monlvl) && 79 87 (crc==crc32(0L, MD5((unsigned char *)account->usr, strlen(account->usr), md5tmp), MD5_DIGEST_LENGTH))) 80 88 { 81 memcpy( cur_cl->ucrc, ucrc, 4);82 aes_set_key(& cur_cl->aes_keys, (char *)MD5((unsigned char *)ESTR(account->pwd), strlen(ESTR(account->pwd)), md5tmp));89 memcpy(module_data->ucrc, ucrc, 4); 90 aes_set_key(&module_data->aes_keys, (char *)MD5((unsigned char *)ESTR(account->pwd), strlen(ESTR(account->pwd)), md5tmp)); 83 91 if (cs_auth_client(cur_cl, account, NULL)) 84 92 return -1; 85 cur_cl->auth=1;86 } 87 if (! cur_cl->auth)93 module_data->auth=1; 94 } 95 if (!module_data->auth) 88 96 { 89 97 cs_auth_client(cur_cl, (struct s_auth *)0, "invalid user"); 90 98 return -1; 91 99 } 92 return cur_cl->auth;100 return module_data->auth; 93 101 } 94 102 95 103 int32_t monitor_send_idx(struct s_client *cl, char *txt) 96 104 { 105 struct monitor_data *module_data = cl->module_data; 97 106 int32_t l; 98 107 unsigned char buf[256+32]; … … 108 117 buf[9]=l=strlen(txt); 109 118 l=boundary(4, l+5)+5; 110 memcpy(buf+1, cl->ucrc, 4);119 memcpy(buf+1, module_data->ucrc, 4); 111 120 cs_strncpy((char *)buf+10, txt, sizeof(buf)-10); 112 121 uchar tmp[10]; 113 122 memcpy(buf+5, i2b_buf(4, crc32(0L, buf+10, l-10), tmp), 4); 114 aes_encrypt_idx(& cl->aes_keys, buf+5, l-5);123 aes_encrypt_idx(&module_data->aes_keys, buf+5, l-5); 115 124 return sendto(cl->udp_fd, buf, l, 0, (struct sockaddr *)&cl->udp_sa, cl->udp_sa_len); 116 125 } … … 123 132 if (!n) 124 133 return buf[0]=0; 134 if (!client->module_data && !cs_malloc(&client->module_data, sizeof(struct monitor_data))) 135 return 0; 125 136 if (buf[0]=='&') 126 137 { … … 139 150 return buf[0]=0; 140 151 } 141 aes_decrypt(&client->aes_keys, buf+5, 16); 152 struct monitor_data *module_data = client->module_data; 153 aes_decrypt(&module_data->aes_keys, buf+5, 16); 142 154 bsize=boundary(4, buf[9]+5)+5; 143 155 if (n<bsize) … … 146 158 return buf[0]=0; 147 159 } 148 aes_decrypt(& client->aes_keys, buf+21, n-21);160 aes_decrypt(&module_data->aes_keys, buf+21, n-21); 149 161 uchar tmp[10]; 150 162 if (memcmp(buf+5, i2b_buf(4, crc32(0L, buf+10, n-10), tmp), 4)) … … 504 516 char buf[64]; 505 517 struct s_client *cur_cl = cur_client(); 506 if (cur_cl->auth && cur_cl->account) 518 struct monitor_data *module_data = cur_cl->module_data; 519 if (module_data->auth && cur_cl->account) 507 520 snprintf(buf, sizeof(buf), "[A-0000]1|%s logged in\n", cur_cl->account->usr); 508 521 else … … 781 794 char *arg; 782 795 struct s_client *cur_cl = cur_client(); 796 struct monitor_data *module_data = cur_cl->module_data; 783 797 784 798 if( (arg = strchr(req, ' ')) ) { *arg++ = 0; trim(arg); } 785 799 //trim(req); 786 if ((!cur_cl->auth) && (strcmp(req, cmd[0]))) monitor_login(NULL); 800 801 if (!module_data->auth && strcmp(req, cmd[0]) != 0) 802 monitor_login(NULL); 787 803 788 804 for (rc=1, i = 0; i < cmdcnt; i++) … … 821 837 } 822 838 839 static void monitor_cleanup(struct s_client * client) { 840 NULLFREE(client->module_data); 841 } 842 823 843 void module_monitor(struct s_module *ph){ 824 844 ph->ptab.nports = 1; … … 829 849 ph->s_handler = monitor_server; 830 850 ph->recv = monitor_recv; 851 ph->cleanup = monitor_cleanup; 831 852 // ph->send_dcw=NULL; 832 853 } -
trunk/oscam-chk.c
r8470 r8531 643 643 #ifdef CS_CACHEEX 644 644 //To avoid cascading, a incoming cache request should not invoke a outgoing cache request: 645 if (rdr->cacheex.mode == 1 && cur_cl->a uth && cur_cl->account->cacheex.mode == 1)645 if (rdr->cacheex.mode == 1 && cur_cl->account->cacheex.mode == 1) 646 646 return (0); 647 647 -
trunk/oscam-client.c
r8527 r8531 597 597 cs_statistics(cl); 598 598 cs_sleepms(500); //just wait a bit that really really nobody is accessing client data 599 struct s_module *module = get_module(cl); 600 if (module->cleanup) 601 module->cleanup(cl); 602 } 599 } 600 601 struct s_module *module = get_module(cl); 602 if (module->cleanup) 603 module->cleanup(cl); 603 604 604 605 // Close network socket if not already cleaned by previous cleanup functions
Note:
See TracChangeset
for help on using the changeset viewer.