[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.4

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