Changeset 1677
- Timestamp:
- 02/24/10 21:46:24 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/monitor-improvement/oscam-config.c
r1675 r1677 191 191 void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName) 192 192 { 193 int i,j; 194 char *ptr1,*ptr2,*ptr3; 195 char *ptr[CS_MAXFILTERS] = {0}; 196 197 memset(ftab, 0, sizeof(FTAB)); 198 for( i=0, ptr1=strtok(zFilterAsc, ";"); (i<CS_MAXFILTERS) && (ptr1); ptr1=strtok(NULL, ";"), i++ ) 199 { 200 //cs_log("ptr1=%s", ptr1); 201 ptr[i] = ptr1; 202 if( (ptr2=strchr(trim(ptr1), ':')) ) 203 { 204 //cs_log("ptr2=%s", ptr2); 205 *ptr2++='\0'; 206 //cs_log("ptr2=%s", ptr2); 207 ftab->filts[i].caid = (ushort)a2i(ptr1, 4); 208 //cs_log("caid=%04X", ftab->filts[i].caid); 209 ptr[i] = ptr2; 210 } 211 else if (zFiltName && zFiltName[0]=='c') 212 { 213 cs_log("PANIC: CAID field not found in CHID parameter!"); 214 cs_exit(1); 215 } 216 ftab->nfilts++; 217 } 218 219 if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName); 220 for( i=0; i<ftab->nfilts; i++ ) 221 { 222 cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid); 223 for( j=0, ptr3=strtok(ptr[i], ","); (j<CS_MAXPROV) && (ptr3); ptr3=strtok(NULL, ","), j++ ) 224 { 225 ftab->filts[i].prids[j] = a2i(ptr3,6); 226 ftab->filts[i].nprids++; 227 cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]); 228 } 229 } 230 //cs_log("exit chk_ftab"); 193 int i, j; 194 char *ptr1, *ptr2, *ptr3; 195 char *ptr[CS_MAXFILTERS] = {0}; 196 197 memset(ftab, 0, sizeof(FTAB)); 198 for( i = 0, ptr1 = strtok(zFilterAsc, ";"); (i < CS_MAXFILTERS) && (ptr1); ptr1 = strtok(NULL, ";"), i++ ) { 199 ptr[i] = ptr1; 200 if( (ptr2 = strchr(trim(ptr1), ':')) ) { 201 *ptr2++ ='\0'; 202 ftab->filts[i].caid = (ushort)a2i(ptr1, 4); 203 ptr[i] = ptr2; 204 } 205 else if (zFiltName && zFiltName[0] == 'c') { 206 cs_log("PANIC: CAID field not found in CHID parameter!"); 207 cs_exit(1); 208 } 209 ftab->nfilts++; 210 } 211 212 if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName); 213 for( i = 0; i < ftab->nfilts; i++ ) { 214 cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid); 215 for( j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++ ) { 216 ftab->filts[i].prids[j] = a2i(ptr3,6); 217 ftab->filts[i].nprids++; 218 cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]); 219 } 220 } 231 221 } 232 222 233 223 void chk_cltab(char *classasc, CLASSTAB *clstab) 234 224 { 235 int i; 236 char *ptr1; 237 for( i=0, ptr1=strtok(classasc, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ",") ) 238 { 239 ptr1=trim(ptr1); 240 if( ptr1[0] == '!' ) 241 clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2); 242 else 243 clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2); 244 } 225 int i; 226 char *ptr1; 227 for( i = 0, ptr1 = strtok(classasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",") ) { 228 ptr1 = trim(ptr1); 229 if( ptr1[0] == '!' ) 230 clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2); 231 else 232 clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2); 233 } 245 234 } 246 235 247 236 void chk_port_tab(char *portasc, PTAB *ptab) 248 237 { 249 int i,j,nfilts,ifilt,iport; 250 char *ptr1,*ptr2,*ptr3; 251 char *ptr[CS_MAXPORTS] = {0}; 252 int port[CS_MAXPORTS] = {0}; 253 int previous_nports = ptab->nports; 254 255 for (nfilts=i=previous_nports, ptr1=strtok(portasc, ";"); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ";"), i++) 256 { 257 ptr[i] = ptr1; 258 if( (ptr2=strchr(trim(ptr1), '@')) ) 259 { 260 *ptr2++='\0'; 261 ptab->ports[i].s_port = atoi(ptr1); 262 ptr[i] = ptr2; 263 port[i] = ptab->ports[i].s_port; 264 ptab->nports++; 265 } 266 nfilts++; 267 } 268 269 if( nfilts==1 && strlen(portasc)<6 && ptab->ports[0].s_port == 0 ) { 270 ptab->ports[0].s_port = atoi(portasc); 271 ptab->nports = 1; 272 } 273 274 iport=ifilt = previous_nports; 275 for (i=previous_nports; i<nfilts; i++) 276 { 277 if( port[i]!=0 ) iport = i; 278 for (j=0, ptr3=strtok(ptr[i], ","); (j<CS_MAXPROV) && (ptr3); ptr3=strtok(NULL, ","), j++) 279 { 280 if( (ptr2=strchr(trim(ptr3), ':')) ) 281 { 282 *ptr2++='\0'; 283 ptab->ports[iport].ftab.nfilts++; 284 ifilt = ptab->ports[iport].ftab.nfilts-1; 285 ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4); 286 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6); 287 } else { 288 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6); 289 } 290 ptab->ports[iport].ftab.filts[ifilt].nprids++; 291 } 292 } 238 int i, j, nfilts, ifilt, iport; 239 char *ptr1, *ptr2, *ptr3; 240 char *ptr[CS_MAXPORTS] = {0}; 241 int port[CS_MAXPORTS] = {0}; 242 int previous_nports = ptab->nports; 243 244 for (nfilts = i = previous_nports, ptr1 = strtok(portasc, ";"); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ";"), i++) { 245 ptr[i] = ptr1; 246 if( (ptr2=strchr(trim(ptr1), '@')) ) { 247 *ptr2++ ='\0'; 248 ptab->ports[i].s_port = atoi(ptr1); 249 ptr[i] = ptr2; 250 port[i] = ptab->ports[i].s_port; 251 ptab->nports++; 252 } 253 nfilts++; 254 } 255 256 if( nfilts == 1 && strlen(portasc) < 6 && ptab->ports[0].s_port == 0 ) { 257 ptab->ports[0].s_port = atoi(portasc); 258 ptab->nports = 1; 259 } 260 261 iport = ifilt = previous_nports; 262 for (i=previous_nports; i<nfilts; i++) { 263 if( port[i] != 0 ) 264 iport = i; 265 for (j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++) { 266 if( (ptr2=strchr(trim(ptr3), ':')) ) { 267 *ptr2++='\0'; 268 ptab->ports[iport].ftab.nfilts++; 269 ifilt = ptab->ports[iport].ftab.nfilts-1; 270 ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4); 271 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6); 272 } else { 273 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6); 274 } 275 ptab->ports[iport].ftab.filts[ifilt].nprids++; 276 } 277 } 293 278 } 294 279 … … 296 281 static void chk_srvip(char *value, in_addr_t *ip) 297 282 { 298 299 300 301 if (i<8) ip[i++]=inet_addr(ptr);283 int i; 284 char *ptr; 285 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ",")) 286 if (i<8) ip[i++ = inet_addr(ptr); 302 287 } 303 288 #endif … … 305 290 void chk_t_global(char *token, char *value) 306 291 { 307 if (!strcmp(token, "disablelog")) { cfg->disablelog = atoi(value); return; } 292 if (!strcmp(token, "disablelog")) { 293 if (strlen(value) == 0) { 294 cfg->disablelog = 0; 295 return; 296 } else { 297 cfg->disablelog = atoi(value); 298 return; 299 } 300 } 308 301 309 302 if (!strcmp(token, "serverip")) { 310 303 if (strlen(value) == 0) { 304 cfg->srvip = 0; 311 305 return; 312 306 } else { … … 316 310 } 317 311 318 if (!strcmp(token, "logfile")) { 319 if (cfg->logfile != NULL) { 320 free(cfg->logfile); 321 cfg->logfile = NULL; 322 } 323 if (value[0]) 324 asprintf(&(cfg->logfile), "%s", value); 325 return; 326 } 327 if (!strcmp(token, "pidfile")) { 328 if (cfg->pidfile != NULL) { 329 free(cfg->pidfile); 330 cfg->pidfile = NULL; 331 } 332 if (value[0]) 333 asprintf(&(cfg->pidfile), "%s", value); 334 return; 335 } 336 if (!strcmp(token, "usrfile")) { 337 if (cfg->usrfile != NULL) { 338 free(cfg->usrfile); 339 cfg->usrfile = NULL; 340 } 341 if (value[0]) 342 asprintf(&(cfg->usrfile), "%s", value); 343 return; 344 } 345 if (!strcmp(token, "cwlogdir")) { 346 if (cfg->cwlogdir != NULL) { 347 free(cfg->cwlogdir); 348 cfg->cwlogdir = NULL; 349 } 350 if (value[0]) 351 asprintf(&(cfg->cwlogdir), "%s", value); 352 return; 353 } 354 355 if (!strcmp(token, "usrfileflag")) { cfg->usrfileflag=atoi(value); return; } 356 357 if (!strcmp(token, "clienttimeout")) 358 { 359 cfg->ctimeout = atoi(value); 360 if (cfg->ctimeout < 100) 361 cfg->ctimeout *= 1000; 362 return; 363 } 364 if (!strcmp(token, "fallbacktimeout")) 365 { 366 cfg->ftimeout = atoi(value); 367 if (cfg->ftimeout < 100) 368 cfg->ftimeout *= 1000; 369 return; 370 } 371 372 if (!strcmp(token, "clientmaxidle")) { cfg->cmaxidle=atoi(value); return; } 373 if (!strcmp(token, "cachedelay")) { cfg->delay=atoi(value); return; } 374 if (!strcmp(token, "bindwait")) { cfg->bindwait=atoi(value); return; } 375 if (!strcmp(token, "netprio")) { cfg->netprio=atoi(value); return; } 376 if (!strcmp(token, "resolvedelay")) { cfg->resolvedelay=atoi(value); return; } 377 if (!strcmp(token, "sleep")) { cfg->tosleep=atoi(value); return; } 378 if (!strcmp(token, "unlockparental")) { cfg->ulparent=atoi(value); return; } 379 if (!strcmp(token, "nice")) 380 { 381 cfg->nice=atoi(value); 382 if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice=99; 383 if (cfg->nice!=99) cs_setpriority(cfg->nice); // ignore errors 384 return; 385 } 386 if (!strcmp(token, "serialreadertimeout")) 387 { 388 if (cfg->srtimeout < 100) 389 cfg->srtimeout = atoi(value) * 1000; 390 else 391 cfg->srtimeout = atoi(value); 392 if( cfg->srtimeout <=0 ) 393 cfg->srtimeout=1500; 394 return; 395 } 396 if (!strcmp(token, "maxlogsize")) 397 { 398 cfg->max_log_size=atoi(value); 399 if( cfg->max_log_size <=10 ) 400 cfg->max_log_size=10; 401 return; 402 } 403 if( !strcmp(token, "waitforcards")) { cfg->waitforcards = atoi(value); return; } 404 if( !strcmp(token, "preferlocalcards")) { cfg->preferlocalcards = atoi(value); return; } 405 if (token[0] != '#') 406 fprintf(stderr, "Warning: keyword '%s' in global section not recognized\n",token); 312 if (!strcmp(token, "logfile")) { 313 if (cfg->logfile != NULL) { 314 free(cfg->logfile); 315 cfg->logfile = NULL; 316 } 317 if (strlen(value) > 0) 318 asprintf(&(cfg->logfile), "%s", value); 319 return; 320 } 321 322 if (!strcmp(token, "pidfile")) { 323 if (cfg->pidfile != NULL) { 324 free(cfg->pidfile); 325 cfg->pidfile = NULL; 326 } 327 if (strlen(value) > 0) 328 asprintf(&(cfg->pidfile), "%s", value); 329 return; 330 } 331 332 if (!strcmp(token, "usrfile")) { 333 if (cfg->usrfile != NULL) { 334 free(cfg->usrfile); 335 cfg->usrfile = NULL; 336 } 337 if (strlen(value) > 0) 338 asprintf(&(cfg->usrfile), "%s", value); 339 return; 340 } 341 342 if (!strcmp(token, "cwlogdir")) { 343 if (cfg->cwlogdir != NULL) { 344 free(cfg->cwlogdir); 345 cfg->cwlogdir = NULL; 346 } 347 if (strlen(value) > 0) 348 asprintf(&(cfg->cwlogdir), "%s", value); 349 return; 350 } 351 352 if (!strcmp(token, "usrfileflag")) { 353 if (strlen(value) == 0) { 354 cfg->usrfileflag = 0; 355 return; 356 } else { 357 cfg->usrfileflag = atoi(value); 358 return; 359 } 360 } 361 362 if (!strcmp(token, "clienttimeout")) { 363 if (strlen(value) == 0) { 364 cfg->ctimeout = CS_CLIENT_TIMEOUT; 365 return; 366 } else { 367 cfg->ctimeout = atoi(value); 368 if (cfg->ctimeout < 100) 369 cfg->ctimeout *= 1000; 370 return; 371 } 372 } 373 374 if (!strcmp(token, "fallbacktimeout")) { 375 if (strlen(value) == 0) { 376 cfg->ftimeout = CS_CLIENT_TIMEOUT; 377 return; 378 } else { 379 cfg->ftimeout = atoi(value); 380 if (cfg->ftimeout < 100) 381 cfg->ftimeout *= 1000; 382 return; 383 } 384 } 385 386 if (!strcmp(token, "clientmaxidle")) { 387 if (strlen(value) == 0) { 388 cfg->cmaxidle = CS_CLIENT_MAXIDLE; 389 return; 390 } else { 391 cfg->cmaxidle = atoi(value); 392 return; 393 } 394 } 395 396 if (!strcmp(token, "cachedelay")) { 397 if (strlen(value) == 0) { 398 cfg->delay = CS_DELAY; 399 return; 400 } else { 401 cfg->delay = atoi(value); 402 return; 403 } 404 } 405 406 if (!strcmp(token, "bindwait")) { 407 if (strlen(value) == 0) { 408 cfg->bindwait = CS_BIND_TIMEOUT; 409 return; 410 } else { 411 cfg->bindwait = atoi(value); 412 return; 413 } 414 } 415 416 if (!strcmp(token, "netprio")) { 417 if (strlen(value) == 0) { 418 cfg->netprio = 0; 419 return; 420 } else { 421 cfg->netprio = atoi(value); 422 return; 423 } 424 } 425 426 if (!strcmp(token, "resolvedelay")) { 427 if (strlen(value) == 0) { 428 cfg->resolvedelay = CS_RESOLVE_DELAY; 429 return; 430 } else { 431 cfg->resolvedelay = atoi(value); 432 return; 433 } 434 } 435 436 if (!strcmp(token, "sleep")) { 437 if (strlen(value) == 0) { 438 cfg->tosleep = 0; 439 return; 440 } else { 441 cfg->tosleep = atoi(value); 442 return; 443 } 444 } 445 446 if (!strcmp(token, "unlockparental")) { 447 if (strlen(value) == 0) { 448 cfg->ulparent = 0; 449 return; 450 } else { 451 cfg->ulparent = atoi(value); 452 return; 453 } 454 } 455 456 if (!strcmp(token, "nice")) { 457 if (strlen(value) == 0) { 458 cfg->nice = 99; 459 return; 460 } else { 461 cfg->nice = atoi(value); 462 if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice = 99; 463 if (cfg->nice != 99) cs_setpriority(cfg->nice); // ignore errors 464 return; 465 } 466 } 467 468 if (!strcmp(token, "serialreadertimeout")) { 469 if (cfg->srtimeout < 100) 470 cfg->srtimeout = atoi(value) * 1000; 471 else 472 cfg->srtimeout = atoi(value); 473 if (cfg->srtimeout <= 0) 474 cfg->srtimeout = 1500; 475 return; 476 } 477 478 if (!strcmp(token, "maxlogsize")) { 479 if (strlen(value) == 0) { 480 cfg->max_log_size = 10; 481 return; 482 } else { 483 cfg->max_log_size = atoi(value); 484 if( cfg->max_log_size <= 10 ) 485 cfg->max_log_size = 10; 486 return; 487 } 488 } 489 490 if( !strcmp(token, "waitforcards")) { 491 if (strlen(value) == 0) { 492 cfg->waitforcards = 0; 493 return; 494 } else { 495 cfg->waitforcards = atoi(value); 496 return; 497 } 498 } 499 500 if( !strcmp(token, "preferlocalcards")) { 501 if (strlen(value) == 0) { 502 cfg->preferlocalcards = 0; 503 return; 504 } else { 505 cfg->preferlocalcards = atoi(value); 506 return; 507 } 508 } 509 510 if (token[0] != '#') 511 cs_log("Warning: keyword '%s' in global section not recognized", token); 407 512 } 408 513 … … 491 596 if (!strcmp(token, "hideclient_to")) { cfg->mon_hideclient_to=atoi(value); return; } 492 597 if (token[0] != '#') 493 fprintf(stderr, "Warning: keyword '%s' in monitor section not recognized\n",token);598 cs_log("Warning: keyword '%s' in monitor section not recognized",token); 494 599 } 495 600 … … 643 748 644 749 if (token[0] != '#') 645 750 fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token); 646 751 } 647 752 #endif … … 649 754 static void chk_token(char *token, char *value, int tag) 650 755 { 651 switch(tag) 652 { 653 case TAG_GLOBAL : chk_t_global(token, value); break; 654 case TAG_MONITOR : chk_t_monitor(token, value); break; 655 case TAG_CAMD33 : chk_t_camd33(token, value); break; 656 case TAG_CAMD35 : 657 case TAG_CS357X : chk_t_camd35(token, value); break; 658 case TAG_NEWCAMD : chk_t_newcamd(token, value); break; 659 case TAG_RADEGAST: chk_t_radegast(token, value); break; 660 case TAG_SERIAL : chk_t_serial(token, value); break; 661 case TAG_CS378X : chk_t_camd35_tcp(token, value); break; 756 switch(tag) { 757 case TAG_GLOBAL : chk_t_global(token, value); break; 758 case TAG_MONITOR : chk_t_monitor(token, value); break; 759 case TAG_CAMD33 : chk_t_camd33(token, value); break; 760 case TAG_CAMD35 : 761 case TAG_CS357X : chk_t_camd35(token, value); break; 762 case TAG_NEWCAMD : chk_t_newcamd(token, value); break; 763 case TAG_RADEGAST: chk_t_radegast(token, value); break; 764 case TAG_SERIAL : chk_t_serial(token, value); break; 765 case TAG_CS378X : chk_t_camd35_tcp(token, value); break; 662 766 #ifdef CS_WITH_GBOX 663 664 #endif 665 767 case TAG_GBOX : chk_t_gbox(token, value); break; 768 #endif 769 case TAG_CCCAM : chk_t_cccam(token, value); break; 666 770 #ifdef HAVE_DVBAPI 667 771 case TAG_DVBAPI : chk_t_dvbapi(token, value); break; 668 772 #else 669 773 case TAG_DVBAPI : fprintf(stderr, "Warning: OSCam compiled without DVB API support.\n"); break; 670 774 #endif 671 775 #ifdef CS_ANTICASC 672 673 #endif 674 776 case TAG_ANTICASC: chk_t_ac(token, value); break; 777 #endif 778 } 675 779 } 676 780 677 781 void init_len4caid() 678 782 { 679 int nr; 680 FILE *fp; 681 char *value; 682 683 memset(len4caid, 0, sizeof(ushort)<<8); 684 sprintf(token, "%s%s", cs_confdir, cs_l4ca); 685 if (!(fp=fopen(token, "r"))) 686 return; 687 for(nr=0; fgets(token, sizeof(token), fp);) 688 { 689 int i, c; 690 char *ptr; 691 if (!(value=strchr(token, ':'))) continue; 692 *value++='\0'; 693 if( (ptr=strchr(value, '#')) ) 694 *ptr='\0'; 695 if (strlen(trim(token))!=2) continue; 696 if (strlen(trim(value))!=4) continue; 697 if ((i=byte_atob(token))<0) continue; 698 if ((c=word_atob(value))<0) continue; 699 //printf("idx %02X = %04X\n", i, c); fflush(stdout); 700 len4caid[i]=c; 701 nr++; 702 } 703 fclose(fp); 704 cs_log("%d lengths for caid guessing loaded", nr); 705 return; 783 int nr; 784 FILE *fp; 785 char *value; 786 787 memset(len4caid, 0, sizeof(ushort)<<8); 788 sprintf(token, "%s%s", cs_confdir, cs_l4ca); 789 if (!(fp = fopen(token, "r"))) 790 return; 791 for(nr = 0; fgets(token, sizeof(token), fp);) { 792 int i, c; 793 char *ptr; 794 if (!(value=strchr(token, ':'))) 795 continue; 796 *value++ ='\0'; 797 if( (ptr = strchr(value, '#')) ) 798 *ptr = '\0'; 799 if (strlen(trim(token)) != 2) 800 continue; 801 if (strlen(trim(value)) != 4) 802 continue; 803 if ((i = byte_atob(token)) < 0) 804 continue; 805 if ((c = word_atob(value)) < 0) 806 continue; 807 len4caid[i] = c; 808 nr++; 809 } 810 fclose(fp); 811 cs_log("%d lengths for caid guessing loaded", nr); 812 return; 706 813 } 707 814 708 815 int search_boxkey(ushort caid, char *key) 709 816 { 710 int i, rc=0; 711 FILE *fp; 712 char c_caid[512]; 713 714 sprintf(c_caid, "%s%s", cs_confdir, cs_cert); 715 fp=fopen(c_caid, "r"); 716 if (fp) 717 { 718 for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);) 719 { 720 char *c_provid, *c_key; 721 722 c_provid=strchr(c_caid, '#'); 723 if (c_provid) *c_provid='\0'; 724 if (!(c_provid=strchr(c_caid, ':'))) continue; 725 *c_provid++='\0'; 726 if (!(c_key=strchr(c_provid, ':'))) continue; 727 *c_key++='\0'; 728 if (word_atob(trim(c_caid))!=caid) continue; 729 if ((i=(strlen(trim(c_key))>>1))>256) continue; 730 if (cs_atob((uchar *)key, c_key, i)<0) 731 { 732 cs_log("wrong key in \"%s\"", cs_cert); 733 continue; 734 } 735 rc=1; 736 } 737 fclose(fp); 738 } 817 int i, rc = 0; 818 FILE *fp; 819 char c_caid[512]; 820 821 sprintf(c_caid, "%s%s", cs_confdir, cs_cert); 822 fp = fopen(c_caid, "r"); 823 if (fp) { 824 for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);) { 825 char *c_provid, *c_key; 826 827 c_provid = strchr(c_caid, '#'); 828 if (c_provid) 829 *c_provid = '\0'; 830 if (!(c_provid = strchr(c_caid, ':'))) 831 continue; 832 *c_provid++ ='\0'; 833 if (!(c_key = strchr(c_provid, ':'))) 834 continue; 835 *c_key++ ='\0'; 836 if (word_atob(trim(c_caid))!=caid) 837 continue; 838 if ((i=(strlen(trim(c_key))>>1)) > 256) 839 continue; 840 if (cs_atob((uchar *)key, c_key, i) < 0) { 841 cs_log("wrong key in \"%s\"", cs_cert); 842 continue; 843 } 844 rc = 1; 845 } 846 fclose(fp); 847 } 739 848 #ifdef OSCAM_INBUILD_KEYS 740 741 742 743 #endif 744 849 for(i=0; (!rc) && (npkey[i].keylen); i++) 850 if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0))) 851 memcpy(key, npkey[i].key, npkey[i].keylen); 852 #endif 853 return(rc); 745 854 } 746 855 747 856 int init_config() 748 857 { 749 750 751 858 int tag=TAG_GLOBAL; 859 FILE *fp; 860 char *value; 752 861 753 862 #ifndef CS_EMBEDDED 754 863 #ifdef PRIO_PROCESS 755 756 if ((cfg->nice=getpriority(PRIO_PROCESS, 0))==(-1))757 758 #endif 759 #endif 760 cfg->nice=99;761 cfg->ctimeout=CS_CLIENT_TIMEOUT;762 cfg->ftimeout=CS_CLIENT_TIMEOUT / 2;763 cfg->cmaxidle=CS_CLIENT_MAXIDLE;764 cfg->delay=CS_DELAY;765 cfg->bindwait=CS_BIND_TIMEOUT;766 cfg->resolvedelay=CS_RESOLVE_DELAY;767 cfg->mon_level=2;768 cfg->mon_hideclient_to=0;769 cfg->srtimeout=1500;770 cfg->ulparent=0;771 cfg->logfile =NULL;772 cfg->pidfile =NULL;773 cfg->usrfile =NULL;774 cfg->cwlogdir =NULL;775 776 777 778 cfg->http_refresh=0;779 cfg->http_hide_idle_clients=0;780 864 errno=0; 865 if ((cfg->nice = getpriority(PRIO_PROCESS, 0)) == (-1)) 866 if (errno) 867 #endif 868 #endif 869 cfg->nice = 99; 870 cfg->ctimeout = CS_CLIENT_TIMEOUT; 871 cfg->ftimeout = CS_CLIENT_TIMEOUT / 2; 872 cfg->cmaxidle = CS_CLIENT_MAXIDLE; 873 cfg->delay = CS_DELAY; 874 cfg->bindwait = CS_BIND_TIMEOUT; 875 cfg->resolvedelay = CS_RESOLVE_DELAY; 876 cfg->mon_level = 2; 877 cfg->mon_hideclient_to = 0; 878 cfg->srtimeout = 1500; 879 cfg->ulparent = 0; 880 cfg->logfile = NULL; 881 cfg->pidfile = NULL; 882 cfg->usrfile = NULL; 883 cfg->cwlogdir = NULL; 884 strcpy(cfg->http_user, ""); 885 strcpy(cfg->http_pwd, ""); 886 strcpy(cfg->http_css, ""); 887 cfg->http_refresh = 0; 888 cfg->http_hide_idle_clients = 0; 889 strcpy(cfg->http_tpl, ""); 781 890 #ifdef CS_ANTICASC 782 cfg->ac_enabled=0; 783 cfg->ac_users=0; 784 cfg->ac_stime=2; 785 cfg->ac_samples=10; 786 cfg->ac_denysamples=8; 787 cfg->ac_fakedelay=1000; 788 strcpy(cfg->ac_logfile, "./oscam_ac.log"); 789 #endif 790 cfg->ncd_keepalive=1; 791 sprintf(token, "%s%s", cs_confdir, cs_conf); 792 if (!(fp=fopen(token, "r"))) 793 { 794 fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno); 795 exit(1); 796 } 797 while (fgets(token, sizeof(token), fp)) 798 { 799 int i, l; 800 //void *ptr; 801 if ((l=strlen(trim(token)))<3) continue; 802 if ((token[0]=='[') && (token[l-1]==']')) 803 { 804 for (token[l-1]=0, tag=-1, i=TAG_GLOBAL; cctag[i]; i++) 805 if (!strcmp(cctag[i], strtolower(token+1))) 806 tag=i; 807 continue; 808 } 809 if (!(value=strchr(token, '='))) continue; 810 *value++='\0'; 811 chk_token(trim(strtolower(token)), trim(value), tag); 812 } 813 fclose(fp); 891 cfg->ac_enabled = 0; 892 cfg->ac_users = 0; 893 cfg->ac_stime = 2; 894 cfg->ac_samples = 10; 895 cfg->ac_denysamples = 8; 896 cfg->ac_fakedelay = 1000; 897 strcpy(cfg->ac_logfile, "./oscam_ac.log"); 898 #endif 899 cfg->ncd_keepalive=1; 900 sprintf(token, "%s%s", cs_confdir, cs_conf); 901 if (!(fp = fopen(token, "r"))) { 902 fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno); 903 exit(1); 904 } 905 while (fgets(token, sizeof(token), fp)) { 906 int i, l; 907 //void *ptr; 908 if ((l = strlen(trim(token))) < 3) 909 continue; 910 if ((token[0] == '[') && (token[l-1] == ']')) { 911 for (token[l-1] = 0, tag = -1, i = TAG_GLOBAL; cctag[i]; i++) 912 if (!strcmp(cctag[i], strtolower(token+1))) 913 tag = i; 914 continue; 915 } 916 if (!(value=strchr(token, '='))) 917 continue; 918 *value++ ='\0'; 919 chk_token(trim(strtolower(token)), trim(value), tag); 920 } 921 fclose(fp); 814 922 #ifdef CS_LOGFILE 815 923 if (cfg->logfile == NULL) 816 924 asprintf(&(cfg->logfile), "%s", CS_LOGFILE); 817 925 #endif 818 cs_init_log(cfg->logfile); 819 if (cfg->ftimeout>=cfg->ctimeout) 820 { 821 cfg->ftimeout = cfg->ctimeout - 100; 822 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout); 823 } 824 if(cfg->ftimeout < cfg->srtimeout) 825 { 826 cfg->ftimeout = cfg->srtimeout + 100; 827 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout); 828 } 829 if(cfg->ctimeout < cfg->srtimeout) 830 { 831 cfg->ctimeout = cfg->srtimeout + 100; 832 cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout); 833 } 926 cs_init_log(cfg->logfile); 927 if (cfg->ftimeout >= cfg->ctimeout) { 928 cfg->ftimeout = cfg->ctimeout - 100; 929 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout); 930 } 931 if(cfg->ftimeout < cfg->srtimeout) { 932 cfg->ftimeout = cfg->srtimeout + 100; 933 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout); 934 } 935 if(cfg->ctimeout < cfg->srtimeout) { 936 cfg->ctimeout = cfg->srtimeout + 100; 937 cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout); 938 } 834 939 #ifdef CS_ANTICASC 835 if( cfg->ac_denysamples+1>cfg->ac_samples ) 836 { 837 cfg->ac_denysamples=cfg->ac_samples-1; 838 cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples); 839 } 840 #endif 841 return 0; 940 if( cfg->ac_denysamples+1 > cfg->ac_samples ) { 941 cfg->ac_denysamples = cfg->ac_samples - 1; 942 cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples); 943 } 944 #endif 945 return 0; 842 946 } 843 947 … … 964 1068 965 1069 if (!(f=fopen(tmpfile, "w"))){ 966 967 968 969 1070 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno); 1071 return(1); 1072 } 1073 fprintf(f,"#oscam.services generated automatically\n\n"); 970 1074 971 1075 while(sidtab != NULL){ 972 1076 fprintf(f,"[%s]\n", sidtab->label); 973 1077 fprintf_conf(f, CONFVARWIDTH, "caid", ""); 974 1078 for (i=0; i<sidtab->num_caid; i++){ 975 1079 if (i==0) fprintf(f,"%04X", sidtab->caid[i]); 976 1080 else fprintf(f,",%04X", sidtab->caid[i]); 977 978 979 980 981 if (i==0) fprintf(f,"%0 8lX", sidtab->provid[i]);982 else fprintf(f,",%0 8lX", sidtab->provid[i]);983 984 985 986 1081 } 1082 fputc((int)'\n', f); 1083 fprintf_conf(f, CONFVARWIDTH, "provid", ""); 1084 for (i=0; i<sidtab->num_provid; i++){ 1085 if (i==0) fprintf(f,"%06lX", sidtab->provid[i]); 1086 else fprintf(f,",%06lX", sidtab->provid[i]); 1087 } 1088 fputc((int)'\n', f); 1089 fprintf_conf(f, CONFVARWIDTH, "srvid", ""); 1090 for (i=0; i<sidtab->num_srvid; i++){ 987 1091 if (i==0) fprintf(f,"%04X", sidtab->srvid[i]); 988 1092 else fprintf(f,",%04X", sidtab->srvid[i]); … … 990 1094 fprintf(f,"\n\n"); 991 1095 sidtab=sidtab->next; 992 1096 } 993 1097 994 1098 fclose(f); … … 1843 1947 if (!strcmp(token, "deprecated")) { rdr->deprecated=atoi(value); return; } 1844 1948 if (token[0] != '#') 1845 fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);1949 cs_log( "Warning: keyword '%s' in reader section not recognized",token); 1846 1950 } 1847 1951
Note:
See TracChangeset
for help on using the changeset viewer.