xref: /freebsd/lib/libc/rpc/authdes_prot.c (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1 #if defined(LIBC_SCCS) && !defined(lint)
2 static char sccsid[] = 	"@(#)authdes_prot.c	2.1 88/07/29 4.0 RPCSRC; from 1.6 88/02/08 SMI";
3 #endif
4 #include <sys/cdefs.h>
5 /*-
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Copyright (c) 2009, Sun Microsystems, Inc.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  * - Redistributions of source code must retain the above copyright notice,
14  *   this list of conditions and the following disclaimer.
15  * - Redistributions in binary form must reproduce the above copyright notice,
16  *   this list of conditions and the following disclaimer in the documentation
17  *   and/or other materials provided with the distribution.
18  * - Neither the name of Sun Microsystems, Inc. nor the names of its
19  *   contributors may be used to endorse or promote products derived
20  *   from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 /*
35  * Copyright (c) 1986-1991 by Sun Microsystems Inc.
36  */
37 
38 /*
39  * authdes_prot.c, XDR routines for DES authentication
40  */
41 
42 #include "namespace.h"
43 #include <rpc/types.h>
44 #include <rpc/xdr.h>
45 #include <rpc/auth.h>
46 #include <rpc/auth_des.h>
47 #include "un-namespace.h"
48 
49 #define ATTEMPT(xdr_op) if (!(xdr_op)) return (FALSE)
50 
51 bool_t
52 xdr_authdes_cred(XDR *xdrs, struct authdes_cred *cred)
53 {
54 	enum authdes_namekind *padc_namekind = &cred->adc_namekind;
55 	/*
56 	 * Unrolled xdr
57 	 */
58 	ATTEMPT(xdr_enum(xdrs, (enum_t *) padc_namekind));
59 	switch (cred->adc_namekind) {
60 	case ADN_FULLNAME:
61 		ATTEMPT(xdr_string(xdrs, &cred->adc_fullname.name,
62 		    MAXNETNAMELEN));
63 		ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_fullname.key,
64 		    sizeof(des_block)));
65 		ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_fullname.window,
66 		    sizeof(cred->adc_fullname.window)));
67 		return (TRUE);
68 	case ADN_NICKNAME:
69 		ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_nickname,
70 		    sizeof(cred->adc_nickname)));
71 		return (TRUE);
72 	default:
73 		return (FALSE);
74 	}
75 }
76 
77 
78 bool_t
79 xdr_authdes_verf(XDR *xdrs, struct authdes_verf *verf)
80 {
81 	/*
82  	 * Unrolled xdr
83  	 */
84 	ATTEMPT(xdr_opaque(xdrs, (caddr_t)&verf->adv_xtimestamp,
85 	    sizeof(des_block)));
86 	ATTEMPT(xdr_opaque(xdrs, (caddr_t)&verf->adv_int_u,
87 	    sizeof(verf->adv_int_u)));
88 	return (TRUE);
89 }
90