|
|
1.1 ! root 1: /* ! 2: * fullname.c - this file is made separate so that different local ! 3: * conventions can be applied. The stock version understands two ! 4: * conventions: ! 5: * ! 6: * (a) Berkeley finger: the gecos field in /etc/passwd begins with ! 7: * the full name, terminated with comma, semicolon, or end of ! 8: * field. & expands to the login name. ! 9: * (b) BTL RJE: the gecos field looks like ! 10: * : junk - full name ( junk : ! 11: * where the "junk -" is optional. ! 12: * ! 13: * If you have a different local convention, modify this file accordingly. ! 14: */ ! 15: ! 16: static char *sccsid = "@(#)fullname.c 1.4 5/3/83"; ! 17: ! 18: #include <stdio.h> ! 19: #include <ctype.h> ! 20: #include <pwd.h> ! 21: #include "defs.h" ! 22: ! 23: #ifndef LOCALNAME ! 24: /* ! 25: * Figure out who is sending the message and sign it. ! 26: * We attempt to look up the user in the gecos field of /etc/passwd. ! 27: */ ! 28: char * ! 29: fullname(un) ! 30: char *un; ! 31: { ! 32: static char inbuf[100]; ! 33: struct passwd *pw, *getpwnam(); ! 34: ! 35: pw = getpwnam(un); ! 36: if (pw == NULL) ! 37: return un; ! 38: buildfname(pw->pw_gecos, un, inbuf); ! 39: if (inbuf[0] == 0) ! 40: return un; ! 41: return inbuf; ! 42: } ! 43: ! 44: #else ! 45: ! 46: /* ! 47: * Alternative version of fullname which asks the user for his full name. ! 48: * This is mainly suitable for systems that don't have a full name ! 49: * database somewhere. It puts the answer in $HOME/.name ! 50: */ ! 51: char * ! 52: fullname(un) ! 53: char *un; ! 54: { ! 55: static char inbuf[100]; ! 56: char fbuf[100]; ! 57: FILE *fd; ! 58: char *p, *index(), *getenv(); ! 59: int pid; ! 60: ! 61: if (!isatty(2)) ! 62: return un; ! 63: printf("What is your full name (for news article signatures): "); ! 64: fflush(stdout); ! 65: read(2, inbuf, sizeof inbuf); ! 66: if (inbuf[0] == 0) ! 67: return un; ! 68: p = index(inbuf, '\n'); ! 69: if (p) ! 70: *p = 0; ! 71: if ((p = getenv("HOME")) == NULL) { ! 72: fprintf(stderr, ! 73: "inews: no HOME environment variable - .name not written\n"); ! 74: return inbuf; ! 75: } ! 76: sprintf(fbuf, "%s/%s", p, ".name"); ! 77: if ((pid = fork()) < 0) { ! 78: perror("inews"); ! 79: return inbuf; ! 80: } ! 81: else if (pid != 0) ! 82: while (wait((int *)0) != pid) ! 83: ; ! 84: else { ! 85: setuid(getuid()); /* become the user */ ! 86: if ((fd = fopen(fbuf, "w")) == NULL) ! 87: fprintf(stderr, "inews: can't create %s\n", fbuf); ! 88: else { ! 89: fprintf(fd, "%s\n", inbuf); ! 90: fclose(fd); ! 91: } ! 92: exit(0); ! 93: } ! 94: return inbuf; ! 95: } ! 96: #endif ! 97: ! 98: #ifndef LOCALNAME ! 99: /* ! 100: ** BUILDFNAME -- build full name from gecos style entry. ! 101: ** (routine lifted from sendmail) ! 102: ** ! 103: ** This routine interprets the strange entry that would appear ! 104: ** in the GECOS field of the password file. ! 105: ** ! 106: ** Parameters: ! 107: ** p -- name to build. ! 108: ** login -- the login name of this user (for &). ! 109: ** buf -- place to put the result. ! 110: ** ! 111: ** Returns: ! 112: ** none. ! 113: ** ! 114: ** Side Effects: ! 115: ** none. ! 116: */ ! 117: ! 118: buildfname(p, login, buf) ! 119: register char *p; ! 120: char *login; ! 121: char *buf; ! 122: { ! 123: register char *bp = buf; ! 124: ! 125: if (*p == '*') ! 126: p++; ! 127: while (*p != '\0' && *p != ',' && *p != ';' && *p != ':' && *p != '(') ! 128: { ! 129: if (*p == '-') { ! 130: bp = buf; ! 131: p++; ! 132: } ! 133: else if (*p == '&') ! 134: { ! 135: (void) strcpy(bp, login); ! 136: if (islower(*bp)) ! 137: *bp = toupper(*bp); ! 138: while (*bp != '\0') ! 139: bp++; ! 140: p++; ! 141: } ! 142: else ! 143: *bp++ = *p++; ! 144: } ! 145: *bp = '\0'; ! 146: } ! 147: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.