Annotation of src/usr.bin/rdist/message.c, Revision 1.11
1.11 ! deraadt 1: /* $OpenBSD: message.c,v 1.10 2001/11/19 19:02:15 mpech Exp $ */
1.4 deraadt 2:
1.1 dm 3: /*
4: * Copyright (c) 1983 Regents of the University of California.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #ifndef lint
1.7 millert 37: #if 0
1.1 dm 38: static char RCSid[] =
1.7 millert 39: "$From: message.c,v 6.24 1996/07/19 17:00:35 michaelc Exp $";
40: #else
41: static char RCSid[] =
1.11 ! deraadt 42: "$OpenBSD: message.c,v 1.10 2001/11/19 19:02:15 mpech Exp $";
1.7 millert 43: #endif
1.1 dm 44:
45: static char sccsid[] = "@(#)common.c";
46:
47: static char copyright[] =
48: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
49: All rights reserved.\n";
50: #endif /* !lint */
51:
52: /*
53: * Message handling functions for both rdist and rdistd.
54: */
55:
56: #include "defs.h"
57:
58: #define MSGBUFSIZ 32*1024
59:
60: int debug = 0; /* Debugging level */
61: int nerrs = 0; /* Number of errors */
62: char *tempfile = NULL; /* Name of temporary file */
63:
64: /*
65: * Message Types
66: */
67: MSGTYPE msgtypes[] = {
68: { MT_CHANGE, "change" },
69: { MT_INFO, "info" },
70: { MT_NOTICE, "notice" },
71: { MT_NERROR, "nerror" },
72: { MT_FERROR, "ferror" },
73: { MT_WARNING, "warning" },
74: { MT_VERBOSE, "verbose" },
75: { MT_ALL, "all" },
76: { MT_DEBUG, "debug" },
77: { 0 },
78: };
79:
80: static void msgsendstdout(), msgsendfile(), msgsendsyslog(),
81: msgsendnotify();
82:
83: /*
84: * Message Facilities
85: */
86: MSGFACILITY msgfacility[] = {
87: { MF_STDOUT, "stdout", msgsendstdout },
88: { MF_FILE, "file", msgsendfile },
89: { MF_SYSLOG, "syslog", msgsendsyslog },
90: { MF_NOTIFY, "notify", msgsendnotify },
91: { 0 },
92: };
93:
94: /*
95: * Print message logging usage message
96: */
97: extern void msgprusage()
98: {
1.10 mpech 99: int i, x;
1.1 dm 100:
101: (void) fprintf(stderr, "\nWhere <msgopt> is of form\n");
102: (void) fprintf(stderr,
103: "\t<facility1>=<type1>,<type2>,...:<facility2>=<type1>,<type2>...\n");
104:
105: (void) fprintf(stderr, "Valid <facility> names:");
106:
107: for (i = 0; msgfacility[i].mf_name; ++i)
108: (void) fprintf(stderr, " %s", msgfacility[i].mf_name);
109:
110: (void) fprintf(stderr, "\nValid <type> names:");
111: for (x = 0; msgtypes[x].mt_name; ++x)
112: (void) fprintf(stderr, " %s", msgtypes[x].mt_name);
113:
114: (void) fprintf(stderr, "\n");
115: }
116:
117: /*
118: * Print enabled message logging info
119: */
120: extern void msgprconfig()
121: {
1.10 mpech 122: int i, x;
1.1 dm 123: static char buf[MSGBUFSIZ];
124:
125: debugmsg(DM_MISC, "Current message logging config:");
126: for (i = 0; msgfacility[i].mf_name; ++i) {
1.5 millert 127: (void) snprintf(buf, sizeof(buf),
128: " %s=", msgfacility[i].mf_name);
1.1 dm 129: for (x = 0; msgtypes[x].mt_name; ++x)
130: if (IS_ON(msgfacility[i].mf_msgtypes,
131: msgtypes[x].mt_type)) {
132: if (x > 0)
133: (void) strcat(buf, ",");
134: (void) strcat(buf, msgtypes[x].mt_name);
135: }
136: debugmsg(DM_MISC, "%s", buf);
137: }
138:
139: }
140:
141: /*
142: * Get the Message Facility entry "name"
143: */
144: static MSGFACILITY *getmsgfac(name)
145: char *name;
146: {
1.10 mpech 147: int i;
1.1 dm 148:
149: for (i = 0; msgfacility[i].mf_name; ++i)
150: if (strcasecmp(name, msgfacility[i].mf_name) == 0)
151: return(&msgfacility[i]);
152:
1.7 millert 153: return(NULL);
1.1 dm 154: }
155:
156: /*
157: * Get the Message Type entry named "name"
158: */
159: static MSGTYPE *getmsgtype(name)
160: char *name;
161: {
1.10 mpech 162: int i;
1.1 dm 163:
164: for (i = 0; msgtypes[i].mt_name; ++i)
165: if (strcasecmp(name, msgtypes[i].mt_name) == 0)
166: return(&msgtypes[i]);
167:
1.7 millert 168: return(NULL);
1.1 dm 169: }
170:
171: /*
172: * Set Message Type information for Message Facility "msgfac" as
173: * indicated by string "str".
174: */
175: static char *setmsgtypes(msgfac, str)
176: MSGFACILITY *msgfac;
177: char *str;
178: {
179: static char ebuf[BUFSIZ];
1.10 mpech 180: char *cp;
181: char *strptr, *word;
182: MSGTYPE *mtp;
1.1 dm 183:
184: /*
185: * MF_SYSLOG is the only supported message facility for the server
186: */
187: if (isserver && (msgfac->mf_msgfac != MF_SYSLOG &&
188: msgfac->mf_msgfac != MF_FILE)) {
1.5 millert 189: (void) snprintf(ebuf, sizeof(ebuf),
1.1 dm 190: "The \"%s\" message facility cannot be used by the server.",
1.7 millert 191: msgfac->mf_name);
1.1 dm 192: return(ebuf);
193: }
194:
195: strptr = str;
196:
197: /*
198: * Do any necessary Message Facility preparation
199: */
200: switch(msgfac->mf_msgfac) {
201: case MF_FILE:
202: /*
203: * The MF_FILE string should look like "<file>=<types>".
204: */
205: if ((cp = strchr(strptr, '=')) == NULL)
206: return(
207: "No file name found for \"file\" message facility");
208: *cp++ = CNULL;
209:
210: if ((msgfac->mf_fptr = fopen(strptr, "w")) == NULL)
211: fatalerr("Cannot open log file for writing: %s: %s.",
212: strptr, SYSERR);
1.8 millert 213: msgfac->mf_filename = xstrdup(strptr);
1.1 dm 214:
215: strptr = cp;
216: break;
217:
218: case MF_NOTIFY:
219: break;
220:
221: case MF_STDOUT:
222: msgfac->mf_fptr = stdout;
223: break;
224:
225: case MF_SYSLOG:
226: #if defined(LOG_OPTS)
227: #if defined(LOG_FACILITY)
228: openlog(progname, LOG_OPTS, LOG_FACILITY);
229: #else
230: openlog(progname, LOG_OPTS);
231: #endif /* LOG_FACILITY */
232: #endif /* LOG_OPTS */
233: break;
234: }
235:
236: /*
237: * Parse each type word
238: */
239: msgfac->mf_msgtypes = 0; /* Start from scratch */
240: while (strptr) {
241: word = strptr;
1.7 millert 242: if ((cp = strchr(strptr, ',')))
1.1 dm 243: *cp++ = CNULL;
244: strptr = cp;
245:
1.7 millert 246: if ((mtp = getmsgtype(word))) {
1.1 dm 247: msgfac->mf_msgtypes |= mtp->mt_type;
248: /*
249: * XXX This is really a kludge until we add real
250: * control over debugging.
251: */
252: if (!debug && isserver &&
253: strcasecmp(word, "debug") == 0)
254: debug = DM_ALL;
255: } else {
1.5 millert 256: (void) snprintf(ebuf, sizeof(ebuf),
257: "Message type \"%s\" is invalid.",
258: word);
1.1 dm 259: return(ebuf);
260: }
261: }
262:
1.7 millert 263: return(NULL);
1.1 dm 264: }
265:
266: /*
267: * Parse a message logging option string
268: */
269: extern char *msgparseopts(msgstr, doset)
270: char *msgstr;
271: int doset;
272: {
273: static char ebuf[BUFSIZ], msgbuf[MSGBUFSIZ];
1.10 mpech 274: char *cp, *optstr;
275: char *word;
1.1 dm 276: MSGFACILITY *msgfac;
277:
278: if (msgstr == NULL)
279: return("NULL message string");
280:
281: /* strtok() is harmful */
1.11 ! deraadt 282: (void) strlcpy(msgbuf, msgstr, sizeof msgbuf);
1.1 dm 283:
284: /*
1.9 provos 285: * Each <facility>=<types> list is separated by ":".
1.1 dm 286: */
287: for (optstr = strtok(msgbuf, ":"); optstr;
1.7 millert 288: optstr = strtok(NULL, ":")) {
1.1 dm 289:
290: if ((cp = strchr(optstr, '=')) == NULL)
291: return("No '=' found");
292:
293: *cp++ = CNULL;
294: word = optstr;
295: if ((int)strlen(word) <= 0)
296: return("No message facility specified");
297: if ((int)strlen(cp) <= 0)
298: return("No message type specified");
299:
300: if ((msgfac = getmsgfac(word)) == NULL) {
1.5 millert 301: (void) snprintf(ebuf, sizeof(ebuf),
302: "%s is not a valid message facility",
303: word);
1.1 dm 304: return(ebuf);
305: }
306:
307: if (doset) {
308: char *mcp;
309:
1.7 millert 310: if ((mcp = setmsgtypes(msgfac, cp)))
1.1 dm 311: return(mcp);
312: }
313: }
314:
315: if (isserver && debug) {
316: debugmsg(DM_MISC, "%s", getversion());
317: msgprconfig();
318: }
319:
1.7 millert 320: return(NULL);
1.1 dm 321: }
322:
323: /*
324: * Send a message to facility "stdout".
325: * For rdistd, this is really the rdist client.
326: */
327: static void msgsendstdout(msgfac, mtype, flags, msgbuf)
328: /*ARGSUSED*/
329: MSGFACILITY *msgfac;
330: int mtype;
331: int flags;
332: char *msgbuf;
333: {
334: char cmd;
335:
336: if (isserver) {
337: if (rem_w < 0 || IS_ON(flags, MT_NOREMOTE))
338: return;
339:
340: cmd = CNULL;
341:
342: switch(mtype) {
343: case MT_NERROR: cmd = C_ERRMSG; break;
344: case MT_FERROR: cmd = C_FERRMSG; break;
345: case MT_NOTICE: cmd = C_NOTEMSG; break;
346: case MT_REMOTE: cmd = C_LOGMSG; break;
347: }
348:
349: if (cmd != CNULL)
350: (void) sendcmd(cmd, "%s", msgbuf);
351: } else {
352: switch(mtype) {
353: case MT_FERROR:
354: case MT_NERROR:
355: if (msgbuf && *msgbuf) {
356: (void) fprintf(stderr, "%s\n", msgbuf);
357: (void) fflush(stderr);
358: }
359: break;
360:
361: case MT_DEBUG:
362: /*
363: * Only things that are strictly MT_DEBUG should
364: * be shown.
365: */
366: if (flags != MT_DEBUG)
367: return;
368: case MT_NOTICE:
369: case MT_CHANGE:
370: case MT_INFO:
371: case MT_VERBOSE:
372: case MT_WARNING:
373: if (msgbuf && *msgbuf) {
374: (void) printf("%s\n", msgbuf);
375: (void) fflush(stdout);
376: }
377: break;
378: }
379: }
380: }
381:
382: /*
383: * Send a message to facility "syslog"
384: */
385: static void msgsendsyslog(msgfac, mtype, flags, msgbuf)
386: /*ARGSUSED*/
387: MSGFACILITY *msgfac;
388: int mtype;
389: int flags;
390: char *msgbuf;
391: {
392: int syslvl = 0;
393:
394: if (!msgbuf || !*msgbuf)
395: return;
396:
397: switch(mtype) {
398: #if defined(SL_NERROR)
399: case MT_NERROR: syslvl = SL_NERROR; break;
400: #endif
401: #if defined(SL_FERROR)
402: case MT_FERROR: syslvl = SL_FERROR; break;
403: #endif
404: #if defined(SL_WARNING)
405: case MT_WARNING: syslvl = SL_WARNING; break;
406: #endif
407: #if defined(SL_CHANGE)
408: case MT_CHANGE: syslvl = SL_CHANGE; break;
409: #endif
410: #if defined(SL_INFO)
411: case MT_SYSLOG:
412: case MT_VERBOSE:
413: case MT_INFO: syslvl = SL_INFO; break;
414: #endif
415: #if defined(SL_NOTICE)
416: case MT_NOTICE: syslvl = SL_NOTICE; break;
417: #endif
418: #if defined(SL_DEBUG)
419: case MT_DEBUG: syslvl = SL_DEBUG; break;
420: #endif
421: }
422:
423: if (syslvl)
424: syslog(syslvl, "%s", msgbuf);
425: }
426:
427: /*
428: * Send a message to a "file" facility.
429: */
430: static void msgsendfile(msgfac, mtype, flags, msgbuf)
431: /*ARGSUSED*/
432: MSGFACILITY *msgfac;
433: int mtype;
434: int flags;
435: char *msgbuf;
436: {
437: if (msgfac->mf_fptr == NULL)
438: return;
439:
440: if (!msgbuf || !*msgbuf)
441: return;
442:
443: (void) fprintf(msgfac->mf_fptr, "%s\n", msgbuf);
444: (void) fflush(msgfac->mf_fptr);
445: }
446:
447: /*
448: * Same method as msgsendfile()
449: */
450: static void msgsendnotify(msgfac, mtype, flags, msgbuf)
451: /*ARGSUSED*/
452: MSGFACILITY *msgfac;
453: int mtype;
454: int flags;
455: char *msgbuf;
456: {
457: if (IS_ON(flags, MT_DEBUG))
458: return;
459:
460: if (!msgbuf || !*msgbuf)
461: return;
462:
463: if (!msgfac->mf_fptr) {
1.10 mpech 464: char *cp;
1.7 millert 465: int fd;
1.1 dm 466: char *getenv();
1.11 ! deraadt 467: size_t len;
1.1 dm 468:
469: /*
470: * Create and open a new temporary file
471: */
1.7 millert 472: if ((cp = getenv("TMPDIR")) == NULL)
1.1 dm 473: cp = _PATH_TMP;
1.11 ! deraadt 474: len = strlen(cp) + 1 + strlen(_RDIST_TMP) + 2;
! 475: tempfile = (char *) xmalloc(len);
! 476: (void) snprintf(tempfile, len, "%s/%s", cp, _RDIST_TMP);
1.1 dm 477:
478: msgfac->mf_filename = tempfile;
1.3 deraadt 479: if ((fd = mkstemp(msgfac->mf_filename)) == -1 ||
1.6 millert 480: (msgfac->mf_fptr = fdopen(fd, "w")) == NULL) {
1.3 deraadt 481: if (fd != -1)
482: close(fd);
1.1 dm 483: fatalerr("Cannot open notify file for writing: %s: %s.",
484: msgfac->mf_filename, SYSERR);
1.3 deraadt 485: }
1.1 dm 486: debugmsg(DM_MISC, "Created notify temp file '%s'",
487: msgfac->mf_filename);
488: }
489:
490: if (msgfac->mf_fptr == NULL)
491: return;
492:
493: (void) fprintf(msgfac->mf_fptr, "%s\n", msgbuf);
494: (void) fflush(msgfac->mf_fptr);
495: }
496:
497: /*
498: * Insure currenthost is set to something reasonable.
499: */
500: extern void checkhostname()
501: {
502: static char mbuf[MAXHOSTNAMELEN];
503: char *cp;
504:
505: if (!currenthost) {
506: if (gethostname(mbuf, sizeof(mbuf)) == 0) {
507: if ((cp = strchr(mbuf, '.')) != NULL)
508: *cp = CNULL;
1.8 millert 509: currenthost = xstrdup(mbuf);
1.1 dm 510: } else
511: currenthost = "(unknown)";
512: }
513: }
514:
515: /*
516: * Print a message contained in "msgbuf" if a level "lvl" is set.
517: */
518: static void _message(flags, msgbuf)
519: int flags;
520: char *msgbuf;
521: {
1.10 mpech 522: int i, x;
523: char *cp;
1.1 dm 524: static char mbuf[2048];
525:
526: if (msgbuf && *msgbuf) {
527: /*
528: * Ensure no stray newlines are present
529: */
1.7 millert 530: if ((cp = strchr(msgbuf, '\n')))
1.1 dm 531: *cp = CNULL;
532:
533: checkhostname();
534: if (strncmp(currenthost, msgbuf, strlen(currenthost)) == 0)
1.11 ! deraadt 535: (void) strlcpy(mbuf, msgbuf, sizeof mbuf);
1.1 dm 536: else
1.11 ! deraadt 537: (void) snprintf(mbuf, sizeof mbuf,
! 538: "%s: %s", currenthost, msgbuf);
1.1 dm 539: } else
1.11 ! deraadt 540: (void) strlcpy(mbuf, "", sizeof mbuf);
1.1 dm 541:
542: /*
543: * Special case for messages that only get
544: * logged to the system log facility
545: */
546: if (IS_ON(flags, MT_SYSLOG)) {
1.7 millert 547: msgsendsyslog(NULL, MT_SYSLOG, flags, mbuf);
1.1 dm 548: return;
549: }
550:
551: /*
552: * Special cases
553: */
1.5 millert 554: if (isserver && IS_ON(flags, MT_NOTICE)) {
1.7 millert 555: msgsendstdout(NULL, MT_NOTICE, flags, mbuf);
1.5 millert 556: return;
557: } else if (isserver && IS_ON(flags, MT_REMOTE))
1.7 millert 558: msgsendstdout(NULL, MT_REMOTE, flags, mbuf);
1.1 dm 559: else if (isserver && IS_ON(flags, MT_NERROR))
1.7 millert 560: msgsendstdout(NULL, MT_NERROR, flags, mbuf);
1.1 dm 561: else if (isserver && IS_ON(flags, MT_FERROR))
1.7 millert 562: msgsendstdout(NULL, MT_FERROR, flags, mbuf);
1.1 dm 563:
564: /*
565: * For each Message Facility, check each Message Type to see
566: * if the bits in "flags" are set. If so, call the appropriate
567: * Message Facility to dispatch the message.
568: */
569: for (i = 0; msgfacility[i].mf_name; ++i)
570: for (x = 0; msgtypes[x].mt_name; ++x)
571: /*
572: * XXX MT_ALL should not be used directly
573: */
574: if (msgtypes[x].mt_type != MT_ALL &&
575: IS_ON(flags, msgtypes[x].mt_type) &&
576: IS_ON(msgfacility[i].mf_msgtypes,
577: msgtypes[x].mt_type))
578: (*msgfacility[i].mf_sendfunc)(&msgfacility[i],
579: msgtypes[x].mt_type,
580: flags,
581: mbuf);
582: }
583:
584: #if defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
585: /*
586: * Varargs front-end to _message()
587: */
588: extern void message(va_alist)
589: va_dcl
590: {
591: static char buf[MSGBUFSIZ];
592: va_list args;
593: char *fmt;
594: int lvl;
595:
596: va_start(args);
597: lvl = (int) va_arg(args, int);
598: fmt = (char *) va_arg(args, char *);
599: va_end(args);
600:
1.11 ! deraadt 601: (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1 dm 602:
603: _message(lvl, buf);
604: }
605: #endif /* ARG_VARARGS */
606:
607: #if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
608: /*
609: * Stdarg front-end to _message()
610: */
611: extern void message(int lvl, char *fmt, ...)
612: {
613: static char buf[MSGBUFSIZ];
614: va_list args;
615:
616: va_start(args, fmt);
1.11 ! deraadt 617: (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1 dm 618: va_end(args);
619:
620: _message(lvl, buf);
621: }
622: #endif /* ARG_STDARG */
623:
624:
625: #if !defined(ARG_TYPE)
626: /*
627: * Simple front-end to _message()
628: */
629: /*VARARGS2*/
630: extern void message(lvl, fmt, a1, a2, a3, a4, a5)
631: int lvl;
632: char *fmt;
633: {
634: static char buf[MSGBUFSIZ];
635:
1.11 ! deraadt 636: (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5);
1.1 dm 637:
638: _message(lvl, buf);
639: }
640: #endif /* !ARG_TYPE */
641:
642: /*
643: * Display a debugging message
644: */
645: static void _debugmsg(lvl, buf)
646: int lvl;
647: char *buf;
648: {
649: if (IS_ON(debug, lvl))
650: _message(MT_DEBUG, buf);
651: }
652:
653: #if defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
654: /*
655: * Varargs front-end to _debugmsg()
656: */
657: extern void debugmsg(va_alist)
658: va_dcl
659: {
660: static char buf[MSGBUFSIZ];
661: va_list args;
662: char *fmt;
663: int lvl;
664:
665: va_start(args);
666: lvl = (int) va_arg(args, int);
667: fmt = (char *) va_arg(args, char *);
668: va_end(args);
669:
1.11 ! deraadt 670: (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1 dm 671:
672: _debugmsg(lvl, buf);
673: }
674: #endif /* ARG_VARARGS */
675:
676: #if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
677: /*
678: * Stdarg front-end to _debugmsg()
679: */
680: extern void debugmsg(int lvl, char *fmt, ...)
681: {
682: static char buf[MSGBUFSIZ];
683: va_list args;
684:
685: va_start(args, fmt);
1.11 ! deraadt 686: (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1 dm 687: va_end(args);
688:
689: _debugmsg(lvl, buf);
690: }
691: #endif /* ARG_STDARG */
692:
693: #if !defined(ARG_TYPE)
694: /*
695: * Simple front-end to _debugmsg()
696: */
697: /*VARARGS2*/
698: extern void debugmsg(lvl, fmt, a1, a2, a3, a4, a5)
699: int lvl;
700: char *fmt;
701: {
702: static char buf[MSGBUFSIZ];
703:
1.11 ! deraadt 704: (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5);
1.1 dm 705:
706: _debugmsg(lvl, buf);
707: }
708: #endif /* ARG_TYPE */
709:
710: /*
711: * Print an error message
712: */
713: static void _error(msg)
714: char *msg;
715: {
716: static char buf[MSGBUFSIZ];
717:
718: nerrs++;
719: buf[0] = CNULL;
720:
721: if (msg) {
722: if (isserver)
1.11 ! deraadt 723: (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg);
1.1 dm 724: else
1.11 ! deraadt 725: (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg);
1.1 dm 726: }
727:
728: _message(MT_NERROR, (buf[0]) ? buf : NULL);
729: }
730:
731: #if defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
732: /*
733: * Varargs frontend to _error()
734: */
735: extern void error(va_alist)
736: va_dcl
737: {
738: static char buf[MSGBUFSIZ];
739: va_list args;
740: char *fmt;
741:
742: buf[0] = CNULL;
743: va_start(args);
744: fmt = (char *) va_arg(args, char *);
745: if (fmt)
1.11 ! deraadt 746: (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1 dm 747: va_end(args);
748:
749: _error((buf[0]) ? buf : NULL);
750: }
751: #endif /* ARG_VARARGS */
752:
753: #if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
754: /*
755: * Stdarg frontend to _error()
756: */
757: extern void error(char *fmt, ...)
758: {
759: static char buf[MSGBUFSIZ];
760: va_list args;
761:
762: buf[0] = CNULL;
763: va_start(args, fmt);
764: if (fmt)
1.11 ! deraadt 765: (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1 dm 766: va_end(args);
767:
768: _error((buf[0]) ? buf : NULL);
769: }
770: #endif /* ARG_STDARG */
771:
772: #if !defined(ARG_TYPE)
773: /*
774: * Simple frontend to _error()
775: */
776: /*VARARGS1*/
777: extern void error(fmt, a1, a2, a3, a4, a5, a6)
778: char *fmt;
779: {
780: static char buf[MSGBUFSIZ];
781:
782: buf[0] = CNULL;
783: if (fmt)
1.11 ! deraadt 784: (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5, a6);
1.1 dm 785:
786: _error((buf[0]) ? buf : NULL);
787: }
788: #endif /* ARG_TYPE */
789:
790: /*
791: * Display a fatal message
792: */
793: static void _fatalerr(msg)
794: char *msg;
795: {
796: static char buf[MSGBUFSIZ];
797:
798: ++nerrs;
799:
800: if (isserver)
1.11 ! deraadt 801: (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg);
1.1 dm 802: else
1.11 ! deraadt 803: (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg);
1.1 dm 804:
805: _message(MT_FERROR, buf);
806:
807: exit(nerrs);
808: }
809:
810: #if defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
811: /*
812: * Varargs front-end to _fatalerr()
813: */
814: extern void fatalerr(va_alist)
815: va_dcl
816: {
817: static char buf[MSGBUFSIZ];
818: va_list args;
819: char *fmt;
820:
821: va_start(args);
822: fmt = (char *) va_arg(args, char *);
1.11 ! deraadt 823: (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1 dm 824: va_end(args);
825:
826: _fatalerr(buf);
827: }
828: #endif /* ARG_VARARGS */
829:
830: #if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
831: /*
832: * Stdarg front-end to _fatalerr()
833: */
834: extern void fatalerr(char *fmt, ...)
835: {
836: static char buf[MSGBUFSIZ];
837: va_list args;
838:
839: va_start(args, fmt);
1.11 ! deraadt 840: (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1 dm 841: va_end(args);
842:
843: _fatalerr(buf);
844: }
845: #endif /* ARG_STDARG */
846:
847: #if !defined(ARG_TYPE)
848: /*
849: * Simple front-end to _fatalerr()
850: */
851: /*VARARGS1*/
852: extern void fatalerr(fmt, a1, a2, a3, a4, a5)
853: char *fmt;
854: {
855: static char buf[MSGBUFSIZ];
856:
1.11 ! deraadt 857: (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5);
1.1 dm 858:
859: _fatalerr(buf);
860: }
861: #endif /* !ARG_TYPE */
862:
863: /*
864: * Get the name of the file used for notify.
865: * A side effect is that the file pointer to the file
866: * is closed. We assume this function is only called when
867: * we are ready to read the file.
868: */
869: extern char *getnotifyfile()
870: {
1.10 mpech 871: int i;
1.1 dm 872:
873: for (i = 0; msgfacility[i].mf_name; i++)
874: if (msgfacility[i].mf_msgfac == MF_NOTIFY &&
875: msgfacility[i].mf_fptr) {
876: (void) fclose(msgfacility[i].mf_fptr);
877: msgfacility[i].mf_fptr = NULL;
878: return(msgfacility[i].mf_filename);
879: }
880:
1.7 millert 881: return(NULL);
1.1 dm 882: }