Annotation of 43BSD/usr.bin/uucp/uucpname.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)uucpname.c 5.5 (Berkeley) 10/9/85";
        !             3: #endif
        !             4: 
        !             5: #include "uucp.h"
        !             6: #include <sys/stat.h>
        !             7: 
        !             8: /*LINTLIBRARY*/
        !             9: 
        !            10: #ifdef GETMYHNAME
        !            11: #include <UNET/unetio.h>
        !            12: #endif
        !            13: 
        !            14: #ifdef UNAME
        !            15: /* Use USG uname() library routine */
        !            16: #include <sys/utsname.h>
        !            17: #endif
        !            18: 
        !            19: #ifdef CCWHOAMI
        !            20: /* Compile in 'sysname' as found in standard(!) include file */
        !            21: #include <whoami.h>
        !            22: #endif
        !            23: char Myfullname[64];
        !            24: 
        !            25: /*
        !            26:  *     uucpname(name)          get the uucp name
        !            27:  *
        !            28:  *     return code - none
        !            29:  */
        !            30: uucpname(name)
        !            31: register char *name;
        !            32: {
        !            33:        register char *s;
        !            34: 
        !            35:        /*
        !            36:         * Since some UNIX systems do not honor the set-user-id bit
        !            37:         * when the invoking user is root, we must change the uid here.
        !            38:         * So uucp files are created with the correct owner.
        !            39:         */
        !            40:        if (geteuid() == 0 && getuid() == 0) {
        !            41:                struct stat stbuf;
        !            42:                stbuf.st_uid = 0;       /* In case the stat fails */
        !            43:                stbuf.st_gid = 0;
        !            44:                stat(UUCICO, &stbuf);   /* Assume uucico is correctly owned */
        !            45:                setgid(stbuf.st_gid);
        !            46:                setuid(stbuf.st_uid);
        !            47:        }
        !            48: 
        !            49:        s = NULL;       /* system name unknown, so far */
        !            50: 
        !            51: #ifdef GETHOSTNAME
        !            52:        if (s == NULL || *s == '\0') {
        !            53: #ifdef VMS
        !            54:                int i = sizeof(Myfullname);
        !            55: #endif VMS
        !            56: 
        !            57:                s = Myfullname;
        !            58: #ifdef VMS
        !            59:                if(gethostname(Myfullname, &i) == -1) {
        !            60: #else !VMS
        !            61:                if(gethostname(Myfullname, sizeof(Myfullname)) == -1) {
        !            62: #endif !VMS
        !            63:                        DEBUG(1, "gethostname", _FAILED);
        !            64:                        s = NULL;
        !            65:                }
        !            66:        }
        !            67: #endif GETHOSTNAME
        !            68: 
        !            69: #ifdef UNAME
        !            70:        /* Use USG library routine */
        !            71:        if (s == NULL || *s == '\0') {
        !            72:                struct utsname utsn;
        !            73: 
        !            74:                if (uname(&utsn) == -1) {
        !            75:                        DEBUG(1, "uname", _FAILED);
        !            76:                        s = NULL;
        !            77:                } else {
        !            78:                        strncpy(Myfullname, utsn.nodename, sizeof Myfullname);
        !            79:                        s = Myfullname;
        !            80:                }
        !            81:        }
        !            82: #endif
        !            83: 
        !            84: #ifdef WHOAMI
        !            85:        /* Use fake gethostname() routine */
        !            86:        if (s == NULL || *s == '\0') {
        !            87: 
        !            88:                s = Myfullname;
        !            89:                if (fakegethostname(Myfullname, sizeof(Myfullname)) == -1) {
        !            90:                        DEBUG(1, "whoami search", _FAILED);
        !            91:                        s = NULL;
        !            92:                }
        !            93:        }
        !            94: #endif
        !            95: 
        !            96: #ifdef CCWHOAMI
        !            97:        /* compile sysname right into uucp */
        !            98:        if (s == NULL || *s == '\0') {
        !            99:                s = sysname;
        !           100:                strncpy(Myfullname, s, sizeof Myfullname);
        !           101:        }
        !           102: #endif
        !           103: 
        !           104: #ifdef UUNAME
        !           105:        /* uucp name is stored in /etc/uucpname or /local/uucpname */
        !           106:        if (s == NULL || *s == '\0') {
        !           107:                FILE *uucpf;
        !           108: 
        !           109:                s = Myfullname;
        !           110:                if (((uucpf = fopen("/etc/uucpname", "r")) == NULL &&
        !           111:                     (uucpf = fopen("/local/uucpname", "r")) == NULL) ||
        !           112:                        fgets(Myfullname, sizeof Myfullname, uucpf) == NULL) {
        !           113:                                DEBUG(1, "uuname search", _FAILED);
        !           114:                                s = NULL;
        !           115:                }
        !           116:                if (s == Myfullname) {
        !           117:                        register char *p;
        !           118:                        p = index(s, '\n');
        !           119:                        if (p)
        !           120:                                *p = '\0';
        !           121:                }
        !           122:                if (uucpf != NULL)
        !           123:                        fclose(uucpf);
        !           124:        }
        !           125: #endif
        !           126: 
        !           127: #ifdef GETMYHNAME
        !           128:        /* Use 3Com's getmyhname() routine */
        !           129:        if (s == NULL || *s == '\0') {
        !           130:                if ((s = getmyhname()) == NULL)
        !           131:                        DEBUG(1, "getmyhname", _FAILED);
        !           132:                else
        !           133:                        strncpy(Myfullname, s, sizeof Myfullname);
        !           134:        }
        !           135: #endif
        !           136: 
        !           137: #ifdef MYNAME
        !           138:        if (s == NULL || *s == '\0') {
        !           139:                s = MYNAME;
        !           140:                strncpy(Myfullname, s, sizeof Myfullname);
        !           141:        }
        !           142: #endif
        !           143: 
        !           144:        if (s == NULL || *s == '\0') {
        !           145:                /*
        !           146:                 * As a last ditch thing, we *could* search Spool
        !           147:                 * for D.<uucpname> and use that,
        !           148:                 * but that is too much trouble, isn't it?
        !           149:                 */
        !           150:                logent("SYSTEM NAME", "CANNOT DETERMINE");
        !           151:                strcpy(Myfullname, "unknown");
        !           152:        }
        !           153: 
        !           154:        /*
        !           155:         * copy uucpname back to caller-supplied buffer,
        !           156:         * truncating to MAXBASENAME characters.
        !           157:         * Also set up subdirectory names
        !           158:         * Truncate names at '.' if found to handle cases like
        !           159:         * seismo.css.gov being returned by gethostname().
        !           160:         * uucp sites should not have '.' in their name anyway
        !           161:         */
        !           162:        s = index(Myfullname, '.');
        !           163:        if (s != NULL)
        !           164:                *s = '\0';
        !           165:        strncpy(name, Myfullname, MAXBASENAME);
        !           166:        name[MAXBASENAME] = '\0';
        !           167:        DEBUG(1, "My uucpname = %s\n", name);
        !           168: 
        !           169:        sprintf(DLocal, "D.%.*s", SYSNSIZE, name);
        !           170:        sprintf(DLocalX, "D.%.*sX", SYSNSIZE, name);
        !           171: }
        !           172: 
        !           173: #ifdef WHOAMI
        !           174: /*
        !           175:  * simulate the 4.2 bsd system call by reading /usr/include/whoami.h
        !           176:  * and looking for the #define sysname
        !           177:  */
        !           178: 
        !           179: #define        HDRFILE "/usr/include/whoami.h"
        !           180: 
        !           181: fakegethostname(name, len)
        !           182: char *name;
        !           183: int len;
        !           184: {
        !           185:        char buf[BUFSIZ];
        !           186:        char bname[32];
        !           187:        char hname[32];
        !           188:        char nname[128];
        !           189:        register char *p, *q, *nptr;
        !           190:        int i;
        !           191:        register FILE *fd;
        !           192:        
        !           193:        fd = fopen(HDRFILE, "r");
        !           194:        if (fd == NULL)
        !           195:                return(-1);
        !           196:        
        !           197:        hname[0] = 0;
        !           198:        nname[0] = 0;
        !           199:        nptr = nname;
        !           200: 
        !           201:        while (fgets(buf, sizeof buf, fd) != NULL) { /* each line in the file */
        !           202:                if (sscanf(buf, "#define sysname \"%[^\"]\"", bname) == 1) {
        !           203:                        strcpy(hname, bname);
        !           204:                } else if (sscanf(buf, "#define nickname \"%[^\"]\"", bname) == 1) {
        !           205:                        strcpy(nptr, bname);
        !           206:                        nptr += strlen(bname) + 1;
        !           207:                } else if (sscanf(buf, "#define nickname%d \"%[^\"]\"", &i, bname) == 2) {
        !           208:                        strcpy(nptr, bname);
        !           209:                        nptr += strlen(bname) + 1;
        !           210:                }
        !           211:        }
        !           212:        fclose(fd);
        !           213:        if (hname[0] == 0)
        !           214:                return FAIL;
        !           215:        strncpy(name, hname, len);
        !           216:        p = nname;
        !           217:        i = strlen(hname) + 1;
        !           218:        q = name + i;
        !           219:        while (i < len && (p[0] != 0 || p[1] != 0)) {
        !           220:                *q++ = *p++;
        !           221:                i++;
        !           222:        }
        !           223:        *q++ = 0;
        !           224:        return SUCCESS;
        !           225: }
        !           226: #endif

unix.superglobalmegacorp.com

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