xref: /titanic_50/usr/src/lib/krb5/kadm5/srv/adb_xdr.c (revision 927a453e165c072d45bd6aa2945b3db0fce17c56)
1 /*
2  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
10  *
11  *	Openvision retains the copyright to derivative works of
12  *	this source code.  Do *NOT* create a derivative of this
13  *	source code before consulting with your legal department.
14  *	Do *NOT* integrate *ANY* of this source code into another
15  *	product before consulting with your legal department.
16  *
17  *	For further information, read the top-level Openvision
18  *	copyright which is contained in the top-level MIT Kerberos
19  *	copyright.
20  *
21  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
22  *
23  */
24 
25 
26 /*
27  * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
28  *
29  * $Header: /cvs/krbdev/krb5/src/lib/kadm5/srv/adb_xdr.c,v 1.4 2001/07/25 19:03:35 epeisach Exp $
30  */
31 
32 #if !defined(lint) && !defined(__CODECENTER__)
33 static char *rcsid = "$Header: /cvs/krbdev/krb5/src/lib/kadm5/srv/adb_xdr.c,v 1.2 1998/02/14 02:31:34 tlyu Exp $";
34 #endif
35 
36 #include <sys/types.h>
37 #include <krb5.h>
38 #include <rpc/rpc.h> /* SUNWresync121 XXX */
39 #include "adb.h"
40 #include "admin_xdr.h"
41 #ifdef HAVE_MEMORY_H
42 #include <memory.h>
43 #endif
44 
45 bool_t
46 xdr_krb5_key_data(XDR *xdrs, krb5_key_data *objp)
47 {
48     unsigned int tmp;
49 
50     if (!xdr_krb5_int16(xdrs, &objp->key_data_ver))
51 	return(FALSE);
52     if (!xdr_krb5_int16(xdrs, &objp->key_data_kvno))
53 	return(FALSE);
54     if (!xdr_krb5_int16(xdrs, &objp->key_data_type[0]))
55 	return(FALSE);
56     if (!xdr_krb5_int16(xdrs, &objp->key_data_type[1]))
57 	return(FALSE);
58 	/* SUNW14resync */
59     if (!xdr_krb5_ui_2(xdrs, (krb5_ui_2 *)&objp->key_data_length[0]))
60 	return(FALSE);
61     if (!xdr_krb5_ui_2(xdrs, (krb5_ui_2 *)&objp->key_data_length[1]))
62 	return(FALSE);
63 
64     tmp = (unsigned int) objp->key_data_length[0];
65     if (!xdr_bytes(xdrs, (char **) &objp->key_data_contents[0],
66 		   &tmp, ~0))
67 	return FALSE;
68 
69     tmp = (unsigned int) objp->key_data_length[1];
70     if (!xdr_bytes(xdrs, (char **) &objp->key_data_contents[1],
71 		   &tmp, ~0))
72 	return FALSE;
73 
74     /* don't need to copy tmp out, since key_data_length will be set
75        by the above encoding. */
76 
77     return(TRUE);
78 }
79 
80 bool_t
81 xdr_osa_pw_hist_ent(XDR *xdrs, osa_pw_hist_ent *objp)
82 {
83     if (!xdr_array(xdrs, (caddr_t *) &objp->key_data,
84 		   (u_int *) &objp->n_key_data, ~0,
85 		   sizeof(krb5_key_data),
86 		   xdr_krb5_key_data))
87 	return (FALSE);
88     return (TRUE);
89 }
90 
91 bool_t
92 xdr_osa_princ_ent_rec(XDR *xdrs, osa_princ_ent_t objp)
93 {
94     switch (xdrs->x_op) {
95     case XDR_ENCODE:
96 	 objp->version = OSA_ADB_PRINC_VERSION_1;
97 	 /* fall through */
98     case XDR_FREE:
99 	 if (!xdr_int(xdrs, &objp->version))
100 	      return FALSE;
101 	 break;
102     case XDR_DECODE:
103 	 if (!xdr_int(xdrs, &objp->version))
104 	      return FALSE;
105 	 if (objp->version != OSA_ADB_PRINC_VERSION_1)
106 	      return FALSE;
107 	 break;
108     }
109 
110     if (!xdr_nullstring(xdrs, &objp->policy))
111 	return (FALSE);
112     if (!xdr_long(xdrs, &objp->aux_attributes))
113 	return (FALSE);
114     if (!xdr_u_int(xdrs, &objp->old_key_next))
115 	return (FALSE);
116     if (!xdr_krb5_kvno(xdrs, &objp->admin_history_kvno))
117 	return (FALSE);
118     if (!xdr_array(xdrs, (caddr_t *) &objp->old_keys,
119 		   (unsigned int *) &objp->old_key_len, ~0,
120 		   sizeof(osa_pw_hist_ent),
121 		   xdr_osa_pw_hist_ent))
122 	return (FALSE);
123     return (TRUE);
124 }
125 
126 bool_t
127 xdr_osa_policy_ent_rec(XDR *xdrs, osa_policy_ent_t objp)
128 {
129     switch (xdrs->x_op) {
130     case XDR_ENCODE:
131 	 objp->version = OSA_ADB_POLICY_VERSION_1;
132 	 /* fall through */
133     case XDR_FREE:
134 	 if (!xdr_int(xdrs, &objp->version))
135 	      return FALSE;
136 	 break;
137     case XDR_DECODE:
138 	 if (!xdr_int(xdrs, &objp->version))
139 	      return FALSE;
140 	 if (objp->version != OSA_ADB_POLICY_VERSION_1)
141 	      return FALSE;
142 	 break;
143     }
144 
145     if(!xdr_nullstring(xdrs, &objp->name))
146 	return (FALSE);
147     if (!xdr_u_int(xdrs, &objp->pw_min_life))
148 	return (FALSE);
149     if (!xdr_u_int(xdrs, &objp->pw_max_life))
150 	return (FALSE);
151     if (!xdr_u_int(xdrs, &objp->pw_min_length))
152 	return (FALSE);
153     if (!xdr_u_int(xdrs, &objp->pw_min_classes))
154 	return (FALSE);
155     if (!xdr_u_int(xdrs, &objp->pw_history_num))
156 	return (FALSE);
157     if (!xdr_u_int(xdrs, &objp->policy_refcnt))
158 	return (FALSE);
159     return (TRUE);
160 }
161