Changeset 1542
- Timestamp:
- 02/13/10 19:33:05 (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-config.c
r1509 r1542 882 882 int init_userdb() 883 883 { 884 int tag=0, nr, nro, expired, disabled; 885 //int first=1; 886 FILE *fp; 887 char *value; 888 struct s_auth *ptr; 889 /*static */struct s_auth *account=(struct s_auth *)0; 890 891 sprintf(token, "%s%s", cs_confdir, cs_user); 892 if (!(fp=fopen(token, "r"))) 893 { 894 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno); 895 return(1); 896 } 897 for (nro=0, ptr=cfg->account; ptr; nro++) 898 { 899 struct s_auth *ptr_next; 900 ptr_next=ptr->next; 901 free(ptr); 902 ptr=ptr_next; 903 } 904 nr=0; 905 while (fgets(token, sizeof(token), fp)) 906 { 907 int i, l; 908 void *ptr; 909 if ((l=strlen(trim(token)))<3) continue; 910 if ((token[0]=='[') && (token[l-1]==']')) 911 { 912 token[l-1]=0; 913 tag=(!strcmp("account", strtolower(token+1))); 914 if (!(ptr=malloc(sizeof(struct s_auth)))) 915 { 916 cs_log("Error allocating memory (errno=%d)", errno); 917 return(1); 918 } 919 if (account) 920 account->next=ptr; 921 else 922 cfg->account=ptr; 923 account=ptr; 924 memset(account, 0, sizeof(struct s_auth)); 925 account->au=(-1); 926 account->monlvl=cfg->mon_level; 927 account->tosleep=cfg->tosleep; 928 account->c35_suppresscmd08=cfg->c35_suppresscmd08; 929 for (i=1; i<CS_MAXCAIDTAB; account->ctab.mask[i++]=0xffff); 930 for (i=1; i<CS_MAXTUNTAB; account->ttab.bt_srvid[i++]=0x0000); 931 nr++; 884 int tag = 0, nr, nro, expired, disabled; 885 //int first=1; 886 FILE *fp; 887 char *value; 888 struct s_auth *ptr; 889 /*static */struct s_auth *account=(struct s_auth *)0; 890 891 sprintf(token, "%s%s", cs_confdir, cs_user); 892 if (!(fp = fopen(token, "r"))) { 893 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno); 894 return(1); 895 } 896 897 for (nro = 0, ptr = cfg->account; ptr; nro++) { 898 struct s_auth *ptr_next; 899 ptr_next = ptr->next; 900 free(ptr); 901 ptr = ptr_next; 902 } 903 nr = 0; 904 905 while (fgets(token, sizeof(token), fp)) { 906 int i, l; 907 void *ptr; 908 909 if ((l=strlen(trim(token))) < 3) 910 continue; 911 912 if ((token[0] == '[') && (token[l-1] == ']')) { 913 token[l - 1] = 0; 914 tag = (!strcmp("account", strtolower(token + 1))); 915 916 if (!(ptr=malloc(sizeof(struct s_auth)))) { 917 cs_log("Error allocating memory (errno=%d)", errno); 918 return(1); 919 } 920 921 if (account) 922 account->next = ptr; 923 else 924 cfg->account = ptr; 925 926 account = ptr; 927 memset(account, 0, sizeof(struct s_auth)); 928 account->au = (-1); 929 for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff); 930 for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000); 931 nr++; 932 932 933 #ifdef CS_ANTICASC 933 account->ac_users=cfg->ac_users; 934 account->ac_penalty=cfg->ac_penalty; 935 account->ac_idx = nr; 936 #endif 937 continue; 938 } 939 if (!tag) continue; 940 if (!(value=strchr(token, '='))) continue; 941 *value++='\0'; 942 chk_account(trim(strtolower(token)), trim(value), account); 943 } 944 fclose(fp); 945 946 for (expired=0, disabled=0, ptr=cfg->account; ptr;) 947 { 948 if(ptr->expirationdate && ptr->expirationdate<time(NULL)) expired++; 949 if(ptr->disabled != 0) disabled++; 950 ptr=ptr->next; 951 } 952 953 cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled); 954 return(0); 934 account->ac_users = cfg->ac_users; 935 account->ac_penalty = cfg->ac_penalty; 936 account->ac_idx = nr; 937 #endif 938 continue; 939 } 940 941 if (!tag) 942 continue; 943 944 if (!(value=strchr(token, '='))) 945 continue; 946 947 *value++ = '\0'; 948 chk_account(trim(strtolower(token)), trim(value), account); 949 } 950 951 fclose(fp); 952 953 for (expired = 0, disabled = 0, ptr = cfg->account; ptr;) { 954 955 if(ptr->expirationdate && ptr->expirationdate < time(NULL)) 956 expired++; 957 958 if(ptr->disabled != 0) 959 disabled++; 960 961 ptr = ptr->next; 962 } 963 964 cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled); 965 return(0); 955 966 } 956 967 -
trunk/oscam.c
r1533 r1542 341 341 static void cs_reinit_clients() 342 342 { 343 int i; 344 struct s_auth *account; 345 346 for( i=1; i<CS_MAXPID; i++ ) 347 if( client[i].pid && client[i].typ=='c' && client[i].usr[0] ) 348 { 349 for (account=cfg->account; (account) ; account=account->next) 350 if (!strcmp(client[i].usr, account->usr)) 351 break; 352 353 if (account && 354 client[i].pcrc==crc32(0L, MD5((uchar *)account->pwd, strlen(account->pwd), NULL), 16)) 355 { 356 client[i].grp = account->grp; 357 client[i].au = account->au; 358 client[i].autoau = account->autoau; 359 client[i].expirationdate = account->expirationdate; 360 client[i].c35_suppresscmd08 = account->c35_suppresscmd08; 361 client[i].disabled = account->disabled; 362 client[i].tosleep = (60*account->tosleep); 363 client[i].monlvl = account->monlvl; 364 client[i].fchid = account->fchid; // CHID filters 365 client[i].cltab = account->cltab; // Class 366 if(!client[i].ncd_server) // newcamd module dosent like ident reloading 367 client[i].ftab = account->ftab; // Ident 368 client[i].sidtabok= account->sidtabok; // services 369 client[i].sidtabno= account->sidtabno; // services 370 memcpy(&client[i].ctab, &account->ctab, sizeof(client[i].ctab)); 371 memcpy(&client[i].ttab, &account->ttab, sizeof(client[i].ttab)); 343 int i; 344 struct s_auth *account; 345 346 for( i = 1; i < CS_MAXPID; i++ ) 347 if( client[i].pid && client[i].typ == 'c' && client[i].usr[0] ) { 348 for (account = cfg->account; (account) ; account = account->next) 349 if (!strcmp(client[i].usr, account->usr)) 350 break; 351 352 if (account && client[i].pcrc == crc32(0L, MD5((uchar *)account->pwd, strlen(account->pwd), NULL), 16)) { 353 client[i].grp = account->grp; 354 client[i].au = account->au; 355 client[i].autoau = account->autoau; 356 client[i].expirationdate = account->expirationdate; 357 358 //set first to global value and then to specific (higher prio) 359 client[i].c35_suppresscmd08 = cfg->c35_suppresscmd08; 360 client[i].c35_suppresscmd08 = account->c35_suppresscmd08; 361 362 //set first to global value and then to specific (higher prio) 363 client[i].tosleep = (60*cfg->tosleep); 364 client[i].tosleep = (60*account->tosleep); 365 366 //set first to global value and then to specific (higher prio) 367 client[i].monlvl = cfg->mon_level; 368 client[i].monlvl = account->monlvl; 369 370 client[i].disabled = account->disabled; 371 client[i].fchid = account->fchid; // CHID filters 372 client[i].cltab = account->cltab; // Class 373 374 // newcamd module dosent like ident reloading 375 if(!client[i].ncd_server) 376 client[i].ftab = account->ftab; // Ident 377 378 client[i].sidtabok = account->sidtabok; // services 379 client[i].sidtabno = account->sidtabno; // services 380 381 memcpy(&client[i].ctab, &account->ctab, sizeof(client[i].ctab)); 382 memcpy(&client[i].ttab, &account->ttab, sizeof(client[i].ttab)); 383 372 384 #ifdef CS_ANTICASC 373 client[i].ac_idx = account->ac_idx; 374 client[i].ac_penalty = account->ac_penalty; 375 client[i].ac_limit = (account->ac_users*100+80)*cfg->ac_stime; 376 #endif 377 } 378 else 379 { 380 if (ph[client[i].ctyp].type & MOD_CONN_NET) 381 { 382 cs_debug("client '%s', pid=%d not found in db (or password changed)", 383 client[i].usr, client[i].pid); 384 kill(client[i].pid, SIGQUIT); 385 } 386 } 387 } 385 client[i].ac_idx = account->ac_idx; 386 client[i].ac_penalty= account->ac_penalty; 387 client[i].ac_limit = (account->ac_users * 100 + 80) * cfg->ac_stime; 388 #endif 389 } else { 390 if (ph[client[i].ctyp].type & MOD_CONN_NET) { 391 cs_debug("client '%s', pid=%d not found in db (or password changed)", client[i].usr, client[i].pid); 392 kill(client[i].pid, SIGQUIT); 393 } 394 } 395 } 388 396 } 389 397
Note:
See TracChangeset
for help on using the changeset viewer.