1 /* $OpenBSD: yp_order.c,v 1.11 2022/08/02 16:59:30 deraadt Exp $ */
2 /*
3 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@theos.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/types.h>
29 #include <string.h>
30 #include <limits.h>
31 #include <rpc/rpc.h>
32 #include <rpc/xdr.h>
33 #include <rpcsvc/yp.h>
34 #include <rpcsvc/ypclnt.h>
35 #include "ypinternal.h"
36
37 int
yp_order(const char * indomain,const char * inmap,int * outorder)38 yp_order(const char *indomain, const char *inmap, int *outorder)
39 {
40 struct dom_binding *ysd;
41 struct ypresp_order ypro;
42 struct ypreq_nokey yprnk;
43 struct timeval tv;
44 int r = 0;
45
46 if (indomain == NULL || *indomain == '\0' ||
47 strlen(indomain) > YPMAXDOMAIN || inmap == NULL ||
48 *inmap == '\0' || strlen(inmap) > YPMAXMAP || outorder == NULL)
49 return YPERR_BADARGS;
50
51 again:
52 if (_yp_dobind(indomain, &ysd) != 0)
53 return YPERR_DOMAIN;
54
55 tv.tv_sec = _yplib_timeout;
56 tv.tv_usec = 0;
57
58 yprnk.domain = (char *)indomain;
59 yprnk.map = (char *)inmap;
60
61 (void)memset(&ypro, 0, sizeof ypro);
62
63 r = clnt_call(ysd->dom_client, YPPROC_ORDER,
64 xdr_ypreq_nokey, &yprnk, xdr_ypresp_order, &ypro, tv);
65 /*
66 * XXX
67 * NIS+ YP emulation package does not implement YPPROC_ORDER
68 */
69 if (r == RPC_PROCUNAVAIL) {
70 r = YPERR_YPERR;
71 goto bail;
72 }
73 if (r != RPC_SUCCESS) {
74 clnt_perror(ysd->dom_client, "yp_order: clnt_call");
75 _yp_unbind(ysd);
76 goto again;
77 }
78 *outorder = ypro.ordernum;
79 xdr_free(xdr_ypresp_order, (char *) &ypro);
80 r = ypprot_err(ypro.stat);
81 bail:
82 _yp_unbind(ysd);
83 return r;
84 }
85