1 /*	$OpenBSD: yp_prot.h,v 1.11 2022/01/28 04:59:15 guenther Exp $	*/
2 /*	$NetBSD: yp_prot.h,v 1.6 1995/07/14 21:10:58 christos Exp $	*/
3 
4 /*
5  * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@openbsd.org>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
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 _RPCSVC_YP_PROT_H_
31 #define _RPCSVC_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 its 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 unsigned int bool;
70 #define BOOL_DEFINED
71 #endif
72 
73 
74 /* Program and version symbols, magic numbers */
75 #define YPPROG		((unsigned long)100004)
76 #define YPVERS		((unsigned long)2)
77 #define YPVERS_ORIG	((unsigned long)1)
78 #define YPMAXRECORD	((unsigned long)1024)
79 #define YPMAXDOMAIN	((unsigned long)64)
80 #define YPMAXMAP	((unsigned long)64)
81 #define YPMAXPEER	((unsigned long)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 long 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 long transid;
119 	unsigned long proto;
120 	unsigned short 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 long status;
129 	datum valdat;
130 };
131 
132 struct ypresp_key_val {
133 	unsigned long status;
134 	datum keydat;
135 	datum valdat;
136 };
137 
138 struct ypresp_master {
139 	unsigned long status;
140 	char *master;
141 };
142 
143 struct ypresp_order {
144 	unsigned long status;
145 	unsigned long ordernum;
146 };
147 
148 struct ypresp_all {
149 	bool_t more;
150 	union {
151 		struct ypresp_key_val val;
152 	} ypresp_all_u;
153 };
154 
155 struct ypmaplist {
156 	char ypml_name[YPMAXMAP + 1];
157 	struct ypmaplist *ypml_next;
158 };
159 
160 struct ypresp_maplist {
161 	unsigned long status;
162 	struct ypmaplist *list;
163 };
164 
165 /* ypserv procedure numbers */
166 #define YPPROC_NULL		((unsigned long)0)
167 #define YPPROC_DOMAIN		((unsigned long)1)
168 #define YPPROC_DOMAIN_NONACK	((unsigned long)2)
169 #define YPPROC_MATCH		((unsigned long)3)
170 #define YPPROC_FIRST		((unsigned long)4)
171 #define YPPROC_NEXT		((unsigned long)5)
172 #define YPPROC_XFR		((unsigned long)6)
173 #define YPPROC_CLEAR		((unsigned long)7)
174 #define YPPROC_ALL		((unsigned long)8)
175 #define YPPROC_MASTER		((unsigned long)9)
176 #define YPPROC_ORDER		((unsigned long)10)
177 #define YPPROC_MAPLIST		((unsigned long)11)
178 
179 /* ypserv procedure return status values */
180 #define YP_TRUE		((unsigned long)1)	/* general purpose success code */
181 #define YP_NOMORE	((unsigned long)2)	/* no more entries in map */
182 #define YP_FALSE	((unsigned long)0)	/* general purpose failure code */
183 #define YP_NOMAP	((unsigned long)-1)	/* no such map in domain */
184 #define YP_NODOM	((unsigned long)-2)	/* domain not supported */
185 #define YP_NOKEY	((unsigned long)-3)	/* no such key in map */
186 #define YP_BADOP	((unsigned long)-4)	/* invalid operation */
187 #define YP_BADDB	((unsigned long)-5)	/* server data base is bad */
188 #define YP_YPERR	((unsigned long)-6)	/* YP server error */
189 #define YP_BADARGS	((unsigned long)-7)	/* request arguments bad */
190 #define YP_VERS		((unsigned long)-8)	/* YP server version mismatch */
191 
192 /*
193  * YPBIND PROTOCOL:
194  *
195  * ypbind supports the following procedures:
196  *
197  * YPBINDPROC_NULL	takes (void), returns (void).
198  *			to check if ypbind is running.
199  * YPBINDPROC_DOMAIN	takes (char *), returns (struct ypbind_resp).
200  *			requests that ypbind start to serve the
201  *			named domain (if it doesn't already)
202  * YPBINDPROC_SETDOM	takes (struct ypbind_setdom), returns (void).
203  *			used by ypset.
204  */
205 
206 #define YPBINDPROG		((unsigned long)100007)
207 #define YPBINDVERS		((unsigned long)2)
208 #define YPBINDVERS_ORIG		((unsigned long)1)
209 
210 /* ypbind procedure numbers */
211 #define YPBINDPROC_NULL		((unsigned long)0)
212 #define YPBINDPROC_DOMAIN	((unsigned long)1)
213 #define YPBINDPROC_SETDOM	((unsigned long)2)
214 
215 /* error code in ypbind_resp.ypbind_status */
216 enum ypbind_resptype {
217 	YPBIND_SUCC_VAL = 1,
218 	YPBIND_FAIL_VAL = 2
219 };
220 
221 /* network order, of course */
222 struct ypbind_binding {
223 	struct in_addr	ypbind_binding_addr;
224 	unsigned short	ypbind_binding_port;
225 };
226 
227 struct ypbind_resp {
228 	enum ypbind_resptype	ypbind_status;
229 	union {
230 		unsigned long		ypbind_error;
231 		struct ypbind_binding	ypbind_bindinfo;
232 	} ypbind_respbody;
233 };
234 
235 /* error code in ypbind_resp.ypbind_respbody.ypbind_error */
236 #define YPBIND_ERR_ERR		1	/* internal error */
237 #define YPBIND_ERR_NOSERV	2	/* no bound server for passed domain */
238 #define YPBIND_ERR_RESC		3	/* system resource allocation failure */
239 
240 /*
241  * Request data structure for ypbind "Set domain" procedure.
242  */
243 struct ypbind_setdom {
244 	char ypsetdom_domain[YPMAXDOMAIN + 1];
245 	struct ypbind_binding ypsetdom_binding;
246 	unsigned short ypsetdom_vers;
247 };
248 #define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr
249 #define ypsetdom_port ypsetdom_binding.ypbind_binding_port
250 
251 /*
252  * YPPUSH PROTOCOL:
253  *
254  * Sun says:
255  * "Protocol between clients (ypxfr, only) and yppush
256  *  yppush speaks a protocol in the transient range, which
257  *  is supplied to ypxfr as a command-line parameter when it
258  *  is activated by ypserv."
259  *
260  * This protocol is not implemented, naturally, because this YP
261  * implementation only does the client side.
262  */
263 #define YPPUSHVERS		((unsigned long)1)
264 #define YPPUSHVERS_ORIG		((unsigned long)1)
265 
266 /* yppush procedure numbers */
267 #define YPPUSHPROC_NULL		((unsigned long)0)
268 #define YPPUSHPROC_XFRRESP	((unsigned long)1)
269 
270 struct yppushresp_xfr {
271 	unsigned long	transid;
272 	unsigned long	status;
273 };
274 
275 /* yppush status value in yppushresp_xfr.status */
276 #define YPPUSH_SUCC	((unsigned long)1)	/* Success */
277 #define YPPUSH_AGE	((unsigned long)2)	/* Master's version not newer */
278 #define YPPUSH_NOMAP	((unsigned long)-1)	/* Can't find server for map */
279 #define YPPUSH_NODOM	((unsigned long)-2)	/* Domain not supported */
280 #define YPPUSH_RSRC	((unsigned long)-3)	/* Local resouce alloc failure */
281 #define YPPUSH_RPC	((unsigned long)-4)	/* RPC failure talking to server */
282 #define YPPUSH_MADDR	((unsigned long)-5)	/* Can't get master address */
283 #define YPPUSH_YPERR	((unsigned long)-6)	/* YP server/map db error */
284 #define YPPUSH_BADARGS	((unsigned long)-7)	/* Request arguments bad */
285 #define YPPUSH_DBM	((unsigned long)-8)	/* Local dbm operation failed */
286 #define YPPUSH_FILE	((unsigned long)-9)	/* Local file I/O operation failed */
287 #define YPPUSH_SKEW	((unsigned long)-10)	/* Map version skew during transfer */
288 #define YPPUSH_CLEAR	((unsigned long)-11)	/* Can't send "Clear" req to local ypserv */
289 #define YPPUSH_FORCE	((unsigned long)-12)	/* No local order number in map - use -f */
290 #define YPPUSH_XFRERR	((unsigned long)-13)	/* ypxfr error */
291 #define YPPUSH_REFUSED	((unsigned long)-14)	/* Transfer request refused by ypserv */
292 
293 __BEGIN_DECLS
294 bool_t xdr_domainname(XDR *, char *);
295 bool_t xdr_peername(XDR *, char *);
296 bool_t xdr_datum(XDR *, datum *);
297 bool_t xdr_mapname(XDR *, char *);
298 bool_t xdr_ypreq_key(XDR *, struct ypreq_key *);
299 bool_t xdr_ypreq_nokey(XDR *, struct ypreq_nokey *);
300 bool_t xdr_yp_inaddr(XDR *, struct in_addr *);
301 bool_t xdr_ypbind_binding(XDR *, struct ypbind_binding *);
302 bool_t xdr_ypbind_resptype(XDR *, enum ypbind_resptype *);
303 bool_t xdr_ypstat(XDR *, enum ypbind_resptype *);
304 bool_t xdr_ypbind_resp(XDR *, struct ypbind_resp *);
305 bool_t xdr_ypresp_val(XDR *, struct ypresp_val *);
306 bool_t xdr_ypbind_setdom(XDR *, struct ypbind_setdom *);
307 bool_t xdr_ypresp_key_val(XDR *, struct ypresp_key_val *);
308 bool_t xdr_ypresp_all(XDR *, struct ypresp_all *);
309 bool_t xdr_ypresp_master(XDR *, struct ypresp_master *);
310 bool_t xdr_ypmaplist_str(XDR *, char *);
311 bool_t xdr_ypmaplist(XDR *, struct ypmaplist *);
312 bool_t xdr_ypresp_maplist(XDR *, struct ypresp_maplist *);
313 bool_t xdr_ypresp_order(XDR *, struct ypresp_order *);
314 __END_DECLS
315 
316 #endif /* _RPCSVC_YP_PROT_H_ */
317