source: trunk/oscam-config.c@ 1674

Last change on this file since 1674 was 1674, checked in by merek, 11 years ago

Backport bugfix in expdate config handling from WebIf branch

File size: 46.5 KB
Line 
1#include "globals.h"
2#ifdef CS_WITH_BOXKEYS
3# include "oscam-boxkeys.np"
4#endif
5
6static char *cs_conf="oscam.conf";
7static char *cs_user="oscam.user";
8static char *cs_srvr="oscam.server";
9static char *cs_srid="oscam.srvid";
10static char *cs_l4ca="oscam.guess";
11static char *cs_cert="oscam.cert";
12static char *cs_sidt="oscam.services";
13//static char *cs_ird="oscam.ird";
14#ifdef CS_ANTICASC
15static char *cs_ac="oscam.ac";
16#endif
17
18static char token[4096];
19
20typedef enum cs_proto_type
21{
22 TAG_GLOBAL, // must be first !
23 TAG_MONITOR, // monitor
24 TAG_CAMD33, // camd 3.3x
25 TAG_CAMD35, // camd 3.5x UDP
26 TAG_NEWCAMD, // newcamd
27 TAG_RADEGAST, // radegast
28 TAG_SERIAL, // serial (static)
29 TAG_CS357X, // camd 3.5x UDP
30 TAG_CS378X, // camd 3.5x TCP
31#ifdef CS_WITH_GBOX
32 TAG_GBOX, // gbox
33#endif
34 TAG_CCCAM, // cccam
35 TAG_DVBAPI
36#ifdef CS_ANTICASC
37 ,TAG_ANTICASC // anti-cascading
38#endif
39} cs_proto_type_t;
40
41static char *cctag[]={"global", "monitor", "camd33", "camd35",
42 "newcamd", "radegast", "serial", "cs357x", "cs378x",
43#ifdef CS_WITH_GBOX
44 "gbox",
45#endif
46 "cccam", "dvbapi",
47#ifdef CS_ANTICASC
48 "anticasc",
49#endif
50 NULL};
51
52#ifdef DEBUG_SIDTAB
53static void show_sidtab(struct s_sidtab *sidtab)
54{
55 for (; sidtab; sidtab=sidtab->next)
56 {
57 int i;
58 char buf[1024];
59 cs_log("label=%s", sidtab->label);
60 sprintf(buf, "caid(%d)=", sidtab->num_caid);
61 for (i=0; i<sidtab->num_caid; i++)
62 sprintf(buf+strlen(buf), "%04X ", sidtab->caid[i]);
63 cs_log("%s", buf);
64 sprintf(buf, "provider(%d)=", sidtab->num_provid);
65 for (i=0; i<sidtab->num_provid; i++)
66 sprintf(buf+strlen(buf), "%08X ", sidtab->provid[i]);
67 cs_log("%s", buf);
68 sprintf(buf, "services(%d)=", sidtab->num_srvid);
69 for (i=0; i<sidtab->num_srvid; i++)
70 sprintf(buf+strlen(buf), "%04X ", sidtab->srvid[i]);
71 cs_log("%s", buf);
72 }
73}
74#endif
75
76void chk_iprange(char *value, struct s_ip **base)
77{
78 int i = 0;
79 char *ptr1, *ptr2;
80 struct s_ip *lip, *cip;
81
82 for (cip=lip=*base; cip; cip=cip->next)
83 lip=cip;
84 if (!(cip=malloc(sizeof(struct s_ip))))
85 {
86 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
87 exit(1);
88 }
89 if (*base)
90 lip->next=cip;
91 else
92 *base=cip;
93
94 memset(cip, 0, sizeof(struct s_ip));
95 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ","))
96 {
97 if (i == 0) ++i;
98 else {
99 if (!(cip=malloc(sizeof(struct s_ip)))){
100 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
101 exit(1);
102 }
103 lip->next = cip;
104 memset(cip, 0, sizeof(struct s_ip));
105 }
106 if( (ptr2=strchr(trim(ptr1), '-')) )
107 {
108 *ptr2++='\0';
109 cip->ip[0]=cs_inet_addr(trim(ptr1));
110 cip->ip[1]=cs_inet_addr(trim(ptr2));
111 }
112 else
113 cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1);
114 lip = cip;
115 }
116}
117
118void chk_caidtab(char *caidasc, CAIDTAB *ctab)
119{
120 int i;
121 char *ptr1, *ptr2, *ptr3;
122 for (i=0, ptr1=strtok(caidasc, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ","))
123 {
124 ulong caid, mask, cmap;
125 if( (ptr3=strchr(trim(ptr1), ':')) )
126 *ptr3++='\0';
127 else
128 ptr3="";
129 if( (ptr2=strchr(trim(ptr1), '&')) )
130 *ptr2++='\0';
131 else
132 ptr2="";
133 if (((caid=a2i(ptr1, 2))|(mask=a2i(ptr2,-2))|(cmap=a2i(ptr3, 2))) < 0x10000)
134 {
135 ctab->caid[i]=caid;
136 ctab->mask[i]=mask;
137 ctab->cmap[i++]=cmap;
138 }
139// else
140// cs_log("WARNING: wrong CAID in %s -> ignored", cs_user);
141 }
142}
143
144void chk_tuntab(char *tunasc, TUNTAB *ttab)
145{
146 int i;
147 char *ptr1, *ptr2, *ptr3;
148 for (i=0, ptr1=strtok(tunasc, ","); (i<CS_MAXTUNTAB) && (ptr1); ptr1=strtok(NULL, ","))
149 {
150 ulong bt_caidfrom, bt_caidto, bt_srvid;
151 if( (ptr3=strchr(trim(ptr1), ':')) )
152 *ptr3++='\0';
153 else
154 ptr3="";
155 if( (ptr2=strchr(trim(ptr1), '.')) )
156 *ptr2++='\0';
157 else
158 ptr2="";
159 if ((bt_caidfrom=a2i(ptr1, 2))|(bt_srvid=a2i(ptr2,-2))|(bt_caidto=a2i(ptr3, 2)))
160 {
161 ttab->bt_caidfrom[i]=bt_caidfrom;
162 ttab->bt_caidto[i]=bt_caidto;
163 ttab->bt_srvid[i++]=bt_srvid;
164 }
165// else
166// cs_log("WARNING: wrong Betatunnel in %s -> ignored", cs_user);
167 }
168}
169
170void chk_services(char *labels, ulong *sidok, ulong *sidno)
171{
172 int i;
173 char *ptr;
174 SIDTAB *sidtab;
175 *sidok=*sidno=0;
176 for (ptr=strtok(labels, ","); ptr; ptr=strtok(NULL, ","))
177 for (trim(ptr), i=0, sidtab=cfg->sidtab; sidtab; sidtab=sidtab->next, i++)
178 {
179 if (!strcmp(sidtab->label, ptr)) *sidok|=(1<<i);
180 if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) *sidno|=(1<<i);
181 }
182}
183
184void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName)
185{
186 int i,j;
187 char *ptr1,*ptr2,*ptr3;
188 char *ptr[CS_MAXFILTERS] = {0};
189
190 memset(ftab, 0, sizeof(FTAB));
191 for( i=0, ptr1=strtok(zFilterAsc, ";"); (i<CS_MAXFILTERS) && (ptr1); ptr1=strtok(NULL, ";"), i++ )
192 {
193 //cs_log("ptr1=%s", ptr1);
194 ptr[i] = ptr1;
195 if( (ptr2=strchr(trim(ptr1), ':')) )
196 {
197 //cs_log("ptr2=%s", ptr2);
198 *ptr2++='\0';
199 //cs_log("ptr2=%s", ptr2);
200 ftab->filts[i].caid = (ushort)a2i(ptr1, 4);
201 //cs_log("caid=%04X", ftab->filts[i].caid);
202 ptr[i] = ptr2;
203 }
204 else if (zFiltName && zFiltName[0]=='c')
205 {
206 cs_log("PANIC: CAID field not found in CHID parameter!");
207 cs_exit(1);
208 }
209 ftab->nfilts++;
210 }
211
212 if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName);
213 for( i=0; i<ftab->nfilts; i++ )
214 {
215 cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid);
216 for( j=0, ptr3=strtok(ptr[i], ","); (j<CS_MAXPROV) && (ptr3); ptr3=strtok(NULL, ","), j++ )
217 {
218 ftab->filts[i].prids[j] = a2i(ptr3,6);
219 ftab->filts[i].nprids++;
220 cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]);
221 }
222 }
223 //cs_log("exit chk_ftab");
224}
225
226void chk_cltab(char *classasc, CLASSTAB *clstab)
227{
228 int i;
229 char *ptr1;
230 for( i=0, ptr1=strtok(classasc, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ",") )
231 {
232 ptr1=trim(ptr1);
233 if( ptr1[0] == '!' )
234 clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2);
235 else
236 clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2);
237 }
238}
239
240void chk_port_tab(char *portasc, PTAB *ptab)
241{
242 int i,j,nfilts,ifilt,iport;
243 char *ptr1,*ptr2,*ptr3;
244 char *ptr[CS_MAXPORTS] = {0};
245 int port[CS_MAXPORTS] = {0};
246 int previous_nports = ptab->nports;
247
248 for (nfilts=i=previous_nports, ptr1=strtok(portasc, ";"); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ";"), i++)
249 {
250 ptr[i] = ptr1;
251 if( (ptr2=strchr(trim(ptr1), '@')) )
252 {
253 *ptr2++='\0';
254 ptab->ports[i].s_port = atoi(ptr1);
255 ptr[i] = ptr2;
256 port[i] = ptab->ports[i].s_port;
257 ptab->nports++;
258 }
259 nfilts++;
260 }
261
262 if( nfilts==1 && strlen(portasc)<6 && ptab->ports[0].s_port == 0 ) {
263 ptab->ports[0].s_port = atoi(portasc);
264 ptab->nports = 1;
265 }
266
267 iport=ifilt = previous_nports;
268 for (i=previous_nports; i<nfilts; i++)
269 {
270 if( port[i]!=0 ) iport = i;
271 for (j=0, ptr3=strtok(ptr[i], ","); (j<CS_MAXPROV) && (ptr3); ptr3=strtok(NULL, ","), j++)
272 {
273 if( (ptr2=strchr(trim(ptr3), ':')) )
274 {
275 *ptr2++='\0';
276 ptab->ports[iport].ftab.nfilts++;
277 ifilt = ptab->ports[iport].ftab.nfilts-1;
278 ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4);
279 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
280 } else {
281 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
282 }
283 ptab->ports[iport].ftab.filts[ifilt].nprids++;
284 }
285 }
286}
287
288#ifdef NOTUSED
289static void chk_srvip(char *value, in_addr_t *ip)
290{
291 int i;
292 char *ptr;
293 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
294 if (i<8) ip[i++]=inet_addr(ptr);
295}
296#endif
297
298void chk_t_global(char *token, char *value)
299{
300 if (!strcmp(token, "serverip")) { cfg->srvip=inet_addr(value); return; }
301 if (!strcmp(token, "logfile")) {
302 if (cfg->logfile != NULL) {
303 free(cfg->logfile);
304 cfg->logfile = NULL;
305 }
306 if (value[0])
307 asprintf(&(cfg->logfile), "%s", value);
308 return;
309 }
310 if (!strcmp(token, "pidfile")) {
311 if (cfg->pidfile != NULL) {
312 free(cfg->pidfile);
313 cfg->pidfile = NULL;
314 }
315 if (value[0])
316 asprintf(&(cfg->pidfile), "%s", value);
317 return;
318 }
319 if (!strcmp(token, "usrfile")) {
320 if (cfg->usrfile != NULL) {
321 free(cfg->usrfile);
322 cfg->usrfile = NULL;
323 }
324 if (value[0])
325 asprintf(&(cfg->usrfile), "%s", value);
326 return;
327 }
328 if (!strcmp(token, "cwlogdir")) {
329 if (cfg->cwlogdir != NULL) {
330 free(cfg->cwlogdir);
331 cfg->cwlogdir = NULL;
332 }
333 if (value[0])
334 asprintf(&(cfg->cwlogdir), "%s", value);
335 return;
336 }
337 if (!strcmp(token, "clienttimeout"))
338 {
339 cfg->ctimeout = atoi(value);
340 if (cfg->ctimeout < 100)
341 cfg->ctimeout *= 1000;
342 return;
343 }
344 if (!strcmp(token, "fallbacktimeout"))
345 {
346 cfg->ftimeout = atoi(value);
347 if (cfg->ftimeout < 100)
348 cfg->ftimeout *= 1000;
349 return;
350 }
351
352 if (!strcmp(token, "clientmaxidle")) { cfg->cmaxidle=atoi(value); return; }
353 if (!strcmp(token, "cachedelay")) { cfg->delay=atoi(value); return; }
354 if (!strcmp(token, "bindwait")) { cfg->bindwait=atoi(value); return; }
355 if (!strcmp(token, "netprio")) { cfg->netprio=atoi(value); return; }
356 if (!strcmp(token, "resolvedelay")) { cfg->resolvedelay=atoi(value); return; }
357 if (!strcmp(token, "sleep")) { cfg->tosleep=atoi(value); return; }
358 if (!strcmp(token, "unlockparental")) { cfg->ulparent=atoi(value); return; }
359 if (!strcmp(token, "nice"))
360 {
361 cfg->nice=atoi(value);
362 if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice=99;
363 if (cfg->nice!=99) cs_setpriority(cfg->nice); // ignore errors
364 return;
365 }
366 if (!strcmp(token, "serialreadertimeout"))
367 {
368 if (cfg->srtimeout < 100)
369 cfg->srtimeout = atoi(value) * 1000;
370 else
371 cfg->srtimeout = atoi(value);
372 if( cfg->srtimeout <=0 )
373 cfg->srtimeout=1500;
374 return;
375 }
376 if (!strcmp(token, "maxlogsize"))
377 {
378 cfg->max_log_size=atoi(value);
379 if( cfg->max_log_size <=10 )
380 cfg->max_log_size=10;
381 return;
382 }
383 if( !strcmp(token, "waitforcards")) { cfg->waitforcards = atoi(value); return; }
384 if( !strcmp(token, "preferlocalcards")) { cfg->preferlocalcards = atoi(value); return; }
385 if (token[0] != '#')
386 fprintf(stderr, "Warning: keyword '%s' in global section not recognized\n",token);
387}
388
389#ifdef CS_ANTICASC
390void chk_t_ac(char *token, char *value)
391{
392 if (!strcmp(token, "enabled"))
393 {
394 cfg->ac_enabled=atoi(value);
395 if( cfg->ac_enabled<=0 ) cfg->ac_enabled=0;
396 else cfg->ac_enabled=1;
397 return;
398 }
399
400 if (!strcmp(token, "numusers"))
401 {
402 cfg->ac_users=atoi(value);
403 if( cfg->ac_users<0 ) cfg->ac_users=0;
404 return;
405 }
406 if (!strcmp(token, "sampletime"))
407 {
408 cfg->ac_stime=atoi(value);
409 if( cfg->ac_stime<0 ) cfg->ac_stime=2;
410 return;
411 }
412 if (!strcmp(token, "samples"))
413 {
414 cfg->ac_samples=atoi(value);
415 if( cfg->ac_samples<2 || cfg->ac_samples>10) cfg->ac_samples=10;
416 return;
417 }
418 if (!strcmp(token, "penalty"))
419 {
420 cfg->ac_penalty=atoi(value);
421 if( cfg->ac_penalty<0 ) cfg->ac_penalty=0;
422 return;
423 }
424 if (!strcmp(token, "aclogfile"))
425 {
426 strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile)-1);
427 return;
428 }
429 if( !strcmp(token, "fakedelay") )
430 {
431 cfg->ac_fakedelay=atoi(value);
432 if( cfg->ac_fakedelay<100 || cfg->ac_fakedelay>1000 )
433 cfg->ac_fakedelay=1000;
434 return;
435 }
436 if( !strcmp(token, "denysamples") )
437 {
438 cfg->ac_denysamples=atoi(value);
439 if( cfg->ac_denysamples<2 || cfg->ac_denysamples>cfg->ac_samples-1 )
440 cfg->ac_denysamples=cfg->ac_samples-1;
441 return;
442 }
443 if (token[0] != '#')
444 fprintf(stderr, "Warning: keyword '%s' in anticascading section not recognized\n",token);
445//#endif moved this endif up two lines, I think this was erroneous - dingo35
446}
447#endif
448
449void chk_t_monitor(char *token, char *value)
450{
451 if (!strcmp(token, "port")) { cfg->mon_port=atoi(value); return; }
452 if (!strcmp(token, "serverip")) { cfg->mon_srvip=inet_addr(value); return; }
453 if (!strcmp(token, "nocrypt")) { chk_iprange(value, &cfg->mon_allowed); return; }
454 if (!strcmp(token, "aulow")) { cfg->mon_aulow=atoi(value); return; }
455 if (!strcmp(token, "monlevel")) { cfg->mon_level=atoi(value); return; }
456 if (!strcmp(token, "hideclient_to")) { cfg->mon_hideclient_to=atoi(value); return; }
457 if (token[0] != '#')
458 fprintf(stderr, "Warning: keyword '%s' in monitor section not recognized\n",token);
459}
460
461void chk_t_camd33(char *token, char *value)
462{
463 if (!strcmp(token, "port")) { cfg->c33_port=atoi(value); return; }
464 if (!strcmp(token, "serverip")) { cfg->c33_srvip=inet_addr(value); return; }
465 if (!strcmp(token, "nocrypt")) { chk_iprange(value, &cfg->c33_plain); return; }
466 if (!strcmp(token, "passive")) { cfg->c33_passive=(value[0]!='0'); return; }
467 if (!strcmp(token, "key"))
468 {
469 if (key_atob(value, cfg->c33_key))
470 {
471 fprintf(stderr, "Configuration camd3.3x: Error in Key\n");
472 exit(1);
473 }
474 cfg->c33_crypted=1;
475 return;
476 }
477 if (token[0] != '#')
478 fprintf(stderr, "Warning: keyword '%s' in camd33 section not recognized\n",token);
479}
480
481void chk_t_camd35(char *token, char *value)
482{
483 if (!strcmp(token, "port")) { cfg->c35_port=atoi(value); return; }
484 if (!strcmp(token, "serverip")) { cfg->c35_tcp_srvip=inet_addr(value); return; }
485 if (!strcmp(token, "suppresscmd08")) { cfg->c35_suppresscmd08=atoi(value); return; }
486 if (token[0] != '#')
487 fprintf(stderr, "Warning: keyword '%s' in camd35 section not recognized\n",token);
488}
489
490void chk_t_camd35_tcp(char *token, char *value)
491{
492 if (!strcmp(token, "port")) { chk_port_tab(value, &cfg->c35_tcp_ptab); return; }
493 if (!strcmp(token, "serverip")) { cfg->c35_tcp_srvip=inet_addr(value); return; }
494 if (!strcmp(token, "suppresscmd08")) { cfg->c35_suppresscmd08=atoi(value); return; }
495 if (token[0] != '#')
496 fprintf(stderr, "Warning: keyword '%s' in camd35 tcp section not recognized\n",token);
497}
498
499void chk_t_newcamd(char *token, char *value)
500{
501 if (!strcmp(token, "port")) { chk_port_tab(value, &cfg->ncd_ptab); return; }
502 if (!strcmp(token, "serverip")) { cfg->ncd_srvip=inet_addr(value); return; }
503 if (!strcmp(token, "allowed")) { chk_iprange(value, &cfg->ncd_allowed); return; }
504 if (!strcmp(token, "key"))
505 {
506 if (key_atob14(value, cfg->ncd_key))
507 {
508 fprintf(stderr, "Configuration newcamd: Error in Key\n");
509 exit(1);
510 }
511 return;
512 }
513 if (!strcmp(token, "keepalive"))
514 {
515 cfg->ncd_keepalive=atoi(value);
516 return;
517 }
518 if (token[0] != '#')
519 fprintf(stderr, "Warning: keyword '%s' in newcamd section not recognized\n",token);
520}
521
522void chk_t_cccam(char *token, char *value)
523{
524 if (!strcmp(token, "port")) { cfg->cc_port=atoi(value); return; }
525 //if (!strcmp(token, "serverip")) { cfg->cc_srvip=inet_addr(value); return; }
526 if (!strcmp(token, "reshare")) { cfg->cc_reshare=atoi(value); return; }
527 if (!strcmp(token, "version")) { // cccam version
528 if (strlen(value)>sizeof(cfg->cc_version)-1) {
529 fprintf(stderr, "cccam config: version too long\n");
530 exit(1);
531 }
532 memset(cfg->cc_version, 0, sizeof(cfg->cc_version));
533 strncpy((char*)cfg->cc_version, value, sizeof(cfg->cc_version)-1);
534 return;
535 }
536 if (!strcmp(token, "build")) { // cccam build number
537 if (strlen(value)>sizeof(cfg->cc_build)-1) {
538 fprintf(stderr, "cccam config build number too long\n");
539 exit(1);
540 }
541 memset(cfg->cc_build, 0, sizeof(cfg->cc_build));
542 strncpy((char*)cfg->cc_build, value, sizeof(cfg->cc_build)-1);
543 return;
544 }
545 if (token[0] != '#')
546 fprintf(stderr, "Warning: keyword '%s' in cccam section not recognized\n",token);
547}
548
549void chk_t_radegast(char *token, char *value)
550{
551 if (!strcmp(token, "port")) { cfg->rad_port=atoi(value); return; }
552 if (!strcmp(token, "serverip")) { cfg->rad_srvip=inet_addr(value); return; }
553 if (!strcmp(token, "allowed")) { chk_iprange(value, &cfg->rad_allowed); return; }
554 if (!strcmp(token, "user")) { strncpy(cfg->rad_usr, value, sizeof(cfg->rad_usr)-1); return; }
555 if (token[0] != '#')
556 fprintf(stderr, "Warning: keyword '%s' in radegast section not recognized\n",token);
557}
558
559void chk_t_serial(char *token, char *value)
560{
561 if (!strcmp(token, "device"))
562 {
563 int l;
564 l=strlen(cfg->ser_device);
565 if (l) cfg->ser_device[l++]=1; // use ctrl-a as delimiter
566 strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-1-l);
567 return;
568 }
569 if (token[0] != '#')
570 fprintf(stderr, "Warning: keyword '%s' in serial section not recognized\n",token);
571}
572
573#ifdef CS_WITH_GBOX
574static void chk_t_gbox(char *token, char *value)
575{
576// if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
577 if (!strcmp(token, "password")) { cs_atob(cfg->gbox_pwd, value, 4); return; }
578 if (!strcmp(token, "maxdist")) { cfg->maxdist=atoi(value); return; }
579 if (!strcmp(token, "ignorelist")) { strncpy((char *)cfg->ignorefile, value, sizeof(cfg->ignorefile)-1); return; }
580 if (!strcmp(token, "onlineinfos")) { strncpy((char *)cfg->gbxShareOnl, value, sizeof(cfg->gbxShareOnl)-1); return; }
581 if (!strcmp(token, "cardinfos")) { strncpy((char *)cfg->cardfile, value, sizeof(cfg->cardfile)-1); return; }
582 if (!strcmp(token, "locals"))
583 {
584 char *ptr1;
585 int n=0, i;
586 for (i=0, ptr1=strtok(value, ","); (i<CS_MAXLOCALS) && (ptr1); ptr1=strtok(NULL, ","))
587 {
588 cfg->locals[n++]=a2i(ptr1, 8);
589 //printf("%i %08X",n,cfg->locals[n-1]);
590 }
591 cfg->num_locals=n;
592 return;
593 }
594 if (token[0] != '#')
595 fprintf(stderr, "Warning: keyword '%s' in gbox section not recognized\n",token);
596}
597#endif
598
599#ifdef HAVE_DVBAPI
600void chk_t_dvbapi(char *token, char *value)
601{
602 if (!strcmp(token, "enabled")) { cfg->dvbapi_enabled=atoi(value); return; }
603 if (!strcmp(token, "au")) { cfg->dvbapi_au=atoi(value); return; }
604 if (!strcmp(token, "boxtype")) { strncpy(cfg->dvbapi_boxtype, value, sizeof(cfg->dvbapi_boxtype)-1); return; }
605 if (!strcmp(token, "user")) { strncpy(cfg->dvbapi_usr, value, sizeof(cfg->dvbapi_usr)-1); return; }
606 if (!strcmp(token, "priority")) { strncpy(cfg->dvbapi_priority, value, sizeof(cfg->dvbapi_priority)-1); return; }
607 if (!strcmp(token, "ignore")) { strncpy(cfg->dvbapi_ignore, value, sizeof(cfg->dvbapi_ignore)-1); return; }
608
609 if (token[0] != '#')
610 fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token);
611}
612#endif
613
614static void chk_token(char *token, char *value, int tag)
615{
616 switch(tag)
617 {
618 case TAG_GLOBAL : chk_t_global(token, value); break;
619 case TAG_MONITOR : chk_t_monitor(token, value); break;
620 case TAG_CAMD33 : chk_t_camd33(token, value); break;
621 case TAG_CAMD35 :
622 case TAG_CS357X : chk_t_camd35(token, value); break;
623 case TAG_NEWCAMD : chk_t_newcamd(token, value); break;
624 case TAG_RADEGAST: chk_t_radegast(token, value); break;
625 case TAG_SERIAL : chk_t_serial(token, value); break;
626 case TAG_CS378X : chk_t_camd35_tcp(token, value); break;
627#ifdef CS_WITH_GBOX
628 case TAG_GBOX : chk_t_gbox(token, value); break;
629#endif
630 case TAG_CCCAM : chk_t_cccam(token, value); break;
631#ifdef HAVE_DVBAPI
632 case TAG_DVBAPI : chk_t_dvbapi(token, value); break;
633#else
634 case TAG_DVBAPI : fprintf(stderr, "Warning: OSCam compiled without DVB API support.\n"); break;
635#endif
636#ifdef CS_ANTICASC
637 case TAG_ANTICASC: chk_t_ac(token, value); break;
638#endif
639 }
640}
641
642void init_len4caid()
643{
644 int nr;
645 FILE *fp;
646 char *value;
647
648 memset(len4caid, 0, sizeof(ushort)<<8);
649 sprintf(token, "%s%s", cs_confdir, cs_l4ca);
650 if (!(fp=fopen(token, "r")))
651 return;
652 for(nr=0; fgets(token, sizeof(token), fp);)
653 {
654 int i, c;
655 char *ptr;
656 if (!(value=strchr(token, ':'))) continue;
657 *value++='\0';
658 if( (ptr=strchr(value, '#')) )
659 *ptr='\0';
660 if (strlen(trim(token))!=2) continue;
661 if (strlen(trim(value))!=4) continue;
662 if ((i=byte_atob(token))<0) continue;
663 if ((c=word_atob(value))<0) continue;
664//printf("idx %02X = %04X\n", i, c); fflush(stdout);
665 len4caid[i]=c;
666 nr++;
667 }
668 fclose(fp);
669 cs_log("%d lengths for caid guessing loaded", nr);
670 return;
671}
672
673int search_boxkey(ushort caid, char *key)
674{
675 int i, rc=0;
676 FILE *fp;
677 char c_caid[512];
678
679 sprintf(c_caid, "%s%s", cs_confdir, cs_cert);
680 fp=fopen(c_caid, "r");
681 if (fp)
682 {
683 for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);)
684 {
685 char *c_provid, *c_key;
686
687 c_provid=strchr(c_caid, '#');
688 if (c_provid) *c_provid='\0';
689 if (!(c_provid=strchr(c_caid, ':'))) continue;
690 *c_provid++='\0';
691 if (!(c_key=strchr(c_provid, ':'))) continue;
692 *c_key++='\0';
693 if (word_atob(trim(c_caid))!=caid) continue;
694 if ((i=(strlen(trim(c_key))>>1))>256) continue;
695 if (cs_atob((uchar *)key, c_key, i)<0)
696 {
697 cs_log("wrong key in \"%s\"", cs_cert);
698 continue;
699 }
700 rc=1;
701 }
702 fclose(fp);
703 }
704#ifdef OSCAM_INBUILD_KEYS
705 for(i=0; (!rc) && (npkey[i].keylen); i++)
706 if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0)))
707 memcpy(key, npkey[i].key, npkey[i].keylen);
708#endif
709 return(rc);
710}
711
712int init_config()
713{
714 int tag=TAG_GLOBAL;
715 FILE *fp;
716 char *value;
717
718#ifndef CS_EMBEDDED
719#ifdef PRIO_PROCESS
720 errno=0;
721 if ((cfg->nice=getpriority(PRIO_PROCESS, 0))==(-1))
722 if (errno)
723#endif
724#endif
725 cfg->nice=99;
726 cfg->ctimeout=CS_CLIENT_TIMEOUT;
727 cfg->ftimeout=CS_CLIENT_TIMEOUT / 2;
728 cfg->cmaxidle=CS_CLIENT_MAXIDLE;
729 cfg->delay=CS_DELAY;
730 cfg->bindwait=CS_BIND_TIMEOUT;
731 cfg->resolvedelay=CS_RESOLVE_DELAY;
732 cfg->mon_level=2;
733 cfg->mon_hideclient_to=0;
734 cfg->srtimeout=1500;
735 cfg->ulparent=0;
736 cfg->logfile=NULL;
737 cfg->pidfile=NULL;
738 cfg->usrfile=NULL;
739 cfg->cwlogdir=NULL;
740#ifdef CS_ANTICASC
741 cfg->ac_enabled=0;
742 cfg->ac_users=0;
743 cfg->ac_stime=2;
744 cfg->ac_samples=10;
745 cfg->ac_denysamples=8;
746 cfg->ac_fakedelay=1000;
747 strcpy(cfg->ac_logfile, "./oscam_ac.log");
748#endif
749 cfg->ncd_keepalive=1;
750 sprintf(token, "%s%s", cs_confdir, cs_conf);
751 if (!(fp=fopen(token, "r")))
752 {
753 fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno);
754 exit(1);
755 }
756 while (fgets(token, sizeof(token), fp))
757 {
758 int i, l;
759 //void *ptr;
760 if ((l=strlen(trim(token)))<3) continue;
761 if ((token[0]=='[') && (token[l-1]==']'))
762 {
763 for (token[l-1]=0, tag=-1, i=TAG_GLOBAL; cctag[i]; i++)
764 if (!strcmp(cctag[i], strtolower(token+1)))
765 tag=i;
766 continue;
767 }
768 if (!(value=strchr(token, '='))) continue;
769 *value++='\0';
770 chk_token(trim(strtolower(token)), trim(value), tag);
771 }
772 fclose(fp);
773#ifdef CS_LOGFILE
774 if (cfg->logfile == NULL)
775 asprintf(&(cfg->logfile), "%s", CS_LOGFILE);
776#endif
777 cs_init_log(cfg->logfile);
778 if (cfg->ftimeout>=cfg->ctimeout)
779 {
780 cfg->ftimeout = cfg->ctimeout - 100;
781 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout);
782 }
783 if(cfg->ftimeout < cfg->srtimeout)
784 {
785 cfg->ftimeout = cfg->srtimeout + 100;
786 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout);
787 }
788 if(cfg->ctimeout < cfg->srtimeout)
789 {
790 cfg->ctimeout = cfg->srtimeout + 100;
791 cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout);
792 }
793#ifdef CS_ANTICASC
794 if( cfg->ac_denysamples+1>cfg->ac_samples )
795 {
796 cfg->ac_denysamples=cfg->ac_samples-1;
797 cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples);
798 }
799#endif
800 return 0;
801}
802
803void chk_account(char *token, char *value, struct s_auth *account)
804{
805 int i;
806 char *ptr1;//, *ptr2;
807 if (!strcmp(token, "user")) { strncpy(account->usr, value, sizeof(account->usr)-1); return; }
808 if (!strcmp(token, "pwd")) { strncpy(account->pwd, value, sizeof(account->pwd)-1); return; }
809 if (!strcmp(token, "hostname")) { strncpy((char *)account->dyndns, value, sizeof(account->dyndns)-1); return; }
810 if (!strcmp(token, "betatunnel")) { chk_tuntab(value, &account->ttab); return; }
811 if (!strcmp(token, "uniq")) { account->uniq=atoi(value); return; }
812 if (!strcmp(token, "sleep")) { account->tosleep=atoi(value); return; }
813 if (!strcmp(token, "monlevel")) { account->monlvl=atoi(value); return; }
814 if (!strcmp(token, "caid")) { chk_caidtab(value, &account->ctab); return; }
815 if (!strcmp(token, "disabled")) { account->disabled=atoi(value); return; }
816 if (!strcmp(token, "suppresscmd08")) { account->c35_suppresscmd08=atoi(value); return; }
817 if (!strcmp(token, "keepalive"))
818 {
819 account->ncd_keepalive = atoi(value);
820 return;
821 }
822 /*
823 * case insensitive
824 */
825 strtolower(value);
826 if (!strcmp(token, "au"))
827 {
828 if(value && value[0]=='1') account->autoau=1;
829 for (i=0; i<CS_MAXREADER; i++)
830 if ((reader[i].label[0]) &&
831 (!strncmp(reader[i].label, value, strlen(reader[i].label))))
832 account->au=i;
833 return;
834 }
835 if (!strcmp(token, "group"))\
836 {
837 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ","))
838 {
839 int g;
840 g=atoi(ptr1);
841 if ((g>0) && (g<33)) account->grp|=(1<<(g-1));
842 }
843 return;
844 }
845 if(!strcmp(token, "services")) { chk_services(value, &account->sidtabok, &account->sidtabno); return; }
846 if(!strcmp(token, "ident")) { chk_ftab(value, &account->ftab, "user", account->usr, "provid"); return; }
847 if(!strcmp(token, "class")) { chk_cltab(value, &account->cltab); return; }
848 if(!strcmp(token, "chid")) { chk_ftab(value, &account->fchid, "user", account->usr, "chid"); return; }
849
850 if (!strcmp(token, "expdate"))
851 {
852 if (!value[0]) {
853 account->expirationdate=(time_t)NULL;
854 return;
855 }
856 struct tm cstime;
857 memset(&cstime,0,sizeof(cstime));
858 for (i=0, ptr1=strtok(value, "-/"); (i<3)&&(ptr1); ptr1=strtok(NULL, "-/"), i++)
859 {
860 switch(i)
861 {
862 case 0: cstime.tm_year=atoi(ptr1)-1900; break;
863 case 1: cstime.tm_mon =atoi(ptr1)-1; break;
864 case 2: cstime.tm_mday=atoi(ptr1); break;
865 }
866 }
867 account->expirationdate=mktime(&cstime);
868 return;
869 }
870
871#ifdef CS_ANTICASC
872 if( !strcmp(token, "numusers") )
873 {
874 account->ac_users = atoi(value);
875 return;
876 }
877 if( !strcmp(token, "penalty") )
878 {
879 account->ac_penalty = atoi(value);
880 return;
881 }
882#endif
883 if (token[0] != '#')
884 fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n",token);
885
886// if (!strcmp(token, "caid"))
887// {
888// for (i=0, ptr1=strtok(value, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ","))
889// {
890// ulong caid, mask;
891// if (ptr2=strchr(trim(ptr1), '&'))
892// *ptr2++='\0';
893// else
894// ptr2="";
895// if (((caid=a2i(ptr1, 2))|(mask=a2i(ptr2,-2))) < 0x10000)
896// {
897// account->caidtab[i][0]=caid;
898// account->caidtab[i++][1]=mask;
899// }
900// else
901// cs_log("WARNING: wrong CAID in %s -> ignored", cs_user);
902// }
903// }
904}
905
906int init_userdb()
907{
908 int tag = 0, nr, nro, expired, disabled;
909 //int first=1;
910 FILE *fp;
911 char *value;
912 struct s_auth *ptr;
913 /*static */struct s_auth *account=(struct s_auth *)0;
914
915 sprintf(token, "%s%s", cs_confdir, cs_user);
916 if (!(fp = fopen(token, "r"))) {
917 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
918 return(1);
919 }
920
921 for (nro = 0, ptr = cfg->account; ptr; nro++) {
922 struct s_auth *ptr_next;
923 ptr_next = ptr->next;
924 free(ptr);
925 ptr = ptr_next;
926 }
927 nr = 0;
928
929 while (fgets(token, sizeof(token), fp)) {
930 int i, l;
931 void *ptr;
932
933 if ((l=strlen(trim(token))) < 3)
934 continue;
935
936 if ((token[0] == '[') && (token[l-1] == ']')) {
937 token[l - 1] = 0;
938 tag = (!strcmp("account", strtolower(token + 1)));
939
940 if (!(ptr=malloc(sizeof(struct s_auth)))) {
941 cs_log("Error allocating memory (errno=%d)", errno);
942 return(1);
943 }
944
945 if (account)
946 account->next = ptr;
947 else
948 cfg->account = ptr;
949
950 account = ptr;
951 memset(account, 0, sizeof(struct s_auth));
952 account->au = (-1);
953 account->monlvl = cfg->mon_level;
954 account->tosleep = cfg->tosleep;
955 account->c35_suppresscmd08 = cfg->c35_suppresscmd08;
956 account->ncd_keepalive = cfg->ncd_keepalive;
957 for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff);
958 for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000);
959 nr++;
960
961#ifdef CS_ANTICASC
962 account->ac_users = cfg->ac_users;
963 account->ac_penalty = cfg->ac_penalty;
964 account->ac_idx = nr;
965#endif
966 continue;
967 }
968
969 if (!tag)
970 continue;
971
972 if (!(value=strchr(token, '=')))
973 continue;
974
975 *value++ = '\0';
976 chk_account(trim(strtolower(token)), trim(value), account);
977 }
978
979 fclose(fp);
980
981 for (expired = 0, disabled = 0, ptr = cfg->account; ptr;) {
982
983 if(ptr->expirationdate && ptr->expirationdate < time(NULL))
984 expired++;
985
986 if(ptr->disabled != 0)
987 disabled++;
988
989 ptr = ptr->next;
990 }
991
992 cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled);
993 return(0);
994}
995
996static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
997{
998 int i, b;
999 char *ptr;
1000 ushort *slist=(ushort *) 0;
1001 ulong *llist=(ulong *) 0;
1002 ulong caid;
1003 char buf[strlen(value) + 1];
1004 strncpy(buf, value, sizeof(buf));
1005 b=(what==1) ? sizeof(ulong) : sizeof(ushort);
1006 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1007 {
1008 caid=a2i(ptr, b);
1009 if (!errno) i++;
1010 }
1011 //if (!i) return(0);
1012 if (b==sizeof(ushort))
1013 slist=malloc(i*sizeof(ushort));
1014 else
1015 llist=malloc(i*sizeof(ulong));
1016 strcpy(value, buf);
1017 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1018 {
1019 caid=a2i(ptr, b);
1020 if (errno) continue;
1021 if (b==sizeof(ushort))
1022 slist[i++]=(ushort) caid;
1023 else
1024 llist[i++]=caid;
1025 }
1026 switch (what)
1027 {
1028 case 0: sidtab->caid=slist;
1029 sidtab->num_caid=i;
1030 break;
1031 case 1: sidtab->provid=llist;
1032 sidtab->num_provid=i;
1033 break;
1034 case 2: sidtab->srvid=slist;
1035 sidtab->num_srvid=i;
1036 break;
1037 }
1038}
1039
1040void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
1041{
1042 if (!strcmp(token, "caid")) { chk_entry4sidtab(value, sidtab, 0); return; }
1043 if (!strcmp(token, "provid")) { chk_entry4sidtab(value, sidtab, 1); return; }
1044 if (!strcmp(token, "ident")) { chk_entry4sidtab(value, sidtab, 1); return; }
1045 if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; }
1046 if (token[0] != '#')
1047 fprintf(stderr, "Warning: keyword '%s' in sidtab section not recognized\n",token);
1048}
1049
1050int init_sidtab()
1051{
1052 int nr, nro;
1053 FILE *fp;
1054 char *value;
1055 struct s_sidtab *ptr;
1056 struct s_sidtab *sidtab=(struct s_sidtab *)0;
1057
1058 sprintf(token, "%s%s", cs_confdir, cs_sidt);
1059 if (!(fp=fopen(token, "r")))
1060 {
1061 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
1062 return(1);
1063 }
1064 for (nro=0, ptr=cfg->sidtab; ptr; nro++)
1065 {
1066 struct s_sidtab *ptr_next;
1067 ptr_next=ptr->next;
1068 if (ptr->caid) free(ptr->caid);
1069 if (ptr->provid) free(ptr->provid);
1070 if (ptr->srvid) free(ptr->srvid);
1071 free(ptr);
1072 ptr=ptr_next;
1073 }
1074 nr=0;
1075 while (fgets(token, sizeof(token), fp))
1076 {
1077 int l;
1078 void *ptr;
1079 if ((l=strlen(trim(token)))<3) continue;
1080 if ((token[0]=='[') && (token[l-1]==']'))
1081 {
1082 token[l-1]=0;
1083 if (!(ptr=malloc(sizeof(struct s_sidtab))))
1084 {
1085 cs_log("Error allocating memory (errno=%d)", errno);
1086 return(1);
1087 }
1088 if (sidtab)
1089 sidtab->next=ptr;
1090 else
1091 cfg->sidtab=ptr;
1092 sidtab=ptr;
1093 nr++;
1094 memset(sidtab, 0, sizeof(struct s_sidtab));
1095 strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
1096 continue;
1097 }
1098 if (!sidtab) continue;
1099 if (!(value=strchr(token, '='))) continue;
1100 *value++='\0';
1101 chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
1102 }
1103 fclose(fp);
1104
1105#ifdef DEBUG_SIDTAB
1106 show_sidtab(cfg->sidtab);
1107#endif
1108 cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
1109 return(0);
1110}
1111
1112int init_srvid()
1113{
1114 int nr;
1115 FILE *fp;
1116 char *payload;
1117 static struct s_srvid *srvid=(struct s_srvid *)0;
1118 sprintf(token, "%s%s", cs_confdir, cs_srid);
1119
1120 if (!(fp=fopen(token, "r"))) {
1121 cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
1122 return(0);
1123 }
1124
1125 nr=0;
1126 while (fgets(token, sizeof(token), fp)) {
1127
1128 int l;
1129 void *ptr;
1130 char *tmp;
1131 tmp = trim(token);
1132
1133 if (tmp[0] == '#') continue;
1134 if ((l=strlen(tmp)) < 6) continue;
1135 if (!(payload=strchr(token, '|'))) continue;
1136 *payload++ = '\0';
1137
1138 if (!(ptr = malloc(sizeof(struct s_srvid)))) {
1139 cs_log("Error allocating memory (errno=%d)", errno);
1140 return(1);
1141 }
1142
1143 if (srvid)
1144 srvid->next = ptr;
1145 else
1146 cfg->srvid = ptr;
1147
1148 srvid = ptr;
1149 memset(srvid, 0, sizeof(struct s_srvid));
1150
1151 int i;
1152 char *ptr1;
1153 for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
1154 switch(i){
1155 case 0:
1156 strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov)-1);
1157 break;
1158 case 1:
1159 strncpy(srvid->name, trim(ptr1), sizeof(srvid->name)-1);
1160 break;
1161 case 2:
1162 strncpy(srvid->type, trim(ptr1), sizeof(srvid->type)-1);
1163 break;
1164 case 3:
1165 strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc)-1);
1166 break;
1167 }
1168 }
1169
1170 char *srvidasc = strchr(token, ':');
1171 *srvidasc++ = '\0';
1172 srvid->srvid = word_atob(srvidasc);
1173
1174 srvid->ncaid = 0;
1175 for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
1176 srvid->caid[i] = word_atob(ptr1);
1177 srvid->ncaid = i+1;
1178 }
1179 nr++;
1180 }
1181
1182 fclose(fp);
1183 if (nr>0)
1184 cs_log("%d service-id's loaded", nr);
1185 else{
1186 cs_log("oscam.srvid loading failed, old format");
1187 }
1188 return(0);
1189}
1190
1191static void chk_reader(char *token, char *value, struct s_reader *rdr)
1192{
1193 int i;
1194 char *ptr;
1195 /*
1196 * case sensitive first
1197 */
1198 if (!strcmp(token, "device"))
1199 {
1200 for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
1201 {
1202 trim(ptr);
1203 switch(i)
1204 {
1205 case 0: strncpy(rdr->device, ptr, sizeof(rdr->device)-1); break;
1206 case 1: rdr->r_port=atoi(ptr); break;
1207 case 2: rdr->l_port=atoi(ptr); break;
1208 }
1209 }
1210 return;
1211 }
1212 if (!strcmp(token, "key"))
1213 {
1214 if (key_atob14(value, rdr->ncd_key))
1215 {
1216 fprintf(stderr, "Configuration newcamd: Error in Key\n");
1217 exit(1);
1218 }
1219 return;
1220 }
1221#ifdef CS_WITH_GBOX
1222 if (!strcmp(token, "password")) { strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4); return; }
1223 if (!strcmp(token, "premium")) { rdr->gbox_prem=1; return; }
1224#endif
1225 if (!strcmp(token, "account"))
1226 {
1227 for (i=0, ptr=strtok(value, ","); (i<2)&&(ptr); ptr=strtok(NULL, ","), i++)
1228 {
1229 trim(ptr);
1230 switch(i)
1231 {
1232 case 0: strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr)-1); break;
1233 case 1: strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd)-1); break;
1234 }
1235 }
1236 return;
1237 }
1238 if( !strcmp(token, "pincode")) { strncpy(rdr->pincode, value, sizeof(rdr->pincode)-1); return; }
1239 if (!strcmp(token, "readnano") && value[0]) { asprintf(&(rdr->emmfile), "%s", value); return; }
1240 /*
1241 * case insensitive
1242 */
1243 strtolower(value);
1244
1245 if (!strcmp(token, "enable")) { rdr->enable=atoi(value) ? 1 : 0; return; }
1246 if (!strcmp(token, "services")) { chk_services(value, &rdr->sidtabok, &rdr->sidtabno); return; }
1247 if (!strcmp(token, "inactivitytimeout")) { rdr->tcp_ito = atoi(value); return; }
1248 if (!strcmp(token, "reconnecttimeout")) { rdr->tcp_rto = atoi(value); return; }
1249 if (!strcmp(token, "disableserverfilter")) { rdr->ncd_disable_server_filt = atoi(value); return; }
1250 //FIXME workaround for Smargo until native mode works
1251 if (!strcmp(token, "smargopatch")) { rdr->smargopatch = atoi(value); return; }
1252 if (!strcmp(token, "label")) { strncpy(rdr->label, value, sizeof(rdr->label)-1); return; }
1253 if (!strcmp(token, "fallback")) { rdr->fallback=atoi(value) ? 1 : 0; return; }
1254 if (!strcmp(token, "logport")) { rdr->log_port=atoi(value); return; }
1255 if (!strcmp(token, "caid")) { chk_caidtab(value, &rdr->ctab); return; }
1256 if (!strcmp(token, "boxid")) { rdr->boxid=a2i(value,4); return; }
1257 if (!strcmp(token, "aeskey"))
1258 {
1259 if (key_atob(value, rdr->aes_key))
1260 {
1261 fprintf(stderr, "Configuration reader: Error in AES Key\n");
1262 exit(1);
1263 }
1264 return;
1265 }
1266 if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey")) )
1267 {
1268 rdr->has_rsa=1;
1269 if (key_atob_l(value, rdr->rsa_mod, 128))
1270 {
1271 fprintf(stderr, "Configuration reader: Error in rsakey\n");
1272 exit(1);
1273 }
1274 return;
1275 }
1276 if (!strcmp(token, "tiger_rsakey"))
1277 {
1278 if (key_atob_l(value, rdr->rsa_mod, 240))
1279 {
1280 fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
1281 exit(1);
1282 }
1283 return;
1284 }
1285 if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey")))
1286 {
1287 if (key_atob_l(value, rdr->nagra_boxkey, 16))
1288 {
1289 fprintf(stderr, "Configuration reader: Error in boxkey\n");
1290 exit(1);
1291 }
1292 return;
1293 }
1294 if (!strcmp(token, "detect"))
1295 {
1296 for (i=0; RDR_CD_TXT[i]; i++)
1297 {
1298 if (!strcmp(value, RDR_CD_TXT[i]))
1299 rdr->detect=i;
1300 else
1301 if ((value[0]=='!') && (!strcmp(value+1, RDR_CD_TXT[i])))
1302 rdr->detect=i|0x80;
1303 }
1304 return;
1305 }
1306 if (!strcmp(token, "mhz")) { rdr->mhz=atoi(value); return; }
1307 if (!strcmp(token, "cardmhz")) { rdr->cardmhz=atoi(value); return; }
1308 if (!strcmp(token, "protocol"))
1309 {
1310 if (!strcmp(value, "mouse")) { rdr->typ=R_MOUSE; return; }
1311 if (!strcmp(value, "smartreader")) { rdr->typ=R_SMART; return; }
1312 if (!strcmp(value, "internal")) { rdr->typ=R_INTERNAL; return; }
1313#ifdef HAVE_PCSC
1314 if (!strcmp(value, "pcsc")) { rdr->typ=R_PCSC; return; }
1315#endif
1316 if (!strcmp(value, "serial")) { rdr->typ=R_SERIAL; return; }
1317 if (!strcmp(value, "camd35")) { rdr->typ=R_CAMD35; return; }
1318 if (!strcmp(value, "cs378x")) { rdr->typ=R_CS378X; return; }
1319 if (!strcmp(value, "cs357x")) { rdr->typ=R_CAMD35; return; }
1320 if (!strcmp(value, "gbox")) { rdr->typ=R_GBOX; return; }
1321 if (!strcmp(value, "cccam")) {
1322 rdr->typ=R_CCCAM;
1323 // strcpy(value, "1");
1324 // chk_caidtab(value, &rdr->ctab); // this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
1325 return;
1326 }
1327 if (!strcmp(value, "radegast")) { rdr->typ=R_RADEGAST; return; }
1328 if (!strcmp(value, "newcamd") ||
1329 !strcmp(value, "newcamd525")) {rdr->typ=R_NEWCAMD;
1330 rdr->ncd_proto=NCD_525; return; }
1331 if (!strcmp(value, "newcamd524")) {rdr->typ=R_NEWCAMD;
1332 rdr->ncd_proto=NCD_524; return; }
1333 fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
1334 rdr->typ=R_MOUSE;
1335 return;
1336 }
1337 if (!strcmp(token, "loadbalanced")) { rdr->loadbalanced=atoi(value); return; }
1338 if (!strcmp(token, "ident")) { chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid"); return; }
1339 if (!strcmp(token, "class")) { chk_cltab(value, &rdr->cltab); return; }
1340 if (!strcmp(token, "chid")) { chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid"); return; }
1341 if (!strcmp(token, "showcls")) { rdr->show_cls = atoi(value); return; }
1342 if (!strcmp(token, "maxqlen"))
1343 {
1344 rdr->maxqlen = atoi(value);
1345 if( rdr->maxqlen<0 || rdr->maxqlen>CS_MAXQLEN )
1346 rdr->maxqlen=CS_MAXQLEN;
1347 return;
1348 }
1349 if (!strcmp(token, "group"))
1350 {
1351 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1352 {
1353 int g;
1354 g=atoi(ptr);
1355 if ((g>0) && (g<33)) rdr->grp|=(1<<(g-1));
1356 }
1357 return;
1358 }
1359 if (!strcmp(token, "emmcache"))
1360 {
1361 for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
1362 switch(i)
1363 {
1364 case 0: rdr->cachemm=atoi(ptr); break;
1365 case 1: rdr->rewritemm=atoi(ptr); break;
1366 case 2: rdr->logemm=atoi(ptr); break;
1367 }
1368 if (rdr->rewritemm <=0) {
1369 fprintf(stderr, "Notice: Setting EMMCACHE to %i,1,%i instead of %i,%i,%i. Zero or negative number of rewrites is silly\n", rdr->cachemm,rdr->logemm,rdr->cachemm,rdr->rewritemm,rdr->logemm);
1370 rdr->rewritemm = 1;
1371 }
1372 return;
1373 }
1374
1375 if (!strcmp(token, "blocknano"))
1376 {
1377 if (!strcmp(value,"all")) //wildcard is used
1378 for (i=0 ; i<256; i++)
1379 rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
1380 else
1381 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1382 if ((i=byte_atob(ptr))>=0)
1383 rdr->b_nano[i]|= 0x01; //lsb is set when to block nano
1384 return;
1385 }
1386 if (!strcmp(token, "savenano"))
1387 {
1388 if (!strcmp(value,"all")) //wildcard is used
1389 for (i=0 ; i<256; i++)
1390 rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
1391 else
1392 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1393 if ((i=byte_atob(ptr))>=0)
1394 rdr->b_nano[i]|= 0x02; //lsb+1 is set when to save nano to file
1395 return;
1396 }
1397 if (!strcmp(token, "cccversion")) { // cccam version
1398 if (strlen(value)>sizeof(rdr->cc_version)-1) {
1399 fprintf(stderr, "cccam config: version too long\n");
1400 exit(1);
1401 }
1402 memset(rdr->cc_version, 0, sizeof(rdr->cc_version));
1403 strncpy(rdr->cc_version, value, sizeof(rdr->cc_version)-1);
1404 return;
1405 }
1406 if (!strcmp(token, "cccbuild")) { // cccam build number
1407 if (strlen(value)>sizeof(rdr->cc_build)-1) {
1408 fprintf(stderr, "cccam config build number too long\n");
1409 exit(1);
1410 }
1411 memset(rdr->cc_build, 0, sizeof(rdr->cc_build));
1412 strncpy(rdr->cc_build, value, sizeof(rdr->cc_build)-1);
1413 return;
1414 }
1415 if (!strcmp(token, "cccmaxhop")) { // cccam max card distance
1416 rdr->cc_maxhop = atoi(value);
1417 return;
1418 }
1419 if (!strcmp(token, "deprecated")) { rdr->deprecated=atoi(value); return; }
1420 if (token[0] != '#')
1421 fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);
1422}
1423
1424int init_readerdb()
1425{
1426 int tag=0, nr;
1427 FILE *fp;
1428 char *value;
1429
1430 sprintf(token, "%s%s", cs_confdir, cs_srvr);
1431 if (!(fp=fopen(token, "r")))
1432 {
1433 cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
1434 return(1);
1435 }
1436 nr=0;
1437 while (fgets(token, sizeof(token), fp))
1438 {
1439 int i, l;
1440 if ((l=strlen(trim(token)))<3) continue;
1441 if ((token[0]=='[') && (token[l-1]==']'))
1442 {
1443 token[l-1]=0;
1444 tag=(!strcmp("reader", strtolower(token+1)));
1445 if (reader[nr].label[0] && reader[nr].typ) nr++;
1446 memset(&reader[nr], 0, sizeof(struct s_reader));
1447 reader[nr].enable = 1;
1448 reader[nr].tcp_rto = 30;
1449 reader[nr].show_cls = 10;
1450 reader[nr].maxqlen = CS_MAXQLEN;
1451 reader[nr].mhz = 357;
1452 reader[nr].cardmhz = 357;
1453 reader[nr].deprecated = 0;
1454 strcpy(reader[nr].pincode, "none");
1455 for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
1456 continue;
1457 }
1458 if (!tag) continue;
1459 if (!(value=strchr(token, '='))) continue;
1460 *value++='\0';
1461 chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
1462 }
1463 fclose(fp);
1464 return(0);
1465}
1466
1467/*
1468int init_irdeto_guess_tab()
1469{
1470 int i, j, skip;
1471 int b47;
1472 FILE *fp;
1473 char token[128], *value, *ptr;
1474 char zSid[5];
1475 uchar b3;
1476 ushort caid, sid;
1477 struct s_irdeto_quess *ird_row, *head;
1478
1479 memset(cfg->itab, 0, sizeof(cfg->itab));
1480 sprintf(token, "%s%s", cs_confdir, cs_ird);
1481 if (!(fp=fopen(token, "r")))
1482 {
1483 cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
1484 token, errno);
1485 return(1);
1486 }
1487 while (fgets(token, sizeof(token), fp))
1488 {
1489 if( strlen(token)<20 ) continue;
1490 for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
1491 {
1492 trim(ptr);
1493 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
1494 skip=1;
1495 break;
1496 }
1497 switch(i)
1498 {
1499 case 0: b3 = a2i(ptr, 2); break;
1500 case 1: b47 = a2i(ptr, 8); break;
1501 case 2: caid = a2i(ptr, 4); break;
1502 case 3:
1503 for( j=0; j<4; j++ )
1504 zSid[j]=ptr[j];
1505 zSid[4]=0;
1506 sid = a2i(zSid, 4);
1507 break;
1508 }
1509 }
1510 if( !skip )
1511 {
1512 if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
1513 {
1514 cs_log("Error allocating memory (errno=%d)", errno);
1515 return;
1516 }
1517 ird_row->b47 = b47;
1518 ird_row->caid = caid;
1519 ird_row->sid = sid;
1520 ird_row->next = 0;
1521
1522 head = cfg->itab[b3];
1523 if( head ) {
1524 while( head->next )
1525 head=head->next;
1526 head->next=ird_row;
1527 }
1528 else
1529 cfg->itab[b3]=ird_row;
1530
1531 //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
1532 }
1533 }
1534 fclose(fp);
1535
1536 for( i=0; i<0xff; i++ )
1537 {
1538 head=cfg->itab[i];
1539 while(head)
1540 {
1541 cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
1542 i, head->b47, head->caid, head->sid);
1543 head=head->next;
1544 }
1545 }
1546 return(0);
1547}
1548*/
1549
1550#ifdef CS_ANTICASC
1551void init_ac()
1552{
1553 int nr;
1554 FILE *fp;
1555 //char *value;
1556
1557 sprintf(token, "%s%s", cs_confdir, cs_ac);
1558 if (!(fp=fopen(token, "r")))
1559 {
1560 cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
1561 token, errno);
1562 return;
1563 }
1564
1565 for(nr=0; fgets(token, sizeof(token), fp);)
1566 {
1567 int i, skip;
1568 ushort caid, sid, chid, dwtime;
1569 ulong provid;
1570 char *ptr, *ptr1;
1571 struct s_cpmap *ptr_cpmap;
1572 static struct s_cpmap *cpmap=(struct s_cpmap *)0;
1573
1574 if( strlen(token)<4 ) continue;
1575
1576 caid=sid=chid=dwtime=0;
1577 provid=0;
1578 skip=0;
1579 ptr1=0;
1580 for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
1581 {
1582 trim(ptr);
1583 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
1584 skip=1;
1585 break;
1586 }
1587 switch( i )
1588 {
1589 case 0:
1590 ptr1=ptr;
1591 break;
1592 case 1:
1593 dwtime = atoi(ptr);
1594 break;
1595 }
1596 }
1597
1598 if( !skip )
1599 {
1600 for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
1601 {
1602 trim(ptr);
1603 switch( i )
1604 {
1605 case 0:
1606 if( *ptr=='*' ) caid = 0;
1607 else caid = a2i(ptr, 4);
1608 break;
1609 case 1:
1610 if( *ptr=='*' ) provid = 0;
1611 else provid = a2i(ptr, 6);
1612 break;
1613 case 2:
1614 if( *ptr=='*' ) sid = 0;
1615 else sid = a2i(ptr, 4);
1616 break;
1617 case 3:
1618 if( *ptr=='*' ) chid = 0;
1619 else chid = a2i(ptr, 4);
1620 break;
1621 }
1622 }
1623 if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
1624 {
1625 cs_log("Error allocating memory (errno=%d)", errno);
1626 return;
1627 }
1628 if( cpmap )
1629 cpmap->next=ptr_cpmap;
1630 else
1631 cfg->cpmap=ptr_cpmap;
1632 cpmap=ptr_cpmap;
1633
1634 cpmap->caid = caid;
1635 cpmap->provid = provid;
1636 cpmap->sid = sid;
1637 cpmap->chid = chid;
1638 cpmap->dwtime = dwtime;
1639 cpmap->next = 0;
1640
1641 cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
1642 nr, caid, provid, sid, chid, dwtime);
1643 nr++;
1644 }
1645 }
1646 fclose(fp);
1647 //cs_log("%d lengths for caid guessing loaded", nr);
1648 return;
1649}
1650#endif
Note: See TracBrowser for help on using the repository browser.