8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / krb5 / kadm5 / clnt / clnt_policy.c
blob2c97b167236218960dd045f30970cb6682cffec9
1 /*
2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
7 /*
8 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
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.
16 * For further information, read the top-level Openvision
17 * copyright which is contained in the top-level MIT Kerberos
18 * copyright.
20 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
26 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
28 * $Header$
31 #if !defined(lint) && !defined(__CODECENTER__)
32 static char *rcsid = "$Header$";
33 #endif
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>
43 kadm5_ret_t
44 kadm5_create_policy(void *server_handle,
45 kadm5_policy_ent_t policy, long mask)
47 cpol_arg arg;
48 generic_ret *r;
49 kadm5_server_handle_t handle = server_handle;
51 CHECK_HANDLE(server_handle);
53 if(policy == (kadm5_policy_ent_t) NULL)
54 return EINVAL;
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;
63 return r->code;
66 kadm5_ret_t
67 kadm5_delete_policy(void *server_handle, char *name)
69 dpol_arg arg;
70 generic_ret *r;
71 kadm5_server_handle_t handle = server_handle;
73 CHECK_HANDLE(server_handle);
75 if(name == NULL)
76 return EINVAL;
78 arg.name = name;
79 arg.api_version = handle->api_version;
81 r = delete_policy_2(&arg, handle->clnt);
82 if(r == NULL)
83 return KADM5_RPC_ERROR;
85 return r->code;
88 kadm5_ret_t
89 kadm5_modify_policy(void *server_handle,
90 kadm5_policy_ent_t policy, long mask)
92 mpol_arg arg;
93 generic_ret *r;
94 kadm5_server_handle_t handle = server_handle;
96 CHECK_HANDLE(server_handle);
98 if(policy == (kadm5_policy_ent_t) NULL)
99 return EINVAL;
101 arg.mask = mask;
102 arg.api_version = handle->api_version;
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;
109 return r->code;
112 kadm5_ret_t
113 kadm5_get_policy(void *server_handle, char *name, kadm5_policy_ent_t ent)
115 gpol_arg arg;
116 gpol_ret *r;
117 kadm5_server_handle_t handle = server_handle;
119 CHECK_HANDLE(server_handle);
121 arg.name = name;
122 arg.api_version = handle->api_version;
124 if(name == NULL)
125 return EINVAL;
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;
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;
142 } else {
143 if (r->code == 0)
144 memcpy(ent, &r->rec, sizeof(r->rec));
147 return r->code;
150 kadm5_ret_t
151 kadm5_get_policies(void *server_handle,
152 char *exp, char ***pols, int *count)
154 gpols_arg arg;
155 gpols_ret *r;
156 kadm5_server_handle_t handle = server_handle;
158 CHECK_HANDLE(server_handle);
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;
175 return r->code;