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