1 #include "all.h"
2
3 static void pcinit(int, char**);
4 static int pcnull(int, Rpccall*, Rpccall*);
5 static int pcinfo(int, Rpccall*, Rpccall*);
6 static int pcauth(int, Rpccall*, Rpccall*);
7 static int pc1auth(int, Rpccall*, Rpccall*);
8 static int pcfacilities[15];
9 static char no_comment[] = "Trust me.";
10 static char pc_vers[] = "@(#)pcnfsd_v2.c 1.6 - rpc.pcnfsd V2.0 (c) 1994 P9, GmbH";
11 static char pc_home[] = "merrimack:/";
12
13 static Procmap pcproc[] = { /* pcnfsd v2 */
14 0, pcnull,
15 1, pcinfo,
16 13, pcauth,
17 0, 0
18 };
19
20 static Procmap pc1proc[] = { /* pc-nfsd v1 */
21 0, pcnull,
22 1, pc1auth,
23 0, 0
24 };
25
26 int myport = 1111;
27
28 Progmap progmap[] = {
29 150001, 2, pcinit, pcproc,
30 150001, 1, 0, pc1proc,
31 0, 0, 0,
32 };
33
34 void
main(int argc,char * argv[])35 main(int argc, char *argv[])
36 {
37 server(argc, argv, myport, progmap);
38 }
39
40 static void
pcinit(int argc,char ** argv)41 pcinit(int argc, char **argv)
42 {
43 Procmap *p;
44 int i;
45 char *config = "config";
46
47 ARGBEGIN{
48 case 'c':
49 config = ARGF();
50 break;
51 default:
52 if(argopt(ARGC()) < 0)
53 sysfatal("usage: %s %s [-c config]", argv0, commonopts);
54 break;
55 }ARGEND;
56 clog("pc init\n");
57
58 for(i=0; i<nelem(pcfacilities); i++)
59 pcfacilities[i] = -1;
60 for(p=pcproc; p->procp; p++)
61 pcfacilities[p->procno] = 100;
62 readunixidmaps(config);
63 }
64
65 static int
pcnull(int n,Rpccall * cmd,Rpccall * reply)66 pcnull(int n, Rpccall *cmd, Rpccall *reply)
67 {
68 USED(n, cmd, reply);
69 return 0;
70 }
71
72 static void
scramble(String * x)73 scramble(String *x)
74 {
75 int i;
76
77 for(i=0; i<x->n; i++)
78 x->s[i] = (x->s[i] ^ 0x5b) & 0x7f;
79 }
80
81 static int
pcinfo(int n,Rpccall * cmd,Rpccall * reply)82 pcinfo(int n, Rpccall *cmd, Rpccall *reply)
83 {
84 uchar *argptr = cmd->args;
85 uchar *dataptr = reply->results;
86 String vers, cm;
87 int i;
88
89 chat("host=%I, port=%ld: pcinfo...",
90 cmd->host, cmd->port);
91 if(n <= 16)
92 return garbage(reply, "count too small");
93 argptr += string2S(argptr, &vers);
94 argptr += string2S(argptr, &cm);
95 if(argptr != &((uchar *)cmd->args)[n])
96 return garbage(reply, "bad count");
97 chat("\"%.*s\",\"%.*s\"\n", utfnlen(vers.s, vers.n), vers.s, utfnlen(cm.s, cm.n), cm.s);
98 PLONG(sizeof(pc_vers)-1);
99 PPTR(pc_vers, sizeof(pc_vers)-1);
100 PLONG(sizeof(no_comment)-1);
101 PPTR(no_comment, sizeof(no_comment)-1);
102 PLONG(nelem(pcfacilities));
103 for(i=0; i<nelem(pcfacilities); i++)
104 PLONG(pcfacilities[i]);
105 return dataptr - (uchar *)reply->results;
106 }
107
108 static int
pc1auth(int n,Rpccall * cmd,Rpccall * reply)109 pc1auth(int n, Rpccall *cmd, Rpccall *reply)
110 {
111 uchar *argptr = cmd->args;
112 uchar *dataptr = reply->results;
113 String id, pw;
114 Unixidmap *m;
115 int uid;
116
117 chat("host=%I, port=%ld: pcauth...",
118 cmd->host, cmd->port);
119 if(n <= 8)
120 return garbage(reply, "count too small");
121 argptr += string2S(argptr, &id);
122 argptr += string2S(argptr, &pw);
123 if(argptr != &((uchar*)cmd->args)[n])
124 return garbage(reply, "bad count");
125 scramble(&id);
126 scramble(&pw);
127 m = pair2idmap("pcnfsd", cmd->host);
128 uid = -1;
129 if(m)
130 uid = name2id(&m->u.ids, id.s);
131 if(uid < 0)
132 uid = 1;
133 chat("\"%.*s\",\"%.*s\" uid=%d\n", utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, uid);
134 PLONG(0); /* status */
135 PLONG(uid); /* uid */
136 PLONG(uid); /* gid */
137 return dataptr - (uchar*)reply->results;
138 }
139
140 static int
pcauth(int n,Rpccall * cmd,Rpccall * reply)141 pcauth(int n, Rpccall *cmd, Rpccall *reply)
142 {
143 uchar *argptr = cmd->args;
144 uchar *dataptr = reply->results;
145 String sys, id, pw, cm;
146 Unixidmap *m;
147 int uid;
148
149 chat("host=%I, port=%ld: pcauth...",
150 cmd->host, cmd->port);
151 if(n <= 16)
152 return garbage(reply, "count too small");
153 argptr += string2S(argptr, &sys);
154 argptr += string2S(argptr, &id);
155 argptr += string2S(argptr, &pw);
156 argptr += string2S(argptr, &cm);
157 if(argptr != &((uchar *)cmd->args)[n])
158 return garbage(reply, "bad count");
159 scramble(&id);
160 scramble(&pw);
161
162 m = pair2idmap("pcnfsd", cmd->host);
163 uid = -1;
164 if(m)
165 uid = name2id(&m->u.ids, id.s);
166 if(uid < 0)
167 uid = 1;
168 chat("\"%.*s\",\"%.*s\",\"%.*s\",\"%.*s\"\n", utfnlen(sys.s, sys.n), sys.s,
169 utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, utfnlen(cm.s, cm.n), cm.s);
170 PLONG(0); /* status - OK */
171 PLONG(uid);
172 PLONG(uid); /* gid */
173 PLONG(0); /* ngids */
174 PLONG(sizeof(pc_home)-1);
175 PPTR(pc_home, sizeof(pc_home)-1);
176 PLONG(0); /* umask */
177 PLONG(sizeof(no_comment)-1);
178 PPTR(no_comment, sizeof(no_comment)-1);
179 return dataptr - (uchar *)reply->results;
180 }
181