|
|
1.1 ! root 1: #include <sys/types.h> ! 2: #include <sys/ioctl.h> ! 3: #include <pwd.h> ! 4: #include <ipc.h> ! 5: #include "defs.h" ! 6: ! 7: /* buffer definition */ ! 8: #define BUFLEN 512 ! 9: ! 10: /* have to define this somewhere */ ! 11: char *ipcname; ! 12: ! 13: /* ! 14: * Recieve an fd ! 15: */ ! 16: _fd_read(onfd, pp) ! 17: int onfd; ! 18: struct passfd *pp; ! 19: { ! 20: register int rv; ! 21: ! 22: while((rv=ioctl(onfd, FIORCVFD, pp))<0 && errno==EINTR) ! 23: ; ! 24: return rv; ! 25: } ! 26: ! 27: /* ! 28: * Send an fd ! 29: */ ! 30: _fd_write(onfd, tofd) ! 31: { ! 32: return ioctl(onfd, FIOSNDFD, &tofd); ! 33: } ! 34: ! 35: /* ! 36: * Send the connection info. ! 37: */ ! 38: int ! 39: _info_write(fd, ip) ! 40: int fd; ! 41: ipcinfo *ip; ! 42: { ! 43: char b[BUFLEN]; ! 44: int n; ! 45: ! 46: if (ip->name==NULL) ! 47: ip->name = ""; ! 48: if (ip->param==NULL) ! 49: ip->param = ""; ! 50: if (ip->machine==NULL) ! 51: ip->machine = ""; ! 52: if (ip->user==NULL) ! 53: ip->user = ""; ! 54: if (ip->myname==NULL) ! 55: ip->myname = ""; ! 56: sprintf(b, "%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n", ip->myname, ip->name, ! 57: ip->param, ip->machine, ip->user, ip->flags, ip->uid, ip->gid); ! 58: n = strlen(b); ! 59: if (write(fd, b, n)!=n) ! 60: return ABORT(errno, "can't send request", NULLINFO); ! 61: return 0; ! 62: } ! 63: ! 64: /* ! 65: * Read the connection info. If an error occurs, ip->reply and ip->conn are ! 66: * closed. ! 67: */ ! 68: int ! 69: _info_read(fd, ip) ! 70: int fd; ! 71: ipcinfo *ip; ! 72: { ! 73: static char b[BUFLEN]; ! 74: char *f[8]; ! 75: int n; ! 76: ! 77: while((n=read(fd, b, sizeof(b)))<0 && errno==EINTR) ! 78: ; ! 79: if (n <= 0) ! 80: return ABORT(errno, "error reading request", ip); ! 81: b[n] = '\0'; ! 82: setfields("\n"); ! 83: if (getfields(b, f, 8)!=8) ! 84: return ABORT(EINVAL, "protocol botch", ip); ! 85: ip->myname = f[0]; ! 86: ip->name = f[1]; ! 87: ip->param = f[2]; ! 88: ip->machine = f[3]; ! 89: ip->flags = atoi(f[5]); ! 90: ! 91: /* supply a system name */ ! 92: if (ip->uid!=ROOTUID || ip->machine[0]=='\0') ! 93: ip->machine = ""; ! 94: ! 95: /* supply a user name */ ! 96: if (ip->uid==ROOTUID && *(f[4])!='\0') ! 97: ip->user = f[4]; ! 98: ! 99: /* supply uid/gid cruft */ ! 100: if (ip->uid==ROOTUID && atoi(f[6])!=-1) { ! 101: ip->uid = atoi(f[6]); ! 102: ip->gid = atoi(f[7]); ! 103: } ! 104: return 0; ! 105: } ! 106: ! 107: /* ! 108: * Send a reply to a connection request ! 109: */ ! 110: _reply_write(fd, no, str) ! 111: int fd; ! 112: int no; ! 113: char *str; ! 114: { ! 115: char b[BUFLEN]; ! 116: int n; ! 117: ! 118: if (str==NULL) ! 119: str = ""; ! 120: sprintf(b, "%d\n%s\n", no, str); ! 121: n = strlen(b); ! 122: if (write(fd, b, n)!=n) ! 123: return -1; ! 124: return 0; ! 125: } ! 126: ! 127: /* ! 128: * Get a reply to a connection request. ! 129: */ ! 130: int ! 131: _reply_read(fd) ! 132: int fd; ! 133: { ! 134: static char b[BUFLEN]; ! 135: char *f[2]; ! 136: char *ptr; ! 137: int n; ! 138: ! 139: while((n=read(fd, b, sizeof(b)))<0 && errno==EINTR) ! 140: ; ! 141: if (n <= 0) ! 142: return ABORT(errno, "error reading request", NULLINFO); ! 143: b[n] = '\0'; ! 144: setfields("\n"); ! 145: getfields(b, f, 2); ! 146: errno = atoi(f[0]); ! 147: if ((ptr=strchr(f[1], '\n'))!=NULL) ! 148: *ptr = '\0'; ! 149: if (errno!=0) ! 150: errstr = f[1]; ! 151: else ! 152: ipcname = f[1]; ! 153: return 0; ! 154: } ! 155:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.