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 * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 /* 30 * Portions of this source code were derived from Berkeley 31 * under license from the Regents of the University of 32 * California. 33 */ 34 35 #pragma ident "%Z%%M% %I% %E% SMI" 36 37 /* 38 * This contains ALL xdr routines used by the YP rpc interface. 39 */ 40 41 #define NULL 0 42 #include <rpc/rpc.h> 43 #include "yp_b.h" 44 #include <rpcsvc/yp_prot.h> 45 #include <rpcsvc/ypclnt.h> 46 #include <sys/types.h> 47 #include <rpc/trace.h> 48 #include <stdlib.h> 49 #include <limits.h> 50 51 static bool xdr_ypmaplist(XDR *, struct ypmaplist **); 52 static bool xdr_ypmaplist_wrap_string(XDR *, char *); 53 54 typedef struct xdr_discrim XDR_DISCRIM; 55 bool xdr_ypreq_key(XDR *, struct ypreq_key *); 56 bool xdr_ypreq_nokey(XDR *, struct ypreq_nokey *); 57 bool xdr_ypresp_val(XDR *, struct ypresp_val *); 58 bool xdr_ypresp_key_val(XDR *, struct ypresp_key_val *); 59 bool xdr_ypmap_parms(XDR *, struct ypmap_parms *); 60 bool xdr_ypowner_wrap_string(XDR *, char **); 61 bool xdr_ypreq_newname_string(XDR *, char **); 62 63 64 /* 65 * Serializes/deserializes a dbm datum data structure. 66 */ 67 bool 68 xdr_datum(xdrs, pdatum) 69 XDR * xdrs; 70 datum * pdatum; 71 { 72 bool dummy; 73 uint_t dsize; 74 75 /* 76 * LP64 case : 77 * xdr_bytes() expects a uint_t for the 3rd argument. Since 78 * datum.dsize is a long, we need a new temporary to pass to 79 * xdr_bytes() 80 */ 81 trace1(TR_xdr_datum, 0); 82 if (xdrs->x_op == XDR_ENCODE) { 83 if (pdatum->dsize > UINT_MAX) 84 return (FALSE); 85 } 86 dsize = (uint_t)pdatum->dsize; 87 dummy = xdr_bytes(xdrs, (char **)&(pdatum->dptr), &dsize, YPMAXRECORD); 88 if (xdrs->x_op == XDR_DECODE) { 89 pdatum->dsize = dsize; 90 } 91 92 trace1(TR_xdr_datum, 1); 93 return (dummy); 94 } 95 96 97 /* 98 * Serializes/deserializes a domain name string. This is a "wrapper" for 99 * xdr_string which knows about the maximum domain name size. 100 */ 101 bool 102 xdr_ypdomain_wrap_string(xdrs, ppstring) 103 XDR * xdrs; 104 char **ppstring; 105 { 106 bool dummy; 107 108 trace1(TR_xdr_ypdomain_wrap_string, 0); 109 dummy = xdr_string(xdrs, ppstring, YPMAXDOMAIN); 110 trace1(TR_xdr_ypdomain_wrap_string, 1); 111 return (dummy); 112 } 113 114 /* 115 * Serializes/deserializes a map name string. This is a "wrapper" for 116 * xdr_string which knows about the maximum map name size. 117 */ 118 bool 119 xdr_ypmap_wrap_string(xdrs, ppstring) 120 XDR * xdrs; 121 char **ppstring; 122 { 123 bool dummy; 124 125 trace1(TR_xdr_ypmap_wrap_string, 0); 126 dummy = xdr_string(xdrs, ppstring, YPMAXMAP); 127 trace1(TR_xdr_ypmap_wrap_string, 1); 128 return (dummy); 129 } 130 131 /* 132 * Serializes/deserializes a ypreq_key structure. 133 */ 134 bool 135 xdr_ypreq_key(xdrs, ps) 136 XDR *xdrs; 137 struct ypreq_key *ps; 138 { 139 bool dummy; 140 141 trace1(TR_xdr_ypreq_key, 0); 142 dummy = xdr_ypdomain_wrap_string(xdrs, &ps->domain) && 143 xdr_ypmap_wrap_string(xdrs, &ps->map) && 144 xdr_datum(xdrs, &ps->keydat); 145 trace1(TR_xdr_ypreq_key, 1); 146 return (dummy); 147 } 148 149 /* 150 * Serializes/deserializes a ypreq_nokey structure. 151 */ 152 bool 153 xdr_ypreq_nokey(xdrs, ps) 154 XDR * xdrs; 155 struct ypreq_nokey *ps; 156 { 157 bool dummy; 158 159 trace1(TR_xdr_ypreq_nokey, 0); 160 dummy = xdr_ypdomain_wrap_string(xdrs, &ps->domain) && 161 xdr_ypmap_wrap_string(xdrs, &ps->map); 162 trace1(TR_xdr_ypreq_nokey, 1); 163 return (dummy); 164 } 165 166 /* 167 * Serializes/deserializes a ypresp_val structure. 168 */ 169 170 bool 171 xdr_ypresp_val(xdrs, ps) 172 XDR * xdrs; 173 struct ypresp_val *ps; 174 { 175 bool dummy; 176 177 trace1(TR_xdr_ypresp_val, 0); 178 dummy = xdr_u_int(xdrs, &ps->status) && 179 xdr_datum(xdrs, &ps->valdat); 180 trace1(TR_xdr_ypresp_val, 1); 181 return (dummy); 182 } 183 184 /* 185 * Serializes/deserializes a ypresp_key_val structure. 186 */ 187 bool 188 xdr_ypresp_key_val(xdrs, ps) 189 XDR * xdrs; 190 struct ypresp_key_val *ps; 191 { 192 bool dummy; 193 194 trace1(TR_xdr_ypresp_key_val, 0); 195 dummy = xdr_u_int(xdrs, &ps->status) && 196 xdr_datum(xdrs, &ps->valdat) && 197 xdr_datum(xdrs, &ps->keydat); 198 trace1(TR_xdr_ypresp_key_val, 1); 199 return (dummy); 200 } 201 202 /* 203 * Serializes/deserializes a peer server's node name 204 */ 205 bool 206 xdr_ypowner_wrap_string(xdrs, ppstring) 207 XDR * xdrs; 208 char **ppstring; 209 { 210 bool dummy; 211 212 trace1(TR_xdr_ypowner_wrap_string, 0); 213 dummy = xdr_string(xdrs, ppstring, YPMAXPEER); 214 trace1(TR_xdr_ypowner_wrap_string, 1); 215 return (dummy); 216 } 217 218 /* 219 * Serializes/deserializes a ypmap_parms structure. 220 */ 221 bool 222 xdr_ypmap_parms(xdrs, ps) 223 XDR *xdrs; 224 struct ypmap_parms *ps; 225 { 226 bool dummy; 227 228 trace1(TR_xdr_ypmap_parms, 0); 229 dummy = xdr_ypdomain_wrap_string(xdrs, &ps->domain) && 230 xdr_ypmap_wrap_string(xdrs, &ps->map) && 231 xdr_u_int(xdrs, &ps->ordernum) && 232 xdr_ypowner_wrap_string(xdrs, &ps->owner); 233 trace1(TR_xdr_ypmap_parms, 1); 234 return (dummy); 235 } 236 237 /* 238 * Serializes/deserializes a ypreq_newxfr name 239 */ 240 bool 241 xdr_ypreq_newname_string(xdrs, ppstring) 242 XDR * xdrs; 243 char **ppstring; 244 { 245 bool dummy; 246 247 trace1(TR_xdr_ypreq_newname_string, 0); 248 dummy = xdr_string(xdrs, ppstring, 256); 249 trace1(TR_xdr_ypreq_newname_string, 1); 250 return (dummy); 251 } 252 253 /* 254 * Serializes/deserializes a ypresp_master structure. 255 */ 256 bool 257 xdr_ypresp_master(xdrs, ps) 258 XDR * xdrs; 259 struct ypresp_master *ps; 260 { 261 bool dummy; 262 263 trace1(TR_xdr_ypresp_master, 0); 264 dummy = xdr_u_int(xdrs, &ps->status) && 265 xdr_ypowner_wrap_string(xdrs, &ps->master); 266 trace1(TR_xdr_ypresp_master, 1); 267 return (dummy); 268 } 269 270 /* 271 * Serializes/deserializes a ypresp_order structure. 272 */ 273 bool 274 xdr_ypresp_order(xdrs, ps) 275 XDR * xdrs; 276 struct ypresp_order *ps; 277 { 278 bool dummy; 279 280 trace1(TR_xdr_ypresp_order, 0); 281 dummy = xdr_u_int(xdrs, &ps->status) && 282 xdr_u_int(xdrs, &ps->ordernum); 283 trace1(TR_xdr_ypresp_order, 1); 284 return (dummy); 285 } 286 287 /* 288 * This is like xdr_ypmap_wrap_string except that it serializes/deserializes 289 * an array, instead of a pointer, so xdr_reference can work on the structure 290 * containing the char array itself. 291 */ 292 static bool 293 xdr_ypmaplist_wrap_string(xdrs, pstring) 294 XDR * xdrs; 295 char *pstring; 296 { 297 char *s; 298 bool dummy; 299 300 301 trace1(TR_xdr_ypmaplist_wrap_string, 0); 302 s = pstring; 303 dummy = xdr_string(xdrs, &s, YPMAXMAP); 304 trace1(TR_xdr_ypmaplist_wrap_string, 1); 305 return (dummy); 306 } 307 308 /* 309 * Serializes/deserializes a ypmaplist. 310 */ 311 static bool 312 xdr_ypmaplist(xdrs, lst) 313 XDR *xdrs; 314 struct ypmaplist **lst; 315 { 316 bool_t more_elements; 317 int freeing = (xdrs->x_op == XDR_FREE); 318 struct ypmaplist **next; 319 320 trace1(TR_xdr_ypmaplist, 0); 321 for (;;) { 322 more_elements = (*lst != (struct ypmaplist *) NULL); 323 324 if (! xdr_bool(xdrs, &more_elements)) { 325 trace1(TR_xdr_ypmaplist, 1); 326 return (FALSE); 327 } 328 329 if (! more_elements) { 330 trace1(TR_xdr_ypmaplist, 1); 331 return (TRUE); /* All done */ 332 } 333 334 if (freeing) 335 next = &((*lst)->ypml_next); 336 337 if (! xdr_reference(xdrs, (caddr_t *)lst, 338 (u_int) sizeof (struct ypmaplist), 339 (xdrproc_t)xdr_ypmaplist_wrap_string)) { 340 trace1(TR_xdr_ypmaplist, 1); 341 return (FALSE); 342 } 343 344 lst = (freeing) ? next : &((*lst)->ypml_next); 345 } 346 /*NOTREACHED*/ 347 } 348 349 /* 350 * Serializes/deserializes a ypresp_maplist. 351 */ 352 bool 353 xdr_ypresp_maplist(xdrs, ps) 354 XDR * xdrs; 355 struct ypresp_maplist *ps; 356 { 357 bool dummy; 358 359 trace1(TR_xdr_ypresp_maplist, 0); 360 dummy = xdr_u_int(xdrs, &ps->status) && 361 xdr_ypmaplist(xdrs, &ps->list); 362 trace1(TR_xdr_ypresp_maplist, 1); 363 return (dummy); 364 } 365 366 /* 367 * Serializes/deserializes a yppushresp_xfr structure. 368 */ 369 bool 370 xdr_yppushresp_xfr(xdrs, ps) 371 XDR *xdrs; 372 struct yppushresp_xfr *ps; 373 { 374 bool dummy; 375 376 trace1(TR_xdr_yppushresp_xfr, 0); 377 dummy = xdr_u_int(xdrs, &ps->transid) && 378 xdr_u_int(xdrs, &ps->status); 379 trace1(TR_xdr_yppushresp_xfr, 1); 380 return (dummy); 381 } 382 383 384 /* 385 * Serializes/deserializes a ypreq_xfr structure. 386 */ 387 bool 388 xdr_ypreq_newxfr(xdrs, ps) 389 XDR * xdrs; 390 struct ypreq_newxfr *ps; 391 { 392 bool dummy; 393 394 trace1(TR_xdr_ypreq_newxfr, 0); 395 dummy = xdr_ypmap_parms(xdrs, &ps->map_parms) && 396 xdr_u_int(xdrs, &ps->transid) && 397 xdr_u_int(xdrs, &ps->proto) && 398 xdr_string(xdrs, &ps->name, 256); 399 trace1(TR_xdr_ypreq_newxfr, 1); 400 return (dummy); 401 } 402 403 /* 404 * Serializes/deserializes a ypreq_xfr structure. 405 */ 406 bool 407 xdr_ypreq_xfr(xdrs, ps) 408 XDR * xdrs; 409 struct ypreq_xfr *ps; 410 { 411 bool dummy; 412 413 trace1(TR_xdr_ypreq_xfr, 0); 414 dummy = xdr_ypmap_parms(xdrs, &ps->map_parms) && 415 xdr_u_int(xdrs, &ps->transid) && 416 xdr_u_int(xdrs, &ps->proto) && 417 xdr_u_short(xdrs, &ps->port); 418 trace1(TR_xdr_ypreq_xfr, 1); 419 return (dummy); 420 } 421 422 423 /* 424 * Serializes/deserializes a stream of struct ypresp_key_val's. This is used 425 * only by the client side of the batch enumerate operation. 426 */ 427 bool 428 xdr_ypall(xdrs, callback) 429 XDR * xdrs; 430 struct ypall_callback *callback; 431 { 432 bool_t more; 433 struct ypresp_key_val kv; 434 bool s; 435 char keybuf[YPMAXRECORD]; 436 char valbuf[YPMAXRECORD]; 437 438 trace1(TR_xdr_ypall, 0); 439 if (xdrs->x_op == XDR_ENCODE) { 440 trace1(TR_xdr_ypall, 1); 441 return (FALSE); 442 } 443 444 if (xdrs->x_op == XDR_FREE) { 445 trace1(TR_xdr_ypall, 1); 446 return (TRUE); 447 } 448 449 kv.keydat.dptr = keybuf; 450 kv.valdat.dptr = valbuf; 451 kv.keydat.dsize = YPMAXRECORD; 452 kv.valdat.dsize = YPMAXRECORD; 453 454 for (;;) { 455 if (! xdr_bool(xdrs, &more)) { 456 trace1(TR_xdr_ypall, 1); 457 return (FALSE); 458 } 459 460 if (! more) { 461 trace1(TR_xdr_ypall, 1); 462 return (TRUE); 463 } 464 465 s = xdr_ypresp_key_val(xdrs, &kv); 466 467 if (s) { 468 s = (*callback->foreach)(kv.status, kv.keydat.dptr, 469 kv.keydat.dsize, kv.valdat.dptr, kv.valdat.dsize, 470 callback->data); 471 472 if (s) { 473 trace1(TR_xdr_ypall, 1); 474 return (TRUE); 475 } 476 } else { 477 trace1(TR_xdr_ypall, 1); 478 return (FALSE); 479 } 480 } 481 } 482 483 bool_t 484 xdr_netconfig(xdrs, objp) 485 XDR *xdrs; 486 struct netconfig *objp; 487 { 488 489 trace1(TR_xdr_netconfig, 0); 490 if (!xdr_string(xdrs, &objp->nc_netid, ~0)) { 491 trace1(TR_xdr_netconfig, 1); 492 return (FALSE); 493 } 494 if (!xdr_u_int(xdrs, &objp->nc_semantics)) { 495 trace1(TR_xdr_netconfig, 1); 496 return (FALSE); 497 } 498 if (!xdr_u_int(xdrs, &objp->nc_flag)) { 499 trace1(TR_xdr_netconfig, 1); 500 return (FALSE); 501 } 502 if (!xdr_string(xdrs, &objp->nc_protofmly, ~0)) { 503 trace1(TR_xdr_netconfig, 1); 504 return (FALSE); 505 } 506 if (!xdr_string(xdrs, &objp->nc_proto, ~0)) { 507 trace1(TR_xdr_netconfig, 1); 508 return (FALSE); 509 } 510 if (!xdr_string(xdrs, &objp->nc_device, ~0)) { 511 trace1(TR_xdr_netconfig, 1); 512 return (FALSE); 513 } 514 if (!xdr_array(xdrs, (char **) &objp->nc_lookups, 515 (u_int *)&objp->nc_nlookups, 100, sizeof (char *), 516 xdr_wrapstring)) { 517 trace1(TR_xdr_netconfig, 1); 518 return (FALSE); 519 } 520 if (!xdr_vector(xdrs, (char *)objp->nc_unused, 521 8, sizeof (u_int), xdr_u_int)) { 522 trace1(TR_xdr_netconfig, 1); 523 return (FALSE); 524 } 525 trace1(TR_xdr_netconfig, 1); 526 return (TRUE); 527 } 528