xref: /illumos-gate/usr/src/lib/krb5/kadm5/clnt/clnt_policy.c (revision 2983dda76a6d296fdb560c88114fe41caad1b84f)
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    <rpc/rpc.h> /* SUNWresync121 XXX */
36 #include    <kadm5/admin.h>
37 #include    <kadm5/kadm_rpc.h>
38 #include    "client_internal.h"
39 #include	<stdlib.h>
40 #include	<string.h>
41 #include	<errno.h>
42 
43 kadm5_ret_t
44 kadm5_create_policy(void *server_handle,
45 			 kadm5_policy_ent_t policy, long mask)
46 {
47     cpol_arg		arg;
48     generic_ret		*r;
49     kadm5_server_handle_t handle = server_handle;
50 
51     CHECK_HANDLE(server_handle);
52 
53     if(policy == (kadm5_policy_ent_t) NULL)
54 	return EINVAL;
55 
56     arg.mask = mask;
57     arg.api_version = handle->api_version;
58     memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
59     r = create_policy_2(&arg, handle->clnt);
60     if(r == NULL)
61 	return KADM5_RPC_ERROR;
62 
63     return r->code;
64 }
65 
66 kadm5_ret_t
67 kadm5_delete_policy(void *server_handle, char *name)
68 {
69     dpol_arg		arg;
70     generic_ret		*r;
71     kadm5_server_handle_t handle = server_handle;
72 
73     CHECK_HANDLE(server_handle);
74 
75     if(name == NULL)
76 	return EINVAL;
77 
78     arg.name = name;
79     arg.api_version = handle->api_version;
80 
81     r = delete_policy_2(&arg, handle->clnt);
82     if(r == NULL)
83 	return KADM5_RPC_ERROR;
84 
85     return r->code;
86 }
87 
88 kadm5_ret_t
89 kadm5_modify_policy(void *server_handle,
90 			 kadm5_policy_ent_t policy, long mask)
91 {
92     mpol_arg		arg;
93     generic_ret		*r;
94     kadm5_server_handle_t handle = server_handle;
95 
96     CHECK_HANDLE(server_handle);
97 
98     if(policy == (kadm5_policy_ent_t) NULL)
99 	return EINVAL;
100 
101     arg.mask = mask;
102     arg.api_version = handle->api_version;
103 
104     memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
105     r = modify_policy_2(&arg, handle->clnt);
106     if(r == NULL)
107 	return KADM5_RPC_ERROR;
108 
109     return r->code;
110 }
111 
112 kadm5_ret_t
113 kadm5_get_policy(void *server_handle, char *name, kadm5_policy_ent_t ent)
114 {
115     gpol_arg	    arg;
116     gpol_ret	    *r;
117     kadm5_server_handle_t handle = server_handle;
118 
119     CHECK_HANDLE(server_handle);
120 
121     arg.name = name;
122     arg.api_version = handle->api_version;
123 
124     if(name == NULL)
125 	return EINVAL;
126 
127     r = get_policy_2(&arg, handle->clnt);
128     if(r == NULL)
129 	return KADM5_RPC_ERROR;
130     if (handle->api_version == KADM5_API_VERSION_1) {
131 	 kadm5_policy_ent_t *entp;
132 
133 	 entp = (kadm5_policy_ent_t *) ent;
134 	 if(r->code == 0) {
135 	      if (!(*entp = (kadm5_policy_ent_t)
136 		    malloc(sizeof(kadm5_policy_ent_rec))))
137 		   return ENOMEM;
138 	      memcpy(*entp, &r->rec, sizeof(**entp));
139 	 } else {
140 	      *entp = NULL;
141 	 }
142     } else {
143 	 if (r->code == 0)
144 	      memcpy(ent, &r->rec, sizeof(r->rec));
145     }
146 
147     return r->code;
148 }
149 
150 kadm5_ret_t
151 kadm5_get_policies(void *server_handle,
152 			  char *exp, char ***pols, int *count)
153 {
154     gpols_arg	arg;
155     gpols_ret	*r;
156     kadm5_server_handle_t handle = server_handle;
157 
158     CHECK_HANDLE(server_handle);
159 
160     if(pols == NULL || count == NULL)
161 	return EINVAL;
162     arg.exp = exp;
163     arg.api_version = handle->api_version;
164     r = get_pols_2(&arg, handle->clnt);
165     if(r == NULL)
166 	return KADM5_RPC_ERROR;
167     if(r->code == 0) {
168 	 *count = r->count;
169 	 *pols = r->pols;
170     } else {
171 	 *count = 0;
172 	 *pols = NULL;
173     }
174 
175     return r->code;
176 }
177