373 |
return ret; |
return ret; |
374 |
} |
} |
375 |
|
|
376 |
int |
static int |
377 |
check_acct_dir() |
check_acct_dir() |
378 |
{ |
{ |
379 |
struct stat st; |
struct stat st; |
380 |
|
|
381 |
if (stat(radacct_dir, &st) == 0) { |
if (stat(radacct_dir, &st) == 0) { |
382 |
if (S_ISDIR(st.st_mode)) |
if (S_ISDIR(st.st_mode)) { |
383 |
|
if (access(radacct_dir, W_OK)) { |
384 |
|
radlog(L_ERR, |
385 |
|
_("%s: directory not writable"), |
386 |
|
radacct_dir); |
387 |
|
return 1; |
388 |
|
} |
389 |
return 0; |
return 0; |
390 |
else { |
} else { |
391 |
radlog(L_ERR, |
radlog(L_ERR, _("%s: not a directory"), |
392 |
_("%s: not a directory"), |
radacct_dir); |
|
radacct_dir); |
|
393 |
return 1; |
return 1; |
394 |
} |
} |
395 |
} |
} |
396 |
if (mkdir(radacct_dir, 0755)) { |
if (mkdir(radacct_dir, 0755)) { |
397 |
radlog(L_CRIT|L_PERROR, |
radlog(L_ERR|L_PERROR, |
398 |
_("can't create accounting directory `%s'"), |
_("can't create accounting directory `%s'"), |
399 |
radacct_dir); |
radacct_dir); |
400 |
return 1; |
return 1; |
402 |
return 0; |
return 0; |
403 |
} |
} |
404 |
|
|
405 |
|
static int acct_dir_status; |
406 |
|
|
407 |
|
static void |
408 |
|
acct_after_config_hook(void *arg ARG_UNUSED, void *data ARG_UNUSED) |
409 |
|
{ |
410 |
|
if (auth_detail || acct_detail) { |
411 |
|
acct_dir_status = check_acct_dir(); |
412 |
|
if (acct_dir_status) { |
413 |
|
radlog(L_NOTICE, |
414 |
|
_("Detailed accounting is disabled")); |
415 |
|
auth_detail = acct_detail = 0; |
416 |
|
} |
417 |
|
} |
418 |
|
} |
419 |
|
|
420 |
|
void |
421 |
|
acct_init() |
422 |
|
{ |
423 |
|
radiusd_set_postconfig_hook(acct_after_config_hook, NULL, 0); |
424 |
|
} |
425 |
|
|
426 |
int |
int |
427 |
write_detail(RADIUS_REQ *radreq, int authtype, char *f) |
write_detail(RADIUS_REQ *radreq, int authtype, char *f) |
428 |
{ |
{ |
429 |
FILE *outfd; |
FILE *outfd; |
430 |
char nasname[MAX_LONGNAME]; |
char nasname[MAX_LONGNAME]; |
431 |
char *dir, *path; |
char *dir, *path; |
432 |
char *save; |
char *save; |
433 |
VALUE_PAIR *pair; |
VALUE_PAIR *pair; |
434 |
UINT4 nas; |
UINT4 nas; |
435 |
NAS *cl; |
NAS *cl; |
436 |
time_t curtime; |
time_t curtime; |
437 |
int ret = 0; |
int ret = 0; |
438 |
struct stat st; |
|
439 |
|
if (acct_dir_status) |
440 |
/* A superfluous precaution, maybe: */ |
return; |
441 |
if (stat(radacct_dir, &st) < 0) |
|
|
return 0; |
|
442 |
curtime = time(0); |
curtime = time(0); |
443 |
|
|
444 |
/* Find out the name of this terminal server. We try to find |
/* Find out the name of this terminal server. We try to find |