Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / ircd_log.c
1 /************************************************************************
2  *   IRC - Internet Relay Chat, src/ircd_log.c
3  *   Copyright (C) 1999 Thomas Helvey (BleepSoft)
4  *   Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
5  *                     
6  *   See file AUTHORS in IRC package for additional names of
7  *   the programmers. 
8  *
9  *   This program is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU General Public License as published by
11  *   the Free Software Foundation; either version 1, or (at your option)
12  *   any later version.
13  *
14  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  *   $Id$
24  */
25 #include "ircd_log.h"
26 #include "client.h"
27 #include "config.h"
28 #include "ircd_alloc.h"
29 #include "ircd_reply.h"
30 #include "ircd_snprintf.h"
31 #include "ircd_string.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "s_debug.h"
35 #include "send.h"
36 #include "struct.h"
37
38 #include <assert.h>
39 #include <errno.h>
40 #include <fcntl.h>
41 #include <stdarg.h>
42 #include <stdio.h>
43 #include <sys/stat.h>
44 #include <sys/types.h>
45 #include <sys/uio.h>
46 #include <syslog.h>
47 #include <time.h>
48 #include <unistd.h>
49
50 #define LOG_BUFSIZE 2048 
51
52 /* select default log level cutoff */
53 #ifdef DEBUGMODE
54 # define L_DEFAULT      L_DEBUG
55 #else
56 # define L_DEFAULT      L_INFO
57 #endif
58
59 #define LOG_DOSYSLOG    0x10
60 #define LOG_DOFILELOG   0x20
61 #define LOG_DOSNOTICE   0x40
62
63 #define LOG_DOMASK      (LOG_DOSYSLOG | LOG_DOFILELOG | LOG_DOSNOTICE)
64
65 /* Map severity levels to strings and syslog levels */
66 static struct LevelData {
67   enum LogLevel level;
68   char         *string;
69   int           syslog;
70   unsigned int  snomask; /* 0 means use default in LogDesc */
71 } levelData[] = {
72 #define L(level, syslog, mask) { L_ ## level, #level, (syslog), (mask) }
73   L(CRIT, LOG_CRIT, SNO_OLDSNO),
74   L(ERROR, LOG_ERR, 0),
75   L(WARNING, LOG_WARNING, 0),
76   L(NOTICE, LOG_NOTICE, 0),
77   L(TRACE, LOG_INFO, 0),
78   L(INFO, LOG_INFO, 0),
79   L(DEBUG, LOG_INFO, SNO_DEBUG),
80 #undef L
81   { L_LAST_LEVEL, 0, 0, 0 }
82 };
83
84 /* Just in case some implementation of syslog has them... */
85 #undef LOG_NONE
86 #undef LOG_DEFAULT
87 #undef LOG_NOTFOUND
88
89 #define LOG_NONE     -1 /* don't syslog */
90 #define LOG_DEFAULT   0 /* syslog to logInfo.facility */
91 #define LOG_NOTFOUND -2 /* didn't find a facility corresponding to name */
92
93 /* Map names to syslog facilities--allows syslog configuration from .conf */
94 static struct {
95   char *name;
96   int facility;
97 } facilities[] = {
98 #define F(fac) { #fac, LOG_ ## fac }
99   F(NONE),    F(DEFAULT), F(AUTH),
100 #ifdef LOG_AUTHPRIV
101   F(AUTHPRIV),
102 #endif
103   F(CRON),    F(DAEMON),  F(LOCAL0),  F(LOCAL1),  F(LOCAL2),  F(LOCAL3),
104   F(LOCAL4),  F(LOCAL5),  F(LOCAL6),  F(LOCAL7),  F(LPR),     F(MAIL),
105   F(NEWS),    F(USER),    F(UUCP),
106 #undef F
107   { 0, 0 }
108 };
109
110 #define SNO_NONE     0x00000000 /* don't send server notices */
111 #define SNO_NOTFOUND 0xffffffff /* didn't find a SNO_MASK value for name */
112
113 /* Map names to snomask values--allows configuration from .conf */
114 static struct {
115   char *name;
116   unsigned int snomask;
117 } masks[] = {
118 #define M(mask) { #mask, SNO_ ## mask }
119   M(NONE),       M(OLDSNO),     M(SERVKILL),   M(OPERKILL),   M(HACK2),
120   M(HACK3),      M(UNAUTH),     M(TCPCOMMON),  M(TOOMANY),    M(HACK4),
121   M(GLINE),      M(NETWORK),    M(IPMISMATCH), M(THROTTLE),   M(OLDREALOP),
122   M(CONNEXIT),   M(DEBUG),
123 #undef M
124   { 0, 0 }
125 };
126
127 /* Descriptions of all logging subsystems */
128 static struct LogDesc {
129   enum LogSys     subsys;   /* number for subsystem */
130   char           *name;     /* subsystem name */
131   struct LogFile *file;     /* file descriptor for subsystem */
132   int             def_fac;  /* default facility */
133   unsigned int    def_sno;  /* default snomask */
134   int             facility; /* -1 means don't use syslog */
135   unsigned int    snomask;  /* 0 means no server message */
136   enum LogLevel   level;    /* logging level */
137 } logDesc[] = {
138 #define S(sys, p, sn) { LS_ ## sys, #sys, 0, (p), (sn), (p), (sn), L_DEFAULT }
139   S(SYSTEM, -1, 0),
140   S(CONFIG, 0, SNO_OLDSNO),
141   S(OPERMODE, -1, SNO_HACK4),
142   S(GLINE, -1, SNO_GLINE),
143   S(JUPE, -1, SNO_NETWORK),
144   S(WHO, -1, 0),
145   S(NETWORK, -1, SNO_NETWORK),
146   S(OPERKILL, -1, 0),
147   S(SERVKILL, -1, 0),
148   S(OPER, -1, SNO_OLDREALOP),
149   S(OPERLOG, -1, 0),
150   S(USERLOG, -1, 0),
151   S(RESOLVER, -1, 0),
152   S(SOCKET, -1, 0),
153   S(DEBUG, -1, SNO_DEBUG),
154   S(OLDLOG, -1, 0),
155 #undef S
156   { LS_LAST_SYSTEM, 0, 0, -1, 0, -1, 0 }
157 };
158
159 /* describes a log file */
160 struct LogFile {
161   struct LogFile  *next;   /* next log file descriptor */
162   struct LogFile **prev_p; /* what points to us */
163   int              fd;     /* file's descriptor-- -1 if not open */
164   int              ref;    /* how many things refer to us? */
165   char            *file;   /* file name */
166 };
167
168 /* modifiable static information */
169 static struct {
170   struct LogFile *filelist; /* list of log files */
171   struct LogFile *freelist; /* list of free'd log files */
172   int             facility; /* default facility */
173   const char     *procname; /* process's name */
174   struct LogFile *dbfile;   /* debug file */
175 } logInfo = { 0, 0, LOG_USER, "ircd", 0 };
176
177 void ircd_log(int priority, const char* fmt, ...)
178 {
179   va_list vl;
180
181   va_start(vl, fmt);
182   log_vwrite(LS_OLDLOG, priority, 0, fmt, vl);
183   va_end(vl);
184 }
185
186 /* helper routine to open a log file if needed */
187 static void
188 log_open(struct LogFile *lf)
189 {
190   /* only open the file if we haven't already */
191   if (lf && lf->fd < 0) {
192     alarm(3); /* if NFS hangs, we hang only for 3 seconds */
193     lf->fd = open(lf->file, O_WRONLY | O_CREAT | O_APPEND,
194                   S_IREAD | S_IWRITE);
195     alarm(0);
196   }
197 }
198
199 #ifdef DEBUGMODE
200
201 /* reopen debug log */
202 static void
203 log_debug_reopen(void)
204 {
205   if (!logInfo.dbfile) /* no open debugging file */
206     return;
207
208   if (!logInfo.dbfile->file) { /* using terminal output */
209     logInfo.dbfile->fd = 2;
210     return;
211   }
212
213   /* Ok, it's a real file; close it if necessary and use log_open to open it */
214   if (logInfo.dbfile->fd >= 0)
215     close(logInfo.dbfile->fd);
216
217   log_open(logInfo.dbfile);
218
219   if (logInfo.dbfile->fd < 0) { /* try again with /dev/null */
220     if ((logInfo.dbfile->fd = open("/dev/null", O_WRONLY)) < 0)
221       exit(-1);
222   }
223
224   /* massage the file descriptor to be stderr */
225   if (logInfo.dbfile->fd != 2) {
226     dup2(logInfo.dbfile->fd, 2);
227     close(logInfo.dbfile->fd);
228     logInfo.dbfile->fd = 2;
229   }
230 }
231
232 /* initialize debugging log */
233 void
234 log_debug_init(char *file)
235 {
236   logInfo.dbfile = MyMalloc(sizeof(struct LogFile));
237
238   logInfo.dbfile->next = 0; /* initialize debugging filename */
239   logInfo.dbfile->prev_p = 0;
240   logInfo.dbfile->fd = -1;
241   logInfo.dbfile->ref = 1;
242
243   if (file) /* store pathname to use */
244     DupString(logInfo.dbfile->file, file);
245   else
246     logInfo.dbfile->file = 0;
247
248   log_debug_reopen(); /* open the debug log */
249
250   logDesc[LS_DEBUG].file = logInfo.dbfile; /* remember where it went */
251 }
252
253 #endif /* DEBUGMODE */
254
255 /* set the debug log file */
256 static int
257 log_debug_file(const char *file)
258 {
259 #ifdef DEBUGMODE
260   assert(0 != file);
261
262   /* If we weren't started with debugging enabled, or if we're using
263    * the terminal, don't do anything at all.
264    */
265   if (!logInfo.dbfile || !logInfo.dbfile->file)
266     return 1;
267
268   MyFree(logInfo.dbfile->file); /* free old pathname */
269   DupString(logInfo.dbfile->file, file); /* store new pathname */
270
271   log_debug_reopen(); /* reopen the debug log */
272 #endif /* DEBUGMODE */
273   return 0;
274 }
275
276 /* called in place of open_log(), this stores the process name and prepares
277  * for syslogging
278  */
279 void
280 log_init(const char *process_name)
281 {
282   /* store the process name; probably belongs in ircd.c, but oh well... */
283   if (!EmptyString(process_name))
284     logInfo.procname = process_name;
285
286   /* ok, open syslog; default facility: LOG_USER */
287   openlog(logInfo.procname, LOG_PID | LOG_NDELAY, logInfo.facility);
288 }
289
290 /* Files are persistently open; this closes and reopens them to allow
291  * log file rotation
292  */
293 void
294 log_reopen(void)
295 {
296   log_close(); /* close everything...we reopen on demand */
297
298 #ifdef DEBUGMODE
299   log_debug_reopen(); /* reopen debugging log if necessary */
300 #endif /* DEBUGMODE */
301
302   /* reopen syslog, if needed; default facility: LOG_USER */
303   openlog(logInfo.procname, LOG_PID | LOG_NDELAY, logInfo.facility);
304 }
305
306 /* close the log files */
307 void
308 log_close(void)
309 {
310   struct LogFile *ptr;
311
312   closelog(); /* close syslog */
313
314   for (ptr = logInfo.filelist; ptr; ptr = ptr->next) {
315     if (ptr->fd >= 0)
316       close(ptr->fd); /* close all the files... */
317
318     ptr->fd = -1;
319   }
320
321   if (logInfo.dbfile && logInfo.dbfile->file) {
322     if (logInfo.dbfile->fd >= 0)
323       close(logInfo.dbfile->fd); /* close the debug log file */
324
325     logInfo.dbfile->fd = -1;
326   }
327 }
328
329 /* These write entries to a log file */
330 void
331 log_write(enum LogSys subsys, enum LogLevel severity, unsigned int flags,
332           const char *fmt, ...)
333 {
334   va_list vl;
335
336   va_start(vl, fmt);
337   log_vwrite(subsys, severity, flags, fmt, vl);
338   va_end(vl);
339 }
340
341 void
342 log_vwrite(enum LogSys subsys, enum LogLevel severity, unsigned int flags,
343            const char *fmt, va_list vl)
344 {
345   struct VarData vd;
346   struct LogDesc *desc;
347   struct LevelData *ldata;
348   struct tm *tstamp;
349   struct iovec vector[3];
350   time_t curtime;
351   char buf[LOG_BUFSIZE];
352   /* 1234567890123456789012 3 */
353   /* [2000-11-28 16:11:20] \0 */
354   char timebuf[23];
355
356   /* check basic assumptions */
357   assert(-1 < (int)subsys);
358   assert((int)subsys < LS_LAST_SYSTEM);
359   assert(-1 < (int)severity);
360   assert((int)severity < L_LAST_LEVEL);
361   assert(0 == (flags & ~LOG_NOMASK));
362   assert(0 != fmt);
363
364   /* find the log data and the severity data */
365   desc = &logDesc[subsys];
366   ldata = &levelData[severity];
367
368   /* check the set of ordering assumptions */
369   assert(desc->subsys == subsys);
370   assert(ldata->level == severity);
371
372   /* check severity... */
373   if (severity > desc->level)
374     return;
375
376   /* figure out where all we need to log */
377   if (!(flags & LOG_NOFILELOG) && desc->file) {
378     log_open(desc->file);
379     if (desc->file->fd >= 0) /* don't log to file if we can't open the file */
380       flags |= LOG_DOFILELOG;
381   }
382
383   if (!(flags & LOG_NOSYSLOG) && desc->facility >= 0)
384     flags |= LOG_DOSYSLOG; /* will syslog */
385
386   if (!(flags & LOG_NOSNOTICE) && (desc->snomask != 0 || ldata->snomask != 0))
387     flags |= LOG_DOSNOTICE; /* will send a server notice */
388
389   /* short-circuit if there's nothing to do... */
390   if (!(flags & LOG_DOMASK))
391     return;
392
393   /* Build the basic log string */
394   vd.vd_format = fmt;
395   vd.vd_args = vl;
396
397   /* save the length for writev */
398   /* Log format: "SYSTEM [SEVERITY]: log message" */
399   vector[1].iov_len =
400     ircd_snprintf(0, buf, sizeof(buf), "%s [%s]: %v", desc->name,
401                   ldata->string, &vd);
402
403   /* if we have something to write to... */
404   if (flags & LOG_DOFILELOG) {
405     curtime = TStime();
406     tstamp = localtime(&curtime); /* build the timestamp */
407
408     vector[0].iov_len =
409       ircd_snprintf(0, timebuf, sizeof(timebuf), "[%d-%d-%d %d:%02d:%02d] ",
410                     tstamp->tm_year + 1900, tstamp->tm_mon + 1,
411                     tstamp->tm_mday, tstamp->tm_hour, tstamp->tm_min,
412                     tstamp->tm_sec);
413
414     /* set up the remaining parts of the writev vector... */
415     vector[0].iov_base = timebuf;
416     vector[1].iov_base = buf;
417
418     vector[2].iov_base = "\n"; /* terminate lines with a \n */
419     vector[2].iov_len = 1;
420
421     /* write it out to the log file */
422     writev(desc->file->fd, vector, 3);
423   }
424
425   /* oh yeah, syslog it too... */
426   if (flags & LOG_DOSYSLOG)
427     syslog(ldata->syslog | desc->facility, "%s", buf);
428
429   /* can't forget server notices... */
430   if (flags & LOG_DOSNOTICE)
431     sendto_opmask_butone(0, ldata->snomask ? ldata->snomask : desc->snomask,
432                          "%s", buf);
433 }
434
435 /* log kills for fun and profit */
436 void
437 log_write_kill(const struct Client *victim, const struct Client *killer,
438                const char *inpath, const char *path)
439 {
440   if (MyUser(victim))
441     log_write(IsServer(killer) ? LS_SERVKILL : LS_OPERKILL, L_TRACE, 0,
442               "A local client %#C KILLED by %#C Path: %s!%s",
443               victim, killer, inpath, path);
444   else
445     log_write(IsServer(killer) ? LS_SERVKILL : LS_OPERKILL, L_TRACE, 0,
446               "KILL from %C For %C Path: %s!%s", killer, victim, inpath, path);
447 }
448
449 /* return a struct LogFile for a specific filename--reference counted */
450 static struct LogFile *
451 log_file_create(const char *file)
452 {
453   struct LogFile *tmp;
454
455   assert(0 != file);
456
457   /* if one already exists for that file, return it */
458   for (tmp = logInfo.filelist; tmp; tmp = tmp->next)
459     if (!strcmp(tmp->file, file)) {
460       tmp->ref++;
461       return tmp;
462     }
463
464   if (logInfo.freelist) { /* pop one off the free list */
465     tmp = logInfo.freelist;
466     logInfo.freelist = tmp->next;
467   } else /* allocate a new one */
468     tmp = MyMalloc(sizeof(struct LogFile));
469
470   tmp->fd = -1; /* initialize the structure */
471   tmp->ref = 1;
472   DupString(tmp->file, file);
473
474   tmp->next = logInfo.filelist; /* link it into the list... */
475   tmp->prev_p = &logInfo.filelist;
476   logInfo.filelist->prev_p = &tmp->next;
477   logInfo.filelist = tmp;
478
479   return tmp;
480 }
481
482 /* destroy a log file descriptor, under the control of the reference count */
483 static void
484 log_file_destroy(struct LogFile *lf)
485 {
486   assert(0 != lf);
487
488   if (--lf->ref == 0) {
489     if (lf->next) /* clip it out of the list */
490       lf->next->prev_p = lf->prev_p;
491     *lf->prev_p = lf->next;
492
493     lf->prev_p = 0; /* we won't use it for the free list */
494     if (lf->fd >= 0)
495       close(lf->fd);
496     lf->fd = -1;
497     MyFree(lf->file); /* free the file name */
498
499     lf->next = logInfo.freelist; /* stack it onto the free list */
500     logInfo.freelist = lf;
501   }
502 }
503
504 /* finds a subsystem given its name */
505 static struct LogDesc *
506 log_find(const char *subsys)
507 {
508   int i;
509
510   assert(0 != subsys);
511
512   /* find the named subsystem */
513   for (i = 0; i < LS_LAST_SYSTEM; i++)
514     if (!ircd_strcmp(subsys, logDesc[i].name))
515       return &logDesc[i];
516
517   return 0; /* not found */
518 }
519
520 /* canonicalize subsystem names */
521 char *
522 log_canon(const char *subsys)
523 {
524   struct LogDesc *desc;
525
526   if (!(desc = log_find(subsys)))
527     return 0;
528
529   return desc->name;
530 }
531
532 /* find a level given its name */
533 static enum LogLevel
534 log_lev_find(const char *level)
535 {
536   int i;
537
538   assert(0 != level);
539
540   /* find the named level */
541   for (i = 0; levelData[i].string; i++)
542     if (!ircd_strcmp(level, levelData[i].string))
543       return levelData[i].level;
544
545   return L_LAST_LEVEL; /* not found */
546 }
547
548 /* return a name for a level */
549 static char *
550 log_lev_name(enum LogLevel lev)
551 {
552   assert(-1 < (int)lev);
553   assert((int)lev < L_LAST_LEVEL);
554   assert(lev == levelData[lev].level);
555
556   return levelData[lev].string;
557 }
558
559 /* find a facility given its name */
560 static int
561 log_fac_find(const char *facility)
562 {
563   int i;
564
565   assert(0 != facility);
566
567   /* find the named facility */
568   for (i = 0; facilities[i].name; i++)
569     if (!ircd_strcmp(facility, facilities[i].name))
570       return facilities[i].facility;
571
572   return LOG_NOTFOUND; /* not found */
573 }
574
575 /* return a name for a facility */
576 static char *
577 log_fac_name(int fac)
578 {
579   int i;
580
581   /* find the facility */
582   for (i = 0; facilities[i].name; i++)
583     if (facilities[i].facility == fac)
584       return facilities[i].name;
585
586   return 0; /* not found; should never happen */
587 }
588
589 /* find a snomask value given its name */
590 static unsigned int
591 log_sno_find(const char *maskname)
592 {
593   int i;
594
595   assert(0 != maskname);
596
597   /* find the named snomask */
598   for (i = 0; masks[i].name; i++)
599     if (!ircd_strcmp(maskname, masks[i].name))
600       return masks[i].snomask;
601
602   return SNO_NOTFOUND; /* not found */
603 }
604
605 /* return a name for a snomask value */
606 static char *
607 log_sno_name(unsigned int sno)
608 {
609   int i;
610
611   /* find the snomask */
612   for (i = 0; masks[i].name; i++)
613     if (masks[i].snomask == sno)
614       return masks[i].name;
615
616   return 0; /* not found; should never happen */
617 }
618
619 /* set the log file for a subsystem */
620 int
621 log_set_file(const char *subsys, const char *filename)
622 {
623   struct LogDesc *desc;
624
625   /* find subsystem */
626   if (!(desc = log_find(subsys)))
627     return 2;
628
629   /* no change, don't go to the trouble of destroying and recreating */
630   if (filename && !strcmp(desc->file->file, filename))
631     return 0;
632
633   /* debug log is special, since it has to be opened on fd 2 */
634   if (desc->subsys == LS_DEBUG) {
635     return log_debug_file(filename);
636   }
637
638   if (desc->file) /* destroy previous entry... */
639     log_file_destroy(desc->file);
640
641   /* set the file to use */
642   desc->file = filename ? log_file_create(filename) : 0;
643
644   return 0;
645 }
646
647 /* get the log file for a subsystem */
648 char *
649 log_get_file(const char *subsys)
650 {
651   struct LogDesc *desc;
652
653   /* find subsystem */
654   if (!(desc = log_find(subsys)))
655     return 0;
656
657   return desc->file ? desc->file->file : 0;
658 }
659
660 /* set the facility for a subsystem */
661 int
662 log_set_facility(const char *subsys, const char *facility)
663 {
664   struct LogDesc *desc;
665   int fac;
666
667   /* find subsystem */
668   if (!(desc = log_find(subsys)))
669     return 2;
670
671   /* set syslog facility */
672   if (EmptyString(facility))
673     desc->facility = desc->def_fac;
674   else if ((fac = log_fac_find(facility)) != LOG_NOTFOUND)
675     desc->facility = fac;
676   else
677     return 1;
678
679   return 0;
680 }
681
682 /* get the facility for a subsystem */
683 char *
684 log_get_facility(const char *subsys)
685 {
686   struct LogDesc *desc;
687
688   /* find subsystem */
689   if (!(desc = log_find(subsys)))
690     return 0;
691
692   /* find the facility's name */
693   return log_fac_name(desc->facility);
694 }
695
696 /* set the snomask value for a subsystem */
697 int
698 log_set_snomask(const char *subsys, const char *snomask)
699 {
700   struct LogDesc *desc;
701   unsigned int sno = SNO_DEFAULT;
702
703   /* find subsystem */
704   if (!(desc = log_find(subsys)))
705     return 2;
706
707   /* set snomask value */
708   if (EmptyString(snomask))
709     desc->snomask = desc->def_sno;
710   else if ((sno = log_sno_find(snomask)) != SNO_NOTFOUND)
711     desc->snomask = sno;
712   else
713     return 1;
714
715   return 0;
716 }
717
718 /* get the snomask value for a subsystem */
719 char *
720 log_get_snomask(const char *subsys)
721 {
722   struct LogDesc *desc;
723
724   /* find subsystem */
725   if (!(desc = log_find(subsys)))
726     return 0;
727
728   /* find the snomask value's name */
729   return log_sno_name(desc->snomask);
730 }
731
732 /* set the level for a subsystem */
733 int
734 log_set_level(const char *subsys, const char *level)
735 {
736   struct LogDesc *desc;
737   enum LogLevel lev;
738
739   /* find subsystem */
740   if (!(desc = log_find(subsys)))
741     return 2;
742
743   /* set logging level */
744   if (EmptyString(level))
745     desc->level = L_DEFAULT;
746   else if ((lev = log_lev_find(level)) != L_LAST_LEVEL)
747     desc->level = lev;
748   else
749     return 1;
750
751   return 0;
752 }
753
754 /* get the level for a subsystem */
755 char *
756 log_get_level(const char *subsys)
757 {
758   struct LogDesc *desc;
759
760   /* find subsystem */
761   if (!(desc = log_find(subsys)))
762     return 0;
763
764   /* find the level's name */
765   return log_lev_name(desc->level);
766 }
767
768 /* set the overall default syslog facility */
769 int
770 log_set_default(const char *facility)
771 {
772   int fac, oldfac;
773
774   oldfac = logInfo.facility;
775
776   if (EmptyString(facility))
777     logInfo.facility = LOG_USER;
778   else if ((fac = log_fac_find(facility)) != LOG_NOTFOUND &&
779            fac != LOG_NONE && fac != LOG_DEFAULT)
780     logInfo.facility = fac;
781   else
782     return 1;
783
784   if (logInfo.facility != oldfac) {
785     closelog(); /* reopen syslog with new facility setting */
786     openlog(logInfo.procname, LOG_PID | LOG_NDELAY, logInfo.facility);
787   }
788
789   return 0;
790 }
791
792 /* get the overall default syslog facility */
793 char *
794 log_get_default(void)
795 {
796   /* find the facility's name */
797   return log_fac_name(logInfo.facility);
798 }
799
800 /* Report feature settings */
801 void
802 log_feature_report(struct Client *to)
803 {
804   int i;
805
806   for (i = 0; i < LS_LAST_SYSTEM; i++) {
807     if (logDesc[i].file && logDesc[i].file->file) /* report file */
808       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F LOG %s FILE %s",
809                  logDesc[i].name, logDesc[i].file->file);
810
811     if (logDesc[i].facility != logDesc[i].def_fac) /* report facility */
812       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F LOG %s FACILITY %s",
813                  logDesc[i].name, log_fac_name(logDesc[i].facility));
814
815     if (logDesc[i].snomask != logDesc[i].def_sno) /* report snomask */
816       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F LOG %s SNOMASK %s",
817                  logDesc[i].name, log_sno_name(logDesc[i].snomask));
818
819     if (logDesc[i].level != L_DEFAULT) /* report log level */
820       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F LOG %s LEVEL %s",
821                  logDesc[i].name, log_lev_name(logDesc[i].level));
822   }
823
824   if (logInfo.facility != LOG_USER) /* report default facility */
825     send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F LOG %s",
826                log_fac_name(logInfo.facility));
827 }