1*7f2fe78bSCy Schubert #include <sys/types.h>
2*7f2fe78bSCy Schubert #include <krb5.h>
3*7f2fe78bSCy Schubert #include <gssrpc/rpc.h>
4*7f2fe78bSCy Schubert #include <kdb.h>
5*7f2fe78bSCy Schubert #include <kadm5/admin_xdr.h>
6*7f2fe78bSCy Schubert #include "policy_db.h"
7*7f2fe78bSCy Schubert #ifdef HAVE_MEMORY_H
8*7f2fe78bSCy Schubert #include <memory.h>
9*7f2fe78bSCy Schubert #endif
10*7f2fe78bSCy Schubert #include <string.h>
11*7f2fe78bSCy Schubert
12*7f2fe78bSCy Schubert static int
osa_policy_min_vers(osa_policy_ent_t objp)13*7f2fe78bSCy Schubert osa_policy_min_vers(osa_policy_ent_t objp)
14*7f2fe78bSCy Schubert {
15*7f2fe78bSCy Schubert if (objp->attributes ||
16*7f2fe78bSCy Schubert objp->max_life ||
17*7f2fe78bSCy Schubert objp->max_renewable_life ||
18*7f2fe78bSCy Schubert objp->allowed_keysalts ||
19*7f2fe78bSCy Schubert objp->n_tl_data)
20*7f2fe78bSCy Schubert return OSA_ADB_POLICY_VERSION_3;
21*7f2fe78bSCy Schubert
22*7f2fe78bSCy Schubert if (objp->pw_max_fail ||
23*7f2fe78bSCy Schubert objp->pw_failcnt_interval ||
24*7f2fe78bSCy Schubert objp->pw_lockout_duration)
25*7f2fe78bSCy Schubert return OSA_ADB_POLICY_VERSION_2;
26*7f2fe78bSCy Schubert
27*7f2fe78bSCy Schubert return OSA_ADB_POLICY_VERSION_1;
28*7f2fe78bSCy Schubert }
29*7f2fe78bSCy Schubert
30*7f2fe78bSCy Schubert bool_t
xdr_osa_policy_ent_rec(XDR * xdrs,osa_policy_ent_t objp)31*7f2fe78bSCy Schubert xdr_osa_policy_ent_rec(XDR *xdrs, osa_policy_ent_t objp)
32*7f2fe78bSCy Schubert {
33*7f2fe78bSCy Schubert switch (xdrs->x_op) {
34*7f2fe78bSCy Schubert case XDR_ENCODE:
35*7f2fe78bSCy Schubert objp->version = osa_policy_min_vers(objp);
36*7f2fe78bSCy Schubert /* fall through */
37*7f2fe78bSCy Schubert case XDR_FREE:
38*7f2fe78bSCy Schubert if (!xdr_int(xdrs, &objp->version))
39*7f2fe78bSCy Schubert return FALSE;
40*7f2fe78bSCy Schubert break;
41*7f2fe78bSCy Schubert case XDR_DECODE:
42*7f2fe78bSCy Schubert if (!xdr_int(xdrs, &objp->version))
43*7f2fe78bSCy Schubert return FALSE;
44*7f2fe78bSCy Schubert if (objp->version != OSA_ADB_POLICY_VERSION_1 &&
45*7f2fe78bSCy Schubert objp->version != OSA_ADB_POLICY_VERSION_2 &&
46*7f2fe78bSCy Schubert objp->version != OSA_ADB_POLICY_VERSION_3)
47*7f2fe78bSCy Schubert return FALSE;
48*7f2fe78bSCy Schubert break;
49*7f2fe78bSCy Schubert }
50*7f2fe78bSCy Schubert
51*7f2fe78bSCy Schubert if(!xdr_nullstring(xdrs, &objp->name))
52*7f2fe78bSCy Schubert return (FALSE);
53*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->pw_min_life))
54*7f2fe78bSCy Schubert return (FALSE);
55*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->pw_max_life))
56*7f2fe78bSCy Schubert return (FALSE);
57*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->pw_min_length))
58*7f2fe78bSCy Schubert return (FALSE);
59*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->pw_min_classes))
60*7f2fe78bSCy Schubert return (FALSE);
61*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->pw_history_num))
62*7f2fe78bSCy Schubert return (FALSE);
63*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->policy_refcnt))
64*7f2fe78bSCy Schubert return (FALSE);
65*7f2fe78bSCy Schubert if (objp->version > OSA_ADB_POLICY_VERSION_1) {
66*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->pw_max_fail))
67*7f2fe78bSCy Schubert return (FALSE);
68*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->pw_failcnt_interval))
69*7f2fe78bSCy Schubert return (FALSE);
70*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->pw_lockout_duration))
71*7f2fe78bSCy Schubert return (FALSE);
72*7f2fe78bSCy Schubert }
73*7f2fe78bSCy Schubert if (objp->version > OSA_ADB_POLICY_VERSION_2) {
74*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->attributes))
75*7f2fe78bSCy Schubert return (FALSE);
76*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->max_life))
77*7f2fe78bSCy Schubert return (FALSE);
78*7f2fe78bSCy Schubert if (!xdr_u_int32(xdrs, &objp->max_renewable_life))
79*7f2fe78bSCy Schubert return (FALSE);
80*7f2fe78bSCy Schubert if (!xdr_nullstring(xdrs, &objp->allowed_keysalts))
81*7f2fe78bSCy Schubert return (FALSE);
82*7f2fe78bSCy Schubert if (!xdr_short(xdrs, &objp->n_tl_data))
83*7f2fe78bSCy Schubert return (FALSE);
84*7f2fe78bSCy Schubert if (!xdr_nulltype(xdrs, (void **) &objp->tl_data,
85*7f2fe78bSCy Schubert xdr_krb5_tl_data))
86*7f2fe78bSCy Schubert return FALSE;
87*7f2fe78bSCy Schubert }
88*7f2fe78bSCy Schubert return (TRUE);
89*7f2fe78bSCy Schubert }
90