source: trunk/oscam-config.c@ 1658

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

Backport smargopatch reader setting vom WebIf Branch

File size: 46.4 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 bzero(cfg->cc_version, 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 bzero(cfg->cc_build, 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 struct tm cstime;
853 memset(&cstime,0,sizeof(cstime));
854 for (i=0, ptr1=strtok(value, "-/"); (i<3)&&(ptr1); ptr1=strtok(NULL, "-/"), i++)
855 {
856 switch(i)
857 {
858 case 0: cstime.tm_year=atoi(ptr1)-1900; break;
859 case 1: cstime.tm_mon =atoi(ptr1)-1; break;
860 case 2: cstime.tm_mday=atoi(ptr1); break;
861 }
862 }
863 account->expirationdate=mktime(&cstime);
864 return;
865 }
866
867#ifdef CS_ANTICASC
868 if( !strcmp(token, "numusers") )
869 {
870 account->ac_users = atoi(value);
871 return;
872 }
873 if( !strcmp(token, "penalty") )
874 {
875 account->ac_penalty = atoi(value);
876 return;
877 }
878#endif
879 if (token[0] != '#')
880 fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n",token);
881
882// if (!strcmp(token, "caid"))
883// {
884// for (i=0, ptr1=strtok(value, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ","))
885// {
886// ulong caid, mask;
887// if (ptr2=strchr(trim(ptr1), '&'))
888// *ptr2++='\0';
889// else
890// ptr2="";
891// if (((caid=a2i(ptr1, 2))|(mask=a2i(ptr2,-2))) < 0x10000)
892// {
893// account->caidtab[i][0]=caid;
894// account->caidtab[i++][1]=mask;
895// }
896// else
897// cs_log("WARNING: wrong CAID in %s -> ignored", cs_user);
898// }
899// }
900}
901
902int init_userdb()
903{
904 int tag = 0, nr, nro, expired, disabled;
905 //int first=1;
906 FILE *fp;
907 char *value;
908 struct s_auth *ptr;
909 /*static */struct s_auth *account=(struct s_auth *)0;
910
911 sprintf(token, "%s%s", cs_confdir, cs_user);
912 if (!(fp = fopen(token, "r"))) {
913 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
914 return(1);
915 }
916
917 for (nro = 0, ptr = cfg->account; ptr; nro++) {
918 struct s_auth *ptr_next;
919 ptr_next = ptr->next;
920 free(ptr);
921 ptr = ptr_next;
922 }
923 nr = 0;
924
925 while (fgets(token, sizeof(token), fp)) {
926 int i, l;
927 void *ptr;
928
929 if ((l=strlen(trim(token))) < 3)
930 continue;
931
932 if ((token[0] == '[') && (token[l-1] == ']')) {
933 token[l - 1] = 0;
934 tag = (!strcmp("account", strtolower(token + 1)));
935
936 if (!(ptr=malloc(sizeof(struct s_auth)))) {
937 cs_log("Error allocating memory (errno=%d)", errno);
938 return(1);
939 }
940
941 if (account)
942 account->next = ptr;
943 else
944 cfg->account = ptr;
945
946 account = ptr;
947 memset(account, 0, sizeof(struct s_auth));
948 account->au = (-1);
949 account->monlvl = cfg->mon_level;
950 account->tosleep = cfg->tosleep;
951 account->c35_suppresscmd08 = cfg->c35_suppresscmd08;
952 account->ncd_keepalive = cfg->ncd_keepalive;
953 for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff);
954 for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000);
955 nr++;
956
957#ifdef CS_ANTICASC
958 account->ac_users = cfg->ac_users;
959 account->ac_penalty = cfg->ac_penalty;
960 account->ac_idx = nr;
961#endif
962 continue;
963 }
964
965 if (!tag)
966 continue;
967
968 if (!(value=strchr(token, '=')))
969 continue;
970
971 *value++ = '\0';
972 chk_account(trim(strtolower(token)), trim(value), account);
973 }
974
975 fclose(fp);
976
977 for (expired = 0, disabled = 0, ptr = cfg->account; ptr;) {
978
979 if(ptr->expirationdate && ptr->expirationdate < time(NULL))
980 expired++;
981
982 if(ptr->disabled != 0)
983 disabled++;
984
985 ptr = ptr->next;
986 }
987
988 cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled);
989 return(0);
990}
991
992static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
993{
994 int i, b;
995 char *ptr;
996 ushort *slist=(ushort *) 0;
997 ulong *llist=(ulong *) 0;
998 ulong caid;
999 char buf[strlen(value) + 1];
1000 strncpy(buf, value, sizeof(buf));
1001 b=(what==1) ? sizeof(ulong) : sizeof(ushort);
1002 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1003 {
1004 caid=a2i(ptr, b);
1005 if (!errno) i++;
1006 }
1007 //if (!i) return(0);
1008 if (b==sizeof(ushort))
1009 slist=malloc(i*sizeof(ushort));
1010 else
1011 llist=malloc(i*sizeof(ulong));
1012 strcpy(value, buf);
1013 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1014 {
1015 caid=a2i(ptr, b);
1016 if (errno) continue;
1017 if (b==sizeof(ushort))
1018 slist[i++]=(ushort) caid;
1019 else
1020 llist[i++]=caid;
1021 }
1022 switch (what)
1023 {
1024 case 0: sidtab->caid=slist;
1025 sidtab->num_caid=i;
1026 break;
1027 case 1: sidtab->provid=llist;
1028 sidtab->num_provid=i;
1029 break;
1030 case 2: sidtab->srvid=slist;
1031 sidtab->num_srvid=i;
1032 break;
1033 }
1034}
1035
1036void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
1037{
1038 if (!strcmp(token, "caid")) { chk_entry4sidtab(value, sidtab, 0); return; }
1039 if (!strcmp(token, "provid")) { chk_entry4sidtab(value, sidtab, 1); return; }
1040 if (!strcmp(token, "ident")) { chk_entry4sidtab(value, sidtab, 1); return; }
1041 if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; }
1042 if (token[0] != '#')
1043 fprintf(stderr, "Warning: keyword '%s' in sidtab section not recognized\n",token);
1044}
1045
1046int init_sidtab()
1047{
1048 int nr, nro;
1049 FILE *fp;
1050 char *value;
1051 struct s_sidtab *ptr;
1052 struct s_sidtab *sidtab=(struct s_sidtab *)0;
1053
1054 sprintf(token, "%s%s", cs_confdir, cs_sidt);
1055 if (!(fp=fopen(token, "r")))
1056 {
1057 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
1058 return(1);
1059 }
1060 for (nro=0, ptr=cfg->sidtab; ptr; nro++)
1061 {
1062 struct s_sidtab *ptr_next;
1063 ptr_next=ptr->next;
1064 if (ptr->caid) free(ptr->caid);
1065 if (ptr->provid) free(ptr->provid);
1066 if (ptr->srvid) free(ptr->srvid);
1067 free(ptr);
1068 ptr=ptr_next;
1069 }
1070 nr=0;
1071 while (fgets(token, sizeof(token), fp))
1072 {
1073 int l;
1074 void *ptr;
1075 if ((l=strlen(trim(token)))<3) continue;
1076 if ((token[0]=='[') && (token[l-1]==']'))
1077 {
1078 token[l-1]=0;
1079 if (!(ptr=malloc(sizeof(struct s_sidtab))))
1080 {
1081 cs_log("Error allocating memory (errno=%d)", errno);
1082 return(1);
1083 }
1084 if (sidtab)
1085 sidtab->next=ptr;
1086 else
1087 cfg->sidtab=ptr;
1088 sidtab=ptr;
1089 nr++;
1090 memset(sidtab, 0, sizeof(struct s_sidtab));
1091 strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
1092 continue;
1093 }
1094 if (!sidtab) continue;
1095 if (!(value=strchr(token, '='))) continue;
1096 *value++='\0';
1097 chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
1098 }
1099 fclose(fp);
1100
1101#ifdef DEBUG_SIDTAB
1102 show_sidtab(cfg->sidtab);
1103#endif
1104 cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
1105 return(0);
1106}
1107
1108int init_srvid()
1109{
1110 int nr;
1111 FILE *fp;
1112 char *payload;
1113 static struct s_srvid *srvid=(struct s_srvid *)0;
1114 sprintf(token, "%s%s", cs_confdir, cs_srid);
1115
1116 if (!(fp=fopen(token, "r"))) {
1117 cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
1118 return(0);
1119 }
1120
1121 nr=0;
1122 while (fgets(token, sizeof(token), fp)) {
1123
1124 int l;
1125 void *ptr;
1126 char *tmp;
1127 tmp = trim(token);
1128
1129 if (tmp[0] == '#') continue;
1130 if ((l=strlen(tmp)) < 6) continue;
1131 if (!(payload=strchr(token, '|'))) continue;
1132 *payload++ = '\0';
1133
1134 if (!(ptr = malloc(sizeof(struct s_srvid)))) {
1135 cs_log("Error allocating memory (errno=%d)", errno);
1136 return(1);
1137 }
1138
1139 if (srvid)
1140 srvid->next = ptr;
1141 else
1142 cfg->srvid = ptr;
1143
1144 srvid = ptr;
1145 memset(srvid, 0, sizeof(struct s_srvid));
1146
1147 int i;
1148 char *ptr1;
1149 for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
1150 switch(i){
1151 case 0:
1152 strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov)-1);
1153 break;
1154 case 1:
1155 strncpy(srvid->name, trim(ptr1), sizeof(srvid->name)-1);
1156 break;
1157 case 2:
1158 strncpy(srvid->type, trim(ptr1), sizeof(srvid->type)-1);
1159 break;
1160 case 3:
1161 strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc)-1);
1162 break;
1163 }
1164 }
1165
1166 char *srvidasc = strchr(token, ':');
1167 *srvidasc++ = '\0';
1168 srvid->srvid = word_atob(srvidasc);
1169
1170 srvid->ncaid = 0;
1171 for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
1172 srvid->caid[i] = word_atob(ptr1);
1173 srvid->ncaid = i+1;
1174 }
1175 nr++;
1176 }
1177
1178 fclose(fp);
1179 if (nr>0)
1180 cs_log("%d service-id's loaded", nr);
1181 else{
1182 cs_log("oscam.srvid loading failed, old format");
1183 }
1184 return(0);
1185}
1186
1187static void chk_reader(char *token, char *value, struct s_reader *rdr)
1188{
1189 int i;
1190 char *ptr;
1191 /*
1192 * case sensitive first
1193 */
1194 if (!strcmp(token, "device"))
1195 {
1196 for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
1197 {
1198 trim(ptr);
1199 switch(i)
1200 {
1201 case 0: strncpy(rdr->device, ptr, sizeof(rdr->device)-1); break;
1202 case 1: rdr->r_port=atoi(ptr); break;
1203 case 2: rdr->l_port=atoi(ptr); break;
1204 }
1205 }
1206 return;
1207 }
1208 if (!strcmp(token, "key"))
1209 {
1210 if (key_atob14(value, rdr->ncd_key))
1211 {
1212 fprintf(stderr, "Configuration newcamd: Error in Key\n");
1213 exit(1);
1214 }
1215 return;
1216 }
1217#ifdef CS_WITH_GBOX
1218 if (!strcmp(token, "password")) { strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4); return; }
1219 if (!strcmp(token, "premium")) { rdr->gbox_prem=1; return; }
1220#endif
1221 if (!strcmp(token, "account"))
1222 {
1223 for (i=0, ptr=strtok(value, ","); (i<2)&&(ptr); ptr=strtok(NULL, ","), i++)
1224 {
1225 trim(ptr);
1226 switch(i)
1227 {
1228 case 0: strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr)-1); break;
1229 case 1: strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd)-1); break;
1230 }
1231 }
1232 return;
1233 }
1234 if( !strcmp(token, "pincode")) { strncpy(rdr->pincode, value, sizeof(rdr->pincode)-1); return; }
1235 if (!strcmp(token, "readnano") && value[0]) { asprintf(&(rdr->emmfile), "%s", value); return; }
1236 /*
1237 * case insensitive
1238 */
1239 strtolower(value);
1240
1241 if (!strcmp(token, "enable")) { rdr->enable=atoi(value) ? 1 : 0; return; }
1242 if (!strcmp(token, "services")) { chk_services(value, &rdr->sidtabok, &rdr->sidtabno); return; }
1243 if (!strcmp(token, "inactivitytimeout")) { rdr->tcp_ito = atoi(value); return; }
1244 if (!strcmp(token, "reconnecttimeout")) { rdr->tcp_rto = atoi(value); return; }
1245 if (!strcmp(token, "disableserverfilter")) { rdr->ncd_disable_server_filt = atoi(value); return; }
1246 //FIXME workaround for Smargo until native mode works
1247 if (!strcmp(token, "smargopatch")) { rdr->smargopatch = atoi(value); return; }
1248 if (!strcmp(token, "label")) { strncpy(rdr->label, value, sizeof(rdr->label)-1); return; }
1249 if (!strcmp(token, "fallback")) { rdr->fallback=atoi(value) ? 1 : 0; return; }
1250 if (!strcmp(token, "logport")) { rdr->log_port=atoi(value); return; }
1251 if (!strcmp(token, "caid")) { chk_caidtab(value, &rdr->ctab); return; }
1252 if (!strcmp(token, "boxid")) { rdr->boxid=a2i(value,4); return; }
1253 if (!strcmp(token, "aeskey"))
1254 {
1255 if (key_atob(value, rdr->aes_key))
1256 {
1257 fprintf(stderr, "Configuration reader: Error in AES Key\n");
1258 exit(1);
1259 }
1260 return;
1261 }
1262 if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey")) )
1263 {
1264 rdr->has_rsa=1;
1265 if (key_atob_l(value, rdr->rsa_mod, 128))
1266 {
1267 fprintf(stderr, "Configuration reader: Error in rsakey\n");
1268 exit(1);
1269 }
1270 return;
1271 }
1272 if (!strcmp(token, "tiger_rsakey"))
1273 {
1274 if (key_atob_l(value, rdr->rsa_mod, 240))
1275 {
1276 fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
1277 exit(1);
1278 }
1279 return;
1280 }
1281 if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey")))
1282 {
1283 if (key_atob_l(value, rdr->nagra_boxkey, 16))
1284 {
1285 fprintf(stderr, "Configuration reader: Error in boxkey\n");
1286 exit(1);
1287 }
1288 return;
1289 }
1290 if (!strcmp(token, "detect"))
1291 {
1292 for (i=0; RDR_CD_TXT[i]; i++)
1293 {
1294 if (!strcmp(value, RDR_CD_TXT[i]))
1295 rdr->detect=i;
1296 else
1297 if ((value[0]=='!') && (!strcmp(value+1, RDR_CD_TXT[i])))
1298 rdr->detect=i|0x80;
1299 }
1300 return;
1301 }
1302 if (!strcmp(token, "mhz")) { rdr->mhz=atoi(value); return; }
1303 if (!strcmp(token, "cardmhz")) { rdr->cardmhz=atoi(value); return; }
1304 if (!strcmp(token, "protocol"))
1305 {
1306 if (!strcmp(value, "mouse")) { rdr->typ=R_MOUSE; return; }
1307 if (!strcmp(value, "smartreader")) { rdr->typ=R_SMART; return; }
1308 if (!strcmp(value, "internal")) { rdr->typ=R_INTERNAL; return; }
1309#ifdef HAVE_PCSC
1310 if (!strcmp(value, "pcsc")) { rdr->typ=R_PCSC; return; }
1311#endif
1312 if (!strcmp(value, "serial")) { rdr->typ=R_SERIAL; return; }
1313 if (!strcmp(value, "camd35")) { rdr->typ=R_CAMD35; return; }
1314 if (!strcmp(value, "cs378x")) { rdr->typ=R_CS378X; return; }
1315 if (!strcmp(value, "cs357x")) { rdr->typ=R_CAMD35; return; }
1316 if (!strcmp(value, "gbox")) { rdr->typ=R_GBOX; return; }
1317 if (!strcmp(value, "cccam")) {
1318 rdr->typ=R_CCCAM;
1319 // strcpy(value, "1");
1320 // chk_caidtab(value, &rdr->ctab); // this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
1321 return;
1322 }
1323 if (!strcmp(value, "radegast")) { rdr->typ=R_RADEGAST; return; }
1324 if (!strcmp(value, "newcamd") ||
1325 !strcmp(value, "newcamd525")) {rdr->typ=R_NEWCAMD;
1326 rdr->ncd_proto=NCD_525; return; }
1327 if (!strcmp(value, "newcamd524")) {rdr->typ=R_NEWCAMD;
1328 rdr->ncd_proto=NCD_524; return; }
1329 fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
1330 rdr->typ=R_MOUSE;
1331 return;
1332 }
1333 if (!strcmp(token, "loadbalanced")) { rdr->loadbalanced=atoi(value); return; }
1334 if (!strcmp(token, "ident")) { chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid"); return; }
1335 if (!strcmp(token, "class")) { chk_cltab(value, &rdr->cltab); return; }
1336 if (!strcmp(token, "chid")) { chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid"); return; }
1337 if (!strcmp(token, "showcls")) { rdr->show_cls = atoi(value); return; }
1338 if (!strcmp(token, "maxqlen"))
1339 {
1340 rdr->maxqlen = atoi(value);
1341 if( rdr->maxqlen<0 || rdr->maxqlen>CS_MAXQLEN )
1342 rdr->maxqlen=CS_MAXQLEN;
1343 return;
1344 }
1345 if (!strcmp(token, "group"))
1346 {
1347 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1348 {
1349 int g;
1350 g=atoi(ptr);
1351 if ((g>0) && (g<33)) rdr->grp|=(1<<(g-1));
1352 }
1353 return;
1354 }
1355 if (!strcmp(token, "emmcache"))
1356 {
1357 for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
1358 switch(i)
1359 {
1360 case 0: rdr->cachemm=atoi(ptr); break;
1361 case 1: rdr->rewritemm=atoi(ptr); break;
1362 case 2: rdr->logemm=atoi(ptr); break;
1363 }
1364 if (rdr->rewritemm <=0) {
1365 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);
1366 rdr->rewritemm = 1;
1367 }
1368 return;
1369 }
1370
1371 if (!strcmp(token, "blocknano"))
1372 {
1373 if (!strcmp(value,"all")) //wildcard is used
1374 for (i=0 ; i<256; i++)
1375 rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
1376 else
1377 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1378 if ((i=byte_atob(ptr))>=0)
1379 rdr->b_nano[i]|= 0x01; //lsb is set when to block nano
1380 return;
1381 }
1382 if (!strcmp(token, "savenano"))
1383 {
1384 if (!strcmp(value,"all")) //wildcard is used
1385 for (i=0 ; i<256; i++)
1386 rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
1387 else
1388 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1389 if ((i=byte_atob(ptr))>=0)
1390 rdr->b_nano[i]|= 0x02; //lsb+1 is set when to save nano to file
1391 return;
1392 }
1393 if (!strcmp(token, "cccversion")) { // cccam version
1394 if (strlen(value)>sizeof(rdr->cc_version)-1) {
1395 fprintf(stderr, "cccam config: version too long\n");
1396 exit(1);
1397 }
1398 bzero(rdr->cc_version, sizeof(rdr->cc_version));
1399 strncpy(rdr->cc_version, value, sizeof(rdr->cc_version)-1);
1400 return;
1401 }
1402 if (!strcmp(token, "cccbuild")) { // cccam build number
1403 if (strlen(value)>sizeof(rdr->cc_build)-1) {
1404 fprintf(stderr, "cccam config build number too long\n");
1405 exit(1);
1406 }
1407 bzero(rdr->cc_build, sizeof(rdr->cc_build));
1408 strncpy(rdr->cc_build, value, sizeof(rdr->cc_build)-1);
1409 return;
1410 }
1411 if (!strcmp(token, "cccmaxhop")) { // cccam max card distance
1412 rdr->cc_maxhop = atoi(value);
1413 return;
1414 }
1415 if (!strcmp(token, "deprecated")) { rdr->deprecated=atoi(value); return; }
1416 if (token[0] != '#')
1417 fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);
1418}
1419
1420int init_readerdb()
1421{
1422 int tag=0, nr;
1423 FILE *fp;
1424 char *value;
1425
1426 sprintf(token, "%s%s", cs_confdir, cs_srvr);
1427 if (!(fp=fopen(token, "r")))
1428 {
1429 cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
1430 return(1);
1431 }
1432 nr=0;
1433 while (fgets(token, sizeof(token), fp))
1434 {
1435 int i, l;
1436 if ((l=strlen(trim(token)))<3) continue;
1437 if ((token[0]=='[') && (token[l-1]==']'))
1438 {
1439 token[l-1]=0;
1440 tag=(!strcmp("reader", strtolower(token+1)));
1441 if (reader[nr].label[0] && reader[nr].typ) nr++;
1442 memset(&reader[nr], 0, sizeof(struct s_reader));
1443 reader[nr].enable = 1;
1444 reader[nr].tcp_rto = 30;
1445 reader[nr].show_cls = 10;
1446 reader[nr].maxqlen = CS_MAXQLEN;
1447 reader[nr].mhz = 357;
1448 reader[nr].cardmhz = 357;
1449 reader[nr].deprecated = 0;
1450 strcpy(reader[nr].pincode, "none");
1451 for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
1452 continue;
1453 }
1454 if (!tag) continue;
1455 if (!(value=strchr(token, '='))) continue;
1456 *value++='\0';
1457 chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
1458 }
1459 fclose(fp);
1460 return(0);
1461}
1462
1463/*
1464int init_irdeto_guess_tab()
1465{
1466 int i, j, skip;
1467 int b47;
1468 FILE *fp;
1469 char token[128], *value, *ptr;
1470 char zSid[5];
1471 uchar b3;
1472 ushort caid, sid;
1473 struct s_irdeto_quess *ird_row, *head;
1474
1475 memset(cfg->itab, 0, sizeof(cfg->itab));
1476 sprintf(token, "%s%s", cs_confdir, cs_ird);
1477 if (!(fp=fopen(token, "r")))
1478 {
1479 cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
1480 token, errno);
1481 return(1);
1482 }
1483 while (fgets(token, sizeof(token), fp))
1484 {
1485 if( strlen(token)<20 ) continue;
1486 for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
1487 {
1488 trim(ptr);
1489 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
1490 skip=1;
1491 break;
1492 }
1493 switch(i)
1494 {
1495 case 0: b3 = a2i(ptr, 2); break;
1496 case 1: b47 = a2i(ptr, 8); break;
1497 case 2: caid = a2i(ptr, 4); break;
1498 case 3:
1499 for( j=0; j<4; j++ )
1500 zSid[j]=ptr[j];
1501 zSid[4]=0;
1502 sid = a2i(zSid, 4);
1503 break;
1504 }
1505 }
1506 if( !skip )
1507 {
1508 if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
1509 {
1510 cs_log("Error allocating memory (errno=%d)", errno);
1511 return;
1512 }
1513 ird_row->b47 = b47;
1514 ird_row->caid = caid;
1515 ird_row->sid = sid;
1516 ird_row->next = 0;
1517
1518 head = cfg->itab[b3];
1519 if( head ) {
1520 while( head->next )
1521 head=head->next;
1522 head->next=ird_row;
1523 }
1524 else
1525 cfg->itab[b3]=ird_row;
1526
1527 //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
1528 }
1529 }
1530 fclose(fp);
1531
1532 for( i=0; i<0xff; i++ )
1533 {
1534 head=cfg->itab[i];
1535 while(head)
1536 {
1537 cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
1538 i, head->b47, head->caid, head->sid);
1539 head=head->next;
1540 }
1541 }
1542 return(0);
1543}
1544*/
1545
1546#ifdef CS_ANTICASC
1547void init_ac()
1548{
1549 int nr;
1550 FILE *fp;
1551 //char *value;
1552
1553 sprintf(token, "%s%s", cs_confdir, cs_ac);
1554 if (!(fp=fopen(token, "r")))
1555 {
1556 cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
1557 token, errno);
1558 return;
1559 }
1560
1561 for(nr=0; fgets(token, sizeof(token), fp);)
1562 {
1563 int i, skip;
1564 ushort caid, sid, chid, dwtime;
1565 ulong provid;
1566 char *ptr, *ptr1;
1567 struct s_cpmap *ptr_cpmap;
1568 static struct s_cpmap *cpmap=(struct s_cpmap *)0;
1569
1570 if( strlen(token)<4 ) continue;
1571
1572 caid=sid=chid=dwtime=0;
1573 provid=0;
1574 skip=0;
1575 ptr1=0;
1576 for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
1577 {
1578 trim(ptr);
1579 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
1580 skip=1;
1581 break;
1582 }
1583 switch( i )
1584 {
1585 case 0:
1586 ptr1=ptr;
1587 break;
1588 case 1:
1589 dwtime = atoi(ptr);
1590 break;
1591 }
1592 }
1593
1594 if( !skip )
1595 {
1596 for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
1597 {
1598 trim(ptr);
1599 switch( i )
1600 {
1601 case 0:
1602 if( *ptr=='*' ) caid = 0;
1603 else caid = a2i(ptr, 4);
1604 break;
1605 case 1:
1606 if( *ptr=='*' ) provid = 0;
1607 else provid = a2i(ptr, 6);
1608 break;
1609 case 2:
1610 if( *ptr=='*' ) sid = 0;
1611 else sid = a2i(ptr, 4);
1612 break;
1613 case 3:
1614 if( *ptr=='*' ) chid = 0;
1615 else chid = a2i(ptr, 4);
1616 break;
1617 }
1618 }
1619 if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
1620 {
1621 cs_log("Error allocating memory (errno=%d)", errno);
1622 return;
1623 }
1624 if( cpmap )
1625 cpmap->next=ptr_cpmap;
1626 else
1627 cfg->cpmap=ptr_cpmap;
1628 cpmap=ptr_cpmap;
1629
1630 cpmap->caid = caid;
1631 cpmap->provid = provid;
1632 cpmap->sid = sid;
1633 cpmap->chid = chid;
1634 cpmap->dwtime = dwtime;
1635 cpmap->next = 0;
1636
1637 cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
1638 nr, caid, provid, sid, chid, dwtime);
1639 nr++;
1640 }
1641 }
1642 fclose(fp);
1643 //cs_log("%d lengths for caid guessing loaded", nr);
1644 return;
1645}
1646#endif
Note: See TracBrowser for help on using the repository browser.