|
|
1.1 ! root 1: #define DKMSGS 1 ! 2: #include <dk.h> ! 3: #include <dkerr.h> ! 4: #include <sgtty.h> ! 5: #include <stdio.h> ! 6: #include <signal.h> ! 7: #include <errno.h> ! 8: #include "dkdial.h" ! 9: ! 10: #define SUBR "/etc/dkdialsub" ! 11: ! 12: int dkverbose; ! 13: int dkrchan; ! 14: char *dkerror; ! 15: ! 16: static char *msgs[] = { ! 17: NULL, /* NORM */ ! 18: "bad call to dk dialler", /* ILLEG */ ! 19: "can't tell who you are", /* NOUID */ ! 20: "remote system doesn't respond", /* NOREP */ ! 21: "can't find dial program", /* NODIAL */ ! 22: "can't find outgoing channel", /* NOOCHAN */ ! 23: "can't open manager channel", /* NOMGR */ ! 24: "can't get dial tone", /* NODIALT */ ! 25: "DK controller system error", ! 26: "destination busy", ! 27: "remote node not answering", ! 28: "destination not answering", ! 29: "unassigned destination", ! 30: "DK system overload", ! 31: "server already exists", ! 32: }; ! 33: ! 34: static char *argbuf; ! 35: static char **bufptr; ! 36: extern int rdk_ld; ! 37: extern int errno ; ! 38: ! 39: int ! 40: tdkdial(dialstr, traffic) ! 41: int traffic ; ! 42: char * dialstr ; ! 43: { ! 44: return (_tdkdial(1, traffic, dialstr)) ; ! 45: } ! 46: ! 47: int ! 48: tdkserv(srvname, maxtraf) ! 49: int maxtraf ; ! 50: char * srvname ; ! 51: { ! 52: return (_tdkdial(2, maxtraf, srvname)) ; ! 53: } ! 54: ! 55: ! 56: int ! 57: _tdkdial (type, traffic, dialstr) ! 58: int type ; ! 59: int traffic ; ! 60: char * dialstr ; ! 61: { ! 62: register int fd, pid, rc; ! 63: char args[100]; ! 64: char *argptrs[10]; ! 65: int status; ! 66: struct dialout reply; ! 67: int pipefd[2]; ! 68: register i; ! 69: char outname[64]; ! 70: int popld ; ! 71: int oldchdie ; ! 72: int n3dig = 0, n2dig = 0; ! 73: extern errno; ! 74: static char alph[] = "0123456789abcdefghijklmnopqrstuvwxyz"; ! 75: ! 76: /* establish the initial connection */ ! 77: if (traffic) ! 78: traffic = 2; ! 79: for (i=3; i<256; i+=2) { ! 80: if (n3dig<3) { ! 81: sprintf(outname, "/dev/dk/dk%d%c%d", traffic, ! 82: alph[i/10], i%10); ! 83: if ((fd = open(outname, 2)) >= 0) ! 84: break; ! 85: if (errno==ENOENT) ! 86: n3dig++; ! 87: } ! 88: if (n2dig < 5) { ! 89: sprintf(outname, "/dev/dk/dk%c%d", alph[i/10], i%10); ! 90: if ((fd = open(outname, 2)) >= 0) ! 91: break; ! 92: if (errno==ENOENT) ! 93: ++n2dig; ! 94: } ! 95: } ! 96: if (fd < 0) { ! 97: dkerror = msgs[NOOCHAN]; ! 98: return fd; ! 99: } ! 100: ioctl(fd, FIOPUSHLD, &rdk_ld) ; ! 101: ! 102: /* create a pipe to the sub-process */ ! 103: if (pipe (pipefd) < 0) { ! 104: dkerror = "Can't pipe to dialler"; ! 105: close (fd); ! 106: return -1; ! 107: } ! 108: ! 109: /* build the arg list for the sub-process */ ! 110: arginit (args, argptrs); ! 111: strarg ("tdkdial"); ! 112: intarg (fd); ! 113: intarg (pipefd[1]); ! 114: intarg (type); ! 115: intarg(traffic) ; ! 116: strarg(dialstr) ; ! 117: argend(); ! 118: oldchdie = (int)signal(SIGCHLD, SIG_IGN) ; ! 119: ! 120: /* start up a sub-process */ ! 121: switch (pid = fork()) { ! 122: ! 123: /* child */ ! 124: case 0: ! 125: close (pipefd[0]); ! 126: setuid (geteuid()); ! 127: execv (SUBR, argptrs); ! 128: exit (NODIAL); ! 129: ! 130: /* error */ ! 131: case -1: ! 132: close (pipefd[0]); ! 133: close (pipefd[1]); ! 134: close(fd); ! 135: dkerror = "DK dialler can't fork"; ! 136: signal(SIGCHLD, oldchdie) ; ! 137: return -1; ! 138: ! 139: /* parent */ ! 140: default: ! 141: close (pipefd[1]); ! 142: ! 143: /* wait for the child to complete */ ! 144: do ! 145: rc = wait (&status); ! 146: while (rc > 0 && rc != pid); ! 147: signal(SIGCHLD, oldchdie) ; ! 148: /* figure out what happened */ ! 149: if (rc < 0 || status&0xff) { ! 150: dkerror = "DK dialler exited abnormally"; ! 151: goto bad; ! 152: } ! 153: /* read the reply */ ! 154: rc = read (pipefd[0], &reply, sizeof (reply)); ! 155: if (rc != sizeof (reply)) { ! 156: dkerror = "Bad reply from DK dialler"; ! 157: goto bad; ! 158: } ! 159: close (pipefd[0]); ! 160: if ((status & 0xFF00) == 0) { ! 161: ioctl(fd, FIOPOPLD, 0) ; ! 162: return fd; ! 163: } ! 164: status >>= 8; ! 165: if (status < sizeof(msgs)/sizeof(msgs[0])) ! 166: dkerror = msgs[status]; ! 167: else { ! 168: static char msg[32]; ! 169: sprintf(msg, "DK dial error %d", status-8); ! 170: dkerror = msg; ! 171: } ! 172: goto bad; ! 173: } ! 174: bad: ! 175: close (pipefd[0]); ! 176: close (fd); ! 177: return -1; ! 178: } ! 179: ! 180: ! 181: tdkerrmess (s) ! 182: register char *s; ! 183: { ! 184: if (dkverbose) ! 185: write (2, s, strlen(s)); ! 186: } ! 187: ! 188: ! 189: /* ! 190: * The following subroutines help build argument lists ! 191: */ ! 192: ! 193: static ! 194: arginit (x, y) ! 195: char *x; ! 196: char **y; ! 197: { ! 198: argbuf = x; ! 199: bufptr = y; ! 200: } ! 201: ! 202: ! 203: static ! 204: strarg (x) ! 205: register char *x; ! 206: { ! 207: *bufptr++ = x; ! 208: } ! 209: ! 210: ! 211: static ! 212: intarg (x) ! 213: int x; ! 214: { ! 215: *bufptr++ = argbuf; ! 216: if (x < 0) ! 217: *argbuf++ = '-'; ! 218: else ! 219: x = -x; ! 220: convint (x); ! 221: *argbuf++ = '\0'; ! 222: } ! 223: ! 224: ! 225: static ! 226: convint (x) ! 227: register int x; ! 228: { ! 229: if (x <= -10) ! 230: convint (x / 10); ! 231: *argbuf++ = '0' - x % 10; ! 232: } ! 233: ! 234: ! 235: static ! 236: argend() ! 237: { ! 238: *bufptr++ = 0; ! 239: } ! 240: ! 241:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.