|
|
1.1 ! root 1: /* pathalias -- by steve bellovin, as told to peter honeyman */ ! 2: #ifndef lint ! 3: static char *sccsid = "@(#)local.c 8.1 (down!honey) 86/01/19"; ! 4: #endif lint ! 5: ! 6: #include <stdio.h> ! 7: #include "config.h" ! 8: ! 9: #ifdef UNAME ! 10: #include <sys/utsname.h> ! 11: ! 12: char * ! 13: local() ! 14: { ! 15: static struct utsname utsname; ! 16: ! 17: uname(&utsname); ! 18: return(utsname.nodename); ! 19: } ! 20: ! 21: #else !UNAME ! 22: ! 23: char * ! 24: local() ! 25: { ! 26: static char lname[64]; ! 27: void gethostname(); ! 28: ! 29: gethostname(lname, sizeof(lname)); ! 30: return(lname); ! 31: } ! 32: ! 33: #ifndef GETHOSTNAME ! 34: ! 35: static void ! 36: gethostname(name, len) ! 37: char *name; ! 38: { ! 39: FILE *whoami, *fopen(), *popen(); ! 40: char *ptr, *index(); ! 41: ! 42: *name = '\0'; ! 43: ! 44: /* try /etc/whoami */ ! 45: if ((whoami = fopen("/etc/whoami", "r")) != 0) { ! 46: (void) fgets(name, len, whoami); ! 47: (void) fclose(whoami); ! 48: if ((ptr = index(name, '\n')) != 0) ! 49: *ptr = '\0'; ! 50: } ! 51: if (*name) ! 52: return; ! 53: ! 54: /* try /usr/include/whoami.h */ ! 55: if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) { ! 56: while (!feof(whoami)) { ! 57: char buf[100]; ! 58: ! 59: if (fgets(buf, 100, whoami) == 0) ! 60: break; ! 61: if (sscanf(buf, "#define sysname \"%[^\"]\"", name)) ! 62: break; ! 63: } ! 64: (void) fclose(whoami); ! 65: if (*name) ! 66: return; ! 67: } ! 68: ! 69: /* ask uucp */ ! 70: if ((whoami = popen("uuname -l", "r")) != 0) { ! 71: (void) fgets(name, len, whoami); ! 72: (void) pclose(whoami); ! 73: if ((ptr = index(name, '\n')) != 0) ! 74: *ptr = '\0'; ! 75: } ! 76: if (*name) ! 77: return; ! 78: ! 79: /* aw hell, i give up! is this a real unix? */ ! 80: return; ! 81: } ! 82: #endif GETHOSTNAME ! 83: #endif UNAME
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.