1 |
/* This file is part of GNU RADIUS. |
/* This file is part of GNU Radius. |
2 |
Copyright (C) 2000,2001, Sergey Poznyakoff |
Copyright (C) 2000,2001,2002,2003 Sergey Poznyakoff |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Radius is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
7 |
(at your option) any later version. |
(at your option) any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Radius is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
GNU General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software Foundation, |
along with GNU Radius; if not, write to the Free Software Foundation, |
16 |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
18 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
29 |
#include <radiusd.h> |
#include <radiusd.h> |
30 |
#include <slist.h> |
#include <slist.h> |
31 |
|
|
32 |
static pthread_once_t log_once = PTHREAD_ONCE_INIT; |
static int logging_category = L_CAT(L_MAIN); |
|
static pthread_key_t log_key; |
|
33 |
static Channel *chanlist; /* List of defined channels */ |
static Channel *chanlist; /* List of defined channels */ |
34 |
|
|
35 |
static void log_to_channel(Channel *chan, int cat, int pri, |
static void log_to_channel(Channel *chan, int cat, int pri, |
41 |
|
|
42 |
#define SP(p) ((p)?(p):"") |
#define SP(p) ((p)?(p):"") |
43 |
|
|
|
static void |
|
|
log_init_specific() |
|
|
{ |
|
|
pthread_key_create(&log_key, NULL); |
|
|
} |
|
|
|
|
44 |
static int |
static int |
45 |
log_get_category() |
log_get_category() |
46 |
{ |
{ |
47 |
void *p; |
return logging_category; |
|
pthread_once(&log_once, log_init_specific); |
|
|
p = pthread_getspecific(log_key); |
|
|
return p ? (int) p : L_CAT(L_MAIN); |
|
48 |
} |
} |
49 |
|
|
50 |
static void |
static void |
51 |
log_set_category(cat) |
log_set_category(int cat) |
|
int cat; |
|
52 |
{ |
{ |
53 |
pthread_once(&log_once, log_init_specific); |
logging_category = L_CAT(cat); |
|
pthread_setspecific(log_key, (const void*) L_CAT(cat)); |
|
54 |
} |
} |
55 |
|
|
56 |
void |
void |
57 |
log_open(cat) |
log_open(int cat) |
|
int cat; |
|
58 |
{ |
{ |
59 |
log_set_category(cat); |
log_set_category(cat); |
60 |
} |
} |
66 |
} |
} |
67 |
|
|
68 |
void |
void |
69 |
vlog(level, file, line, func_name, en, fmt, ap) |
vlog(int level, char *file, int line, char *func_name, |
70 |
int level; |
int en, char *fmt, va_list ap) |
|
char *file; |
|
|
int line; |
|
|
char *func_name; |
|
|
int en; |
|
|
char *fmt; |
|
|
va_list ap; |
|
71 |
{ |
{ |
72 |
Channel *chan; |
Channel *chan; |
73 |
int cat, pri; |
int cat, pri; |
122 |
}; |
}; |
123 |
|
|
124 |
void |
void |
125 |
log_to_channel(chan, cat, pri, buf1, buf2, buf3) |
log_to_channel(Channel *chan, int cat, int pri, |
126 |
Channel *chan; |
char *buf1, char *buf2, char *buf3) |
|
int cat, pri; |
|
|
char *buf1, *buf2, *buf3; |
|
127 |
{ |
{ |
128 |
char *cat_pref = NULL; |
char *cat_pref = NULL; |
129 |
char *prefix = NULL; |
char *prefix = NULL; |
173 |
fprintf(fp, "%s ", buffer); |
fprintf(fp, "%s ", buffer); |
174 |
if (chan->options & LO_PID) |
if (chan->options & LO_PID) |
175 |
fprintf(fp, "[%lu]: ", getpid()); |
fprintf(fp, "[%lu]: ", getpid()); |
|
if (chan->options & LO_TID) |
|
|
fprintf(fp, "(%lu): ", (long) pthread_self()); |
|
176 |
if (prefix) |
if (prefix) |
177 |
fprintf(fp, "%s: ", prefix); |
fprintf(fp, "%s: ", prefix); |
178 |
if (buf1) |
if (buf1) |
189 |
spri = chan->id.prio; |
spri = chan->id.prio; |
190 |
if (chan->options & LO_PID) |
if (chan->options & LO_PID) |
191 |
spri |= LOG_PID; |
spri |= LOG_PID; |
|
if (chan->options & LO_TID) |
|
|
snprintf(buffer, sizeof buffer, "(%#lx): ", |
|
|
(long) pthread_self()); |
|
|
else |
|
|
buffer[0] = 0; |
|
192 |
if (prefix) |
if (prefix) |
193 |
syslog(spri, "%s%s: %s%s%s", |
syslog(spri, "%s: %s%s%s", |
194 |
buffer, prefix, SP(buf1), SP(buf2), SP(buf3)); |
prefix, SP(buf1), SP(buf2), SP(buf3)); |
195 |
else |
else |
196 |
syslog(spri, "%s%s%s%s", |
syslog(spri, "%s%s%s", |
197 |
buffer, SP(buf1), SP(buf2), SP(buf3)); |
SP(buf1), SP(buf2), SP(buf3)); |
198 |
break; |
break; |
199 |
} |
} |
200 |
|
|
203 |
} |
} |
204 |
|
|
205 |
FILE * |
FILE * |
206 |
channel_open_file(chan) |
channel_open_file(Channel *chan) |
|
Channel *chan; |
|
207 |
{ |
{ |
208 |
FILE *fp = NULL; |
FILE *fp = NULL; |
209 |
|
|
214 |
|
|
215 |
/*ARGSUSED*/ |
/*ARGSUSED*/ |
216 |
void |
void |
217 |
channel_close_file(chan, fp) |
channel_close_file(Channel *chan, FILE *fp) |
|
Channel *chan; |
|
|
FILE *fp; |
|
218 |
{ |
{ |
219 |
if (fp != stderr) |
if (fp != stderr) |
220 |
fclose(fp); |
fclose(fp); |
225 |
#ifdef USE_SQL |
#ifdef USE_SQL |
226 |
/*PRINTFLIKE2*/ |
/*PRINTFLIKE2*/ |
227 |
void |
void |
228 |
sqllog |
sqllog(int status, char *msg, ...) |
|
#if STDC_HEADERS |
|
|
(int status, char *msg, ...) |
|
|
#else |
|
|
(status, msg, va_alist) |
|
|
int status; |
|
|
char *msg; |
|
|
va_dcl |
|
|
#endif |
|
229 |
{ |
{ |
230 |
va_list ap; |
va_list ap; |
231 |
FILE *fp; |
FILE *fp; |
240 |
return; |
return; |
241 |
} |
} |
242 |
efree(path); |
efree(path); |
|
#if STDC_HEADERS |
|
243 |
va_start(ap, msg); |
va_start(ap, msg); |
|
#else |
|
|
va_start(ap); |
|
|
#endif |
|
244 |
vfprintf(fp, msg, ap); |
vfprintf(fp, msg, ap); |
245 |
fprintf(fp, ";\n"); |
fprintf(fp, ";\n"); |
246 |
va_end(ap); |
va_end(ap); |
251 |
/* Registering functions */ |
/* Registering functions */ |
252 |
|
|
253 |
void |
void |
254 |
channel_free(chan) |
channel_free(Channel *chan) |
|
Channel *chan; |
|
255 |
{ |
{ |
256 |
efree(chan->name); |
efree(chan->name); |
257 |
if (chan->mode == LM_FILE) |
if (chan->mode == LM_FILE) |
260 |
} |
} |
261 |
|
|
262 |
void |
void |
263 |
channel_free_list(chan) |
channel_free_list(Channel *chan) |
|
Channel *chan; |
|
264 |
{ |
{ |
265 |
Channel *next; |
Channel *next; |
266 |
|
|
278 |
} |
} |
279 |
|
|
280 |
void |
void |
281 |
log_release(chan) |
log_release(Channel *chan) |
|
Channel *chan; |
|
282 |
{ |
{ |
283 |
Channel *cp, *prev = NULL; |
Channel *cp, *prev = NULL; |
284 |
int emerg, alert, crit; |
int emerg, alert, crit; |
323 |
} |
} |
324 |
|
|
325 |
Channel * |
Channel * |
326 |
channel_lookup(name) |
channel_lookup(char *name) |
|
char *name; |
|
327 |
{ |
{ |
328 |
Channel *chan; |
Channel *chan; |
329 |
|
|
335 |
} |
} |
336 |
|
|
337 |
void |
void |
338 |
register_channel(chan) |
register_channel(Channel *chan) |
|
Channel *chan; |
|
339 |
{ |
{ |
340 |
FILE *fp; |
FILE *fp; |
341 |
Channel *channel; |
Channel *channel; |
374 |
} |
} |
375 |
|
|
376 |
void |
void |
377 |
register_category(cat, pri, chanlist) |
register_category(int cat, int pri, Chanlist *chanlist) |
|
int cat; |
|
|
int pri; |
|
|
Chanlist *chanlist; |
|
378 |
{ |
{ |
379 |
Channel *chan; |
Channel *chan; |
380 |
|
|
396 |
|
|
397 |
/* channel lists */ |
/* channel lists */ |
398 |
Chanlist * |
Chanlist * |
399 |
make_chanlist(chan) |
make_chanlist(Channel *chan) |
|
Channel *chan; |
|
400 |
{ |
{ |
401 |
Chanlist *cl = mem_alloc(sizeof(*cl)); |
Chanlist *cl = mem_alloc(sizeof(*cl)); |
402 |
cl->next = NULL; |
cl->next = NULL; |
405 |
} |
} |
406 |
|
|
407 |
void |
void |
408 |
free_chanlist(cp) |
free_chanlist(Chanlist *cp) |
|
Chanlist *cp; |
|
409 |
{ |
{ |
410 |
free_slist((struct slist*)cp, NULL); |
free_slist((struct slist*)cp, NULL); |
411 |
} |
} |
429 |
} |
} |
430 |
|
|
431 |
void |
void |
432 |
log_set_default(name, cat, pri) |
log_set_default(char *name, int cat, int pri) |
|
char *name; |
|
|
int cat; |
|
|
int pri; |
|
433 |
{ |
{ |
434 |
Channel chan; |
Channel chan; |
435 |
Chanlist chanlist; |
Chanlist chanlist; |
449 |
|
|
450 |
|
|
451 |
void |
void |
452 |
format_exit_status(buffer, buflen, status) |
format_exit_status(char *buffer, int buflen, int status) |
|
char *buffer; |
|
|
int buflen; |
|
|
int status; |
|
453 |
{ |
{ |
454 |
if (WIFEXITED(status)) { |
if (WIFEXITED(status)) { |
455 |
snprintf(buffer, buflen, |
snprintf(buffer, buflen, |
524 |
}; |
}; |
525 |
|
|
526 |
int |
int |
527 |
logging_stmt_handler(argc, argv, block_data, handler_data) |
logging_stmt_handler(int argc, cfg_value_t *argv, void *block_data, |
528 |
int argc; |
void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
529 |
{ |
{ |
530 |
mark = log_mark(); |
mark = log_mark(); |
531 |
return 0; |
return 0; |
533 |
|
|
534 |
|
|
535 |
int |
int |
536 |
logging_stmt_end(block_data, handler_data) |
logging_stmt_end(void *block_data, void *handler_data) |
|
void *block_data; |
|
|
void *handler_data; |
|
537 |
{ |
{ |
538 |
log_release(mark); |
log_release(mark); |
539 |
return 0; |
return 0; |
540 |
} |
} |
541 |
|
|
542 |
int |
int |
543 |
logging_stmt_begin(finish, block_data, handler_data) |
logging_stmt_begin(int finish, void *block_data, void *handler_data) |
|
int finish; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
544 |
{ |
{ |
545 |
/*FIXME*/ |
/*FIXME*/ |
546 |
return 0; |
return 0; |
547 |
} |
} |
548 |
|
|
549 |
static int |
static int |
550 |
channel_stmt_handler(argc, argv, block_data, handler_data) |
channel_stmt_handler(int argc, cfg_value_t *argv, void *block_data, |
551 |
int argc; |
void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
552 |
{ |
{ |
553 |
if (argc != 2) { |
if (argc != 2) { |
554 |
cfg_argc_error(argc < 2); |
cfg_argc_error(argc < 2); |
566 |
} |
} |
567 |
|
|
568 |
static int |
static int |
569 |
channel_stmt_end(block_data, handler_data) |
channel_stmt_end(void *block_data, void *handler_data) |
|
void *block_data; |
|
|
void *handler_data; |
|
570 |
{ |
{ |
571 |
if (channel.mode == LM_UNKNOWN) { |
if (channel.mode == LM_UNKNOWN) { |
572 |
radlog(L_ERR, |
radlog(L_ERR, |
578 |
} |
} |
579 |
|
|
580 |
static int |
static int |
581 |
get_priority(argv) |
get_priority(cfg_value_t *argv) |
|
cfg_value_t *argv; |
|
582 |
{ |
{ |
583 |
if (argv[0].type != CFG_CHAR || argv[1].type != CFG_STRING) |
if (argv[0].type != CFG_CHAR || argv[1].type != CFG_STRING) |
584 |
return 1; |
return 1; |
604 |
} |
} |
605 |
|
|
606 |
static int |
static int |
607 |
category_stmt_handler(argc, argv, block_data, handler_data) |
category_stmt_handler(int argc, cfg_value_t *argv, |
608 |
int argc; |
void *block_data, void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
609 |
{ |
{ |
610 |
cat_def.init = 0; |
cat_def.init = 0; |
611 |
cat_def.cat = cat_def.pri = -1; |
cat_def.cat = cat_def.pri = -1; |
721 |
} |
} |
722 |
|
|
723 |
static int |
static int |
724 |
category_stmt_end(block_data, handler_data) |
category_stmt_end(void *block_data, void *handler_data) |
|
void *block_data; |
|
|
void *handler_data; |
|
725 |
{ |
{ |
726 |
if (cat_def.init) { |
if (cat_def.init) { |
727 |
switch (cat_def.cat) { |
switch (cat_def.cat) { |
742 |
} |
} |
743 |
|
|
744 |
static int |
static int |
745 |
category_set_channel(argc, argv, block_data, handler_data) |
category_set_channel(int argc, cfg_value_t *argv, |
746 |
int argc; |
void *block_data, void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
747 |
{ |
{ |
748 |
Channel *channel; |
Channel *channel; |
749 |
|
|
774 |
} |
} |
775 |
|
|
776 |
static int |
static int |
777 |
category_set_flag(argc, argv, block_data, handler_data) |
category_set_flag(int argc, cfg_value_t *argv, void *block_data, |
778 |
int argc; |
void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
779 |
{ |
{ |
780 |
int flag = (int) handler_data; |
int flag = (int) handler_data; |
781 |
if (argc != 2) { |
if (argc != 2) { |
794 |
} |
} |
795 |
|
|
796 |
static int |
static int |
797 |
category_set_level(argc, argv, block_data, handler_data) |
category_set_level(int argc, cfg_value_t *argv, |
798 |
int argc; |
void *block_data, void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
799 |
{ |
{ |
800 |
int i; |
int i; |
801 |
|
|
830 |
} |
} |
831 |
|
|
832 |
static int |
static int |
833 |
channel_file_handler(argc, argv, block_data, handler_data) |
channel_file_handler(int argc, cfg_value_t *argv, void *block_data, |
834 |
int argc; |
void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
835 |
{ |
{ |
836 |
if (argc != 2) { |
if (argc != 2) { |
837 |
cfg_argc_error(argc < 2); |
cfg_argc_error(argc < 2); |
847 |
} |
} |
848 |
|
|
849 |
static int |
static int |
850 |
channel_syslog_handler(argc, argv, block_data, handler_data) |
channel_syslog_handler(int argc, cfg_value_t *argv, void *block_data, |
851 |
int argc; |
void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
852 |
{ |
{ |
853 |
int facility; |
int facility; |
854 |
int prio; |
int prio; |
899 |
} |
} |
900 |
|
|
901 |
static int |
static int |
902 |
channel_set_flag(argc, argv, block_data, handler_data) |
channel_set_flag(int argc, cfg_value_t *argv, |
903 |
int argc; |
void *block_data, void *handler_data) |
|
cfg_value_t *argv; |
|
|
void *block_data; |
|
|
void *handler_data; |
|
904 |
{ |
{ |
905 |
int flag = (int) handler_data; |
int flag = (int) handler_data; |
906 |
if (argc != 2) { |
if (argc != 2) { |
932 |
NULL, NULL }, |
NULL, NULL }, |
933 |
{ "print-priority", CS_STMT, NULL, channel_set_flag, (void*)LO_PRI, |
{ "print-priority", CS_STMT, NULL, channel_set_flag, (void*)LO_PRI, |
934 |
NULL, NULL }, |
NULL, NULL }, |
|
{ "print-tid", CS_STMT, NULL, channel_set_flag, (void*)LO_TID, |
|
|
NULL, NULL }, |
|
935 |
{ "print-milliseconds", CS_STMT, NULL, channel_set_flag, |
{ "print-milliseconds", CS_STMT, NULL, channel_set_flag, |
936 |
(void*)LO_MSEC, NULL, NULL }, |
(void*)LO_MSEC, NULL, NULL }, |
937 |
{ NULL } |
{ NULL } |