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