1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2014 Garrett D'Amore <garrett@damore.org> 24 * 25 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 30 /* All Rights Reserved */ 31 32 /* 33 * Portions of this source code were derived from Berkeley 4.3 BSD 34 * under license from the Regents of the University of California. 35 */ 36 37 #ifndef _RPCSVC_YP_PROT_H 38 #define _RPCSVC_YP_PROT_H 39 40 #include <rpc/rpc.h> 41 #include <rpcsvc/ypclnt.h> 42 #include <ndbm.h> 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /* 49 * This file contains symbols and structures defining the rpc protocol 50 * between the YP clients and the YP servers. The servers are the YP 51 * database servers, and the YP. 52 */ 53 54 /* 55 * The following procedures are supported by the protocol: 56 * 57 * YPPROC_NULL() returns () takes nothing, returns nothing. This indicates 58 * that the yp server is alive. 59 * 60 * YPPROC_DOMAIN (char *) returns (bool_t) TRUE. Indicates that the 61 * responding yp server does serve the named domain; FALSE indicates no 62 * support. 63 * 64 * YPPROC_DOMAIN_NONACK (char *) returns (TRUE) if the yp server does serve 65 * the named domain, otherwise does not return. Used in the broadcast case. 66 * 67 * YPPROC_MATCH (struct ypreq_key) returns (struct ypresp_val). Returns the 68 * right-hand value for a passed left-hand key, within a named map and 69 * domain. 70 * 71 * YPPROC_FIRST (struct ypreq_nokey) returns (struct ypresp_key_val). 72 * Returns the first key-value pair from a named domain and map. 73 * 74 * YPPROC_NEXT (struct ypreq_key) returns (struct ypresp_key_val). Returns 75 * the key-value pair following a passed key-value pair within a named 76 * domain and map. 77 * 78 * YPPROC_XFR (struct ypreq_xfr) returns nothing. Indicates to a server that 79 * a map should be updated. 80 * 81 * YPPROC_NEWXFR (struct ypreq_newxfr) returns nothing. Indicates to a server 82 * that a map should be updated. Uses protocol independent request struct. 83 * 84 * YPPROC_CLEAR takes nothing, returns nothing. Instructs a yp server to 85 * close the current map, so that old versions of the disk file don't get 86 * held open. 87 * 88 * YPPROC_ALL (struct ypreq_nokey), returns 89 * union switch (bool more) { 90 * TRUE: (struct ypresp_key_val); 91 * FALSE: (struct) {}; 92 * } 93 * 94 * YPPROC_MASTER (struct ypreq_nokey), returns (ypresp_master) 95 * 96 * YPPROC_ORDER (struct ypreq_nokey), returns (ypresp_order) 97 * 98 * YPPROC_MAPLIST (char *), returns (struct ypmaplist *) 99 */ 100 101 /* 'bool' is a built-in type for g++ */ 102 #if !(defined(__cplusplus) && defined(_BOOL)) && !defined(__GNUG__) 103 #ifndef BOOL_DEFINED 104 typedef unsigned int bool; 105 #define BOOL_DEFINED 106 #endif 107 #endif 108 109 /* Program and version symbols, magic numbers */ 110 111 #define YPPROG ((rpcprog_t)100004) 112 #define YPVERS ((rpcvers_t)2) 113 #define YPVERS_ORIG ((rpcvers_t)1) 114 #define YPMAXRECORD ((uint_t)1024) 115 #define YPMAXDOMAIN ((uint_t)256) 116 #define YPMAXMAP ((uint_t)64) 117 #define YPMAXPEER ((uint_t)256) 118 119 /* byte size of a large yp packet */ 120 #define YPMSGSZ 1600 121 122 struct ypmap_parms { 123 char *domain; /* Null string means not available */ 124 char *map; /* Null string means not available */ 125 unsigned int ordernum; /* 0 means not available */ 126 char *owner; /* Null string means not available */ 127 }; 128 129 /* 130 * Request parameter structures 131 */ 132 133 struct ypreq_key { 134 char *domain; 135 char *map; 136 datum keydat; 137 }; 138 139 struct ypreq_nokey { 140 char *domain; 141 char *map; 142 }; 143 144 struct ypreq_xfr { 145 struct ypmap_parms map_parms; 146 unsigned int transid; 147 unsigned int proto; 148 unsigned short port; 149 }; 150 151 struct ypreq_newxfr { 152 struct ypmap_parms map_parms; 153 unsigned int transid; 154 unsigned int proto; 155 char *name; 156 }; 157 158 #define ypxfr_domain map_parms.domain 159 #define ypxfr_map map_parms.map 160 #define ypxfr_ordernum map_parms.ordernum 161 #define ypxfr_owner map_parms.owner 162 163 /* 164 * Response parameter structures 165 */ 166 167 struct ypresp_val { 168 unsigned int status; 169 datum valdat; 170 }; 171 172 struct ypresp_key_val { 173 unsigned int status; 174 datum valdat; 175 datum keydat; 176 }; 177 178 struct ypresp_master { 179 unsigned int status; 180 char *master; 181 }; 182 183 struct ypresp_order { 184 unsigned int status; 185 unsigned int ordernum; 186 }; 187 188 struct ypmaplist { 189 char ypml_name[YPMAXMAP + 1]; 190 struct ypmaplist *ypml_next; 191 }; 192 193 struct ypresp_maplist { 194 unsigned int status; 195 struct ypmaplist *list; 196 }; 197 198 /* 199 * Procedure symbols. YPPROC_NULL, YPPROC_DOMAIN, and YPPROC_DOMAIN_NONACK 200 * must keep the same values (0, 1, and 2) that they had in the first version 201 * of the protocol. 202 */ 203 204 #define YPPROC_NULL ((rpcproc_t)0) 205 #define YPPROC_DOMAIN ((rpcproc_t)1) 206 #define YPPROC_DOMAIN_NONACK ((rpcproc_t)2) 207 #define YPPROC_MATCH ((rpcproc_t)3) 208 #define YPPROC_FIRST ((rpcproc_t)4) 209 #define YPPROC_NEXT ((rpcproc_t)5) 210 #define YPPROC_XFR ((rpcproc_t)6) 211 #define YPPROC_NEWXFR ((rpcproc_t)12) 212 #define YPPROC_CLEAR ((rpcproc_t)7) 213 #define YPPROC_ALL ((rpcproc_t)8) 214 #define YPPROC_MASTER ((rpcproc_t)9) 215 #define YPPROC_ORDER ((rpcproc_t)10) 216 #define YPPROC_MAPLIST ((rpcproc_t)11) 217 218 /* Return status values */ 219 220 #define YP_TRUE (1) /* General purpose success code */ 221 #define YP_NOMORE (2) /* No more entries in map */ 222 #define YP_FALSE (0) /* General purpose failure code */ 223 #define YP_NOMAP (-1) /* No such map in domain */ 224 #define YP_NODOM (-2) /* Domain not supported */ 225 #define YP_NOKEY (-3) /* No such key in map */ 226 #define YP_BADOP (-4) /* Invalid operation */ 227 #define YP_BADDB (-5) /* Server data base is bad */ 228 #define YP_YPERR (-6) /* YP server error */ 229 #define YP_BADARGS (-7) /* Request arguments bad */ 230 #define YP_VERS (-8) /* YP server vers. mismatch - server */ 231 /* can't supply requested service. */ 232 233 enum ypreqtype {YPREQ_KEY = 1, YPREQ_NOKEY = 2, YPREQ_MAP_PARMS = 3}; 234 struct yprequest { 235 enum ypreqtype yp_reqtype; 236 union { 237 struct ypreq_key yp_req_keytype; 238 struct ypreq_nokey yp_req_nokeytype; 239 struct ypmap_parms yp_req_map_parmstype; 240 }yp_reqbody; 241 }; 242 243 #define YPMATCH_REQTYPE YPREQ_KEY 244 #define ypmatch_req_domain yp_reqbody.yp_req_keytype.domain 245 #define ypmatch_req_map yp_reqbody.yp_req_keytype.map 246 #define ypmatch_req_keydat yp_reqbody.yp_req_keytype.keydat 247 #define ypmatch_req_keyptr yp_reqbody.yp_req_keytype.keydat.dptr 248 #define ypmatch_req_keysize yp_reqbody.yp_req_keytype.keydat.dsize 249 250 #define YPFIRST_REQTYPE YPREQ_NOKEY 251 #define ypfirst_req_domain yp_reqbody.yp_req_nokeytype.domain 252 #define ypfirst_req_map yp_reqbody.yp_req_nokeytype.map 253 254 #define YPNEXT_REQTYPE YPREQ_KEY 255 #define ypnext_req_domain yp_reqbody.yp_req_keytype.domain 256 #define ypnext_req_map yp_reqbody.yp_req_keytype.map 257 #define ypnext_req_keydat yp_reqbody.yp_req_keytype.keydat 258 #define ypnext_req_keyptr yp_reqbody.yp_req_keytype.keydat.dptr 259 #define ypnext_req_keysize yp_reqbody.yp_req_keytype.keydat.dsize 260 261 #define YPPUSH_REQTYPE YPREQ_NOKEY 262 #define yppush_req_domain yp_reqbody.yp_req_nokeytype.domain 263 #define yppush_req_map yp_reqbody.yp_req_nokeytype.map 264 265 #define YPPULL_REQTYPE YPREQ_NOKEY 266 #define yppull_req_domain yp_reqbody.yp_req_nokeytype.domain 267 #define yppull_req_map yp_reqbody.yp_req_nokeytype.map 268 269 #define YPPOLL_REQTYPE YPREQ_NOKEY 270 #define yppoll_req_domain yp_reqbody.yp_req_nokeytype.domain 271 #define yppoll_req_map yp_reqbody.yp_req_nokeytype.map 272 273 #define YPGET_REQTYPE YPREQ_MAP_PARMS 274 #define ypget_req_domain yp_reqbody.yp_req_map_parmstype.domain 275 #define ypget_req_map yp_reqbody.yp_req_map_parmstype.map 276 #define ypget_req_ordernum yp_reqbody.yp_req_map_parmstype.ordernum 277 #define ypget_req_owner yp_reqbody.yp_req_map_parmstype.owner 278 279 enum ypresptype {YPRESP_VAL = 1, YPRESP_KEY_VAL = 2, YPRESP_MAP_PARMS = 3}; 280 struct ypresponse { 281 enum ypresptype yp_resptype; 282 union { 283 struct ypresp_val yp_resp_valtype; 284 struct ypresp_key_val yp_resp_key_valtype; 285 struct ypmap_parms yp_resp_map_parmstype; 286 } yp_respbody; 287 }; 288 289 #define YPMATCH_RESPTYPE YPRESP_VAL 290 #define ypmatch_resp_status yp_respbody.yp_resp_valtype.status 291 #define ypmatch_resp_valdat yp_respbody.yp_resp_valtype.valdat 292 #define ypmatch_resp_valptr yp_respbody.yp_resp_valtype.valdat.dptr 293 #define ypmatch_resp_valsize yp_respbody.yp_resp_valtype.valdat.dsize 294 295 #define YPFIRST_RESPTYPE YPRESP_KEY_VAL 296 #define ypfirst_resp_status yp_respbody.yp_resp_key_valtype.status 297 #define ypfirst_resp_keydat yp_respbody.yp_resp_key_valtype.keydat 298 #define ypfirst_resp_keyptr yp_respbody.yp_resp_key_valtype.keydat.dptr 299 #define ypfirst_resp_keysize yp_respbody.yp_resp_key_valtype.keydat.dsize 300 #define ypfirst_resp_valdat yp_respbody.yp_resp_key_valtype.valdat 301 #define ypfirst_resp_valptr yp_respbody.yp_resp_key_valtype.valdat.dptr 302 #define ypfirst_resp_valsize yp_respbody.yp_resp_key_valtype.valdat.dsize 303 304 #define YPNEXT_RESPTYPE YPRESP_KEY_VAL 305 #define ypnext_resp_status yp_respbody.yp_resp_key_valtype.status 306 #define ypnext_resp_keydat yp_respbody.yp_resp_key_valtype.keydat 307 #define ypnext_resp_keyptr yp_respbody.yp_resp_key_valtype.keydat.dptr 308 #define ypnext_resp_keysize yp_respbody.yp_resp_key_valtype.keydat.dsize 309 #define ypnext_resp_valdat yp_respbody.yp_resp_key_valtype.valdat 310 #define ypnext_resp_valptr yp_respbody.yp_resp_key_valtype.valdat.dptr 311 #define ypnext_resp_valsize yp_respbody.yp_resp_key_valtype.valdat.dsize 312 313 #define YPPOLL_RESPTYPE YPRESP_MAP_PARMS 314 #define yppoll_resp_domain yp_respbody.yp_resp_map_parmstype.domain 315 #define yppoll_resp_map yp_respbody.yp_resp_map_parmstype.map 316 #define yppoll_resp_ordernum yp_respbody.yp_resp_map_parmstype.ordernum 317 #define yppoll_resp_owner yp_respbody.yp_resp_map_parmstype.owner 318 319 320 extern bool _xdr_yprequest(); 321 extern bool _xdr_ypresponse(); 322 /* 323 * Protocol between clients (ypxfr, only) and yppush 324 * yppush speaks a protocol in the transient range, which 325 * is supplied to ypxfr as a command-line parameter when it 326 * is activated by ypserv. 327 */ 328 #define YPPUSHVERS ((rpcvers_t)1) 329 #define YPPUSHVERS_ORIG ((rpcvers_t)1) 330 331 /* Procedure symbols */ 332 333 #define YPPUSHPROC_NULL ((rpcproc_t)0) 334 #define YPPUSHPROC_XFRRESP ((rpcproc_t)1) 335 336 struct yppushresp_xfr { 337 unsigned int transid; 338 unsigned int status; 339 }; 340 341 /* Status values for yppushresp_xfr.status */ 342 343 #define YPPUSH_SUCC (1) /* Success */ 344 #define YPPUSH_AGE (2) /* Master's version not newer */ 345 #define YPPUSH_NOMAP (-1) /* Can't find server for map */ 346 #define YPPUSH_NODOM (-2) /* Domain not supported */ 347 #define YPPUSH_RSRC (-3) /* Local resouce alloc failure */ 348 #define YPPUSH_RPC (-4) /* RPC failure talking to server */ 349 #define YPPUSH_MADDR (-5) /* Can't get master address */ 350 #define YPPUSH_YPERR (-6) /* YP server/map db error */ 351 #define YPPUSH_BADARGS (-7) /* Request arguments bad */ 352 #define YPPUSH_DBM (-8) /* Local dbm operation failed */ 353 #define YPPUSH_FILE (-9) /* Local file I/O operation failed */ 354 #define YPPUSH_SKEW (-10) /* Map version skew during transfer */ 355 #define YPPUSH_CLEAR (-11) /* Can't send "Clear" req to local */ 356 /* ypserv */ 357 #define YPPUSH_FORCE (-12) /* No local order number in map - */ 358 /* use -f flag. */ 359 #define YPPUSH_XFRERR (-13) /* ypxfr error */ 360 #define YPPUSH_REFUSED (-14) /* Transfer request refused by ypserv */ 361 #define YPPUSH_NOALIAS (-15) /* Alias not found for map or domain */ 362 363 extern bool xdr_datum(XDR *, datum *); 364 extern bool xdr_ypdomain_wrap_string(XDR *, char **); 365 extern bool xdr_ypmap_wrap_string(XDR *, char **); 366 extern bool xdr_ypreq_key(XDR *, struct ypreq_key *); 367 extern bool xdr_ypreq_nokey(XDR *, struct ypreq_nokey *); 368 extern bool xdr_ypreq_xfr(XDR *, struct ypreq_xfr *); 369 extern bool xdr_ypreq_newxfr(XDR *, struct ypreq_newxfr *); 370 extern bool xdr_ypresp_val(XDR *, struct ypresp_val *); 371 extern bool xdr_ypresp_key_val(XDR *, struct ypresp_key_val *); 372 extern bool xdr_ypmap_parms(XDR *, struct ypmap_parms *); 373 extern bool xdr_ypowner_wrap_string(XDR *, char **); 374 extern bool xdr_yppushresp_xfr(XDR *, struct yppushresp_xfr *); 375 extern bool xdr_ypresp_order(XDR *, struct ypresp_order *); 376 extern bool xdr_ypresp_master(XDR *, struct ypresp_master *); 377 extern bool xdr_ypall(XDR *, struct ypall_callback *); 378 extern bool xdr_ypresp_maplist(XDR *, struct ypresp_maplist *); 379 380 #ifdef __cplusplus 381 } 382 #endif 383 384 #endif /* _RPCSVC_YP_PROT_H */