xref: /titanic_52/usr/src/lib/libnsl/yp/yp_order.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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 #define	NULL 0
38 #include <rpc/rpc.h>
39 #include "yp_b.h"
40 #include <rpcsvc/yp_prot.h>
41 #include <rpcsvc/ypclnt.h>
42 #include <sys/types.h>
43 #include <rpc/trace.h>
44 #include <stdlib.h>
45 #include <unistd.h>
46 #include <string.h>
47 
48 static int doorder(char *, char *, struct dom_binding *, struct timeval,
49     unsigned long *);
50 
51 
52 /*
53  * This checks parameters, and implements the outer "until binding success"
54  * loop.
55  */
56 int
57 yp_order (domain, map, order)
58 	char *domain;
59 	char *map;
60 	unsigned long *order;
61 {
62 	size_t domlen;
63 	size_t maplen;
64 	int reason;
65 	struct dom_binding *pdomb;
66 
67 	trace1(TR_yp_order, 0);
68 	if ((map == NULL) || (domain == NULL)) {
69 		trace1(TR_yp_order, 1);
70 		return (YPERR_BADARGS);
71 	}
72 
73 	domlen = strlen(domain);
74 	maplen = strlen(map);
75 
76 	if ((domlen == 0) || (domlen > YPMAXDOMAIN) ||
77 	    (maplen == 0) || (maplen > YPMAXMAP) ||
78 	    (order == NULL)) {
79 		trace1(TR_yp_order, 1);
80 		return (YPERR_BADARGS);
81 	}
82 
83 	for (;;) {
84 
85 		if (reason = __yp_dobind(domain, &pdomb)) {
86 			trace1(TR_yp_order, 1);
87 			return (reason);
88 		}
89 
90 		if (pdomb->dom_binding->ypbind_hi_vers >= YPVERS) {
91 
92 			reason = doorder(domain, map, pdomb, _ypserv_timeout,
93 			    order);
94 
95 			__yp_rel_binding(pdomb);
96 			if (reason == YPERR_RPC) {
97 				yp_unbind(domain);
98 				(void) _sleep(_ypsleeptime);
99 			} else {
100 				break;
101 			}
102 		} else {
103 			__yp_rel_binding(pdomb);
104 			trace1(TR_yp_order, 1);
105 			return (YPERR_VERS);
106 		}
107 	}
108 
109 	trace1(TR_yp_order, 1);
110 	return (reason);
111 
112 }
113 
114 /*
115  * This talks v3 to ypserv
116  */
117 static int
118 doorder (domain, map, pdomb, timeout, order)
119 	char *domain;
120 	char *map;
121 	struct dom_binding *pdomb;
122 	struct timeval timeout;
123 	unsigned long *order;
124 {
125 	struct ypreq_nokey req;
126 	struct ypresp_order resp;
127 	unsigned int retval = 0;
128 
129 	trace1(TR_doorder, 0);
130 	req.domain = domain;
131 	req.map = map;
132 	(void) memset((char *)&resp, 0, sizeof (struct ypresp_order));
133 
134 	/*
135 	 * Do the get_order request.  If the rpc call failed, return with
136 	 * status from this point.
137 	 */
138 
139 	if (clnt_call(pdomb->dom_client, YPPROC_ORDER,
140 			(xdrproc_t)xdr_ypreq_nokey,
141 		    (char *)&req, (xdrproc_t) xdr_ypresp_order, (char *)&resp,
142 		    timeout) != RPC_SUCCESS) {
143 		trace1(TR_doorder, 1);
144 		return (YPERR_RPC);
145 	}
146 
147 	/* See if the request succeeded */
148 
149 	if (resp.status != YP_TRUE) {
150 		retval = ypprot_err(resp.status);
151 	}
152 
153 	*order = (unsigned long)resp.ordernum;
154 	CLNT_FREERES(pdomb->dom_client,
155 		(xdrproc_t)xdr_ypresp_order, (char *)&resp);
156 	trace1(TR_doorder, 1);
157 	return (retval);
158 
159 }
160