|
|
1.1 ! root 1: #include "mgr.h" ! 2: #include <sys/param.h> ! 3: #include <sys/ioctl.h> ! 4: #include <pwd.h> ! 5: #include <ctype.h> ! 6: #include "defs.h" ! 7: ! 8: /* ! 9: * get parameters from caller ! 10: */ ! 11: parms(rp, ap) ! 12: Request *rp; ! 13: Action *ap; ! 14: { ! 15: char pbuf[ARB]; ! 16: char *s; ! 17: char *rdline(); ! 18: char *strchr(); ! 19: ! 20: USE(ap); ! 21: if ((s = rdline(rp->i->cfd)) == NULL) ! 22: return -1; ! 23: rp->args = strdup(s); ! 24: return 0; ! 25: } ! 26: ! 27: /* ! 28: * get terminal type(speed, etc) from caller ! 29: */ ! 30: term(rp, ap) ! 31: Request *rp; ! 32: Action *ap; ! 33: { ! 34: char pbuf[ARB]; ! 35: char *s, *sl; ! 36: char *rdline(); ! 37: char *strchr(); ! 38: ! 39: USE(ap); ! 40: if (ap->arg!=NULL && *(ap->arg)!='\0') { ! 41: rp->term = strdup(ap->arg); ! 42: } else { ! 43: if((s = rdline(rp->i->cfd)) == NULL) ! 44: return -1; ! 45: if(sl=strchr(s, '/')) ! 46: *sl = '\0'; ! 47: rp->term = strdup(s); ! 48: } ! 49: return 0; ! 50: } ! 51: ! 52: /* ! 53: * action routines that end in execs ! 54: */ ! 55: ! 56: doconn(rp, ap) ! 57: Request *rp; ! 58: Action *ap; ! 59: { ! 60: USE(ap); ! 61: ioctl(rp->i->cfd, TCPIOHUP, 0); /* hang-up TCP on FIN */ ! 62: login(rp, rp->line, (char *)NULL); ! 63: } ! 64: ! 65: doexec(rp, ap) ! 66: Request *rp; ! 67: Action *ap; ! 68: { ! 69: USE(ap); ! 70: login(rp, rp->line, rp->args); ! 71: } ! 72: ! 73: docmd(rp, ap) ! 74: Request *rp; ! 75: Action *ap; ! 76: { ! 77: register char *p; ! 78: char buf[ARB]; ! 79: ! 80: for(p=rp->args; *p; p++) ! 81: if (strchr("\n&;^|<>(){}`", *p)) ! 82: *p = ' '; ! 83: strcpy(buf, ap->arg); ! 84: strcat(buf, " "); ! 85: /* ! 86: for(p=rp->args; *p && !isspace(*p); p++) ! 87: ; ! 88: */ ! 89: strcat(buf, rp->args); ! 90: login(rp, rp->line, buf); ! 91: } ! 92: ! 93: login(rp, pw, cmd) ! 94: Request *rp; ! 95: char *pw, *cmd; ! 96: { ! 97: char *args[5]; ! 98: register char **ap; ! 99: register int i; ! 100: char **inienv; ! 101: char **srcenv(), **termenv(); ! 102: ! 103: ap = args; ! 104: *ap++ = "login"; ! 105: if (pw) { ! 106: *ap++ = "-p"; ! 107: *ap++ = pw; ! 108: if (cmd) ! 109: *ap++ = cmd; ! 110: } ! 111: *ap = NULL; ! 112: for (i = 0; i < NSYSFILE; i++) ! 113: dup2(rp->i->cfd, i); ! 114: for (; i < NOFILE; i++) ! 115: close(i); ! 116: termenv(rp); ! 117: inienv = srcenv(rp); ! 118: ioctl(0, TIOCSPGRP, 0); ! 119: execve("/etc/login", args, inienv); ! 120: execve("/bin/login", args, inienv); ! 121: _exit(1); ! 122: } ! 123: ! 124: char **newep; /* set up by init */ ! 125: char *newenv[5]; ! 126: ! 127: char ** ! 128: srcenv(rp) ! 129: Request *rp; ! 130: { ! 131: static char buf[100]; ! 132: ! 133: sprintf(buf, "CSOURCE=%s!%s", rp->i->machine, rp->i->user); ! 134: *newep++ = buf; ! 135: *newep = NULL; ! 136: return (newenv); ! 137: } ! 138: ! 139: char ** ! 140: termenv(rp) ! 141: Request *rp; ! 142: { ! 143: static char buf[100]; ! 144: ! 145: if (rp->term == NULL) ! 146: return (newenv); ! 147: sprintf(buf, "TERM=%s", rp->term); ! 148: *newep++ = buf; ! 149: *newep = NULL; ! 150: return (newenv); ! 151: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.