source: trunk/oscam-config.c@ 1740

Last change on this file since 1740 was 1740, checked in by merek, 10 years ago

Revert last changes

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