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