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