|
|
1.1 ! root 1: #include "mgr.h" ! 2: #include <sys/param.h> ! 3: #include <sys/filio.h> ! 4: #include <sys/inio.h> ! 5: #include <pwd.h> ! 6: #include <ctype.h> ! 7: #include "defs.h" ! 8: ! 9: int debug; ! 10: ! 11: /* ! 12: * get parameters from caller ! 13: */ ! 14: parms(rp, ap) ! 15: Request *rp; ! 16: Action *ap; ! 17: { ! 18: char *s; ! 19: char *rdline(); ! 20: ! 21: USE(ap); ! 22: if ((s = rdline(rp->i->cfd)) == NULL) ! 23: return -1; ! 24: rp->args = strdup(s); ! 25: return 0; ! 26: } ! 27: ! 28: /* ! 29: * get system V parameters from caller ! 30: */ ! 31: char * ! 32: rdstring(fd) ! 33: int fd; ! 34: { ! 35: static char buf[ARB]; ! 36: int len; ! 37: ! 38: /* get count */ ! 39: if (read(fd, buf, 2)!=2) ! 40: return NULL; ! 41: len = (((unsigned char)buf[1])<<8)+((unsigned char)buf[0]); ! 42: if(len>=ARB||len<0) ! 43: return NULL; ! 44: if (len>0 && read(fd, buf, len)!=len) ! 45: return NULL; ! 46: buf[len] = '\0'; ! 47: return buf; ! 48: } ! 49: ! 50: s5parms(rp, ap) ! 51: Request *rp; ! 52: Action *ap; ! 53: { ! 54: #include <sys/ttyio.h> ! 55: struct sgttyb ttyb; ! 56: char *s; ! 57: char *cp; ! 58: ! 59: USE(ap); ! 60: ! 61: /* ! 62: * name is flag string for service ! 63: */ ! 64: for (cp=rp->i->name; *cp && *cp!='.'; cp++){ ! 65: switch(*cp){ ! 66: case 'v': ! 67: case 'd': ! 68: /* ignore an input string */ ! 69: rdstring(rp->i->cfd); ! 70: break; ! 71: case 'a': ! 72: /* get the arg string */ ! 73: if ((s = rdstring(rp->i->cfd)) == NULL) ! 74: return -1; ! 75: rp->args = strdup(s); ! 76: break; ! 77: case 't': ! 78: if(ttyld(rp, ap)!=0) ! 79: return -1; ! 80: ioctl(rp->i->cfd, TIOCGETP, &ttyb); ! 81: ttyb.sg_flags &= ~ECHO; ! 82: ioctl(rp->i->cfd, TIOCSETP, &ttyb); ! 83: break; ! 84: } ! 85: } ! 86: if(*cp=='.') ! 87: cp++; ! 88: ! 89: /* ! 90: * cp now points to field after flag field ! 91: */ ! 92: return 0; ! 93: } ! 94: ! 95: /* ! 96: * get terminal type(speed, etc) from caller ! 97: */ ! 98: term(rp, ap) ! 99: Request *rp; ! 100: Action *ap; ! 101: { ! 102: char pbuf[ARB]; ! 103: char *s, *sl; ! 104: char *rdline(); ! 105: char *strchr(); ! 106: ! 107: USE(ap); ! 108: if (ap->arg!=NULL && *(ap->arg)!='\0') { ! 109: rp->term = strdup(ap->arg); ! 110: } else { ! 111: if((s = rdline(rp->i->cfd)) == NULL) ! 112: return -1; ! 113: if(sl=strchr(s, '/')) ! 114: *sl = '\0'; ! 115: rp->term = strdup(s); ! 116: } ! 117: return 0; ! 118: } ! 119: ! 120: /* ! 121: * action routines that end in execs ! 122: */ ! 123: ! 124: doconn(rp, ap) ! 125: Request *rp; ! 126: Action *ap; ! 127: { ! 128: USE(ap); ! 129: ioctl(rp->i->cfd, TCPIOHUP, 0); /* hang-up TCP on FIN */ ! 130: login(rp, rp->line, (char *)NULL); ! 131: } ! 132: ! 133: #define SNDMSG(x) write(rp->i->cfd, x, strlen(x)) ! 134: doexec(rp, ap) ! 135: Request *rp; ! 136: Action *ap; ! 137: { ! 138: USE(ap); ! 139: if(rp->line==0 || *rp->line==0) { ! 140: SNDMSG("access denied\n"); ! 141: _exit(1); ! 142: } ! 143: login(rp, rp->line, rp->args); ! 144: } ! 145: ! 146: docmd(rp, ap) ! 147: Request *rp; ! 148: Action *ap; ! 149: { ! 150: register char *p; ! 151: char buf[ARB]; ! 152: int execit; ! 153: ! 154: /* ! 155: * protect against sh security holes ! 156: */ ! 157: for(p=rp->args; *p; p++) ! 158: if (strchr("\n&;^|<>(){}`", *p)) ! 159: *p = ' '; ! 160: /* ! 161: * avoid an extra process ! 162: */ ! 163: for(execit=1,p=ap->arg; *p; p++) ! 164: if (strchr("=\n&;^|(){}`", *p)) ! 165: execit=0; ! 166: if(execit) ! 167: strcpy(buf, "exec "); ! 168: else ! 169: buf[0]=0; ! 170: strcat(buf, ap->arg); ! 171: strcat(buf, " "); ! 172: /* ! 173: for(p=rp->args; *p && !isspace(*p); p++) ! 174: ; ! 175: */ ! 176: strcat(buf, rp->args); ! 177: login(rp, rp->line, buf); ! 178: } ! 179: ! 180: dologin(rp, ap) ! 181: Request *rp; ! 182: Action *ap; ! 183: { ! 184: USE(ap); ! 185: login(rp, (char *)0, (char *)0); ! 186: } ! 187: ! 188: login(rp, pw, cmd) ! 189: Request *rp; ! 190: char *pw, *cmd; ! 191: { ! 192: char *args[5]; ! 193: char buf[512]; ! 194: char *cp; ! 195: register char **ap; ! 196: register int i; ! 197: char **inienv; ! 198: char **srcenv(), **termenv(); ! 199: ! 200: if(debug) ! 201: logtime("login:\n"); ! 202: errno = 0; errstr = ""; ! 203: buf[0] = '\0'; ! 204: logstatus("in", rp->i); ! 205: ap = args; ! 206: *ap++ = "login"; ! 207: if (pw) { ! 208: *ap++ = "-p"; ! 209: *ap++ = pw; ! 210: strcpy(buf, " -p "); ! 211: for(cp=buf+4; *pw && *pw!=':';) ! 212: *cp++ = *pw++; ! 213: *cp = '\0'; ! 214: } ! 215: if (cmd) { ! 216: *ap++ = cmd; ! 217: strcat(buf, " "); ! 218: strcat(buf, cmd); ! 219: } ! 220: *ap = NULL; ! 221: pwclose(); ! 222: logevent("login %s\n", buf); ! 223: for (i = 0; i < NSYSFILE; i++) ! 224: dup2(rp->i->cfd, i); ! 225: if (rp->errfd>=0) ! 226: dup2(rp->errfd, 2); ! 227: if(rp->i->cfd>=NSYSFILE) ! 228: close(rp->i->cfd); ! 229: if(rp->errfd>=NSYSFILE) ! 230: close(rp->errfd); ! 231: if (rp->term) ! 232: termenv(rp); ! 233: inienv = srcenv(rp); ! 234: ioctl(0, TIOCSPGRP, 0); ! 235: execve("/etc/login", args, inienv); ! 236: execve("/bin/login", args, inienv); ! 237: _exit(1); ! 238: } ! 239: ! 240: char **newep; /* set up by init */ ! 241: char *newenv[5]; ! 242: ! 243: char ** ! 244: srcenv(rp) ! 245: Request *rp; ! 246: { ! 247: static char cbuf[ARB]; ! 248: static char nbuf[ARB]; ! 249: char param[ARB]; ! 250: char *field[10]; ! 251: char *line; ! 252: int i; ! 253: ! 254: line=""; ! 255: strcpy(param, rp->i->param); ! 256: setfields(" "); ! 257: i=getfields(param, field, 10); ! 258: for(; i; i--) ! 259: if(strncmp(field[i-1], "PSOURCE=", 8)==0){ ! 260: line=field[i-1]+8; ! 261: break; ! 262: } ! 263: sprintf(cbuf, "CSOURCE=source=%s user=%s line=%s", ! 264: rp->i->machine, rp->i->user, line); ! 265: *newep++ = cbuf; ! 266: sprintf(nbuf, "CDEST=%s!%s", rp->i->myname, rp->i->name); ! 267: *newep++ = nbuf; ! 268: *newep = NULL; ! 269: return (newenv); ! 270: } ! 271: ! 272: char ** ! 273: termenv(rp) ! 274: Request *rp; ! 275: { ! 276: static char buf[100]; ! 277: ! 278: sprintf(buf, "TERM=%s", rp->term); ! 279: *newep++ = buf; ! 280: *newep = NULL; ! 281: return (newenv); ! 282: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.