|
|
1.1 root 1: #include "mgr.h"
2: #include <pwd.h>
3: #include <sys/ioctl.h>
4: #include "defs.h"
5:
6: /*
7: * execute as a specific user
8: */
9: asuser(rp, ap)
10: Request *rp;
11: Action *ap;
12: {
13: char line[ARB];
14: struct passwd *pwsearch();
15:
16: if(pwsearch(ap->arg, -1, line)==NULL) {
17: logevent("bad login: %s\n", ap->arg);
18: return -1;
19: }
20: rp->line = strdup(line);
21: return 0;
22: }
23:
24: /*
25: * simple authentication
26: */
27: auth(rp, ap)
28: Request *rp;
29: Action *ap;
30: {
31: struct passwd *pw;
32: static char line[ARB];
33: struct passwd *pwsearch();
34: char *mapuser();
35: char *u;
36:
37: USE(ap);
38: /* do the mapping from the authentication files */
39: u = mapuser(rp->s->name, rp->i->machine, rp->i->user);
40: if(u!=NULL) {
41: if ((pw = pwsearch(u, -1, line)) != NULL
42: && strcmp(pw->pw_name, "root") != 0) {
43: rp->line = line;
44: return 0;
45: }
46: }
47: return 1;
48: }
49:
50: /*
51: * v9 authentication
52: */
53: v9auth(rp, ap)
54: Request *rp;
55: Action *ap;
56: {
57: struct passwd *pw;
58: static char line[ARB];
59: register char *u, *p;
60: struct passwd *pwsearch();
61: char *mapuser();
62: char *rdline();
63:
64: USE(ap);
65: /* do the mapping from the authentication files */
66: u = mapuser(rp->s->name, rp->i->machine, rp->i->user);
67: if(u!=NULL) {
68: if ((pw = pwsearch(u, -1, line)) != NULL
69: && pw->pw_uid != 0) {
70: write(rp->i->cfd, "OK", 2);
71: rp->line = line;
72: return 0;
73: }
74: }
75: for (;;) {
76: write(rp->i->cfd, "NO", 2);
77: if ((u = rdline(rp->i->cfd))==NULL)
78: return -1;
79: p = strchr(u, ',');
80: if (p)
81: *p++ = '\0';
82: if ((pw = pwsearch(u, -1, line)) == NULL)
83: continue;
84: if (strcmp(crypt(p, pw->pw_passwd), pw->pw_passwd) == 0)
85: break;
86: }
87: write(rp->i->cfd, "OK", 2);
88: rp->line = strdup(line);
89: return 0;
90: }
91:
92: /* 4.2BSD inet stye authentication */
93: #define SNDMSG(x) write(rp->i->cfd, x, strlen(x))
94: inauth(rp, ap)
95: Request *rp;
96: Action *ap;
97: {
98: static char line[ARB];
99: struct passwd *pw;
100: struct passwd *pwsearch();
101: char *port;
102: char *u;
103: char buf[ARB];
104: char *rdline();
105: char *mapuser();
106: char *tcptofs();
107:
108: USE(ap);
109: /* get port number for stderr */
110: port = rdline(rp->i->cfd);
111: if(port==NULL) {
112: SNDMSG("\nprotocol botch\n");
113: return -1;
114: }
115: if(*port!='\0')
116: rp->errfd = ipcopen(ipcpath(rp->i->machine, "tcp",
117: tcptofs(atoi(port))), "light");
118:
119: /* get remuser, locuser */
120: u = rdline(rp->i->cfd);
121: if(u==NULL) {
122: SNDMSG("\nprotocol botch\n");
123: return -1;
124: }
125: strcpy(buf, u);
126: u = rdline(rp->i->cfd);
127: if(u==NULL) {
128: SNDMSG("\nprotocol botch\n");
129: return -1;
130: }
131: if(strcmp(buf, u)!=0) {
132: SNDMSG("\ncannot specify user-id\n");
133: return -1;
134: }
135: write(rp->i->cfd, "", 1);
136:
137: /* authenticate */
138: if ((u=mapuser(rp->s->name, rp->i->machine, u))!=NULL) {
139: if ((pw = pwsearch(u, -1, line)) != NULL
140: && pw->pw_uid != 0)
141: rp->line = strdup(line);
142: }
143: return 0;
144: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.