Blob


1 /*
2 * Sun RPC; see RFC 1057
3 */
5 /*
6 #pragma lib "libsunrpc.a"
7 #pragma src "/sys/src/libsunrpc"
8 */
10 typedef uchar u1int;
12 typedef struct SunAuthInfo SunAuthInfo;
13 typedef struct SunAuthUnix SunAuthUnix;
14 typedef struct SunRpc SunRpc;
15 typedef struct SunCall SunCall;
17 enum
18 {
19 /* Authinfo.flavor */
20 SunAuthNone = 0,
21 SunAuthSys,
22 SunAuthShort,
23 SunAuthDes,
24 };
26 typedef enum {
27 SunAcceptError = 0x10000,
28 SunRejectError = 0x20000,
29 SunAuthError = 0x40000,
31 /* Reply.status */
32 SunSuccess = 0,
34 SunProgUnavail = SunAcceptError | 1,
35 SunProgMismatch,
36 SunProcUnavail,
37 SunGarbageArgs,
38 SunSystemErr,
40 SunRpcMismatch = SunRejectError | 0,
42 SunAuthBadCred = SunAuthError | 1,
43 SunAuthRejectedCred,
44 SunAuthBadVerf,
45 SunAuthRejectedVerf,
46 SunAuthTooWeak,
47 SunAuthInvalidResp,
48 SunAuthFailed,
49 } SunStatus;
51 struct SunAuthInfo
52 {
53 uint flavor;
54 uchar *data;
55 uint ndata;
56 };
58 struct SunAuthUnix
59 {
60 u32int stamp;
61 char *sysname;
62 u32int uid;
63 u32int gid;
64 u32int g[16];
65 u32int ng;
66 };
68 struct SunRpc
69 {
70 u32int xid;
71 uint iscall;
73 /*
74 * only sent on wire in call
75 * caller fills in for the reply unpackers.
76 */
77 u32int proc;
79 /* call */
80 // uint proc;
81 u32int prog, vers;
82 SunAuthInfo cred;
83 SunAuthInfo verf;
84 uchar *data;
85 uint ndata;
87 /* reply */
88 u32int status;
89 // SunAuthInfo verf;
90 u32int low, high;
91 // uchar *data;
92 // uint ndata;
93 };
95 typedef enum
96 {
97 SunCallTypeTNull,
98 SunCallTypeRNull,
99 } SunCallType;
101 struct SunCall
103 SunRpc rpc;
104 SunCallType type;
105 };
107 void sunerrstr(SunStatus);
109 void sunrpcprint(Fmt*, SunRpc*);
110 uint sunrpcsize(SunRpc*);
111 SunStatus sunrpcpack(uchar*, uchar*, uchar**, SunRpc*);
112 SunStatus sunrpcunpack(uchar*, uchar*, uchar**, SunRpc*);
114 void sunauthinfoprint(Fmt*, SunAuthInfo*);
115 uint sunauthinfosize(SunAuthInfo*);
116 int sunauthinfopack(uchar*, uchar*, uchar**, SunAuthInfo*);
117 int sunauthinfounpack(uchar*, uchar*, uchar**, SunAuthInfo*);
119 void sunauthunixprint(Fmt*, SunAuthUnix*);
120 uint sunauthunixsize(SunAuthUnix*);
121 int sunauthunixpack(uchar*, uchar*, uchar**, SunAuthUnix*);
122 int sunauthunixunpack(uchar*, uchar*, uchar**, SunAuthUnix*);
124 int sunenumpack(uchar*, uchar*, uchar**, int*);
125 int sunenumunpack(uchar*, uchar*, uchar**, int*);
126 int sunuint1pack(uchar*, uchar*, uchar**, u1int*);
127 int sunuint1unpack(uchar*, uchar*, uchar**, u1int*);
129 int sunstringpack(uchar*, uchar*, uchar**, char**, u32int);
130 int sunstringunpack(uchar*, uchar*, uchar**, char**, u32int);
131 uint sunstringsize(char*);
133 int sunuint32pack(uchar*, uchar*, uchar**, u32int*);
134 int sunuint32unpack(uchar*, uchar*, uchar**, u32int*);
135 int sunuint64pack(uchar*, uchar*, uchar**, u64int*);
136 int sunuint64unpack(uchar*, uchar*, uchar**, u64int*);
138 int sunvaropaquepack(uchar*, uchar*, uchar**, uchar**, u32int*, u32int);
139 int sunvaropaqueunpack(uchar*, uchar*, uchar**, uchar**, u32int*, u32int);
140 uint sunvaropaquesize(u32int);
142 int sunfixedopaquepack(uchar*, uchar*, uchar**, uchar*, u32int);
143 int sunfixedopaqueunpack(uchar*, uchar*, uchar**, uchar*, u32int);
144 uint sunfixedopaquesize(u32int);
146 /*
147 * Sun RPC Program
148 */
149 typedef struct SunProc SunProc;
150 typedef struct SunProg SunProg;
151 struct SunProg
153 uint prog;
154 uint vers;
155 SunProc *proc;
156 int nproc;
157 };
159 struct SunProc
161 int (*pack)(uchar*, uchar*, uchar**, SunCall*);
162 int (*unpack)(uchar*, uchar*, uchar**, SunCall*);
163 uint (*size)(SunCall*);
164 void (*fmt)(Fmt*, SunCall*);
165 uint sizeoftype;
166 };
168 SunStatus suncallpack(SunProg*, uchar*, uchar*, uchar**, SunCall*);
169 SunStatus suncallunpack(SunProg*, uchar*, uchar*, uchar**, SunCall*);
170 SunStatus suncallunpackalloc(SunProg*, SunCallType, uchar*, uchar*, uchar**, SunCall**);
171 void suncallsetup(SunCall*, SunProg*, uint);
172 uint suncallsize(SunProg*, SunCall*);
174 /*
175 * Formatting
176 #pragma varargck type "B" SunRpc*
177 #pragma varargck type "C" SunCall*
178 */
180 int sunrpcfmt(Fmt*);
181 int suncallfmt(Fmt*);
182 void sunfmtinstall(SunProg*);
185 /*
186 * Sun RPC Server
187 */
188 typedef struct SunMsg SunMsg;
189 typedef struct SunSrv SunSrv;
191 enum
193 SunStackSize = 32768,
194 };
196 struct SunMsg
198 uchar *data;
199 int count;
200 SunSrv *srv;
201 SunRpc rpc;
202 SunProg *pg;
203 SunCall *call;
204 Channel *creply; /* chan(SunMsg*) */
205 };
207 struct SunSrv
209 int chatty;
210 int cachereplies;
211 int alwaysreject;
212 int localonly;
213 int localparanoia;
214 SunProg **map;
215 Channel *crequest;
217 /* implementation use only */
218 Channel **cdispatch;
219 SunProg **prog;
220 int nprog;
221 void *cache;
222 Channel *creply;
223 Channel *cthread;
224 };
226 SunSrv *sunsrv(void);
228 void sunsrvprog(SunSrv *srv, SunProg *prog, Channel *c);
229 int sunsrvannounce(SunSrv *srv, char *address);
230 int sunsrvudp(SunSrv *srv, char *address);
231 int sunsrvnet(SunSrv *srv, char *address);
232 int sunsrvfd(SunSrv *srv, int fd);
233 void sunsrvthreadcreate(SunSrv *srv, void (*fn)(void*), void*);
234 void sunsrvclose(SunSrv*);
236 int sunmsgreply(SunMsg*, SunCall*);
237 int sunmsgdrop(SunMsg*);
238 int sunmsgreplyerror(SunMsg*, SunStatus);
240 /*
241 * Sun RPC Client
242 */
243 typedef struct SunClient SunClient;
245 struct SunClient
247 int fd;
248 int chatty;
249 int needcount;
250 ulong maxwait;
251 ulong xidgen;
252 int nsend;
253 int nresend;
254 struct {
255 ulong min;
256 ulong max;
257 ulong avg;
258 } rtt;
259 Channel *dying;
260 Channel *rpcchan;
261 Channel *timerchan;
262 Channel *flushchan;
263 Channel *readchan;
264 SunProg **prog;
265 int nprog;
266 int timertid;
267 int nettid;
268 };
270 SunClient *sundial(char*);
272 int sunclientrpc(SunClient*, ulong, SunCall*, SunCall*, uchar**);
273 void sunclientclose(SunClient*);
274 void sunclientflushrpc(SunClient*, ulong);
275 void sunclientprog(SunClient*, SunProg*);
278 /*
279 * Provided by callers.
280 * Should remove dependence on this, but hard.
281 */
282 void *emalloc(ulong);
283 void *erealloc(void*, ulong);
286 /*
287 * Sun RPC port mapper; see RFC 1057 Appendix A
288 */
290 typedef struct PortMap PortMap;
291 typedef struct PortTNull PortTNull;
292 typedef struct PortRNull PortRNull;
293 typedef struct PortTSet PortTSet;
294 typedef struct PortRSet PortRSet;
295 typedef struct PortTUnset PortTUnset;
296 typedef struct PortRUnset PortRUnset;
297 typedef struct PortTGetport PortTGetport;
298 typedef struct PortRGetport PortRGetport;
299 typedef struct PortTDump PortTDump;
300 typedef struct PortRDump PortRDump;
301 typedef struct PortTCallit PortTCallit;
302 typedef struct PortRCallit PortRCallit;
304 typedef enum
306 PortCallTNull,
307 PortCallRNull,
308 PortCallTSet,
309 PortCallRSet,
310 PortCallTUnset,
311 PortCallRUnset,
312 PortCallTGetport,
313 PortCallRGetport,
314 PortCallTDump,
315 PortCallRDump,
316 PortCallTCallit,
317 PortCallRCallit,
318 } PortCallType;
320 enum
322 PortProgram = 100000,
323 PortVersion = 2,
325 PortProtoTcp = 6, /* protocol number for TCP/IP */
326 PortProtoUdp = 17 /* protocol number for UDP/IP */
327 };
329 struct PortMap {
330 u32int prog;
331 u32int vers;
332 u32int prot;
333 u32int port;
334 };
336 struct PortTNull {
337 SunCall call;
338 };
340 struct PortRNull {
341 SunCall call;
342 };
344 struct PortTSet {
345 SunCall call;
346 PortMap map;
347 };
349 struct PortRSet {
350 SunCall call;
351 u1int b;
352 };
354 struct PortTUnset {
355 SunCall call;
356 PortMap map;
357 };
359 struct PortRUnset {
360 SunCall call;
361 u1int b;
362 };
364 struct PortTGetport {
365 SunCall call;
366 PortMap map;
367 };
369 struct PortRGetport {
370 SunCall call;
371 u32int port;
372 };
374 struct PortTDump {
375 SunCall call;
376 };
378 struct PortRDump {
379 SunCall call;
380 PortMap *map;
381 int nmap;
382 };
384 struct PortTCallit {
385 SunCall call;
386 u32int prog;
387 u32int vers;
388 u32int proc;
389 uchar *data;
390 u32int count;
391 };
393 struct PortRCallit {
394 SunCall call;
395 u32int port;
396 uchar *data;
397 u32int count;
398 };
400 extern SunProg portprog;