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 /* 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 29 /* All Rights Reserved */ 30 31 /* 32 * Portions of this source code were derived from Berkeley 33 * under license from the Regents of the University of 34 * California. 35 */ 36 37 #include "mt.h" 38 #include <stdlib.h> 39 #include <unistd.h> 40 #include <rpc/rpc.h> 41 #include "yp_b.h" 42 #include <rpcsvc/yp_prot.h> 43 #include <rpcsvc/ypclnt.h> 44 #include <sys/types.h> 45 #include <string.h> 46 47 static int doorder(char *, char *, struct dom_binding *, struct timeval, 48 unsigned long *); 49 50 51 /* 52 * This checks parameters, and implements the outer "until binding success" 53 * loop. 54 */ 55 int 56 yp_order(char *domain, char *map, unsigned long *order) 57 { 58 size_t domlen; 59 size_t maplen; 60 int reason; 61 struct dom_binding *pdomb; 62 63 if ((map == NULL) || (domain == NULL)) 64 return (YPERR_BADARGS); 65 66 domlen = strlen(domain); 67 maplen = strlen(map); 68 69 if ((domlen == 0) || (domlen > YPMAXDOMAIN) || 70 (maplen == 0) || (maplen > YPMAXMAP) || 71 (order == NULL)) 72 return (YPERR_BADARGS); 73 74 for (;;) { 75 76 if (reason = __yp_dobind(domain, &pdomb)) 77 return (reason); 78 79 if (pdomb->dom_binding->ypbind_hi_vers >= YPVERS) { 80 81 reason = doorder(domain, map, pdomb, _ypserv_timeout, 82 order); 83 84 __yp_rel_binding(pdomb); 85 if (reason == YPERR_RPC) { 86 yp_unbind(domain); 87 (void) sleep(_ypsleeptime); 88 } else { 89 break; 90 } 91 } else { 92 __yp_rel_binding(pdomb); 93 return (YPERR_VERS); 94 } 95 } 96 97 return (reason); 98 } 99 100 /* 101 * This talks v3 to ypserv 102 */ 103 static int 104 doorder(char *domain, char *map, struct dom_binding *pdomb, 105 struct timeval timeout, unsigned long *order) 106 { 107 struct ypreq_nokey req; 108 struct ypresp_order resp; 109 unsigned int retval = 0; 110 111 req.domain = domain; 112 req.map = map; 113 (void) memset((char *)&resp, 0, sizeof (struct ypresp_order)); 114 115 /* 116 * Do the get_order request. If the rpc call failed, return with 117 * status from this point. 118 */ 119 120 if (clnt_call(pdomb->dom_client, YPPROC_ORDER, 121 (xdrproc_t)xdr_ypreq_nokey, 122 (char *)&req, (xdrproc_t)xdr_ypresp_order, (char *)&resp, 123 timeout) != RPC_SUCCESS) 124 return (YPERR_RPC); 125 126 /* See if the request succeeded */ 127 128 if (resp.status != YP_TRUE) { 129 retval = ypprot_err(resp.status); 130 } 131 132 *order = (unsigned long)resp.ordernum; 133 CLNT_FREERES(pdomb->dom_client, 134 (xdrproc_t)xdr_ypresp_order, (char *)&resp); 135 return (retval); 136 } 137