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