1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
/*
* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
*
* $Header$
*/
#if !defined(lint) && !defined(__CODECENTER__)
static char *rcsid = "$Header$";
#endif
#include <rpc/rpc.h>
#include <kadm5/admin.h>
#include <kadm5/kadm_rpc.h>
#include <memory.h>
#include "client_internal.h"
kadm5_ret_t
kadm5_create_principal(void *server_handle,
kadm5_principal_ent_t princ, long mask,
char *pw)
{
generic_ret *r;
cprinc_arg arg;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.mask = mask;
arg.passwd = pw;
arg.api_version = handle->api_version;
if(princ == NULL)
return EINVAL;
memcpy(&arg.rec, princ, sizeof(kadm5_principal_ent_rec));
if (handle->api_version == KADM5_API_VERSION_1) {
/*
* hack hack cough cough.
* krb5_unparse name dumps core if we pass it in garbage
* or null. So, since the client is not allowed to set mod_name
* anyway, we just fill it in with a dummy principal. The server of
* course ignores this.
*/
krb5_parse_name(handle->context, "bogus/bogus", &arg.rec.mod_name);
} else
arg.rec.mod_name = NULL;
if(!(mask & KADM5_POLICY))
arg.rec.policy = NULL;
if (! (mask & KADM5_KEY_DATA)) {
arg.rec.n_key_data = 0;
arg.rec.key_data = NULL;
}
if (! (mask & KADM5_TL_DATA)) {
arg.rec.n_tl_data = 0;
arg.rec.tl_data = NULL;
}
r = create_principal_1(&arg, handle->clnt);
if (handle->api_version == KADM5_API_VERSION_1)
krb5_free_principal(handle->context, arg.rec.mod_name);
if(r == NULL)
return KADM5_RPC_ERROR;
return r->code;
}
kadm5_ret_t
kadm5_delete_principal(void *server_handle, krb5_principal principal)
{
dprinc_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
if(principal == NULL)
return EINVAL;
arg.princ = principal;
arg.api_version = handle->api_version;
r = delete_principal_1(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
return r->code;
}
kadm5_ret_t
kadm5_modify_principal(void *server_handle,
kadm5_principal_ent_t princ, long mask)
{
mprinc_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.mask = mask;
arg.api_version = handle->api_version;
/*
* cough cough gag gag
* see comment in create_principal.
*/
if(princ == NULL)
return EINVAL;
memcpy(&arg.rec, princ, sizeof(kadm5_principal_ent_rec));
if(!(mask & KADM5_POLICY))
arg.rec.policy = NULL;
if (! (mask & KADM5_KEY_DATA)) {
arg.rec.n_key_data = 0;
arg.rec.key_data = NULL;
}
if (! (mask & KADM5_TL_DATA)) {
arg.rec.n_tl_data = 0;
arg.rec.tl_data = NULL;
}
if (handle->api_version == KADM5_API_VERSION_1) {
/*
* See comment in create_principal
*/
krb5_parse_name(handle->context, "bogus/bogus", &arg.rec.mod_name);
} else
arg.rec.mod_name = NULL;
r = modify_principal_1(&arg, handle->clnt);
if (handle->api_version == KADM5_API_VERSION_1)
krb5_free_principal(handle->context, arg.rec.mod_name);
if(r == NULL)
return KADM5_RPC_ERROR;
return r->code;
}
kadm5_ret_t
kadm5_get_principal(void *server_handle,
krb5_principal princ, kadm5_principal_ent_t ent,
long mask)
{
gprinc_arg arg;
gprinc_ret *r;
kadm5_server_handle_t handle = server_handle;
krb5_error_code retval;
CHECK_HANDLE(server_handle);
if(princ == NULL)
return EINVAL;
arg.princ = princ;
if (handle->api_version == KADM5_API_VERSION_1)
arg.mask = KADM5_PRINCIPAL_NORMAL_MASK;
else
arg.mask = mask;
arg.api_version = handle->api_version;
r = get_principal_1(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
if (handle->api_version == KADM5_API_VERSION_1) {
kadm5_principal_ent_t_v1 *entp;
entp = (kadm5_principal_ent_t_v1 *) ent;
if (r->code == 0) {
if (!(*entp = (kadm5_principal_ent_t_v1)
malloc(sizeof(kadm5_principal_ent_rec_v1))))
return ENOMEM;
/* this memcpy works because the v1 structure is an initial
subset of the v2 struct. C guarantees that this will
result in the same layout in memory */
memcpy(*entp, &r->rec, sizeof(**entp));
} else {
*entp = NULL;
}
} else {
if (r->code == 0)
memcpy(ent, &r->rec, sizeof(r->rec));
}
return r->code;
}
kadm5_ret_t
kadm5_get_principals(void *server_handle,
char *exp, char ***princs, int *count)
{
gprincs_arg arg;
gprincs_ret *r;
kadm5_server_handle_t handle = server_handle;
krb5_error_code retval;
CHECK_HANDLE(server_handle);
if(princs == NULL || count == NULL)
return EINVAL;
arg.exp = exp;
arg.api_version = handle->api_version;
r = get_princs_1(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
if(r->code == 0) {
*count = r->count;
*princs = r->princs;
} else {
*count = 0;
*princs = NULL;
}
return r->code;
}
kadm5_ret_t
kadm5_rename_principal(void *server_handle,
krb5_principal source, krb5_principal dest)
{
rprinc_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.src = source;
arg.dest = dest;
arg.api_version = handle->api_version;
if (source == NULL || dest == NULL)
return EINVAL;
r = rename_principal_1(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
return r->code;
}
kadm5_ret_t
kadm5_chpass_principal(void *server_handle,
krb5_principal princ, char *password)
{
chpass_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.pass = password;
arg.api_version = handle->api_version;
if(princ == NULL)
return EINVAL;
r = chpass_principal_1(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
return r->code;
}
kadm5_ret_t
kadm5_randkey_principal(void *server_handle,
krb5_principal princ,
krb5_keyblock **key, int *n_keys)
{
chrand_arg arg;
chrand_ret *r;
krb5_keyblock new;
kadm5_server_handle_t handle = server_handle;
int i, ret;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.api_version = handle->api_version;
if(princ == NULL)
return EINVAL;
r = chrand_principal_1(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
if (handle->api_version == KADM5_API_VERSION_1) {
if (key)
krb5_copy_keyblock(handle->context, &r->key, key);
} else {
if (n_keys)
*n_keys = r->n_keys;
if (key) {
*key = (krb5_keyblock *) malloc(r->n_keys*sizeof(krb5_keyblock));
if (*key == NULL)
return ENOMEM;
for (i = 0; i < r->n_keys; i++) {
ret = krb5_copy_keyblock_contents(handle->context,
&r->keys[i],
&(*key)[i]);
if (ret) {
free(*key);
return ENOMEM;
}
}
}
}
return r->code;
}
/* not supported on client side */
kadm5_ret_t kadm5_decrypt_key(void *server_handle,
kadm5_principal_ent_t entry, krb5_int32
ktype, krb5_int32 stype, krb5_int32
kvno, krb5_keyblock *keyblock,
krb5_keysalt *keysalt, int *kvnop)
{
return EINVAL;
}
|