xref: /netbsd-src/include/rpcsvc/yp_prot.h (revision 5b84b3983f71fd20a534cfa5d1556623a8aaa717)
1 /*	$NetBSD: yp_prot.h,v 1.14 2005/02/03 04:39:33 perry Exp $	*/
2 
3 /*
4  * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _RPCSVC_YP_PROT_H_
30 #define _RPCSVC_YP_PROT_H_
31 
32 /*
33  * YPSERV PROTOCOL:
34  *
35  * ypserv supports the following procedures:
36  *
37  * YPPROC_NULL		takes (void), returns (void).
38  * 			called to check if server is alive.
39  * YPPROC_DOMAIN	takes (char *), returns (bool_t).
40  * 			true if ypserv serves the named domain.
41  * YPPROC_DOMAIN_NOACK	takes (char *), returns (bool_t).
42  * 			true if ypserv serves the named domain.
43  *			used for broadcasts, does not ack if ypserv
44  *			doesn't handle named domain.
45  * YPPROC_MATCH		takes (struct ypreq_key), returns (struct ypresp_val)
46  * 			does a lookup.
47  * YPPROC_FIRST		takes (struct ypreq_nokey) returns (ypresp_key_val).
48  * 			gets the first key/datum from the map.
49  * YPPROC_NEXT		takes (struct ypreq_key) returns (ypresp_key_val).
50  * 			gets the next key/datum from the map.
51  * YPPROC_XFR		takes (struct ypreq_xfr), returns (void).
52  * 			tells ypserv to check if there is a new version of
53  *			the map.
54  * YPPROC_CLEAR		takes (void), returns (void).
55  * 			tells ypserv to flush it's file cache, so that
56  *			newly transferred files will get read.
57  * YPPROC_ALL		takes (struct ypreq_nokey), returns (bool_t and
58  *			struct ypresp_key_val).
59  * 			returns an array of data, with the bool_t being
60  * 			false on the last datum. read the source, it's
61  *			convoluted.
62  * YPPROC_MASTER	takes (struct ypreq_nokey), returns (ypresp_master).
63  * YPPROC_ORDER		takes (struct ypreq_nokey), returns (ypresp_order).
64  * YPPROC_MAPLIST	takes (char *), returns (struct ypmaplist *).
65  */
66 
67 #ifndef BOOL_DEFINED
68 typedef u_int bool;
69 #define BOOL_DEFINED
70 #endif
71 
72 
73 /* Program and version symbols, magic numbers */
74 #define YPPROG		((unsigned long)100004)
75 #define YPVERS		((unsigned long)2)
76 #define YPVERS_ORIG	((unsigned long)1)
77 
78 #define YPMAXRECORD	1024
79 #define YPMAXDOMAIN	64
80 #define YPMAXMAP	64
81 #define YPMAXPEER	256
82 
83 /*
84  * I don't know if anything of sun's depends on this, or if they
85  * simply defined it so that their own code wouldn't try to send
86  * packets over the ethernet MTU. This YP code doesn't use it.
87  */
88 #define YPMSGSZ		1600
89 
90 #ifndef DATUM
91 typedef struct {
92 	const char	*dptr;
93 	int		 dsize;
94 } datum;
95 #define DATUM
96 #endif
97 
98 struct ypmap_parms {
99 	const char *domain;
100 	const char *map;
101 	unsigned int ordernum;
102 	char *owner;
103 };
104 
105 struct ypreq_key {
106 	const char *domain;
107 	const char *map;
108 	datum keydat;
109 };
110 
111 struct ypreq_nokey {
112 	const char *domain;
113 	const char *map;
114 };
115 
116 struct ypreq_xfr {
117 	struct ypmap_parms map_parms;
118 	unsigned int transid;
119 	unsigned int proto;
120 	unsigned int port;
121 };
122 #define ypxfr_domain	map_parms.domain
123 #define ypxfr_map	map_parms.map
124 #define ypxfr_ordernum	map_parms.ordernum
125 #define ypxfr_owner	map_parms.owner
126 
127 struct ypresp_val {
128 	unsigned int status;
129 	datum valdat;
130 };
131 
132 struct ypresp_key_val {
133 	unsigned int status;
134 	datum keydat;
135 	datum valdat;
136 };
137 
138 struct ypresp_master {
139 	unsigned int status;
140 	char *master;
141 };
142 
143 struct ypresp_order {
144 	unsigned int status;
145 	unsigned int ordernum;
146 };
147 
148 struct ypmaplist {
149 	char ypml_name[YPMAXMAP + 1];
150 	struct ypmaplist *ypml_next;
151 };
152 
153 struct ypresp_maplist {
154 	unsigned int status;
155 	struct ypmaplist *list;
156 };
157 
158 /* ypserv procedure numbers */
159 #define YPPROC_NULL		((unsigned long)0)
160 #define YPPROC_DOMAIN		((unsigned long)1)
161 #define YPPROC_DOMAIN_NONACK	((unsigned long)2)
162 #define YPPROC_MATCH		((unsigned long)3)
163 #define YPPROC_FIRST		((unsigned long)4)
164 #define YPPROC_NEXT		((unsigned long)5)
165 #define YPPROC_XFR		((unsigned long)6)
166 #define YPPROC_CLEAR		((unsigned long)7)
167 #define YPPROC_ALL		((unsigned long)8)
168 #define YPPROC_MASTER		((unsigned long)9)
169 #define YPPROC_ORDER		((unsigned long)10)
170 #define YPPROC_MAPLIST		((unsigned long)11)
171 
172 /* ypserv procedure return status values */
173 #define YP_TRUE	 	((unsigned int)1)	/* general purpose success code */
174 #define YP_NOMORE 	((unsigned int)2)	/* no more entries in map */
175 #define YP_FALSE 	((unsigned int)0)	/* general purpose failure code */
176 #define YP_NOMAP 	((unsigned int)-1)	/* no such map in domain */
177 #define YP_NODOM 	((unsigned int)-2)	/* domain not supported */
178 #define YP_NOKEY 	((unsigned int)-3)	/* no such key in map */
179 #define YP_BADOP 	((unsigned int)-4)	/* invalid operation */
180 #define YP_BADDB 	((unsigned int)-5)	/* server data base is bad */
181 #define YP_YPERR 	((unsigned int)-6)	/* YP server error */
182 #define YP_BADARGS 	((unsigned int)-7)	/* request arguments bad */
183 #define YP_VERS		((unsigned int)-8)	/* YP server version mismatch */
184 
185 /*
186  * Sun's header file says:
187  * "Domain binding data structure, used by ypclnt package and ypserv modules.
188  * Users of the ypclnt package (or of this protocol) don't HAVE to know about
189  * it, but it must be available to users because _yp_dobind is a public
190  * interface."
191  *
192  * This is totally bogus! Nowhere else does Sun state that _yp_dobind() is
193  * a public interface, and I don't know any reason anyone would want to call
194  * it. But, just in case anyone does actually expect it to be available..
195  * we provide this.. exactly as Sun wants it.
196  */
197 struct dom_binding {
198 	struct dom_binding *dom_pnext;
199 	char dom_domain[YPMAXDOMAIN + 1];
200 	struct sockaddr_in dom_server_addr;
201 	u_short dom_server_port;
202 	int dom_socket;
203 	CLIENT *dom_client;
204 	u_short dom_local_port;
205 	long dom_vers;
206 };
207 
208 /*
209  * YPBIND PROTOCOL:
210  *
211  * ypbind supports the following procedures:
212  *
213  * YPBINDPROC_NULL	takes (void), returns (void).
214  *			to check if ypbind is running.
215  * YPBINDPROC_DOMAIN	takes (char *), returns (struct ypbind_resp).
216  *			requests that ypbind start to serve the
217  *			named domain (if it doesn't already)
218  * YPBINDPROC_SETDOM	takes (struct ypbind_setdom), returns (void).
219  *			used by ypset.
220  */
221 
222 #define YPBINDPROG		((unsigned long)100007)
223 #define YPBINDVERS		((unsigned long)2)
224 #define YPBINDVERS_ORIG		((unsigned long)1)
225 
226 /* ypbind procedure numbers */
227 #define YPBINDPROC_NULL		((unsigned long)0)
228 #define YPBINDPROC_DOMAIN	((unsigned long)1)
229 #define YPBINDPROC_SETDOM	((unsigned long)2)
230 
231 /* error code in ypbind_resp.ypbind_status */
232 enum ypbind_resptype {
233 	YPBIND_SUCC_VAL = 1,
234 	YPBIND_FAIL_VAL = 2
235 };
236 
237 /* network order, of course */
238 struct ypbind_binding {
239 	struct in_addr	ypbind_binding_addr;
240 	u_int16_t	ypbind_binding_port;
241 };
242 
243 struct ypbind_resp {
244 	enum ypbind_resptype	ypbind_status;
245 	union {
246 		unsigned int		ypbind_error;
247 		struct ypbind_binding	ypbind_bindinfo;
248 	} ypbind_respbody;
249 };
250 
251 /* error code in ypbind_resp.ypbind_respbody.ypbind_error */
252 #define YPBIND_ERR_ERR		1	/* internal error */
253 #define YPBIND_ERR_NOSERV	2	/* no bound server for passed domain */
254 #define YPBIND_ERR_RESC		3	/* system resource allocation failure */
255 
256 /*
257  * Request data structure for ypbind "Set domain" procedure.
258  */
259 struct ypbind_setdom {
260 	char ypsetdom_domain[YPMAXDOMAIN + 1];
261 	struct ypbind_binding ypsetdom_binding;
262 	unsigned int ypsetdom_vers;
263 };
264 #define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr
265 #define ypsetdom_port ypsetdom_binding.ypbind_binding_port
266 
267 /*
268  * YPPUSH PROTOCOL:
269  *
270  * Sun says:
271  * "Protocol between clients (ypxfr, only) and yppush
272  *  yppush speaks a protocol in the transient range, which
273  *  is supplied to ypxfr as a command-line parameter when it
274  *  is activated by ypserv."
275  *
276  * This protocol is not implimented, naturally, because this YP
277  * implimentation only does the client side.
278  */
279 #define YPPUSHVERS		((unsigned long)1)
280 #define YPPUSHVERS_ORIG		((unsigned long)1)
281 
282 /* yppush procedure numbers */
283 #define YPPUSHPROC_NULL		((unsigned long)0)
284 #define YPPUSHPROC_XFRRESP	((unsigned long)1)
285 
286 struct yppushresp_xfr {
287 	unsigned int	transid;
288 	unsigned int	status;
289 };
290 
291 /* yppush status value in yppushresp_xfr.status */
292 #define YPPUSH_SUCC	((unsigned int)1)	/* Success */
293 #define YPPUSH_AGE	((unsigned int)2)	/* Master's version not newer */
294 #define YPPUSH_NOMAP 	((unsigned int)-1)	/* Can't find server for map */
295 #define YPPUSH_NODOM 	((unsigned int)-2)	/* Domain not supported */
296 #define YPPUSH_RSRC 	((unsigned int)-3)	/* Local resouce alloc failure */
297 #define YPPUSH_RPC 	((unsigned int)-4)	/* RPC failure talking to server */
298 #define YPPUSH_MADDR	((unsigned int)-5)	/* Can't get master address */
299 #define YPPUSH_YPERR 	((unsigned int)-6)	/* YP server/map db error */
300 #define YPPUSH_BADARGS 	((unsigned int)-7)	/* Request arguments bad */
301 #define YPPUSH_DBM	((unsigned int)-8)	/* Local dbm operation failed */
302 #define YPPUSH_FILE	((unsigned int)-9)	/* Local file I/O operation failed */
303 #define YPPUSH_SKEW	((unsigned int)-10)	/* Map version skew during transfer */
304 #define YPPUSH_CLEAR	((unsigned int)-11)	/* Can't send "Clear" req to local ypserv */
305 #define YPPUSH_FORCE	((unsigned int)-12)	/* No local order number in map - use -f */
306 #define YPPUSH_XFRERR	((unsigned int)-13)	/* ypxfr error */
307 #define YPPUSH_REFUSED	((unsigned int)-14)	/* Transfer request refused by ypserv */
308 
309 struct ypall_callback;
310 
311 __BEGIN_DECLS
312 bool_t xdr_domainname(XDR *, char *);	/* obsolete */
313 bool_t xdr_peername(XDR *, char *);	/* obsolete */
314 bool_t xdr_mapname(XDR *, char *);	/* obsolete */
315 bool_t xdr_datum(XDR *, datum *);
316 bool_t xdr_ypdomain_wrap_string(XDR *, char **);
317 bool_t xdr_ypmap_wrap_string(XDR *, char **);
318 bool_t xdr_ypreq_key(XDR *, struct ypreq_key *);
319 bool_t xdr_ypreq_nokey(XDR *, struct ypreq_nokey *);
320 bool_t xdr_ypreq_xfr(XDR *, struct ypreq_xfr *);
321 bool_t xdr_ypresp_val(XDR *, struct ypresp_val *);
322 bool_t xdr_ypresp_key_val(XDR *, struct ypresp_key_val *);
323 bool_t xdr_ypmap_parms(XDR *, struct ypmap_parms *);
324 bool_t xdr_ypowner_wrap_string(XDR *, char **);
325 bool_t xdr_yppushresp_xfr(XDR *, struct yppushresp_xfr *);
326 bool_t xdr_ypresp_order(XDR *, struct ypresp_order *);
327 bool_t xdr_ypresp_master(XDR *, struct ypresp_master *);
328 bool_t xdr_ypall(XDR *, struct ypall_callback *);
329 bool_t xdr_ypresp_maplist(XDR *, struct ypresp_maplist *);
330 bool_t xdr_ypbind_resp(XDR *, struct ypbind_resp *);
331 bool_t xdr_ypbind_setdom(XDR *, struct ypbind_setdom *);
332 bool_t xdr_ypmaplist(XDR *, struct ypmaplist *);
333 bool_t xdr_yp_inaddr(XDR *, struct in_addr *);
334 __END_DECLS
335 
336 #endif /* _RPCSVC_YP_PROT_H_ */
337