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