source: trunk/oscam-config.c@ 1196

Last change on this file since 1196 was 1196, checked in by nightmann, 12 years ago
  1. simplifiy tiger sessionkey negotiation. Patch by hexalot
  2. make rsa key config more global. Probably we can use this var again in other situations like irdeto camkey data.
File size: 43.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#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 *value;
1022 static struct s_srvid *srvid=(struct s_srvid *)0;
1023
1024 sprintf(token, "%s%s", cs_confdir, cs_srid);
1025 if (!(fp=fopen(token, "r")))
1026 {
1027 cs_log("can't open file \"%s\" (err=%d), no service-id's loaded",
1028 token, errno);
1029 return(0);
1030 }
1031 nr=0;
1032 while (fgets(token, sizeof(token), fp))
1033 {
1034 int l;
1035 void *ptr;
1036 if ((l=strlen(trim(token)))<6) continue;
1037 if (!(value=strchr(token, ':'))) continue;
1038 *value++='\0';
1039 if (strlen(token)!=4) continue;
1040 if (!(ptr=malloc(sizeof(struct s_srvid))))
1041 {
1042 cs_log("Error allocating memory (errno=%d)", errno);
1043 return(1);
1044 }
1045 if (srvid)
1046 srvid->next=ptr;
1047 else
1048 cfg->srvid=ptr;
1049 srvid=ptr;
1050 memset(srvid, 0, sizeof(struct s_srvid));
1051 srvid->srvid=word_atob(token);
1052 strncpy(srvid->name, value, sizeof(srvid->name)-1);
1053 nr++;
1054 }
1055 fclose(fp);
1056 cs_log("%d service-id's loaded", nr);
1057 return(0);
1058}
1059
1060static void chk_reader(char *token, char *value, struct s_reader *rdr)
1061{
1062 int i;
1063 char *ptr;
1064 /*
1065 * case sensitive first
1066 */
1067 if (!strcmp(token, "device"))
1068 {
1069 for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
1070 {
1071 trim(ptr);
1072 switch(i)
1073 {
1074 case 0: strncpy(rdr->device, ptr, sizeof(rdr->device)-1); break;
1075 case 1: rdr->r_port=atoi(ptr); break;
1076 case 2: rdr->l_port=atoi(ptr); break;
1077 }
1078 }
1079 return;
1080 }
1081 if (!strcmp(token, "key"))
1082 {
1083 if (key_atob14(value, rdr->ncd_key))
1084 {
1085 fprintf(stderr, "Configuration newcamd: Error in Key\n");
1086 exit(1);
1087 }
1088 return;
1089 }
1090#ifdef CS_WITH_GBOX
1091 if (!strcmp(token, "password")) { strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4); return; }
1092 if (!strcmp(token, "premium")) { rdr->gbox_prem=1; return; }
1093#endif
1094 if (!strcmp(token, "account"))
1095 {
1096 for (i=0, ptr=strtok(value, ","); (i<2)&&(ptr); ptr=strtok(NULL, ","), i++)
1097 {
1098 trim(ptr);
1099 switch(i)
1100 {
1101 case 0: strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr)-1); break;
1102 case 1: strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd)-1); break;
1103 }
1104 }
1105 return;
1106 }
1107 if( !strcmp(token, "pincode")) { strncpy(rdr->pincode, value, sizeof(rdr->pincode)-1); return; }
1108 if (!strcmp(token, "readnano")) { strncpy((char *)rdr->emmfile, value, sizeof(rdr->emmfile)-1); return; }
1109 /*
1110 * case insensitive
1111 */
1112 strtolower(value);
1113
1114 if (!strcmp(token, "services")) { chk_services(value, &rdr->sidtabok, &rdr->sidtabno); return; }
1115 if (!strcmp(token, "inactivitytimeout")) { rdr->tcp_ito = atoi(value); return; }
1116 if (!strcmp(token, "reconnecttimeout")) { rdr->tcp_rto = atoi(value); return; }
1117 if (!strcmp(token, "disableserverfilter")) { rdr->ncd_disable_server_filt = atoi(value); return; }
1118
1119 if (!strcmp(token, "label")) { strncpy(rdr->label, value, sizeof(rdr->label)-1); return; }
1120 if (!strcmp(token, "fallback")) { rdr->fallback=atoi(value) ? 1 : 0; return; }
1121 if (!strcmp(token, "logport")) { rdr->log_port=atoi(value); return; }
1122 if (!strcmp(token, "caid")) { chk_caidtab(value, &rdr->ctab); return; }
1123 if (!strcmp(token, "boxid")) { rdr->boxid=a2i(value,4); return; }
1124 if (!strcmp(token, "aeskey"))
1125 {
1126 if (key_atob(value, rdr->aes_key))
1127 {
1128 fprintf(stderr, "Configuration reader: Error in AES Key\n");
1129 exit(1);
1130 }
1131 return;
1132 }
1133 if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey")) )
1134 {
1135 rdr->has_rsa=1;
1136 if (key_atob_l(value, rdr->rsa_mod, 128))
1137 {
1138 fprintf(stderr, "Configuration reader: Error in n3_rsakey\n");
1139 exit(1);
1140 }
1141 return;
1142 }
1143 if (!strcmp(token, "tiger_rsakey"))
1144 {
1145 if (key_atob_l(value, rdr->rsa_mod, 240))
1146 {
1147 fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
1148 exit(1);
1149 }
1150 return;
1151 }
1152 if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey")))
1153 {
1154 if (key_atob_l(value, rdr->nagra_boxkey, 16))
1155 {
1156 fprintf(stderr, "Configuration reader: Error in Nagra Boxkey\n");
1157 exit(1);
1158 }
1159 return;
1160 }
1161 if (!strcmp(token, "tiger_ideakey"))
1162 {
1163 if (key_atob_l(value, rdr->nagra_boxkey, 32))
1164 {
1165 fprintf(stderr, "Configuration reader: Error in Nagra Boxkey\n");
1166 exit(1);
1167 }
1168 return;
1169 }
1170 if (!strcmp(token, "detect"))
1171 {
1172 for (i=0; RDR_CD_TXT[i]; i++)
1173 {
1174 if (!strcmp(value, RDR_CD_TXT[i]))
1175 rdr->detect=i;
1176 else
1177 if ((value[0]=='!') && (!strcmp(value+1, RDR_CD_TXT[i])))
1178 rdr->detect=i|0x80;
1179 }
1180 return;
1181 }
1182 if (!strcmp(token, "mhz")) { rdr->mhz=atoi(value); return; }
1183 if (!strcmp(token, "cardmhz")) { rdr->cardmhz=atoi(value); return; }
1184 if (!strcmp(token, "protocol"))
1185 {
1186 if (!strcmp(value, "mouse")) { rdr->typ=R_MOUSE; return; }
1187 if (!strcmp(value, "smartreader")) { rdr->typ=R_SMART; return; }
1188 if (!strcmp(value, "internal")) { rdr->typ=R_INTERNAL; return; }
1189#ifdef HAVE_PCSC
1190 if (!strcmp(value, "pcsc")) { rdr->typ=R_PCSC; return; }
1191#endif
1192 if (!strcmp(value, "serial")) { rdr->typ=R_SERIAL; return; }
1193 if (!strcmp(value, "camd35")) { rdr->typ=R_CAMD35; return; }
1194 if (!strcmp(value, "cs378x")) { rdr->typ=R_CS378X; return; }
1195 if (!strcmp(value, "cs357x")) { rdr->typ=R_CAMD35; return; }
1196 if (!strcmp(value, "gbox")) { rdr->typ=R_GBOX; return; }
1197 if (!strcmp(value, "cccam")) {
1198 rdr->typ=R_CCCAM;
1199 // strcpy(value, "1");
1200 // chk_caidtab(value, &rdr->ctab); // this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
1201 return;
1202 }
1203 if (!strcmp(value, "radegast")) { rdr->typ=R_RADEGAST; return; }
1204 if (!strcmp(value, "newcamd") ||
1205 !strcmp(value, "newcamd525")) {rdr->typ=R_NEWCAMD;
1206 rdr->ncd_proto=NCD_525; return; }
1207 if (!strcmp(value, "newcamd524")) {rdr->typ=R_NEWCAMD;
1208 rdr->ncd_proto=NCD_524; return; }
1209 fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
1210 rdr->typ=R_MOUSE;
1211 return;
1212 }
1213 if (!strcmp(token, "ident")) { chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid"); return; }
1214 if (!strcmp(token, "class")) { chk_cltab(value, &rdr->cltab); return; }
1215 if (!strcmp(token, "chid")) { chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid"); return; }
1216 if (!strcmp(token, "showcls")) { rdr->show_cls = atoi(value); return; }
1217 if (!strcmp(token, "maxqlen"))
1218 {
1219 rdr->maxqlen = atoi(value);
1220 if( rdr->maxqlen<0 || rdr->maxqlen>CS_MAXQLEN )
1221 rdr->maxqlen=CS_MAXQLEN;
1222 return;
1223 }
1224 if (!strcmp(token, "group"))
1225 {
1226 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1227 {
1228 int g;
1229 g=atoi(ptr);
1230 if ((g>0) && (g<33)) rdr->grp|=(1<<(g-1));
1231 }
1232 return;
1233 }
1234 if (!strcmp(token, "emmcache"))
1235 {
1236 for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
1237 switch(i)
1238 {
1239 case 0: rdr->cachemm=atoi(ptr); break;
1240 case 1: rdr->rewritemm=atoi(ptr); break;
1241 case 2: rdr->logemm=atoi(ptr); break;
1242 }
1243 if (rdr->rewritemm <=0) {
1244 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);
1245 rdr->rewritemm = 1;
1246 }
1247 return;
1248 }
1249
1250 if (!strcmp(token, "blocknano"))
1251 {
1252 if (!strcmp(value,"all")) //wildcard is used
1253 for (i=0 ; i<256; i++)
1254 rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
1255 else
1256 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1257 if ((i=byte_atob(ptr))>=0)
1258 rdr->b_nano[i]|= 0x01; //lsb is set when to block nano
1259 return;
1260 }
1261 if (!strcmp(token, "savenano"))
1262 {
1263 if (!strcmp(value,"all")) //wildcard is used
1264 for (i=0 ; i<256; i++)
1265 rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
1266 else
1267 for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1268 if ((i=byte_atob(ptr))>=0)
1269 rdr->b_nano[i]|= 0x02; //lsb+1 is set when to save nano to file
1270 return;
1271 }
1272 if (!strcmp(token, "cccversion")) { // cccam version
1273 if (strlen(value)>sizeof(rdr->cc_version)-1) {
1274 fprintf(stderr, "cccam config: version too long\n");
1275 exit(1);
1276 }
1277 bzero(rdr->cc_version, sizeof(rdr->cc_version));
1278 strncpy(rdr->cc_version, value, sizeof(rdr->cc_version)-1);
1279 return;
1280 }
1281 if (!strcmp(token, "cccbuild")) { // cccam build number
1282 if (strlen(value)>sizeof(rdr->cc_build)-1) {
1283 fprintf(stderr, "cccam config build number too long\n");
1284 exit(1);
1285 }
1286 bzero(rdr->cc_build, sizeof(rdr->cc_build));
1287 strncpy(rdr->cc_build, value, sizeof(rdr->cc_build)-1);
1288 return;
1289 }
1290 if (!strcmp(token, "cccmaxhop")) { // cccam max card distance
1291 rdr->cc_maxhop = atoi(value);
1292 return;
1293 }
1294 if (token[0] != '#')
1295 fprintf(stderr, "Warning: keyword '%s' in reader section not recognized\n",token);
1296}
1297
1298int init_readerdb()
1299{
1300 int tag=0, nr;
1301 FILE *fp;
1302 char *value;
1303
1304 sprintf(token, "%s%s", cs_confdir, cs_srvr);
1305 if (!(fp=fopen(token, "r")))
1306 {
1307 cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
1308 return(1);
1309 }
1310 nr=0;
1311 while (fgets(token, sizeof(token), fp))
1312 {
1313 int i, l;
1314 if ((l=strlen(trim(token)))<3) continue;
1315 if ((token[0]=='[') && (token[l-1]==']'))
1316 {
1317 token[l-1]=0;
1318 tag=(!strcmp("reader", strtolower(token+1)));
1319 if (reader[nr].label[0] && reader[nr].typ) nr++;
1320 memset(&reader[nr], 0, sizeof(struct s_reader));
1321 reader[nr].tcp_rto = 30;
1322 reader[nr].show_cls = 10;
1323 reader[nr].maxqlen = CS_MAXQLEN;
1324 reader[nr].mhz = 357;
1325 reader[nr].cardmhz = 357;
1326 strcpy(reader[nr].pincode, "none");
1327 for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
1328 continue;
1329 }
1330 if (!tag) continue;
1331 if (!(value=strchr(token, '='))) continue;
1332 *value++='\0';
1333 chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
1334 }
1335 fclose(fp);
1336 return(0);
1337}
1338
1339/*
1340int init_irdeto_guess_tab()
1341{
1342 int i, j, skip;
1343 int b47;
1344 FILE *fp;
1345 char token[128], *value, *ptr;
1346 char zSid[5];
1347 uchar b3;
1348 ushort caid, sid;
1349 struct s_irdeto_quess *ird_row, *head;
1350
1351 memset(cfg->itab, 0, sizeof(cfg->itab));
1352 sprintf(token, "%s%s", cs_confdir, cs_ird);
1353 if (!(fp=fopen(token, "r")))
1354 {
1355 cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
1356 token, errno);
1357 return(1);
1358 }
1359 while (fgets(token, sizeof(token), fp))
1360 {
1361 if( strlen(token)<20 ) continue;
1362 for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
1363 {
1364 trim(ptr);
1365 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
1366 skip=1;
1367 break;
1368 }
1369 switch(i)
1370 {
1371 case 0: b3 = a2i(ptr, 2); break;
1372 case 1: b47 = a2i(ptr, 8); break;
1373 case 2: caid = a2i(ptr, 4); break;
1374 case 3:
1375 for( j=0; j<4; j++ )
1376 zSid[j]=ptr[j];
1377 zSid[4]=0;
1378 sid = a2i(zSid, 4);
1379 break;
1380 }
1381 }
1382 if( !skip )
1383 {
1384 if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
1385 {
1386 cs_log("Error allocating memory (errno=%d)", errno);
1387 return;
1388 }
1389 ird_row->b47 = b47;
1390 ird_row->caid = caid;
1391 ird_row->sid = sid;
1392 ird_row->next = 0;
1393
1394 head = cfg->itab[b3];
1395 if( head ) {
1396 while( head->next )
1397 head=head->next;
1398 head->next=ird_row;
1399 }
1400 else
1401 cfg->itab[b3]=ird_row;
1402
1403 //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
1404 }
1405 }
1406 fclose(fp);
1407
1408 for( i=0; i<0xff; i++ )
1409 {
1410 head=cfg->itab[i];
1411 while(head)
1412 {
1413 cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
1414 i, head->b47, head->caid, head->sid);
1415 head=head->next;
1416 }
1417 }
1418 return(0);
1419}
1420*/
1421
1422#ifdef CS_ANTICASC
1423void init_ac()
1424{
1425 int nr;
1426 FILE *fp;
1427 //char *value;
1428
1429 sprintf(token, "%s%s", cs_confdir, cs_ac);
1430 if (!(fp=fopen(token, "r")))
1431 {
1432 cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
1433 token, errno);
1434 return;
1435 }
1436
1437 for(nr=0; fgets(token, sizeof(token), fp);)
1438 {
1439 int i, skip;
1440 ushort caid, sid, chid, dwtime;
1441 ulong provid;
1442 char *ptr, *ptr1;
1443 struct s_cpmap *ptr_cpmap;
1444 static struct s_cpmap *cpmap=(struct s_cpmap *)0;
1445
1446 if( strlen(token)<4 ) continue;
1447
1448 caid=sid=chid=dwtime=0;
1449 provid=0;
1450 skip=0;
1451 ptr1=0;
1452 for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
1453 {
1454 trim(ptr);
1455 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
1456 skip=1;
1457 break;
1458 }
1459 switch( i )
1460 {
1461 case 0:
1462 ptr1=ptr;
1463 break;
1464 case 1:
1465 dwtime = atoi(ptr);
1466 break;
1467 }
1468 }
1469
1470 if( !skip )
1471 {
1472 for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
1473 {
1474 trim(ptr);
1475 switch( i )
1476 {
1477 case 0:
1478 if( *ptr=='*' ) caid = 0;
1479 else caid = a2i(ptr, 4);
1480 break;
1481 case 1:
1482 if( *ptr=='*' ) provid = 0;
1483 else provid = a2i(ptr, 6);
1484 break;
1485 case 2:
1486 if( *ptr=='*' ) sid = 0;
1487 else sid = a2i(ptr, 4);
1488 break;
1489 case 3:
1490 if( *ptr=='*' ) chid = 0;
1491 else chid = a2i(ptr, 4);
1492 break;
1493 }
1494 }
1495 if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
1496 {
1497 cs_log("Error allocating memory (errno=%d)", errno);
1498 return;
1499 }
1500 if( cpmap )
1501 cpmap->next=ptr_cpmap;
1502 else
1503 cfg->cpmap=ptr_cpmap;
1504 cpmap=ptr_cpmap;
1505
1506 cpmap->caid = caid;
1507 cpmap->provid = provid;
1508 cpmap->sid = sid;
1509 cpmap->chid = chid;
1510 cpmap->dwtime = dwtime;
1511 cpmap->next = 0;
1512
1513 cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
1514 nr, caid, provid, sid, chid, dwtime);
1515 nr++;
1516 }
1517 }
1518 fclose(fp);
1519 //cs_log("%d lengths for caid guessing loaded", nr);
1520 return;
1521}
1522#endif
Note: See TracBrowser for help on using the repository browser.