source: trunk/oscam-config.c@ 1838

Last change on this file since 1838 was 1838, checked in by alno, 10 years ago

new parameter "clientdyndns=0|1" avoids running the clientresolve thread. If you have already have defined hostname for your clients the parameter must be 1, otherwise no auth is possible for this clients

File size: 71.5 KB
Line 
1#include "globals.h"
2#ifdef CS_WITH_BOXKEYS
3# include "oscam-boxkeys.np"
4#endif
5
6#define CONFVARWIDTH 20
7
8static char *cs_conf="oscam.conf";
9static char *cs_user="oscam.user";
10static char *cs_srvr="oscam.server";
11static char *cs_srid="oscam.srvid";
12static char *cs_l4ca="oscam.guess";
13static char *cs_cert="oscam.cert";
14static char *cs_sidt="oscam.services";
15#ifdef CS_ANTICASC
16static char *cs_ac="oscam.ac";
17#endif
18
19#ifdef IRDETO_GUESSING
20static char *cs_ird="oscam.ird";
21#endif
22
23static char token[4096];
24
25typedef enum cs_proto_type
26{
27 TAG_GLOBAL, // must be first !
28 TAG_MONITOR, // monitor
29 TAG_CAMD33, // camd 3.3x
30 TAG_CAMD35, // camd 3.5x UDP
31 TAG_NEWCAMD, // newcamd
32 TAG_RADEGAST, // radegast
33 TAG_SERIAL, // serial (static)
34 TAG_CS357X, // camd 3.5x UDP
35 TAG_CS378X, // camd 3.5x TCP
36 TAG_GBOX, // gbox
37 TAG_CCCAM, // cccam
38 TAG_DVBAPI, // dvbapi
39 TAG_WEBIF, // webif
40 TAG_ANTICASC // anti-cascading
41} cs_proto_type_t;
42
43static char *cctag[]={"global", "monitor", "camd33", "camd35", "newcamd", "radegast", "serial",
44 "cs357x", "cs378x", "gbox", "cccam", "dvbapi", "webif", "anticasc", NULL};
45
46#ifdef DEBUG_SIDTAB
47static void show_sidtab(struct s_sidtab *sidtab)
48{
49 for (; sidtab; sidtab=sidtab->next)
50 {
51 int i;
52 char buf[1024];
53 cs_log("label=%s", sidtab->label);
54 sprintf(buf, "caid(%d)=", sidtab->num_caid);
55 for (i=0; i<sidtab->num_caid; i++)
56 sprintf(buf+strlen(buf), "%04X ", sidtab->caid[i]);
57 cs_log("%s", buf);
58 sprintf(buf, "provider(%d)=", sidtab->num_provid);
59 for (i=0; i<sidtab->num_provid; i++)
60 sprintf(buf+strlen(buf), "%08X ", sidtab->provid[i]);
61 cs_log("%s", buf);
62 sprintf(buf, "services(%d)=", sidtab->num_srvid);
63 for (i=0; i<sidtab->num_srvid; i++)
64 sprintf(buf+strlen(buf), "%04X ", sidtab->srvid[i]);
65 cs_log("%s", buf);
66 }
67}
68#endif
69
70void chk_iprange(char *value, struct s_ip **base)
71{
72 int i = 0;
73 char *ptr1, *ptr2;
74 struct s_ip *lip, *cip;
75
76 for (cip=lip=*base; cip; cip=cip->next)
77 lip = cip;
78 if (!(cip=malloc(sizeof(struct s_ip)))) {
79 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
80 exit(1);
81 }
82 if (*base)
83 lip->next = cip;
84 else
85 *base = cip;
86
87 memset(cip, 0, sizeof(struct s_ip));
88 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
89 if (i == 0)
90 ++i;
91 else {
92 if (!(cip=malloc(sizeof(struct s_ip)))) {
93 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
94 exit(1);
95 }
96 lip->next = cip;
97 memset(cip, 0, sizeof(struct s_ip));
98 }
99
100 if( (ptr2=strchr(trim(ptr1), '-')) ) {
101 *ptr2++ ='\0';
102 cip->ip[0]=cs_inet_addr(trim(ptr1));
103 cip->ip[1]=cs_inet_addr(trim(ptr2));
104 } else {
105 cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1);
106 }
107 lip = cip;
108 }
109}
110
111void chk_caidtab(char *caidasc, CAIDTAB *ctab)
112{
113 int i;
114 char *ptr1, *ptr2, *ptr3;
115
116 for (i = 0, ptr1 = strtok(caidasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
117 ulong caid, mask, cmap;
118 if( (ptr3 = strchr(trim(ptr1), ':')) )
119 *ptr3++ = '\0';
120 else
121 ptr3 = "";
122
123 if( (ptr2 = strchr(trim(ptr1), '&')) )
124 *ptr2++ = '\0';
125 else
126 ptr2 = "";
127
128 if (((caid = a2i(ptr1, 2)) | (mask = a2i(ptr2,-2)) | (cmap = a2i(ptr3, 2))) < 0x10000) {
129 ctab->caid[i] = caid;
130 ctab->mask[i] = mask;
131 ctab->cmap[i++] = cmap;
132 }
133 }
134}
135
136void chk_tuntab(char *tunasc, TUNTAB *ttab)
137{
138 int i;
139 char *ptr1, *ptr2, *ptr3;
140
141 for (i = 0, ptr1 = strtok(tunasc, ","); (i < CS_MAXTUNTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
142 ulong bt_caidfrom, bt_caidto, bt_srvid;
143 if( (ptr3 = strchr(trim(ptr1), ':')) )
144 *ptr3++ = '\0';
145 else
146 ptr3 = "";
147
148 if( (ptr2 = strchr(trim(ptr1), '.')) )
149 *ptr2++ = '\0';
150 else
151 ptr2 = "";
152
153 if ((bt_caidfrom = a2i(ptr1, 2)) | (bt_srvid = a2i(ptr2,-2)) | (bt_caidto = a2i(ptr3, 2))) {
154 ttab->bt_caidfrom[i] = bt_caidfrom;
155 ttab->bt_caidto[i] = bt_caidto;
156 ttab->bt_srvid[i++] = bt_srvid;
157 }
158 }
159}
160
161void chk_services(char *labels, ulong *sidok, ulong *sidno)
162{
163 int i;
164 char *ptr;
165 SIDTAB *sidtab;
166 *sidok = *sidno = 0;
167 for (ptr=strtok(labels, ","); ptr; ptr=strtok(NULL, ",")) {
168 for (trim(ptr), i = 0, sidtab = cfg->sidtab; sidtab; sidtab = sidtab->next, i++) {
169 if (!strcmp(sidtab->label, ptr)) *sidok|=(1<<i);
170 if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) *sidno|=(1<<i);
171 }
172 }
173}
174
175void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName)
176{
177 int i, j;
178 char *ptr1, *ptr2, *ptr3;
179 char *ptr[CS_MAXFILTERS] = {0};
180
181 memset(ftab, 0, sizeof(FTAB));
182 for( i = 0, ptr1 = strtok(zFilterAsc, ";"); (i < CS_MAXFILTERS) && (ptr1); ptr1 = strtok(NULL, ";"), i++ ) {
183 ptr[i] = ptr1;
184 if( (ptr2 = strchr(trim(ptr1), ':')) ) {
185 *ptr2++ ='\0';
186 ftab->filts[i].caid = (ushort)a2i(ptr1, 4);
187 ptr[i] = ptr2;
188 }
189 else if (zFiltName && zFiltName[0] == 'c') {
190 cs_log("PANIC: CAID field not found in CHID parameter!");
191 cs_exit(1);
192 }
193 ftab->nfilts++;
194 }
195
196 if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName);
197 for( i = 0; i < ftab->nfilts; i++ ) {
198 cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid);
199 for( j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++ ) {
200 ftab->filts[i].prids[j] = a2i(ptr3,6);
201 ftab->filts[i].nprids++;
202 cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]);
203 }
204 }
205}
206
207void chk_cltab(char *classasc, CLASSTAB *clstab)
208{
209 int i;
210 char *ptr1;
211 for( i = 0, ptr1 = strtok(classasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",") ) {
212 ptr1 = trim(ptr1);
213 if( ptr1[0] == '!' )
214 clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2);
215 else
216 clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2);
217 }
218}
219
220void chk_port_tab(char *portasc, PTAB *ptab)
221{
222 int i, j, nfilts, ifilt, iport;
223 char *ptr1, *ptr2, *ptr3;
224 char *ptr[CS_MAXPORTS] = {0};
225 int port[CS_MAXPORTS] = {0};
226 int previous_nports = ptab->nports;
227
228 for (nfilts = i = previous_nports, ptr1 = strtok(portasc, ";"); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ";"), i++) {
229 ptr[i] = ptr1;
230 if( (ptr2=strchr(trim(ptr1), '@')) ) {
231 *ptr2++ ='\0';
232 ptab->ports[i].s_port = atoi(ptr1);
233 ptr[i] = ptr2;
234 port[i] = ptab->ports[i].s_port;
235 ptab->nports++;
236 }
237 nfilts++;
238 }
239
240 if( nfilts == 1 && strlen(portasc) < 6 && ptab->ports[0].s_port == 0 ) {
241 ptab->ports[0].s_port = atoi(portasc);
242 ptab->nports = 1;
243 }
244
245 iport = ifilt = previous_nports;
246 for (i=previous_nports; i<nfilts; i++) {
247 if( port[i] != 0 )
248 iport = i;
249 for (j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++) {
250 if( (ptr2=strchr(trim(ptr3), ':')) ) {
251 *ptr2++='\0';
252 ptab->ports[iport].ftab.nfilts++;
253 ifilt = ptab->ports[iport].ftab.nfilts-1;
254 ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4);
255 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
256 } else {
257 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
258 }
259 ptab->ports[iport].ftab.filts[ifilt].nprids++;
260 }
261 }
262}
263
264#ifdef NOTUSED
265static void chk_srvip(char *value, in_addr_t *ip)
266{
267 int i;
268 char *ptr;
269 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
270 if (i<8) ip[i++] = inet_addr(ptr);
271}
272#endif
273
274void chk_t_global(char *token, char *value)
275{
276 if (!strcmp(token, "disablelog")) {
277 if (strlen(value) == 0) {
278 cfg->disablelog = 0;
279 return;
280 } else {
281 cfg->disablelog = atoi(value);
282 return;
283 }
284 }
285
286 if (!strcmp(token, "disableuserfile")) {
287 if (strlen(value) == 0) {
288 cfg->disableuserfile = 0;
289 return;
290 } else {
291 cfg->disableuserfile = atoi(value);
292 return;
293 }
294 }
295
296 if (!strcmp(token, "serverip")) {
297 if (strlen(value) == 0) {
298 cfg->srvip = 0;
299 return;
300 } else {
301 cfg->srvip=inet_addr(value);
302 return;
303 }
304 }
305
306 if (!strcmp(token, "logfile")) {
307 if (cfg->logfile != NULL) {
308 free(cfg->logfile);
309 cfg->logfile = NULL;
310 }
311 if (strlen(value) > 0)
312 asprintf(&(cfg->logfile), "%s", value);
313 return;
314 }
315
316 if (!strcmp(token, "pidfile")) {
317 if (cfg->pidfile != NULL) {
318 free(cfg->pidfile);
319 cfg->pidfile = NULL;
320 }
321 if (strlen(value) > 0)
322 asprintf(&(cfg->pidfile), "%s", value);
323 return;
324 }
325
326 if (!strcmp(token, "usrfile")) {
327 if (cfg->usrfile != NULL) {
328 free(cfg->usrfile);
329 cfg->usrfile = NULL;
330 }
331 if (strlen(value) > 0)
332 asprintf(&(cfg->usrfile), "%s", value);
333 return;
334 }
335
336 if (!strcmp(token, "cwlogdir")) {
337 if (cfg->cwlogdir != NULL) {
338 free(cfg->cwlogdir);
339 cfg->cwlogdir = NULL;
340 }
341 if (strlen(value) > 0)
342 asprintf(&(cfg->cwlogdir), "%s", value);
343 return;
344 }
345
346 if (!strcmp(token, "usrfileflag")) {
347 if (strlen(value) == 0) {
348 cfg->usrfileflag = 0;
349 return;
350 } else {
351 cfg->usrfileflag = atoi(value);
352 return;
353 }
354 }
355
356 if (!strcmp(token, "clienttimeout")) {
357 if (strlen(value) == 0) {
358 cfg->ctimeout = CS_CLIENT_TIMEOUT;
359 return;
360 } else {
361 cfg->ctimeout = atoi(value);
362 if (cfg->ctimeout < 100)
363 cfg->ctimeout *= 1000;
364 return;
365 }
366 }
367
368 if (!strcmp(token, "fallbacktimeout")) {
369 if (strlen(value) == 0) {
370 cfg->ftimeout = CS_CLIENT_TIMEOUT;
371 return;
372 } else {
373 cfg->ftimeout = atoi(value);
374 if (cfg->ftimeout < 100)
375 cfg->ftimeout *= 1000;
376 return;
377 }
378 }
379
380 if (!strcmp(token, "clientmaxidle")) {
381 if (strlen(value) == 0) {
382 cfg->cmaxidle = CS_CLIENT_MAXIDLE;
383 return;
384 } else {
385 cfg->cmaxidle = atoi(value);
386 return;
387 }
388 }
389
390 if (!strcmp(token, "cachedelay")) {
391 if (strlen(value) == 0) {
392 cfg->delay = CS_DELAY;
393 return;
394 } else {
395 cfg->delay = atoi(value);
396 return;
397 }
398 }
399
400 if (!strcmp(token, "bindwait")) {
401 if (strlen(value) == 0) {
402 cfg->bindwait = CS_BIND_TIMEOUT;
403 return;
404 } else {
405 cfg->bindwait = atoi(value);
406 return;
407 }
408 }
409
410 if (!strcmp(token, "netprio")) {
411 if (strlen(value) == 0) {
412 cfg->netprio = 0;
413 return;
414 } else {
415 cfg->netprio = atoi(value);
416 return;
417 }
418 }
419
420 if (!strcmp(token, "resolvedelay")) {
421 if (strlen(value) == 0) {
422 cfg->resolvedelay = CS_RESOLVE_DELAY;
423 return;
424 } else {
425 cfg->resolvedelay = atoi(value);
426 return;
427 }
428 }
429
430 if (!strcmp(token, "clientdyndns")) {
431 if (strlen(value) == 0) {
432 cfg->clientdyndns = 0;
433 return;
434 } else {
435 cfg->clientdyndns = atoi(value);
436 return;
437 }
438 }
439
440 if (!strcmp(token, "sleep")) {
441 if (strlen(value) == 0) {
442 cfg->tosleep = 0;
443 return;
444 } else {
445 cfg->tosleep = atoi(value);
446 return;
447 }
448 }
449
450 if (!strcmp(token, "unlockparental")) {
451 if (strlen(value) == 0) {
452 cfg->ulparent = 0;
453 return;
454 } else {
455 cfg->ulparent = atoi(value);
456 return;
457 }
458 }
459
460 if (!strcmp(token, "nice")) {
461 if (strlen(value) == 0) {
462 cfg->nice = 99;
463 return;
464 } else {
465 cfg->nice = atoi(value);
466 if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice = 99;
467 if (cfg->nice != 99) cs_setpriority(cfg->nice); // ignore errors
468 return;
469 }
470 }
471
472 if (!strcmp(token, "serialreadertimeout")) {
473 if (cfg->srtimeout < 100)
474 cfg->srtimeout = atoi(value) * 1000;
475 else
476 cfg->srtimeout = atoi(value);
477 if (cfg->srtimeout <= 0)
478 cfg->srtimeout = 1500;
479 return;
480 }
481
482 if (!strcmp(token, "maxlogsize")) {
483 if (strlen(value) == 0) {
484 cfg->max_log_size = 10;
485 return;
486 } else {
487 cfg->max_log_size = atoi(value);
488 if( cfg->max_log_size <= 10 )
489 cfg->max_log_size = 10;
490 return;
491 }
492 }
493
494 if( !strcmp(token, "waitforcards")) {
495 if (strlen(value) == 0) {
496 cfg->waitforcards = 0;
497 return;
498 } else {
499 cfg->waitforcards = atoi(value);
500 return;
501 }
502 }
503
504 if( !strcmp(token, "preferlocalcards")) {
505 if (strlen(value) == 0) {
506 cfg->preferlocalcards = 0;
507 return;
508 } else {
509 cfg->preferlocalcards = atoi(value);
510 return;
511 }
512 }
513
514 if (token[0] != '#')
515 fprintf(stderr, "Warning: keyword '%s' in global section not recognized\n", token);
516}
517
518#ifdef CS_ANTICASC
519void chk_t_ac(char *token, char *value)
520{
521 if (!strcmp(token, "enabled")) {
522 cfg->ac_enabled = atoi(value);
523 if( cfg->ac_enabled <= 0 )
524 cfg->ac_enabled = 0;
525 else
526 cfg->ac_enabled = 1;
527 return;
528 }
529
530 if (!strcmp(token, "numusers")) {
531 cfg->ac_users = atoi(value);
532 if( cfg->ac_users < 0 )
533 cfg->ac_users = 0;
534 return;
535 }
536
537 if (!strcmp(token, "sampletime")) {
538 cfg->ac_stime = atoi(value);
539 if( cfg->ac_stime < 0 )
540 cfg->ac_stime = 2;
541 return;
542 }
543
544 if (!strcmp(token, "samples")) {
545 cfg->ac_samples = atoi(value);
546 if( cfg->ac_samples < 2 || cfg->ac_samples > 10)
547 cfg->ac_samples = 10;
548 return;
549 }
550
551 if (!strcmp(token, "penalty")) {
552 cfg->ac_penalty = atoi(value);
553 if( cfg->ac_penalty < 0 )
554 cfg->ac_penalty = 0;
555 return;
556 }
557
558 if (!strcmp(token, "aclogfile")) {
559 cs_strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile));
560 return;
561 }
562
563 if( !strcmp(token, "fakedelay") ) {
564 cfg->ac_fakedelay = atoi(value);
565 if( cfg->ac_fakedelay < 100 || cfg->ac_fakedelay > 1000 )
566 cfg->ac_fakedelay = 1000;
567 return;
568 }
569
570 if( !strcmp(token, "denysamples") ) {
571 cfg->ac_denysamples = atoi(value);
572 if( cfg->ac_denysamples < 2 || cfg->ac_denysamples > cfg->ac_samples - 1 )
573 cfg->ac_denysamples=cfg->ac_samples-1;
574 return;
575 }
576
577 if (token[0] != '#')
578 fprintf(stderr, "Warning: keyword '%s' in anticascading section not recognized\n",token);
579}
580#endif
581
582void chk_t_monitor(char *token, char *value)
583{
584 if (!strcmp(token, "port")) {
585 if(strlen(value) == 0) {
586 cfg->mon_port = 0;
587 return;
588 } else {
589 cfg->mon_port=atoi(value);
590 return;
591 }
592 }
593
594 if (!strcmp(token, "serverip")) {
595 if(strlen(value) == 0) {
596 cfg->mon_srvip = 0;
597 return;
598 } else {
599 cfg->mon_srvip=inet_addr(value);
600 return;
601 }
602 }
603
604 if (!strcmp(token, "nocrypt")) {
605 if(strlen(value) == 0) {
606 clear_sip(&cfg->mon_allowed);
607 return;
608 } else {
609 chk_iprange(value, &cfg->mon_allowed);
610 return;
611 }
612 }
613
614 if (!strcmp(token, "aulow")) {
615 if(strlen(value) == 0) {
616 cfg->mon_aulow = 0;
617 return;
618 } else {
619 cfg->mon_aulow = atoi(value);
620 return;
621 }
622 }
623
624 if (!strcmp(token, "monlevel")) {
625 if(strlen(value) == 0) {
626 cfg->mon_level = 0;
627 return;
628 } else {
629 cfg->mon_level = atoi(value);
630 return;
631 }
632 }
633
634 if (!strcmp(token, "hideclient_to")) {
635 if(strlen(value) == 0) {
636 cfg->mon_hideclient_to = 0;
637 return;
638 } else {
639 cfg->mon_hideclient_to = atoi(value);
640 return;
641 }
642 }
643
644 if (!strcmp(token, "appendchaninfo")) {
645 if(strlen(value) == 0) {
646 cfg->mon_appendchaninfo = 0;
647 return;
648 } else {
649 cfg->mon_appendchaninfo = atoi(value);
650 return;
651 }
652 }
653
654 if (token[0] != '#')
655 fprintf(stderr, "Warning: keyword '%s' in monitor section not recognized\n",token);
656}
657
658#ifdef WEBIF
659void chk_t_webif(char *token, char *value)
660{
661 if (!strcmp(token, "httpport")) {
662 if(strlen(value) == 0) {
663 cfg->http_port = 0;
664 return;
665 } else {
666 cfg->http_port = atoi(value);
667 return;
668 }
669 }
670
671 if (!strcmp(token, "httpuser")) {
672 cs_strncpy(cfg->http_user, value, sizeof(cfg->http_user));
673 return;
674 }
675
676 if (!strcmp(token, "httppwd")) {
677 cs_strncpy(cfg->http_pwd, value, sizeof(cfg->http_pwd));
678 return;
679 }
680
681 if (!strcmp(token, "httpcss")) {
682 cs_strncpy(cfg->http_css, value, sizeof(cfg->http_css));
683 return;
684 }
685
686 if (!strcmp(token, "httpscript")) {
687 cs_strncpy(cfg->http_script, value, sizeof(cfg->http_script));
688 return;
689 }
690
691 if (!strcmp(token, "httptpl")) {
692 cfg->http_tpl[0] = '\0';
693 cs_strncpy(cfg->http_tpl, value, sizeof(cfg->http_tpl));
694 if(strlen(value) != 0) {
695 if(strlen(cfg->http_tpl) < (sizeof(cfg->http_tpl)-2) && cfg->http_tpl[strlen(cfg->http_tpl)-1] != '/') {
696 cfg->http_tpl[strlen(cfg->http_tpl)] = '/';
697 cfg->http_tpl[strlen(cfg->http_tpl)] = '\0';
698 }
699 }
700 return;
701 }
702
703 if (!strcmp(token, "httprefresh")) {
704 if(strlen(value) == 0) {
705 cfg->http_refresh = 0;
706 return;
707 } else {
708 cfg->http_refresh = atoi(value);
709 return;
710 }
711 }
712
713 if (!strcmp(token, "httphideidleclients")) {
714 if(strlen(value) == 0) {
715 cfg->http_hide_idle_clients = 0;
716 return;
717 } else {
718 cfg->http_hide_idle_clients = atoi(value);
719 return;
720 }
721 }
722
723 if (!strcmp(token, "httpallowed")) {
724 if(strlen(value) == 0) {
725 clear_sip(&cfg->http_allowed);
726 return;
727 } else {
728 chk_iprange(value, &cfg->http_allowed);
729 return;
730 }
731 }
732
733 if (!strcmp(token, "httpreadonly")) {
734 if(strlen(value) == 0) {
735 cfg->http_readonly = 0;
736 return;
737 } else {
738 cfg->http_readonly = atoi(value);
739 return;
740 }
741 }
742
743 if (!strcmp(token, "httpdyndns")) {
744 cs_strncpy((char *)cfg->http_dyndns, value, sizeof(cfg->http_dyndns));
745 return;
746 }
747
748 if (token[0] != '#')
749 fprintf(stderr, "Warning: keyword '%s' in webif section not recognized\n",token);
750}
751#endif
752
753
754void chk_t_camd33(char *token, char *value)
755{
756 if (!strcmp(token, "port")) {
757 if(strlen(value) == 0) {
758 cfg->c33_port = 0;
759 return;
760 } else {
761 cfg->c33_port = atoi(value);
762 return;
763 }
764 }
765
766 if (!strcmp(token, "serverip")) {
767 if(strlen(value) == 0) {
768 cfg->c33_srvip = 0;
769 return;
770 } else {
771 cfg->c33_srvip = inet_addr(value);
772 return;
773 }
774 }
775
776 if (!strcmp(token, "nocrypt")) {
777 if(strlen(value) == 0) {
778 return;
779 } else {
780 chk_iprange(value, &cfg->c33_plain);
781 return;
782 }
783 }
784
785 if (!strcmp(token, "passive")) {
786 cfg->c33_passive = (value[0]!='0');
787 return;
788 }
789
790 if (!strcmp(token, "key")) {
791 if (key_atob(value, cfg->c33_key)) {
792 fprintf(stderr, "Configuration camd3.3x: Error in Key\n");
793 exit(1);
794 }
795 cfg->c33_crypted=1;
796 return;
797 }
798
799 if (token[0] != '#')
800 fprintf(stderr, "Warning: keyword '%s' in camd33 section not recognized\n",token);
801}
802
803void chk_t_camd35(char *token, char *value)
804{
805 if (!strcmp(token, "port")) {
806 if(strlen(value) == 0) {
807 cfg->c35_port = 0;
808 return;
809 } else {
810 cfg->c35_port = atoi(value);
811 return;
812 }
813 }
814
815 if (!strcmp(token, "serverip")) {
816 if(strlen(value) == 0) {
817 cfg->c35_tcp_srvip = 0;
818 return;
819 } else {
820 cfg->c35_tcp_srvip = inet_addr(value);
821 return;
822 }
823 }
824
825 if (!strcmp(token, "suppresscmd08")) {
826 if(strlen(value) == 0) {
827 cfg->c35_suppresscmd08 = 0;
828 return;
829 } else {
830 cfg->c35_suppresscmd08=atoi(value);
831 return;
832 }
833 }
834
835 if (token[0] != '#')
836 fprintf(stderr, "Warning: keyword '%s' in camd35 section not recognized\n", token);
837}
838
839void chk_t_camd35_tcp(char *token, char *value)
840{
841 if (!strcmp(token, "port")) {
842 if(strlen(value) == 0) {
843 clear_ptab(&cfg->c35_tcp_ptab);
844 return;
845 } else {
846 chk_port_tab(value, &cfg->c35_tcp_ptab);
847 return;
848 }
849 }
850
851 if (!strcmp(token, "serverip")) {
852 if(strlen(value) == 0) {
853 cfg->c35_tcp_srvip = 0;
854 return;
855 } else {
856 cfg->c35_tcp_srvip = inet_addr(value);
857 return;
858 }
859 }
860
861 if (!strcmp(token, "suppresscmd08")) {
862 if(strlen(value) == 0) {
863 cfg->c35_suppresscmd08 = 0;
864 return;
865 } else {
866 cfg->c35_suppresscmd08 = atoi(value);
867 return;
868 }
869 }
870
871 if (token[0] != '#')
872 fprintf(stderr, "Warning: keyword '%s' in camd35 tcp section not recognized\n", token);
873}
874
875void chk_t_newcamd(char *token, char *value)
876{
877 if (!strcmp(token, "port")) {
878 if(strlen(value) == 0) {
879 clear_ptab(&cfg->ncd_ptab);
880 return;
881 } else {
882 chk_port_tab(value, &cfg->ncd_ptab);
883 return;
884 }
885 }
886
887 if (!strcmp(token, "serverip")) {
888 if(strlen(value) == 0) {
889 cfg->ncd_srvip = 0;
890 return;
891 } else {
892 cfg->ncd_srvip = inet_addr(value);
893 return;
894 }
895 }
896
897 if (!strcmp(token, "allowed")) {
898 if(strlen(value) == 0) {
899 clear_sip(&cfg->ncd_allowed);
900 return;
901 } else {
902 chk_iprange(value, &cfg->ncd_allowed);
903 return;
904 }
905 }
906
907 if (!strcmp(token, "key")) {
908 if (key_atob14(value, cfg->ncd_key)) {
909 fprintf(stderr, "Configuration newcamd: Error in Key\n");
910 exit(1);
911 }
912 return;
913 }
914
915 if (!strcmp(token, "keepalive")) {
916 if(strlen(value) == 0) {
917 cfg->ncd_keepalive = 1;
918 return;
919 } else {
920 cfg->ncd_keepalive = atoi(value);
921 return;
922 }
923 }
924
925 if (token[0] != '#')
926 fprintf(stderr, "Warning: keyword '%s' in newcamd section not recognized\n", token);
927}
928
929void chk_t_cccam(char *token, char *value)
930{
931 if (!strcmp(token, "port")) {
932 if(strlen(value) == 0) {
933 cfg->cc_port = 0;
934 return;
935 } else {
936 cfg->cc_port = atoi(value);
937 return;
938 }
939 }
940 //if (!strcmp(token, "serverip")) { cfg->cc_srvip=inet_addr(value); return; }
941
942 if (!strcmp(token, "reshare")) {
943 if(strlen(value) == 0) {
944 cfg->cc_reshare = 0;
945 return;
946 } else {
947 cfg->cc_reshare=atoi(value);
948 return;
949 }
950 }
951 // cccam version
952 if (!strcmp(token, "version")) {
953 if (strlen(value) > sizeof(cfg->cc_version) - 1) {
954 fprintf(stderr, "cccam config: version too long\n");
955 exit(1);
956 }
957 memset(cfg->cc_version, 0, sizeof(cfg->cc_version));
958 strncpy((char*)cfg->cc_version, value, sizeof(cfg->cc_version) - 1);
959 return;
960 }
961 // cccam build number
962 if (!strcmp(token, "build")) {
963 if (strlen(value) > sizeof(cfg->cc_build) - 1) {
964 fprintf(stderr, "cccam config build number too long\n");
965 exit(1);
966 }
967 memset(cfg->cc_build, 0, sizeof(cfg->cc_build));
968 strncpy((char*)cfg->cc_build, value, sizeof(cfg->cc_build)-1);
969 return;
970 }
971
972 if (token[0] != '#')
973 fprintf(stderr, "Warning: keyword '%s' in cccam section not recognized\n",token);
974}
975
976void chk_t_radegast(char *token, char *value)
977{
978 if (!strcmp(token, "port")) {
979 if(strlen(value) == 0) {
980 cfg->rad_port = 0;
981 return;
982 } else {
983 cfg->rad_port = atoi(value);
984 return;
985 }
986 }
987
988 if (!strcmp(token, "serverip")) {
989 if(strlen(value) == 0) {
990 cfg->rad_srvip = 0;
991 return;
992 } else {
993 cfg->rad_srvip = inet_addr(value);
994 return;
995 }
996 }
997
998 if (!strcmp(token, "allowed")) {
999 if(strlen(value) == 0) {
1000 clear_sip(&cfg->rad_allowed);
1001 return;
1002 } else {
1003 chk_iprange(value, &cfg->rad_allowed);
1004 return;
1005 }
1006 }
1007
1008 if (!strcmp(token, "user")) {
1009 cs_strncpy(cfg->rad_usr, value, sizeof(cfg->rad_usr));
1010 return;
1011 }
1012
1013 if (token[0] != '#')
1014 fprintf(stderr, "Warning: keyword '%s' in radegast section not recognized\n", token);
1015}
1016
1017void chk_t_serial(char *token, char *value)
1018{
1019 if (!strcmp(token, "device")) {
1020 int l;
1021 l = strlen(cfg->ser_device);
1022 if (l)
1023 cfg->ser_device[l++]=1; // use ctrl-a as delimiter
1024 cs_strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-l);
1025 return;
1026 }
1027 if (token[0] != '#')
1028 fprintf(stderr, "Warning: keyword '%s' in serial section not recognized\n", token);
1029}
1030
1031#ifdef CS_WITH_GBOX
1032static void chk_t_gbox(char *token, char *value)
1033{
1034 //if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
1035 if (!strcmp(token, "password")) {
1036 cs_atob(cfg->gbox_pwd, value, 4);
1037 return;
1038 }
1039
1040 if (!strcmp(token, "maxdist")) {
1041 cfg->maxdist=atoi(value);
1042 return;
1043 }
1044
1045 if (!strcmp(token, "ignorelist")) {
1046 cs_strncpy((char *)cfg->ignorefile, value, sizeof(cfg->ignorefile));
1047 return;
1048 }
1049
1050 if (!strcmp(token, "onlineinfos")) {
1051 cs_strncpy((char *)cfg->gbxShareOnl, value, sizeof(cfg->gbxShareOnl));
1052 return;
1053 }
1054
1055 if (!strcmp(token, "cardinfos")) {
1056 cs_strncpy((char *)cfg->cardfile, value, sizeof(cfg->cardfile));
1057 return;
1058 }
1059
1060 if (!strcmp(token, "locals"))
1061 {
1062 char *ptr1;
1063 int n = 0, i;
1064 for (i = 0, ptr1 = strtok(value, ","); (i < CS_MAXLOCALS) && (ptr1); ptr1 = strtok(NULL, ",")) {
1065 cfg->locals[n++] = a2i(ptr1, 8);
1066 //printf("%i %08X",n,cfg->locals[n-1]);
1067 }
1068 cfg->num_locals = n;
1069 return;
1070 }
1071
1072 if (token[0] != '#')
1073 fprintf(stderr, "Warning: keyword '%s' in gbox section not recognized\n",token);
1074}
1075#endif
1076
1077#ifdef HAVE_DVBAPI
1078void chk_t_dvbapi(char *token, char *value)
1079{
1080 if (!strcmp(token, "enabled")) {
1081 cfg->dvbapi_enabled = atoi(value);
1082 return;
1083 }
1084
1085 if (!strcmp(token, "au")) {
1086 cfg->dvbapi_au = atoi(value);
1087 return;
1088 }
1089
1090 if (!strcmp(token, "boxtype")) {
1091 cs_strncpy(cfg->dvbapi_boxtype, value, sizeof(cfg->dvbapi_boxtype));
1092 return;
1093 }
1094
1095 if (!strcmp(token, "user")) {
1096 cs_strncpy(cfg->dvbapi_usr, value, sizeof(cfg->dvbapi_usr));
1097 return;
1098 }
1099
1100 if (!strcmp(token, "priority")) {
1101 cs_strncpy(cfg->dvbapi_priority, value, sizeof(cfg->dvbapi_priority));
1102 return;
1103 }
1104
1105 if (!strcmp(token, "ignore")) {
1106 cs_strncpy(cfg->dvbapi_ignore, value, sizeof(cfg->dvbapi_ignore));
1107 return;
1108 }
1109
1110 if (token[0] != '#')
1111 fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token);
1112}
1113#endif
1114
1115static void chk_token(char *token, char *value, int tag)
1116{
1117 switch(tag) {
1118 case TAG_GLOBAL : chk_t_global(token, value); break;
1119 case TAG_MONITOR : chk_t_monitor(token, value); break;
1120 case TAG_CAMD33 : chk_t_camd33(token, value); break;
1121 case TAG_CAMD35 :
1122 case TAG_CS357X : chk_t_camd35(token, value); break;
1123 case TAG_NEWCAMD : chk_t_newcamd(token, value); break;
1124 case TAG_RADEGAST: chk_t_radegast(token, value); break;
1125 case TAG_SERIAL : chk_t_serial(token, value); break;
1126 case TAG_CS378X : chk_t_camd35_tcp(token, value); break;
1127 case TAG_CCCAM : chk_t_cccam(token, value); break;
1128
1129#ifdef CS_WITH_GBOX
1130 case TAG_GBOX : chk_t_gbox(token, value); break;
1131#else
1132 case TAG_GBOX : fprintf(stderr, "Warning: OSCam compiled without gbox support.\n"); break;
1133#endif
1134
1135
1136#ifdef HAVE_DVBAPI
1137 case TAG_DVBAPI : chk_t_dvbapi(token, value); break;
1138#else
1139 case TAG_DVBAPI : fprintf(stderr, "Warning: OSCam compiled without DVB API support.\n"); break;
1140#endif
1141
1142
1143#ifdef WEBIF
1144 case TAG_WEBIF : chk_t_webif(token, value); break;
1145#else
1146 case TAG_WEBIF : fprintf(stderr, "Warning: OSCam compiled without Webinterface support.\n"); break;
1147#endif
1148
1149
1150#ifdef CS_ANTICASC
1151 case TAG_ANTICASC: chk_t_ac(token, value); break;
1152#else
1153 case TAG_ANTICASC: fprintf(stderr, "Warning: OSCam compiled without anticascading support.\n"); break;
1154#endif
1155
1156 }
1157}
1158
1159void init_len4caid()
1160{
1161 int nr;
1162 FILE *fp;
1163 char *value;
1164
1165 memset(len4caid, 0, sizeof(ushort)<<8);
1166 sprintf(token, "%s%s", cs_confdir, cs_l4ca);
1167 if (!(fp = fopen(token, "r")))
1168 return;
1169 for(nr = 0; fgets(token, sizeof(token), fp);) {
1170 int i, c;
1171 char *ptr;
1172 if (!(value=strchr(token, ':')))
1173 continue;
1174 *value++ ='\0';
1175 if( (ptr = strchr(value, '#')) )
1176 *ptr = '\0';
1177 if (strlen(trim(token)) != 2)
1178 continue;
1179 if (strlen(trim(value)) != 4)
1180 continue;
1181 if ((i = byte_atob(token)) < 0)
1182 continue;
1183 if ((c = word_atob(value)) < 0)
1184 continue;
1185 len4caid[i] = c;
1186 nr++;
1187 }
1188 fclose(fp);
1189 cs_log("%d lengths for caid guessing loaded", nr);
1190 return;
1191}
1192
1193int search_boxkey(ushort caid, char *key)
1194{
1195 int i, rc = 0;
1196 FILE *fp;
1197 char c_caid[512];
1198
1199 sprintf(c_caid, "%s%s", cs_confdir, cs_cert);
1200 fp = fopen(c_caid, "r");
1201 if (fp) {
1202 for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);) {
1203 char *c_provid, *c_key;
1204
1205 c_provid = strchr(c_caid, '#');
1206 if (c_provid)
1207 *c_provid = '\0';
1208 if (!(c_provid = strchr(c_caid, ':')))
1209 continue;
1210 *c_provid++ ='\0';
1211 if (!(c_key = strchr(c_provid, ':')))
1212 continue;
1213 *c_key++ ='\0';
1214 if (word_atob(trim(c_caid))!=caid)
1215 continue;
1216 if ((i=(strlen(trim(c_key))>>1)) > 256)
1217 continue;
1218 if (cs_atob((uchar *)key, c_key, i) < 0) {
1219 cs_log("wrong key in \"%s\"", cs_cert);
1220 continue;
1221 }
1222 rc = 1;
1223 }
1224 fclose(fp);
1225 }
1226#ifdef OSCAM_INBUILD_KEYS
1227 for(i=0; (!rc) && (npkey[i].keylen); i++)
1228 if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0)))
1229 memcpy(key, npkey[i].key, npkey[i].keylen);
1230#endif
1231 return(rc);
1232}
1233
1234int init_config()
1235{
1236 int tag=TAG_GLOBAL;
1237 FILE *fp;
1238 char *value;
1239
1240#ifndef CS_EMBEDDED
1241#ifdef PRIO_PROCESS
1242 errno=0;
1243 if ((cfg->nice = getpriority(PRIO_PROCESS, 0)) == (-1))
1244 if (errno)
1245#endif
1246#endif
1247 cfg->nice = 99;
1248 cfg->ctimeout = CS_CLIENT_TIMEOUT;
1249 cfg->ftimeout = CS_CLIENT_TIMEOUT / 2;
1250 cfg->cmaxidle = CS_CLIENT_MAXIDLE;
1251 cfg->delay = CS_DELAY;
1252 cfg->bindwait = CS_BIND_TIMEOUT;
1253 cfg->resolvedelay = CS_RESOLVE_DELAY;
1254 cfg->mon_level = 2;
1255 cfg->mon_hideclient_to = 0;
1256 cfg->srtimeout = 1500;
1257 cfg->ulparent = 0;
1258 cfg->logfile = NULL;
1259 cfg->pidfile = NULL;
1260 cfg->usrfile = NULL;
1261 cfg->cwlogdir = NULL;
1262#ifdef WEBIF
1263 strcpy(cfg->http_user, "");
1264 strcpy(cfg->http_pwd, "");
1265 strcpy(cfg->http_css, "");
1266 cfg->http_refresh = 0;
1267 cfg->http_hide_idle_clients = 0;
1268 strcpy(cfg->http_tpl, "");
1269#endif
1270 cfg->ncd_keepalive = 1;
1271#ifdef CS_ANTICASC
1272 cfg->ac_enabled = 0;
1273 cfg->ac_users = 0;
1274 cfg->ac_stime = 2;
1275 cfg->ac_samples = 10;
1276 cfg->ac_denysamples = 8;
1277 cfg->ac_fakedelay = 1000;
1278 strcpy(cfg->ac_logfile, "./oscam_ac.log");
1279#endif
1280 sprintf(token, "%s%s", cs_confdir, cs_conf);
1281 if (!(fp = fopen(token, "r"))) {
1282 fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno);
1283 exit(1);
1284 }
1285 while (fgets(token, sizeof(token), fp)) {
1286 int i, l;
1287 //void *ptr;
1288 if ((l = strlen(trim(token))) < 3)
1289 continue;
1290 if ((token[0] == '[') && (token[l-1] == ']')) {
1291 for (token[l-1] = 0, tag = -1, i = TAG_GLOBAL; cctag[i]; i++)
1292 if (!strcmp(cctag[i], strtolower(token+1)))
1293 tag = i;
1294 continue;
1295 }
1296 if (!(value=strchr(token, '=')))
1297 continue;
1298 *value++ ='\0';
1299 chk_token(trim(strtolower(token)), trim(value), tag);
1300 }
1301 fclose(fp);
1302#ifdef CS_LOGFILE
1303 if (cfg->logfile == NULL)
1304 asprintf(&(cfg->logfile), "%s", CS_LOGFILE);
1305#endif
1306 cs_init_log(cfg->logfile);
1307 if (cfg->ftimeout >= cfg->ctimeout) {
1308 cfg->ftimeout = cfg->ctimeout - 100;
1309 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout);
1310 }
1311 if(cfg->ftimeout < cfg->srtimeout) {
1312 cfg->ftimeout = cfg->srtimeout + 100;
1313 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout);
1314 }
1315 if(cfg->ctimeout < cfg->srtimeout) {
1316 cfg->ctimeout = cfg->srtimeout + 100;
1317 cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout);
1318 }
1319#ifdef CS_ANTICASC
1320 if( cfg->ac_denysamples+1 > cfg->ac_samples ) {
1321 cfg->ac_denysamples = cfg->ac_samples - 1;
1322 cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples);
1323 }
1324#endif
1325 return 0;
1326}
1327
1328void chk_account(char *token, char *value, struct s_auth *account)
1329{
1330 int i;
1331 char *ptr1;
1332
1333 if (!strcmp(token, "user")) {
1334 cs_strncpy(account->usr, value, sizeof(account->usr));
1335 return;
1336 }
1337
1338 if (!strcmp(token, "pwd")) {
1339 cs_strncpy(account->pwd, value, sizeof(account->pwd));
1340 return;
1341 }
1342
1343 if (!strcmp(token, "hostname")) {
1344 cs_strncpy((char *)account->dyndns, value, sizeof(account->dyndns));
1345 return;
1346 }
1347
1348 if (!strcmp(token, "betatunnel")) {
1349 if(strlen(value) == 0) {
1350 clear_tuntab(&account->ttab);
1351 return;
1352 } else {
1353 chk_tuntab(value, &account->ttab);
1354 return;
1355 }
1356 }
1357
1358 if (!strcmp(token, "uniq")) {
1359 if(strlen(value) == 0) {
1360 account->uniq = 0;
1361 return;
1362 } else {
1363 account->uniq = atoi(value);
1364 return;
1365 }
1366 }
1367
1368 if (!strcmp(token, "sleep")) {
1369 if(strlen(value) == 0) {
1370 account->tosleep = 0;
1371 return;
1372 } else {
1373 account->tosleep=atoi(value);
1374 return;
1375 }
1376 }
1377
1378 if (!strcmp(token, "monlevel")) {
1379 if(strlen(value) == 0) {
1380 account->monlvl = 0;
1381 return;
1382 } else {
1383 account->monlvl = atoi(value);
1384 return;
1385 }
1386 }
1387
1388 if (!strcmp(token, "caid")) {
1389 if(strlen(value) == 0) {
1390 clear_caidtab(&account->ctab);
1391 return;
1392 } else {
1393 chk_caidtab(value, &account->ctab);
1394 return;
1395 }
1396 }
1397
1398 if (!strcmp(token, "disabled")) {
1399 if(strlen(value) == 0) {
1400 account->disabled = 0;
1401 return;
1402 } else {
1403 account->disabled = atoi(value);
1404 return;
1405 }
1406 }
1407
1408 if (!strcmp(token, "suppresscmd08")) {
1409 if(strlen(value) == 0) {
1410 account->c35_suppresscmd08 = 0;
1411 return;
1412 } else {
1413 account->c35_suppresscmd08=atoi(value);
1414 return;
1415 }
1416 }
1417
1418 if (!strcmp(token, "keepalive")) {
1419 if(strlen(value) == 0) {
1420 account->ncd_keepalive = 1;
1421 return;
1422 } else {
1423 account->ncd_keepalive = atoi(value);
1424 return;
1425 }
1426 }
1427 /*
1428 * case insensitive
1429 */
1430 strtolower(value);
1431
1432 if (!strcmp(token, "au")) {
1433 //set default values for usage during runtime from Webif
1434 account->au=-1;
1435 account->autoau=0;
1436
1437 if(value && value[0]=='1') account->autoau=1;
1438 for (i=0; i<CS_MAXREADER; i++)
1439 if ((reader[i].label[0]) && (!strncmp(reader[i].label, value, strlen(reader[i].label))))
1440 account->au=i;
1441 return;
1442 }
1443
1444 if (!strcmp(token, "group")) {
1445 account->grp = 0;
1446 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
1447 int g;
1448 g = atoi(ptr1);
1449 if ((g>0) && (g < 33)) account->grp|=(1<<(g-1));
1450 }
1451 return;
1452 }
1453
1454 if(!strcmp(token, "services")) {
1455 chk_services(value, &account->sidtabok, &account->sidtabno);
1456 return;
1457 }
1458
1459 if(!strcmp(token, "ident")) { /*ToDo ftab clear*/
1460 chk_ftab(value, &account->ftab, "user", account->usr, "provid");
1461 return;
1462 }
1463
1464 if(!strcmp(token, "class")) {
1465 chk_cltab(value, &account->cltab);
1466 return;
1467 }
1468
1469 if(!strcmp(token, "chid")) {
1470 chk_ftab(value, &account->fchid, "user", account->usr, "chid");
1471 return;
1472 }
1473
1474 if (!strcmp(token, "expdate")) {
1475 if (!value[0]) {
1476 account->expirationdate=(time_t)NULL;
1477 return;
1478 }
1479 struct tm cstime;
1480 memset(&cstime,0,sizeof(cstime));
1481 for (i=0, ptr1=strtok(value, "-/"); (i<3)&&(ptr1); ptr1=strtok(NULL, "-/"), i++) {
1482 switch(i) {
1483 case 0: cstime.tm_year=atoi(ptr1)-1900; break;
1484 case 1: cstime.tm_mon =atoi(ptr1)-1; break;
1485 case 2: cstime.tm_mday=atoi(ptr1); break;
1486 }
1487 }
1488 account->expirationdate=mktime(&cstime);
1489 return;
1490 }
1491
1492#ifdef CS_ANTICASC
1493 if( !strcmp(token, "numusers") ) {
1494 account->ac_users = atoi(value);
1495 return;
1496 }
1497
1498 if( !strcmp(token, "penalty") ) {
1499 account->ac_penalty = atoi(value);
1500 return;
1501 }
1502#endif
1503
1504 if (token[0] != '#')
1505 fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n",token);
1506}
1507
1508int write_services()
1509{
1510 int i;
1511 FILE *f;
1512 struct s_sidtab *sidtab = cfg->sidtab;
1513 char tmpfile[256];
1514 char destfile[256];
1515 char bakfile[256];
1516
1517 snprintf(destfile, 255,"%s%s", cs_confdir, cs_sidt);
1518 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_sidt);
1519 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_sidt);
1520
1521 if (!(f=fopen(tmpfile, "w"))){
1522 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
1523 return(1);
1524 }
1525 fprintf(f,"#oscam.services generated automatically\n\n");
1526
1527 while(sidtab != NULL){
1528 fprintf(f,"[%s]\n", sidtab->label);
1529 fprintf_conf(f, CONFVARWIDTH, "caid", "");
1530 for (i=0; i<sidtab->num_caid; i++){
1531 if (i==0) fprintf(f,"%04X", sidtab->caid[i]);
1532 else fprintf(f,",%04X", sidtab->caid[i]);
1533 }
1534 fputc((int)'\n', f);
1535 fprintf_conf(f, CONFVARWIDTH, "provid", "");
1536 for (i=0; i<sidtab->num_provid; i++){
1537 if (i==0) fprintf(f,"%06lX", sidtab->provid[i]);
1538 else fprintf(f,",%06lX", sidtab->provid[i]);
1539 }
1540 fputc((int)'\n', f);
1541 fprintf_conf(f, CONFVARWIDTH, "srvid", "");
1542 for (i=0; i<sidtab->num_srvid; i++){
1543 if (i==0) fprintf(f,"%04X", sidtab->srvid[i]);
1544 else fprintf(f,",%04X", sidtab->srvid[i]);
1545 }
1546 fprintf(f,"\n\n");
1547 sidtab=sidtab->next;
1548 }
1549
1550 fclose(f);
1551 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
1552}
1553
1554int write_config()
1555{
1556 int i,j;
1557 FILE *f;
1558 char *dot = "", *dot1 = "", *dot2 = ""; //flags for delimiters
1559 char tmpfile[256];
1560 char destfile[256];
1561 char bakfile[256];
1562
1563 snprintf(destfile, 255,"%s%s", cs_confdir, cs_conf);
1564 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_conf);
1565 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_conf);
1566
1567 if (!(f=fopen(tmpfile, "w"))){
1568 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
1569 return(1);
1570 }
1571 fprintf(f,"#oscam.config generated automatically\n\n");
1572
1573 /*global settings*/
1574 fprintf(f,"[global]\n");
1575 if (cfg->srvip != 0)
1576 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->srvip));
1577 if (cfg->pidfile != NULL) fprintf_conf(f, CONFVARWIDTH, "pidfile", "%s\n", cfg->pidfile);
1578 if (cfg->usrfile != NULL) fprintf_conf(f, CONFVARWIDTH, "usrfile", "%s\n", cfg->usrfile);
1579 if (cfg->logfile != NULL) fprintf_conf(f, CONFVARWIDTH, "logfile", "%s\n", cfg->logfile);
1580 if (cfg->cwlogdir != NULL) fprintf_conf(f, CONFVARWIDTH, "cwlogdir", "%s\n", cfg->cwlogdir);
1581 fprintf_conf(f, CONFVARWIDTH, "disablelog", "%d\n", cfg->disablelog);
1582 fprintf_conf(f, CONFVARWIDTH, "disableuserfile", "%d\n", cfg->disableuserfile);
1583 fprintf_conf(f, CONFVARWIDTH, "usrfileflag", "%d\n", cfg->usrfileflag);
1584 fprintf_conf(f, CONFVARWIDTH, "clienttimeout", "%ld\n", cfg->ctimeout);
1585 fprintf_conf(f, CONFVARWIDTH, "fallbacktimeout", "%ld\n", cfg->ftimeout);
1586 fprintf_conf(f, CONFVARWIDTH, "clientmaxidle", "%d\n", cfg->cmaxidle);
1587 fprintf_conf(f, CONFVARWIDTH, "cachedelay", "%ld\n", cfg->delay);
1588 fprintf_conf(f, CONFVARWIDTH, "bindwait", "%d\n", cfg->bindwait);
1589 fprintf_conf(f, CONFVARWIDTH, "netprio", "%ld\n", cfg->netprio);
1590 fprintf_conf(f, CONFVARWIDTH, "resolvedelay", "%d\n", cfg->resolvedelay);
1591 if (cfg->tosleep) fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", cfg->tosleep);
1592 fprintf_conf(f, CONFVARWIDTH, "unlockparental", "%d\n", cfg->ulparent);
1593 fprintf_conf(f, CONFVARWIDTH, "nice", "%d\n", cfg->nice);
1594 fprintf_conf(f, CONFVARWIDTH, "serialreadertimeout", "%d\n", cfg->srtimeout);
1595 fprintf_conf(f, CONFVARWIDTH, "maxlogsize", "%d\n", cfg->max_log_size);
1596 fprintf_conf(f, CONFVARWIDTH, "waitforcards", "%d\n", cfg->waitforcards);
1597 fprintf_conf(f, CONFVARWIDTH, "preferlocalcards", "%d\n", cfg->preferlocalcards);
1598 fputc((int)'\n', f);
1599
1600 /*monitor settings*/
1601 fprintf(f,"[monitor]\n");
1602 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->mon_port);
1603 if (cfg->mon_srvip != 0)
1604 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
1605
1606 fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
1607 struct s_ip *cip;
1608 for (cip = cfg->mon_allowed; cip; cip = cip->next){
1609 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
1610 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
1611 dot=",";
1612 }
1613 fputc((int)'\n', f);
1614 fprintf_conf(f, CONFVARWIDTH, "aulow", "%d\n", cfg->mon_aulow);
1615 fprintf_conf(f, CONFVARWIDTH, "hideclient_to", "%d\n", cfg->mon_hideclient_to);
1616 fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", cfg->mon_level);
1617 fprintf_conf(f, CONFVARWIDTH, "appendchaninfo", "%d\n", cfg->mon_appendchaninfo);
1618 fputc((int)'\n', f);
1619
1620 /*newcamd*/
1621 if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
1622 fprintf(f,"[newcamd]\n");
1623 fprintf_conf(f, CONFVARWIDTH, "port", "");
1624 dot1 = "";
1625 for(i = 0; i < cfg->ncd_ptab.nports; ++i){
1626 fprintf(f,"%s%d@%04X", dot1, cfg->ncd_ptab.ports[i].s_port, cfg->ncd_ptab.ports[i].ftab.filts[0].caid);
1627 if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){
1628 fprintf(f,":");
1629 dot2 = "";
1630 for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){
1631 fprintf(f,"%s%06X", dot2, (int)cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
1632 dot2 = ",";
1633 }
1634 }
1635 dot1=";";
1636 }
1637
1638 fputc((int)'\n', f);
1639 if (cfg->ncd_srvip != 0)
1640 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
1641 fprintf_conf(f, CONFVARWIDTH, "key", "");
1642 for (i=0;i<14;i++) fprintf(f,"%02X", cfg->ncd_key[i]);
1643 fprintf(f,"\n");
1644 fprintf_conf(f, CONFVARWIDTH, "allowed", "");
1645 struct s_ip *cip;
1646 dot="";
1647 for (cip = cfg->ncd_allowed; cip; cip = cip->next){
1648 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
1649 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
1650 dot=",";
1651 }
1652 fprintf(f,"\n");
1653 fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", cfg->ncd_keepalive);
1654 fprintf(f,"\n");
1655 }
1656
1657 /*camd3.3*/
1658 if ( cfg->c33_port > 0) {
1659 fprintf(f,"[camd33]\n");
1660 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c33_port);
1661 if (cfg->c33_srvip != 0)
1662 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
1663 fprintf_conf(f, CONFVARWIDTH, "passive", "%d\n", cfg->c33_passive);
1664 fprintf_conf(f, CONFVARWIDTH, "key", ""); for (i = 0; i < (int) sizeof(cfg->c33_key); ++i) fprintf(f,"%02X", cfg->c33_key[i]); fputc((int)'\n', f);
1665 fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
1666 dot="";
1667 for (cip = cfg->c33_plain; cip; cip = cip->next){
1668 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
1669 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
1670 dot=",";
1671 }
1672 fprintf(f,"\n\n");
1673 }
1674
1675 /*camd3.5*/
1676 if ( cfg->c35_port > 0) {
1677 fprintf(f,"[cs357x]\n");
1678 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c35_port);
1679 if (cfg->c35_tcp_srvip != 0)
1680 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
1681 if (cfg->c35_suppresscmd08)
1682 fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", cfg->c35_suppresscmd08);
1683 fprintf(f,"\n");
1684 }
1685
1686 /*camd3.5 TCP*/
1687 if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)) {
1688 fprintf(f,"[cs378x]\n");
1689 fprintf_conf(f, CONFVARWIDTH, "port", "");
1690 dot1 = "";
1691 for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){
1692 fprintf(f,"%s%d@%04X", dot1, cfg->c35_tcp_ptab.ports[i].s_port, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].caid);
1693 if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 0){
1694 fprintf(f,":");
1695 dot2 = "";
1696 for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){
1697 fprintf(f,"%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
1698 dot2 = ",";
1699 }
1700 }
1701 dot1=";";
1702 }
1703
1704 fputc((int)'\n', f);
1705 if (cfg->c35_tcp_srvip != 0)
1706 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
1707 fputc((int)'\n', f);
1708 }
1709
1710 /*Radegast*/
1711 if ( cfg->rad_port > 0) {
1712 fprintf(f,"[radegast]\n");
1713 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->rad_port);
1714 if (cfg->rad_srvip != 0)
1715 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
1716 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->rad_usr);
1717 fprintf_conf(f, CONFVARWIDTH, "allowed", "");
1718 struct s_ip *cip;
1719 for (cip = cfg->rad_allowed; cip; cip = cip->next){
1720 fprintf(f,"%s%s", dot, inet_ntoa(*(struct in_addr *)&cip->ip[0]));
1721 if (cip->ip[0] == cip->ip[1]) fprintf(f,"-%s", inet_ntoa(*(struct in_addr *)&cip->ip[1]));
1722 dot=",";
1723 }
1724 fprintf(f,"\n\n");
1725 }
1726
1727#ifdef CS_WITH_GBOX
1728 /*Gbox*/
1729 if ((cfg->gbox_pwd[0] > 0) || (cfg->gbox_pwd[1] > 0) || (cfg->gbox_pwd[2] > 0) || (cfg->gbox_pwd[3] > 0)){
1730 fprintf(f,"[gbox]\n");
1731 fprintf_conf(f, CONFVARWIDTH, "password", ""); for (i=0;i<4;i++) fprintf(f,"%02X", cfg->gbox_pwd[i]); fputc((int)'\n', f);;
1732 fprintf_conf(f, CONFVARWIDTH, "maxdist", "%d\n", cfg->maxdist);
1733 fprintf_conf(f, CONFVARWIDTH, "ignorelist", "%s\n", cfg->ignorefile);
1734 fprintf_conf(f, CONFVARWIDTH, "onlineinfos", "%s\n", cfg->gbxShareOnl);
1735 fprintf_conf(f, CONFVARWIDTH, "cardinfos", "%s\n", cfg->cardfile);
1736 fprintf_conf(f, CONFVARWIDTH, "locals", "");
1737 char *dot = "";
1738 for (i = 0; i < cfg->num_locals; i++){
1739 fprintf(f,"%s%06lX", dot, cfg->locals[i]);
1740 dot=";";
1741 }
1742 fprintf(f,"\n\n");
1743 }
1744#endif
1745
1746 /*serial*/
1747
1748
1749 /*cccam*/
1750 if ( cfg->cc_port > 0) {
1751 fprintf(f,"[cccam]\n");
1752 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->cc_port);
1753 fprintf_conf(f, CONFVARWIDTH, "reshare", "%d\n", cfg->cc_reshare);
1754 fprintf_conf(f, CONFVARWIDTH, "version", "%s\n", cfg->cc_version);
1755 fprintf_conf(f, CONFVARWIDTH, "build", "%s\n", cfg->cc_build);
1756 fprintf(f,"\n");
1757 }
1758
1759#ifdef HAVE_DVBAPI
1760 /*dvb-api*/
1761 if (cfg->dvbapi_enabled > 0) {
1762 fprintf(f,"[dvbapi]\n");
1763 fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->dvbapi_enabled);
1764 fprintf_conf(f, CONFVARWIDTH, "au", "%d\n", cfg->dvbapi_au);
1765 fprintf_conf(f, CONFVARWIDTH, "boxtype", "%s\n", cfg->dvbapi_boxtype);
1766 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->dvbapi_usr);
1767 fputc((int)'\n', f);
1768 }
1769#endif
1770
1771#ifdef WEBIF
1772 /*webinterface*/
1773 if (cfg->http_port > 0) {
1774 fprintf(f,"[webif]\n");
1775 fprintf_conf(f, CONFVARWIDTH, "httpport", "%d\n", cfg->http_port);
1776 fprintf_conf(f, CONFVARWIDTH, "httpuser", "%s\n", cfg->http_user);
1777 fprintf_conf(f, CONFVARWIDTH, "httppwd", "%s\n", cfg->http_pwd);
1778 fprintf_conf(f, CONFVARWIDTH, "httpcss", "%s\n", cfg->http_css);
1779 fprintf_conf(f, CONFVARWIDTH, "httptpl", "%s\n", cfg->http_tpl);
1780 fprintf_conf(f, CONFVARWIDTH, "httpscript", "%s\n", cfg->http_script);
1781 fprintf_conf(f, CONFVARWIDTH, "httprefresh", "%d\n", cfg->http_refresh);
1782 fprintf_conf(f, CONFVARWIDTH, "httpallowed", "");
1783 dot = "";
1784 for (cip = cfg->http_allowed; cip; cip = cip->next){
1785 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
1786 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
1787 dot = ",";
1788 }
1789 fputc((int)'\n', f);
1790 fprintf_conf(f, CONFVARWIDTH, "httpdyndns", "%s\n", cfg->http_dyndns);
1791 fprintf_conf(f, CONFVARWIDTH, "httphideidleclients", "%d\n", cfg->http_hide_idle_clients);
1792 fprintf_conf(f, CONFVARWIDTH, "httpreadonly", "%d\n", cfg->http_readonly);
1793 fputc((int)'\n', f);
1794 }
1795#endif
1796
1797#ifdef CS_ANTICASC
1798 fprintf(f,"[anticasc]\n");
1799 fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->ac_enabled);
1800 fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", cfg->ac_users);
1801 fprintf_conf(f, CONFVARWIDTH, "sampletime", "%d\n", cfg->ac_stime);
1802 fprintf_conf(f, CONFVARWIDTH, "samples", "%d\n", cfg->ac_samples);
1803 fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", cfg->ac_penalty);
1804 fprintf_conf(f, CONFVARWIDTH, "aclogfile", "%s\n", cfg->ac_logfile);
1805 fprintf_conf(f, CONFVARWIDTH, "denysamples", "%d\n", cfg->ac_denysamples);
1806 fprintf_conf(f, CONFVARWIDTH, "fakedelay", "%d\n", cfg->ac_fakedelay);
1807 fputc((int)'\n', f);
1808#endif
1809
1810 fclose(f);
1811
1812 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
1813}
1814
1815int write_userdb()
1816{
1817 int i;
1818 FILE *f;
1819 struct s_auth *account;
1820 char *dot = ""; //flag for comma
1821 char tmpfile[256];
1822 char destfile[256];
1823 char bakfile[256];
1824
1825 snprintf(destfile, 255,"%s%s", cs_confdir, cs_user);
1826 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_user);
1827 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_user);
1828
1829 if (!(f=fopen(tmpfile, "w"))){
1830 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
1831 return(1);
1832 }
1833 fprintf(f,"#oscam.user generated automatically\n\n");
1834
1835 //each account
1836 for (account=cfg->account; (account) ; account=account->next){
1837 fprintf(f,"[account]\n");
1838 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", account->usr);
1839 fprintf_conf(f, CONFVARWIDTH, "pwd", "%s\n", account->pwd);
1840 fprintf_conf(f, CONFVARWIDTH, "disabled", "%d\n", account->disabled);
1841 struct tm * timeinfo = localtime (&account->expirationdate);
1842 char buf [80];
1843 strftime (buf,80,"%Y-%m-%d",timeinfo);
1844 if(strcmp(buf,"1970-01-01"))
1845 fprintf_conf(f, CONFVARWIDTH, "expdate", "%s\n", buf);
1846 else
1847 fprintf_conf(f, CONFVARWIDTH, "expdate", "\n");
1848
1849 //group
1850 char *value = mk_t_group((ulong*)account->grp);
1851 fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value);
1852 free(value);
1853
1854 fprintf_conf(f, CONFVARWIDTH, "hostname", "%s\n", account->dyndns);
1855 fprintf_conf(f, CONFVARWIDTH, "uniq", "%d\n", account->uniq);
1856 fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", account->tosleep);
1857 fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", account->monlvl);
1858
1859 if (account->au > -1)
1860 if (account->au < CS_MAXREADER)
1861 fprintf_conf(f, CONFVARWIDTH, "au", "%s\n", reader[account->au].label);
1862 if (account->autoau == 1) fprintf_conf(f, CONFVARWIDTH, "au", "1\n");
1863
1864 fprintf_conf(f, CONFVARWIDTH, "services", "");
1865 char sidok[33]; long2bitchar(account->sidtabok,sidok);
1866 char sidno[33]; long2bitchar(account->sidtabno,sidno);
1867 struct s_sidtab *sidtab = cfg->sidtab;
1868 i=0; dot = "";
1869 for (; sidtab; sidtab=sidtab->next){
1870 if(sidok[i]=='1') {fprintf(f,"%s%s", dot, sidtab->label); dot = ",";}
1871 if(sidno[i]=='1') {fprintf(f,"%s!%s", dot, sidtab->label); dot = ",";}
1872 i++;
1873 }
1874 fputc((int)'\n', f);
1875
1876 //CAID
1877 value = mk_t_caidtab(&account->ctab);
1878 fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value);
1879 free(value);
1880
1881 //betatunnel
1882 value = mk_t_tuntab(&account->ttab);
1883 fprintf_conf(f, CONFVARWIDTH, "betatunnel", "%s\n", value);
1884 free(value);
1885
1886 //ident
1887 value = mk_t_ftab(&account->ftab);
1888 fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value);
1889 free(value);
1890
1891 if (account->c35_suppresscmd08)
1892 fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", account->c35_suppresscmd08);
1893
1894 fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", account->ncd_keepalive);
1895
1896#ifdef CS_ANTICASC
1897 fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", account->ac_users);
1898 fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", account->ac_penalty);
1899#endif
1900 fputc((int)'\n', f);
1901 }
1902 fclose(f);
1903
1904 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
1905}
1906
1907int init_userdb()
1908{
1909 int tag = 0, nr, nro, expired, disabled;
1910 //int first=1;
1911 FILE *fp;
1912 char *value;
1913 struct s_auth *ptr;
1914 /*static */struct s_auth *account=(struct s_auth *)0;
1915
1916 sprintf(token, "%s%s", cs_confdir, cs_user);
1917 if (!(fp = fopen(token, "r"))) {
1918 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
1919 return(1);
1920 }
1921
1922 for (nro = 0, ptr = cfg->account; ptr; nro++) {
1923 struct s_auth *ptr_next;
1924 ptr_next = ptr->next;
1925 free(ptr);
1926 ptr = ptr_next;
1927 }
1928 nr = 0;
1929
1930 while (fgets(token, sizeof(token), fp)) {
1931 int i, l;
1932 void *ptr;
1933
1934 if ((l=strlen(trim(token))) < 3)
1935 continue;
1936
1937 if ((token[0] == '[') && (token[l-1] == ']')) {
1938 token[l - 1] = 0;
1939 tag = (!strcmp("account", strtolower(token + 1)));
1940
1941 if (!(ptr=malloc(sizeof(struct s_auth)))) {
1942 cs_log("Error allocating memory (errno=%d)", errno);
1943 return(1);
1944 }
1945
1946 if (account)
1947 account->next = ptr;
1948 else
1949 cfg->account = ptr;
1950
1951 account = ptr;
1952 memset(account, 0, sizeof(struct s_auth));
1953 account->au = (-1);
1954 account->monlvl = cfg->mon_level;
1955 account->tosleep = cfg->tosleep;
1956 account->c35_suppresscmd08 = cfg->c35_suppresscmd08;
1957 account->ncd_keepalive = cfg->ncd_keepalive;
1958 for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff);
1959 for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000);
1960 nr++;
1961
1962#ifdef CS_ANTICASC
1963 account->ac_users = cfg->ac_users;
1964 account->ac_penalty = cfg->ac_penalty;
1965 account->ac_idx = nr;
1966#endif
1967 continue;
1968 }
1969
1970 if (!tag)
1971 continue;
1972
1973 if (!(value=strchr(token, '=')))
1974 continue;
1975
1976 *value++ = '\0';
1977 chk_account(trim(strtolower(token)), trim(value), account);
1978 }
1979
1980 fclose(fp);
1981
1982 for (expired = 0, disabled = 0, ptr = cfg->account; ptr;) {
1983
1984 if(ptr->expirationdate && ptr->expirationdate < time(NULL))
1985 expired++;
1986
1987 if(ptr->disabled != 0)
1988 disabled++;
1989
1990 ptr = ptr->next;
1991 }
1992
1993 cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled);
1994 return(0);
1995}
1996
1997static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
1998{
1999 int i, b;
2000 char *ptr;
2001 ushort *slist=(ushort *) 0;
2002 ulong *llist=(ulong *) 0;
2003 ulong caid;
2004 char buf[strlen(value) + 1];
2005 cs_strncpy(buf, value, sizeof(buf));
2006 b=(what==1) ? sizeof(ulong) : sizeof(ushort);
2007 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
2008 {
2009 caid=a2i(ptr, b);
2010 if (!errno) i++;
2011 }
2012 //if (!i) return(0);
2013 if (b==sizeof(ushort))
2014 slist=malloc(i*sizeof(ushort));
2015 else
2016 llist=malloc(i*sizeof(ulong));
2017 strcpy(value, buf);
2018 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
2019 {
2020 caid=a2i(ptr, b);
2021 if (errno) continue;
2022 if (b==sizeof(ushort))
2023 slist[i++]=(ushort) caid;
2024 else
2025 llist[i++]=caid;
2026 }
2027 switch (what)
2028 {
2029 case 0: sidtab->caid=slist;
2030 sidtab->num_caid=i;
2031 break;
2032 case 1: sidtab->provid=llist;
2033 sidtab->num_provid=i;
2034 break;
2035 case 2: sidtab->srvid=slist;
2036 sidtab->num_srvid=i;
2037 break;
2038 }
2039}
2040
2041void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
2042{
2043 if (!strcmp(token, "caid")) { chk_entry4sidtab(value, sidtab, 0); return; }
2044 if (!strcmp(token, "provid")) { chk_entry4sidtab(value, sidtab, 1); return; }
2045 if (!strcmp(token, "ident")) { chk_entry4sidtab(value, sidtab, 1); return; }
2046 if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; }
2047 if (token[0] != '#')
2048 fprintf(stderr, "Warning: keyword '%s' in sidtab section not recognized\n",token);
2049}
2050
2051int init_sidtab()
2052{
2053 int nr, nro;
2054 FILE *fp;
2055 char *value;
2056 struct s_sidtab *ptr;
2057 struct s_sidtab *sidtab=(struct s_sidtab *)0;
2058
2059 sprintf(token, "%s%s", cs_confdir, cs_sidt);
2060 if (!(fp=fopen(token, "r")))
2061 {
2062 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
2063 return(1);
2064 }
2065 for (nro=0, ptr=cfg->sidtab; ptr; nro++)
2066 {
2067 struct s_sidtab *ptr_next;
2068 ptr_next=ptr->next;
2069 if (ptr->caid) free(ptr->caid);
2070 if (ptr->provid) free(ptr->provid);
2071 if (ptr->srvid) free(ptr->srvid);
2072 free(ptr);
2073 ptr=ptr_next;
2074 }
2075 nr=0;
2076 while (fgets(token, sizeof(token), fp))
2077 {
2078 int l;
2079 void *ptr;
2080 if ((l=strlen(trim(token)))<3) continue;
2081 if ((token[0]=='[') && (token[l-1]==']'))
2082 {
2083 token[l-1]=0;
2084 if (!(ptr=malloc(sizeof(struct s_sidtab))))
2085 {
2086 cs_log("Error allocating memory (errno=%d)", errno);
2087 return(1);
2088 }
2089 if (sidtab)
2090 sidtab->next=ptr;
2091 else
2092 cfg->sidtab=ptr;
2093 sidtab=ptr;
2094 nr++;
2095 memset(sidtab, 0, sizeof(struct s_sidtab));
2096 cs_strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
2097 continue;
2098 }
2099 if (!sidtab) continue;
2100 if (!(value=strchr(token, '='))) continue;
2101 *value++='\0';
2102 chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
2103 }
2104 fclose(fp);
2105
2106#ifdef DEBUG_SIDTAB
2107 show_sidtab(cfg->sidtab);
2108#endif
2109 cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
2110 return(0);
2111}
2112
2113int init_srvid()
2114{
2115 int nr;
2116 FILE *fp;
2117 char *payload;
2118 static struct s_srvid *srvid=(struct s_srvid *)0;
2119 sprintf(token, "%s%s", cs_confdir, cs_srid);
2120
2121 if (!(fp=fopen(token, "r"))) {
2122 cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
2123 return(0);
2124 }
2125
2126 nr=0;
2127 while (fgets(token, sizeof(token), fp)) {
2128
2129 int l;
2130 void *ptr;
2131 char *tmp;
2132 tmp = trim(token);
2133
2134 if (tmp[0] == '#') continue;
2135 if ((l=strlen(tmp)) < 6) continue;
2136 if (!(payload=strchr(token, '|'))) continue;
2137 *payload++ = '\0';
2138
2139 if (!(ptr = malloc(sizeof(struct s_srvid)))) {
2140 cs_log("Error allocating memory (errno=%d)", errno);
2141 return(1);
2142 }
2143
2144 if (srvid)
2145 srvid->next = ptr;
2146 else
2147 cfg->srvid = ptr;
2148
2149 srvid = ptr;
2150 memset(srvid, 0, sizeof(struct s_srvid));
2151
2152 int i;
2153 char *ptr1;
2154 for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
2155 switch(i){
2156 case 0:
2157 cs_strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov));
2158 break;
2159 case 1:
2160 cs_strncpy(srvid->name, trim(ptr1), sizeof(srvid->name));
2161 break;
2162 case 2:
2163 cs_strncpy(srvid->type, trim(ptr1), sizeof(srvid->type));
2164 break;
2165 case 3:
2166 cs_strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc));
2167 break;
2168 }
2169 }
2170
2171 char *srvidasc = strchr(token, ':');
2172 *srvidasc++ = '\0';
2173 srvid->srvid = word_atob(srvidasc);
2174
2175 srvid->ncaid = 0;
2176 for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
2177 srvid->caid[i] = word_atob(ptr1);
2178 srvid->ncaid = i+1;
2179 //cs_debug("ld caid: %04X srvid: %04X Prov: %s Chan: %s",srvid->caid[i],srvid->srvid,srvid->prov,srvid->name);
2180 }
2181 nr++;
2182 }
2183
2184 fclose(fp);
2185 if (nr>0)
2186 cs_log("%d service-id's loaded", nr);
2187 else{
2188 cs_log("oscam.srvid loading failed, old format");
2189 }
2190 return(0);
2191}
2192
2193static void chk_reader(char *token, char *value, struct s_reader *rdr)
2194{
2195 int i;
2196 char *ptr;
2197 /*
2198 * case sensitive first
2199 */
2200 if (!strcmp(token, "device")) {
2201 for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
2202 trim(ptr);
2203 switch(i) {
2204 case 0:
2205 cs_strncpy(rdr->device, ptr, sizeof(rdr->device));
2206 break;
2207
2208 case 1:
2209 rdr->r_port = atoi(ptr);
2210 break;
2211
2212 case 2:
2213 rdr->l_port = atoi(ptr);
2214 break;
2215 }
2216 }
2217 return;
2218 }
2219
2220 if (!strcmp(token, "key")) {
2221 if (key_atob14(value, rdr->ncd_key)) {
2222 fprintf(stderr, "Configuration newcamd: Error in Key\n");
2223 exit(1);
2224 }
2225 return;
2226 }
2227
2228#ifdef CS_WITH_GBOX
2229 if (!strcmp(token, "password")) {
2230 cs_strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4);
2231 return;
2232 }
2233
2234 if (!strcmp(token, "premium")) {
2235 rdr->gbox_prem = 1;
2236 return;
2237 }
2238#endif
2239 if (!strcmp(token, "account")) {
2240 for (i = 0, ptr = strtok(value, ","); (i < 2) && (ptr); ptr = strtok(NULL, ","), i++) {
2241 trim(ptr);
2242 switch(i) {
2243 case 0:
2244 cs_strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr));
2245 break;
2246
2247 case 1:
2248 cs_strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd));
2249 break;
2250 }
2251 }
2252 return;
2253 }
2254
2255 if (!strcmp(token, "pincode")) {
2256 strncpy(rdr->pincode, value, sizeof(rdr->pincode) - 1);
2257 return;
2258 }
2259
2260 if (!strcmp(token, "readnano") && value[0]) {
2261 if (rdr->emmfile != NULL) {
2262 free(rdr->emmfile);
2263 rdr->emmfile = NULL;
2264 }
2265 if (strlen(value) > 0)
2266 asprintf(&(rdr->emmfile), "%s", value);
2267 return;
2268 }
2269
2270 /*
2271 * case insensitive
2272 */
2273 strtolower(value);
2274
2275 if (!strcmp(token, "enable")) {
2276 if(strlen(value) == 0) {
2277 rdr->enable = 0;
2278 return;
2279 } else {
2280 rdr->enable = atoi(value) ? 1 : 0;
2281 return;
2282 }
2283 }
2284
2285 if (!strcmp(token, "services")) {
2286 if(strlen(value) == 0) {
2287 rdr->sidtabok = 0;
2288 rdr->sidtabno = 0;
2289 return;
2290 } else {
2291 chk_services(value, &rdr->sidtabok, &rdr->sidtabno);
2292 return;
2293 }
2294 }
2295
2296 if (!strcmp(token, "inactivitytimeout")) {
2297 if(strlen(value) == 0) {
2298 rdr->tcp_ito = 0;
2299 return;
2300 } else {
2301 rdr->tcp_ito = atoi(value);
2302 return;
2303 }
2304 }
2305
2306 if (!strcmp(token, "reconnecttimeout")) {
2307 if(strlen(value) == 0) {
2308 rdr->tcp_rto = 0;
2309 return;
2310 } else {
2311 rdr->tcp_rto = atoi(value);
2312 return;
2313 }
2314 }
2315
2316 if (!strcmp(token, "disableserverfilter")) {
2317 if(strlen(value) == 0) {
2318 rdr->ncd_disable_server_filt = 0;
2319 return;
2320 } else {
2321 rdr->ncd_disable_server_filt = atoi(value);
2322 return;
2323 }
2324 }
2325
2326 //FIXME workaround for Smargo until native mode works
2327 if (!strcmp(token, "smargopatch")) {
2328 if(strlen(value) == 0) {
2329 rdr->smargopatch = 0;
2330 return;
2331 } else {
2332 rdr->smargopatch = atoi(value);
2333 return;
2334 }
2335 }
2336
2337 if (!strcmp(token, "label")) {
2338 cs_strncpy(rdr->label, value, sizeof(rdr->label));
2339 return;
2340 }
2341
2342 if (!strcmp(token, "fallback")) {
2343 if(strlen(value) == 0) {
2344 rdr->fallback = 0;
2345 return;
2346 } else {
2347 rdr->fallback = atoi(value) ? 1 : 0;
2348 return;
2349 }
2350 }
2351
2352 if (!strcmp(token, "logport")) {
2353 if(strlen(value) == 0) {
2354 rdr->log_port = 0;
2355 return;
2356 } else {
2357 rdr->log_port = atoi(value);
2358 return;
2359 }
2360 }
2361
2362 if (!strcmp(token, "caid")) {
2363 if(strlen(value) == 0) {
2364 clear_caidtab(&rdr->ctab);
2365 return;
2366 } else {
2367 chk_caidtab(value, &rdr->ctab);
2368 return;
2369 }
2370 }
2371
2372 if (!strcmp(token, "boxid")) {
2373 if(strlen(value) == 0) {
2374 rdr->boxid = 0;
2375 return;
2376 } else {
2377 rdr->boxid = a2i(value, 4);
2378 return;
2379 }
2380 }
2381
2382 if (!strcmp(token, "aeskey")) {
2383 if (key_atob(value, rdr->aes_key)) {
2384 fprintf(stderr, "Configuration reader: Error in AES Key\n");
2385 exit(1);
2386 }
2387 return;
2388 }
2389
2390 if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey"))) {
2391 rdr->has_rsa = 1;
2392 if (key_atob_l(value, rdr->rsa_mod, 128)) {
2393 fprintf(stderr, "Configuration reader: Error in rsakey\n");
2394 exit(1);
2395 }
2396 return;
2397 }
2398
2399 if (!strcmp(token, "tiger_rsakey")) {
2400 if (key_atob_l(value, rdr->rsa_mod, 240)) {
2401 fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
2402 exit(1);
2403 }
2404 return;
2405 }
2406
2407 if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey"))) {
2408 if (key_atob_l(value, rdr->nagra_boxkey, 16)) {
2409 fprintf(stderr, "Configuration reader: Error in boxkey\n");
2410 exit(1);
2411 }
2412 return;
2413 }
2414
2415 if (!strcmp(token, "detect")) {
2416 for (i = 0; RDR_CD_TXT[i]; i++) {
2417 if (!strcmp(value, RDR_CD_TXT[i])) {
2418 rdr->detect = i;
2419 }
2420 else {
2421 if ((value[0] == '!') && (!strcmp(value+1, RDR_CD_TXT[i])))
2422 rdr->detect = i|0x80;
2423 }
2424 }
2425 return;
2426 }
2427
2428 if (!strcmp(token, "mhz")) {
2429 if(strlen(value) == 0) {
2430 rdr->mhz = 0;
2431 return;
2432 } else {
2433 rdr->mhz = atoi(value);
2434 return;
2435 }
2436 }
2437
2438 if (!strcmp(token, "cardmhz")) {
2439 if(strlen(value) == 0) {
2440 rdr->cardmhz = 0;
2441 return;
2442 } else {
2443 rdr->cardmhz = atoi(value);
2444 return;
2445 }
2446 }
2447
2448 if (!strcmp(token, "protocol")) {
2449
2450 if (!strcmp(value, "mouse")) {
2451 rdr->typ = R_MOUSE;
2452 return;
2453 }
2454
2455 if (!strcmp(value, "smartreader")) {
2456 rdr->typ = R_SMART;
2457 return;
2458 }
2459
2460 if (!strcmp(value, "internal")) {
2461 rdr->typ = R_INTERNAL;
2462 return;
2463 }
2464
2465#ifdef HAVE_PCSC
2466 if (!strcmp(value, "pcsc")) {
2467 rdr->typ = R_PCSC;
2468 return;
2469 }
2470#endif
2471
2472 if (!strcmp(value, "serial")) {
2473 rdr->typ = R_SERIAL;
2474 return;
2475 }
2476
2477 if (!strcmp(value, "camd35")) {
2478 rdr->typ = R_CAMD35;
2479 return;
2480 }
2481
2482 if (!strcmp(value, "cs378x")) {
2483 rdr->typ = R_CS378X;
2484 return;
2485 }
2486
2487 if (!strcmp(value, "cs357x")) {
2488 rdr->typ = R_CAMD35;
2489 return;
2490 }
2491
2492#ifdef CS_WITH_GBOX
2493 if (!strcmp(value, "gbox")) {
2494 rdr->typ = R_GBOX;
2495 return;
2496 }
2497#endif
2498
2499 if (!strcmp(value, "cccam")) {
2500 rdr->typ = R_CCCAM;
2501 //strcpy(value, "1");
2502 //chk_caidtab(value, &rdr->ctab);
2503 //this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
2504 return;
2505 }
2506
2507 if (!strcmp(value, "radegast")) {
2508 rdr->typ = R_RADEGAST;
2509 return;
2510 }
2511
2512 if (!strcmp(value, "newcamd") || !strcmp(value, "newcamd525")) {
2513 rdr->typ = R_NEWCAMD;
2514 rdr->ncd_proto = NCD_525;
2515 return;
2516 }
2517
2518 if (!strcmp(value, "newcamd524")) {
2519 rdr->typ = R_NEWCAMD;
2520 rdr->ncd_proto = NCD_524;
2521 return;
2522 }
2523
2524 fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
2525 rdr->typ = R_MOUSE;
2526 return;
2527 }
2528
2529 if (!strcmp(token, "loadbalanced")) {
2530 if(strlen(value) == 0) {
2531 rdr->loadbalanced = 0;
2532 return;
2533 } else {
2534 rdr->loadbalanced = atoi(value);
2535 return;
2536 }
2537 }
2538
2539 if (!strcmp(token, "ident")) {
2540 if(strlen(value) == 0) {
2541 clear_ftab(&rdr->ftab);
2542 return;
2543 } else {
2544 chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid");
2545 return;
2546 }
2547 }
2548
2549 if (!strcmp(token, "class")) {
2550 chk_cltab(value, &rdr->cltab);
2551 return;
2552 }
2553
2554 if (!strcmp(token, "chid")) {
2555 chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid");
2556 return;
2557 }
2558
2559 if (!strcmp(token, "showcls")) {
2560 rdr->show_cls = atoi(value);
2561 return;
2562 }
2563
2564 if (!strcmp(token, "maxqlen")) {
2565 rdr->maxqlen = atoi(value);
2566 if( rdr->maxqlen < 0 || rdr->maxqlen > CS_MAXQLEN) {
2567 rdr->maxqlen = CS_MAXQLEN;
2568 }
2569 return;
2570 }
2571
2572 if (!strcmp(token, "group")) {
2573 if(strlen(value) == 0) {
2574 rdr->grp = 0;
2575 return;
2576 } else {
2577 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
2578 int g;
2579 g = atoi(ptr);
2580 if ((g>0) && (g<33)) {
2581 rdr->grp |= (1<<(g-1));
2582 }
2583 }
2584 return;
2585 }
2586 }
2587
2588 if (!strcmp(token, "emmcache")) {
2589 if(strlen(value) == 0) {
2590 rdr->cachemm = 0;
2591 rdr->rewritemm = 0;
2592 rdr->logemm = 0;
2593 return;
2594 } else {
2595 for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
2596 switch(i)
2597 {
2598 case 0:
2599 rdr->cachemm = atoi(ptr);
2600 break;
2601
2602 case 1:
2603 rdr->rewritemm = atoi(ptr);
2604 break;
2605
2606 case 2: rdr->logemm = atoi(ptr);
2607 break;
2608 }
2609 }
2610
2611 if (rdr->rewritemm <= 0) {
2612 fprintf(stderr, "Notice: Setting EMMCACHE to %i,1,%i instead of %i,%i,%i. ",
2613 rdr->cachemm, rdr->logemm,
2614 rdr->cachemm, rdr->rewritemm,
2615 rdr->logemm);
2616
2617 fprintf(stderr, "Zero or negative number of rewrites is silly\n");
2618 rdr->rewritemm = 1;
2619 }
2620 return;
2621 }
2622 }
2623
2624 if (!strcmp(token, "blocknano")) {
2625 //wildcard is used
2626 if (!strcmp(value,"all")) {
2627 for (i = 0 ; i < 256; i++) {
2628 rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
2629 }
2630 }
2631 else {
2632 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
2633 if ((i = byte_atob(ptr)) >= 0) {
2634 rdr->b_nano[i] |= 0x01; //lsb is set when to block nano
2635 }
2636 }
2637 }
2638 return;
2639 }
2640
2641 if (!strcmp(token, "blockemm-unknown")) {
2642 if (strlen(value) == 0) {
2643 rdr->blockemm_unknown = 0;
2644 return;
2645 }
2646 else {
2647 rdr->blockemm_unknown = atoi(value);
2648 return;
2649 }
2650 }
2651
2652 if (!strcmp(token, "blockemm-u")) {
2653 if (strlen(value) == 0) {
2654 rdr->blockemm_u = 0;
2655 return;
2656 }
2657 else {
2658 rdr->blockemm_u = atoi(value);
2659 return;
2660 }
2661 }
2662
2663 if (!strcmp(token, "blockemm-s")) {
2664 if (strlen(value) == 0) {
2665 rdr->blockemm_s = 0;
2666 return;
2667 }
2668 else {
2669 rdr->blockemm_s = atoi(value);
2670 return;
2671 }
2672 }
2673
2674 if (!strcmp(token, "blockemm-g")) {
2675 if (strlen(value) == 0) {
2676 rdr->blockemm_g = 0;
2677 return;
2678 }
2679 else {
2680 rdr->blockemm_g = atoi(value);
2681 return;
2682 }
2683 }
2684
2685 if (!strcmp(token, "savenano")) {
2686 //wildcard is used
2687 if (!strcmp(value,"all")) {
2688 for (i = 0 ; i < 256; i++) {
2689 rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
2690 }
2691 }
2692 else {
2693 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
2694 if ((i = byte_atob(ptr)) >= 0) {
2695 rdr->b_nano[i] |= 0x02; //lsb+1 is set when to save nano to file
2696 }
2697 }
2698 }
2699 return;
2700 }
2701
2702 if (!strcmp(token, "cccversion")) {
2703 // cccam version
2704 if (strlen(value) > sizeof(rdr->cc_version) - 1) {
2705 fprintf(stderr, "cccam config: version too long\n");
2706 exit(1);
2707 }
2708 memset(rdr->cc_version, 0, sizeof(rdr->cc_version));
2709 cs_strncpy(rdr->cc_version, value, sizeof(rdr->cc_version));
2710 return;
2711 }
2712
2713 if (!strcmp(token, "cccbuild")) {
2714 // cccam build number
2715 if (strlen(value) > sizeof(rdr->cc_build) - 1) {
2716 fprintf(stderr, "cccam config build number too long\n");
2717 exit(1);
2718 }
2719
2720 memset(rdr->cc_build, 0, sizeof(rdr->cc_build));
2721 cs_strncpy(rdr->cc_build, value, sizeof(rdr->cc_build));
2722 return;
2723 }
2724
2725 if (!strcmp(token, "cccmaxhop")) {
2726 // cccam max card distance
2727 rdr->cc_maxhop = atoi(value);
2728 return;
2729 }
2730
2731 if (!strcmp(token, "deprecated")) {
2732 rdr->deprecated = atoi(value);
2733 return;
2734 }
2735
2736 if (token[0] != '#')
2737 fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);
2738}
2739
2740#ifdef IRDETO_GUESSING
2741int init_irdeto_guess_tab()
2742{
2743 int i, j, skip;
2744 int b47;
2745 FILE *fp;
2746 char token[128], *ptr;
2747 char zSid[5];
2748 uchar b3;
2749 ushort caid, sid;
2750 struct s_irdeto_quess *ird_row, *head;
2751
2752 memset(cfg->itab, 0, sizeof(cfg->itab));
2753 sprintf(token, "%s%s", cs_confdir, cs_ird);
2754 if (!(fp=fopen(token, "r")))
2755 {
2756 cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
2757 token, errno);
2758 return(1);
2759 }
2760 while (fgets(token, sizeof(token), fp))
2761 {
2762 if( strlen(token)<20 ) continue;
2763 for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
2764 {
2765 trim(ptr);
2766 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
2767 skip=1;
2768 break;
2769 }
2770 switch(i)
2771 {
2772 case 0: b3 = a2i(ptr, 2); break;
2773 case 1: b47 = a2i(ptr, 8); break;
2774 case 2: caid = a2i(ptr, 4); break;
2775 case 3:
2776 for( j=0; j<4; j++ )
2777 zSid[j]=ptr[j];
2778 zSid[4]=0;
2779 sid = a2i(zSid, 4);
2780 break;
2781 }
2782 }
2783 if( !skip )
2784 {
2785 if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
2786 {
2787 cs_log("Error allocating memory (errno=%d)", errno);
2788 return(1);
2789 }
2790 ird_row->b47 = b47;
2791 ird_row->caid = caid;
2792 ird_row->sid = sid;
2793 ird_row->next = 0;
2794
2795 head = cfg->itab[b3];
2796 if( head ) {
2797 while( head->next )
2798 head=head->next;
2799 head->next=ird_row;
2800 }
2801 else
2802 cfg->itab[b3]=ird_row;
2803 //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
2804 }
2805 }
2806 fclose(fp);
2807
2808 for( i=0; i<0xff; i++ )
2809 {
2810 head=cfg->itab[i];
2811 while(head)
2812 {
2813 cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
2814 i, head->b47, head->caid, head->sid);
2815 head=head->next;
2816 }
2817 }
2818 return(0);
2819}
2820#endif
2821
2822int init_readerdb()
2823{
2824 int tag = 0, nr;
2825 FILE *fp;
2826 char *value;
2827
2828 sprintf(token, "%s%s", cs_confdir, cs_srvr);
2829 if (!(fp=fopen(token, "r"))) {
2830 cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
2831 return(1);
2832 }
2833 nr = 0;
2834 while (fgets(token, sizeof(token), fp)) {
2835 int i, l;
2836 if ((l = strlen(trim(token))) < 3)
2837 continue;
2838 if ((token[0] == '[') && (token[l-1] == ']')) {
2839 token[l-1] = 0;
2840 tag = (!strcmp("reader", strtolower(token+1)));
2841 if (reader[nr].label[0] && reader[nr].typ) nr++;
2842 memset(&reader[nr], 0, sizeof(struct s_reader));
2843 reader[nr].enable = 1;
2844 reader[nr].tcp_rto = 30;
2845 reader[nr].show_cls = 10;
2846 reader[nr].maxqlen = CS_MAXQLEN;
2847 reader[nr].mhz = 357;
2848 reader[nr].cardmhz = 357;
2849 reader[nr].deprecated = 0;
2850 strcpy(reader[nr].pincode, "none");
2851 for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
2852 continue;
2853 }
2854
2855 if (!tag)
2856 continue;
2857 if (!(value=strchr(token, '=')))
2858 continue;
2859 *value++ ='\0';
2860 chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
2861 }
2862 fclose(fp);
2863 return(0);
2864}
2865
2866#ifdef CS_ANTICASC
2867void init_ac()
2868{
2869 int nr;
2870 FILE *fp;
2871 //char *value;
2872
2873 sprintf(token, "%s%s", cs_confdir, cs_ac);
2874 if (!(fp=fopen(token, "r")))
2875 {
2876 cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
2877 token, errno);
2878 return;
2879 }
2880
2881 for(nr=0; fgets(token, sizeof(token), fp);)
2882 {
2883 int i, skip;
2884 ushort caid, sid, chid, dwtime;
2885 ulong provid;
2886 char *ptr, *ptr1;
2887 struct s_cpmap *ptr_cpmap;
2888 static struct s_cpmap *cpmap=(struct s_cpmap *)0;
2889
2890 if( strlen(token)<4 ) continue;
2891
2892 caid=sid=chid=dwtime=0;
2893 provid=0;
2894 skip=0;
2895 ptr1=0;
2896 for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
2897 {
2898 trim(ptr);
2899 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
2900 skip=1;
2901 break;
2902 }
2903 switch( i )
2904 {
2905 case 0:
2906 ptr1=ptr;
2907 break;
2908 case 1:
2909 dwtime = atoi(ptr);
2910 break;
2911 }
2912 }
2913
2914 if( !skip )
2915 {
2916 for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
2917 {
2918 trim(ptr);
2919 switch( i )
2920 {
2921 case 0:
2922 if( *ptr=='*' ) caid = 0;
2923 else caid = a2i(ptr, 4);
2924 break;
2925 case 1:
2926 if( *ptr=='*' ) provid = 0;
2927 else provid = a2i(ptr, 6);
2928 break;
2929 case 2:
2930 if( *ptr=='*' ) sid = 0;
2931 else sid = a2i(ptr, 4);
2932 break;
2933 case 3:
2934 if( *ptr=='*' ) chid = 0;
2935 else chid = a2i(ptr, 4);
2936 break;
2937 }
2938 }
2939 if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
2940 {
2941 cs_log("Error allocating memory (errno=%d)", errno);
2942 return;
2943 }
2944 if( cpmap )
2945 cpmap->next=ptr_cpmap;
2946 else
2947 cfg->cpmap=ptr_cpmap;
2948 cpmap=ptr_cpmap;
2949
2950 cpmap->caid = caid;
2951 cpmap->provid = provid;
2952 cpmap->sid = sid;
2953 cpmap->chid = chid;
2954 cpmap->dwtime = dwtime;
2955 cpmap->next = 0;
2956
2957 cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
2958 nr, caid, provid, sid, chid, dwtime);
2959 nr++;
2960 }
2961 }
2962 fclose(fp);
2963 //cs_log("%d lengths for caid guessing loaded", nr);
2964 return;
2965}
2966#endif
2967
2968/*
2969 * makes a char ready to write a token into config or webIf
2970 */
2971char *mk_t_caidtab(CAIDTAB *ctab){
2972 int i = 0, needed = 1, pos = 0;
2973 while(ctab->caid[i]){
2974 if(ctab->mask[i]) needed += 10;
2975 else needed += 5;
2976 if(ctab->cmap[i]) needed += 5;
2977 ++i;
2978 }
2979 char *value = (char *) malloc(needed * sizeof(char));
2980 i = 0;
2981 while(ctab->caid[i]) {
2982 if(i == 0) {
2983 sprintf(value + pos, "%04X", ctab->caid[i]);
2984 pos += 4;
2985 } else {
2986 sprintf(value + pos, ",%04X", ctab->caid[i]);
2987 pos += 5;
2988 }
2989 if(ctab->mask[i]){
2990 sprintf(value + pos, "&%04X", ctab->mask[i]);
2991 pos += 5;
2992 }
2993 if(ctab->cmap[i]){
2994 sprintf(value + pos, ":%04X", ctab->cmap[i]);
2995 pos += 5;
2996 }
2997 ++i;
2998 }
2999 value[pos] = '\0';
3000 return value;
3001}
3002
3003/*
3004 * makes a char ready to write a token into config or webIf
3005 */
3006char *mk_t_tuntab(TUNTAB *ttab){
3007 int i = 0, needed = 1, pos = 0;
3008 while(ttab->bt_caidfrom[i]){
3009 if(ttab->bt_srvid[i]) needed += 10;
3010 else needed += 5;
3011 if(ttab->bt_caidto[i]) needed += 5;
3012 ++i;
3013 }
3014 char *value = (char *) malloc(needed * sizeof(char));
3015 i = 0;
3016 while(ttab->bt_caidfrom[i]) {
3017 if(i == 0) {
3018 sprintf(value + pos, "%04X", ttab->bt_caidfrom[i]);
3019 pos += 4;
3020 } else {
3021 sprintf(value + pos, ",%04X", ttab->bt_caidfrom[i]);
3022 pos += 5;
3023 }
3024 if(ttab->bt_srvid[i]){
3025 sprintf(value + pos, ".%04X", ttab->bt_srvid[i]);
3026 pos += 5;
3027 }
3028 if(ttab->bt_caidto[i]){
3029 sprintf(value + pos, ":%04X", ttab->bt_caidto[i]);
3030 pos += 5;
3031 }
3032 ++i;
3033 }
3034 value[pos] = '\0';
3035 return value;
3036}
3037
3038/*
3039 * makes a char ready to write a token into config or webIf
3040 */
3041char *mk_t_group(ulong *grp){
3042 int i = 0, needed = 1, pos = 0, dot = 0;
3043 char grpbit[33];
3044 long2bitchar((long) grp, grpbit);
3045
3046 for(i = 0; i < 32; i++){
3047 if (grpbit[i] == '1'){
3048 needed += 2;
3049 if(i > 9) needed += 1;
3050 }
3051 }
3052 char *value = (char *) malloc(needed * sizeof(char));
3053
3054 for(i = 0; i < 32; i++){
3055 if (grpbit[i] == '1'){
3056 if (dot == 0){
3057 sprintf(value + pos, "%d", i+1);
3058 if (i > 9)pos += 2;
3059 else pos += 1;
3060 dot = 1;
3061 } else {
3062 sprintf(value + pos, ",%d", i+1);
3063 if (i > 9)pos += 3;
3064 else pos += 2;
3065 }
3066 }
3067 }
3068 value[pos] = '\0';
3069 return value;
3070}
3071
3072/*
3073 * makes a char ready to write a token into config or webIf
3074 */
3075char *mk_t_ftab(FTAB *ftab){
3076 int i = 0, j = 0, needed = 1, pos = 0;
3077
3078 needed = ftab->nfilts * 5;
3079 for (i = 0; i < ftab->nfilts; ++i)
3080 needed += ftab->filts[i].nprids * 7;
3081
3082 char *value = (char *) malloc(needed * sizeof(char));
3083
3084 char *dot="";
3085 for (i = 0; i < ftab->nfilts; ++i){
3086 sprintf(value + pos, "%s%04X", dot, ftab->filts[i].caid);
3087 pos += 4;
3088 if (i > 0) pos += 1;
3089 dot=":";
3090 for (j = 0; j < ftab->filts[i].nprids; ++j) {
3091 sprintf(value + pos, "%s%06lX", dot, ftab->filts[i].prids[j]);
3092 pos += 7;
3093 dot=",";
3094 }
3095 dot=";";
3096 }
3097
3098 value[pos] = '\0';
3099 return value;
3100}
Note: See TracBrowser for help on using the repository browser.