|
|
1.1 ! root 1: /* ! 2: * dcputil.c ! 3: * ! 4: * miscellaneous utility functions ! 5: */ ! 6: ! 7: #include <ctype.h> ! 8: #include <pwd.h> ! 9: #include "dcp.h" ! 10: #include "perm.h" ! 11: ! 12: /* ! 13: * |myname()| returns a pointer to the local host's UUCP nodename. ! 14: * ! 15: * If there is a MYNAME entry in the PERMS, then return this entry ! 16: * instead of the name in the NODENAME file. ! 17: */ ! 18: ! 19: char * ! 20: myname() ! 21: { ! 22: register char *tmp; ! 23: ! 24: if ( (tmp=perm_value(myname_e)) != NULL ) ! 25: return( tmp ); ! 26: else ! 27: return( uucpname() ); ! 28: } ! 29: ! 30: /* ! 31: * char *visib(str) char *str; ! 32: * char *visbuf(data, len) char *data; int len; ! 33: * ! 34: * Print the string or buffer of data in "visible" format. Printable ! 35: * characters are printed as themselves, special control characters ! 36: * (CR, LF, BS, HT) are printed in the usual escape format, and others ! 37: * are printed using 3-digit octal escapes. Returns a pointer to a ! 38: * static buffer containing the visible data. ! 39: */ ! 40: ! 41: char * ! 42: visib(str) ! 43: unsigned char *str; ! 44: { ! 45: return( visbuf(str, strlen(str)) ); ! 46: } ! 47: ! 48: char * ! 49: visbuf(data, len) ! 50: unsigned char *data; ! 51: int len; ! 52: { ! 53: static char buf[BUFSIZ]; ! 54: register unsigned char c; ! 55: register char *p; ! 56: ! 57: ! 58: if ( len <= 0 ) ! 59: return(""); ! 60: p = buf; ! 61: while( (p<&buf[BUFSIZ-4]) && (len--) ) { ! 62: c = *data++; ! 63: if ( (c!='\\') && isascii(c) && (isprint(c) || (c==' ')) ) { ! 64: *p++ = c; ! 65: continue; ! 66: } ! 67: *p++ = '\\'; ! 68: switch ( c ) { ! 69: case '\\': *p++ = '\\'; break; ! 70: case '\n': *p++ = 'n'; break; ! 71: case '\t': *p++ = 't'; break; ! 72: case '\b': *p++ = 'b'; break; ! 73: case '\r': *p++ = 'r'; break; ! 74: case '\f': *p++ = 'f'; break; ! 75: case '\0': *p++ = '0'; break; ! 76: default: ! 77: sprintf(p, "%03o", c); ! 78: p += 3; ! 79: } ! 80: } ! 81: *p = '\0'; ! 82: return( buf ); ! 83: } ! 84: ! 85: /* ! 86: * |expandtilde(filename)| expands |filename| using the usual "~" convention. ! 87: * That is, "~user" expands to the home directory of "user". "~" by itself ! 88: * expands to the home directory of the effective userid, which in this ! 89: * case is usually the /usr/spool/uucppublic directory. Care is taken not ! 90: * to overflow the (static) name buffer. ! 91: */ ! 92: char *expandtilde(filename) ! 93: char *filename; ! 94: { ! 95: struct passwd *pw, *getpwnam(), *getpwuid(); ! 96: static char namebuf[PATHLEN]; ! 97: int goodname = 1; ! 98: char *p; ! 99: char logline[60]; ! 100: ! 101: if ('~' != *filename) { ! 102: strcpy(namebuf, filename); ! 103: } else { ! 104: ++filename; ! 105: p = namebuf; ! 106: while(*filename && '/' != *filename && (p - namebuf) < PATHLEN) ! 107: *p++ = *filename++; ! 108: *p = '\0'; ! 109: if (strlen(namebuf) == 0) ! 110: pw = getpwuid(geteuid()); ! 111: else ! 112: pw = getpwnam(namebuf); ! 113: if (NULL == pw) { ! 114: goodname = 0; ! 115: } else if (strlen(pw->pw_dir)+strlen(filename)+1 > PATHLEN) { ! 116: goodname = 0; ! 117: } else { ! 118: strcpy(namebuf, pw->pw_dir); ! 119: strcat(namebuf, filename); ! 120: } ! 121: } ! 122: if (goodname) { ! 123: sprintf(logline, "tilde->%s", namebuf); ! 124: plog(M_TRANSFER, logline); ! 125: return namebuf; ! 126: } else { ! 127: plog(M_TRANSFER, "tilde->NULL"); ! 128: return NULL; ! 129: } ! 130: } ! 131:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.