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

Annotation of src/usr.bin/rdistd/message.c, Revision 1.3

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