|
|
1.1 ! root 1: #include "fserv.h" ! 2: #include "dk.h" ! 3: #include "dkmgr.h" ! 4: #include "sys/ioctl.h" ! 5: #include "signal.h" ! 6: #include "errno.h" ! 7: ! 8: extern int dkp_ld, rdk_ld; ! 9: extern int dkmgrreply; /* global variable for dkmgrack */ ! 10: extern int dkmgropen; ! 11: char mgrbuf[128]; ! 12: struct mgrmsg mesg; ! 13: char buf[1024]; ! 14: ! 15: announce(s) /* hello world, here we are */ ! 16: char *s; ! 17: { int i, fd; ! 18: persist: ! 19: for(i = 0; i < 5; i++) { ! 20: fd = tdkserv(s, 2); ! 21: if(fd < 0) { ! 22: debug("announce(%s) failed", s); ! 23: sleep(5); ! 24: continue; ! 25: } ! 26: dkmgropen = cntlfd = fd; ! 27: debug("announce %d", cntlfd); ! 28: dkproto(fd, dkp_ld); ! 29: /*fd = open("/dev/dk/dk01", 2);*/ ! 30: fd = dkctlchan(2); ! 31: if(fd < 0) { ! 32: perror("dkctlchan"); ! 33: break; ! 34: } ! 35: dkmgrreply = ackfd = fd; ! 36: debug("ackfd %d", ackfd); ! 37: FD_SET(cntlfd, active); ! 38: return; ! 39: } ! 40: debug("sleeping 100 and trying again"); ! 41: for(i = 4; i < NOFILE; i++) /* smash some just in case */ ! 42: close(fd); ! 43: sleep(100); ! 44: goto persist; ! 45: } ! 46: ! 47: newone() ! 48: { int n, i, fd; ! 49: char *p; ! 50: n = read(cntlfd, mgrbuf, sizeof(mgrbuf)); ! 51: if(n < 0) { ! 52: perror("select lied about control channel"); ! 53: exit(1); ! 54: } ! 55: if(n == 0) { ! 56: debug("0 length read on control channel"); ! 57: debug("assuming datakit died, killing children"); ! 58: if(chdir("/usr/net") == -1) ! 59: chdir("/etc/net"); ! 60: for(i = 0; i < NORMAN; i++) ! 61: if(children[i].pid && children[i].flags == SPLIT) ! 62: kill(children[i].pid, SIGKILL); ! 63: close(cntlfd); ! 64: cntlfd = -1; ! 65: return; ! 66: } ! 67: if(!readmgr()) ! 68: return; ! 69: if(!(n = isfriend(mesg.m_source))) { ! 70: debug("not friend, nak"); ! 71: nakit: ! 72: dkmgrnak(mesg.m_chan, 4); ! 73: return; ! 74: } ! 75: for(i = 0; i < NORMAN; i++) ! 76: if(children[i].who && strcmp(children[i].who, mesg.m_source) == 0) { ! 77: debug("already attached"); ! 78: free(children[i].who); ! 79: children[i].who = 0; ! 80: /* some more? */ ! 81: if (children[i].pid) ! 82: kill(children[i].pid, SIGKILL); /* who did we kill?*/ ! 83: break; ! 84: } ! 85: /*sprintf(buf, "/dev/dk/dk%02d", mesg.m_chan);*/ ! 86: p = (char *) dkfilename(mesg.m_chan); ! 87: if((fd = open(p, 2)) < 0) { ! 88: perror(p); ! 89: goto nakit; ! 90: } ! 91: if (fd >= NORMAN) { ! 92: close(fd); ! 93: debug("too many connections, nak"); ! 94: goto nakit; ! 95: } ! 96: if(children[fd].flags) { ! 97: debug("opened %s twice", buf); ! 98: debug("pid %d fd %d flags %d %s\n", children[fd].pid, ! 99: children[fd].fd, children[fd].flags, ! 100: children[fd].who); ! 101: /* who should we believe? the new one */ ! 102: if(children[fd].pid != 0) ! 103: kill(children[fd].pid, SIGKILL); ! 104: /* did that pid exist, and was it us? */ ! 105: } ! 106: children[fd].pid = 0; ! 107: children[fd].fd = fd; ! 108: children[fd].flags = UNINIT; ! 109: children[fd].host = n; ! 110: children[fd].lastheard = time(0); ! 111: children[fd].who = malloc(strlen(mesg.m_source) + 1); ! 112: strcpy(children[fd].who, mesg.m_source); ! 113: debug("ok, %s (%d) on fd %d", mesg.m_source, n, fd); ! 114: if((i = dkproto(fd, rdk_ld)) < 0) { ! 115: /*if((i = ioctl(fd, FIOPUSHLD, &rdk_ld)) <0) {*/ ! 116: perror("rdk_ld"); ! 117: close(fd); ! 118: goto nakit; ! 119: } ! 120: dkmgrack(mesg.m_chan); ! 121: ioctl(fd, FIOPOPLD, 0); ! 122: if((i = dkproto(fd, dkp_ld)) < 0) { ! 123: /*if((i = ioctl(fd, FIOPUSHLD, &dkp_ld)) < 0) {*/ ! 124: perror("dkp_ld"); ! 125: close(fd); ! 126: goto nakit; /* clean up. too late to nak */ ! 127: } ! 128: FD_SET(fd, active); ! 129: } ! 130: ! 131: #define skip while(*p != '.' && *p && *p != '\n') p++ ! 132: readmgr() ! 133: { char *p; ! 134: debug("mgrbuf: %s", mgrbuf); ! 135: p = mgrbuf; ! 136: mesg.m_chan = 0; ! 137: while(*p >= '0' && *p <= '7') ! 138: mesg.m_chan = mesg.m_chan * 8 + *p++ - '0'; ! 139: if(mesg.m_chan == 0) { ! 140: debug("incall wanted channel 0"); ! 141: return(0); ! 142: } ! 143: while(*p && *p != '\n') ! 144: p++; ! 145: if(*p++ != '\n') { ! 146: debug("bad incall message %s", mgrbuf); ! 147: return(0); ! 148: } ! 149: mesg.m_dial = p; ! 150: mesg.m_service = 0; ! 151: skip; ! 152: if(*p == '.') { ! 153: *p++ = 0; ! 154: mesg.m_service = p; ! 155: while(*p != '\n' && *p) ! 156: p++; ! 157: } ! 158: if(*p == '\n') ! 159: *p++ = 0; ! 160: mesg.m_param1 = 0; ! 161: mesg.m_param2 = 0; ! 162: mesg.m_uid = 0; ! 163: mesg.m_source = 0; ! 164: if(*p == 0) { ! 165: dkmgrnak(mesg.m_chan, 4); ! 166: debug("nak, no source"); ! 167: return(0); ! 168: } ! 169: /* two forms for source and uid are: ! 170: * uid ! 171: * source ! 172: * and ! 173: * source.uid ! 174: */ ! 175: mesg.m_source = p; ! 176: skip; ! 177: if(*p == '.') { ! 178: /* form 2 */ ! 179: *p++ = 0; ! 180: mesg.m_uid = p; ! 181: } else { ! 182: /* form 1 */ ! 183: *p++ = 0; ! 184: mesg.m_uid = mesg.m_source; ! 185: mesg.m_source = p; ! 186: } ! 187: skip; ! 188: *p++ = 0; ! 189: /* ignore the rest */ ! 190: return(1); ! 191: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.