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
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.
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]
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 * Copyright (c) 2016 by Delphix. All rights reserved.
29 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
30 /* All Rights Reserved */
33 * Portions of this source code were derived from Berkeley
34 * under license from the Regents of the University of
38 #pragma ident "%Z%%M% %I% %E% SMI"
44 #include <sys/types.h>
46 #include <rpcsvc/yp_prot.h>
47 #include <rpcsvc/ypclnt.h>
50 static int domaster(char *, char *, struct dom_binding
*, struct timeval
,
52 extern int __yp_master_rsvdport(char *, char *, char **);
55 * This checks parameters, and implements the outer "until binding success"
59 yp_master(char *domain
, char *map
, char **master
)
64 struct dom_binding
*pdomb
;
66 if ((map
== NULL
) || (domain
== NULL
))
67 return (YPERR_BADARGS
);
69 domlen
= strlen(domain
);
72 if ((domlen
== 0) || (domlen
> YPMAXDOMAIN
) ||
73 (maplen
== 0) || (maplen
> YPMAXMAP
) ||
75 return (YPERR_BADARGS
);
79 if (reason
= __yp_dobind(domain
, &pdomb
))
82 if (pdomb
->dom_binding
->ypbind_hi_vers
>= YPVERS
) {
84 reason
= domaster(domain
, map
, pdomb
, _ypserv_timeout
,
87 __yp_rel_binding(pdomb
);
88 if (reason
== YPERR_RPC
) {
90 (void) sleep(_ypsleeptime
);
95 __yp_rel_binding(pdomb
);
100 if (reason
== YPERR_MAP
&& geteuid() == 0) {
102 * Lookup could be for a secure map; fail over to retry
103 * from a reserved port. Only useful to try this if we're
107 rsvdreason
= __yp_master_rsvdport(domain
, map
, master
);
117 * This function is identical to 'yp_master' with the exception that it calls
118 * '__yp_dobind_rsvdport' rather than '__yp_dobind'
121 __yp_master_rsvdport(char *domain
, char *map
, char **master
)
126 struct dom_binding
*pdomb
;
128 if ((map
== NULL
) || (domain
== NULL
))
129 return (YPERR_BADARGS
);
131 domlen
= strlen(domain
);
132 maplen
= strlen(map
);
134 if ((domlen
== 0) || (domlen
> YPMAXDOMAIN
) ||
135 (maplen
== 0) || (maplen
> YPMAXMAP
) ||
137 return (YPERR_BADARGS
);
141 if (reason
= __yp_dobind_rsvdport(domain
, &pdomb
))
144 if (pdomb
->dom_binding
->ypbind_hi_vers
>= YPVERS
) {
146 reason
= domaster(domain
, map
, pdomb
, _ypserv_timeout
,
150 * Have to free the binding since the reserved
151 * port bindings are not cached.
153 __yp_rel_binding(pdomb
);
154 free_dom_binding(pdomb
);
155 if (reason
== YPERR_RPC
) {
157 (void) sleep(_ypsleeptime
);
163 * Have to free the binding since the reserved
164 * port bindings are not cached.
166 __yp_rel_binding(pdomb
);
167 free_dom_binding(pdomb
);
175 * This talks v2 to ypserv
178 domaster(char *domain
, char *map
, struct dom_binding
*pdomb
,
179 struct timeval timeout
, char **master
)
181 struct ypreq_nokey req
;
182 struct ypresp_master resp
;
183 unsigned int retval
= 0;
187 (void) memset(&resp
, 0, sizeof (struct ypresp_master
));
190 * Do the get_master request. If the rpc call failed, return with
191 * status from this point.
194 if (clnt_call(pdomb
->dom_client
,
195 YPPROC_MASTER
, (xdrproc_t
)xdr_ypreq_nokey
,
196 (char *)&req
, (xdrproc_t
)xdr_ypresp_master
, (char *)&resp
,
197 timeout
) != RPC_SUCCESS
)
200 /* See if the request succeeded */
202 if (resp
.status
!= YP_TRUE
)
203 retval
= ypprot_err(resp
.status
);
205 /* Get some memory which the user can get rid of as they like */
207 if (!retval
&& ((*master
= malloc(strlen(resp
.master
) + 1)) == NULL
))
208 retval
= YPERR_RESRC
;
211 (void) strcpy(*master
, resp
.master
);
213 CLNT_FREERES(pdomb
->dom_client
,
214 (xdrproc_t
)xdr_ypresp_master
, (char *)&resp
);