|
|
1.1 ! root 1: /* ! 2: * dkcc -- Remote Execute or Login over DATAKIT VCS to UNIX-V ! 3: */ ! 4: static char SCCSID[] = "@(#)dkrx.c 2.1 DKHOST 84/07/03"; ! 5: ! 6: #include <stdio.h> ! 7: #include <ipc.h> ! 8: #include "sysexits.h" ! 9: #include "string.h" ! 10: /* extern int dkp_ld ; */ ! 11: /* extern char * dkerror ; */ ! 12: ! 13: char system[64]; ! 14: char *ttyname(); ! 15: ! 16: main(argc, argv) ! 17: char **argv; ! 18: { ! 19: register int f, exitcode; ! 20: register char *p, *ttyn; ! 21: int force, env; ! 22: extern char *miscfield() ; ! 23: char * cmdname ; ! 24: ! 25: cmdname = argv[0] ; ! 26: if(p = strrchr(argv[0], '/')) ! 27: strcpy(system, p+1); ! 28: else ! 29: strcpy(system, argv[0]); ! 30: ! 31: argc--; argv++; ! 32: ! 33: if(strcmp(argv[0], "-f") == 0){ ! 34: force = 1; ! 35: argc--; argv++; ! 36: }else ! 37: force = 0; ! 38: ! 39: env = 1; ! 40: ! 41: if(strcmp(system, "dkcc") == 0) { ! 42: if(argc == 0){ ! 43: fprintf(stderr, "Usage: dkcc system [ command [ args ] ]\n"); ! 44: exit(EX_USAGE); ! 45: } ! 46: ! 47: ! 48: strcpy(system, argv[0]); ! 49: ! 50: argc--; argv++; ! 51: } ! 52: ! 53: ! 54: if(argc > 0) ! 55: strcpy(system, maphost(system, 'x', "rx", "aevx", "")); ! 56: else ! 57: strcpy(system, maphost(system, 'l', "rl", "vx", "")); ! 58: ! 59: if(p = miscfield((argc > 0) ? 'x' : 'l', 'c')) ! 60: execalt(p, system, argv); ! 61: ! 62: if(p = miscfield((argc > 0) ? 'x' : 'l', 'v')) ! 63: env = (*p == 'y'); ! 64: ! 65: f = ipcopen (ipcpath (system, "dk", ""), "heavy"); ! 66: if (f < 0) { ! 67: fprintf(stderr, ! 68: "%s: call to %s failed, %s\n", cmdname, system, errstr); ! 69: exit (-f); ! 70: } ! 71: ! 72: exitcode = 0; ! 73: ! 74: if(env) ! 75: exitcode = dkxenviron(f); ! 76: ! 77: if(exitcode >= 0 && argc > 0) ! 78: exitcode = sendargs(f, argv, !!miscfield('x', 's')); ! 79: ! 80: if(exitcode >= 0) ! 81: exitcode = dkxstdio(f); ! 82: ! 83: if(exitcode == -EX_IOERR && argc == 0) ! 84: exit(0); /* no exitcode specified */ ! 85: else if(exitcode < 0) ! 86: exit(-exitcode); /* if error processing the call */ ! 87: else if(exitcode & 0xFF) ! 88: exit(exitcode | 0x80); /* remote terminated on signal */ ! 89: else ! 90: exit(exitcode>>8); /* else it finished with this code */ ! 91: } ! 92: ! 93: execalt(string, system, argv) ! 94: char *string, *system; ! 95: char *argv[]; ! 96: { ! 97: char **ap, *args[32]; ! 98: ! 99: ap = args; ! 100: ! 101: do{ ! 102: *ap++ = string; ! 103: ! 104: if(string = strchr(string, ':')) ! 105: *string++ = '\0'; ! 106: }while(string); ! 107: ! 108: *ap++ = system; ! 109: while(*ap++ = *argv++); ! 110: ! 111: execvp(args[0], args); ! 112: ! 113: fprintf(stderr, "dk: Can't exec %s\n", args[0]); ! 114: exit(EX_UNAVAILABLE); ! 115: } ! 116: ! 117: sendargs(fd, argarray, minusc) ! 118: char *argarray[]; ! 119: { ! 120: register int aoffset; ! 121: char argstring[2048]; ! 122: ! 123: if(minusc){ ! 124: aoffset = 3; ! 125: strcpy(argstring, "-c"); ! 126: }else ! 127: aoffset = 0; ! 128: ! 129: return(dkxlwrite(fd, argstring, bldargs(&argstring[aoffset], argarray) + aoffset)); ! 130: } ! 131: ! 132: bldargs(args, argv) ! 133: char *args; ! 134: register char *argv[]; ! 135: { ! 136: register char *s, *t; ! 137: ! 138: s = args; ! 139: ! 140: if (t = *argv++) { ! 141: while (*s++ = *t++); ! 142: ! 143: s[-1] = ' '; ! 144: } ! 145: while(t = *argv++){ ! 146: *s++ = '"'; ! 147: ! 148: while(*s++ = *t++); ! 149: ! 150: s[-1] = '"'; ! 151: *s++ = ' '; ! 152: } ! 153: *s++ = '\0'; ! 154: return(s - args); ! 155: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.