[BACK]Return to parse.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / libexec / identd

Annotation of src/libexec/identd/parse.c, Revision 1.10

1.10    ! mycroft     1: /*     $NetBSD: parse.c,v 1.9 1998/07/15 07:31:57 msaitoh Exp $        */
1.8       mrg         2:
1.1       cgd         3: /*
                      4: ** parse.c                         This file contains the protocol parser
                      5: **
                      6: ** This program is in the public domain and may be used freely by anyone
1.9       msaitoh     7: ** who wants to.
1.1       cgd         8: **
1.9       msaitoh     9: ** Last update: 23 Feb 1994
1.1       cgd        10: **
                     11: ** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se>
                     12: */
                     13:
1.9       msaitoh    14: #ifdef NeXT31
                     15: #  include <libc.h>
                     16: #endif
                     17:
1.1       cgd        18: #include <stdio.h>
1.9       msaitoh    19: #include <stdlib.h>
1.4       cgd        20: #include <string.h>
1.1       cgd        21: #include <errno.h>
                     22: #include <ctype.h>
                     23: #include <pwd.h>
1.9       msaitoh    24: #ifdef ALLOW_FORMAT
                     25: #  include <grp.h>
                     26: #endif
1.1       cgd        27:
                     28: #include <sys/types.h>
                     29: #include <netinet/in.h>
                     30:
                     31: #ifndef HPUX7
                     32: #  include <arpa/inet.h>
                     33: #endif
                     34:
1.2       cgd        35: #include <kvm.h>
1.1       cgd        36:
                     37: #include <sys/types.h>
                     38: #include <sys/stat.h>
                     39:
                     40: #if defined(MIPS) || defined(BSD43)
                     41: extern int errno;
                     42: #endif
                     43:
1.9       msaitoh    44: #if defined(SOLARIS) || defined(__linux__)
                     45: #  include <string.h>
                     46: #  include <stdlib.h>
                     47: #endif
                     48:
1.1       cgd        49: #include "identd.h"
                     50: #include "error.h"
                     51:
1.8       mrg        52: static int eat_whitespace __P((void));
1.10    ! mycroft    53: static int check_noident __P((const char *));
1.9       msaitoh    54: static int valid_fhost(struct in_addr *, char *);
1.1       cgd        55:
                     56: /*
                     57: ** This function will eat whitespace characters until
                     58: ** either a non-whitespace character is read, or EOF
                     59: ** occurs. This function is only used if the "-m" option
                     60: ** is enabled.
                     61: */
                     62: static int eat_whitespace()
                     63: {
                     64:   int c;
                     65:
1.9       msaitoh    66:
1.1       cgd        67:   while ((c = getchar()) != EOF &&
                     68:         !(c == '\r' || c == '\n'))
                     69:     ;
                     70:
                     71:   if (c != EOF)
                     72:     while ((c = getchar()) != EOF &&
                     73:           (c == ' ' || c == '\t' || c == '\n' || c == '\r'))
                     74:       ;
                     75:
                     76:   if (c != EOF)
                     77:     ungetc(c, stdin);
1.9       msaitoh    78:
1.1       cgd        79:   return (c != EOF);
                     80: }
                     81:
                     82:
                     83: #ifdef INCLUDE_EXTENSIONS
                     84: /*
                     85: ** Validate an indirect request
                     86: */
                     87: static int valid_fhost(faddr, password)
                     88:   struct in_addr *faddr;
                     89:   char *password;
                     90: {
                     91:   if (indirect_host == NULL)
                     92:     return 0;
                     93:
                     94:   if (strcmp(indirect_host, "*") != 0)
                     95:   {
                     96:     if (isdigit(indirect_host[0]))
                     97:     {
                     98:       if (strcmp(inet_ntoa(*faddr), indirect_host))
                     99:       {
1.9       msaitoh   100:        syslog(LOG_NOTICE, "valid_fhost: Access Denied for: %s",
1.1       cgd       101:               gethost(faddr));
                    102:        return 0;
                    103:       }
                    104:     }
                    105:     else
                    106:     {
                    107:       if (strcmp(gethost(faddr), indirect_host))
                    108:       {
1.9       msaitoh   109:        syslog(LOG_NOTICE, "valid_fhost: Access Denied for: %s",
1.1       cgd       110:               gethost(faddr));
                    111:        return 0;
                    112:       }
                    113:     }
                    114:   }
1.9       msaitoh   115:
1.1       cgd       116:   if (indirect_password == NULL)
                    117:     return 1;
1.9       msaitoh   118:
1.1       cgd       119:   if (strcmp(password, indirect_password))
                    120:   {
1.9       msaitoh   121:     syslog(LOG_NOTICE, "valid_fhost: Invalid password from: %s",
1.1       cgd       122:           gethost(faddr));
                    123:     return 0;
                    124:   }
                    125:
                    126:   return 1;
                    127: }
                    128: #endif
                    129:
                    130: /*
                    131: ** A small routine to check for the existance of the ".noident"
                    132: ** file in a users home directory.
                    133: */
                    134: static int check_noident(homedir)
1.10    ! mycroft   135:   const char *homedir;
1.1       cgd       136: {
                    137:   char *tmp_path;
                    138:   struct stat sbuf;
                    139:   int rcode;
1.9       msaitoh   140:
1.1       cgd       141:
                    142:   if (!homedir)
                    143:     return 0;
1.9       msaitoh   144:
1.1       cgd       145:   tmp_path = (char *) malloc(strlen(homedir) + sizeof("/.noident") + 1);
                    146:   if (!tmp_path)
                    147:     return 0;
                    148:
                    149:   strcpy(tmp_path, homedir);
                    150:   strcat(tmp_path, "/.noident");
                    151:
                    152:   rcode = stat(tmp_path, &sbuf);
                    153:   free(tmp_path);
                    154:
                    155:   return (rcode == 0);
                    156: }
                    157:
1.9       msaitoh   158: #ifdef INCLUDE_CRYPT
                    159: /*
                    160: ** Checks address of incoming call against network/mask pairs of trusted
                    161: ** networks to determine whether to crypt response or not.
                    162: */
                    163: int check_crypt(faddr)
                    164:   struct in_addr *faddr;
                    165: {
                    166:   int i;
                    167:   extern int netcnt;
                    168:   extern u_long localnet[], localmask[];
                    169:
                    170:   for (i = 0; i < netcnt; i++) {
                    171:     if ((faddr->s_addr & localmask[i]) == localnet[i])
                    172:       return 0;
                    173:   }
                    174:   return 1;
                    175: }
                    176: #endif
1.1       cgd       177:
                    178: int parse(fp, laddr, faddr)
                    179:   FILE *fp;
                    180:   struct in_addr *laddr, *faddr;
                    181: {
                    182:   int uid, try, rcode;
                    183:   struct passwd *pwp;
1.9       msaitoh   184: #ifdef ALLOW_FORMAT
                    185:   int pid;
                    186:   char *cmd, *cmd_and_args;
                    187:   struct group *grp;
                    188:   char grname[128];
                    189: #endif
1.1       cgd       190:   char lhostaddr[16];
                    191:   char fhostaddr[16];
                    192:   char password[33];
1.9       msaitoh   193: #if defined(INCLUDE_EXTENSIONS) || defined(STRONG_LOG)
1.1       cgd       194:   char arg[33];
1.9       msaitoh   195: #endif
                    196: #ifdef INCLUDE_EXTENSIONS
1.1       cgd       197:   int c;
                    198: #endif
                    199:   struct in_addr laddr2;
                    200:   struct in_addr faddr2;
1.9       msaitoh   201:   int k_opened;
                    202:
                    203:   k_opened = 0;
                    204:
                    205:
1.1       cgd       206:   if (debug_flag && syslog_flag)
                    207:     syslog(LOG_DEBUG, "In function parse()");
1.9       msaitoh   208:
                    209:
1.1       cgd       210:   /*
                    211:   ** Get the local/foreign port pair from the luser
                    212:   */
                    213:   do
                    214:   {
                    215:     if (debug_flag && syslog_flag)
                    216:       syslog(LOG_DEBUG, "  Before fscanf()");
1.9       msaitoh   217:
1.1       cgd       218:     faddr2 = *faddr;
                    219:     laddr2 = *laddr;
                    220:     lport = fport = 0;
                    221:     lhostaddr[0] = fhostaddr[0] = password[0] = '\0';
                    222:
1.9       msaitoh   223:
1.1       cgd       224:     /* Read query from client */
                    225:     rcode = fscanf(fp, " %d , %d", &lport, &fport);
                    226:
                    227: #ifdef INCLUDE_EXTENSIONS
                    228:     /*
                    229:     ** Do additional parsing in case of extended request
                    230:     */
                    231:     if (rcode == 0)
                    232:     {
                    233:       rcode = fscanf(fp, "%32[^ \t\n\r:]", arg);
                    234:
                    235:       /* Skip leading space up to EOF, EOL or non-space char */
                    236:       while ((c = getc(fp)) == ' ' || c == '\t')
                    237:        ;
1.9       msaitoh   238:
1.1       cgd       239:       if (rcode <= 0)
                    240:       {
1.9       msaitoh   241: #ifdef STRONG_LOG
                    242:        if (syslog_flag)
                    243:              syslog(LOG_NOTICE, "from: %s (%s) INVALID REQUEST",
                    244:                     inet_ntoa(*faddr), gethost(faddr));
                    245: #endif
1.1       cgd       246:        printf("%d , %d : ERROR : %s\r\n",
                    247:               lport, fport,
                    248:               unknown_flag ? "UNKNOWN-ERROR" : "X-INVALID-REQUEST");
                    249:        continue;
                    250:       }
                    251:
                    252:       /*
                    253:       ** Non-standard extended request, returns with Pidentd
                    254:       ** version information
                    255:       */
                    256:       if (strcmp(arg, "VERSION") == 0)
                    257:       {
1.9       msaitoh   258: #ifdef STRONG_LOG
                    259:          if (syslog_flag)
                    260:              syslog(LOG_NOTICE, "from: %s (%s) VERSION REQUEST",
                    261:                     inet_ntoa(*faddr), gethost(faddr));
                    262: #endif
                    263: #if defined(__TIME__) && defined(__DATE__)
                    264:        printf("%d , %d : X-VERSION : %s (Compiled: %s %s)\r\n", lport, fport,
                    265:               version, __TIME__, __DATE__);
                    266: #else
                    267:        printf("%d , %d : X-VERSION : %s\r\n", lport, fport,
1.1       cgd       268:               version);
1.9       msaitoh   269: #endif
1.1       cgd       270:        continue;
                    271:       }
                    272:
                    273:       /*
                    274:       ** Non-standard extended proxy request
                    275:       */
                    276:       else if (strcmp(arg, "PROXY") == 0 && c == ':')
                    277:       {
                    278:        /* We have a colon char, check for port numbers */
                    279:        rcode = fscanf(fp, " %d , %d : %15[0-9.] , %15[0-9.]",
                    280:                       &lport, &fport, fhostaddr, lhostaddr);
                    281:
                    282:        if (!(rcode == 3 || rcode == 4))
                    283:        {
1.9       msaitoh   284: #ifdef STRONG_LOG
                    285:            if (syslog_flag)
                    286:                syslog(LOG_NOTICE, "from: %s (%s) INVALID PROXY REQUEST",
                    287:                       inet_ntoa(*faddr), gethost(faddr));
                    288: #endif
                    289:
1.1       cgd       290:          printf("%d , %d : ERROR : %s\r\n",
                    291:                 lport, fport,
                    292:                 unknown_flag ? "UNKNOWN-ERROR" : "X-INVALID-REQUEST");
                    293:          continue;
                    294:        }
                    295:
                    296:        if (rcode == 4)
1.9       msaitoh   297:          laddr2.s_addr = inet_addr(lhostaddr);
                    298:
                    299:        faddr2.s_addr = inet_addr(fhostaddr);
                    300:
                    301: #ifdef STRONG_LOG
                    302:        if (syslog_flag)
                    303:        {
                    304:            char a1[64], a2[64], a3[64];
                    305:
                    306:            strcpy(a1, inet_ntoa(*faddr));
                    307:            strcpy(a2, inet_ntoa(faddr2));
                    308:            strcpy(a3, inet_ntoa(laddr2));
                    309:
                    310:            syslog(LOG_NOTICE,
                    311:                   "from: %s (%s) PROXY REQUEST for %d, %d between %s and %s",
                    312:                   a1, gethost(faddr), lport, fport, a2, a3);
                    313:        }
                    314: #endif
1.1       cgd       315:
                    316:        proxy(&laddr2, &faddr2, lport, fport, NULL);
                    317:        continue;
                    318:       }
1.9       msaitoh   319:
1.1       cgd       320:       /*
                    321:       ** Non-standard extended remote indirect request
                    322:       */
                    323:       else if (strcmp(arg, "REMOTE") == 0 && c == ':')
                    324:       {
                    325:        /* We have a colon char, check for port numbers */
                    326:        rcode = fscanf(fp, " %d , %d", &lport, &fport);
1.9       msaitoh   327:
1.1       cgd       328:        /* Skip leading space up to EOF, EOL or non-space char */
                    329:        while ((c = getc(fp)) == ' ' || c == '\t')
                    330:          ;
                    331:
                    332:        if (rcode != 2 || c != ':')
                    333:        {
1.9       msaitoh   334: #ifdef STRONG_LOG
                    335:            if (syslog_flag)
                    336:                syslog(LOG_NOTICE, "from: %s (%s) INVALID REMOTE REQUEST",
                    337:                       inet_ntoa(*faddr), gethost(faddr));
                    338: #endif
                    339:
1.1       cgd       340:          printf("%d , %d : ERROR : %s\r\n",
                    341:                 lport, fport,
                    342:                 unknown_flag ? "UNKNOWN-ERROR" : "X-INVALID-REQUEST");
                    343:          continue;
                    344:        }
1.9       msaitoh   345:
1.1       cgd       346:        /* We have a colon char, check for addr and password */
                    347:        rcode = fscanf(fp, " %15[0-9.] , %32[^ \t\r\n]",
                    348:                       fhostaddr, password);
                    349:        if (rcode > 0)
                    350:          rcode += 2;
                    351:        else
                    352:        {
1.9       msaitoh   353: #ifdef STRONG_LOG
                    354:            if (syslog_flag)
                    355:                syslog(LOG_NOTICE,
                    356:                       "from: %s (%s) INVALID REMOTE REQUEST for %d, %d",
                    357:                       inet_ntoa(*faddr), gethost(faddr), lport, fport);
                    358: #endif
                    359:            printf("%d , %d : ERROR : %s\r\n",
                    360:                   lport, fport,
                    361:                   unknown_flag ? "UNKNOWN-ERROR" : "X-INVALID-REQUEST");
                    362:            continue;
1.1       cgd       363:        }
1.9       msaitoh   364:
1.1       cgd       365:        /*
                    366:        ** Verify that the host originating the indirect request
                    367:        ** is allowed to do that
                    368:        */
                    369:        if (!valid_fhost(faddr, password))
                    370:        {
1.9       msaitoh   371: #ifdef STRONG_LOG
                    372:            if (syslog_flag)
                    373:                syslog(LOG_NOTICE,
                    374:        "from: %s (%s) REJECTED REMOTE REQUEST for %d, %d with password %s",
                    375:                       inet_ntoa(*faddr), gethost(faddr), lport, fport,
                    376:                       password);
                    377: #endif
                    378:            printf("%d , %d : ERROR : %s\r\n",
                    379:                   lport, fport,
                    380:                   unknown_flag ? "UNKNOWN-ERROR" : "X-ACCESS-DENIED");
                    381:            continue;
                    382:        }
                    383:
                    384:        faddr2.s_addr = inet_addr(fhostaddr);
                    385: #ifdef STRONG_LOG
                    386:        if (syslog_flag)
                    387:        {
                    388:            char a1[64];
                    389:
                    390:            strcpy(a1, inet_ntoa(*faddr));
                    391:
                    392:            syslog(LOG_INFO,
                    393:           "from: %s (%s) REMOTE REQUEST for %d, %d from %s with password %s",
                    394:                   a1, gethost(faddr), lport, fport,
                    395:                   inet_ntoa(faddr2), password);
                    396:        }
                    397: #endif
                    398:     }
                    399:
                    400:       else
                    401:       {
                    402: #ifdef STRONG_LOG
                    403:          if (syslog_flag)
                    404:              syslog(LOG_NOTICE, "from: %s (%s) UNKNOWN REQUEST: %s",
                    405:                     inet_ntoa(*faddr), gethost(faddr), arg);
                    406: #endif
                    407:
1.1       cgd       408:          printf("%d , %d : ERROR : %s\r\n",
                    409:                 lport, fport,
1.9       msaitoh   410:                 unknown_flag ? "UNKNOWN-ERROR" : "X-INVALID-REQUEST");
1.1       cgd       411:          continue;
                    412:       }
                    413:     }
                    414: #endif /* EXTENSIONS */
1.9       msaitoh   415:
1.1       cgd       416:     if (rcode < 2 || lport < 1 || lport > 65535 || fport < 1 || fport > 65535)
                    417:     {
1.9       msaitoh   418: #ifdef STRONG_LOG
                    419:        if (syslog_flag)
                    420:        {
                    421:            if (rcode > 0)
                    422:                /* we have scanned at least one correct port */
                    423:                syslog(LOG_NOTICE,
                    424:                       "from: %s (%s) for invalid-port(s): %d , %d",
                    425:                       inet_ntoa(*faddr), gethost(faddr), lport, fport);
                    426:            else
                    427:            {
                    428:                /* we have scanned nothing at all so try to get the rest */
                    429:                if (fscanf(fp, "%32[^\n\r]", arg) <= 0)
                    430:                    syslog(LOG_NOTICE, "from: %s (%s) EMPTY REQUEST",
                    431:                           inet_ntoa(*faddr), gethost(faddr));
                    432:                else
                    433:                    syslog(LOG_NOTICE, "from: %s (%s) INVALID REQUEST: %s",
                    434:                           inet_ntoa(*faddr), gethost(faddr), arg);
                    435:            }
                    436:        }
                    437: #else
                    438:        if (syslog_flag && rcode > 0)
                    439:            syslog(LOG_NOTICE, "scanf: invalid-port(s): %d , %d from %s",
                    440:                   lport, fport, gethost(faddr));
                    441: #endif
                    442:
1.1       cgd       443:       printf("%d , %d : ERROR : %s\r\n",
                    444:             lport, fport,
                    445:             unknown_flag ? "UNKNOWN-ERROR" : "INVALID-PORT");
                    446:       continue;
                    447:     }
                    448:
1.9       msaitoh   449: #ifdef STRONG_LOG
                    450:       if (syslog_flag)
                    451:       {
                    452:          syslog(LOG_INFO, "from: %s ( %s ) for: %d, %d",
                    453:                 inet_ntoa(*faddr), gethost(faddr), lport, fport);
                    454:       }
                    455: #endif
                    456:
                    457:     if (debug_flag && syslog_flag)
                    458:       syslog(LOG_DEBUG, "  After fscanf(), before k_open()");
                    459:
                    460:
                    461:     if (! k_opened)
                    462:     {
                    463:       /*
                    464:       ** Open the kernel memory device and read the nlist table
                    465:       **
                    466:       ** Of course k_open should not call ERROR (which then exits)
                    467:       ** but maybe use syslog(LOG_ERR) and return non-zero. But I am
                    468:       ** too lazy to change them all ...
                    469:       */
                    470:       if (k_open() != 0)
                    471:       {
                    472:        if (syslog_flag) syslog(LOG_ERR, "k_open call failed");
                    473:        printf("%d , %d : ERROR : %s\r\n",
                    474:             lport, fport,
                    475:             unknown_flag ? "UNKNOWN-ERROR" : "X-CANNOT-OPEN-KMEM");
                    476:        continue;
                    477:       }
                    478:       k_opened = 1;
                    479:     }
                    480:
1.3       cgd       481:
1.1       cgd       482:     if (debug_flag && syslog_flag)
1.9       msaitoh   483:       syslog(LOG_DEBUG, "  After k_open(), before k_getuid()");
                    484:
                    485:
1.1       cgd       486:     /*
1.9       msaitoh   487:     ** Get the specific TCP connection and return the uid - user number.
                    488:     */
                    489:
                    490: #ifdef ALLOW_FORMAT
                    491:     /* Initialize values, for architectures that do not set it */
                    492:     pid = 0;
                    493:     cmd = "";
                    494:     cmd_and_args = "";
                    495: #endif
                    496:
                    497: #define MAX_RETRY 20
                    498:     /*
                    499:     ** Try to fetch the information MAX_RETRY times in case the
                    500:     ** kernel changed beneath us and we missed or took a fault.
1.1       cgd       501:     **
1.9       msaitoh   502:     ** Why would we ever fail? Is not there a reliable way for the
                    503:     ** kernel to identify its sockets? Cannot we use that interface?
                    504:     **
                    505:     ** Used to be 5 times, but often this is not enough on Alpha OSF.
1.1       cgd       506:     */
1.9       msaitoh   507: /* #define SLEEP_BETWEEN_RETRIES 1 */
                    508:     /*
                    509:     ** If we failed in k_getuid, that is presumably because the OS was
                    510:     ** busy creating or destroying processes. We may want to sleep for
                    511:     ** a random time between retries, hoping for peace and quiet.
                    512:     */
                    513:
                    514: /* k_getuid returns 0 on success, any non-zero on failure. */
                    515:
1.1       cgd       516:     for (try = 0;
1.9       msaitoh   517:         (try < MAX_RETRY &&
                    518:           k_getuid(&faddr2, htons(fport), laddr, htons(lport), &uid
                    519: #ifdef ALLOW_FORMAT
                    520:                    , &pid, &cmd, &cmd_and_args
                    521: #endif
                    522:                    ) != 0);
1.1       cgd       523:         try++)
1.9       msaitoh   524: #ifdef SLEEP_BETWEEN_RETRIES
                    525:       {
                    526:        /* Seed the generator: lport should be unique (among other concurrent identd's) */
                    527:        if (try < 1) srandom(lport);
                    528:        /* This gives a max sleep of 0xffff = 65535 microsecs, about 32millisec average */
                    529:        usleep(random()&0x00ffff);
                    530:       }
                    531: #else
1.1       cgd       532:       ;
1.9       msaitoh   533: #endif
1.1       cgd       534:
1.9       msaitoh   535:     if (try >= MAX_RETRY)
1.1       cgd       536:     {
                    537:       if (syslog_flag)
1.9       msaitoh   538:        syslog(LOG_INFO, "Returned: %d , %d : NO-USER", lport, fport);
                    539:
1.1       cgd       540:       printf("%d , %d : ERROR : %s\r\n",
                    541:             lport, fport,
                    542:             unknown_flag ? "UNKNOWN-ERROR" : "NO-USER");
                    543:       continue;
                    544:     }
                    545:
                    546:     if (try > 0 && syslog_flag)
                    547:       syslog(LOG_NOTICE, "k_getuid retries: %d", try);
1.9       msaitoh   548:
1.1       cgd       549:     if (debug_flag && syslog_flag)
                    550:       syslog(LOG_DEBUG, "  After k_getuid(), before getpwuid()");
                    551:
                    552:     /*
                    553:     ** Then we should try to get the username. If that fails we
                    554:     ** return it as an OTHER identifier
                    555:     */
                    556:     pwp = getpwuid(uid);
1.9       msaitoh   557:
                    558:     if (!pwp || uid != pwp->pw_uid)
1.1       cgd       559:     {
                    560:       if (syslog_flag)
                    561:        syslog(LOG_WARNING, "getpwuid() could not map uid (%d) to name",
                    562:               uid);
                    563:
1.9       msaitoh   564:       printf("%d , %d : USERID : OTHER%s%s : %d\r\n",
1.1       cgd       565:             lport, fport,
                    566:             charset_name ? " , " : "",
                    567:             charset_name ? charset_name : "",
                    568:             uid);
                    569:       continue;
                    570:     }
                    571:
1.9       msaitoh   572: #ifdef ALLOW_FORMAT
                    573:     grp = getgrgid(pwp->pw_gid);
                    574:     if (grp && pwp->pw_gid != grp->gr_gid)
                    575:     {
                    576:        if (syslog_flag)
                    577:            syslog(LOG_WARNING,
                    578:                   "getgrgid() could not map gid (%d) to name (for uid %d, name %s)",
                    579:                   pwp->pw_gid, uid, pwp->pw_name);
                    580:
                    581:       printf("%d , %d : USERID : OTHER%s%s : %d\r\n",
                    582:             lport, fport,
                    583:             charset_name ? " , " : "",
                    584:             charset_name ? charset_name : "",
                    585:             uid);
                    586:       continue;
                    587:     }
                    588:     if (grp)
                    589:        sprintf (grname, "%.99s", grp->gr_name);
                    590:     else
                    591:        sprintf (grname, "%d", pwp->pw_gid);
                    592: #endif
                    593:
1.1       cgd       594:     /*
                    595:     ** Hey! We finally made it!!!
                    596:     */
1.9       msaitoh   597: #ifdef ALLOW_FORMAT
                    598:     if (syslog_flag)
                    599:       syslog(LOG_DEBUG, "Successful lookup: %d , %d : %s.%s\n",
                    600:             lport, fport, pwp->pw_name, grname);
                    601: #else
1.1       cgd       602:     if (syslog_flag)
                    603:       syslog(LOG_DEBUG, "Successful lookup: %d , %d : %s\n",
                    604:             lport, fport, pwp->pw_name);
1.9       msaitoh   605: #endif
1.1       cgd       606:
                    607:     if (noident_flag && check_noident(pwp->pw_dir))
                    608:     {
1.9       msaitoh   609:       if (syslog_flag)
                    610:        syslog(LOG_NOTICE, "User %s requested HIDDEN-USER for host %s: %d, %d",
1.1       cgd       611:               pwp->pw_name,
                    612:               gethost(faddr),
                    613:               lport, fport);
1.9       msaitoh   614:
1.1       cgd       615:       printf("%d , %d : ERROR : HIDDEN-USER\r\n",
                    616:           lport, fport);
                    617:       continue;
                    618:     }
                    619:
1.9       msaitoh   620: #ifdef INCLUDE_CRYPT
                    621:     if (crypto_flag && check_crypt(faddr))
                    622:       printf("%d , %d : USERID : OTHER%s%s : [%s]\r\n",
                    623:             lport, fport,
                    624:             charset_name ? " , " : "",
                    625:             charset_name ? charset_name : "",
                    626:             make_packet (pwp->pw_uid, laddr, lport, faddr, fport));
                    627:     else
                    628: #endif
                    629: #ifdef ALLOW_FORMAT
                    630:     if (format_flag)
                    631:     {
1.10    ! mycroft   632:       char *cp;
        !           633:       const char *const *gmp;
1.9       msaitoh   634:       int bp;
                    635:       char buff[512];
                    636:       for (cp = format, bp = 0; *cp != 0; cp++)
                    637:       {
                    638:        if (*cp == '%')
                    639:        {
                    640:          cp++;
                    641:          if (*cp == 0) break;
                    642:          else if (*cp == 'u') sprintf (&buff[bp], "%.*s", 490-bp, pwp->pw_name);
                    643:          else if (*cp == 'U') sprintf (&buff[bp], "%d",           pwp->pw_uid);
                    644:          else if (*cp == 'g') sprintf (&buff[bp], "%.*s", 490-bp, grname);
                    645:          else if (*cp == 'G') sprintf (&buff[bp], "%d",           pwp->pw_gid);
                    646:          else if (*cp == 'c') sprintf (&buff[bp], "%.*s", 490-bp, cmd);
                    647:          else if (*cp == 'C') sprintf (&buff[bp], "%.*s", 490-bp, cmd_and_args);
                    648:          else if (*cp == 'l') {
                    649:            sprintf (&buff[bp], "%.*s", 490-bp, grname);
                    650:            bp += strlen(&buff[bp]); if (bp >= 490) break;
                    651:            setgrent();
                    652:            while ((grp = getgrent()) != NULL) {
                    653:              if (grp->gr_gid == pwp->pw_gid) continue;
                    654:              for (gmp = grp->gr_mem; *gmp && **gmp; gmp++) {
                    655:                if (! strcmp(*gmp, pwp->pw_name)) {
                    656:                  sprintf (&buff[bp], ",%.*s", 490-bp, grp->gr_name);
                    657:                  bp += strlen(&buff[bp]);
                    658:                  break;
                    659:                }
                    660:              }
                    661:              if (bp >= 490) break;
                    662:            }
                    663:            endgrent();
                    664:          }
                    665:          else if (*cp == 'L') {
                    666:            sprintf (&buff[bp], "%d", pwp->pw_gid);
                    667:            bp += strlen(&buff[bp]); if (bp >= 490) break;
                    668:            setgrent();
                    669:            while ((grp = getgrent()) != NULL) {
                    670:              if (grp->gr_gid == pwp->pw_gid) continue;
                    671:              for (gmp = grp->gr_mem; *gmp && **gmp; gmp++) {
                    672:                if (! strcmp(*gmp, pwp->pw_name)) {
                    673:                  sprintf (&buff[bp], ",%d", grp->gr_gid);
                    674:                  bp += strlen(&buff[bp]);
                    675:                  break;
                    676:                }
                    677:              }
                    678:              if (bp >= 490) break;
                    679:            }
                    680:            endgrent();
                    681:          }
                    682:          else if (*cp == 'p') sprintf (&buff[bp], "%d", pid);
                    683:          else { buff[bp] = *cp; buff[bp+1] = 0; }
                    684:          bp += strlen(&buff[bp]); if (bp >= 490) break;
                    685:        }
                    686:        else { buff[bp++] = *cp; if (bp >= 490) break; }
                    687:       }
                    688:       if (bp >= 490) { sprintf(&buff[490], "..."); bp = 493; }
                    689:       buff[bp] = 0;
                    690:       printf("%d , %d : USERID : %s%s%s :%s\r\n",
1.1       cgd       691:             lport, fport,
1.9       msaitoh   692:             other_flag ? "OTHER" : "UNIX",
1.1       cgd       693:             charset_name ? " , " : "",
                    694:             charset_name ? charset_name : "",
1.9       msaitoh   695:             buff);
                    696:     }
1.1       cgd       697:     else
1.9       msaitoh   698: #endif
1.6       jtc       699:       printf("%d , %d : USERID : %s%s%s :%s\r\n",
1.1       cgd       700:             lport, fport,
                    701:             other_flag ? "OTHER" : "UNIX",
                    702:             charset_name ? " , " : "",
                    703:             charset_name ? charset_name : "",
                    704:             pwp->pw_name);
1.9       msaitoh   705:
1.1       cgd       706:   } while(fflush(stdout), fflush(stderr), multi_flag && eat_whitespace());
                    707:
                    708:   return 0;
                    709: }

CVSweb <webmaster@jp.NetBSD.org>