source: trunk/oscam-config.c@ 3181

Last change on this file since 3181 was 3181, checked in by dingo35, 10 years ago

Adding threadsafety FIXMEs, feel free to join checking..

File size: 96.9 KB
Line 
1//FIXME Not checked on threadsafety yet; after checking please remove this line
2
3#include "globals.h"
4#ifdef CS_WITH_BOXKEYS
5# include "oscam-boxkeys.np"
6#endif
7extern struct s_reader * reader;
8
9#define CONFVARWIDTH 30
10
11static const char *cs_conf="oscam.conf";
12static const char *cs_user="oscam.user";
13static const char *cs_srvr="oscam.server";
14static const char *cs_srid="oscam.srvid";
15static const char *cs_trid="oscam.tiers";
16static const char *cs_l4ca="oscam.guess";
17static const char *cs_cert="oscam.cert";
18static const char *cs_sidt="oscam.services";
19#ifdef CS_ANTICASC
20static const char *cs_ac="oscam.ac";
21#endif
22
23//Todo #ifdef CCCAM
24static const char *cs_provid="oscam.provid";
25
26#ifdef IRDETO_GUESSING
27static const char *cs_ird="oscam.ird";
28#endif
29
30static char token[4096];
31
32typedef enum cs_proto_type
33{
34 TAG_GLOBAL, // must be first !
35 TAG_MONITOR, // monitor
36 TAG_CAMD33, // camd 3.3x
37 TAG_CAMD35, // camd 3.5x UDP
38 TAG_NEWCAMD, // newcamd
39 TAG_RADEGAST, // radegast
40 TAG_SERIAL, // serial (static)
41 TAG_CS357X, // camd 3.5x UDP
42 TAG_CS378X, // camd 3.5x TCP
43 TAG_GBOX, // gbox
44 TAG_CCCAM, // cccam
45 TAG_CONSTCW, // constcw
46 TAG_DVBAPI, // dvbapi
47 TAG_WEBIF, // webif
48 TAG_ANTICASC // anti-cascading
49} cs_proto_type_t;
50
51static const char *cctag[]={"global", "monitor", "camd33", "camd35", "newcamd", "radegast", "serial",
52 "cs357x", "cs378x", "gbox", "cccam", "constcw", "dvbapi", "webif", "anticasc", NULL};
53
54#ifdef DEBUG_SIDTAB
55static void show_sidtab(struct s_sidtab *sidtab)
56{
57 for (; sidtab; sidtab=sidtab->next)
58 {
59 int i;
60 char buf[1024];
61 cs_log("label=%s", sidtab->label);
62 sprintf(buf, "caid(%d)=", sidtab->num_caid);
63 for (i=0; i<sidtab->num_caid; i++)
64 sprintf(buf+strlen(buf), "%04X ", sidtab->caid[i]);
65 cs_log("%s", buf);
66 sprintf(buf, "provider(%d)=", sidtab->num_provid);
67 for (i=0; i<sidtab->num_provid; i++)
68 sprintf(buf+strlen(buf), "%08X ", sidtab->provid[i]);
69 cs_log("%s", buf);
70 sprintf(buf, "services(%d)=", sidtab->num_srvid);
71 for (i=0; i<sidtab->num_srvid; i++)
72 sprintf(buf+strlen(buf), "%04X ", sidtab->srvid[i]);
73 cs_log("%s", buf);
74 }
75}
76#endif
77
78void chk_iprange(char *value, struct s_ip **base)
79{
80 int i = 0;
81 char *ptr1, *ptr2;
82 struct s_ip *lip, *cip;
83
84 for (cip=lip=*base; cip; cip=cip->next)
85 lip = cip;
86 if (!(cip=malloc(sizeof(struct s_ip)))) {
87 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
88 exit(1);
89 }
90 if (*base)
91 lip->next = cip;
92 else
93 *base = cip;
94
95 memset(cip, 0, sizeof(struct s_ip));
96 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
97 if (i == 0)
98 ++i;
99 else {
100 if (!(cip=malloc(sizeof(struct s_ip)))) {
101 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
102 exit(1);
103 }
104 lip->next = cip;
105 memset(cip, 0, sizeof(struct s_ip));
106 }
107
108 if( (ptr2=strchr(trim(ptr1), '-')) ) {
109 *ptr2++ ='\0';
110 cip->ip[0]=cs_inet_addr(trim(ptr1));
111 cip->ip[1]=cs_inet_addr(trim(ptr2));
112 } else {
113 cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1);
114 }
115 lip = cip;
116 }
117}
118
119void chk_caidtab(char *caidasc, CAIDTAB *ctab)
120{
121 int i;
122 char *ptr1, *ptr2, *ptr3;
123
124 for (i = 0, ptr1 = strtok(caidasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
125 ulong caid, mask, cmap;
126 if( (ptr3 = strchr(trim(ptr1), ':')) )
127 *ptr3++ = '\0';
128 else
129 ptr3 = "";
130
131 if( (ptr2 = strchr(trim(ptr1), '&')) )
132 *ptr2++ = '\0';
133 else
134 ptr2 = "";
135
136 if (((caid = a2i(ptr1, 2)) | (mask = a2i(ptr2,-2)) | (cmap = a2i(ptr3, 2))) < 0x10000) {
137 ctab->caid[i] = caid;
138 ctab->mask[i] = mask;
139 ctab->cmap[i++] = cmap;
140 }
141 }
142}
143
144void chk_tuntab(char *tunasc, TUNTAB *ttab)
145{
146 int i;
147 char *ptr1, *ptr2, *ptr3;
148
149 for (i = 0, ptr1 = strtok(tunasc, ","); (i < CS_MAXTUNTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
150 ulong bt_caidfrom, bt_caidto, bt_srvid;
151 if( (ptr3 = strchr(trim(ptr1), ':')) )
152 *ptr3++ = '\0';
153 else
154 ptr3 = "";
155
156 if( (ptr2 = strchr(trim(ptr1), '.')) )
157 *ptr2++ = '\0';
158 else
159 ptr2 = "";
160
161 if ((bt_caidfrom = a2i(ptr1, 2)) | (bt_srvid = a2i(ptr2,-2)) | (bt_caidto = a2i(ptr3, 2))) {
162 ttab->bt_caidfrom[i] = bt_caidfrom;
163 ttab->bt_caidto[i] = bt_caidto;
164 ttab->bt_srvid[i++] = bt_srvid;
165 }
166 }
167}
168
169void chk_services(char *labels, ulong *sidok, ulong *sidno)
170{
171 int i;
172 char *ptr;
173 SIDTAB *sidtab;
174 *sidok = *sidno = 0;
175 for (ptr=strtok(labels, ","); ptr; ptr=strtok(NULL, ",")) {
176 for (trim(ptr), i = 0, sidtab = cfg->sidtab; sidtab; sidtab = sidtab->next, i++) {
177 if (!strcmp(sidtab->label, ptr)) *sidok|=(1<<i);
178 if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) *sidno|=(1<<i);
179 }
180 }
181}
182
183void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName)
184{
185 int i, j;
186 char *ptr1, *ptr2, *ptr3;
187 char *ptr[CS_MAXFILTERS] = {0};
188
189 memset(ftab, 0, sizeof(FTAB));
190 for( i = 0, ptr1 = strtok(zFilterAsc, ";"); (i < CS_MAXFILTERS) && (ptr1); ptr1 = strtok(NULL, ";"), i++ ) {
191 ptr[i] = ptr1;
192 if( (ptr2 = strchr(trim(ptr1), ':')) ) {
193 *ptr2++ ='\0';
194 ftab->filts[i].caid = (ushort)a2i(ptr1, 4);
195 ptr[i] = ptr2;
196 }
197 else if (zFiltName && zFiltName[0] == 'c') {
198 cs_log("PANIC: CAID field not found in CHID parameter!");
199 cs_exit(1);
200 }
201 ftab->nfilts++;
202 }
203
204 if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName);
205 for( i = 0; i < ftab->nfilts; i++ ) {
206 cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid);
207 for( j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++ ) {
208 ftab->filts[i].prids[j] = a2i(ptr3,6);
209 ftab->filts[i].nprids++;
210 cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]);
211 }
212 }
213}
214
215void chk_cltab(char *classasc, CLASSTAB *clstab)
216{
217 int i;
218 char *ptr1;
219 for( i = 0, ptr1 = strtok(classasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",") ) {
220 ptr1 = trim(ptr1);
221 if( ptr1[0] == '!' )
222 clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2);
223 else
224 clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2);
225 }
226}
227
228void chk_port_tab(char *portasc, PTAB *ptab)
229{
230 int i, j, nfilts, ifilt, iport;
231 char *ptr1, *ptr2, *ptr3;
232 char *ptr[CS_MAXPORTS] = {0};
233 int port[CS_MAXPORTS] = {0};
234 int previous_nports = ptab->nports;
235
236 for (nfilts = i = previous_nports, ptr1 = strtok(portasc, ";"); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ";"), i++) {
237 ptr[i] = ptr1;
238 if( (ptr2=strchr(trim(ptr1), '@')) ) {
239 *ptr2++ ='\0';
240 ptab->ports[i].s_port = atoi(ptr1);
241
242 //checking for des key for port
243 ptab->ports[i].ncd_key_is_set = 0; //default to 0
244 if( (ptr3=strchr(trim(ptr1), '{')) ) {
245 *ptr3++='\0';
246 if (key_atob14(ptr3, ptab->ports[i].ncd_key))
247 fprintf(stderr, "newcamd: error in DES Key for port %s -> ignored\n", ptr1);
248 else
249 ptab->ports[i].ncd_key_is_set = 1;
250 }
251
252 ptr[i] = ptr2;
253 port[i] = ptab->ports[i].s_port;
254 ptab->nports++;
255 }
256 nfilts++;
257 }
258
259 if( nfilts == 1 && strlen(portasc) < 6 && ptab->ports[0].s_port == 0 ) {
260 ptab->ports[0].s_port = atoi(portasc);
261 ptab->nports = 1;
262 }
263
264 iport = ifilt = previous_nports;
265 for (i=previous_nports; i<nfilts; i++) {
266 if( port[i] != 0 )
267 iport = i;
268 for (j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++) {
269 if( (ptr2=strchr(trim(ptr3), ':')) ) {
270 *ptr2++='\0';
271 ptab->ports[iport].ftab.nfilts++;
272 ifilt = ptab->ports[iport].ftab.nfilts-1;
273 ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4);
274 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
275 } else {
276 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
277 }
278 ptab->ports[iport].ftab.filts[ifilt].nprids++;
279 }
280 }
281}
282
283#ifdef NOTUSED
284static void chk_srvip(char *value, in_addr_t *ip)
285{
286 int i;
287 char *ptr;
288 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
289 if (i<8) ip[i++] = inet_addr(ptr);
290}
291#endif
292
293void chk_t_global(char *token, char *value)
294{
295 if (!strcmp(token, "disablelog")) {
296 if (strlen(value) == 0) {
297 cfg->disablelog = 0;
298 return;
299 } else {
300 cfg->disablelog = atoi(value);
301 return;
302 }
303 }
304
305 if (!strcmp(token, "disableuserfile")) {
306 if (strlen(value) == 0) {
307 cfg->disableuserfile = 0;
308 return;
309 } else {
310 cfg->disableuserfile = atoi(value);
311 return;
312 }
313 }
314
315 if (!strcmp(token, "serverip")) {
316 if (strlen(value) == 0) {
317 cfg->srvip = 0;
318 return;
319 } else {
320 cfg->srvip=inet_addr(value);
321 return;
322 }
323 }
324
325 if (!strcmp(token, "logfile")) {
326 if (cfg->logfile != NULL) {
327 free(cfg->logfile);
328 cfg->logfile = NULL;
329 }
330 if (strlen(value) > 0) {
331 if(asprintf(&(cfg->logfile), "%s", value) < 0)
332 fprintf(stderr, "Error allocating string for cfg->logfile\n");
333 }
334 return;
335 }
336
337 if (!strcmp(token, "pidfile")) {
338 if (cfg->pidfile != NULL) {
339 free(cfg->pidfile);
340 cfg->pidfile = NULL;
341 }
342 if (strlen(value) > 0) {
343 if(asprintf(&(cfg->pidfile), "%s", value) < 0)
344 fprintf(stderr, "Error allocating string for cfg->pidfile\n");
345 }
346 return;
347 }
348
349 if (!strcmp(token, "usrfile")) {
350 if (cfg->usrfile != NULL) {
351 free(cfg->usrfile);
352 cfg->usrfile = NULL;
353 }
354 if (strlen(value) > 0) {
355 if(asprintf(&(cfg->usrfile), "%s", value) < 0)
356 fprintf(stderr, "Error allocating string for cfg->usrfile\n");
357 }
358 return;
359 }
360
361 if (!strcmp(token, "cwlogdir")) {
362 if (cfg->cwlogdir != NULL) {
363 free(cfg->cwlogdir);
364 cfg->cwlogdir = NULL;
365 }
366 if (strlen(value) > 0) {
367 if(asprintf(&(cfg->cwlogdir), "%s", value) < 0)
368 fprintf(stderr, "Error allocating string for cfg->cwlogdir\n");
369 }
370 return;
371 }
372
373 if (!strcmp(token, "usrfileflag")) {
374 if (strlen(value) == 0) {
375 cfg->usrfileflag = 0;
376 return;
377 } else {
378 cfg->usrfileflag = atoi(value);
379 return;
380 }
381 }
382
383 if (!strcmp(token, "clienttimeout")) {
384 if (strlen(value) == 0) {
385 cfg->ctimeout = CS_CLIENT_TIMEOUT;
386 return;
387 } else {
388 cfg->ctimeout = atoi(value);
389 if (cfg->ctimeout < 100)
390 cfg->ctimeout *= 1000;
391 return;
392 }
393 }
394
395 if (!strcmp(token, "fallbacktimeout")) {
396 if (strlen(value) == 0) {
397 cfg->ftimeout = CS_CLIENT_TIMEOUT;
398 return;
399 } else {
400 cfg->ftimeout = atoi(value);
401 if (cfg->ftimeout < 100)
402 cfg->ftimeout *= 1000;
403 return;
404 }
405 }
406
407 if (!strcmp(token, "clientmaxidle")) {
408 if (strlen(value) == 0) {
409 cfg->cmaxidle = CS_CLIENT_MAXIDLE;
410 return;
411 } else {
412 cfg->cmaxidle = atoi(value);
413 return;
414 }
415 }
416
417 if (!strcmp(token, "cachedelay")) {
418 if (strlen(value) == 0) {
419 cfg->delay = CS_DELAY;
420 return;
421 } else {
422 cfg->delay = atoi(value);
423 return;
424 }
425 /*cfg->delay = CS_DELAY;
426 fprintf(stderr, "Parameter %s is deprecated -> ignored\n", token);
427 return;*/
428 }
429
430 if (!strcmp(token, "bindwait")) {
431 if (strlen(value) == 0) {
432 cfg->bindwait = CS_BIND_TIMEOUT;
433 return;
434 } else {
435 cfg->bindwait = atoi(value);
436 return;
437 }
438 }
439
440 if (!strcmp(token, "netprio")) {
441 if (strlen(value) == 0) {
442 cfg->netprio = 0;
443 return;
444 } else {
445 cfg->netprio = atoi(value);
446 return;
447 }
448 }
449
450 if (!strcmp(token, "resolvedelay")) {
451 if (strlen(value) == 0) {
452 cfg->resolvedelay = CS_RESOLVE_DELAY;
453 return;
454 } else {
455 cfg->resolvedelay = atoi(value);
456 return;
457 }
458 }
459
460 if (!strcmp(token, "clientdyndns")) {
461 if (strlen(value) == 0) {
462 cfg->clientdyndns = 0;
463 return;
464 } else {
465 cfg->clientdyndns = atoi(value);
466 return;
467 }
468 }
469
470 if (!strcmp(token, "sleep")) {
471 if (strlen(value) == 0) {
472 cfg->tosleep = 0;
473 return;
474 } else {
475 cfg->tosleep = atoi(value);
476 return;
477 }
478 }
479
480 if (!strcmp(token, "unlockparental")) {
481 if (strlen(value) == 0) {
482 cfg->ulparent = 0;
483 return;
484 } else {
485 cfg->ulparent = atoi(value);
486 return;
487 }
488 }
489
490 if (!strcmp(token, "nice")) {
491 if (strlen(value) == 0) {
492 cfg->nice = 99;
493 return;
494 } else {
495 cfg->nice = atoi(value);
496 if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice = 99;
497 if (cfg->nice != 99) cs_setpriority(cfg->nice); // ignore errors
498 return;
499 }
500 }
501
502 if (!strcmp(token, "serialreadertimeout")) {
503 if (cfg->srtimeout < 100)
504 cfg->srtimeout = atoi(value) * 1000;
505 else
506 cfg->srtimeout = atoi(value);
507 if (cfg->srtimeout <= 0)
508 cfg->srtimeout = 1500;
509 return;
510 }
511
512 if (!strcmp(token, "maxlogsize")) {
513 if (strlen(value) == 0) {
514 cfg->max_log_size = 10;
515 return;
516 } else {
517 cfg->max_log_size = atoi(value);
518 if( cfg->max_log_size <= 10 )
519 cfg->max_log_size = 10;
520 return;
521 }
522 }
523
524 if( !strcmp(token, "waitforcards")) {
525 if (strlen(value) == 0) {
526 cfg->waitforcards = 1;
527 return;
528 } else {
529 cfg->waitforcards = atoi(value);
530 return;
531 }
532 }
533
534 if( !strcmp(token, "preferlocalcards")) {
535 if (strlen(value) == 0) {
536 cfg->preferlocalcards = 0;
537 return;
538 } else {
539 cfg->preferlocalcards = atoi(value);
540 return;
541 }
542 }
543
544 if( !strcmp(token, "saveinithistory")) {
545 if (strlen(value) == 0) {
546 cfg->saveinithistory = 0;
547 return;
548 } else {
549 cfg->saveinithistory = atoi(value);
550 return;
551 }
552 }
553
554 if (!strcmp(token, "readerrestartseconds")) {
555 if (strlen(value) == 0) {
556 cfg->reader_restart_seconds = 5;
557 return;
558 } else {
559 cfg->reader_restart_seconds = atoi(value);
560 return;
561 }
562 }
563
564 if (!strcmp(token, "readerautoloadbalance") || !strcmp(token, "lb_mode")) {
565 if (strlen(value) == 0) {
566 cfg->lb_mode = 0;
567 return;
568 } else {
569 cfg->lb_mode = atoi(value);
570 return;
571 }
572 }
573
574 if (!strcmp(token, "readerautoloadbalance_save") || !strcmp(token, "lb_save")) {
575 if (strlen(value) == 0) {
576 cfg->lb_save = 0;
577 return;
578 } else {
579 cfg->lb_save = atoi(value);
580 return;
581 }
582 }
583
584 if (!strcmp(token, "lb_nbest_readers")) {
585 if (strlen(value))
586 cfg->lb_nbest_readers = atoi(value);
587 return;
588 }
589
590 if (!strcmp(token, "lb_nfb_readers")) {
591 if (strlen(value))
592 cfg->lb_nfb_readers = atoi(value);
593 return;
594 }
595
596 if (!strcmp(token, "lb_min_ecmcount")) {
597 if (strlen(value))
598 cfg->lb_min_ecmcount = atoi(value);
599 return;
600 }
601
602 if (!strcmp(token, "lb_max_ecmcount")) {
603 if (strlen(value))
604 cfg->lb_max_ecmcount = atoi(value);
605 return;
606 }
607
608 if (!strcmp(token, "lb_reopen_seconds")) {
609 if (strlen(value))
610 cfg->lb_reopen_seconds = atoi(value);
611 return;
612 }
613
614 if (!strcmp(token, "resolvegethostbyname")) {
615 if (strlen(value) == 0) {
616 cfg->resolve_gethostbyname = 0;
617 return;
618 } else {
619 cfg->resolve_gethostbyname = atoi(value);
620 return;
621 }
622 }
623
624#ifdef CS_WITH_DOUBLECHECK
625 if (!strcmp(token, "double_check")) {
626 if (strlen(value) == 0) {
627 cfg->double_check = 0;
628 return;
629 } else {
630 cfg->double_check = atoi(value);
631 return;
632 }
633 }
634#endif
635
636
637 if (token[0] != '#')
638 fprintf(stderr, "Warning: keyword '%s' in global section not recognized\n", token);
639}
640
641#ifdef CS_ANTICASC
642void chk_t_ac(char *token, char *value)
643{
644 if (!strcmp(token, "enabled")) {
645 cfg->ac_enabled = atoi(value);
646 if( cfg->ac_enabled <= 0 )
647 cfg->ac_enabled = 0;
648 else
649 cfg->ac_enabled = 1;
650 return;
651 }
652
653 if (!strcmp(token, "numusers")) {
654 cfg->ac_users = atoi(value);
655 if( cfg->ac_users < 0 )
656 cfg->ac_users = 0;
657 return;
658 }
659
660 if (!strcmp(token, "sampletime")) {
661 cfg->ac_stime = atoi(value);
662 if( cfg->ac_stime < 0 )
663 cfg->ac_stime = 2;
664 return;
665 }
666
667 if (!strcmp(token, "samples")) {
668 cfg->ac_samples = atoi(value);
669 if( cfg->ac_samples < 2 || cfg->ac_samples > 10)
670 cfg->ac_samples = 10;
671 return;
672 }
673
674 if (!strcmp(token, "penalty")) {
675 cfg->ac_penalty = atoi(value);
676 if( cfg->ac_penalty < 0 )
677 cfg->ac_penalty = 0;
678 return;
679 }
680
681 if (!strcmp(token, "aclogfile")) {
682 cs_strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile));
683 return;
684 }
685
686 if( !strcmp(token, "fakedelay") ) {
687 cfg->ac_fakedelay = atoi(value);
688 if( cfg->ac_fakedelay < 100 || cfg->ac_fakedelay > 1000 )
689 cfg->ac_fakedelay = 1000;
690 return;
691 }
692
693 if( !strcmp(token, "denysamples") ) {
694 cfg->ac_denysamples = atoi(value);
695 if( cfg->ac_denysamples < 2 || cfg->ac_denysamples > cfg->ac_samples - 1 )
696 cfg->ac_denysamples=cfg->ac_samples-1;
697 return;
698 }
699
700 if (token[0] != '#')
701 fprintf(stderr, "Warning: keyword '%s' in anticascading section not recognized\n",token);
702}
703#endif
704
705void chk_t_monitor(char *token, char *value)
706{
707 if (!strcmp(token, "port")) {
708 if(strlen(value) == 0) {
709 cfg->mon_port = 0;
710 return;
711 } else {
712 cfg->mon_port=atoi(value);
713 return;
714 }
715 }
716
717 if (!strcmp(token, "serverip")) {
718 if(strlen(value) == 0) {
719 cfg->mon_srvip = 0;
720 return;
721 } else {
722 cfg->mon_srvip=inet_addr(value);
723 return;
724 }
725 }
726
727 if (!strcmp(token, "nocrypt")) {
728 if(strlen(value) == 0) {
729 clear_sip(&cfg->mon_allowed);
730 return;
731 } else {
732 chk_iprange(value, &cfg->mon_allowed);
733 return;
734 }
735 }
736
737 if (!strcmp(token, "aulow")) {
738 if(strlen(value) == 0) {
739 cfg->mon_aulow = 0;
740 return;
741 } else {
742 cfg->mon_aulow = atoi(value);
743 return;
744 }
745 }
746
747 if (!strcmp(token, "monlevel")) {
748 if(strlen(value) == 0) {
749 cfg->mon_level = 0;
750 return;
751 } else {
752 cfg->mon_level = atoi(value);
753 return;
754 }
755 }
756
757 if (!strcmp(token, "hideclient_to")) {
758 if(strlen(value) == 0) {
759 cfg->mon_hideclient_to = 0;
760 return;
761 } else {
762 cfg->mon_hideclient_to = atoi(value);
763 return;
764 }
765 }
766
767 if (!strcmp(token, "appendchaninfo")) {
768 if(strlen(value) == 0) {
769 cfg->mon_appendchaninfo = 0;
770 return;
771 } else {
772 cfg->mon_appendchaninfo = atoi(value);
773 return;
774 }
775 }
776
777 if (token[0] != '#')
778 fprintf(stderr, "Warning: keyword '%s' in monitor section not recognized\n",token);
779}
780
781#ifdef WEBIF
782void chk_t_webif(char *token, char *value)
783{
784 if (!strcmp(token, "httpport")) {
785 if(strlen(value) == 0) {
786 cfg->http_port = 0;
787 return;
788 } else {
789 cfg->http_port = atoi(value);
790 return;
791 }
792 }
793
794 if (!strcmp(token, "httpuser")) {
795 cs_strncpy(cfg->http_user, value, sizeof(cfg->http_user));
796 return;
797 }
798
799 if (!strcmp(token, "httppwd")) {
800 cs_strncpy(cfg->http_pwd, value, sizeof(cfg->http_pwd));
801 return;
802 }
803
804 if (!strcmp(token, "httpcss")) {
805 cs_strncpy(cfg->http_css, value, sizeof(cfg->http_css));
806 return;
807 }
808
809 if (!strcmp(token, "httpscript")) {
810 cs_strncpy(cfg->http_script, value, sizeof(cfg->http_script));
811 return;
812 }
813
814 if (!strcmp(token, "httptpl")) {
815 cfg->http_tpl[0] = '\0';
816 cs_strncpy(cfg->http_tpl, value, sizeof(cfg->http_tpl));
817 if(strlen(value) != 0) {
818 if(strlen(cfg->http_tpl) < (sizeof(cfg->http_tpl)-2) && cfg->http_tpl[strlen(cfg->http_tpl)-1] != '/') {
819 cfg->http_tpl[strlen(cfg->http_tpl)] = '/';
820 cfg->http_tpl[strlen(cfg->http_tpl)] = '\0';
821 }
822 }
823 return;
824 }
825
826 if (!strcmp(token, "httprefresh")) {
827 if(strlen(value) == 0) {
828 cfg->http_refresh = 0;
829 return;
830 } else {
831 cfg->http_refresh = atoi(value);
832 return;
833 }
834 }
835
836 if (!strcmp(token, "httphideidleclients")) {
837 if(strlen(value) == 0) {
838 cfg->http_hide_idle_clients = 0;
839 return;
840 } else {
841 cfg->http_hide_idle_clients = atoi(value);
842 return;
843 }
844 }
845
846 if (!strcmp(token, "httpallowed")) {
847 if(strlen(value) == 0) {
848 clear_sip(&cfg->http_allowed);
849 return;
850 } else {
851 chk_iprange(value, &cfg->http_allowed);
852 return;
853 }
854 }
855
856 if (!strcmp(token, "httpreadonly")) {
857 if(strlen(value) == 0) {
858 cfg->http_readonly = 0;
859 return;
860 } else {
861 cfg->http_readonly = atoi(value);
862 return;
863 }
864 }
865
866 if (!strcmp(token, "httpdyndns")) {
867 cs_strncpy((char *)cfg->http_dyndns, value, sizeof(cfg->http_dyndns));
868 return;
869 }
870
871 if (token[0] != '#')
872 fprintf(stderr, "Warning: keyword '%s' in webif section not recognized\n",token);
873}
874#endif
875
876
877void chk_t_camd33(char *token, char *value)
878{
879 if (!strcmp(token, "port")) {
880 if(strlen(value) == 0) {
881 cfg->c33_port = 0;
882 return;
883 } else {
884 cfg->c33_port = atoi(value);
885 return;
886 }
887 }
888
889 if (!strcmp(token, "serverip")) {
890 if(strlen(value) == 0) {
891 cfg->c33_srvip = 0;
892 return;
893 } else {
894 cfg->c33_srvip = inet_addr(value);
895 return;
896 }
897 }
898
899 if (!strcmp(token, "nocrypt")) {
900 if(strlen(value) == 0) {
901 return;
902 } else {
903 chk_iprange(value, &cfg->c33_plain);
904 return;
905 }
906 }
907
908 if (!strcmp(token, "passive")) {
909 cfg->c33_passive = (value[0]!='0');
910 return;
911 }
912
913 if (!strcmp(token, "key")) {
914 if(strlen(value) == 0) {
915 cfg->c33_crypted = 0;
916 return;
917 }
918 if (key_atob(value, cfg->c33_key)) {
919 fprintf(stderr, "Configuration camd3.3x: Error in Key\n");
920 exit(1);
921 }
922 cfg->c33_crypted=1;
923 return;
924 }
925
926 if (token[0] != '#')
927 fprintf(stderr, "Warning: keyword '%s' in camd33 section not recognized\n",token);
928}
929
930void chk_t_camd35(char *token, char *value)
931{
932 if (!strcmp(token, "port")) {
933 if(strlen(value) == 0) {
934 cfg->c35_port = 0;
935 return;
936 } else {
937 cfg->c35_port = atoi(value);
938 return;
939 }
940 }
941
942 if (!strcmp(token, "serverip")) {
943 if(strlen(value) == 0) {
944 cfg->c35_srvip = 0;
945 return;
946 } else {
947 cfg->c35_srvip = inet_addr(value);
948 return;
949 }
950 }
951
952 if (!strcmp(token, "suppresscmd08")) {
953 if(strlen(value) == 0) {
954 cfg->c35_suppresscmd08 = 0;
955 return;
956 } else {
957 cfg->c35_suppresscmd08=atoi(value);
958 return;
959 }
960 }
961
962 if (token[0] != '#')
963 fprintf(stderr, "Warning: keyword '%s' in camd35 section not recognized\n", token);
964}
965
966void chk_t_camd35_tcp(char *token, char *value)
967{
968 if (!strcmp(token, "port")) {
969 if(strlen(value) == 0) {
970 clear_ptab(&cfg->c35_tcp_ptab);
971 return;
972 } else {
973 chk_port_tab(value, &cfg->c35_tcp_ptab);
974 return;
975 }
976 }
977
978 if (!strcmp(token, "serverip")) {
979 if(strlen(value) == 0) {
980 cfg->c35_tcp_srvip = 0;
981 return;
982 } else {
983 cfg->c35_tcp_srvip = inet_addr(value);
984 return;
985 }
986 }
987
988 if (token[0] != '#')
989 fprintf(stderr, "Warning: keyword '%s' in camd35 tcp section not recognized\n", token);
990}
991
992void chk_t_newcamd(char *token, char *value)
993{
994 if (!strcmp(token, "port")) {
995 if(strlen(value) == 0) {
996 clear_ptab(&cfg->ncd_ptab);
997 return;
998 } else {
999 chk_port_tab(value, &cfg->ncd_ptab);
1000 return;
1001 }
1002 }
1003
1004 if (!strcmp(token, "serverip")) {
1005 if(strlen(value) == 0) {
1006 cfg->ncd_srvip = 0;
1007 return;
1008 } else {
1009 cfg->ncd_srvip = inet_addr(value);
1010 return;
1011 }
1012 }
1013
1014 if (!strcmp(token, "allowed")) {
1015 if(strlen(value) == 0) {
1016 clear_sip(&cfg->ncd_allowed);
1017 return;
1018 } else {
1019 chk_iprange(value, &cfg->ncd_allowed);
1020 return;
1021 }
1022 }
1023
1024 if (!strcmp(token, "key")) {
1025 if(strlen(value) == 0)
1026 return;
1027 if (key_atob14(value, cfg->ncd_key)) {
1028 fprintf(stderr, "Configuration newcamd: Error in Key\n");
1029 exit(1);
1030 }
1031 return;
1032 }
1033
1034 if (!strcmp(token, "keepalive")) {
1035 if(strlen(value) == 0) {
1036 cfg->ncd_keepalive = 1;
1037 return;
1038 } else {
1039 cfg->ncd_keepalive = atoi(value);
1040 return;
1041 }
1042 }
1043
1044 if (!strcmp(token, "mgclient")) {
1045 if(strlen(value) == 0) {
1046 cfg->ncd_mgclient = 0;
1047 return;
1048 } else {
1049 cfg->ncd_mgclient = atoi(value);
1050 return;
1051 }
1052 }
1053
1054 if (token[0] != '#')
1055 fprintf(stderr, "Warning: keyword '%s' in newcamd section not recognized\n", token);
1056}
1057
1058void chk_t_cccam(char *token, char *value)
1059{
1060 if (!strcmp(token, "port")) {
1061 if(strlen(value) == 0) {
1062 cfg->cc_port = 0;
1063 return;
1064 } else {
1065 cfg->cc_port = atoi(value);
1066 return;
1067 }
1068 }
1069 //if (!strcmp(token, "serverip")) { cfg->cc_srvip=inet_addr(value); return; }
1070
1071 if (!strcmp(token, "reshare")) {
1072 if(strlen(value) == 0) {
1073 cfg->cc_reshare = 0;
1074 return;
1075 } else {
1076 cfg->cc_reshare=atoi(value);
1077 return;
1078 }
1079 }
1080 // cccam version
1081 if (!strcmp(token, "version")) {
1082 if (strlen(value) > sizeof(cfg->cc_version) - 1) {
1083 fprintf(stderr, "cccam config: version too long\n");
1084 exit(1);
1085 }
1086 memset(cfg->cc_version, 0, sizeof(cfg->cc_version));
1087 strncpy((char*)cfg->cc_version, value, sizeof(cfg->cc_version) - 1);
1088 return;
1089 }
1090 // cccam: Update cards interval
1091 if (!strcmp(token, "updateinterval")) {
1092 if (strlen(value) == 0)
1093 cfg->cc_update_interval = 4*60; //4x60s = 4min
1094 else
1095 cfg->cc_update_interval = atoi(value);
1096 return;
1097 }
1098
1099 // cccam: Update cards interval
1100 if (!strcmp(token, "minimizecards")) {
1101 if (strlen(value) == 0)
1102 cfg->cc_minimize_cards = 0;
1103 else
1104 cfg->cc_minimize_cards = atoi(value);
1105 return;
1106 }
1107
1108
1109 if (token[0] != '#')
1110 fprintf(stderr, "Warning: keyword '%s' in cccam section not recognized\n",token);
1111}
1112
1113void chk_t_radegast(char *token, char *value)
1114{
1115 if (!strcmp(token, "port")) {
1116 if(strlen(value) == 0) {
1117 cfg->rad_port = 0;
1118 return;
1119 } else {
1120 cfg->rad_port = atoi(value);
1121 return;
1122 }
1123 }
1124
1125 if (!strcmp(token, "serverip")) {
1126 if(strlen(value) == 0) {
1127 cfg->rad_srvip = 0;
1128 return;
1129 } else {
1130 cfg->rad_srvip = inet_addr(value);
1131 return;
1132 }
1133 }
1134
1135 if (!strcmp(token, "allowed")) {
1136 if(strlen(value) == 0) {
1137 clear_sip(&cfg->rad_allowed);
1138 return;
1139 } else {
1140 chk_iprange(value, &cfg->rad_allowed);
1141 return;
1142 }
1143 }
1144
1145 if (!strcmp(token, "user")) {
1146 cs_strncpy(cfg->rad_usr, value, sizeof(cfg->rad_usr));
1147 return;
1148 }
1149
1150 if (token[0] != '#')
1151 fprintf(stderr, "Warning: keyword '%s' in radegast section not recognized\n", token);
1152}
1153
1154void chk_t_serial(char *token, char *value)
1155{
1156 if (!strcmp(token, "device")) {
1157 int l;
1158 l = strlen(cfg->ser_device);
1159 if (l)
1160 cfg->ser_device[l++]=1; // use ctrl-a as delimiter
1161 cs_strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-l);
1162 return;
1163 }
1164 if (token[0] != '#')
1165 fprintf(stderr, "Warning: keyword '%s' in serial section not recognized\n", token);
1166}
1167
1168#ifdef CS_WITH_GBOX
1169void chk_t_gbox(char *token, char *value)
1170{
1171 //if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
1172 if (!strcmp(token, "password")) {
1173 cs_atob(cfg->gbox_pwd, value, 4);
1174 return;
1175 }
1176
1177 if (!strcmp(token, "maxdist")) {
1178 cfg->maxdist=atoi(value);
1179 return;
1180 }
1181
1182 if (!strcmp(token, "ignorelist")) {
1183 cs_strncpy((char *)cfg->ignorefile, value, sizeof(cfg->ignorefile));
1184 return;
1185 }
1186
1187 if (!strcmp(token, "onlineinfos")) {
1188 cs_strncpy((char *)cfg->gbxShareOnl, value, sizeof(cfg->gbxShareOnl));
1189 return;
1190 }
1191
1192 if (!strcmp(token, "cardinfos")) {
1193 cs_strncpy((char *)cfg->cardfile, value, sizeof(cfg->cardfile));
1194 return;
1195 }
1196
1197 if (!strcmp(token, "locals"))
1198 {
1199 char *ptr1;
1200 int n = 0, i;
1201 for (i = 0, ptr1 = strtok(value, ","); (i < CS_MAXLOCALS) && (ptr1); ptr1 = strtok(NULL, ",")) {
1202 cfg->locals[n++] = a2i(ptr1, 8);
1203 //printf("%i %08X",n,cfg->locals[n-1]);
1204 }
1205 cfg->num_locals = n;
1206 return;
1207 }
1208
1209 if (token[0] != '#')
1210 fprintf(stderr, "Warning: keyword '%s' in gbox section not recognized\n",token);
1211}
1212#endif
1213
1214#ifdef HAVE_DVBAPI
1215void chk_t_dvbapi(char *token, char *value)
1216{
1217 if (!strcmp(token, "enabled")) {
1218 if(strlen(value) == 0) {
1219 cfg->dvbapi_enabled = 0;
1220 } else {
1221 cfg->dvbapi_enabled = atoi(value);
1222 }
1223 return;
1224 }
1225
1226 if (!strcmp(token, "au")) {
1227 if(strlen(value) == 0) {
1228 cfg->dvbapi_au = 0;
1229 } else {
1230 cfg->dvbapi_au = atoi(value);
1231 }
1232 return;
1233 }
1234
1235 if (!strcmp(token, "pmt_mode")) {
1236 if(strlen(value) == 0) {
1237 cfg->dvbapi_pmtmode = 0;
1238 } else {
1239 cfg->dvbapi_pmtmode = atoi(value);
1240 if(cfg->dvbapi_pmtmode > 3)
1241 cfg->dvbapi_pmtmode = 3;
1242 }
1243 return;
1244 }
1245
1246 if (!strcmp(token, "boxtype")) {
1247 int i;
1248 for (i=1;i<=BOXTYPES;i++) {
1249 if (strcmp(value, boxdesc[i])==0) {
1250 cfg->dvbapi_boxtype=i;
1251 return;
1252 }
1253 }
1254
1255 cfg->dvbapi_boxtype=0;
1256 return;
1257 }
1258
1259 if (!strcmp(token, "user")) {
1260 cs_strncpy(cfg->dvbapi_usr, value, sizeof(cfg->dvbapi_usr));
1261 return;
1262 }
1263
1264 if (!strcmp(token, "priority")) {
1265 dvbapi_chk_caidtab(value, &cfg->dvbapi_prioritytab);
1266 return;
1267 }
1268
1269 if (!strcmp(token, "ignore")) {
1270 dvbapi_chk_caidtab(value, &cfg->dvbapi_ignoretab);
1271 return;
1272 }
1273
1274 if (!strcmp(token, "cw_delay")) {
1275 dvbapi_chk_caidtab(value, &cfg->dvbapi_delaytab);
1276 return;
1277 }
1278
1279 if (token[0] != '#')
1280 fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token);
1281}
1282#endif
1283
1284static void chk_token(char *token, char *value, int tag)
1285{
1286 switch(tag) {
1287 case TAG_GLOBAL : chk_t_global(token, value); break;
1288 case TAG_MONITOR : chk_t_monitor(token, value); break;
1289 case TAG_CAMD33 : chk_t_camd33(token, value); break;
1290 case TAG_CAMD35 :
1291 case TAG_CS357X : chk_t_camd35(token, value); break;
1292 case TAG_NEWCAMD : chk_t_newcamd(token, value); break;
1293 case TAG_RADEGAST: chk_t_radegast(token, value); break;
1294 case TAG_SERIAL : chk_t_serial(token, value); break;
1295 case TAG_CS378X : chk_t_camd35_tcp(token, value); break;
1296 case TAG_CCCAM : chk_t_cccam(token, value); break;
1297
1298#ifdef CS_WITH_GBOX
1299 case TAG_GBOX : chk_t_gbox(token, value); break;
1300#else
1301 case TAG_GBOX : fprintf(stderr, "OSCam compiled without gbox support. Parameter %s ignored\n", token); break;
1302#endif
1303
1304
1305#ifdef HAVE_DVBAPI
1306 case TAG_DVBAPI : chk_t_dvbapi(token, value); break;
1307#else
1308 case TAG_DVBAPI : fprintf(stderr, "OSCam compiled without DVB API support. Parameter %s ignored\n", token); break;
1309#endif
1310
1311
1312#ifdef WEBIF
1313 case TAG_WEBIF : chk_t_webif(token, value); break;
1314#else
1315 case TAG_WEBIF : fprintf(stderr, "OSCam compiled without Webinterface support. Parameter %s ignored\n", token); break;
1316#endif
1317
1318
1319#ifdef CS_ANTICASC
1320 case TAG_ANTICASC: chk_t_ac(token, value); break;
1321#else
1322 case TAG_ANTICASC: fprintf(stderr, "OSCam compiled without Anticascading support. Parameter %s ignored\n", token); break;
1323#endif
1324
1325 }
1326}
1327
1328void init_len4caid()
1329{
1330 int nr;
1331 FILE *fp;
1332 char *value;
1333
1334 memset(len4caid, 0, sizeof(ushort)<<8);
1335 sprintf(token, "%s%s", cs_confdir, cs_l4ca);
1336 if (!(fp = fopen(token, "r")))
1337 return;
1338 for(nr = 0; fgets(token, sizeof(token), fp);) {
1339 int i, c;
1340 char *ptr;
1341 if (!(value=strchr(token, ':')))
1342 continue;
1343 *value++ ='\0';
1344 if( (ptr = strchr(value, '#')) )
1345 *ptr = '\0';
1346 if (strlen(trim(token)) != 2)
1347 continue;
1348 if (strlen(trim(value)) != 4)
1349 continue;
1350 if ((i = byte_atob(token)) < 0)
1351 continue;
1352 if ((c = word_atob(value)) < 0)
1353 continue;
1354 len4caid[i] = c;
1355 nr++;
1356 }
1357 fclose(fp);
1358 cs_log("%d lengths for caid guessing loaded", nr);
1359 return;
1360}
1361
1362int search_boxkey(ushort caid, char *key)
1363{
1364 int i, rc = 0;
1365 FILE *fp;
1366 char c_caid[512];
1367
1368 sprintf(c_caid, "%s%s", cs_confdir, cs_cert);
1369 fp = fopen(c_caid, "r");
1370 if (fp) {
1371 for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);) {
1372 char *c_provid, *c_key;
1373
1374 c_provid = strchr(c_caid, '#');
1375 if (c_provid)
1376 *c_provid = '\0';
1377 if (!(c_provid = strchr(c_caid, ':')))
1378 continue;
1379 *c_provid++ ='\0';
1380 if (!(c_key = strchr(c_provid, ':')))
1381 continue;
1382 *c_key++ ='\0';
1383 if (word_atob(trim(c_caid))!=caid)
1384 continue;
1385 if ((i=(strlen(trim(c_key))>>1)) > 256)
1386 continue;
1387 if (cs_atob((uchar *)key, c_key, i) < 0) {
1388 cs_log("wrong key in \"%s\"", cs_cert);
1389 continue;
1390 }
1391 rc = 1;
1392 }
1393 fclose(fp);
1394 }
1395#ifdef OSCAM_INBUILD_KEYS
1396 for(i=0; (!rc) && (npkey[i].keylen); i++)
1397 if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0)))
1398 memcpy(key, npkey[i].key, npkey[i].keylen);
1399#endif
1400 return(rc);
1401}
1402
1403int init_config()
1404{
1405 int tag=TAG_GLOBAL;
1406 FILE *fp;
1407 char *value;
1408
1409#ifndef CS_EMBEDDED
1410#ifdef PRIO_PROCESS
1411 errno=0;
1412 if ((cfg->nice = getpriority(PRIO_PROCESS, 0)) == (-1))
1413 if (errno)
1414#endif
1415#endif
1416 cfg->nice = 99;
1417 cfg->ctimeout = CS_CLIENT_TIMEOUT;
1418 cfg->ftimeout = CS_CLIENT_TIMEOUT / 2;
1419 cfg->cmaxidle = CS_CLIENT_MAXIDLE;
1420 cfg->delay = CS_DELAY;
1421 cfg->bindwait = CS_BIND_TIMEOUT;
1422 cfg->resolvedelay = CS_RESOLVE_DELAY;
1423 cfg->mon_level = 2;
1424 cfg->mon_hideclient_to = 0;
1425 cfg->srtimeout = 1500;
1426 cfg->ulparent = 0;
1427 cfg->logfile = NULL;
1428 cfg->pidfile = NULL;
1429 cfg->usrfile = NULL;
1430 cfg->cwlogdir = NULL;
1431 cfg->reader_restart_seconds = 5;
1432 cfg->waitforcards = 1;
1433#ifdef WEBIF
1434 strcpy(cfg->http_user, "");
1435 strcpy(cfg->http_pwd, "");
1436 strcpy(cfg->http_css, "");
1437 cfg->http_refresh = 0;
1438 cfg->http_hide_idle_clients = 0;
1439 strcpy(cfg->http_tpl, "");
1440#endif
1441 cfg->ncd_keepalive = 1;
1442#ifdef CS_ANTICASC
1443 cfg->ac_enabled = 0;
1444 cfg->ac_users = 0;
1445 cfg->ac_stime = 2;
1446 cfg->ac_samples = 10;
1447 cfg->ac_denysamples = 8;
1448 cfg->ac_fakedelay = 1000;
1449 strcpy(cfg->ac_logfile, "./oscam_ac.log");
1450#endif
1451 sprintf(token, "%s%s", cs_confdir, cs_conf);
1452 if (!(fp = fopen(token, "r"))) {
1453 fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno);
1454 exit(1);
1455 }
1456 while (fgets(token, sizeof(token), fp)) {
1457 int i, l;
1458 //void *ptr;
1459 if ((l = strlen(trim(token))) < 3)
1460 continue;
1461 if ((token[0] == '[') && (token[l-1] == ']')) {
1462 for (token[l-1] = 0, tag = -1, i = TAG_GLOBAL; cctag[i]; i++)
1463 if (!strcmp(cctag[i], strtolower(token+1)))
1464 tag = i;
1465 continue;
1466 }
1467 if (!(value=strchr(token, '=')))
1468 continue;
1469 *value++ ='\0';
1470 chk_token(trim(strtolower(token)), trim(value), tag);
1471 }
1472 fclose(fp);
1473#ifdef CS_LOGFILE
1474 if (cfg->logfile == NULL) {
1475 if(asprintf(&(cfg->logfile), "%s", CS_LOGFILE) < 0)
1476 fprintf(stderr, "Error allocating string for cfg->logfile\n");
1477 }
1478#endif
1479 cs_init_statistics(cfg->usrfile);
1480 cs_init_log(cfg->logfile);
1481 if (cfg->ftimeout >= cfg->ctimeout) {
1482 cfg->ftimeout = cfg->ctimeout - 100;
1483 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout);
1484 }
1485 if(cfg->ftimeout < cfg->srtimeout) {
1486 cfg->ftimeout = cfg->srtimeout + 100;
1487 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout);
1488 }
1489 if(cfg->ctimeout < cfg->srtimeout) {
1490 cfg->ctimeout = cfg->srtimeout + 100;
1491 cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout);
1492 }
1493#ifdef CS_ANTICASC
1494 if( cfg->ac_denysamples+1 > cfg->ac_samples ) {
1495 cfg->ac_denysamples = cfg->ac_samples - 1;
1496 cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples);
1497 }
1498#endif
1499 return 0;
1500}
1501
1502void chk_account(char *token, char *value, struct s_auth *account)
1503{
1504 int i;
1505 char *ptr1;
1506
1507 if (!strcmp(token, "user")) {
1508 cs_strncpy(account->usr, value, sizeof(account->usr));
1509 return;
1510 }
1511
1512 if (!strcmp(token, "pwd")) {
1513 cs_strncpy(account->pwd, value, sizeof(account->pwd));
1514 return;
1515 }
1516
1517 if (!strcmp(token, "hostname")) {
1518 cs_strncpy((char *)account->dyndns, value, sizeof(account->dyndns));
1519 return;
1520 }
1521
1522 if (!strcmp(token, "betatunnel")) {
1523 if(strlen(value) == 0) {
1524 clear_tuntab(&account->ttab);
1525 return;
1526 } else {
1527 chk_tuntab(value, &account->ttab);
1528 return;
1529 }
1530 }
1531
1532 if (!strcmp(token, "uniq")) {
1533 if(strlen(value) == 0) {
1534 account->uniq = 0;
1535 return;
1536 } else {
1537 account->uniq = atoi(value);
1538 return;
1539 }
1540 }
1541
1542 if (!strcmp(token, "sleep")) {
1543 if(strlen(value) == 0) {
1544 account->tosleep = 0;
1545 return;
1546 } else {
1547 account->tosleep = atoi(value);
1548 return;
1549 }
1550 }
1551
1552 if (!strcmp(token, "sleepsend")) {
1553 if(strlen(value) == 0) {
1554 account->c35_sleepsend = 0;
1555 return;
1556 } else {
1557 account->c35_sleepsend = atoi(value);
1558 if (account->c35_sleepsend > 0xFF)
1559 account->c35_sleepsend = 0xFF;
1560 return;
1561 }
1562 }
1563
1564 if (!strcmp(token, "monlevel")) {
1565 if(strlen(value) == 0) {
1566 account->monlvl = 0;
1567 return;
1568 } else {
1569 account->monlvl = atoi(value);
1570 return;
1571 }
1572 }
1573
1574 if (!strcmp(token, "caid")) {
1575 if(strlen(value) == 0) {
1576 clear_caidtab(&account->ctab);
1577 return;
1578 } else {
1579 chk_caidtab(value, &account->ctab);
1580 return;
1581 }
1582 }
1583
1584 if (!strcmp(token, "disabled")) {
1585 if(strlen(value) == 0) {
1586 account->disabled = 0;
1587 return;
1588 } else {
1589 account->disabled = atoi(value);
1590 return;
1591 }
1592 }
1593
1594 if (!strcmp(token, "suppresscmd08")) {
1595 if(strlen(value) == 0) {
1596 account->c35_suppresscmd08 = 0;
1597 return;
1598 } else {
1599 account->c35_suppresscmd08=atoi(value);
1600 return;
1601 }
1602 }
1603
1604 if (!strcmp(token, "cccmaxhops")) {
1605 if (strlen(value) == 0) {
1606 account->cccmaxhops = 10;
1607 return;
1608 } else {
1609 account->cccmaxhops = atoi(value);
1610 return;
1611 }
1612 }
1613
1614 if (!strcmp(token, "cccreshare")) {
1615 if (strlen(value) == 0) {
1616 account->cccreshare = 10;
1617 return;
1618 } else {
1619 account->cccreshare = atoi(value);
1620 return;
1621 }
1622 }
1623
1624 if (!strcmp(token, "keepalive")) {
1625 if(strlen(value) == 0) {
1626 account->ncd_keepalive = 1;
1627 return;
1628 } else {
1629 account->ncd_keepalive = atoi(value);
1630 return;
1631 }
1632 }
1633 /*
1634 * case insensitive
1635 */
1636 strtolower(value);
1637
1638 if (!strcmp(token, "au")) {
1639 //set default values for usage during runtime from Webif
1640 account->au = -1;
1641 account->autoau=0;
1642
1643 if(value && value[0] == '1')
1644 account->autoau = 1;
1645 for (i = 0; i < CS_MAXREADER; i++)
1646 if ((reader[i].label[0]) && (!strncmp(reader[i].label, value, strlen(reader[i].label))))
1647 account->au = i;
1648 return;
1649 }
1650
1651 if (!strcmp(token, "group")) {
1652 account->grp = 0;
1653 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
1654 int g;
1655 g = atoi(ptr1);
1656 if ((g>0) && (g < 33)) account->grp|=(1<<(g-1));
1657 }
1658 return;
1659 }
1660
1661 if(!strcmp(token, "services")) {
1662 chk_services(value, &account->sidtabok, &account->sidtabno);
1663 return;
1664 }
1665
1666 if(!strcmp(token, "ident")) { /*ToDo ftab clear*/
1667 chk_ftab(value, &account->ftab, "user", account->usr, "provid");
1668 return;
1669 }
1670
1671 if(!strcmp(token, "class")) {
1672 chk_cltab(value, &account->cltab);
1673 return;
1674 }
1675
1676 if(!strcmp(token, "chid")) {
1677 chk_ftab(value, &account->fchid, "user", account->usr, "chid");
1678 return;
1679 }
1680
1681 if (!strcmp(token, "expdate")) {
1682 if (!value[0]) {
1683 account->expirationdate=(time_t)NULL;
1684 return;
1685 }
1686 struct tm cstime;
1687 memset(&cstime,0,sizeof(cstime));
1688 for (i=0, ptr1=strtok(value, "-/"); (i<3)&&(ptr1); ptr1=strtok(NULL, "-/"), i++) {
1689 switch(i) {
1690 case 0: cstime.tm_year=atoi(ptr1)-1900; break;
1691 case 1: cstime.tm_mon =atoi(ptr1)-1; break;
1692 case 2: cstime.tm_mday=atoi(ptr1); break;
1693 }
1694 }
1695 account->expirationdate=mktime(&cstime);
1696 return;
1697 }
1698
1699 if (!strcmp(token, "allowedtimeframe")) {
1700 if(strlen(value) == 0) {
1701 account->allowedtimeframe[0] = 0;
1702 account->allowedtimeframe[1] = 0;
1703 } else {
1704 int allowed[4];
1705 if (sscanf(value, "%d:%d-%d:%d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) != 4) {
1706 account->allowedtimeframe[0] = 0;
1707 account->allowedtimeframe[1] = 0;
1708 fprintf(stderr, "Warning: value '%s' is not valid for allowedtimeframe (hh:mm-hh:mm)\n", value);
1709 } else {
1710 account->allowedtimeframe[0] = (allowed[0]*60) + allowed[1];
1711 account->allowedtimeframe[1] = (allowed[2]*60) + allowed[3];
1712 }
1713 }
1714 return;
1715 }
1716
1717
1718#ifdef CS_ANTICASC
1719 if( !strcmp(token, "numusers") ) {
1720 account->ac_users = atoi(value);
1721 return;
1722 }
1723
1724 if( !strcmp(token, "penalty") ) {
1725 account->ac_penalty = atoi(value);
1726 return;
1727 }
1728#endif
1729
1730 if (token[0] != '#')
1731 fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n",token);
1732}
1733
1734int write_services()
1735{
1736 int i;
1737 FILE *f;
1738 struct s_sidtab *sidtab = cfg->sidtab;
1739 char tmpfile[256];
1740 char destfile[256];
1741 char bakfile[256];
1742
1743 snprintf(destfile, 255,"%s%s", cs_confdir, cs_sidt);
1744 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_sidt);
1745 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_sidt);
1746
1747 if (!(f=fopen(tmpfile, "w"))){
1748 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
1749 return(1);
1750 }
1751 fprintf(f,"# oscam.services generated automatically by Streamboard OSCAM %s build #%s\n", CS_VERSION, CS_SVN_VERSION);
1752 fprintf(f,"# Read more: http://streamboard.gmc.to/oscam/browser/trunk/Distribution/doc/txt/oscam.services.txt\n\n");
1753
1754 while(sidtab != NULL){
1755 fprintf(f,"[%s]\n", sidtab->label);
1756 fprintf_conf(f, CONFVARWIDTH, "caid", "");
1757 for (i=0; i<sidtab->num_caid; i++){
1758 if (i==0) fprintf(f,"%04X", sidtab->caid[i]);
1759 else fprintf(f,",%04X", sidtab->caid[i]);
1760 }
1761 fputc((int)'\n', f);
1762 fprintf_conf(f, CONFVARWIDTH, "provid", "");
1763 for (i=0; i<sidtab->num_provid; i++){
1764 if (i==0) fprintf(f,"%06lX", sidtab->provid[i]);
1765 else fprintf(f,",%06lX", sidtab->provid[i]);
1766 }
1767 fputc((int)'\n', f);
1768 fprintf_conf(f, CONFVARWIDTH, "srvid", "");
1769 for (i=0; i<sidtab->num_srvid; i++){
1770 if (i==0) fprintf(f,"%04X", sidtab->srvid[i]);
1771 else fprintf(f,",%04X", sidtab->srvid[i]);
1772 }
1773 fprintf(f,"\n\n");
1774 sidtab=sidtab->next;
1775 }
1776
1777 fclose(f);
1778 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
1779}
1780
1781int write_config()
1782{
1783 int i,j;
1784 FILE *f;
1785 char *dot = "", *dot1 = "", *dot2 = ""; //flags for delimiters
1786 char tmpfile[256];
1787 char destfile[256];
1788 char bakfile[256];
1789
1790 snprintf(destfile, 255,"%s%s", cs_confdir, cs_conf);
1791 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_conf);
1792 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_conf);
1793
1794 if (!(f=fopen(tmpfile, "w"))){
1795 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
1796 return(1);
1797 }
1798 fprintf(f,"# oscam.conf generated automatically by Streamboard OSCAM %s build #%s\n", CS_VERSION, CS_SVN_VERSION);
1799 fprintf(f,"# Read more: http://streamboard.gmc.to/oscam/browser/trunk/Distribution/doc/txt/oscam.conf.txt\n\n");
1800
1801 /*global settings*/
1802 fprintf(f,"[global]\n");
1803 if (cfg->srvip != 0)
1804 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->srvip));
1805 if (cfg->pidfile != NULL) fprintf_conf(f, CONFVARWIDTH, "pidfile", "%s\n", cfg->pidfile);
1806 if (cfg->usrfile != NULL) fprintf_conf(f, CONFVARWIDTH, "usrfile", "%s\n", cfg->usrfile);
1807 if (cfg->logfile != NULL) fprintf_conf(f, CONFVARWIDTH, "logfile", "%s\n", cfg->logfile);
1808 if (cfg->cwlogdir != NULL) fprintf_conf(f, CONFVARWIDTH, "cwlogdir", "%s\n", cfg->cwlogdir);
1809 fprintf_conf(f, CONFVARWIDTH, "disablelog", "%d\n", cfg->disablelog);
1810 fprintf_conf(f, CONFVARWIDTH, "disableuserfile", "%d\n", cfg->disableuserfile);
1811 fprintf_conf(f, CONFVARWIDTH, "usrfileflag", "%d\n", cfg->usrfileflag);
1812 fprintf_conf(f, CONFVARWIDTH, "clienttimeout", "%ld\n", cfg->ctimeout);
1813 fprintf_conf(f, CONFVARWIDTH, "fallbacktimeout", "%ld\n", cfg->ftimeout);
1814 fprintf_conf(f, CONFVARWIDTH, "clientmaxidle", "%d\n", cfg->cmaxidle);
1815 if(!cfg->delay == CS_DELAY)
1816 fprintf_conf(f, CONFVARWIDTH, "cachedelay", "%ld\n", cfg->delay); //deprecated
1817 fprintf_conf(f, CONFVARWIDTH, "bindwait", "%d\n", cfg->bindwait);
1818 fprintf_conf(f, CONFVARWIDTH, "netprio", "%ld\n", cfg->netprio);
1819 fprintf_conf(f, CONFVARWIDTH, "clientdyndns", "%d\n", cfg->clientdyndns);
1820 fprintf_conf(f, CONFVARWIDTH, "resolvedelay", "%d\n", cfg->resolvedelay);
1821 if (cfg->tosleep) fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", cfg->tosleep);
1822 fprintf_conf(f, CONFVARWIDTH, "unlockparental", "%d\n", cfg->ulparent);
1823 fprintf_conf(f, CONFVARWIDTH, "nice", "%d\n", cfg->nice);
1824 fprintf_conf(f, CONFVARWIDTH, "serialreadertimeout", "%d\n", cfg->srtimeout);
1825 fprintf_conf(f, CONFVARWIDTH, "maxlogsize", "%d\n", cfg->max_log_size);
1826 fprintf_conf(f, CONFVARWIDTH, "waitforcards", "%d\n", cfg->waitforcards);
1827 fprintf_conf(f, CONFVARWIDTH, "preferlocalcards", "%d\n", cfg->preferlocalcards);
1828 fprintf_conf(f, CONFVARWIDTH, "saveinithistory", "%d\n", cfg->saveinithistory);
1829 fprintf_conf(f, CONFVARWIDTH, "readerrestartseconds", "%d\n", cfg->reader_restart_seconds);
1830
1831 fprintf_conf(f, CONFVARWIDTH, "lb_mode", "%d\n", cfg->lb_mode);
1832 fprintf_conf(f, CONFVARWIDTH, "lb_save", "%d\n", cfg->lb_save);
1833 fprintf_conf(f, CONFVARWIDTH, "lb_nbest_readers", "%d\n", cfg->lb_nbest_readers);
1834 fprintf_conf(f, CONFVARWIDTH, "lb_nfb_readers", "%d\n", cfg->lb_nfb_readers);
1835 fprintf_conf(f, CONFVARWIDTH, "lb_min_ecmcount", "%d\n", cfg->lb_min_ecmcount);
1836 fprintf_conf(f, CONFVARWIDTH, "lb_max_ecmcount", "%d\n", cfg->lb_max_ecmcount);
1837 fprintf_conf(f, CONFVARWIDTH, "lb_reopen_seconds", "%d\n", cfg->lb_reopen_seconds);
1838
1839 fprintf_conf(f, CONFVARWIDTH, "resolvegethostbyname", "%d\n", cfg->resolve_gethostbyname);
1840
1841#ifdef CS_WITH_DOUBLECHECK
1842 fprintf_conf(f, CONFVARWIDTH, "double_check", "%d\n", cfg->double_check);
1843#endif
1844
1845 fputc((int)'\n', f);
1846
1847 /*monitor settings*/
1848 if(cfg->mon_port || cfg->mon_appendchaninfo || cfg->mon_hideclient_to) {
1849 fprintf(f,"[monitor]\n");
1850 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->mon_port);
1851 if (cfg->mon_srvip != 0)
1852 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
1853
1854 fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
1855 struct s_ip *cip;
1856 for (cip = cfg->mon_allowed; cip; cip = cip->next){
1857 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
1858 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
1859 dot=",";
1860 }
1861 fputc((int)'\n', f);
1862 fprintf_conf(f, CONFVARWIDTH, "aulow", "%d\n", cfg->mon_aulow);
1863 fprintf_conf(f, CONFVARWIDTH, "hideclient_to", "%d\n", cfg->mon_hideclient_to);
1864 fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", cfg->mon_level);
1865 fprintf_conf(f, CONFVARWIDTH, "appendchaninfo", "%d\n", cfg->mon_appendchaninfo);
1866 fputc((int)'\n', f);
1867 }
1868
1869 /*newcamd*/
1870 if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
1871 fprintf(f,"[newcamd]\n");
1872 fprintf_conf(f, CONFVARWIDTH, "port", "");
1873 dot1 = "";
1874 for(i = 0; i < cfg->ncd_ptab.nports; ++i){
1875 fprintf(f,"%s%d@%04X", dot1, cfg->ncd_ptab.ports[i].s_port, cfg->ncd_ptab.ports[i].ftab.filts[0].caid);
1876
1877 // separate DES Key
1878 if(cfg->ncd_ptab.ports[i].ncd_key_is_set){
1879 int k;
1880 fprintf(f,"{");
1881 for (k = 0; k < 14; k++)
1882 fprintf(f,"%02X", cfg->ncd_ptab.ports[i].ncd_key[k]);
1883 fprintf(f,"}");
1884 }
1885
1886 if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){
1887 fprintf(f,":");
1888 dot2 = "";
1889 for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){
1890 fprintf(f,"%s%06X", dot2, (int)cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
1891 dot2 = ",";
1892 }
1893 }
1894 dot1=";";
1895 }
1896
1897 fputc((int)'\n', f);
1898 if (cfg->ncd_srvip != 0)
1899 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
1900 fprintf_conf(f, CONFVARWIDTH, "key", "");
1901 for (i = 0; i < 14; i++) fprintf(f,"%02X", cfg->ncd_key[i]);
1902 fprintf(f,"\n");
1903 fprintf_conf(f, CONFVARWIDTH, "allowed", "");
1904 struct s_ip *cip;
1905 dot="";
1906 for (cip = cfg->ncd_allowed; cip; cip = cip->next){
1907 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
1908 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
1909 dot=",";
1910 }
1911 fprintf(f,"\n");
1912 fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", cfg->ncd_keepalive);
1913 fprintf_conf(f, CONFVARWIDTH, "mgclient", "%d\n", cfg->ncd_mgclient);
1914 fprintf(f,"\n");
1915 }
1916
1917 /*camd3.3*/
1918 if ( cfg->c33_port > 0) {
1919 fprintf(f,"[camd33]\n");
1920 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c33_port);
1921 if (cfg->c33_srvip != 0)
1922 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
1923 fprintf_conf(f, CONFVARWIDTH, "passive", "%d\n", cfg->c33_passive);
1924 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);
1925 fprintf_conf(f, CONFVARWIDTH, "nocrypt", "");
1926 struct s_ip *cip;
1927 dot="";
1928 for (cip = cfg->c33_plain; cip; cip = cip->next){
1929 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
1930 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
1931 dot=",";
1932 }
1933 fprintf(f,"\n\n");
1934 }
1935
1936 /*camd3.5*/
1937 if ( cfg->c35_port > 0) {
1938 fprintf(f,"[cs357x]\n");
1939 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c35_port);
1940 if (cfg->c35_srvip != 0)
1941 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_srvip));
1942 if (cfg->c35_suppresscmd08)
1943 fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", cfg->c35_suppresscmd08);
1944 fprintf(f,"\n");
1945 }
1946
1947 /*camd3.5 TCP*/
1948 if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)) {
1949 fprintf(f,"[cs378x]\n");
1950 fprintf_conf(f, CONFVARWIDTH, "port", "");
1951 dot1 = "";
1952 for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){
1953 fprintf(f,"%s%d@%04X", dot1, cfg->c35_tcp_ptab.ports[i].s_port, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].caid);
1954 if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 1){
1955 fprintf(f,":");
1956 dot2 = "";
1957 for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){
1958 fprintf(f,"%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
1959 dot2 = ",";
1960 }
1961 }
1962 dot1=";";
1963 }
1964
1965 fputc((int)'\n', f);
1966 if (cfg->c35_tcp_srvip != 0)
1967 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
1968 fputc((int)'\n', f);
1969 }
1970
1971 /*Radegast*/
1972 if ( cfg->rad_port > 0) {
1973 fprintf(f,"[radegast]\n");
1974 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->rad_port);
1975 if (cfg->rad_srvip != 0)
1976 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
1977 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->rad_usr);
1978 fprintf_conf(f, CONFVARWIDTH, "allowed", "");
1979 struct s_ip *cip;
1980 dot="";
1981 for (cip = cfg->rad_allowed; cip; cip = cip->next){
1982 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
1983 if (cip->ip[0] != cip->ip[1])
1984 fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
1985 dot=",";
1986 }
1987 fprintf(f,"\n\n");
1988 }
1989
1990#ifdef CS_WITH_GBOX
1991 /*Gbox*/
1992 if ((cfg->gbox_pwd[0] > 0) || (cfg->gbox_pwd[1] > 0) || (cfg->gbox_pwd[2] > 0) || (cfg->gbox_pwd[3] > 0)){
1993 fprintf(f,"[gbox]\n");
1994 fprintf_conf(f, CONFVARWIDTH, "password", ""); for (i=0;i<4;i++) fprintf(f,"%02X", cfg->gbox_pwd[i]); fputc((int)'\n', f);;
1995 fprintf_conf(f, CONFVARWIDTH, "maxdist", "%d\n", cfg->maxdist);
1996 fprintf_conf(f, CONFVARWIDTH, "ignorelist", "%s\n", cfg->ignorefile);
1997 fprintf_conf(f, CONFVARWIDTH, "onlineinfos", "%s\n", cfg->gbxShareOnl);
1998 fprintf_conf(f, CONFVARWIDTH, "cardinfos", "%s\n", cfg->cardfile);
1999 fprintf_conf(f, CONFVARWIDTH, "locals", "");
2000 char *dot = "";
2001 for (i = 0; i < cfg->num_locals; i++){
2002 fprintf(f,"%s%06lX", dot, cfg->locals[i]);
2003 dot=";";
2004 }
2005 fprintf(f,"\n\n");
2006 }
2007#endif
2008
2009 /*serial*/
2010 if (cfg->ser_device[0]){
2011 fprintf(f,"[serial]\n");
2012 char sdevice[512];
2013 cs_strncpy(sdevice, cfg->ser_device, sizeof(sdevice));
2014 char *ptr;
2015 char delimiter[2]; delimiter[0] = 1; delimiter[1] = '\0';
2016
2017 ptr = strtok(sdevice, delimiter);
2018 while(ptr != NULL) {
2019 fprintf_conf(f, CONFVARWIDTH, "device", "%s\n", ptr);
2020 ptr = strtok(NULL, delimiter);
2021 }
2022 fprintf(f,"\n");
2023 }
2024
2025 /*cccam*/
2026 if ( cfg->cc_port > 0) {
2027 fprintf(f,"[cccam]\n");
2028 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->cc_port);
2029 fprintf_conf(f, CONFVARWIDTH, "reshare", "%d\n", cfg->cc_reshare);
2030 fprintf_conf(f, CONFVARWIDTH, "version", "%s\n", cfg->cc_version);
2031 fprintf_conf(f, CONFVARWIDTH, "updateinterval", "%d\n", cfg->cc_update_interval);
2032 fprintf_conf(f, CONFVARWIDTH, "minimizecards", "%d\n", cfg->cc_minimize_cards);
2033 fprintf(f,"\n");
2034 }
2035
2036#ifdef HAVE_DVBAPI
2037 /*dvb-api*/
2038 if (cfg->dvbapi_enabled > 0) {
2039 fprintf(f,"[dvbapi]\n");
2040 fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->dvbapi_enabled);
2041 fprintf_conf(f, CONFVARWIDTH, "au", "%d\n", cfg->dvbapi_au);
2042 fprintf_conf(f, CONFVARWIDTH, "boxtype", "%s\n", boxdesc[cfg->dvbapi_boxtype]);
2043 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->dvbapi_usr);
2044 fprintf_conf(f, CONFVARWIDTH, "pmt_mode", "%d\n", cfg->dvbapi_pmtmode);
2045
2046 ulong provid = 0;
2047 if(cfg->dvbapi_prioritytab.caid[0]) {
2048 fprintf_conf(f, CONFVARWIDTH, "priority", "");
2049 i = 0;
2050 dot = "";
2051 while(cfg->dvbapi_prioritytab.caid[i]) {
2052 fprintf(f, "%s%04X", dot, cfg->dvbapi_prioritytab.caid[i]);
2053 if(cfg->dvbapi_prioritytab.mask[i]) {
2054 provid = (cfg->dvbapi_prioritytab.cmap[i] << 8 | cfg->dvbapi_prioritytab.mask[i]);
2055 fprintf(f, ":%06lX", provid);
2056 }
2057 dot = ",";
2058 i++;
2059 }
2060 fprintf(f,"\n");
2061 }
2062
2063 if(cfg->dvbapi_ignoretab.caid[0]) {
2064 provid = 0;
2065 fprintf_conf(f, CONFVARWIDTH, "ignore", "");
2066 i = 0;
2067 dot = "";
2068 while(cfg->dvbapi_ignoretab.caid[i]) {
2069 fprintf(f, "%s%04X", dot, cfg->dvbapi_ignoretab.caid[i]);
2070 if(cfg->dvbapi_ignoretab.mask[i]) {
2071 provid = (cfg->dvbapi_ignoretab.cmap[i] << 8 | cfg->dvbapi_ignoretab.mask[i]);
2072 fprintf(f, ":%06lX", provid);
2073 }
2074 dot = ",";
2075 i++;
2076 }
2077 fprintf(f,"\n");
2078 }
2079
2080 if(cfg->dvbapi_delaytab.caid[0]) {
2081 fprintf_conf(f, CONFVARWIDTH, "cw_delay", "");
2082 i = 0;
2083 dot = "";
2084 while(cfg->dvbapi_delaytab.caid[i]) {
2085 fprintf(f, "%s%04X", dot, cfg->dvbapi_delaytab.caid[i]);
2086 fprintf(f, ":%d", cfg->dvbapi_delaytab.mask[i]);
2087 dot = ",";
2088 i++;
2089 }
2090 fprintf(f,"\n");
2091 }
2092
2093 fputc((int)'\n', f);
2094 }
2095#endif
2096
2097#ifdef WEBIF
2098 /*webinterface*/
2099 if (cfg->http_port > 0) {
2100 fprintf(f,"[webif]\n");
2101 fprintf_conf(f, CONFVARWIDTH, "httpport", "%d\n", cfg->http_port);
2102 if(strlen(cfg->http_user) > 0)
2103 fprintf_conf(f, CONFVARWIDTH, "httpuser", "%s\n", cfg->http_user);
2104 if(strlen(cfg->http_pwd) > 0)
2105 fprintf_conf(f, CONFVARWIDTH, "httppwd", "%s\n", cfg->http_pwd);
2106 if(strlen(cfg->http_css) > 0)
2107 fprintf_conf(f, CONFVARWIDTH, "httpcss", "%s\n", cfg->http_css);
2108 if(strlen(cfg->http_tpl) > 0)
2109 fprintf_conf(f, CONFVARWIDTH, "httptpl", "%s\n", cfg->http_tpl);
2110 if(strlen(cfg->http_script) > 0)
2111 fprintf_conf(f, CONFVARWIDTH, "httpscript", "%s\n", cfg->http_script);
2112 fprintf_conf(f, CONFVARWIDTH, "httprefresh", "%d\n", cfg->http_refresh);
2113 fprintf_conf(f, CONFVARWIDTH, "httpallowed", "");
2114 struct s_ip *cip;
2115 dot = "";
2116 for (cip = cfg->http_allowed; cip; cip = cip->next){
2117 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0]));
2118 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1]));
2119 dot = ",";
2120 }
2121 fputc((int)'\n', f);
2122 if(strlen((const char *) (cfg->http_dyndns)) > 0)
2123 fprintf_conf(f, CONFVARWIDTH, "httpdyndns", "%s\n", cfg->http_dyndns);
2124 fprintf_conf(f, CONFVARWIDTH, "httphideidleclients", "%d\n", cfg->http_hide_idle_clients);
2125 fprintf_conf(f, CONFVARWIDTH, "httpreadonly", "%d\n", cfg->http_readonly);
2126 fputc((int)'\n', f);
2127 }
2128#endif
2129
2130#ifdef CS_ANTICASC
2131 if(cfg->ac_enabled) {
2132 fprintf(f,"[anticasc]\n");
2133 fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->ac_enabled);
2134 fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", cfg->ac_users);
2135 fprintf_conf(f, CONFVARWIDTH, "sampletime", "%d\n", cfg->ac_stime);
2136 fprintf_conf(f, CONFVARWIDTH, "samples", "%d\n", cfg->ac_samples);
2137 fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", cfg->ac_penalty);
2138 fprintf_conf(f, CONFVARWIDTH, "aclogfile", "%s\n", cfg->ac_logfile);
2139 fprintf_conf(f, CONFVARWIDTH, "denysamples", "%d\n", cfg->ac_denysamples);
2140 fprintf_conf(f, CONFVARWIDTH, "fakedelay", "%d\n", cfg->ac_fakedelay);
2141 fputc((int)'\n', f);
2142 }
2143#endif
2144
2145 fclose(f);
2146
2147 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
2148}
2149
2150int write_userdb(struct s_auth *authptr)
2151{
2152 int i;
2153 FILE *f;
2154 struct s_auth *account;
2155 char *dot = ""; //flag for comma
2156 char tmpfile[256];
2157 char destfile[256];
2158 char bakfile[256];
2159
2160 snprintf(destfile, 255,"%s%s", cs_confdir, cs_user);
2161 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_user);
2162 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_user);
2163
2164 if (!(f=fopen(tmpfile, "w"))){
2165 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
2166 return(1);
2167 }
2168 fprintf(f,"# oscam.user generated automatically by Streamboard OSCAM %s build #%s\n", CS_VERSION, CS_SVN_VERSION);
2169 fprintf(f,"# Read more: http://streamboard.gmc.to/oscam/browser/trunk/Distribution/doc/txt/oscam.user.txt\n\n");
2170
2171 //each account
2172 for (account=authptr; (account) ; account=account->next){
2173 fprintf(f,"[account]\n");
2174 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", account->usr);
2175 fprintf_conf(f, CONFVARWIDTH, "pwd", "%s\n", account->pwd);
2176 fprintf_conf(f, CONFVARWIDTH, "disabled", "%d\n", account->disabled);
2177 struct tm * timeinfo = localtime (&account->expirationdate);
2178 char buf [80];
2179 strftime (buf,80,"%Y-%m-%d",timeinfo);
2180 if(strcmp(buf,"1970-01-01"))
2181 fprintf_conf(f, CONFVARWIDTH, "expdate", "%s\n", buf);
2182 else
2183 fprintf_conf(f, CONFVARWIDTH, "expdate", "\n");
2184
2185 if(account->allowedtimeframe[0] && account->allowedtimeframe[1]) {
2186 fprintf_conf(f, CONFVARWIDTH, "allowedtimeframe", "%02d:%02d-%02d:%02d\n",
2187 account->allowedtimeframe[0]/60,
2188 account->allowedtimeframe[0]%60,
2189 account->allowedtimeframe[1]/60,
2190 account->allowedtimeframe[1]%60 );
2191 }
2192
2193 //group
2194 char *value = mk_t_group((ulong*)account->grp);
2195 fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value);
2196 free(value);
2197
2198 fprintf_conf(f, CONFVARWIDTH, "hostname", "%s\n", account->dyndns);
2199 fprintf_conf(f, CONFVARWIDTH, "uniq", "%d\n", account->uniq);
2200 fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", account->tosleep);
2201 fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", account->monlvl);
2202
2203 if (account->au > -1)
2204 if (account->au < CS_MAXREADER)
2205 fprintf_conf(f, CONFVARWIDTH, "au", "%s\n", reader[account->au].label);
2206 if (account->autoau == 1) fprintf_conf(f, CONFVARWIDTH, "au", "1\n");
2207
2208 fprintf_conf(f, CONFVARWIDTH, "services", "");
2209 char sidok[33]; long2bitchar(account->sidtabok,sidok);
2210 char sidno[33]; long2bitchar(account->sidtabno,sidno);
2211 struct s_sidtab *sidtab = cfg->sidtab;
2212 i=0; dot = "";
2213 for (; sidtab; sidtab=sidtab->next){
2214 if(sidok[i]=='1') {fprintf(f,"%s%s", dot, sidtab->label); dot = ",";}
2215 if(sidno[i]=='1') {fprintf(f,"%s!%s", dot, sidtab->label); dot = ",";}
2216 i++;
2217 }
2218 fputc((int)'\n', f);
2219
2220 //CAID
2221 value = mk_t_caidtab(&account->ctab);
2222 fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value);
2223 free(value);
2224
2225 //betatunnel
2226 value = mk_t_tuntab(&account->ttab);
2227 fprintf_conf(f, CONFVARWIDTH, "betatunnel", "%s\n", value);
2228 free(value);
2229
2230 //ident
2231 value = mk_t_ftab(&account->ftab);
2232 fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value);
2233 free(value);
2234
2235 //CHID
2236 value = mk_t_ftab(&account->fchid);
2237 fprintf_conf(f, CONFVARWIDTH, "chid", "%s\n", value);
2238 free(value);
2239
2240 if (account->c35_suppresscmd08)
2241 fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", account->c35_suppresscmd08);
2242
2243 if (account->cccmaxhops)
2244 fprintf_conf(f, CONFVARWIDTH, "cccmaxhops", "%d\n", account->cccmaxhops);
2245
2246 if (account->cccreshare)
2247 fprintf_conf(f, CONFVARWIDTH, "cccreshare", "%d\n", account->cccreshare);
2248
2249 if (account->c35_sleepsend)
2250 fprintf_conf(f, CONFVARWIDTH, "sleepsend", "%d\n", account->c35_sleepsend);
2251
2252 fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", account->ncd_keepalive);
2253
2254#ifdef CS_ANTICASC
2255 fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", account->ac_users);
2256 fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", account->ac_penalty);
2257#endif
2258 fputc((int)'\n', f);
2259 }
2260 fclose(f);
2261
2262 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
2263}
2264
2265int write_server()
2266{
2267 int i,j;
2268 int isphysical = 0;
2269 char *value;
2270 FILE *f;
2271
2272 char *dot = ""; //flag for comma
2273 char tmpfile[256];
2274 char destfile[256];
2275 char bakfile[256];
2276
2277 snprintf(destfile, 255,"%s%s", cs_confdir, cs_srvr);
2278 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_srvr);
2279 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_srvr);
2280
2281 if (!(f=fopen(tmpfile, "w"))){
2282 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno);
2283 return(1);
2284 }
2285 fprintf(f,"# oscam.server generated automatically by Streamboard OSCAM %s build #%s\n", CS_VERSION, CS_SVN_VERSION);
2286 fprintf(f,"# Read more: http://streamboard.gmc.to/oscam/browser/trunk/Distribution/doc/txt/oscam.server.txt\n\n");
2287
2288 for (i = 0; i < CS_MAXREADER; i++) {
2289 if ( reader[i].label[0] && !reader[i].deleted) {
2290 isphysical = 0;
2291 fprintf(f,"[reader]\n");
2292
2293 fprintf_conf(f, CONFVARWIDTH, "label", "%s\n", reader[i].label);
2294 fprintf_conf(f, CONFVARWIDTH, "enable", "%d\n", reader[i].enable);
2295
2296 char *ctyp ="";
2297 switch(reader[i].typ) { /* TODO like ph*/
2298 case R_MP35 :
2299 ctyp = "mp35";
2300 isphysical = 1;
2301 break;
2302 case R_MOUSE :
2303 ctyp = "mouse";
2304 isphysical = 1;
2305 break;
2306 case R_INTERNAL :
2307 ctyp = "internal";
2308 isphysical = 1;
2309 break;
2310 case R_SC8in1 :
2311 ctyp = "sc8in1";
2312 isphysical = 1;
2313 break;
2314 case R_SMART :
2315 ctyp = "smartreader";
2316 isphysical = 1;
2317 break;
2318 case R_CAMD35 : ctyp = "camd35"; break;
2319 case R_CAMD33 : ctyp = "camd33"; break;
2320 case R_NEWCAMD :
2321 if (reader[i].ncd_proto == NCD_524)
2322 ctyp = "newcamd524";
2323 else
2324 ctyp = "newcamd";
2325 break;
2326 case R_RADEGAST : ctyp = "radegast"; break;
2327 case R_SERIAL : ctyp = "serial"; break;
2328#ifdef CS_WITH_GBOX
2329 case R_GBOX : ctyp = "gbox"; break;
2330#endif
2331#ifdef HAVE_PCSC
2332 case R_PCSC : ctyp = "pcsc"; break;
2333#endif
2334 case R_CCCAM : ctyp = "cccam"; break;
2335 case R_CONSTCW : ctyp = "constcw"; break;
2336 case R_CS378X : ctyp = "cs378x"; break;
2337 case R_DB2COM1 :
2338 ctyp = "mouse";
2339 isphysical = 1;
2340 break;
2341 case R_DB2COM2 :
2342 ctyp = "mouse";
2343 isphysical = 1;
2344 break;
2345
2346 }
2347 fprintf_conf(f, CONFVARWIDTH, "protocol", "%s\n", ctyp);
2348
2349 fprintf_conf(f, CONFVARWIDTH, "device", "%s", reader[i].device);
2350 if (reader[i].r_port)
2351 fprintf(f, ",%d", reader[i].r_port);
2352 if (reader[i].l_port)
2353 fprintf(f, ",%d", reader[i].l_port);
2354 fprintf(f, "\n");
2355
2356 if (reader[i].ncd_key[0] || reader[i].ncd_key[13]) {
2357 fprintf_conf(f, CONFVARWIDTH, "key", "");
2358 for (j = 0; j < 14; j++) {
2359 fprintf(f, "%02X", reader[i].ncd_key[j]);
2360 }
2361 fprintf(f, "\n");
2362 }
2363
2364#ifdef CS_WITH_GBOX
2365 if (reader[i].typ == R_GBOX) {
2366 fprintf_conf(f, CONFVARWIDTH, "password", "%s\n", reader[i].gbox_pwd);
2367 fprintf_conf(f, CONFVARWIDTH, "premium", "%d\n", reader[i].gbox_prem);
2368 }
2369#endif
2370
2371 if (reader[i].r_usr[0] && !isphysical)
2372 fprintf_conf(f, CONFVARWIDTH, "account", "%s,%s\n", reader[i].r_usr, reader[i].r_pwd);
2373
2374 if(strcmp(reader[i].pincode, "none"))
2375 fprintf_conf(f, CONFVARWIDTH, "pincode", "%s\n", reader[i].pincode);
2376
2377 if (reader[i].emmfile && isphysical)
2378 fprintf_conf(f, CONFVARWIDTH, "readnano", "%s\n", reader[i].emmfile);
2379
2380 fprintf_conf(f, CONFVARWIDTH, "services", "");
2381 char sidok[33]; long2bitchar(reader[i].sidtabok, sidok);
2382 char sidno[33]; long2bitchar(reader[i].sidtabno, sidno);
2383 struct s_sidtab *sidtab = cfg->sidtab;
2384 j=0; dot = "";
2385 for (; sidtab; sidtab=sidtab->next){
2386 if(sidok[j]=='1') {fprintf(f,"%s%s", dot, sidtab->label); dot = ",";}
2387 if(sidno[j]=='1') {fprintf(f,"%s!%s", dot, sidtab->label); dot = ",";}
2388 j++;
2389 }
2390 fputc((int)'\n', f);
2391
2392 if (reader[i].tcp_ito && !isphysical)
2393 fprintf_conf(f, CONFVARWIDTH, "inactivitytimeout", "%d\n", reader[i].tcp_ito);
2394
2395 if (reader[i].tcp_rto && !isphysical && !reader[i].tcp_rto == 30)
2396 fprintf_conf(f, CONFVARWIDTH, "reconnecttimeout", "%d\n", reader[i].tcp_rto);
2397
2398 if (reader[i].ncd_disable_server_filt && !isphysical)
2399 fprintf_conf(f, CONFVARWIDTH, "disableserverfilter", "%d\n", reader[i].ncd_disable_server_filt);
2400
2401 if (reader[i].smargopatch && isphysical)
2402 fprintf_conf(f, CONFVARWIDTH, "smargopatch", "%d\n", reader[i].smargopatch);
2403
2404 if (reader[i].fallback)
2405 fprintf_conf(f, CONFVARWIDTH, "fallback", "%d\n", reader[i].fallback);
2406
2407 if (reader[i].log_port)
2408 fprintf_conf(f, CONFVARWIDTH, "logport", "%d\n", reader[i].log_port);
2409
2410 value = mk_t_caidtab(&reader[i].ctab);
2411 fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value);
2412 free(value);
2413
2414 if (reader[i].boxid && isphysical)
2415 fprintf_conf(f, CONFVARWIDTH, "boxid", "%08X\n", reader[i].boxid);
2416
2417 if (reader[i].aes_key[0] && isphysical)
2418 fprintf_conf(f, CONFVARWIDTH, "aeskey", "%s\n", key_btoa(NULL, reader[i].aes_key));
2419
2420
2421 //check for rsa
2422 for (j=0;j<64;j++) {
2423 if(reader[i].rsa_mod[j] > 0) {
2424 reader[i].has_rsa = 1;
2425 break;
2426 }
2427 }
2428
2429 //check for tiger
2430 int tigerkey = 0;
2431 for (j=64;j<120;j++) {
2432 if(reader[i].rsa_mod[j] > 0) {
2433 tigerkey = 1;
2434 break;
2435 }
2436 }
2437
2438 //n3_rsakey
2439 if (reader[i].has_rsa) {
2440 if (!tigerkey) {
2441 fprintf_conf(f, CONFVARWIDTH, "rsakey", "");
2442 for (j=0;j<64;j++) {
2443 fprintf(f, "%02X", reader[i].rsa_mod[j]);
2444 }
2445 fprintf(f, "\n");
2446 }
2447 else {
2448 //tiger_rsakey
2449 if (tigerkey) {
2450 fprintf_conf(f, CONFVARWIDTH, "tiger_rsakey", "");
2451 for (j=0;j<120;j++) {
2452 fprintf(f, "%02X", reader[i].rsa_mod[j]);
2453 }
2454 fprintf(f, "\n");
2455 }
2456 }
2457 }
2458
2459 if (reader[i].force_irdeto && isphysical) {
2460 fprintf_conf(f, CONFVARWIDTH, "force_irdeto", "%d\n", reader[i].force_irdeto);
2461 }
2462
2463 if (reader[i].nagra_boxkey[0] && isphysical) {
2464 fprintf_conf(f, CONFVARWIDTH, "boxkey", "");
2465 for (j=0;j<8;j++) {
2466 fprintf(f, "%02X", reader[i].nagra_boxkey[j]);
2467 }
2468 fprintf(f, "\n");
2469 }
2470
2471 if ( reader[i].atr[0] && isphysical) {
2472 fprintf_conf(f, CONFVARWIDTH, "atr", "");
2473 for (j=0; j < reader[i].atrlen/2; j++) {
2474 fprintf(f, "%02X", reader[i].atr[j]);
2475 }
2476 fprintf(f, "\n");
2477 }
2478
2479 if (isphysical) {
2480 if (reader[i].detect&0x80)
2481 fprintf_conf(f, CONFVARWIDTH, "detect", "!%s\n", RDR_CD_TXT[reader[i].detect&0x7f]);
2482 else
2483 fprintf_conf(f, CONFVARWIDTH, "detect", "%s\n", RDR_CD_TXT[reader[i].detect&0x7f]);
2484 }
2485
2486 if (reader[i].mhz && isphysical)
2487 fprintf_conf(f, CONFVARWIDTH, "mhz", "%d\n", reader[i].mhz);
2488
2489 if (reader[i].cardmhz && isphysical)
2490 fprintf_conf(f, CONFVARWIDTH, "cardmhz", "%d\n", reader[i].cardmhz);
2491
2492 value = mk_t_ftab(&reader[i].ftab);
2493 fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value);
2494 free(value);
2495
2496 //Todo: write reader class
2497
2498 value = mk_t_ftab(&reader[i].fchid);
2499 if(value[0])
2500 fprintf_conf(f, CONFVARWIDTH, "chid", "%s\n", value);
2501 free(value);
2502
2503 if (reader[i].show_cls && !reader[i].show_cls == 10)
2504 fprintf_conf(f, CONFVARWIDTH, "showcls", "%d\n", reader[i].show_cls);
2505
2506 if (reader[i].maxqlen && !reader[i].maxqlen == CS_MAXQLEN)
2507 fprintf_conf(f, CONFVARWIDTH, "maxqlen", "%d\n", reader[i].maxqlen);
2508
2509 value = mk_t_group((ulong*)reader[i].grp);
2510 fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value);
2511 free(value);
2512
2513 if (reader[i].cachemm)
2514 fprintf_conf(f, CONFVARWIDTH, "emmcache", "%d,%d,%d\n", reader[i].cachemm, reader[i].rewritemm, reader[i].logemm);
2515
2516 if (reader[i].cachecm)
2517 fprintf_conf(f, CONFVARWIDTH, "ecmcache", "%d\n", reader[i].cachecm);
2518 else
2519 fprintf_conf(f, CONFVARWIDTH, "ecmcache", "%d\n", 0);
2520
2521 //Todo: write blocknano
2522
2523 if (reader[i].blockemm_unknown)
2524 fprintf_conf(f, CONFVARWIDTH, "blockemm-unknown", "%d\n", reader[i].blockemm_unknown);
2525
2526 if (reader[i].blockemm_u)
2527 fprintf_conf(f, CONFVARWIDTH, "blockemm-u", "%d\n", reader[i].blockemm_u);
2528
2529 if (reader[i].blockemm_s)
2530 fprintf_conf(f, CONFVARWIDTH, "blockemm-s", "%d\n", reader[i].blockemm_s);
2531
2532 if (reader[i].blockemm_g)
2533 fprintf_conf(f, CONFVARWIDTH, "blockemm-g", "%d\n", reader[i].blockemm_g);
2534
2535 if (reader[i].lb_weight)
2536 fprintf_conf(f, CONFVARWIDTH, "lb_weight", "%d\n", reader[i].lb_weight);
2537
2538 //Todo: write savenano
2539
2540 if (reader[i].typ == R_CCCAM) {
2541 if (reader[i].cc_version[0])
2542 fprintf_conf(f, CONFVARWIDTH, "cccversion", "%s\n", reader[i].cc_version);
2543
2544 if (reader[i].cc_maxhop)
2545 fprintf_conf(f, CONFVARWIDTH, "cccmaxhops", "%d\n", reader[i].cc_maxhop);
2546
2547 if (reader[i].cc_disable_retry_ecm)
2548 fprintf_conf(f, CONFVARWIDTH, "cccdisableretryecm", "%d\n", reader[i].cc_disable_retry_ecm);
2549
2550 if (reader[i].cc_disable_auto_block)
2551 fprintf_conf(f, CONFVARWIDTH, "cccdisableautoblock", "%d\n", reader[i].cc_disable_auto_block);
2552
2553 if (reader[i].cc_want_emu)
2554 fprintf_conf(f, CONFVARWIDTH, "cccwantemu", "%d\n", reader[i].cc_want_emu);
2555
2556 if (reader[i].cc_keepalive)
2557 fprintf_conf(f, CONFVARWIDTH, "ccckeepalive", "%d\n", reader[i].cc_keepalive);
2558 }
2559
2560 if (reader[i].deprecated && isphysical)
2561 fprintf_conf(f, CONFVARWIDTH, "deprecated", "%d\n", reader[i].deprecated);
2562
2563 if (reader[i].audisabled)
2564 fprintf_conf(f, CONFVARWIDTH, "audisabled", "%d\n", reader[i].audisabled);
2565
2566 if (reader[i].auprovid)
2567 fprintf_conf(f, CONFVARWIDTH, "auprovid", "%06lX", reader[i].auprovid);
2568
2569 if (reader[i].ndsversion && isphysical)
2570 fprintf_conf(f, CONFVARWIDTH, "ndsversion", "%d\n", reader[i].ndsversion);
2571
2572 fprintf(f, "\n\n");
2573 }
2574 }
2575 fclose(f);
2576
2577 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0));
2578}
2579
2580int init_userdb(struct s_auth **authptr_org)
2581{
2582 struct s_auth *authptr = *authptr_org;
2583 int tag = 0, nr, nro, expired, disabled;
2584 //int first=1;
2585 FILE *fp;
2586 char *value;
2587 struct s_auth *ptr;
2588 /*static */struct s_auth *account=(struct s_auth *)0;
2589
2590 sprintf(token, "%s%s", cs_confdir, cs_user);
2591 if (!(fp = fopen(token, "r"))) {
2592 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
2593 return(1);
2594 }
2595
2596 for (nro = 0, ptr = authptr; ptr; nro++) {
2597 struct s_auth *ptr_next;
2598 ptr_next = ptr->next;
2599 free(ptr);
2600 ptr = ptr_next;
2601 }
2602 nr = 0;
2603
2604 while (fgets(token, sizeof(token), fp)) {
2605 int i, l;
2606 void *ptr;
2607
2608 if ((l=strlen(trim(token))) < 3)
2609 continue;
2610
2611 if ((token[0] == '[') && (token[l-1] == ']')) {
2612 token[l - 1] = 0;
2613 tag = (!strcmp("account", strtolower(token + 1)));
2614
2615 if (!(ptr=malloc(sizeof(struct s_auth)))) {
2616 cs_log("Error allocating memory (errno=%d)", errno);
2617 return(1);
2618 }
2619
2620 if (account)
2621 account->next = ptr;
2622 else
2623 authptr = ptr;
2624
2625 account = ptr;
2626 memset(account, 0, sizeof(struct s_auth));
2627 account->au = (-1);
2628 account->monlvl = cfg->mon_level;
2629 account->tosleep = cfg->tosleep;
2630 account->c35_suppresscmd08 = cfg->c35_suppresscmd08;
2631 account->cccmaxhops = 10;
2632 account->cccreshare = cfg->cc_reshare;
2633 account->ncd_keepalive = cfg->ncd_keepalive;
2634 for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff);
2635 for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000);
2636 nr++;
2637
2638#ifdef CS_ANTICASC
2639 account->ac_users = cfg->ac_users;
2640 account->ac_penalty = cfg->ac_penalty;
2641 account->ac_idx = nr;
2642#endif
2643 continue;
2644 }
2645
2646 if (!tag)
2647 continue;
2648
2649 if (!(value=strchr(token, '=')))
2650 continue;
2651
2652 *value++ = '\0';
2653 chk_account(trim(strtolower(token)), trim(value), account);
2654 }
2655
2656 fclose(fp);
2657
2658 for (expired = 0, disabled = 0, ptr = authptr; ptr;) {
2659
2660 if(ptr->expirationdate && ptr->expirationdate < time(NULL))
2661 expired++;
2662
2663 if(ptr->disabled != 0)
2664 disabled++;
2665
2666 ptr = ptr->next;
2667 }
2668
2669 *authptr_org = authptr;
2670
2671 cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled);
2672 return(0);
2673}
2674
2675static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
2676{
2677 int i, b;
2678 char *ptr;
2679 ushort *slist=(ushort *) 0;
2680 ulong *llist=(ulong *) 0;
2681 ulong caid;
2682 char buf[strlen(value) + 1];
2683 cs_strncpy(buf, value, sizeof(buf));
2684 b=(what==1) ? sizeof(ulong) : sizeof(ushort);
2685 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
2686 {
2687 caid=a2i(ptr, b);
2688 if (!errno) i++;
2689 }
2690 //if (!i) return(0);
2691 if (b==sizeof(ushort))
2692 slist=malloc(i*sizeof(ushort));
2693 else
2694 llist=malloc(i*sizeof(ulong));
2695 strcpy(value, buf);
2696 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
2697 {
2698 caid=a2i(ptr, b);
2699 if (errno) continue;
2700 if (b==sizeof(ushort))
2701 slist[i++]=(ushort) caid;
2702 else
2703 llist[i++]=caid;
2704 }
2705 switch (what)
2706 {
2707 case 0: sidtab->caid=slist;
2708 sidtab->num_caid=i;
2709 break;
2710 case 1: sidtab->provid=llist;
2711 sidtab->num_provid=i;
2712 break;
2713 case 2: sidtab->srvid=slist;
2714 sidtab->num_srvid=i;
2715 break;
2716 }
2717}
2718
2719void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
2720{
2721 if (!strcmp(token, "caid")) { chk_entry4sidtab(value, sidtab, 0); return; }
2722 if (!strcmp(token, "provid")) { chk_entry4sidtab(value, sidtab, 1); return; }
2723 if (!strcmp(token, "ident")) { chk_entry4sidtab(value, sidtab, 1); return; }
2724 if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; }
2725 if (token[0] != '#')
2726 fprintf(stderr, "Warning: keyword '%s' in sidtab section not recognized\n",token);
2727}
2728
2729int init_sidtab()
2730{
2731 int nr, nro;
2732 FILE *fp;
2733 char *value;
2734 struct s_sidtab *ptr;
2735 struct s_sidtab *sidtab=(struct s_sidtab *)0;
2736
2737 sprintf(token, "%s%s", cs_confdir, cs_sidt);
2738 if (!(fp=fopen(token, "r")))
2739 {
2740 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
2741 return(1);
2742 }
2743 for (nro=0, ptr=cfg->sidtab; ptr; nro++)
2744 {
2745 struct s_sidtab *ptr_next;
2746 ptr_next=ptr->next;
2747 if (ptr->caid) free(ptr->caid);
2748 if (ptr->provid) free(ptr->provid);
2749 if (ptr->srvid) free(ptr->srvid);
2750 free(ptr);
2751 ptr=ptr_next;
2752 }
2753 nr=0;
2754 while (fgets(token, sizeof(token), fp))
2755 {
2756 int l;
2757 void *ptr;
2758 if ((l=strlen(trim(token)))<3) continue;
2759 if ((token[0]=='[') && (token[l-1]==']'))
2760 {
2761 token[l-1]=0;
2762 if (!(ptr=malloc(sizeof(struct s_sidtab))))
2763 {
2764 cs_log("Error allocating memory (errno=%d)", errno);
2765 return(1);
2766 }
2767 if (sidtab)
2768 sidtab->next=ptr;
2769 else
2770 cfg->sidtab=ptr;
2771 sidtab=ptr;
2772 nr++;
2773 memset(sidtab, 0, sizeof(struct s_sidtab));
2774 cs_strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
2775 continue;
2776 }
2777 if (!sidtab) continue;
2778 if (!(value=strchr(token, '='))) continue;
2779 *value++='\0';
2780 chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
2781 }
2782 fclose(fp);
2783
2784#ifdef DEBUG_SIDTAB
2785 show_sidtab(cfg->sidtab);
2786#endif
2787 cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
2788 return(0);
2789}
2790
2791//Todo #ifdef CCCAM
2792int init_provid() {
2793 int nr;
2794 FILE *fp;
2795 char *payload;
2796 static struct s_provid *provid=(struct s_provid *)0;
2797 sprintf(token, "%s%s", cs_confdir, cs_provid);
2798
2799 if (!(fp=fopen(token, "r"))) {
2800 cs_log("can't open file \"%s\" (err=%d), no provids's loaded", token, errno);
2801 return(0);
2802 }
2803 nr=0;
2804 while (fgets(token, sizeof(token), fp)) {
2805
2806 int l;
2807 void *ptr;
2808 char *tmp;
2809 tmp = trim(token);
2810
2811 if (tmp[0] == '#') continue;
2812 if ((l = strlen(tmp)) < 11) continue;
2813 if (!(payload = strchr(token, '|'))) continue;
2814 *payload++ = '\0';
2815
2816 if (!(ptr = malloc(sizeof(struct s_provid)))) {
2817 cs_log("Error allocating memory (errno=%d)", errno);
2818 return(1);
2819 }
2820
2821 if (provid)
2822 provid->next = ptr;
2823 else
2824 cfg->provid = ptr;
2825
2826 provid = ptr;
2827 memset(provid, 0, sizeof(struct s_provid));
2828
2829 int i;
2830 char *ptr1;
2831 for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
2832 switch(i){
2833 case 0:
2834 cs_strncpy(provid->prov, trim(ptr1), sizeof(provid->prov));
2835 break;
2836 case 1:
2837 cs_strncpy(provid->sat, trim(ptr1), sizeof(provid->sat));
2838 break;
2839 case 2:
2840 cs_strncpy(provid->lang, trim(ptr1), sizeof(provid->lang));
2841 break;
2842 }
2843 }
2844
2845 char *providasc = strchr(token, ':');
2846 *providasc++ = '\0';
2847 provid->provid = a2i(providasc, 3);
2848 provid->caid = a2i(token, 3);
2849 nr++;
2850 }
2851
2852 fclose(fp);
2853 if (nr>0)
2854 cs_log("%d provid's loaded", nr);
2855 else{
2856 cs_log("oscam.provid loading failed, wrong format?");
2857 }
2858 return(0);
2859}
2860
2861int init_srvid()
2862{
2863 int nr;
2864 FILE *fp;
2865 char *payload;
2866 static struct s_srvid *srvid=(struct s_srvid *)0;
2867 sprintf(token, "%s%s", cs_confdir, cs_srid);
2868
2869 if (!(fp=fopen(token, "r"))) {
2870 cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
2871 return(0);
2872 }
2873
2874 nr=0;
2875 while (fgets(token, sizeof(token), fp)) {
2876
2877 int l;
2878 void *ptr;
2879 char *tmp;
2880 tmp = trim(token);
2881
2882 if (tmp[0] == '#') continue;
2883 if ((l=strlen(tmp)) < 6) continue;
2884 if (!(payload=strchr(token, '|'))) continue;
2885 *payload++ = '\0';
2886
2887 if (!(ptr = malloc(sizeof(struct s_srvid)))) {
2888 cs_log("Error allocating memory (errno=%d)", errno);
2889 return(1);
2890 }
2891
2892 if (srvid)
2893 srvid->next = ptr;
2894 else
2895 cfg->srvid = ptr;
2896
2897 srvid = ptr;
2898 memset(srvid, 0, sizeof(struct s_srvid));
2899
2900 int i;
2901 char *ptr1;
2902 for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
2903 switch(i){
2904 case 0:
2905 cs_strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov));
2906 break;
2907 case 1:
2908 cs_strncpy(srvid->name, trim(ptr1), sizeof(srvid->name));
2909 break;
2910 case 2:
2911 cs_strncpy(srvid->type, trim(ptr1), sizeof(srvid->type));
2912 break;
2913 case 3:
2914 cs_strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc));
2915 break;
2916 }
2917 }
2918
2919 char *srvidasc = strchr(token, ':');
2920 *srvidasc++ = '\0';
2921 srvid->srvid = dyn_word_atob(srvidasc);
2922 //printf("srvid %s - %d\n",srvidasc,srvid->srvid );
2923
2924 srvid->ncaid = 0;
2925 for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
2926 srvid->caid[i] = dyn_word_atob(ptr1);
2927 srvid->ncaid = i+1;
2928 //cs_debug("ld caid: %04X srvid: %04X Prov: %s Chan: %s",srvid->caid[i],srvid->srvid,srvid->prov,srvid->name);
2929 }
2930 nr++;
2931 }
2932
2933 fclose(fp);
2934 if (nr>0)
2935 cs_log("%d service-id's loaded", nr);
2936 else{
2937 cs_log("oscam.srvid loading failed, old format");
2938 }
2939 return(0);
2940}
2941
2942int init_tierid()
2943{
2944 int nr;
2945 FILE *fp;
2946 char *payload;
2947 static struct s_tierid *tierid=(struct s_tierid *)0;
2948 sprintf(token, "%s%s", cs_confdir, cs_trid);
2949
2950 if (!(fp=fopen(token, "r"))) {
2951 cs_log("can't open file \"%s\" (err=%d), no tier-id's loaded", token, errno);
2952 return(0);
2953 }
2954
2955 nr=0;
2956 while (fgets(token, sizeof(token), fp)) {
2957
2958 int l;
2959 void *ptr;
2960 char *tmp;
2961 tmp = trim(token);
2962
2963 if (tmp[0] == '#') continue;
2964 if ((l=strlen(tmp)) < 6) continue;
2965 if (!(payload=strchr(token, '|'))) continue;
2966 *payload++ = '\0';
2967
2968 if (!(ptr = malloc(sizeof(struct s_tierid)))) {
2969 cs_log("Error allocating memory (errno=%d)", errno);
2970 return(1);
2971 }
2972
2973 if (tierid)
2974 tierid->next = ptr;
2975 else
2976 cfg->tierid = ptr;
2977
2978 tierid = ptr;
2979 memset(tierid, 0, sizeof(struct s_tierid));
2980
2981 int i;
2982 char *ptr1 = strtok(payload, "|");
2983 if (ptr1)
2984 cs_strncpy(tierid->name, trim(ptr1), sizeof(tierid->name));
2985
2986 char *tieridasc = strchr(token, ':');
2987 *tieridasc++ = '\0';
2988 tierid->tierid = dyn_word_atob(tieridasc);
2989 //printf("tierid %s - %d\n",tieridasc,tierid->tierid );
2990
2991 tierid->ncaid = 0;
2992 for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
2993 tierid->caid[i] = dyn_word_atob(ptr1);
2994 tierid->ncaid = i+1;
2995 // cs_log("ld caid: %04X tierid: %04X name: %s",tierid->caid[i],tierid->tierid,tierid->name);
2996 }
2997 nr++;
2998 }
2999
3000 fclose(fp);
3001 if (nr>0)
3002 cs_log("%d tier-id's loaded", nr);
3003 else{
3004 cs_log("%s loading failed", cs_trid);
3005 }
3006 return(0);
3007}
3008
3009void chk_reader(char *token, char *value, struct s_reader *rdr)
3010{
3011 int i;
3012 char *ptr;
3013 /*
3014 * case sensitive first
3015 */
3016 if (!strcmp(token, "device")) {
3017 for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
3018 trim(ptr);
3019 switch(i) {
3020 case 0:
3021 cs_strncpy(rdr->device, ptr, sizeof(rdr->device));
3022 break;
3023
3024 case 1:
3025 rdr->r_port = atoi(ptr);
3026 break;
3027
3028 case 2:
3029 rdr->l_port = atoi(ptr);
3030 break;
3031 }
3032 }
3033 return;
3034 }
3035
3036 if (!strcmp(token, "key")) {
3037 if (key_atob14(value, rdr->ncd_key)) {
3038 fprintf(stderr, "Configuration newcamd: Error in Key\n");
3039 exit(1);
3040 }
3041 return;
3042 }
3043
3044#ifdef CS_WITH_GBOX
3045 if (!strcmp(token, "password")) {
3046 cs_strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4);
3047 return;
3048 }
3049
3050 if (!strcmp(token, "premium")) {
3051 rdr->gbox_prem = 1;
3052 return;
3053 }
3054#endif
3055 if (!strcmp(token, "account")) {
3056 for (i = 0, ptr = strtok(value, ","); (i < 2) && (ptr); ptr = strtok(NULL, ","), i++) {
3057 trim(ptr);
3058 switch(i) {
3059 case 0:
3060 cs_strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr));
3061 break;
3062
3063 case 1:
3064 cs_strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd));
3065 break;
3066 }
3067 }
3068 return;
3069 }
3070
3071 if (!strcmp(token, "pincode")) {
3072 strncpy(rdr->pincode, value, sizeof(rdr->pincode) - 1);
3073 return;
3074 }
3075
3076 if (!strcmp(token, "readnano")) {
3077 if (rdr->emmfile != NULL) {
3078 free(rdr->emmfile);
3079 rdr->emmfile = NULL;
3080 }
3081 if (strlen(value) > 0) {
3082 if(asprintf(&(rdr->emmfile), "%s", value) < 0)
3083 fprintf(stderr, "Error allocating string for rdr->emmfile\n");
3084 }
3085 return;
3086 }
3087
3088 /*
3089 * case insensitive
3090 */
3091 strtolower(value);
3092
3093 if (!strcmp(token, "enable")) {
3094 if(strlen(value) == 0) {
3095 rdr->enable = 0;
3096 return;
3097 } else {
3098 rdr->enable = atoi(value) ? 1 : 0;
3099 return;
3100 }
3101 }
3102
3103 if (!strcmp(token, "services")) {
3104 if(strlen(value) == 0) {
3105 rdr->sidtabok = 0;
3106 rdr->sidtabno = 0;
3107 return;
3108 } else {
3109 chk_services(value, &rdr->sidtabok, &rdr->sidtabno);
3110 return;
3111 }
3112 }
3113
3114 if (!strcmp(token, "inactivitytimeout")) {
3115 if(strlen(value) == 0) {
3116 rdr->tcp_ito = 0;
3117 return;
3118 } else {
3119 rdr->tcp_ito = atoi(value);
3120 return;
3121 }
3122 }
3123
3124 if (!strcmp(token, "reconnecttimeout")) {
3125 if(strlen(value) == 0) {
3126 rdr->tcp_rto = 0;
3127 return;
3128 } else {
3129 rdr->tcp_rto = atoi(value);
3130 return;
3131 }
3132 }
3133
3134 if (!strcmp(token, "disableserverfilter")) {
3135 if(strlen(value) == 0) {
3136 rdr->ncd_disable_server_filt = 0;
3137 return;
3138 } else {
3139 rdr->ncd_disable_server_filt = atoi(value);
3140 return;
3141 }
3142 }
3143
3144 //FIXME workaround for Smargo until native mode works
3145 if (!strcmp(token, "smargopatch")) {
3146 if(strlen(value) == 0) {
3147 rdr->smargopatch = 0;
3148 return;
3149 } else {
3150 rdr->smargopatch = atoi(value);
3151 return;
3152 }
3153 }
3154
3155 if (!strcmp(token, "label")) {
3156 cs_strncpy(rdr->label, value, sizeof(rdr->label));
3157 return;
3158 }
3159
3160 if (!strcmp(token, "fallback")) {
3161 if(strlen(value) == 0) {
3162 rdr->fallback = 0;
3163 return;
3164 } else {
3165 rdr->fallback = atoi(value) ? 1 : 0;
3166 return;
3167 }
3168 }
3169
3170 if (!strcmp(token, "logport")) {
3171 if(strlen(value) == 0) {
3172 rdr->log_port = 0;
3173 return;
3174 } else {
3175 rdr->log_port = atoi(value);
3176 return;
3177 }
3178 }
3179
3180 if (!strcmp(token, "caid")) {
3181 if(strlen(value) == 0) {
3182 clear_caidtab(&rdr->ctab);
3183 return;
3184 } else {
3185 chk_caidtab(value, &rdr->ctab);
3186 return;
3187 }
3188 }
3189
3190 if (!strcmp(token, "boxid")) {
3191 if(strlen(value) == 0) {
3192 rdr->boxid = 0;
3193 return;
3194 } else {
3195 rdr->boxid = a2i(value, 4);
3196 return;
3197 }
3198 }
3199
3200 if (!strcmp(token, "aeskey")) {
3201 if (key_atob(value, rdr->aes_key)) {
3202 fprintf(stderr, "Configuration reader: Error in AES Key\n");
3203 exit(1);
3204 }
3205 return;
3206 }
3207
3208 if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey"))) {
3209 if(strlen(value) == 0) {
3210 memset(rdr->rsa_mod, 0, 120);
3211 rdr->has_rsa = 0;
3212 return;
3213 } else {
3214 rdr->has_rsa = 1;
3215 if (key_atob_l(value, rdr->rsa_mod, 128)) {
3216 fprintf(stderr, "Configuration reader: Error in rsakey\n");
3217 exit(1);
3218 }
3219 return;
3220 }
3221 }
3222
3223 if (!strcmp(token, "tiger_rsakey")) {
3224 if(strlen(value) == 0) {
3225 memset(rdr->rsa_mod, 0, 120);
3226 return;
3227 } else {
3228 if (key_atob_l(value, rdr->rsa_mod, 240)) {
3229 fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
3230 exit(1);
3231 }
3232 return;
3233 }
3234 }
3235
3236 if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey"))) {
3237 if(strlen(value) == 0) {
3238 memset(rdr->nagra_boxkey, 0, 16);
3239 return;
3240 } else {
3241 if (key_atob_l(value, rdr->nagra_boxkey, 16)) {
3242 fprintf(stderr, "Configuration reader: Error in boxkey\n");
3243 exit(1);
3244 }
3245 return;
3246 }
3247 }
3248
3249 if (!strcmp(token, "force_irdeto")) {
3250 if(strlen(value) == 0) {
3251 rdr->force_irdeto = 0;
3252 return;
3253 } else {
3254 rdr->force_irdeto = atoi(value);
3255 return;
3256 }
3257 }
3258
3259
3260 if ((!strcmp(token, "atr"))) {
3261 memset(rdr->atr, 0, 128);
3262 rdr->atrlen = strlen(value);
3263 if(rdr->atrlen == 0) {
3264 return;
3265 } else {
3266 key_atob_l(value, rdr->atr, rdr->atrlen);
3267 return;
3268 }
3269 }
3270
3271 if (!strcmp(token, "detect")) {
3272 for (i = 0; RDR_CD_TXT[i]; i++) {
3273 if (!strcmp(value, RDR_CD_TXT[i])) {
3274 rdr->detect = i;
3275 }
3276 else {
3277 if ((value[0] == '!') && (!strcmp(value+1, RDR_CD_TXT[i])))
3278 rdr->detect = i|0x80;
3279 }
3280 }
3281 return;
3282 }
3283
3284 if (!strcmp(token, "mhz")) {
3285 if(strlen(value) == 0) {
3286 rdr->mhz = 0;
3287 return;
3288 } else {
3289 rdr->mhz = atoi(value);
3290 return;
3291 }
3292 }
3293
3294 if (!strcmp(token, "cardmhz")) {
3295 if(strlen(value) == 0) {
3296 rdr->cardmhz = 0;
3297 return;
3298 } else {
3299 rdr->cardmhz = atoi(value);
3300 return;
3301 }
3302 }
3303
3304 if (!strcmp(token, "protocol")) {
3305
3306 if (!strcmp(value, "mp35")) {
3307 rdr->typ = R_MP35;
3308 return;
3309 }
3310
3311 if (!strcmp(value, "mouse")) {
3312 rdr->typ = R_MOUSE;
3313 return;
3314 }
3315
3316 if (!strcmp(value, "sc8in1")) {
3317 rdr->typ = R_SC8in1;
3318 return;
3319 }
3320
3321 if (!strcmp(value, "smartreader")) {
3322 rdr->typ = R_SMART;
3323 return;
3324 }
3325
3326 if (!strcmp(value, "internal")) {
3327 rdr->typ = R_INTERNAL;
3328 return;
3329 }
3330
3331#ifdef HAVE_PCSC
3332 if (!strcmp(value, "pcsc")) {
3333 rdr->typ = R_PCSC;
3334 return;
3335 }
3336#endif
3337
3338 if (!strcmp(value, "serial")) {
3339 rdr->typ = R_SERIAL;
3340 return;
3341 }
3342
3343 if (!strcmp(value, "camd35")) {
3344 rdr->typ = R_CAMD35;
3345 return;
3346 }
3347
3348 if (!strcmp(value, "cs378x")) {
3349 rdr->typ = R_CS378X;
3350 return;
3351 }
3352
3353 if (!strcmp(value, "cs357x")) {
3354 rdr->typ = R_CAMD35;
3355 return;
3356 }
3357
3358#ifdef CS_WITH_GBOX
3359 if (!strcmp(value, "gbox")) {
3360 rdr->typ = R_GBOX;
3361 return;
3362 }
3363#endif
3364
3365 if (!strcmp(value, "cccam")) {
3366 rdr->typ = R_CCCAM;
3367 //strcpy(value, "1");
3368 //chk_caidtab(value, &rdr->ctab);
3369 //this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
3370 return;
3371 }
3372
3373 if (!strcmp(value, "constcw")) {
3374 rdr->typ = R_CONSTCW;
3375 return;
3376 }
3377
3378 if (!strcmp(value, "radegast")) {
3379 rdr->typ = R_RADEGAST;
3380 return;
3381 }
3382
3383 if (!strcmp(value, "newcamd") || !strcmp(value, "newcamd525")) {
3384 rdr->typ = R_NEWCAMD;
3385 rdr->ncd_proto = NCD_525;
3386 return;
3387 }
3388
3389 if (!strcmp(value, "newcamd524")) {
3390 rdr->typ = R_NEWCAMD;
3391 rdr->ncd_proto = NCD_524;
3392 return;
3393 }
3394
3395 fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
3396 rdr->typ = R_MOUSE;
3397 return;
3398 }
3399
3400 if (!strcmp(token, "ident")) {
3401 if(strlen(value) == 0) {
3402 clear_ftab(&rdr->ftab);
3403 return;
3404 } else {
3405 chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid");
3406 return;
3407 }
3408 }
3409
3410 if (!strcmp(token, "class")) {
3411 chk_cltab(value, &rdr->cltab);
3412 return;
3413 }
3414
3415 if (!strcmp(token, "chid")) {
3416 chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid");
3417 return;
3418 }
3419
3420 if (!strcmp(token, "showcls")) {
3421 rdr->show_cls = atoi(value);
3422 return;
3423 }
3424
3425 if (!strcmp(token, "maxqlen")) {
3426 rdr->maxqlen = atoi(value);
3427 if( rdr->maxqlen < 0 || rdr->maxqlen > CS_MAXQLEN) {
3428 rdr->maxqlen = CS_MAXQLEN;
3429 }
3430 return;
3431 }
3432
3433 if (!strcmp(token, "group")) {
3434 if(strlen(value) == 0) {
3435 rdr->grp = 0;
3436 return;
3437 } else {
3438 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
3439 int g;
3440 g = atoi(ptr);
3441 if ((g>0) && (g<33)) {
3442 rdr->grp |= (1<<(g-1));
3443 }
3444 }
3445 return;
3446 }
3447 }
3448
3449 if (!strcmp(token, "emmcache")) {
3450 if(strlen(value) == 0) {
3451 rdr->cachemm = 0;
3452 rdr->rewritemm = 0;
3453 rdr->logemm = 0;
3454 return;
3455 } else {
3456 for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
3457 switch(i)
3458 {
3459 case 0:
3460 rdr->cachemm = atoi(ptr);
3461 break;
3462
3463 case 1:
3464 rdr->rewritemm = atoi(ptr);
3465 break;
3466
3467 case 2: rdr->logemm = atoi(ptr);
3468 break;
3469 }
3470 }
3471
3472 if (rdr->rewritemm <= 0) {
3473 fprintf(stderr, "Notice: Setting EMMCACHE to %i,1,%i instead of %i,%i,%i. ",
3474 rdr->cachemm, rdr->logemm,
3475 rdr->cachemm, rdr->rewritemm,
3476 rdr->logemm);
3477
3478 fprintf(stderr, "Zero or negative number of rewrites is silly\n");
3479 rdr->rewritemm = 1;
3480 }
3481 return;
3482 }
3483 }
3484
3485 if (!strcmp(token, "ecmcache")) {
3486 if(strlen(value) == 0) {
3487 rdr->cachecm = 1;
3488 return;
3489 } else {
3490 rdr->cachecm = atoi(value);
3491 return;
3492 }
3493 }
3494
3495 if (!strcmp(token, "blocknano")) {
3496 //wildcard is used
3497 if (!strcmp(value,"all")) {
3498 for (i = 0 ; i < 256; i++) {
3499 rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
3500 }
3501 }
3502 else {
3503 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
3504 if ((i = byte_atob(ptr)) >= 0) {
3505 rdr->b_nano[i] |= 0x01; //lsb is set when to block nano
3506 }
3507 }
3508 }
3509 return;
3510 }
3511
3512 if (!strcmp(token, "blockemm-unknown")) {
3513 if (strlen(value) == 0) {
3514 rdr->blockemm_unknown = 0;
3515 return;
3516 }
3517 else {
3518 rdr->blockemm_unknown = atoi(value);
3519 return;
3520 }
3521 }
3522
3523 if (!strcmp(token, "blockemm-u")) {
3524 if (strlen(value) == 0) {
3525 rdr->blockemm_u = 0;
3526 return;
3527 }
3528 else {
3529 rdr->blockemm_u = atoi(value);
3530 return;
3531 }
3532 }
3533
3534 if (!strcmp(token, "blockemm-s")) {
3535 if (strlen(value) == 0) {
3536 rdr->blockemm_s = 0;
3537 return;
3538 }
3539 else {
3540 rdr->blockemm_s = atoi(value);
3541 return;
3542 }
3543 }
3544
3545 if (!strcmp(token, "blockemm-g")) {
3546 if (strlen(value) == 0) {
3547 rdr->blockemm_g = 0;
3548 return;
3549 }
3550 else {
3551 rdr->blockemm_g = atoi(value);
3552 return;
3553 }
3554 }
3555
3556 if (!strcmp(token, "lb_weight")) {
3557 if(strlen(value) == 0) {
3558 rdr->lb_weight = 100;
3559 return;
3560 } else {
3561 rdr->lb_weight = atoi(value);
3562 if (rdr->lb_weight > 1000) rdr->lb_weight = 1000;
3563 else if (rdr->lb_weight <= 0) rdr->lb_weight = 100;
3564 return;
3565 }
3566 }
3567
3568 if (!strcmp(token, "savenano")) {
3569 //wildcard is used
3570 if (!strcmp(value,"all")) {
3571 for (i = 0 ; i < 256; i++) {
3572 rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
3573 }
3574 }
3575 else {
3576 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
3577 if ((i = byte_atob(ptr)) >= 0) {
3578 rdr->b_nano[i] |= 0x02; //lsb+1 is set when to save nano to file
3579 }
3580 }
3581 }
3582 return;
3583 }
3584
3585 if (!strcmp(token, "cccversion")) {
3586 // cccam version
3587 if (strlen(value) > sizeof(rdr->cc_version) - 1) {
3588 fprintf(stderr, "cccam config: version too long\n");
3589 exit(1);
3590 }
3591 memset(rdr->cc_version, 0, sizeof(rdr->cc_version));
3592 cs_strncpy(rdr->cc_version, value, sizeof(rdr->cc_version));
3593 return;
3594 }
3595
3596 if (!strcmp(token, "cccmaxhop") || !strcmp(token, "cccmaxhops")) { //Schlocke: cccmaxhops is better!
3597 // cccam max card distance
3598 if (!strlen(value))
3599 rdr->cc_maxhop = 10;
3600 else
3601 rdr->cc_maxhop = atoi(value);
3602 return;
3603 }
3604
3605 if (!strcmp(token, "cccdisableretryecm")) {
3606 if (strlen(value) == 0) {
3607 rdr->cc_disable_retry_ecm = 0;
3608 return;
3609 } else {
3610 rdr->cc_disable_retry_ecm = atoi(value);
3611 return;
3612 }
3613 }
3614
3615 if (!strcmp(token, "cccdisableautoblock")) {
3616 if (strlen(value) == 0) {
3617 rdr->cc_disable_auto_block = 0;
3618 return;
3619 } else {
3620 rdr->cc_disable_auto_block = atoi(value);
3621 return;
3622 }
3623 }
3624
3625 if (!strcmp(token, "cccwantemu")) {
3626 if (strlen(value) == 0) {
3627 rdr->cc_want_emu = 0;
3628 return;
3629 } else {
3630 rdr->cc_want_emu = atoi(value);
3631 return;
3632 }
3633 }
3634
3635 if (!strcmp(token, "ccckeepalive")) {
3636 if (strlen(value) == 0) {
3637 rdr->cc_keepalive = 0;
3638 return;
3639 } else {
3640 rdr->cc_keepalive = atoi(value);
3641 return;
3642 }
3643 }
3644
3645 if (!strcmp(token, "deprecated")) {
3646 if (strlen(value) == 0) {
3647 rdr->deprecated = 0;
3648 return;
3649 } else {
3650 rdr->deprecated = atoi(value);
3651 return;
3652 }
3653 }
3654
3655 if (!strcmp(token, "ccchopsaway") || !strcmp(token, "cccreshar") || !strcmp(token, "cccreshare")) {
3656 rdr->cc_reshare = atoi(value);
3657 return;
3658 }
3659
3660 if (!strcmp(token, "audisabled")) {
3661 if (strlen(value) == 0) {
3662 rdr->audisabled = 0;
3663 return;
3664 } else {
3665 rdr->audisabled = atoi(value);
3666 return;
3667 }
3668 }
3669
3670 if (!strcmp(token, "auprovid")) {
3671 if (strlen(value) == 0) {
3672 rdr->auprovid = 0;
3673 return;
3674 } else {
3675 rdr->auprovid = a2i(value, 3);
3676 return;
3677 }
3678 }
3679 // new code for multiple aes key per reader
3680 if (!strcmp(token, "aeskeys")) {
3681 parse_aes_keys(rdr,value);
3682 return;
3683 }
3684
3685 if (!strcmp(token, "ndsversion")) {
3686 if (strlen(value) == 0) {
3687 rdr->ndsversion = 0;
3688 return;
3689 } else {
3690 rdr->ndsversion = atoi(value);
3691 return;
3692 }
3693 }
3694
3695
3696#ifdef AZBOX
3697 if (!strcmp(token, "mode")) {
3698 if(strlen(value) == 0) {
3699 rdr->mode = -1;
3700 return;
3701 } else {
3702 rdr->mode = atoi(value);
3703 return;
3704 }
3705 }
3706#endif
3707
3708 if (token[0] != '#')
3709 fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);
3710}
3711
3712#ifdef IRDETO_GUESSING
3713int init_irdeto_guess_tab()
3714{
3715 int i, j, skip;
3716 int b47;
3717 FILE *fp;
3718 char token[128], *ptr;
3719 char zSid[5];
3720 uchar b3;
3721 ushort caid, sid;
3722 struct s_irdeto_quess *ird_row, *head;
3723
3724 memset(cfg->itab, 0, sizeof(cfg->itab));
3725 sprintf(token, "%s%s", cs_confdir, cs_ird);
3726 if (!(fp=fopen(token, "r")))
3727 {
3728 cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
3729 token, errno);
3730 return(1);
3731 }
3732 while (fgets(token, sizeof(token), fp))
3733 {
3734 if( strlen(token)<20 ) continue;
3735 for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
3736 {
3737 trim(ptr);
3738 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
3739 skip=1;
3740 break;
3741 }
3742 switch(i)
3743 {
3744 case 0: b3 = a2i(ptr, 2); break;
3745 case 1: b47 = a2i(ptr, 8); break;
3746 case 2: caid = a2i(ptr, 4); break;
3747 case 3:
3748 for( j=0; j<4; j++ )
3749 zSid[j]=ptr[j];
3750 zSid[4]=0;
3751 sid = a2i(zSid, 4);
3752 break;
3753 }
3754 }
3755 if( !skip )
3756 {
3757 if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
3758 {
3759 cs_log("Error allocating memory (errno=%d)", errno);
3760 return(1);
3761 }
3762 ird_row->b47 = b47;
3763 ird_row->caid = caid;
3764 ird_row->sid = sid;
3765 ird_row->next = 0;
3766
3767 head = cfg->itab[b3];
3768 if( head ) {
3769 while( head->next )
3770 head=head->next;
3771 head->next=ird_row;
3772 }
3773 else
3774 cfg->itab[b3]=ird_row;
3775 //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
3776 }
3777 }
3778 fclose(fp);
3779
3780 for( i=0; i<0xff; i++ )
3781 {
3782 head=cfg->itab[i];
3783 while(head)
3784 {
3785 cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
3786 i, head->b47, head->caid, head->sid);
3787 head=head->next;
3788 }
3789 }
3790 return(0);
3791}
3792#endif
3793
3794int init_readerdb()
3795{
3796 int tag = 0, nr;
3797 FILE *fp;
3798 char *value;
3799
3800 sprintf(token, "%s%s", cs_confdir, cs_srvr);
3801 if (!(fp=fopen(token, "r"))) {
3802 cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
3803 return(1);
3804 }
3805 nr = 0;
3806 while (fgets(token, sizeof(token), fp)) {
3807 int i, l;
3808 if ((l = strlen(trim(token))) < 3)
3809 continue;
3810 if ((token[0] == '[') && (token[l-1] == ']')) {
3811 token[l-1] = 0;
3812 tag = (!strcmp("reader", strtolower(token+1)));
3813 if (reader[nr].label[0] && reader[nr].typ) nr++;
3814 memset(&reader[nr], 0, sizeof(struct s_reader));
3815 reader[nr].enable = 1;
3816 reader[nr].tcp_rto = 30;
3817 reader[nr].show_cls = 10;
3818 reader[nr].maxqlen = CS_MAXQLEN;
3819 reader[nr].mhz = 357;
3820 reader[nr].cardmhz = 357;
3821 reader[nr].deprecated = 0;
3822 reader[nr].force_irdeto = 0;
3823 reader[nr].cachecm = 1;
3824 reader[nr].cc_reshare = cfg->cc_reshare; //set global value as init value
3825 reader[nr].cc_maxhop = 10;
3826 reader[nr].lb_weight = 100;
3827 strcpy(reader[nr].pincode, "none");
3828 reader[nr].ndsversion = 0;
3829 for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
3830 continue;
3831 }
3832
3833 if (!tag)
3834 continue;
3835 if (!(value=strchr(token, '=')))
3836 continue;
3837 *value++ ='\0';
3838 chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
3839 }
3840 fclose(fp);
3841 return(0);
3842}
3843
3844#ifdef CS_ANTICASC
3845void init_ac()
3846{
3847 int nr;
3848 FILE *fp;
3849 //char *value;
3850
3851 sprintf(token, "%s%s", cs_confdir, cs_ac);
3852 if (!(fp=fopen(token, "r")))
3853 {
3854 cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
3855 token, errno);
3856 return;
3857 }
3858
3859 for(nr=0; fgets(token, sizeof(token), fp);)
3860 {
3861 int i, skip;
3862 ushort caid, sid, chid, dwtime;
3863 ulong provid;
3864 char *ptr, *ptr1;
3865 struct s_cpmap *ptr_cpmap;
3866 static struct s_cpmap *cpmap=(struct s_cpmap *)0;
3867
3868 if( strlen(token)<4 ) continue;
3869
3870 caid=sid=chid=dwtime=0;
3871 provid=0;
3872 skip=0;
3873 ptr1=0;
3874 for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
3875 {
3876 trim(ptr);
3877 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
3878 skip=1;
3879 break;
3880 }
3881 switch( i )
3882 {
3883 case 0:
3884 ptr1=ptr;
3885 break;
3886 case 1:
3887 dwtime = atoi(ptr);
3888 break;
3889 }
3890 }
3891
3892 if( !skip )
3893 {
3894 for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
3895 {
3896 trim(ptr);
3897 switch( i )
3898 {
3899 case 0:
3900 if( *ptr=='*' ) caid = 0;
3901 else caid = a2i(ptr, 4);
3902 break;
3903 case 1:
3904 if( *ptr=='*' ) provid = 0;
3905 else provid = a2i(ptr, 6);
3906 break;
3907 case 2:
3908 if( *ptr=='*' ) sid = 0;
3909 else sid = a2i(ptr, 4);
3910 break;
3911 case 3:
3912 if( *ptr=='*' ) chid = 0;
3913 else chid = a2i(ptr, 4);
3914 break;
3915 }
3916 }
3917 if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
3918 {
3919 cs_log("Error allocating memory (errno=%d)", errno);
3920 return;
3921 }
3922 if( cpmap )
3923 cpmap->next=ptr_cpmap;
3924 else
3925 cfg->cpmap=ptr_cpmap;
3926 cpmap=ptr_cpmap;
3927
3928 cpmap->caid = caid;
3929 cpmap->provid = provid;
3930 cpmap->sid = sid;
3931 cpmap->chid = chid;
3932 cpmap->dwtime = dwtime;
3933 cpmap->next = 0;
3934
3935 cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
3936 nr, caid, provid, sid, chid, dwtime);
3937 nr++;
3938 }
3939 }
3940 fclose(fp);
3941 //cs_log("%d lengths for caid guessing loaded", nr);
3942 return;
3943}
3944#endif
3945
3946/*
3947 * makes a char ready to write a token into config or webIf
3948 */
3949char *mk_t_caidtab(CAIDTAB *ctab){
3950 int i = 0, needed = 1, pos = 0;
3951 while(ctab->caid[i]){
3952 if(ctab->mask[i]) needed += 10;
3953 else needed += 5;
3954 if(ctab->cmap[i]) needed += 5;
3955 ++i;
3956 }
3957 char *value = (char *) malloc(needed * sizeof(char));
3958 i = 0;
3959 while(ctab->caid[i]) {
3960 if(i == 0) {
3961 sprintf(value + pos, "%04X", ctab->caid[i]);
3962 pos += 4;
3963 } else {
3964 sprintf(value + pos, ",%04X", ctab->caid[i]);
3965 pos += 5;
3966 }
3967 if((ctab->mask[i]) && (ctab->mask[i] != 0xFFFF)){
3968 sprintf(value + pos, "&%04X", ctab->mask[i]);
3969 pos += 5;
3970 }
3971 if(ctab->cmap[i]){
3972 sprintf(value + pos, ":%04X", ctab->cmap[i]);
3973 pos += 5;
3974 }
3975 ++i;
3976 }
3977 value[pos] = '\0';
3978 return value;
3979}
3980
3981/*
3982 * makes a char ready to write a token into config or webIf
3983 */
3984char *mk_t_tuntab(TUNTAB *ttab){
3985 int i = 0, needed = 1, pos = 0;
3986 while(ttab->bt_caidfrom[i]){
3987 if(ttab->bt_srvid[i]) needed += 10;
3988 else needed += 5;
3989 if(ttab->bt_caidto[i]) needed += 5;
3990 ++i;
3991 }
3992 char *value = (char *) malloc(needed * sizeof(char));
3993 i = 0;
3994 while(ttab->bt_caidfrom[i]) {
3995 if(i == 0) {
3996 sprintf(value + pos, "%04X", ttab->bt_caidfrom[i]);
3997 pos += 4;
3998 } else {
3999 sprintf(value + pos, ",%04X", ttab->bt_caidfrom[i]);
4000 pos += 5;
4001 }
4002 if(ttab->bt_srvid[i]){
4003 sprintf(value + pos, ".%04X", ttab->bt_srvid[i]);
4004 pos += 5;
4005 }
4006 if(ttab->bt_caidto[i]){
4007 sprintf(value + pos, ":%04X", ttab->bt_caidto[i]);
4008 pos += 5;
4009 }
4010 ++i;
4011 }
4012 value[pos] = '\0';
4013 return value;
4014}
4015
4016/*
4017 * makes a char ready to write a token into config or webIf
4018 */
4019char *mk_t_group(ulong *grp){
4020 int i = 0, needed = 1, pos = 0, dot = 0;
4021 char grpbit[33];
4022 long2bitchar((long) grp, grpbit);
4023
4024 for(i = 0; i < 32; i++){
4025 if (grpbit[i] == '1'){
4026 needed += 2;
4027 if(i > 9) needed += 1;
4028 }
4029 }
4030 char *value = (char *) malloc(needed * sizeof(char));
4031
4032 for(i = 0; i < 32; i++){
4033 if (grpbit[i] == '1'){
4034 if (dot == 0){
4035 sprintf(value + pos, "%d", i+1);
4036 if (i > 8)pos += 2;
4037 else pos += 1;
4038 dot = 1;
4039 } else {
4040 sprintf(value + pos, ",%d", i+1);
4041 if (i > 8)pos += 3;
4042 else pos += 2;
4043 }
4044 }
4045 }
4046 value[pos] = '\0';
4047 return value;
4048}
4049
4050/*
4051 * makes a char ready to write a token into config or webIf
4052 */
4053char *mk_t_ftab(FTAB *ftab){
4054 int i = 0, j = 0, needed = 1, pos = 0;
4055
4056 if (ftab->nfilts != 0) {
4057 needed = ftab->nfilts * 5;
4058 for (i = 0; i < ftab->nfilts; ++i)
4059 needed += ftab->filts[i].nprids * 7;
4060 }
4061
4062 char *value = (char *) malloc(needed * sizeof(char));
4063
4064 char *dot="";
4065 for (i = 0; i < ftab->nfilts; ++i){
4066 sprintf(value + pos, "%s%04X", dot, ftab->filts[i].caid);
4067 pos += 4;
4068 if (i > 0) pos += 1;
4069 dot=":";
4070 for (j = 0; j < ftab->filts[i].nprids; ++j) {
4071 sprintf(value + pos, "%s%06lX", dot, ftab->filts[i].prids[j]);
4072 pos += 7;
4073 dot=",";
4074 }
4075 dot=";";
4076 }
4077
4078 value[pos] = '\0';
4079 return value;
4080}
4081
Note: See TracBrowser for help on using the repository browser.