Annotation of 43BSDReno/usr.bin/uucp/versys.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)versys.c   5.7     (Berkeley) 4/5/88";
                      3: #endif
                      4: 
                      5: #include "uucp.h"
                      6: #include <stdio.h>
                      7: #include <ctype.h>
                      8: 
                      9: /*LINTLIBRARY*/
                     10: 
                     11: char PhoneNumber[MAXPH];
                     12: 
                     13: /*
                     14:  *     verify system names n1 and n2
                     15:  *     return codes:  SUCCESS  |  FAIL
                     16:  *
                     17:  *     NOTE:
                     18:  *             the old calling sequence was versys(name) but is
                     19:  *     now versys(&name) so that we can perform aliasing!!!!
                     20:  *     See accompanying changes in uucp.c and uux.c
                     21:  *             -- Ray Essick, April 27, 1984
                     22:  */
                     23: versys(nameptr)
                     24: register char **nameptr;
                     25: {
                     26:        register FILE *fp;
                     27:        char line[BUFSIZ];
                     28:        char *name;
                     29: 
                     30:        DEBUG (11, "Before Alias: %s\n", *nameptr);
                     31:        uualias (nameptr);                      /* alias expansion */
                     32:        DEBUG (11, "After Alias: %s\n", *nameptr);
                     33:        name = *nameptr;                        /* dereference */
                     34: 
                     35:        if (name[0] == '\0' || strncmp(name, Myname, MAXBASENAME) == 0)
                     36:                return SUCCESS;
                     37: 
                     38:        fp = fopen(SYSFILE, "r");
                     39:        if (fp == NULL) {
                     40:                syslog(LOG_ERR, "fopen(%s) failed: %m", SYSFILE);
                     41:                cleanup(FAIL);
                     42:        }
                     43:        PhoneNumber[0] = '\0';
                     44:        while (cfgets(line, sizeof(line), fp) != NULL) {
                     45:                char *targs[100];
                     46: 
                     47:                getargs(line, targs, 100);
                     48:                if (strncmp(name, targs[0], MAXBASENAME) == SAME) {
                     49:                        fclose(fp);
                     50:                        if (targs[F_PHONE])
                     51:                                strncpy(PhoneNumber, targs[F_PHONE], MAXPH);
                     52:                        return SUCCESS;
                     53:                }
                     54:        }
                     55:        fclose(fp);
                     56:        return FAIL;
                     57: }
                     58: 
                     59: /*
                     60:  *     Works (sort of) like rhost(3) on 4.1[abc] Bsd systems.
                     61:  *
                     62:  *     Looks for the host in the L.aliases file and returns the
                     63:  *     "standard" name by modifying the pointer. The returned
                     64:  *     value is saved with malloc(3) so it isn't zapped by
                     65:  *     subsequent calls.
                     66:  *
                     67:  *     Returns:
                     68:  *             FAIL            No L.aliases file
                     69:  *             SUCCESS         Anything else
                     70:  */
                     71: 
                     72: uualias(hostptr)
                     73: char  **hostptr;                         /* we change it */
                     74: {
                     75:        FILE *Aliases;                    /* list of aliases */
                     76:        char buf[BUFSIZ];
                     77:        int atend;
                     78:        char *p, *q;
                     79:        char *koshername;                /* "official" name */
                     80: 
                     81:        if ((Aliases = fopen(ALIASFILE, "r")) == NULL) {
                     82:                DEBUG(11, "No %s file\n", ALIASFILE);
                     83:                return FAIL;                      /* no alias file */
                     84:        }
                     85: 
                     86:        DEBUG (11, "Alias expansion for %s\n", *hostptr);
                     87:        while (cfgets(buf, sizeof (buf), Aliases)) {
                     88:                p = &buf[0];
                     89:                atend = 0;
                     90:                DEBUG(11, "Alias line: %s\n", buf);
                     91: 
                     92:                while (!atend) {
                     93:                        while (isspace(*p) && *p != '\n')
                     94:                                p++;                      /* skip white space */
                     95:                        q = p;
                     96:                        while (!isspace(*q) && *q != '\n')
                     97:                                q++;                      /* find end */
                     98:                        if (*q == '\n')
                     99:                                atend++;                  /* last entry */
                    100:                        *q = '\0';
                    101:                        DEBUG(11, "Compare against: %s\n", p);
                    102:                        if (strcmp(*hostptr, p) == 0)/* match? */ {
                    103:                                koshername = malloc((unsigned)strlen(buf) + 1);
                    104:                                strcpy(koshername, buf); /* save it */
                    105:                                fclose(Aliases);
                    106:                                DEBUG(4, "Alias: %s to ", *hostptr);
                    107:                                DEBUG(4, "%s\n", koshername);
                    108:                                *hostptr = koshername;    /* correct one */
                    109:                                return SUCCESS;           /* all is well */
                    110:                        }
                    111:                        p = q + 1;                        /* try next entry */
                    112:                }
                    113: 
                    114:        }
                    115:        fclose(Aliases);
                    116:        DEBUG(11, "Alias doesn't match %s, remains unchanged\n", *hostptr);
                    117:        return SUCCESS;                           /* unchanged host */
                    118: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.