source: branches/smartreader/oscam-config.c@ 1049

Last change on this file since 1049 was 1049, checked in by rorothetroll, 13 years ago

resync with trunk

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