1 | #include "globals.h"
|
---|
2 | #ifdef CS_WITH_BOXKEYS
|
---|
3 | # include "mpcs-boxkeys.np"
|
---|
4 | #endif
|
---|
5 |
|
---|
6 | static char *cs_conf="mpcs.conf";
|
---|
7 | static char *cs_user="mpcs.user";
|
---|
8 | static char *cs_srvr="mpcs.server";
|
---|
9 | static char *cs_srid="mpcs.srvid";
|
---|
10 | static char *cs_l4ca="mpcs.guess";
|
---|
11 | static char *cs_cert="mpcs.cert";
|
---|
12 | static char *cs_sidt="mpcs.services";
|
---|
13 | //static char *cs_ird="mpcs.ird";
|
---|
14 | #ifdef CS_ANTICASC
|
---|
15 | static char *cs_ac="mpcs.ac";
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | static char token[4096];
|
---|
19 |
|
---|
20 | typedef enum cs_proto_type
|
---|
21 | {
|
---|
22 | TAG_GLOBAL, // must be first !
|
---|
23 | TAG_MONITOR, // monitor
|
---|
24 | TAG_CAMD33, // camd 3.3x
|
---|
25 | TAG_CAMD35, // camd 3.5x UDP
|
---|
26 | TAG_NEWCAMD, // newcamd
|
---|
27 | TAG_RADEGAST, // radegast
|
---|
28 | TAG_SERIAL, // serial (static)
|
---|
29 | TAG_CS357X, // camd 3.5x UDP
|
---|
30 | TAG_CS378X, // camd 3.5x TCP
|
---|
31 | TAG_GBOX // gbox
|
---|
32 | #ifdef CS_ANTICASC
|
---|
33 | ,TAG_ANTICASC // anti-cascading
|
---|
34 | #endif
|
---|
35 | } cs_proto_type_t;
|
---|
36 |
|
---|
37 | static char *cctag[]={"global", "monitor", "camd33", "camd35",
|
---|
38 | "newcamd", "radegast", "serial", "cs357x", "cs378x", "gbox",
|
---|
39 | #ifdef CS_ANTICASC
|
---|
40 | "anticasc",
|
---|
41 | #endif
|
---|
42 | NULL};
|
---|
43 |
|
---|
44 | #ifdef DEBUG_SIDTAB
|
---|
45 | static void show_sidtab(struct s_sidtab *sidtab)
|
---|
46 | {
|
---|
47 | for (; sidtab; sidtab=sidtab->next)
|
---|
48 | {
|
---|
49 | int i;
|
---|
50 | char buf[1024];
|
---|
51 | cs_log("label=%s", sidtab->label);
|
---|
52 | sprintf(buf, "caid(%d)=", sidtab->num_caid);
|
---|
53 | for (i=0; i<sidtab->num_caid; i++)
|
---|
54 | sprintf(buf+strlen(buf), "%04X ", sidtab->caid[i]);
|
---|
55 | cs_log("%s", buf);
|
---|
56 | sprintf(buf, "provider(%d)=", sidtab->num_provid);
|
---|
57 | for (i=0; i<sidtab->num_provid; i++)
|
---|
58 | sprintf(buf+strlen(buf), "%08X ", sidtab->provid[i]);
|
---|
59 | cs_log("%s", buf);
|
---|
60 | sprintf(buf, "services(%d)=", sidtab->num_srvid);
|
---|
61 | for (i=0; i<sidtab->num_srvid; i++)
|
---|
62 | sprintf(buf+strlen(buf), "%04X ", sidtab->srvid[i]);
|
---|
63 | cs_log("%s", buf);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | #endif
|
---|
67 |
|
---|
68 | static void chk_iprange(char *value, struct s_ip **base)
|
---|
69 | {
|
---|
70 | //int i;
|
---|
71 | char *ptr1, *ptr2;
|
---|
72 | struct s_ip *lip, *cip;
|
---|
73 |
|
---|
74 | for (cip=lip=*base; cip; cip=cip->next)
|
---|
75 | lip=cip;
|
---|
76 | if (!(cip=malloc(sizeof(struct s_ip))))
|
---|
77 | {
|
---|
78 | fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
|
---|
79 | exit(1);
|
---|
80 | }
|
---|
81 | if (*base)
|
---|
82 | lip->next=cip;
|
---|
83 | else
|
---|
84 | *base=cip;
|
---|
85 |
|
---|
86 | memset(cip, 0, sizeof(struct s_ip));
|
---|
87 | for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ","))
|
---|
88 | {
|
---|
89 | if( (ptr2=strchr(trim(ptr1), '-')) )
|
---|
90 | {
|
---|
91 | *ptr2++='\0';
|
---|
92 | cip->ip[0]=cs_inet_addr(trim(ptr1));
|
---|
93 | cip->ip[1]=cs_inet_addr(trim(ptr2));
|
---|
94 | }
|
---|
95 | else
|
---|
96 | cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | static void chk_caidtab(char *caidasc, CAIDTAB *ctab)
|
---|
101 | {
|
---|
102 | int i;
|
---|
103 | char *ptr1, *ptr2, *ptr3;
|
---|
104 | for (i=0, ptr1=strtok(caidasc, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ","))
|
---|
105 | {
|
---|
106 | ulong caid, mask, cmap;
|
---|
107 | if( (ptr3=strchr(trim(ptr1), ':')) )
|
---|
108 | *ptr3++='\0';
|
---|
109 | else
|
---|
110 | ptr3="";
|
---|
111 | if( (ptr2=strchr(trim(ptr1), '&')) )
|
---|
112 | *ptr2++='\0';
|
---|
113 | else
|
---|
114 | ptr2="";
|
---|
115 | if (((caid=a2i(ptr1, 2))|(mask=a2i(ptr2,-2))|(cmap=a2i(ptr3, 2))) < 0x10000)
|
---|
116 | {
|
---|
117 | ctab->caid[i]=caid;
|
---|
118 | ctab->mask[i]=mask;
|
---|
119 | ctab->cmap[i++]=cmap;
|
---|
120 | }
|
---|
121 | // else
|
---|
122 | // cs_log("WARNING: wrong CAID in %s -> ignored", cs_user);
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | static void chk_services(char *labels, ulong *sidok, ulong *sidno)
|
---|
127 | {
|
---|
128 | int i;
|
---|
129 | char *ptr;
|
---|
130 | SIDTAB *sidtab;
|
---|
131 | *sidok=*sidno=0;
|
---|
132 | for (ptr=strtok(labels, ","); ptr; ptr=strtok(NULL, ","))
|
---|
133 | for (trim(ptr), i=0, sidtab=cfg->sidtab; sidtab; sidtab=sidtab->next, i++)
|
---|
134 | {
|
---|
135 | if (!strcmp(sidtab->label, ptr)) *sidok|=(1<<i);
|
---|
136 | if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) *sidno|=(1<<i);
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | static
|
---|
141 | void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName,
|
---|
142 | const char *zFiltName)
|
---|
143 | {
|
---|
144 | int i,j;
|
---|
145 | char *ptr1,*ptr2,*ptr3;
|
---|
146 | char *ptr[CS_MAXFILTERS] = {0};
|
---|
147 |
|
---|
148 | memset(ftab, 0, sizeof(FTAB));
|
---|
149 | for( i=0, ptr1=strtok(zFilterAsc, ";"); (i<CS_MAXFILTERS) && (ptr1); ptr1=strtok(NULL, ";"), i++ )
|
---|
150 | {
|
---|
151 | //cs_log("ptr1=%s", ptr1);
|
---|
152 | ptr[i] = ptr1;
|
---|
153 | if( (ptr2=strchr(trim(ptr1), ':')) )
|
---|
154 | {
|
---|
155 | //cs_log("ptr2=%s", ptr2);
|
---|
156 | *ptr2++='\0';
|
---|
157 | //cs_log("ptr2=%s", ptr2);
|
---|
158 | ftab->filts[i].caid = (ushort)a2i(ptr1, 4);
|
---|
159 | //cs_log("caid=%04X", ftab->filts[i].caid);
|
---|
160 | ptr[i] = ptr2;
|
---|
161 | }
|
---|
162 | else if (zFiltName && zFiltName[0]=='c')
|
---|
163 | {
|
---|
164 | cs_log("PANIC: CAID field not found in CHID parameter!");
|
---|
165 | cs_exit(1);
|
---|
166 | }
|
---|
167 | ftab->nfilts++;
|
---|
168 | }
|
---|
169 |
|
---|
170 | if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName);
|
---|
171 | for( i=0; i<ftab->nfilts; i++ )
|
---|
172 | {
|
---|
173 | cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid);
|
---|
174 | for( j=0, ptr3=strtok(ptr[i], ","); (j<CS_MAXPROV) && (ptr3); ptr3=strtok(NULL, ","), j++ )
|
---|
175 | {
|
---|
176 | ftab->filts[i].prids[j] = a2i(ptr3,6);
|
---|
177 | ftab->filts[i].nprids++;
|
---|
178 | cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]);
|
---|
179 | }
|
---|
180 | }
|
---|
181 | //cs_log("exit chk_ftab");
|
---|
182 | }
|
---|
183 |
|
---|
184 | static void chk_cltab(char *classasc, CLASSTAB *clstab)
|
---|
185 | {
|
---|
186 | int i;
|
---|
187 | char *ptr1;
|
---|
188 | for( i=0, ptr1=strtok(classasc, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ",") )
|
---|
189 | {
|
---|
190 | ptr1=trim(ptr1);
|
---|
191 | if( ptr1[0] == '!' )
|
---|
192 | clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2);
|
---|
193 | else
|
---|
194 | clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2);
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | static void chk_port_tab(char *portasc, PTAB *ptab)
|
---|
199 | {
|
---|
200 | int i,j,nfilts,ifilt,iport;
|
---|
201 | char *ptr1,*ptr2,*ptr3;
|
---|
202 | char *ptr[CS_MAXPORTS] = {0};
|
---|
203 | int port[CS_MAXPORTS] = {0};
|
---|
204 | int previous_nports = ptab->nports;
|
---|
205 |
|
---|
206 | for (nfilts=i=previous_nports, ptr1=strtok(portasc, ";"); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ";"), i++)
|
---|
207 | {
|
---|
208 | ptr[i] = ptr1;
|
---|
209 | if( (ptr2=strchr(trim(ptr1), '@')) )
|
---|
210 | {
|
---|
211 | *ptr2++='\0';
|
---|
212 | ptab->ports[i].s_port = atoi(ptr1);
|
---|
213 | ptr[i] = ptr2;
|
---|
214 | port[i] = ptab->ports[i].s_port;
|
---|
215 | ptab->nports++;
|
---|
216 | }
|
---|
217 | nfilts++;
|
---|
218 | }
|
---|
219 |
|
---|
220 | if( nfilts==1 && strlen(portasc)<6 && ptab->ports[0].s_port == 0 ) {
|
---|
221 | ptab->ports[0].s_port = atoi(portasc);
|
---|
222 | ptab->nports = 1;
|
---|
223 | }
|
---|
224 |
|
---|
225 | iport=ifilt = previous_nports;
|
---|
226 | for (i=previous_nports; i<nfilts; i++)
|
---|
227 | {
|
---|
228 | if( port[i]!=0 ) iport = i;
|
---|
229 | for (j=0, ptr3=strtok(ptr[i], ","); (j<CS_MAXPROV) && (ptr3); ptr3=strtok(NULL, ","), j++)
|
---|
230 | {
|
---|
231 | if( (ptr2=strchr(trim(ptr3), ':')) )
|
---|
232 | {
|
---|
233 | *ptr2++='\0';
|
---|
234 | ptab->ports[iport].ftab.nfilts++;
|
---|
235 | ifilt = ptab->ports[iport].ftab.nfilts-1;
|
---|
236 | ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4);
|
---|
237 | ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
|
---|
238 | } else {
|
---|
239 | ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
|
---|
240 | }
|
---|
241 | ptab->ports[iport].ftab.filts[ifilt].nprids++;
|
---|
242 | }
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | #ifdef NOTUSED
|
---|
247 | static void chk_srvip(char *value, in_addr_t *ip)
|
---|
248 | {
|
---|
249 | int i;
|
---|
250 | char *ptr;
|
---|
251 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
252 | if (i<8) ip[i++]=inet_addr(ptr);
|
---|
253 | }
|
---|
254 | #endif
|
---|
255 |
|
---|
256 | static void chk_t_global(char *token, char *value)
|
---|
257 | {
|
---|
258 | if (!strcmp(token, "serverip")) cfg->srvip=inet_addr(value);
|
---|
259 | if (!strcmp(token, "logfile")) strncpy(logfile, value, sizeof(logfile)-1);
|
---|
260 | if (!strcmp(token, "pidfile")) strncpy(cfg->pidfile, value, sizeof(cfg->pidfile)-1);
|
---|
261 | if (!strcmp(token, "usrfile")) strncpy(cfg->usrfile, value, sizeof(cfg->usrfile)-1);
|
---|
262 | if (!strcmp(token, "clienttimeout")) cfg->ctimeout=atoi(value);
|
---|
263 | if (!strcmp(token, "fallbacktimeout")) cfg->ftimeout=atoi(value);
|
---|
264 | if (!strcmp(token, "clientmaxidle")) cfg->cmaxidle=atoi(value);
|
---|
265 | if (!strcmp(token, "cachedelay")) cfg->delay=atoi(value);
|
---|
266 | if (!strcmp(token, "bindwait")) cfg->bindwait=atoi(value);
|
---|
267 | if (!strcmp(token, "netprio")) cfg->netprio=atoi(value);
|
---|
268 | if (!strcmp(token, "resolvedelay")) cfg->resolvedelay=atoi(value);
|
---|
269 | if (!strcmp(token, "sleep")) cfg->tosleep=atoi(value);
|
---|
270 | if (!strcmp(token, "nice"))
|
---|
271 | {
|
---|
272 | cfg->nice=atoi(value);
|
---|
273 | if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice=99;
|
---|
274 | if (cfg->nice!=99) cs_setpriority(cfg->nice); // ignore errors
|
---|
275 | }
|
---|
276 | if (!strcmp(token, "serialreadertimeout"))
|
---|
277 | {
|
---|
278 | cfg->srtimeout=atoi(value)*1000;
|
---|
279 | if( cfg->srtimeout <=0 )
|
---|
280 | cfg->srtimeout=1500;
|
---|
281 | }
|
---|
282 | if (!strcmp(token, "maxlogsize"))
|
---|
283 | {
|
---|
284 | cfg->max_log_size=atoi(value);
|
---|
285 | if( cfg->max_log_size <=10 )
|
---|
286 | cfg->max_log_size=10;
|
---|
287 | }
|
---|
288 | if( !strcmp(token, "showecmdw") )
|
---|
289 | cfg->show_ecm_dw = atoi(value);
|
---|
290 | }
|
---|
291 |
|
---|
292 | #ifdef CS_ANTICASC
|
---|
293 | static void chk_t_ac(char *token, char *value)
|
---|
294 | {
|
---|
295 | if (!strcmp(token, "enabled"))
|
---|
296 | {
|
---|
297 | cfg->ac_enabled=atoi(value);
|
---|
298 | if( cfg->ac_enabled<=0 ) cfg->ac_enabled=0;
|
---|
299 | else cfg->ac_enabled=1;
|
---|
300 | }
|
---|
301 |
|
---|
302 | if (!strcmp(token, "numusers"))
|
---|
303 | {
|
---|
304 | cfg->ac_users=atoi(value);
|
---|
305 | if( cfg->ac_users<0 ) cfg->ac_users=0;
|
---|
306 | }
|
---|
307 | if (!strcmp(token, "sampletime"))
|
---|
308 | {
|
---|
309 | cfg->ac_stime=atoi(value);
|
---|
310 | if( cfg->ac_stime<0 ) cfg->ac_stime=2;
|
---|
311 | }
|
---|
312 | if (!strcmp(token, "samples"))
|
---|
313 | {
|
---|
314 | cfg->ac_samples=atoi(value);
|
---|
315 | if( cfg->ac_samples<2 || cfg->ac_samples>10) cfg->ac_samples=10;
|
---|
316 | }
|
---|
317 | if (!strcmp(token, "penalty"))
|
---|
318 | {
|
---|
319 | cfg->ac_penalty=atoi(value);
|
---|
320 | if( cfg->ac_penalty<0 ) cfg->ac_penalty=0;
|
---|
321 |
|
---|
322 | }
|
---|
323 | if (!strcmp(token, "aclogfile"))
|
---|
324 | strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile)-1);
|
---|
325 | if( !strcmp(token, "fakedelay") )
|
---|
326 | {
|
---|
327 | cfg->ac_fakedelay=atoi(value);
|
---|
328 | if( cfg->ac_fakedelay<100 || cfg->ac_fakedelay>1000 )
|
---|
329 | cfg->ac_fakedelay=1000;
|
---|
330 | }
|
---|
331 | if( !strcmp(token, "denysamples") )
|
---|
332 | {
|
---|
333 | cfg->ac_denysamples=atoi(value);
|
---|
334 | if( cfg->ac_denysamples<2 || cfg->ac_denysamples>cfg->ac_samples-1 )
|
---|
335 | cfg->ac_denysamples=cfg->ac_samples-1;
|
---|
336 | }
|
---|
337 | #endif
|
---|
338 | }
|
---|
339 |
|
---|
340 | static void chk_t_monitor(char *token, char *value)
|
---|
341 | {
|
---|
342 | if (!strcmp(token, "port")) cfg->mon_port=atoi(value);
|
---|
343 | if (!strcmp(token, "serverip")) cfg->mon_srvip=inet_addr(value);
|
---|
344 | if (!strcmp(token, "nocrypt")) chk_iprange(value, &cfg->mon_allowed);
|
---|
345 | if (!strcmp(token, "aulow")) cfg->mon_aulow=atoi(value);
|
---|
346 | if (!strcmp(token, "monlevel")) cfg->mon_level=atoi(value);
|
---|
347 | if (!strcmp(token, "hideclient_to")) cfg->mon_hideclient_to=atoi(value);
|
---|
348 | }
|
---|
349 |
|
---|
350 | static void chk_t_camd33(char *token, char *value)
|
---|
351 | {
|
---|
352 | if (!strcmp(token, "port")) cfg->c33_port=atoi(value);
|
---|
353 | if (!strcmp(token, "serverip")) cfg->c33_srvip=inet_addr(value);
|
---|
354 | if (!strcmp(token, "nocrypt")) chk_iprange(value, &cfg->c33_plain);
|
---|
355 | if (!strcmp(token, "passive")) cfg->c33_passive=(value[0]!='0');
|
---|
356 | if (!strcmp(token, "key"))
|
---|
357 | {
|
---|
358 | if (key_atob(value, cfg->c33_key))
|
---|
359 | {
|
---|
360 | fprintf(stderr, "Configuration camd3.3x: Error in Key\n");
|
---|
361 | exit(1);
|
---|
362 | }
|
---|
363 | cfg->c33_crypted=1;
|
---|
364 | }
|
---|
365 | }
|
---|
366 |
|
---|
367 | static void chk_t_camd35(char *token, char *value)
|
---|
368 | {
|
---|
369 | if (!strcmp(token, "port")) cfg->c35_port=atoi(value);
|
---|
370 | if (!strcmp(token, "serverip")) cfg->c35_tcp_srvip=inet_addr(value);
|
---|
371 | }
|
---|
372 |
|
---|
373 | static void chk_t_camd35_tcp(char *token, char *value)
|
---|
374 | {
|
---|
375 | if (!strcmp(token, "port")) chk_port_tab(value, &cfg->c35_tcp_ptab);
|
---|
376 | if (!strcmp(token, "serverip")) cfg->c35_tcp_srvip=inet_addr(value);
|
---|
377 | }
|
---|
378 |
|
---|
379 | static void chk_t_newcamd(char *token, char *value)
|
---|
380 | {
|
---|
381 | if (!strcmp(token, "port")) chk_port_tab(value, &cfg->ncd_ptab);
|
---|
382 | if (!strcmp(token, "serverip")) cfg->ncd_srvip=inet_addr(value);
|
---|
383 | if (!strcmp(token, "key"))
|
---|
384 | {
|
---|
385 | if (key_atob14(value, cfg->ncd_key))
|
---|
386 | {
|
---|
387 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
388 | exit(1);
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | }
|
---|
393 |
|
---|
394 | static void chk_t_radegast(char *token, char *value)
|
---|
395 | {
|
---|
396 | if (!strcmp(token, "port")) cfg->rad_port=atoi(value);
|
---|
397 | if (!strcmp(token, "serverip")) cfg->rad_srvip=inet_addr(value);
|
---|
398 | if (!strcmp(token, "allowed")) chk_iprange(value, &cfg->rad_allowed);
|
---|
399 | if (!strcmp(token, "user")) strncpy(cfg->rad_usr, value, sizeof(cfg->rad_usr)-1);
|
---|
400 | }
|
---|
401 |
|
---|
402 | static void chk_t_serial(char *token, char *value)
|
---|
403 | {
|
---|
404 | if (!strcmp(token, "device"))
|
---|
405 | {
|
---|
406 | int l;
|
---|
407 | l=strlen(cfg->ser_device);
|
---|
408 | if (l) cfg->ser_device[l++]=1; // use ctrl-a as delimiter
|
---|
409 | strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-1-l);
|
---|
410 | }
|
---|
411 | }
|
---|
412 |
|
---|
413 | static void chk_t_gbox(char *token, char *value)
|
---|
414 | {
|
---|
415 | // if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
|
---|
416 | if (!strcmp(token, "password")) cs_atob(cfg->gbox_pwd, value, 4);
|
---|
417 | if (!strcmp(token, "maxdist")) cfg->maxdist=atoi(value);
|
---|
418 | if (!strcmp(token, "ignorelist")) strncpy(cfg->ignorefile, value, sizeof(cfg->ignorefile)-1);
|
---|
419 | if (!strcmp(token, "onlineinfos")) strncpy(cfg->gbxShareOnl, value, sizeof(cfg->gbxShareOnl)-1);
|
---|
420 | if (!strcmp(token, "cardinfos")) strncpy(cfg->cardfile, value, sizeof(cfg->cardfile)-1);
|
---|
421 | if (!strcmp(token, "locals"))
|
---|
422 | {
|
---|
423 | char *ptr1;
|
---|
424 | int n=0, i;
|
---|
425 | for (i=0, ptr1=strtok(value, ","); (i<CS_MAXLOCALS) && (ptr1); ptr1=strtok(NULL, ","))
|
---|
426 | {
|
---|
427 | cfg->locals[n++]=a2i(ptr1, 8);
|
---|
428 | //printf("%i %08X",n,cfg->locals[n-1]);
|
---|
429 | }
|
---|
430 | cfg->num_locals=n;
|
---|
431 | }
|
---|
432 | }
|
---|
433 |
|
---|
434 | static void chk_token(char *token, char *value, int tag)
|
---|
435 | {
|
---|
436 | switch(tag)
|
---|
437 | {
|
---|
438 | case TAG_GLOBAL : chk_t_global(token, value); break;
|
---|
439 | case TAG_MONITOR : chk_t_monitor(token, value); break;
|
---|
440 | case TAG_CAMD33 : chk_t_camd33(token, value); break;
|
---|
441 | case TAG_CAMD35 :
|
---|
442 | case TAG_CS357X : chk_t_camd35(token, value); break;
|
---|
443 | case TAG_NEWCAMD : chk_t_newcamd(token, value); break;
|
---|
444 | case TAG_RADEGAST: chk_t_radegast(token, value); break;
|
---|
445 | case TAG_SERIAL : chk_t_serial(token, value); break;
|
---|
446 | case TAG_CS378X : chk_t_camd35_tcp(token, value); break;
|
---|
447 | case TAG_GBOX : chk_t_gbox(token, value); break;
|
---|
448 | #ifdef CS_ANTICASC
|
---|
449 | case TAG_ANTICASC: chk_t_ac(token, value); break;
|
---|
450 | #endif
|
---|
451 | }
|
---|
452 | }
|
---|
453 |
|
---|
454 | void init_len4caid()
|
---|
455 | {
|
---|
456 | int nr;
|
---|
457 | FILE *fp;
|
---|
458 | char *value;
|
---|
459 |
|
---|
460 | memset(len4caid, 0, sizeof(ushort)<<8);
|
---|
461 | sprintf(token, "%s%s", cs_confdir, cs_l4ca);
|
---|
462 | if (!(fp=fopen(token, "r")))
|
---|
463 | return;
|
---|
464 | for(nr=0; fgets(token, sizeof(token), fp);)
|
---|
465 | {
|
---|
466 | int i, c;
|
---|
467 | char *ptr;
|
---|
468 | if (!(value=strchr(token, ':'))) continue;
|
---|
469 | *value++='\0';
|
---|
470 | if( (ptr=strchr(value, '#')) )
|
---|
471 | *ptr='\0';
|
---|
472 | if (strlen(trim(token))!=2) continue;
|
---|
473 | if (strlen(trim(value))!=4) continue;
|
---|
474 | if ((i=byte_atob(token))<0) continue;
|
---|
475 | if ((c=word_atob(value))<0) continue;
|
---|
476 | //printf("idx %02X = %04X\n", i, c); fflush(stdout);
|
---|
477 | len4caid[i]=c;
|
---|
478 | nr++;
|
---|
479 | }
|
---|
480 | fclose(fp);
|
---|
481 | cs_log("%d lengths for caid guessing loaded", nr);
|
---|
482 | return;
|
---|
483 | }
|
---|
484 |
|
---|
485 | int search_boxkey(ushort caid, ulong provid, char *key)
|
---|
486 | {
|
---|
487 | int i, rc=0;
|
---|
488 | FILE *fp;
|
---|
489 | char c_caid[512];
|
---|
490 |
|
---|
491 | sprintf(c_caid, "%s%s", cs_confdir, cs_cert);
|
---|
492 | if (fp=fopen(c_caid, "r"))
|
---|
493 | {
|
---|
494 | for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);)
|
---|
495 | {
|
---|
496 | char *c_provid, *c_key;
|
---|
497 | if (c_provid=strchr(c_caid, '#'))
|
---|
498 | *c_provid='\0';
|
---|
499 | if (!(c_provid=strchr(c_caid, ':'))) continue;
|
---|
500 | *c_provid++='\0';
|
---|
501 | if (!(c_key=strchr(c_provid, ':'))) continue;
|
---|
502 | *c_key++='\0';
|
---|
503 | if (word_atob(trim(c_caid))!=caid) continue;
|
---|
504 | if ((i=(strlen(trim(c_key))>>1))>256) continue;
|
---|
505 | if (cs_atob(key, c_key, i)<0)
|
---|
506 | {
|
---|
507 | cs_log("wrong key in \"%s\"", cs_cert);
|
---|
508 | continue;
|
---|
509 | }
|
---|
510 | rc=1;
|
---|
511 | }
|
---|
512 | fclose(fp);
|
---|
513 | }
|
---|
514 | #ifdef MPCS_INBUILD_KEYS
|
---|
515 | for(i=0; (!rc) && (npkey[i].keylen); i++)
|
---|
516 | if (rc=((caid==npkey[i].caid) && (provid==npkey[i].provid)))
|
---|
517 | memcpy(key, npkey[i].key, npkey[i].keylen);
|
---|
518 | #endif
|
---|
519 | return(rc);
|
---|
520 | }
|
---|
521 |
|
---|
522 | int init_config()
|
---|
523 | {
|
---|
524 | int tag=TAG_GLOBAL;
|
---|
525 | FILE *fp;
|
---|
526 | char *value;
|
---|
527 |
|
---|
528 | #ifndef CS_EMBEDDED
|
---|
529 | #ifdef PRIO_PROCESS
|
---|
530 | errno=0;
|
---|
531 | if ((cfg->nice=getpriority(PRIO_PROCESS, 0))==(-1))
|
---|
532 | if (errno)
|
---|
533 | #endif
|
---|
534 | #endif
|
---|
535 | cfg->nice=99;
|
---|
536 | cfg->ctimeout=CS_CLIENT_TIMEOUT;
|
---|
537 | cfg->ftimeout=2;
|
---|
538 | cfg->cmaxidle=CS_CLIENT_MAXIDLE;
|
---|
539 | cfg->delay=CS_DELAY;
|
---|
540 | cfg->bindwait=CS_BIND_TIMEOUT;
|
---|
541 | cfg->resolvedelay=CS_RESOLVE_DELAY;
|
---|
542 | cfg->mon_level=2;
|
---|
543 | cfg->mon_hideclient_to=0;
|
---|
544 | cfg->srtimeout=1500;
|
---|
545 | #ifdef CS_ANTICASC
|
---|
546 | cfg->ac_enabled=0;
|
---|
547 | cfg->ac_users=0;
|
---|
548 | cfg->ac_stime=2;
|
---|
549 | cfg->ac_samples=10;
|
---|
550 | cfg->ac_denysamples=8;
|
---|
551 | cfg->ac_fakedelay=1000;
|
---|
552 | strcpy(cfg->ac_logfile, "./mpcs_ac.log");
|
---|
553 | #endif
|
---|
554 | sprintf(token, "%s%s", cs_confdir, cs_conf);
|
---|
555 | if (!(fp=fopen(token, "r")))
|
---|
556 | {
|
---|
557 | fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno);
|
---|
558 | exit(1);
|
---|
559 | }
|
---|
560 | while (fgets(token, sizeof(token), fp))
|
---|
561 | {
|
---|
562 | int i, l;
|
---|
563 | //void *ptr;
|
---|
564 | if ((l=strlen(trim(token)))<3) continue;
|
---|
565 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
566 | {
|
---|
567 | for (token[l-1]=0, tag=-1, i=TAG_GLOBAL; cctag[i]; i++)
|
---|
568 | if (!strcmp(cctag[i], strtolower(token+1)))
|
---|
569 | tag=i;
|
---|
570 | continue;
|
---|
571 | }
|
---|
572 | if (!(value=strchr(token, '='))) continue;
|
---|
573 | *value++='\0';
|
---|
574 | chk_token(trim(strtolower(token)), trim(value), tag);
|
---|
575 | }
|
---|
576 | fclose(fp);
|
---|
577 | cs_init_log(logfile);
|
---|
578 | if (cfg->ftimeout>=cfg->ctimeout)
|
---|
579 | {
|
---|
580 | cfg->ftimeout=cfg->ctimeout+1;
|
---|
581 | cs_log("WARNING: fallbacktimeout adjusted to %d", cfg->ftimeout);
|
---|
582 | }
|
---|
583 | if( cfg->ftimeout<(cfg->srtimeout/1000) )
|
---|
584 | {
|
---|
585 | cfg->ftimeout=(cfg->srtimeout/1000)+1;
|
---|
586 | cs_log("WARNING: fallbacktimeout adjusted to %d", cfg->ftimeout);
|
---|
587 | }
|
---|
588 | if( cfg->ctimeout<(cfg->srtimeout/1000) )
|
---|
589 | {
|
---|
590 | cfg->ctimeout=(cfg->srtimeout/1000)+1;
|
---|
591 | cs_log("WARNING: clienttimeout adjusted to %d", cfg->ctimeout);
|
---|
592 | }
|
---|
593 | #ifdef CS_ANTICASC
|
---|
594 | if( cfg->ac_denysamples+1>cfg->ac_samples )
|
---|
595 | {
|
---|
596 | cfg->ac_denysamples=cfg->ac_samples-1;
|
---|
597 | cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples);
|
---|
598 | }
|
---|
599 | #endif
|
---|
600 | return 0;
|
---|
601 | }
|
---|
602 |
|
---|
603 | static void chk_account(char *token, char *value, struct s_auth *account)
|
---|
604 | {
|
---|
605 | int i;
|
---|
606 | char *ptr1;//, *ptr2;
|
---|
607 | if (!strcmp(token, "user")) strncpy(account->usr, value, sizeof(account->usr)-1);
|
---|
608 | if (!strcmp(token, "pwd")) strncpy(account->pwd, value, sizeof(account->pwd)-1);
|
---|
609 | if (!strcmp(token, "hostname")) strncpy(account->dyndns, value, sizeof(account->dyndns)-1);
|
---|
610 | if (!strcmp(token, "1801to1702")) account->premhack=atoi(value);
|
---|
611 | if (!strcmp(token, "uniq")) account->uniq=atoi(value);
|
---|
612 | if (!strcmp(token, "sleep")) account->tosleep=atoi(value);
|
---|
613 | if (!strcmp(token, "monlevel")) account->monlvl=atoi(value);
|
---|
614 | if (!strcmp(token, "caid")) chk_caidtab(value, &account->ctab);
|
---|
615 | /*
|
---|
616 | * case insensitive
|
---|
617 | */
|
---|
618 | strtolower(value);
|
---|
619 | if (!strcmp(token, "au"))
|
---|
620 | for (i=0; i<CS_MAXREADER; i++)
|
---|
621 | if ((reader[i].label[0]) &&
|
---|
622 | (!strncmp(reader[i].label, value, strlen(reader[i].label))))
|
---|
623 | account->au=i;
|
---|
624 | if (!strcmp(token, "group"))
|
---|
625 | for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ","))
|
---|
626 | {
|
---|
627 | int g;
|
---|
628 | g=atoi(ptr1);
|
---|
629 | if ((g>0) && (g<33)) account->grp|=(1<<(g-1));
|
---|
630 | }
|
---|
631 | if(!strcmp(token, "services")) chk_services(value, &account->sidtabok, &account->sidtabno);
|
---|
632 | if(!strcmp(token, "ident")) chk_ftab(value, &account->ftab, "user", account->usr, "provid");
|
---|
633 | if(!strcmp(token, "class")) chk_cltab(value, &account->cltab);
|
---|
634 | if(!strcmp(token, "chid")) chk_ftab(value, &account->fchid, "user", account->usr, "chid");
|
---|
635 |
|
---|
636 | #ifdef CS_ANTICASC
|
---|
637 | if( !strcmp(token, "numusers") )
|
---|
638 | account->ac_users = atoi(value);
|
---|
639 | if( !strcmp(token, "penalty") )
|
---|
640 | account->ac_penalty = atoi(value);
|
---|
641 | #endif
|
---|
642 |
|
---|
643 | // if (!strcmp(token, "caid"))
|
---|
644 | // {
|
---|
645 | // for (i=0, ptr1=strtok(value, ","); (i<CS_MAXCAIDTAB) && (ptr1); ptr1=strtok(NULL, ","))
|
---|
646 | // {
|
---|
647 | // ulong caid, mask;
|
---|
648 | // if (ptr2=strchr(trim(ptr1), '&'))
|
---|
649 | // *ptr2++='\0';
|
---|
650 | // else
|
---|
651 | // ptr2="";
|
---|
652 | // if (((caid=a2i(ptr1, 2))|(mask=a2i(ptr2,-2))) < 0x10000)
|
---|
653 | // {
|
---|
654 | // account->caidtab[i][0]=caid;
|
---|
655 | // account->caidtab[i++][1]=mask;
|
---|
656 | // }
|
---|
657 | // else
|
---|
658 | // cs_log("WARNING: wrong CAID in %s -> ignored", cs_user);
|
---|
659 | // }
|
---|
660 | // }
|
---|
661 | }
|
---|
662 |
|
---|
663 | int init_userdb()
|
---|
664 | {
|
---|
665 | int tag=0, nr, nro;
|
---|
666 | //int first=1;
|
---|
667 | FILE *fp;
|
---|
668 | char *value;
|
---|
669 | struct s_auth *ptr;
|
---|
670 | /*static */struct s_auth *account=(struct s_auth *)0;
|
---|
671 |
|
---|
672 | sprintf(token, "%s%s", cs_confdir, cs_user);
|
---|
673 | if (!(fp=fopen(token, "r")))
|
---|
674 | {
|
---|
675 | cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
|
---|
676 | return(1);
|
---|
677 | }
|
---|
678 | for (nro=0, ptr=cfg->account; ptr; nro++)
|
---|
679 | {
|
---|
680 | struct s_auth *ptr_next;
|
---|
681 | ptr_next=ptr->next;
|
---|
682 | free(ptr);
|
---|
683 | ptr=ptr_next;
|
---|
684 | }
|
---|
685 | nr=0;
|
---|
686 | while (fgets(token, sizeof(token), fp))
|
---|
687 | {
|
---|
688 | int i, l;
|
---|
689 | void *ptr;
|
---|
690 | if ((l=strlen(trim(token)))<3) continue;
|
---|
691 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
692 | {
|
---|
693 | token[l-1]=0;
|
---|
694 | tag=(!strcmp("account", strtolower(token+1)));
|
---|
695 | if (!(ptr=malloc(sizeof(struct s_auth))))
|
---|
696 | {
|
---|
697 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
698 | return(1);
|
---|
699 | }
|
---|
700 | if (account)
|
---|
701 | account->next=ptr;
|
---|
702 | else
|
---|
703 | cfg->account=ptr;
|
---|
704 | account=ptr;
|
---|
705 | memset(account, 0, sizeof(struct s_auth));
|
---|
706 | account->au=(-1);
|
---|
707 | account->monlvl=cfg->mon_level;
|
---|
708 | account->tosleep=cfg->tosleep;
|
---|
709 | for (i=1; i<CS_MAXCAIDTAB; account->ctab.mask[i++]=0xffff);
|
---|
710 | nr++;
|
---|
711 | #ifdef CS_ANTICASC
|
---|
712 | account->ac_users=cfg->ac_users;
|
---|
713 | account->ac_penalty=cfg->ac_penalty;
|
---|
714 | account->ac_idx = nr;
|
---|
715 | #endif
|
---|
716 | continue;
|
---|
717 | }
|
---|
718 | if (!tag) continue;
|
---|
719 | if (!(value=strchr(token, '='))) continue;
|
---|
720 | *value++='\0';
|
---|
721 | chk_account(trim(strtolower(token)), trim(value), account);
|
---|
722 | }
|
---|
723 | fclose(fp);
|
---|
724 | cs_log("userdb reloaded: %d accounts freed, %d accounts loaded", nro, nr);
|
---|
725 | return(0);
|
---|
726 | }
|
---|
727 |
|
---|
728 | static ushort *chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
|
---|
729 | {
|
---|
730 | int i, b;
|
---|
731 | char *ptr;
|
---|
732 | ushort *slist=(ushort *) 0;
|
---|
733 | ulong *llist=(ulong *) 0;
|
---|
734 | ulong caid;
|
---|
735 | char buf[512];
|
---|
736 | strncpy(buf, value, sizeof(buf));
|
---|
737 | b=(what==1) ? sizeof(ulong) : sizeof(ushort);
|
---|
738 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
739 | {
|
---|
740 | caid=a2i(ptr, b);
|
---|
741 | if (!errno) i++;
|
---|
742 | }
|
---|
743 | if (!i) return(0);
|
---|
744 | if (b==sizeof(ushort))
|
---|
745 | slist=malloc(i*sizeof(ushort));
|
---|
746 | else
|
---|
747 | llist=malloc(i*sizeof(ulong));
|
---|
748 | strcpy(value, buf);
|
---|
749 | for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
750 | {
|
---|
751 | caid=a2i(ptr, b);
|
---|
752 | if (errno) continue;
|
---|
753 | if (b==sizeof(ushort))
|
---|
754 | slist[i++]=(ushort) caid;
|
---|
755 | else
|
---|
756 | llist[i++]=caid;
|
---|
757 | }
|
---|
758 | switch (what)
|
---|
759 | {
|
---|
760 | case 0: sidtab->caid=slist;
|
---|
761 | sidtab->num_caid=i;
|
---|
762 | break;
|
---|
763 | case 1: sidtab->provid=llist;
|
---|
764 | sidtab->num_provid=i;
|
---|
765 | break;
|
---|
766 | case 2: sidtab->srvid=slist;
|
---|
767 | sidtab->num_srvid=i;
|
---|
768 | break;
|
---|
769 | }
|
---|
770 | }
|
---|
771 |
|
---|
772 | static void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
|
---|
773 | {
|
---|
774 | if (!strcmp(token, "caid")) chk_entry4sidtab(value, sidtab, 0);
|
---|
775 | if (!strcmp(token, "provid")) chk_entry4sidtab(value, sidtab, 1);
|
---|
776 | if (!strcmp(token, "ident")) chk_entry4sidtab(value, sidtab, 1);
|
---|
777 | if (!strcmp(token, "srvid")) chk_entry4sidtab(value, sidtab, 2);
|
---|
778 | }
|
---|
779 |
|
---|
780 | int init_sidtab()
|
---|
781 | {
|
---|
782 | int tag=0, nr, nro;
|
---|
783 | FILE *fp;
|
---|
784 | char *value;
|
---|
785 | struct s_sidtab *ptr;
|
---|
786 | struct s_sidtab *sidtab=(struct s_sidtab *)0;
|
---|
787 |
|
---|
788 | sprintf(token, "%s%s", cs_confdir, cs_sidt);
|
---|
789 | if (!(fp=fopen(token, "r")))
|
---|
790 | {
|
---|
791 | cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
|
---|
792 | return(1);
|
---|
793 | }
|
---|
794 | for (nro=0, ptr=cfg->sidtab; ptr; nro++)
|
---|
795 | {
|
---|
796 | struct s_sidtab *ptr_next;
|
---|
797 | ptr_next=ptr->next;
|
---|
798 | if (ptr->caid) free(ptr->caid);
|
---|
799 | if (ptr->provid) free(ptr->provid);
|
---|
800 | if (ptr->srvid) free(ptr->srvid);
|
---|
801 | free(ptr);
|
---|
802 | ptr=ptr_next;
|
---|
803 | }
|
---|
804 | nr=0;
|
---|
805 | while (fgets(token, sizeof(token), fp))
|
---|
806 | {
|
---|
807 | int i, l;
|
---|
808 | void *ptr;
|
---|
809 | if ((l=strlen(trim(token)))<3) continue;
|
---|
810 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
811 | {
|
---|
812 | token[l-1]=0;
|
---|
813 | if (!(ptr=malloc(sizeof(struct s_sidtab))))
|
---|
814 | {
|
---|
815 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
816 | return(1);
|
---|
817 | }
|
---|
818 | if (sidtab)
|
---|
819 | sidtab->next=ptr;
|
---|
820 | else
|
---|
821 | cfg->sidtab=ptr;
|
---|
822 | sidtab=ptr;
|
---|
823 | nr++;
|
---|
824 | memset(sidtab, 0, sizeof(struct s_sidtab));
|
---|
825 | strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
|
---|
826 | continue;
|
---|
827 | }
|
---|
828 | if (!sidtab) continue;
|
---|
829 | if (!(value=strchr(token, '='))) continue;
|
---|
830 | *value++='\0';
|
---|
831 | chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
|
---|
832 | }
|
---|
833 | fclose(fp);
|
---|
834 |
|
---|
835 | #ifdef DEBUG_SIDTAB
|
---|
836 | show_sidtab(cfg->sidtab);
|
---|
837 | #endif
|
---|
838 | cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
|
---|
839 | return(0);
|
---|
840 | }
|
---|
841 |
|
---|
842 | int init_srvid()
|
---|
843 | {
|
---|
844 | int nr;
|
---|
845 | FILE *fp;
|
---|
846 | char *value;
|
---|
847 | static struct s_srvid *srvid=(struct s_srvid *)0;
|
---|
848 |
|
---|
849 | sprintf(token, "%s%s", cs_confdir, cs_srid);
|
---|
850 | if (!(fp=fopen(token, "r")))
|
---|
851 | {
|
---|
852 | cs_log("can't open file \"%s\" (err=%d), no service-id's loaded",
|
---|
853 | token, errno);
|
---|
854 | return(0);
|
---|
855 | }
|
---|
856 | nr=0;
|
---|
857 | while (fgets(token, sizeof(token), fp))
|
---|
858 | {
|
---|
859 | int l;
|
---|
860 | void *ptr;
|
---|
861 | if ((l=strlen(trim(token)))<6) continue;
|
---|
862 | if (!(value=strchr(token, ':'))) continue;
|
---|
863 | *value++='\0';
|
---|
864 | if (strlen(token)!=4) continue;
|
---|
865 | if (!(ptr=malloc(sizeof(struct s_srvid))))
|
---|
866 | {
|
---|
867 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
868 | return(1);
|
---|
869 | }
|
---|
870 | if (srvid)
|
---|
871 | srvid->next=ptr;
|
---|
872 | else
|
---|
873 | cfg->srvid=ptr;
|
---|
874 | srvid=ptr;
|
---|
875 | memset(srvid, 0, sizeof(struct s_srvid));
|
---|
876 | srvid->srvid=word_atob(token);
|
---|
877 | strncpy(srvid->name, value, sizeof(srvid->name)-1);
|
---|
878 | nr++;
|
---|
879 | }
|
---|
880 | fclose(fp);
|
---|
881 | cs_log("%d service-id's loaded", nr);
|
---|
882 | return(0);
|
---|
883 | }
|
---|
884 |
|
---|
885 | static void chk_reader(char *token, char *value, struct s_reader *rdr)
|
---|
886 | {
|
---|
887 | int i;
|
---|
888 | char *ptr;
|
---|
889 | unsigned long tmp;
|
---|
890 | /*
|
---|
891 | * case sensitive first
|
---|
892 | */
|
---|
893 | if (!strcmp(token, "device"))
|
---|
894 | for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
895 | {
|
---|
896 | trim(ptr);
|
---|
897 | switch(i)
|
---|
898 | {
|
---|
899 | case 0: strncpy(rdr->device, ptr, sizeof(rdr->device)-1); break;
|
---|
900 | case 1: rdr->r_port=atoi(ptr); break;
|
---|
901 | case 2: rdr->l_port=atoi(ptr); break;
|
---|
902 | }
|
---|
903 | }
|
---|
904 | if (!strcmp(token, "key"))
|
---|
905 | {
|
---|
906 | if (key_atob14(value, rdr->ncd_key))
|
---|
907 | {
|
---|
908 | fprintf(stderr, "Configuration newcamd: Error in Key\n");
|
---|
909 | exit(1);
|
---|
910 | }
|
---|
911 | }
|
---|
912 | if (!strcmp(token, "password")) strncpy(rdr->gbox_pwd, i2b(4, a2i(value, 4)), 4);
|
---|
913 | if (!strcmp(token, "premium")) rdr->gbox_prem=1;
|
---|
914 | if (!strcmp(token, "account"))
|
---|
915 | for (i=0, ptr=strtok(value, ","); (i<2)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
916 | {
|
---|
917 | trim(ptr);
|
---|
918 | switch(i)
|
---|
919 | {
|
---|
920 | case 0: strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr)-1); break;
|
---|
921 | case 1: strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd)-1); break;
|
---|
922 | }
|
---|
923 | }
|
---|
924 | /*
|
---|
925 | * case insensitive
|
---|
926 | */
|
---|
927 | strtolower(value);
|
---|
928 |
|
---|
929 | if (!strcmp(token, "services")) chk_services(value, &rdr->sidtabok, &rdr->sidtabno);
|
---|
930 | if (!strcmp(token, "inactivitytimeout")) rdr->tcp_ito = atoi(value);
|
---|
931 | if (!strcmp(token, "reconnecttimeout")) rdr->tcp_rto = atoi(value);
|
---|
932 | if (!strcmp(token, "disableserverfilter")) rdr->ncd_disable_server_filt = atoi(value);
|
---|
933 |
|
---|
934 | if (!strcmp(token, "label")) strncpy(rdr->label, value, sizeof(rdr->label)-1);
|
---|
935 | if (!strcmp(token, "fallback")) rdr->fallback=atoi(value) ? 1 : 0;
|
---|
936 | if (!strcmp(token, "logport")) rdr->log_port=atoi(value);
|
---|
937 | if (!strcmp(token, "caid")) chk_caidtab(value, &rdr->ctab);
|
---|
938 | if (!strcmp(token, "detect"))
|
---|
939 | for (i=0; RDR_CD_TXT[i]; i++)
|
---|
940 | {
|
---|
941 | if (!strcmp(value, RDR_CD_TXT[i]))
|
---|
942 | rdr->detect=i;
|
---|
943 | else
|
---|
944 | if ((value[0]=='!') && (!strcmp(value+1, RDR_CD_TXT[i])))
|
---|
945 | rdr->detect=i|0x80;
|
---|
946 | }
|
---|
947 | if (!strcmp(token, "mhz"))
|
---|
948 | {
|
---|
949 | if (!strcmp(value, "600")) rdr->mhz=600;
|
---|
950 | if (!strcmp(value, "357")) rdr->mhz=357;
|
---|
951 | if (!strcmp(value, "358")) rdr->mhz=358;
|
---|
952 | }
|
---|
953 | if (!strcmp(token, "customspeed"))
|
---|
954 | {
|
---|
955 | if (!strcmp(value, "0")) rdr->custom_speed=0;
|
---|
956 | if (!strcmp(value, "1"))rdr->custom_speed=1;
|
---|
957 | }
|
---|
958 | if (!strcmp(token, "protocol"))
|
---|
959 | {
|
---|
960 | if (!strcmp(value, "mouse")) rdr->typ=R_MOUSE;
|
---|
961 | if (!strcmp(value, "internal")) rdr->typ=R_INTERN;
|
---|
962 | if (!strcmp(value, "intern")) rdr->typ=R_INTERN;
|
---|
963 | if (!strcmp(value, "serial")) rdr->typ=R_SERIAL;
|
---|
964 | if (!strcmp(value, "camd35")) rdr->typ=R_CAMD35;
|
---|
965 | if (!strcmp(value, "cs378x")) rdr->typ=R_CS378X;
|
---|
966 | if (!strcmp(value, "cs357x")) rdr->typ=R_CAMD35;
|
---|
967 | if (!strcmp(value, "gbox")) rdr->typ=R_GBOX;
|
---|
968 | if (!strcmp(value, "newcamd") ||
|
---|
969 | !strcmp(value, "newcamd525")) {rdr->typ=R_NEWCAMD;
|
---|
970 | rdr->ncd_proto=NCD_525;}
|
---|
971 | if (!strcmp(value, "newcamd524")) {rdr->typ=R_NEWCAMD;
|
---|
972 | rdr->ncd_proto=NCD_524;}
|
---|
973 | }
|
---|
974 | if (!strcmp(token, "ident")) chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid");
|
---|
975 | if (!strcmp(token, "class")) chk_cltab(value, &rdr->cltab);
|
---|
976 | if (!strcmp(token, "chid")) chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid");
|
---|
977 | if (!strcmp(token, "showcls")) rdr->show_cls = atoi(value);
|
---|
978 | if (!strcmp(token, "maxqlen")) rdr->maxqlen = atoi(value);
|
---|
979 | if( rdr->maxqlen<0 || rdr->maxqlen>CS_MAXQLEN ) rdr->maxqlen=CS_MAXQLEN;
|
---|
980 |
|
---|
981 | if (!strcmp(token, "group"))
|
---|
982 | for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
983 | {
|
---|
984 | int g;
|
---|
985 | g=atoi(ptr);
|
---|
986 | if ((g>0) && (g<33)) rdr->grp|=(1<<(g-1));
|
---|
987 | }
|
---|
988 | if (!strcmp(token, "emmcache"))
|
---|
989 | for (i=0, ptr=strtok(value, ","); (i<3)&&(ptr); ptr=strtok(NULL, ","), i++)
|
---|
990 | switch(i)
|
---|
991 | {
|
---|
992 | case 0: rdr->cachemm=atoi(ptr); break;
|
---|
993 | case 1: rdr->rewritemm=atoi(ptr); break;
|
---|
994 | case 2: rdr->logemm=atoi(ptr); break;
|
---|
995 | }
|
---|
996 | if (!strcmp(token, "blocknano"))
|
---|
997 | for (ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
|
---|
998 | if ((i=byte_atob(ptr))>=0)
|
---|
999 | rdr->b_nano[i]=1;
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | int init_readerdb()
|
---|
1003 | {
|
---|
1004 | int tag=0, nr;
|
---|
1005 | FILE *fp;
|
---|
1006 | char *value;
|
---|
1007 |
|
---|
1008 | sprintf(token, "%s%s", cs_confdir, cs_srvr);
|
---|
1009 | if (!(fp=fopen(token, "r")))
|
---|
1010 | {
|
---|
1011 | cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
|
---|
1012 | return(1);
|
---|
1013 | }
|
---|
1014 | nr=0;
|
---|
1015 | while (fgets(token, sizeof(token), fp))
|
---|
1016 | {
|
---|
1017 | int i, l;
|
---|
1018 | if ((l=strlen(trim(token)))<3) continue;
|
---|
1019 | if ((token[0]=='[') && (token[l-1]==']'))
|
---|
1020 | {
|
---|
1021 | token[l-1]=0;
|
---|
1022 | tag=(!strcmp("reader", strtolower(token+1)));
|
---|
1023 | if (reader[nr].label[0] && reader[nr].typ) nr++;
|
---|
1024 | memset(&reader[nr], 0, sizeof(struct s_reader));
|
---|
1025 | reader[nr].tcp_rto = 30;
|
---|
1026 | reader[nr].show_cls = 10;
|
---|
1027 | reader[nr].maxqlen = CS_MAXQLEN;
|
---|
1028 | reader[nr].mhz = 357;
|
---|
1029 | reader[nr].custom_speed = 1;
|
---|
1030 | for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
|
---|
1031 | continue;
|
---|
1032 | }
|
---|
1033 | if (!tag) continue;
|
---|
1034 | if (!(value=strchr(token, '='))) continue;
|
---|
1035 | *value++='\0';
|
---|
1036 | chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
|
---|
1037 | }
|
---|
1038 | fclose(fp);
|
---|
1039 | return(0);
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | /*
|
---|
1043 | int init_irdeto_guess_tab()
|
---|
1044 | {
|
---|
1045 | int i, j, skip;
|
---|
1046 | int b47;
|
---|
1047 | FILE *fp;
|
---|
1048 | char token[128], *value, *ptr;
|
---|
1049 | char zSid[5];
|
---|
1050 | uchar b3;
|
---|
1051 | ushort caid, sid;
|
---|
1052 | struct s_irdeto_quess *ird_row, *head;
|
---|
1053 |
|
---|
1054 | memset(cfg->itab, 0, sizeof(cfg->itab));
|
---|
1055 | sprintf(token, "%s%s", cs_confdir, cs_ird);
|
---|
1056 | if (!(fp=fopen(token, "r")))
|
---|
1057 | {
|
---|
1058 | cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
|
---|
1059 | token, errno);
|
---|
1060 | return(1);
|
---|
1061 | }
|
---|
1062 | while (fgets(token, sizeof(token), fp))
|
---|
1063 | {
|
---|
1064 | if( strlen(token)<20 ) continue;
|
---|
1065 | for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
1066 | {
|
---|
1067 | trim(ptr);
|
---|
1068 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
1069 | skip=1;
|
---|
1070 | break;
|
---|
1071 | }
|
---|
1072 | switch(i)
|
---|
1073 | {
|
---|
1074 | case 0: b3 = a2i(ptr, 2); break;
|
---|
1075 | case 1: b47 = a2i(ptr, 8); break;
|
---|
1076 | case 2: caid = a2i(ptr, 4); break;
|
---|
1077 | case 3:
|
---|
1078 | for( j=0; j<4; j++ )
|
---|
1079 | zSid[j]=ptr[j];
|
---|
1080 | zSid[4]=0;
|
---|
1081 | sid = a2i(zSid, 4);
|
---|
1082 | break;
|
---|
1083 | }
|
---|
1084 | }
|
---|
1085 | if( !skip )
|
---|
1086 | {
|
---|
1087 | if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
|
---|
1088 | {
|
---|
1089 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
1090 | return;
|
---|
1091 | }
|
---|
1092 | ird_row->b47 = b47;
|
---|
1093 | ird_row->caid = caid;
|
---|
1094 | ird_row->sid = sid;
|
---|
1095 | ird_row->next = 0;
|
---|
1096 |
|
---|
1097 | head = cfg->itab[b3];
|
---|
1098 | if( head ) {
|
---|
1099 | while( head->next )
|
---|
1100 | head=head->next;
|
---|
1101 | head->next=ird_row;
|
---|
1102 | }
|
---|
1103 | else
|
---|
1104 | cfg->itab[b3]=ird_row;
|
---|
1105 |
|
---|
1106 | //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
|
---|
1107 | }
|
---|
1108 | }
|
---|
1109 | fclose(fp);
|
---|
1110 |
|
---|
1111 | for( i=0; i<0xff; i++ )
|
---|
1112 | {
|
---|
1113 | head=cfg->itab[i];
|
---|
1114 | while(head)
|
---|
1115 | {
|
---|
1116 | cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
|
---|
1117 | i, head->b47, head->caid, head->sid);
|
---|
1118 | head=head->next;
|
---|
1119 | }
|
---|
1120 | }
|
---|
1121 | return(0);
|
---|
1122 | }
|
---|
1123 | */
|
---|
1124 |
|
---|
1125 | #ifdef CS_ANTICASC
|
---|
1126 | void init_ac()
|
---|
1127 | {
|
---|
1128 | int nr;
|
---|
1129 | FILE *fp;
|
---|
1130 | //char *value;
|
---|
1131 |
|
---|
1132 | sprintf(token, "%s%s", cs_confdir, cs_ac);
|
---|
1133 | if (!(fp=fopen(token, "r")))
|
---|
1134 | {
|
---|
1135 | cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
|
---|
1136 | token, errno);
|
---|
1137 | return;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | for(nr=0; fgets(token, sizeof(token), fp);)
|
---|
1141 | {
|
---|
1142 | int i, skip;
|
---|
1143 | ushort caid, sid, chid, dwtime;
|
---|
1144 | ulong provid;
|
---|
1145 | char *ptr, *ptr1;
|
---|
1146 | struct s_cpmap *ptr_cpmap;
|
---|
1147 | static struct s_cpmap *cpmap=(struct s_cpmap *)0;
|
---|
1148 |
|
---|
1149 | if( strlen(token)<4 ) continue;
|
---|
1150 |
|
---|
1151 | caid=sid=chid=dwtime=0;
|
---|
1152 | provid=0;
|
---|
1153 | skip=0;
|
---|
1154 | ptr1=0;
|
---|
1155 | for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
|
---|
1156 | {
|
---|
1157 | trim(ptr);
|
---|
1158 | if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
|
---|
1159 | skip=1;
|
---|
1160 | break;
|
---|
1161 | }
|
---|
1162 | switch( i )
|
---|
1163 | {
|
---|
1164 | case 0:
|
---|
1165 | ptr1=ptr;
|
---|
1166 | break;
|
---|
1167 | case 1:
|
---|
1168 | dwtime = atoi(ptr);
|
---|
1169 | break;
|
---|
1170 | }
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | if( !skip )
|
---|
1174 | {
|
---|
1175 | for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
|
---|
1176 | {
|
---|
1177 | trim(ptr);
|
---|
1178 | switch( i )
|
---|
1179 | {
|
---|
1180 | case 0:
|
---|
1181 | if( *ptr=='*' ) caid = 0;
|
---|
1182 | else caid = a2i(ptr, 4);
|
---|
1183 | break;
|
---|
1184 | case 1:
|
---|
1185 | if( *ptr=='*' ) provid = 0;
|
---|
1186 | else provid = a2i(ptr, 6);
|
---|
1187 | break;
|
---|
1188 | case 2:
|
---|
1189 | if( *ptr=='*' ) sid = 0;
|
---|
1190 | else sid = a2i(ptr, 4);
|
---|
1191 | break;
|
---|
1192 | case 3:
|
---|
1193 | if( *ptr=='*' ) chid = 0;
|
---|
1194 | else chid = a2i(ptr, 4);
|
---|
1195 | break;
|
---|
1196 | }
|
---|
1197 | }
|
---|
1198 | if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
|
---|
1199 | {
|
---|
1200 | cs_log("Error allocating memory (errno=%d)", errno);
|
---|
1201 | return;
|
---|
1202 | }
|
---|
1203 | if( cpmap )
|
---|
1204 | cpmap->next=ptr_cpmap;
|
---|
1205 | else
|
---|
1206 | cfg->cpmap=ptr_cpmap;
|
---|
1207 | cpmap=ptr_cpmap;
|
---|
1208 |
|
---|
1209 | cpmap->caid = caid;
|
---|
1210 | cpmap->provid = provid;
|
---|
1211 | cpmap->sid = sid;
|
---|
1212 | cpmap->chid = chid;
|
---|
1213 | cpmap->dwtime = dwtime;
|
---|
1214 | cpmap->next = 0;
|
---|
1215 |
|
---|
1216 | cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
|
---|
1217 | nr, caid, provid, sid, chid, dwtime);
|
---|
1218 | nr++;
|
---|
1219 | }
|
---|
1220 | }
|
---|
1221 | fclose(fp);
|
---|
1222 | //cs_log("%d lengths for caid guessing loaded", nr);
|
---|
1223 | return;
|
---|
1224 | }
|
---|
1225 | #endif
|
---|