xref: /illumos-gate/usr/src/lib/krb5/plugins/kdb/db2/pol_xdr.c (revision 9622934a862fa39a8e90c816c4136e293d75629d)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 
3 #include <sys/types.h>
4 #include <krb5.h>
5 /* Solaris Kerberos: gssrpc not supported */
6 #if 0 /************** Begin IFDEF'ed OUT *******************************/
7 #include <gssrpc/rpc.h>
8 #else
9 #include <rpc/rpc.h>
10 #include <kadm5/kadm_rpc.h>
11 #endif /**************** END IFDEF'ed OUT *******************************/
12 #include <kdb.h>
13 #include "policy_db.h"
14 #ifdef HAVE_MEMORY_H
15 #include <memory.h>
16 #endif
17 #include <strings.h>
18 
19 /* Solaris Kerberos: this function taken from MIT's src/lib/rpc/xdr.c */
20 bool_t
21 xdr_u_int32(XDR *xdrs, uint32_t *up)
22 {
23 	u_long ul;
24 
25 	switch (xdrs->x_op) {
26 
27 	case XDR_ENCODE:
28 		ul = *up;
29 		return (xdr_u_long(xdrs, &ul));
30 
31 	case XDR_DECODE:
32 		if (!xdr_u_long(xdrs, &ul)) {
33 			return (FALSE);
34 		}
35 		*up = ul;
36 		return (TRUE);
37 
38 	case XDR_FREE:
39 		return (TRUE);
40 	}
41 	return (FALSE);
42 }
43 
44 static
45 bool_t xdr_nullstring(XDR *xdrs, char **objp)
46 {
47      u_int size;
48 
49      if (xdrs->x_op == XDR_ENCODE) {
50           if (*objp == NULL)
51                size = 0;
52           else
53                size = strlen(*objp) + 1;
54      }
55      if (! xdr_u_int(xdrs, &size)) {
56           return FALSE;
57         }
58      switch (xdrs->x_op) {
59      case XDR_DECODE:
60           if (size == 0) {
61                *objp = NULL;
62                return TRUE;
63           } else if (*objp == NULL) {
64                *objp = (char *) mem_alloc(size);
65                if (*objp == NULL) {
66                     errno = ENOMEM;
67                     return FALSE;
68                }
69           }
70           return (xdr_opaque(xdrs, *objp, size));
71 
72      case XDR_ENCODE:
73           if (size != 0)
74                return (xdr_opaque(xdrs, *objp, size));
75           return TRUE;
76 
77      case XDR_FREE:
78           if (*objp != NULL)
79                mem_free(*objp, size);
80           *objp = NULL;
81           return TRUE;
82      }
83 
84      return FALSE;
85 }
86 
87 
88 
89 bool_t
90 xdr_osa_policy_ent_rec(XDR *xdrs, osa_policy_ent_t objp)
91 {
92     switch (xdrs->x_op) {
93     case XDR_ENCODE:
94 	 objp->version = OSA_ADB_POLICY_VERSION_1;
95 	 /* fall through */
96     case XDR_FREE:
97 	 if (!xdr_int(xdrs, &objp->version))
98 	      return FALSE;
99 	 break;
100     case XDR_DECODE:
101 	 if (!xdr_int(xdrs, &objp->version))
102 	      return FALSE;
103 	 if (objp->version != OSA_ADB_POLICY_VERSION_1)
104 	      return FALSE;
105 	 break;
106     }
107 
108     if(!xdr_nullstring(xdrs, &objp->name))
109 	return (FALSE);
110     if (!xdr_u_int32(xdrs, &objp->pw_min_life))
111 	return (FALSE);
112     if (!xdr_u_int32(xdrs, &objp->pw_max_life))
113 	return (FALSE);
114     if (!xdr_u_int32(xdrs, &objp->pw_min_length))
115 	return (FALSE);
116     if (!xdr_u_int32(xdrs, &objp->pw_min_classes))
117 	return (FALSE);
118     if (!xdr_u_int32(xdrs, &objp->pw_history_num))
119 	return (FALSE);
120     if (!xdr_u_int32(xdrs, &objp->policy_refcnt))
121 	return (FALSE);
122     return (TRUE);
123 }
124