1 | #include "globals.h"
|
---|
2 | #include "module-anticasc.h"
|
---|
3 | #include "oscam-client.h"
|
---|
4 | #include "oscam-conf.h"
|
---|
5 | #include "oscam-conf-chk.h"
|
---|
6 | #include "oscam-conf-mk.h"
|
---|
7 | #include "oscam-config.h"
|
---|
8 | #include "oscam-garbage.h"
|
---|
9 | #include "oscam-lock.h"
|
---|
10 | #include "oscam-string.h"
|
---|
11 |
|
---|
12 | #define cs_user "oscam.user"
|
---|
13 |
|
---|
14 | static void account_tosleep_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
15 | {
|
---|
16 | int32_t *tosleep = setting;
|
---|
17 | if(value)
|
---|
18 | {
|
---|
19 | *tosleep = strToIntVal(value, cfg.tosleep);
|
---|
20 | return;
|
---|
21 | }
|
---|
22 | if(*tosleep != cfg.tosleep || cfg.http_full_cfg)
|
---|
23 | { fprintf_conf(f, token, "%d\n", *tosleep); }
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | static void account_c35_suppresscmd08_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
30 | {
|
---|
31 | int8_t *c35_suppresscmd08 = setting;
|
---|
32 | if(value)
|
---|
33 | {
|
---|
34 | *c35_suppresscmd08 = (int8_t)strToIntVal(value, cfg.c35_suppresscmd08);
|
---|
35 | return;
|
---|
36 | }
|
---|
37 | if(*c35_suppresscmd08 != cfg.c35_suppresscmd08 || cfg.http_full_cfg)
|
---|
38 | { fprintf_conf(f, token, "%d\n", *c35_suppresscmd08); }
|
---|
39 | }
|
---|
40 |
|
---|
41 | static void account_umaxidle_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
42 | {
|
---|
43 | uint32_t *umaxidle = setting;
|
---|
44 | if(value)
|
---|
45 | {
|
---|
46 | *umaxidle = (uint32_t)strToIntVal(value, cfg.umaxidle);
|
---|
47 | return;
|
---|
48 | }
|
---|
49 | if(*umaxidle != cfg.umaxidle || cfg.http_full_cfg)
|
---|
50 | { fprintf_conf(f, token, "%u\n", *umaxidle); }
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 | static void account_ncd_keepalive_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
57 | {
|
---|
58 | int8_t *ncd_keepalive = setting;
|
---|
59 | int8_t def_value = 0;
|
---|
60 | #ifdef MODULE_NEWCAMD
|
---|
61 | def_value = cfg.ncd_keepalive;
|
---|
62 | #endif
|
---|
63 | if(value)
|
---|
64 | {
|
---|
65 | *ncd_keepalive = (int8_t)strToIntVal(value, def_value);
|
---|
66 | return;
|
---|
67 | }
|
---|
68 | if(*ncd_keepalive != def_value || cfg.http_full_cfg)
|
---|
69 | { fprintf_conf(f, token, "%d\n", *ncd_keepalive); }
|
---|
70 | }
|
---|
71 |
|
---|
72 | static void account_allowedprotocols_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
73 | {
|
---|
74 | struct s_auth *account = setting;
|
---|
75 | if(value)
|
---|
76 | {
|
---|
77 | account->allowedprotocols = 0;
|
---|
78 | if(strlen(value) > 3)
|
---|
79 | {
|
---|
80 | int i;
|
---|
81 | char *ptr, *saveptr1 = NULL;
|
---|
82 | for(i = 0, ptr = strtok_r(value, ",", &saveptr1); ptr; ptr = strtok_r(NULL, ",", &saveptr1), i++)
|
---|
83 | {
|
---|
84 | if(streq(ptr, "camd33")) { account->allowedprotocols |= LIS_CAMD33TCP; }
|
---|
85 | else if(streq(ptr, "camd35")) { account->allowedprotocols |= LIS_CAMD35UDP; }
|
---|
86 | else if(streq(ptr, "cs357x")) { account->allowedprotocols |= LIS_CAMD35UDP; }
|
---|
87 | else if(streq(ptr, "cs378x")) { account->allowedprotocols |= LIS_CAMD35TCP; }
|
---|
88 | else if(streq(ptr, "newcamd")) { account->allowedprotocols |= LIS_NEWCAMD; }
|
---|
89 | else if(streq(ptr, "cccam")) { account->allowedprotocols |= LIS_CCCAM; }
|
---|
90 | else if(streq(ptr, "csp")) { account->allowedprotocols |= LIS_CSPUDP; }
|
---|
91 | else if(streq(ptr, "gbox")) { account->allowedprotocols |= LIS_GBOX; }
|
---|
92 | else if(streq(ptr, "radegast")) { account->allowedprotocols |= LIS_RADEGAST; }
|
---|
93 | // these have no listener ports so it doesn't make sense
|
---|
94 | else if(streq(ptr, "dvbapi")) { account->allowedprotocols |= LIS_DVBAPI; }
|
---|
95 | else if(streq(ptr, "constcw")) { account->allowedprotocols |= LIS_CONSTCW; }
|
---|
96 | else if(streq(ptr, "serial")) { account->allowedprotocols |= LIS_SERIAL; }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | return;
|
---|
100 | }
|
---|
101 | if(account->allowedprotocols || cfg.http_full_cfg)
|
---|
102 | {
|
---|
103 | value = mk_t_allowedprotocols(account);
|
---|
104 | fprintf_conf(f, token, "%s\n", value);
|
---|
105 | free_mk_t(value);
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | #ifdef WITH_LB
|
---|
110 | static void caidvaluetab_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
111 | {
|
---|
112 | CAIDVALUETAB *caid_value_table = setting;
|
---|
113 | int limit = streq(token, "lb_retrylimits") ? 50 : 1;
|
---|
114 | if(value)
|
---|
115 | {
|
---|
116 | chk_caidvaluetab(value, caid_value_table, limit);
|
---|
117 | return;
|
---|
118 | }
|
---|
119 | if(caid_value_table->n > 0 || cfg.http_full_cfg)
|
---|
120 | {
|
---|
121 | value = mk_t_caidvaluetab(caid_value_table);
|
---|
122 | fprintf_conf(f, token, "%s\n", value);
|
---|
123 | free_mk_t(value);
|
---|
124 | }
|
---|
125 | }
|
---|
126 | #endif
|
---|
127 |
|
---|
128 |
|
---|
129 | static void account_au_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
130 | {
|
---|
131 | struct s_auth *account = setting;
|
---|
132 | if(value)
|
---|
133 | {
|
---|
134 | // set default values for usage during runtime from Webif
|
---|
135 | account->autoau = 0;
|
---|
136 | if(!account->aureader_list)
|
---|
137 | { account->aureader_list = ll_create("aureader_list"); }
|
---|
138 | if(streq(value, "1"))
|
---|
139 | { account->autoau = 1; }
|
---|
140 | ll_clear(account->aureader_list);
|
---|
141 | LL_ITER itr = ll_iter_create(configured_readers);
|
---|
142 | struct s_reader *rdr;
|
---|
143 | char *pch, *saveptr1 = NULL;
|
---|
144 | for(pch = strtok_r(value, ",", &saveptr1); pch != NULL; pch = strtok_r(NULL, ",", &saveptr1))
|
---|
145 | {
|
---|
146 | ll_iter_reset(&itr);
|
---|
147 | while((rdr = ll_iter_next(&itr)))
|
---|
148 | {
|
---|
149 | if(streq(rdr->label, pch) || account->autoau)
|
---|
150 | {
|
---|
151 | ll_append(account->aureader_list, rdr);
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 | return;
|
---|
156 | }
|
---|
157 | if(account->autoau == 1)
|
---|
158 | {
|
---|
159 | fprintf_conf(f, token, "%d\n", account->autoau);
|
---|
160 | }
|
---|
161 | else if(account->aureader_list)
|
---|
162 | {
|
---|
163 | value = mk_t_aureader(account);
|
---|
164 | if(strlen(value) > 0)
|
---|
165 | { fprintf_conf(f, token, "%s\n", value); }
|
---|
166 | free_mk_t(value);
|
---|
167 | }
|
---|
168 | else if(cfg.http_full_cfg)
|
---|
169 | {
|
---|
170 | fprintf_conf(f, token, "%s\n", "");
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | static void account_expdate_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
175 | {
|
---|
176 | struct s_auth *account = setting;
|
---|
177 | if(value)
|
---|
178 | {
|
---|
179 | if(!value[0])
|
---|
180 | {
|
---|
181 | account->expirationdate = (time_t)NULL;
|
---|
182 | return;
|
---|
183 | }
|
---|
184 | int i;
|
---|
185 | struct tm cstime;
|
---|
186 | char *ptr1, *saveptr1 = NULL;
|
---|
187 | memset(&cstime, 0, sizeof(cstime));
|
---|
188 | for(i = 0, ptr1 = strtok_r(value, "-/", &saveptr1); i < 3 && ptr1; ptr1 = strtok_r(NULL, "-/", &saveptr1), i++)
|
---|
189 | {
|
---|
190 | switch(i)
|
---|
191 | {
|
---|
192 | case 0:
|
---|
193 | cstime.tm_year = atoi(ptr1) - 1900;
|
---|
194 | break;
|
---|
195 | case 1:
|
---|
196 | cstime.tm_mon = atoi(ptr1) - 1;
|
---|
197 | break;
|
---|
198 | case 2:
|
---|
199 | cstime.tm_mday = atoi(ptr1);
|
---|
200 | break;
|
---|
201 | }
|
---|
202 | }
|
---|
203 | cstime.tm_hour = 23;
|
---|
204 | cstime.tm_min = 59;
|
---|
205 | cstime.tm_sec = 59;
|
---|
206 | cstime.tm_isdst = -1;
|
---|
207 | account->expirationdate = mktime(&cstime);
|
---|
208 | return;
|
---|
209 | }
|
---|
210 | if(account->expirationdate || cfg.http_full_cfg)
|
---|
211 | {
|
---|
212 | char buf[16];
|
---|
213 | struct tm timeinfo;
|
---|
214 | localtime_r(&account->expirationdate, &timeinfo);
|
---|
215 | strftime(buf, 16, "%Y-%m-%d", &timeinfo);
|
---|
216 | fprintf_conf(f, token, "%s\n", streq(buf, "1970-01-01") ? "" : buf);
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | static void account_allowedtimeframe_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
221 | {
|
---|
222 | struct s_auth *account = setting;
|
---|
223 | if(value)
|
---|
224 | {
|
---|
225 | account->allowedtimeframe[0] = 0;
|
---|
226 | account->allowedtimeframe[1] = 0;
|
---|
227 | if(strlen(value))
|
---|
228 | {
|
---|
229 | int32_t allowed[4];
|
---|
230 | if(sscanf(value, "%2d:%2d-%2d:%2d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) == 4)
|
---|
231 | {
|
---|
232 | account->allowedtimeframe[0] = allowed[0] * 60 + allowed[1];
|
---|
233 | account->allowedtimeframe[1] = allowed[2] * 60 + allowed[3];
|
---|
234 | }
|
---|
235 | else
|
---|
236 | {
|
---|
237 | fprintf(stderr, "WARNING: Value '%s' is not valid for allowedtimeframe (hh:mm-hh:mm)\n", value);
|
---|
238 | }
|
---|
239 | }
|
---|
240 | return;
|
---|
241 | }
|
---|
242 | if(account->allowedtimeframe[0] && account->allowedtimeframe[1])
|
---|
243 | {
|
---|
244 | fprintf_conf(f, token, "%02d:%02d-%02d:%02d\n",
|
---|
245 | account->allowedtimeframe[0] / 60, account->allowedtimeframe[0] % 60,
|
---|
246 | account->allowedtimeframe[1] / 60, account->allowedtimeframe[1] % 60);
|
---|
247 | }
|
---|
248 | else if(cfg.http_full_cfg)
|
---|
249 | {
|
---|
250 | fprintf_conf(f, token, "%s\n", "");
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | static void account_tuntab_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
255 | {
|
---|
256 | TUNTAB *ttab = setting;
|
---|
257 | if(value)
|
---|
258 | {
|
---|
259 | if(strlen(value) == 0)
|
---|
260 | {
|
---|
261 | clear_tuntab(ttab);
|
---|
262 | }
|
---|
263 | else
|
---|
264 | {
|
---|
265 | chk_tuntab(value, ttab);
|
---|
266 | }
|
---|
267 | return;
|
---|
268 | }
|
---|
269 | if(ttab->bt_caidfrom[0] || cfg.http_full_cfg)
|
---|
270 | {
|
---|
271 | value = mk_t_tuntab(ttab);
|
---|
272 | fprintf_conf(f, token, "%s\n", value);
|
---|
273 | free_mk_t(value);
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 | void group_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
278 | {
|
---|
279 | uint64_t *grp = setting;
|
---|
280 | if(value)
|
---|
281 | {
|
---|
282 | char *ptr1, *saveptr1 = NULL;
|
---|
283 | *grp = 0;
|
---|
284 | for(ptr1 = strtok_r(value, ",", &saveptr1); ptr1; ptr1 = strtok_r(NULL, ",", &saveptr1))
|
---|
285 | {
|
---|
286 | int32_t g;
|
---|
287 | g = atoi(ptr1);
|
---|
288 | if(g > 0 && g < 65)
|
---|
289 | { *grp |= (((uint64_t)1) << (g - 1)); }
|
---|
290 | }
|
---|
291 | return;
|
---|
292 | }
|
---|
293 | if(*grp || cfg.http_full_cfg)
|
---|
294 | {
|
---|
295 | value = mk_t_group(*grp);
|
---|
296 | fprintf_conf(f, token, "%s\n", value);
|
---|
297 | free_mk_t(value);
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 | void services_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
302 | {
|
---|
303 | SIDTABS *sidtabs = setting;
|
---|
304 | if(value)
|
---|
305 | {
|
---|
306 | strtolower(value);
|
---|
307 | chk_services(value, sidtabs);
|
---|
308 | return;
|
---|
309 | }
|
---|
310 | value = mk_t_service(sidtabs);
|
---|
311 | if(strlen(value) > 0 || cfg.http_full_cfg)
|
---|
312 | { fprintf_conf(f, token, "%s\n", value); }
|
---|
313 | free_mk_t(value);
|
---|
314 | }
|
---|
315 |
|
---|
316 | void class_fn(const char *token, char *value, void *setting, FILE *f)
|
---|
317 | {
|
---|
318 | CLASSTAB *cltab = setting;
|
---|
319 | if(value)
|
---|
320 | {
|
---|
321 | strtolower(value);
|
---|
322 | chk_cltab(value, cltab);
|
---|
323 | return;
|
---|
324 | }
|
---|
325 | value = mk_t_cltab(cltab);
|
---|
326 | if(strlen(value) > 0 || cfg.http_full_cfg)
|
---|
327 | {
|
---|
328 | fprintf_conf(f, token, "%s\n", value);
|
---|
329 | free_mk_t(value);
|
---|
330 | }
|
---|
331 | }
|
---|
332 |
|
---|
333 | #ifdef CS_ANTICASC
|
---|
334 | static void account_fixups_fn(void *var)
|
---|
335 | {
|
---|
336 | struct s_auth *account = var;
|
---|
337 | if(account->ac_users < -1) { account->ac_users = DEFAULT_AC_USERS; }
|
---|
338 | if(account->ac_penalty < -1) { account->ac_penalty = DEFAULT_AC_PENALTY; }
|
---|
339 | }
|
---|
340 | #endif
|
---|
341 |
|
---|
342 | #define OFS(X) offsetof(struct s_auth, X)
|
---|
343 | #define SIZEOF(X) sizeof(((struct s_auth *)0)->X)
|
---|
344 |
|
---|
345 | static const struct config_list account_opts[] =
|
---|
346 | {
|
---|
347 | #ifdef CS_ANTICASC
|
---|
348 | DEF_OPT_FIXUP_FUNC(account_fixups_fn),
|
---|
349 | #endif
|
---|
350 | DEF_OPT_INT8("disabled" , OFS(disabled), 0),
|
---|
351 | DEF_OPT_SSTR("user" , OFS(usr), "", SIZEOF(usr)),
|
---|
352 | DEF_OPT_STR("pwd" , OFS(pwd), NULL),
|
---|
353 | #ifdef WEBIF
|
---|
354 | DEF_OPT_STR("description" , OFS(description), NULL),
|
---|
355 | #endif
|
---|
356 | DEF_OPT_STR("hostname" , OFS(dyndns), NULL),
|
---|
357 | DEF_OPT_FUNC("caid" , OFS(ctab), check_caidtab_fn),
|
---|
358 | DEF_OPT_INT8("uniq" , OFS(uniq), 0),
|
---|
359 | DEF_OPT_UINT8("sleepsend" , OFS(c35_sleepsend), 0),
|
---|
360 | DEF_OPT_INT32("failban" , OFS(failban), 0),
|
---|
361 | DEF_OPT_INT8("monlevel" , OFS(monlvl), 0),
|
---|
362 | DEF_OPT_FUNC("sleep" , OFS(tosleep), account_tosleep_fn),
|
---|
363 | DEF_OPT_FUNC("suppresscmd08" , OFS(c35_suppresscmd08), account_c35_suppresscmd08_fn),
|
---|
364 | DEF_OPT_FUNC("umaxidle" , OFS(umaxidle), account_umaxidle_fn),
|
---|
365 | DEF_OPT_FUNC("keepalive" , OFS(ncd_keepalive), account_ncd_keepalive_fn),
|
---|
366 | DEF_OPT_FUNC("au" , 0, account_au_fn),
|
---|
367 | DEF_OPT_UINT8("emmreassembly" , OFS(emm_reassembly), 2),
|
---|
368 | DEF_OPT_FUNC("expdate" , 0, account_expdate_fn),
|
---|
369 | DEF_OPT_FUNC("allowedprotocols" , 0, account_allowedprotocols_fn),
|
---|
370 | DEF_OPT_FUNC("allowedtimeframe" , 0, account_allowedtimeframe_fn),
|
---|
371 | DEF_OPT_FUNC("betatunnel" , OFS(ttab), account_tuntab_fn),
|
---|
372 | DEF_OPT_FUNC("group" , OFS(grp), group_fn),
|
---|
373 | DEF_OPT_FUNC("services" , OFS(sidtabs), services_fn),
|
---|
374 | DEF_OPT_FUNC_X("ident" , OFS(ftab), ftab_fn, FTAB_ACCOUNT | FTAB_PROVID),
|
---|
375 | DEF_OPT_FUNC_X("chid" , OFS(fchid), ftab_fn, FTAB_ACCOUNT | FTAB_CHID),
|
---|
376 | DEF_OPT_FUNC("class" , OFS(cltab), class_fn),
|
---|
377 | #ifdef CS_CACHEEX
|
---|
378 | DEF_OPT_INT8("cacheex" , OFS(cacheex.mode), 0),
|
---|
379 | DEF_OPT_INT8("cacheex_maxhop" , OFS(cacheex.maxhop), 0),
|
---|
380 | DEF_OPT_FUNC("cacheex_ecm_filter" , OFS(cacheex.filter_caidtab), cacheex_hitvaluetab_fn),
|
---|
381 | DEF_OPT_UINT8("cacheex_drop_csp" , OFS(cacheex.drop_csp), 0),
|
---|
382 | DEF_OPT_UINT8("cacheex_allow_request" , OFS(cacheex.allow_request), 0),
|
---|
383 | DEF_OPT_INT8("no_wait_time" , OFS(no_wait_time), 0),
|
---|
384 | #endif
|
---|
385 | #ifdef MODULE_CCCAM
|
---|
386 | DEF_OPT_INT32("cccmaxhops" , OFS(cccmaxhops), DEFAULT_CC_MAXHOPS),
|
---|
387 | DEF_OPT_INT8("cccreshare" , OFS(cccreshare), DEFAULT_CC_RESHARE),
|
---|
388 | DEF_OPT_INT8("cccignorereshare" , OFS(cccignorereshare), DEFAULT_CC_IGNRSHR),
|
---|
389 | DEF_OPT_INT8("cccstealth" , OFS(cccstealth), DEFAULT_CC_STEALTH),
|
---|
390 | #endif
|
---|
391 | #ifdef CS_ANTICASC
|
---|
392 | DEF_OPT_INT32("fakedelay" , OFS(ac_fakedelay), -1),
|
---|
393 | DEF_OPT_INT32("numusers" , OFS(ac_users), DEFAULT_AC_USERS),
|
---|
394 | DEF_OPT_INT8("penalty" , OFS(ac_penalty), DEFAULT_AC_PENALTY),
|
---|
395 | #endif
|
---|
396 | #ifdef WITH_LB
|
---|
397 | DEF_OPT_INT32("lb_nbest_readers" , OFS(lb_nbest_readers), -1),
|
---|
398 | DEF_OPT_INT32("lb_nfb_readers" , OFS(lb_nfb_readers), -1),
|
---|
399 | DEF_OPT_FUNC("lb_nbest_percaid" , OFS(lb_nbest_readers_tab), caidvaluetab_fn),
|
---|
400 | #endif
|
---|
401 | DEF_LAST_OPT
|
---|
402 | };
|
---|
403 |
|
---|
404 | void chk_account(const char *token, char *value, struct s_auth *account)
|
---|
405 | {
|
---|
406 | if(config_list_parse(account_opts, token, value, account))
|
---|
407 | { return; }
|
---|
408 | else if(token[0] != '#')
|
---|
409 | { fprintf(stderr, "Warning: keyword '%s' in account section not recognized\n", token); }
|
---|
410 | }
|
---|
411 |
|
---|
412 | void account_set_defaults(struct s_auth *account)
|
---|
413 | {
|
---|
414 | config_list_set_defaults(account_opts, account);
|
---|
415 | }
|
---|
416 |
|
---|
417 | struct s_auth *init_userdb(void)
|
---|
418 | {
|
---|
419 | FILE *fp = open_config_file(cs_user);
|
---|
420 | if(!fp)
|
---|
421 | { return NULL; }
|
---|
422 |
|
---|
423 | struct s_auth *authptr = NULL;
|
---|
424 | int32_t tag = 0, nr = 0, expired = 0, disabled = 0;
|
---|
425 | char *token;
|
---|
426 | struct s_auth *account = NULL;
|
---|
427 | struct s_auth *probe = NULL;
|
---|
428 | if(!cs_malloc(&token, MAXLINESIZE))
|
---|
429 | { return NULL; }
|
---|
430 |
|
---|
431 | while(fgets(token, MAXLINESIZE, fp))
|
---|
432 | {
|
---|
433 | int32_t l;
|
---|
434 | void *ptr;
|
---|
435 |
|
---|
436 | if((l = strlen(trim(token))) < 3)
|
---|
437 | { continue; }
|
---|
438 | if(token[0] == '[' && token[l - 1] == ']')
|
---|
439 | {
|
---|
440 | token[l - 1] = 0;
|
---|
441 | tag = streq("account", strtolower(token + 1));
|
---|
442 | if(!cs_malloc(&ptr, sizeof(struct s_auth)))
|
---|
443 | { break; }
|
---|
444 | if(account)
|
---|
445 | { account->next = ptr; }
|
---|
446 | else
|
---|
447 | { authptr = ptr; }
|
---|
448 |
|
---|
449 | account = ptr;
|
---|
450 | account_set_defaults(account);
|
---|
451 | nr++;
|
---|
452 |
|
---|
453 | continue;
|
---|
454 | }
|
---|
455 |
|
---|
456 | if(!tag)
|
---|
457 | { continue; }
|
---|
458 | char *value = strchr(token, '=');
|
---|
459 | if(!value)
|
---|
460 | { continue; }
|
---|
461 |
|
---|
462 | *value++ = '\0';
|
---|
463 |
|
---|
464 | // check for duplicate useraccounts and make the name unique
|
---|
465 | if(streq(trim(strtolower(token)), "user"))
|
---|
466 | {
|
---|
467 | for(probe = authptr; probe; probe = probe->next)
|
---|
468 | {
|
---|
469 | if(!strcmp(probe->usr, trim(value)))
|
---|
470 | {
|
---|
471 | fprintf(stderr, "Warning: duplicate account '%s'\n", value);
|
---|
472 | strncat(value, "_x", sizeof(probe->usr) - strlen(value) - 1);
|
---|
473 | }
|
---|
474 | }
|
---|
475 | }
|
---|
476 | chk_account(trim(strtolower(token)), trim(value), account);
|
---|
477 | }
|
---|
478 | NULLFREE(token);
|
---|
479 | fclose(fp);
|
---|
480 |
|
---|
481 | for(account = authptr; account; account = account->next)
|
---|
482 | {
|
---|
483 | if(account->expirationdate && account->expirationdate < time(NULL))
|
---|
484 | { ++expired; }
|
---|
485 | if(account->disabled)
|
---|
486 | { ++disabled; }
|
---|
487 | }
|
---|
488 | cs_log("userdb reloaded: %d accounts loaded, %d expired, %d disabled", nr, expired, disabled);
|
---|
489 | return authptr;
|
---|
490 | }
|
---|
491 |
|
---|
492 | int32_t init_free_userdb(struct s_auth *ptr)
|
---|
493 | {
|
---|
494 | int32_t nro;
|
---|
495 | for(nro = 0; ptr; nro++)
|
---|
496 | {
|
---|
497 | struct s_auth *ptr_next;
|
---|
498 | ptr_next = ptr->next;
|
---|
499 | ll_destroy(ptr->aureader_list);
|
---|
500 | ptr->next = NULL;
|
---|
501 | config_list_gc_values(account_opts, ptr);
|
---|
502 | add_garbage(ptr);
|
---|
503 | ptr = ptr_next;
|
---|
504 | }
|
---|
505 | cs_log("userdb %d accounts freed", nro);
|
---|
506 | return nro;
|
---|
507 | }
|
---|
508 |
|
---|
509 | int32_t write_userdb(void)
|
---|
510 | {
|
---|
511 | struct s_auth *account;
|
---|
512 | FILE *f = create_config_file(cs_user);
|
---|
513 | if(!f)
|
---|
514 | { return 1; }
|
---|
515 | for(account = cfg.account; account; account = account->next)
|
---|
516 | {
|
---|
517 | fprintf(f, "[account]\n");
|
---|
518 | config_list_apply_fixups(account_opts, account);
|
---|
519 | config_list_save(f, account_opts, account, cfg.http_full_cfg);
|
---|
520 | fprintf(f, "\n");
|
---|
521 | }
|
---|
522 | return flush_config_file(f, cs_user);
|
---|
523 | }
|
---|
524 |
|
---|
525 | void cs_accounts_chk(void)
|
---|
526 | {
|
---|
527 | struct s_auth *account1, *account2;
|
---|
528 | struct s_auth *new_accounts = init_userdb();
|
---|
529 | cs_writelock(&config_lock);
|
---|
530 | struct s_auth *old_accounts = cfg.account;
|
---|
531 | for(account1 = cfg.account; account1; account1 = account1->next)
|
---|
532 | {
|
---|
533 | for(account2 = new_accounts; account2; account2 = account2->next)
|
---|
534 | {
|
---|
535 | if(!strcmp(account1->usr, account2->usr))
|
---|
536 | {
|
---|
537 | account2->cwfound = account1->cwfound;
|
---|
538 | account2->cwcache = account1->cwcache;
|
---|
539 | account2->cwnot = account1->cwnot;
|
---|
540 | account2->cwtun = account1->cwtun;
|
---|
541 | account2->cwignored = account1->cwignored;
|
---|
542 | account2->cwtout = account1->cwtout;
|
---|
543 | account2->emmok = account1->emmok;
|
---|
544 | account2->emmnok = account1->emmnok;
|
---|
545 | account2->firstlogin = account1->firstlogin;
|
---|
546 | ac_copy_vars(account1, account2);
|
---|
547 | }
|
---|
548 | }
|
---|
549 | }
|
---|
550 | cs_reinit_clients(new_accounts);
|
---|
551 | cfg.account = new_accounts;
|
---|
552 | init_free_userdb(old_accounts);
|
---|
553 | ac_clear();
|
---|
554 | cs_writeunlock(&config_lock);
|
---|
555 | }
|
---|