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

Defined functions

fakegethostname defined in line 168; used 1 times
  • in line 82

Defined variables

sccsid defined in line 2; never used

Defined macros

HDRFILE defined in line 166; used 1 times
Last modified: 1983-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 958
Valid CSS Valid XHTML 1.0 Strict