[BACK]Return to message.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rdist

Annotation of src/usr.bin/rdist/message.c, Revision 1.12

1.12    ! deraadt     1: /*     $OpenBSD: message.c,v 1.11 2003/04/05 20:31:58 deraadt 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.12    ! deraadt    42: "$OpenBSD: message.c,v 1.11 2003/04/05 20:31:58 deraadt 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)
1.12    ! deraadt   133:                                        (void) strlcat(buf, ",", sizeof buf);
        !           134:                                (void) strlcat(buf, msgtypes[x].mt_name,
        !           135:                                    sizeof buf);
1.1       dm        136:                        }
                    137:                debugmsg(DM_MISC, "%s", buf);
                    138:        }
                    139:
                    140: }
                    141:
                    142: /*
                    143:  * Get the Message Facility entry "name"
                    144:  */
                    145: static MSGFACILITY *getmsgfac(name)
                    146:        char *name;
                    147: {
1.10      mpech     148:        int i;
1.1       dm        149:
                    150:        for (i = 0; msgfacility[i].mf_name; ++i)
                    151:                if (strcasecmp(name, msgfacility[i].mf_name) == 0)
                    152:                        return(&msgfacility[i]);
                    153:
1.7       millert   154:        return(NULL);
1.1       dm        155: }
                    156:
                    157: /*
                    158:  * Get the Message Type entry named "name"
                    159:  */
                    160: static MSGTYPE *getmsgtype(name)
                    161:        char *name;
                    162: {
1.10      mpech     163:        int i;
1.1       dm        164:
                    165:        for (i = 0; msgtypes[i].mt_name; ++i)
                    166:                if (strcasecmp(name, msgtypes[i].mt_name) == 0)
                    167:                        return(&msgtypes[i]);
                    168:
1.7       millert   169:        return(NULL);
1.1       dm        170: }
                    171:
                    172: /*
                    173:  * Set Message Type information for Message Facility "msgfac" as
                    174:  * indicated by string "str".
                    175:  */
                    176: static char *setmsgtypes(msgfac, str)
                    177:        MSGFACILITY *msgfac;
                    178:        char *str;
                    179: {
                    180:        static char ebuf[BUFSIZ];
1.10      mpech     181:        char *cp;
                    182:        char *strptr, *word;
                    183:        MSGTYPE *mtp;
1.1       dm        184:
                    185:        /*
                    186:         * MF_SYSLOG is the only supported message facility for the server
                    187:         */
                    188:        if (isserver && (msgfac->mf_msgfac != MF_SYSLOG &&
                    189:                         msgfac->mf_msgfac != MF_FILE)) {
1.5       millert   190:                (void) snprintf(ebuf, sizeof(ebuf),
1.1       dm        191:                "The \"%s\" message facility cannot be used by the server.",
1.7       millert   192:                                msgfac->mf_name);
1.1       dm        193:                return(ebuf);
                    194:        }
                    195:
                    196:        strptr = str;
                    197:
                    198:        /*
                    199:         * Do any necessary Message Facility preparation
                    200:         */
                    201:        switch(msgfac->mf_msgfac) {
                    202:        case MF_FILE:
                    203:                /*
                    204:                 * The MF_FILE string should look like "<file>=<types>".
                    205:                 */
                    206:                if ((cp = strchr(strptr, '=')) == NULL)
                    207:                        return(
                    208:                           "No file name found for \"file\" message facility");
                    209:                *cp++ = CNULL;
                    210:
                    211:                if ((msgfac->mf_fptr = fopen(strptr, "w")) == NULL)
                    212:                        fatalerr("Cannot open log file for writing: %s: %s.",
                    213:                                 strptr, SYSERR);
1.8       millert   214:                msgfac->mf_filename = xstrdup(strptr);
1.1       dm        215:
                    216:                strptr = cp;
                    217:                break;
                    218:
                    219:        case MF_NOTIFY:
                    220:                break;
                    221:
                    222:        case MF_STDOUT:
                    223:                msgfac->mf_fptr = stdout;
                    224:                break;
                    225:
                    226:        case MF_SYSLOG:
                    227: #if defined(LOG_OPTS)
                    228: #if    defined(LOG_FACILITY)
                    229:                openlog(progname, LOG_OPTS, LOG_FACILITY);
                    230: #else
                    231:                openlog(progname, LOG_OPTS);
                    232: #endif /* LOG_FACILITY */
                    233: #endif /* LOG_OPTS */
                    234:                break;
                    235:        }
                    236:
                    237:        /*
                    238:         * Parse each type word
                    239:         */
                    240:        msgfac->mf_msgtypes = 0;        /* Start from scratch */
                    241:        while (strptr) {
                    242:                word = strptr;
1.7       millert   243:                if ((cp = strchr(strptr, ',')))
1.1       dm        244:                        *cp++ = CNULL;
                    245:                strptr = cp;
                    246:
1.7       millert   247:                if ((mtp = getmsgtype(word))) {
1.1       dm        248:                        msgfac->mf_msgtypes |= mtp->mt_type;
                    249:                        /*
                    250:                         * XXX This is really a kludge until we add real
                    251:                         * control over debugging.
                    252:                         */
                    253:                        if (!debug && isserver &&
                    254:                            strcasecmp(word, "debug") == 0)
                    255:                                debug = DM_ALL;
                    256:                } else {
1.5       millert   257:                        (void) snprintf(ebuf, sizeof(ebuf),
                    258:                                        "Message type \"%s\" is invalid.",
                    259:                                        word);
1.1       dm        260:                        return(ebuf);
                    261:                }
                    262:        }
                    263:
1.7       millert   264:        return(NULL);
1.1       dm        265: }
                    266:
                    267: /*
                    268:  * Parse a message logging option string
                    269:  */
                    270: extern char *msgparseopts(msgstr, doset)
                    271:        char *msgstr;
                    272:        int doset;
                    273: {
                    274:        static char ebuf[BUFSIZ], msgbuf[MSGBUFSIZ];
1.10      mpech     275:        char *cp, *optstr;
                    276:        char *word;
1.1       dm        277:        MSGFACILITY *msgfac;
                    278:
                    279:        if (msgstr == NULL)
                    280:                return("NULL message string");
                    281:
                    282:        /* strtok() is harmful */
1.11      deraadt   283:        (void) strlcpy(msgbuf, msgstr, sizeof msgbuf);
1.1       dm        284:
                    285:        /*
1.9       provos    286:         * Each <facility>=<types> list is separated by ":".
1.1       dm        287:         */
                    288:        for (optstr = strtok(msgbuf, ":"); optstr;
1.7       millert   289:             optstr = strtok(NULL, ":")) {
1.1       dm        290:
                    291:                if ((cp = strchr(optstr, '=')) == NULL)
                    292:                        return("No '=' found");
                    293:
                    294:                *cp++ = CNULL;
                    295:                word = optstr;
                    296:                if ((int)strlen(word) <= 0)
                    297:                        return("No message facility specified");
                    298:                if ((int)strlen(cp) <= 0)
                    299:                        return("No message type specified");
                    300:
                    301:                if ((msgfac = getmsgfac(word)) == NULL) {
1.5       millert   302:                        (void) snprintf(ebuf, sizeof(ebuf),
                    303:                                        "%s is not a valid message facility",
                    304:                                        word);
1.1       dm        305:                        return(ebuf);
                    306:                }
                    307:
                    308:                if (doset) {
                    309:                        char *mcp;
                    310:
1.7       millert   311:                        if ((mcp = setmsgtypes(msgfac, cp)))
1.1       dm        312:                                return(mcp);
                    313:                }
                    314:        }
                    315:
                    316:        if (isserver && debug) {
                    317:                debugmsg(DM_MISC, "%s", getversion());
                    318:                msgprconfig();
                    319:        }
                    320:
1.7       millert   321:        return(NULL);
1.1       dm        322: }
                    323:
                    324: /*
                    325:  * Send a message to facility "stdout".
                    326:  * For rdistd, this is really the rdist client.
                    327:  */
                    328: static void msgsendstdout(msgfac, mtype, flags, msgbuf)
                    329:        /*ARGSUSED*/
                    330:        MSGFACILITY *msgfac;
                    331:        int mtype;
                    332:        int flags;
                    333:        char *msgbuf;
                    334: {
                    335:        char cmd;
                    336:
                    337:        if (isserver) {
                    338:                if (rem_w < 0 || IS_ON(flags, MT_NOREMOTE))
                    339:                        return;
                    340:
                    341:                cmd = CNULL;
                    342:
                    343:                switch(mtype) {
                    344:                case MT_NERROR:         cmd = C_ERRMSG;         break;
                    345:                case MT_FERROR:         cmd = C_FERRMSG;        break;
                    346:                case MT_NOTICE:         cmd = C_NOTEMSG;        break;
                    347:                case MT_REMOTE:         cmd = C_LOGMSG;         break;
                    348:                }
                    349:
                    350:                if (cmd != CNULL)
                    351:                        (void) sendcmd(cmd, "%s", msgbuf);
                    352:        } else {
                    353:                switch(mtype) {
                    354:                case MT_FERROR:
                    355:                case MT_NERROR:
                    356:                        if (msgbuf && *msgbuf) {
                    357:                                (void) fprintf(stderr, "%s\n", msgbuf);
                    358:                                (void) fflush(stderr);
                    359:                        }
                    360:                        break;
                    361:
                    362:                case MT_DEBUG:
                    363:                        /*
                    364:                         * Only things that are strictly MT_DEBUG should
                    365:                         * be shown.
                    366:                         */
                    367:                        if (flags != MT_DEBUG)
                    368:                                return;
                    369:                case MT_NOTICE:
                    370:                case MT_CHANGE:
                    371:                case MT_INFO:
                    372:                case MT_VERBOSE:
                    373:                case MT_WARNING:
                    374:                        if (msgbuf && *msgbuf) {
                    375:                                (void) printf("%s\n", msgbuf);
                    376:                                (void) fflush(stdout);
                    377:                        }
                    378:                        break;
                    379:                }
                    380:        }
                    381: }
                    382:
                    383: /*
                    384:  * Send a message to facility "syslog"
                    385:  */
                    386: static void msgsendsyslog(msgfac, mtype, flags, msgbuf)
                    387:        /*ARGSUSED*/
                    388:        MSGFACILITY *msgfac;
                    389:        int mtype;
                    390:        int flags;
                    391:        char *msgbuf;
                    392: {
                    393:        int syslvl = 0;
                    394:
                    395:        if (!msgbuf || !*msgbuf)
                    396:                return;
                    397:
                    398:        switch(mtype) {
                    399: #if    defined(SL_NERROR)
                    400:        case MT_NERROR:         syslvl = SL_NERROR;     break;
                    401: #endif
                    402: #if    defined(SL_FERROR)
                    403:        case MT_FERROR:         syslvl = SL_FERROR;     break;
                    404: #endif
                    405: #if    defined(SL_WARNING)
                    406:        case MT_WARNING:        syslvl = SL_WARNING;    break;
                    407: #endif
                    408: #if    defined(SL_CHANGE)
                    409:        case MT_CHANGE:         syslvl = SL_CHANGE;     break;
                    410: #endif
                    411: #if    defined(SL_INFO)
                    412:        case MT_SYSLOG:
                    413:        case MT_VERBOSE:
                    414:        case MT_INFO:           syslvl = SL_INFO;       break;
                    415: #endif
                    416: #if    defined(SL_NOTICE)
                    417:        case MT_NOTICE:         syslvl = SL_NOTICE;     break;
                    418: #endif
                    419: #if    defined(SL_DEBUG)
                    420:        case MT_DEBUG:          syslvl = SL_DEBUG;      break;
                    421: #endif
                    422:        }
                    423:
                    424:        if (syslvl)
                    425:                syslog(syslvl, "%s", msgbuf);
                    426: }
                    427:
                    428: /*
                    429:  * Send a message to a "file" facility.
                    430:  */
                    431: static void msgsendfile(msgfac, mtype, flags, msgbuf)
                    432:        /*ARGSUSED*/
                    433:        MSGFACILITY *msgfac;
                    434:        int mtype;
                    435:        int flags;
                    436:        char *msgbuf;
                    437: {
                    438:        if (msgfac->mf_fptr == NULL)
                    439:                return;
                    440:
                    441:        if (!msgbuf || !*msgbuf)
                    442:                return;
                    443:
                    444:        (void) fprintf(msgfac->mf_fptr, "%s\n", msgbuf);
                    445:        (void) fflush(msgfac->mf_fptr);
                    446: }
                    447:
                    448: /*
                    449:  * Same method as msgsendfile()
                    450:  */
                    451: static void msgsendnotify(msgfac, mtype, flags, msgbuf)
                    452:        /*ARGSUSED*/
                    453:        MSGFACILITY *msgfac;
                    454:        int mtype;
                    455:        int flags;
                    456:        char *msgbuf;
                    457: {
                    458:        if (IS_ON(flags, MT_DEBUG))
                    459:                return;
                    460:
                    461:        if (!msgbuf || !*msgbuf)
                    462:                return;
                    463:
                    464:        if (!msgfac->mf_fptr) {
1.10      mpech     465:                char *cp;
1.7       millert   466:                int fd;
1.1       dm        467:                char *getenv();
1.11      deraadt   468:                size_t len;
1.1       dm        469:
                    470:                /*
                    471:                 * Create and open a new temporary file
                    472:                 */
1.7       millert   473:                if ((cp = getenv("TMPDIR")) == NULL)
1.1       dm        474:                        cp = _PATH_TMP;
1.11      deraadt   475:                len = strlen(cp) + 1 + strlen(_RDIST_TMP) + 2;
                    476:                tempfile = (char *) xmalloc(len);
                    477:                (void) snprintf(tempfile, len, "%s/%s", cp, _RDIST_TMP);
1.1       dm        478:
                    479:                msgfac->mf_filename = tempfile;
1.3       deraadt   480:                if ((fd = mkstemp(msgfac->mf_filename)) == -1 ||
1.6       millert   481:                    (msgfac->mf_fptr = fdopen(fd, "w")) == NULL) {
1.3       deraadt   482:                        if (fd != -1)
                    483:                                close(fd);
1.1       dm        484:                        fatalerr("Cannot open notify file for writing: %s: %s.",
                    485:                              msgfac->mf_filename, SYSERR);
1.3       deraadt   486:                }
1.1       dm        487:                debugmsg(DM_MISC, "Created notify temp file '%s'",
                    488:                         msgfac->mf_filename);
                    489:        }
                    490:
                    491:        if (msgfac->mf_fptr == NULL)
                    492:                return;
                    493:
                    494:        (void) fprintf(msgfac->mf_fptr, "%s\n", msgbuf);
                    495:        (void) fflush(msgfac->mf_fptr);
                    496: }
                    497:
                    498: /*
                    499:  * Insure currenthost is set to something reasonable.
                    500:  */
                    501: extern void checkhostname()
                    502: {
                    503:        static char mbuf[MAXHOSTNAMELEN];
                    504:        char *cp;
                    505:
                    506:        if (!currenthost) {
                    507:                if (gethostname(mbuf, sizeof(mbuf)) == 0) {
                    508:                        if ((cp = strchr(mbuf, '.')) != NULL)
                    509:                                *cp = CNULL;
1.8       millert   510:                        currenthost = xstrdup(mbuf);
1.1       dm        511:                } else
                    512:                        currenthost = "(unknown)";
                    513:        }
                    514: }
                    515:
                    516: /*
                    517:  * Print a message contained in "msgbuf" if a level "lvl" is set.
                    518:  */
                    519: static void _message(flags, msgbuf)
                    520:        int flags;
                    521:        char *msgbuf;
                    522: {
1.10      mpech     523:        int i, x;
                    524:        char *cp;
1.1       dm        525:        static char mbuf[2048];
                    526:
                    527:        if (msgbuf && *msgbuf) {
                    528:                /*
                    529:                 * Ensure no stray newlines are present
                    530:                 */
1.7       millert   531:                if ((cp = strchr(msgbuf, '\n')))
1.1       dm        532:                        *cp = CNULL;
                    533:
                    534:                checkhostname();
                    535:                if (strncmp(currenthost, msgbuf, strlen(currenthost)) == 0)
1.11      deraadt   536:                        (void) strlcpy(mbuf, msgbuf, sizeof mbuf);
1.1       dm        537:                else
1.11      deraadt   538:                        (void) snprintf(mbuf, sizeof mbuf,
                    539:                            "%s: %s", currenthost, msgbuf);
1.1       dm        540:        } else
1.11      deraadt   541:                (void) strlcpy(mbuf, "", sizeof mbuf);
1.1       dm        542:
                    543:        /*
                    544:         * Special case for messages that only get
                    545:         * logged to the system log facility
                    546:         */
                    547:        if (IS_ON(flags, MT_SYSLOG)) {
1.7       millert   548:                msgsendsyslog(NULL, MT_SYSLOG, flags, mbuf);
1.1       dm        549:                return;
                    550:        }
                    551:
                    552:        /*
                    553:         * Special cases
                    554:         */
1.5       millert   555:        if (isserver && IS_ON(flags, MT_NOTICE)) {
1.7       millert   556:                msgsendstdout(NULL, MT_NOTICE, flags, mbuf);
1.5       millert   557:                return;
                    558:        } else if (isserver && IS_ON(flags, MT_REMOTE))
1.7       millert   559:                msgsendstdout(NULL, MT_REMOTE, flags, mbuf);
1.1       dm        560:        else if (isserver && IS_ON(flags, MT_NERROR))
1.7       millert   561:                msgsendstdout(NULL, MT_NERROR, flags, mbuf);
1.1       dm        562:        else if (isserver && IS_ON(flags, MT_FERROR))
1.7       millert   563:                msgsendstdout(NULL, MT_FERROR, flags, mbuf);
1.1       dm        564:
                    565:        /*
                    566:         * For each Message Facility, check each Message Type to see
                    567:         * if the bits in "flags" are set.  If so, call the appropriate
                    568:         * Message Facility to dispatch the message.
                    569:         */
                    570:        for (i = 0; msgfacility[i].mf_name; ++i)
                    571:                for (x = 0; msgtypes[x].mt_name; ++x)
                    572:                        /*
                    573:                         * XXX MT_ALL should not be used directly
                    574:                         */
                    575:                        if (msgtypes[x].mt_type != MT_ALL &&
                    576:                            IS_ON(flags, msgtypes[x].mt_type) &&
                    577:                            IS_ON(msgfacility[i].mf_msgtypes,
                    578:                                  msgtypes[x].mt_type))
                    579:                                (*msgfacility[i].mf_sendfunc)(&msgfacility[i],
                    580:                                                           msgtypes[x].mt_type,
                    581:                                                              flags,
                    582:                                                              mbuf);
                    583: }
                    584:
                    585: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
                    586: /*
                    587:  * Varargs front-end to _message()
                    588:  */
                    589: extern void message(va_alist)
                    590:        va_dcl
                    591: {
                    592:        static char buf[MSGBUFSIZ];
                    593:        va_list args;
                    594:        char *fmt;
                    595:        int lvl;
                    596:
                    597:        va_start(args);
                    598:        lvl = (int) va_arg(args, int);
                    599:        fmt = (char *) va_arg(args, char *);
                    600:        va_end(args);
                    601:
1.11      deraadt   602:        (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1       dm        603:
                    604:        _message(lvl, buf);
                    605: }
                    606: #endif /* ARG_VARARGS */
                    607:
                    608: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
                    609: /*
                    610:  * Stdarg front-end to _message()
                    611:  */
                    612: extern void message(int lvl, char *fmt, ...)
                    613: {
                    614:        static char buf[MSGBUFSIZ];
                    615:        va_list args;
                    616:
                    617:        va_start(args, fmt);
1.11      deraadt   618:        (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1       dm        619:        va_end(args);
                    620:
                    621:        _message(lvl, buf);
                    622: }
                    623: #endif /* ARG_STDARG */
                    624:
                    625:
                    626: #if    !defined(ARG_TYPE)
                    627: /*
                    628:  * Simple front-end to _message()
                    629:  */
                    630: /*VARARGS2*/
                    631: extern void message(lvl, fmt, a1, a2, a3, a4, a5)
                    632:        int lvl;
                    633:        char *fmt;
                    634: {
                    635:        static char buf[MSGBUFSIZ];
                    636:
1.11      deraadt   637:        (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5);
1.1       dm        638:
                    639:        _message(lvl, buf);
                    640: }
                    641: #endif /* !ARG_TYPE */
                    642:
                    643: /*
                    644:  * Display a debugging message
                    645:  */
                    646: static void _debugmsg(lvl, buf)
                    647:        int lvl;
                    648:        char *buf;
                    649: {
                    650:        if (IS_ON(debug, lvl))
                    651:                _message(MT_DEBUG, buf);
                    652: }
                    653:
                    654: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
                    655: /*
                    656:  * Varargs front-end to _debugmsg()
                    657:  */
                    658: extern void debugmsg(va_alist)
                    659:        va_dcl
                    660: {
                    661:        static char buf[MSGBUFSIZ];
                    662:        va_list args;
                    663:        char *fmt;
                    664:        int lvl;
                    665:
                    666:        va_start(args);
                    667:        lvl = (int) va_arg(args, int);
                    668:        fmt = (char *) va_arg(args, char *);
                    669:        va_end(args);
                    670:
1.11      deraadt   671:        (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1       dm        672:
                    673:        _debugmsg(lvl, buf);
                    674: }
                    675: #endif /* ARG_VARARGS */
                    676:
                    677: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
                    678: /*
                    679:  * Stdarg front-end to _debugmsg()
                    680:  */
                    681: extern void debugmsg(int lvl, char *fmt, ...)
                    682: {
                    683:        static char buf[MSGBUFSIZ];
                    684:        va_list args;
                    685:
                    686:        va_start(args, fmt);
1.11      deraadt   687:        (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1       dm        688:        va_end(args);
                    689:
                    690:        _debugmsg(lvl, buf);
                    691: }
                    692: #endif /* ARG_STDARG */
                    693:
                    694: #if    !defined(ARG_TYPE)
                    695: /*
                    696:  * Simple front-end to _debugmsg()
                    697:  */
                    698: /*VARARGS2*/
                    699: extern void debugmsg(lvl, fmt, a1, a2, a3, a4, a5)
                    700:        int lvl;
                    701:        char *fmt;
                    702: {
                    703:        static char buf[MSGBUFSIZ];
                    704:
1.11      deraadt   705:        (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5);
1.1       dm        706:
                    707:        _debugmsg(lvl, buf);
                    708: }
                    709: #endif /* ARG_TYPE */
                    710:
                    711: /*
                    712:  * Print an error message
                    713:  */
                    714: static void _error(msg)
                    715:        char *msg;
                    716: {
                    717:        static char buf[MSGBUFSIZ];
                    718:
                    719:        nerrs++;
                    720:        buf[0] = CNULL;
                    721:
                    722:        if (msg) {
                    723:                if (isserver)
1.11      deraadt   724:                        (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg);
1.1       dm        725:                else
1.11      deraadt   726:                        (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg);
1.1       dm        727:        }
                    728:
                    729:        _message(MT_NERROR, (buf[0]) ? buf : NULL);
                    730: }
                    731:
                    732: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
                    733: /*
                    734:  * Varargs frontend to _error()
                    735:  */
                    736: extern void error(va_alist)
                    737:        va_dcl
                    738: {
                    739:        static char buf[MSGBUFSIZ];
                    740:        va_list args;
                    741:        char *fmt;
                    742:
                    743:        buf[0] = CNULL;
                    744:        va_start(args);
                    745:        fmt = (char *) va_arg(args, char *);
                    746:        if (fmt)
1.11      deraadt   747:                (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1       dm        748:        va_end(args);
                    749:
                    750:        _error((buf[0]) ? buf : NULL);
                    751: }
                    752: #endif /* ARG_VARARGS */
                    753:
                    754: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
                    755: /*
                    756:  * Stdarg frontend to _error()
                    757:  */
                    758: extern void error(char *fmt, ...)
                    759: {
                    760:        static char buf[MSGBUFSIZ];
                    761:        va_list args;
                    762:
                    763:        buf[0] = CNULL;
                    764:        va_start(args, fmt);
                    765:        if (fmt)
1.11      deraadt   766:                (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1       dm        767:        va_end(args);
                    768:
                    769:        _error((buf[0]) ? buf : NULL);
                    770: }
                    771: #endif /* ARG_STDARG */
                    772:
                    773: #if    !defined(ARG_TYPE)
                    774: /*
                    775:  * Simple frontend to _error()
                    776:  */
                    777: /*VARARGS1*/
                    778: extern void error(fmt, a1, a2, a3, a4, a5, a6)
                    779:        char *fmt;
                    780: {
                    781:        static char buf[MSGBUFSIZ];
                    782:
                    783:        buf[0] = CNULL;
                    784:        if (fmt)
1.11      deraadt   785:                (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5, a6);
1.1       dm        786:
                    787:        _error((buf[0]) ? buf : NULL);
                    788: }
                    789: #endif /* ARG_TYPE */
                    790:
                    791: /*
                    792:  * Display a fatal message
                    793:  */
                    794: static void _fatalerr(msg)
                    795:        char *msg;
                    796: {
                    797:        static char buf[MSGBUFSIZ];
                    798:
                    799:        ++nerrs;
                    800:
                    801:        if (isserver)
1.11      deraadt   802:                (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg);
1.1       dm        803:        else
1.11      deraadt   804:                (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg);
1.1       dm        805:
                    806:        _message(MT_FERROR, buf);
                    807:
                    808:        exit(nerrs);
                    809: }
                    810:
                    811: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
                    812: /*
                    813:  * Varargs front-end to _fatalerr()
                    814:  */
                    815: extern void fatalerr(va_alist)
                    816:        va_dcl
                    817: {
                    818:        static char buf[MSGBUFSIZ];
                    819:        va_list args;
                    820:        char *fmt;
                    821:
                    822:        va_start(args);
                    823:        fmt = (char *) va_arg(args, char *);
1.11      deraadt   824:        (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1       dm        825:        va_end(args);
                    826:
                    827:        _fatalerr(buf);
                    828: }
                    829: #endif /* ARG_VARARGS */
                    830:
                    831: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
                    832: /*
                    833:  * Stdarg front-end to _fatalerr()
                    834:  */
                    835: extern void fatalerr(char *fmt, ...)
                    836: {
                    837:        static char buf[MSGBUFSIZ];
                    838:        va_list args;
                    839:
                    840:        va_start(args, fmt);
1.11      deraadt   841:        (void) vsnprintf(buf, sizeof buf, fmt, args);
1.1       dm        842:        va_end(args);
                    843:
                    844:        _fatalerr(buf);
                    845: }
                    846: #endif /* ARG_STDARG */
                    847:
                    848: #if    !defined(ARG_TYPE)
                    849: /*
                    850:  * Simple front-end to _fatalerr()
                    851:  */
                    852: /*VARARGS1*/
                    853: extern void fatalerr(fmt, a1, a2, a3, a4, a5)
                    854:        char *fmt;
                    855: {
                    856:        static char buf[MSGBUFSIZ];
                    857:
1.11      deraadt   858:        (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5);
1.1       dm        859:
                    860:        _fatalerr(buf);
                    861: }
                    862: #endif /* !ARG_TYPE */
                    863:
                    864: /*
                    865:  * Get the name of the file used for notify.
                    866:  * A side effect is that the file pointer to the file
                    867:  * is closed.  We assume this function is only called when
                    868:  * we are ready to read the file.
                    869:  */
                    870: extern char *getnotifyfile()
                    871: {
1.10      mpech     872:        int i;
1.1       dm        873:
                    874:        for (i = 0; msgfacility[i].mf_name; i++)
                    875:                if (msgfacility[i].mf_msgfac == MF_NOTIFY &&
                    876:                    msgfacility[i].mf_fptr) {
                    877:                        (void) fclose(msgfacility[i].mf_fptr);
                    878:                        msgfacility[i].mf_fptr = NULL;
                    879:                        return(msgfacility[i].mf_filename);
                    880:                }
                    881:
1.7       millert   882:        return(NULL);
1.1       dm        883: }