|
|
1.1 ! root 1: /* the client set up end of the connection */ ! 2: /* the first message is 16 bytes, (buf-len in 1024's, dev, prot, dbg, 13 unused) ! 3: * the second message is the client's passwd file (name uid '\n') and zeros ! 4: * the third message is client's gid's and zeros ! 5: * each of these is acked by a single byte of 1, 2, resp 3. ! 6: */ ! 7: #include "share.h" ! 8: #include "pwd.h" ! 9: #include "grp.h" ! 10: struct stat rootstat; ! 11: extern int errno; ! 12: extern char *sys_errlist[]; ! 13: int dbgfd = 2, devnum; ! 14: ! 15: /* setup host-name remote-server-to-execute mount-point protocol[dt] */ ! 16: main(argc, argv) ! 17: char **argv; ! 18: { int fd; ! 19: if(argc != 6 && argc != 7) ! 20: fatal("usage: setup host server mount protocol devnum [dbg]\n"); ! 21: switch(argv[4][0]) { ! 22: default: /* cf /n/bowell/usr/jerq/src/sam/io.c */ ! 23: fatal("weird net type %s\n", argv[4]); ! 24: case 'd': /* datakit */ ! 25: #ifdef OLD ! 26: fd = tdkexec(argv[1], argv[2]); ! 27: #else ! 28: fd = ipcopen(ipcpath(argv[1], "dk", "fsb"), "heavy"); ! 29: #endif ! 30: break; ! 31: case 't': ! 32: #ifdef OLD ! 33: fd = tcp_rcmd(argv[1], "shell", "pjw", "pjw", "share/zarf", 0); ! 34: #else ! 35: fd = ipcrexec(argv[1], "heavy", argv[2]); ! 36: #endif ! 37: break; ! 38: } ! 39: devnum = atoi(argv[5]); ! 40: errno = 0; ! 41: if(fd >= 0) ! 42: setup(fd, argv[3], argv[4], argc == 7? argv[6]: 0); ! 43: else ! 44: perror("couldn't call"); ! 45: debug("setup(%s,%s,%s,%s) errno %d\n", argv[1], argv[2], argv[3], argv[4], ! 46: errno); ! 47: } ! 48: ! 49: char msg[16]; ! 50: setup(fd, dir, net, dbg) ! 51: char *dir, *net; ! 52: { struct stat stb; ! 53: int i; ! 54: if(stat(dir, &rootstat) < 0) ! 55: fatal("setup: couldn't stat dir %d\n", dir); ! 56: msg[0] = 5; /* 5*1024 is the largest message i'll send */ ! 57: /* that number is known in the kernel in netb.c */ ! 58: msg[1] = devnum; /* client dev, when shifted left 8 */ ! 59: msg[2] = net[0]; /* so server knows about messages */ ! 60: msg[3] = dbg; ! 61: #if mc68000 ! 62: msg[4] = 's'; ! 63: #endif ! 64: #if vax ! 65: msg[4] = 'v'; ! 66: #endif ! 67: #if cray ! 68: msg[4] = 'c'; ! 69: #endif ! 70: /* the next 12 bytes could be used for authentication or something */ ! 71: i = write(fd, msg, 16); ! 72: if(i != 16) ! 73: fatal("write on setup returned %d\n", i); ! 74: i = read(fd, msg, 16); ! 75: if(i != 1) ! 76: fatal("read on setup returned %d |%s|\n", i, msg); ! 77: if(msg[0] != 1) ! 78: fatal("setup read char %d\b", msg[0]); ! 79: /* whew, paranoia is costly, and they're still out there */ ! 80: /* now send uid table */ ! 81: senduid(fd); ! 82: /* now send gid table */ ! 83: sendgid(fd); ! 84: i = fmount(4 /*fstyp*/, fd, dir, devnum<<8); ! 85: if(i < 0) ! 86: fatal("gmount returned %d, errno %d:%s\n", i, errno, sys_errlist[errno]); ! 87: /* and that's that */ ! 88: } ! 89: ! 90: char uidbuf[5*1024]; /* 1024*msg[0] */ ! 91: senduid(cfd) ! 92: { struct passwd *p; ! 93: char *s = uidbuf, *t; ! 94: int i; ! 95: while(p = getpwent()) { ! 96: for(t = p->pw_name; *t; t++) ! 97: *s++ = *t; ! 98: *s++ = ' '; ! 99: sprintf(s, "%d\n", p->pw_uid); ! 100: while(*s) ! 101: s++; ! 102: } ! 103: endpwent(); ! 104: *s++ = 0; ! 105: if(s >= uidbuf + sizeof(uidbuf)) ! 106: fatal("client password file too big\n"); ! 107: /* send and ack */ ! 108: i = write(cfd, uidbuf, sizeof(uidbuf)); /* write has known length */ ! 109: if(i != sizeof(uidbuf)) ! 110: fatal("write uid %d (%d)\n", i, errno); ! 111: i = read(cfd, uidbuf, 16); ! 112: if(i != 1) ! 113: fatal("senduid ack read %d (%d)\n", i, errno); ! 114: if(uidbuf[0] != 2) ! 115: fatal("send uid ack was %d not 2\n", uidbuf[0]); ! 116: } ! 117: ! 118: sendgid(cfd) ! 119: { struct group *p; ! 120: char *s = uidbuf, *t; ! 121: int i; ! 122: for(i = 0; i < sizeof(uidbuf); i++) ! 123: uidbuf[i] = 0; ! 124: while(p = getgrent()) { ! 125: for(t = p->gr_name; *t; t++) ! 126: *s++ = *t; ! 127: *s++ = ' '; ! 128: sprintf(s, "%d\n", p->gr_gid); ! 129: while(*s) ! 130: s++; ! 131: } ! 132: endgrent(); ! 133: *s++ = 0; ! 134: if(s >= uidbuf + sizeof(uidbuf)) ! 135: fatal("client group file too big\n"); ! 136: /* send and ack */ ! 137: i = write(cfd, uidbuf, sizeof(uidbuf)); ! 138: if(i != sizeof(uidbuf)) ! 139: fatal("write gid %d (%d)\n", i, errno); ! 140: i = read(cfd, uidbuf, 16); ! 141: if(i != 1) ! 142: fatal("sendgid ack read %d (%d)\n", i, errno); ! 143: if(uidbuf[0] != 3) ! 144: fatal("send gid ack was %d not 2\n", uidbuf[0]); ! 145: } ! 146: ! 147: char msgbuf[1024]; ! 148: /* VARARGS1 */ ! 149: fatal(s, a, b, c, d, e, f) ! 150: char *s; ! 151: { ! 152: sprintf(msgbuf, s, a, b, c, d, e, f); ! 153: write(dbgfd, msgbuf, strlen(msgbuf)); ! 154: exit(1); ! 155: } ! 156: ! 157: /* VARARGS1 */ ! 158: debug(s, a, b, c, d, e, f) ! 159: char *s; ! 160: { ! 161: sprintf(msgbuf, s, a, b, c, d, e, f); ! 162: write(dbgfd, msgbuf, strlen(msgbuf)); ! 163: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.