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

Last change on this file since 1254 was 1254, checked in by rorothetroll, 11 years ago

resync with trunk

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