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

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

resync with trunk

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