xref: /illumos-gate/usr/src/lib/libnsl/yp/yp_b_xdr.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 2001 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 #include <rpc/rpc.h>
38 #include <netconfig.h>
39 #include "yp_b.h"
40 #include <rpcsvc/yp_prot.h>
41 #include <sys/types.h>
42 #include <rpc/trace.h>
43 
44 bool_t
45 xdr_ypbind_resptype(xdrs, objp)
46 	XDR *xdrs;
47 	ypbind_resptype *objp;
48 {
49 	trace1(TR_xdr_ypbind_resptype, 0);
50 	if (!xdr_enum(xdrs, (enum_t *)objp)) {
51 		trace1(TR_xdr_ypbind_resptype, 1);
52 		return (FALSE);
53 	}
54 	trace1(TR_xdr_ypbind_resptype, 1);
55 	return (TRUE);
56 }
57 
58 
59 #define	YPBIND_ERR_ERR 1		/* Internal error */
60 #define	YPBIND_ERR_NOSERV 2		/* No bound server for passed domain */
61 #define	YPBIND_ERR_RESC 3		/* System resource allocation failure */
62 #define	YPBIND_ERR_NODOMAIN 4		/* Domain doesn't exist */
63 
64 
65 bool_t
66 xdr_ypbind_domain(xdrs, objp)
67 	XDR *xdrs;
68 	ypbind_domain *objp;
69 {
70 	trace1(TR_xdr_ypbind_domain, 0);
71 	if (!xdr_string(xdrs, &objp->ypbind_domainname, YPMAXDOMAIN)) {
72 		trace1(TR_xdr_ypbind_domain, 1);
73 		return (FALSE);
74 	}
75 	if (!xdr_rpcvers(xdrs, &objp->ypbind_vers)) {
76 		trace1(TR_xdr_ypbind_domain, 1);
77 		return (FALSE);
78 	}
79 	trace1(TR_xdr_ypbind_domain, 1);
80 	return (TRUE);
81 }
82 
83 
84 bool_t
85 xdr_ypbind_binding(xdrs, objp)
86 	XDR *xdrs;
87 	ypbind_binding *objp;
88 {
89 	trace1(TR_xdr_ypbind_binding, 0);
90 	if (!xdr_pointer(xdrs, (char **)&objp->ypbind_nconf,
91 		sizeof (struct netconfig), xdr_netconfig)) {
92 		trace1(TR_xdr_ypbind_binding, 1);
93 		return (FALSE);
94 	}
95 	if (!xdr_pointer(xdrs, (char **)&objp->ypbind_svcaddr,
96 		sizeof (struct netbuf), xdr_netbuf)) {
97 		trace1(TR_xdr_ypbind_binding, 1);
98 		return (FALSE);
99 	}
100 	if (!xdr_string(xdrs, &objp->ypbind_servername, ~0)) {
101 		trace1(TR_xdr_ypbind_binding, 1);
102 		return (FALSE);
103 	}
104 	if (!xdr_rpcvers(xdrs, &objp->ypbind_hi_vers)) {
105 		trace1(TR_xdr_ypbind_binding, 1);
106 		return (FALSE);
107 	}
108 	if (!xdr_rpcvers(xdrs, &objp->ypbind_lo_vers)) {
109 		trace1(TR_xdr_ypbind_binding, 1);
110 		return (FALSE);
111 	}
112 	trace1(TR_xdr_ypbind_binding, 1);
113 	return (TRUE);
114 }
115 
116 
117 bool_t
118 xdr_ypbind_resp(xdrs, objp)
119 	XDR *xdrs;
120 	ypbind_resp *objp;
121 {
122 	trace1(TR_xdr_ypbind_resp, 0);
123 	if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status)) {
124 		trace1(TR_xdr_ypbind_resp, 1);
125 		return (FALSE);
126 	}
127 	switch (objp->ypbind_status) {
128 	case YPBIND_FAIL_VAL:
129 		if (!xdr_u_int(xdrs, &objp->ypbind_resp_u.ypbind_error)) {
130 			trace1(TR_xdr_ypbind_resp, 1);
131 			return (FALSE);
132 		}
133 		break;
134 	case YPBIND_SUCC_VAL:
135 		if (!xdr_pointer(xdrs,
136 			(char **)&objp->ypbind_resp_u.ypbind_bindinfo,
137 			sizeof (ypbind_binding), xdr_ypbind_binding)) {
138 			trace1(TR_xdr_ypbind_resp, 1);
139 			return (FALSE);
140 		}
141 		break;
142 	default:
143 		trace1(TR_xdr_ypbind_resp, 1);
144 		return (FALSE);
145 	}
146 	trace1(TR_xdr_ypbind_resp, 1);
147 	return (TRUE);
148 }
149 
150 
151 bool_t
152 xdr_ypbind_setdom(xdrs, objp)
153 	XDR *xdrs;
154 	ypbind_setdom *objp;
155 {
156 	trace1(TR_xdr_ypbind_setdom, 0);
157 	if (!xdr_string(xdrs, &objp->ypsetdom_domain, YPMAXDOMAIN)) {
158 		trace1(TR_xdr_ypbind_setdom, 1);
159 		return (FALSE);
160 	}
161 	if (!xdr_pointer(xdrs, (char **)&objp->ypsetdom_bindinfo,
162 		sizeof (ypbind_binding), xdr_ypbind_binding)) {
163 		trace1(TR_xdr_ypbind_setdom, 1);
164 		return (FALSE);
165 	}
166 	trace1(TR_xdr_ypbind_setdom, 1);
167 	return (TRUE);
168 }
169