dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / krb5 / kadm5 / kadm_rpc_xdr.c
blobc6220cdaf49f062c606461b76171dacd6d4a28d7
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
29 #include <rpc/rpc.h>
30 #include <errno.h>
31 #include <kadm5/admin.h>
32 #include <kadm5/kadm_rpc.h>
33 #include <krb5.h>
34 #include <stdlib.h>
35 #include <string.h>
37 static bool_t
38 _xdr_kadm5_principal_ent_rec(XDR *xdrs, kadm5_principal_ent_rec *objp,
39 int v);
41 bool_t
42 xdr_krb5_salttype(XDR *xdrs, krb5_int32 *objp); /* SUNWresync121 XXX */
44 * Function: xdr_ui_4
46 * Purpose: XDR function which serves as a wrapper for xdr_u_int,
47 * to prevent compiler warnings about type clashes between u_int32
48 * and krb5_ui_4.
50 bool_t xdr_ui_4(XDR *xdrs, krb5_ui_4 *objp)
52 /* Assumes that krb5_ui_4 and u_int32 are both four bytes long.
53 This should not be a harmful assumption. */
54 return xdr_u_int(xdrs, (uint32_t *) objp);
59 * Function: xdr_nullstring
61 * Purpose: XDR function for "strings" that are either NULL-terminated
62 * or NULL.
64 bool_t xdr_nullstring(XDR *xdrs, char **objp)
66 u_int size;
68 if (xdrs->x_op == XDR_ENCODE) {
69 if (*objp == NULL)
70 size = 0;
71 else
72 size = strlen(*objp) + 1;
74 if (! xdr_u_int(xdrs, &size)) {
75 return FALSE;
77 switch (xdrs->x_op) {
78 case XDR_DECODE:
79 if (size == 0) {
80 *objp = NULL;
81 return TRUE;
82 } else if (*objp == NULL) {
83 *objp = (char *) mem_alloc(size);
84 if (*objp == NULL) {
85 errno = ENOMEM;
86 return FALSE;
89 return (xdr_opaque(xdrs, *objp, size));
91 case XDR_ENCODE:
92 if (size != 0)
93 return (xdr_opaque(xdrs, *objp, size));
94 return TRUE;
96 case XDR_FREE:
97 if (*objp != NULL)
98 mem_free(*objp, size);
99 *objp = NULL;
100 return TRUE;
103 return FALSE;
107 * Function: xdr_nulltype
109 * Purpose: XDR function for arbitrary pointer types that are either
110 * NULL or contain data.
112 bool_t xdr_nulltype(XDR *xdrs, void **objp, xdrproc_t proc)
114 bool_t null;
116 switch (xdrs->x_op) {
117 case XDR_DECODE:
118 if (!xdr_bool(xdrs, &null))
119 return FALSE;
120 if (null) {
121 *objp = NULL;
122 return TRUE;
124 return (*proc)(xdrs, objp);
126 case XDR_ENCODE:
127 if (*objp == NULL)
128 null = TRUE;
129 else
130 null = FALSE;
131 if (!xdr_bool(xdrs, &null))
132 return FALSE;
133 if (null == FALSE)
134 return (*proc)(xdrs, objp);
135 return TRUE;
137 case XDR_FREE:
138 if (*objp)
139 return (*proc)(xdrs, objp);
140 return TRUE;
143 return FALSE;
146 bool_t
147 xdr_krb5_timestamp(XDR *xdrs, krb5_timestamp *objp)
149 /* This assumes that int32 and krb5_timestamp are the same size.
150 This shouldn't be a problem, since we've got a unit test which
151 checks for this. */
152 if (!xdr_int(xdrs, (int32_t *) objp)) {
153 return (FALSE);
155 return (TRUE);
158 bool_t
159 xdr_krb5_kvno(XDR *xdrs, krb5_kvno *objp)
161 unsigned char tmp;
163 tmp = '\0'; /* for purify, else xdr_u_char performs a umr */
165 if (xdrs->x_op == XDR_ENCODE)
166 tmp = (unsigned char) *objp;
168 if (!xdr_u_char(xdrs, &tmp))
169 return (FALSE);
171 if (xdrs->x_op == XDR_DECODE)
172 *objp = (krb5_kvno) tmp;
174 return (TRUE);
177 bool_t
178 xdr_krb5_deltat(XDR *xdrs, krb5_deltat *objp)
180 /* This assumes that int32 and krb5_deltat are the same size.
181 This shouldn't be a problem, since we've got a unit test which
182 checks for this. */
183 if (!xdr_int(xdrs, (int32_t *) objp)) {
184 return (FALSE);
186 return (TRUE);
189 bool_t
190 xdr_krb5_flags(XDR *xdrs, krb5_flags *objp)
192 /* This assumes that int32 and krb5_flags are the same size.
193 This shouldn't be a problem, since we've got a unit test which
194 checks for this. */
195 if (!xdr_int(xdrs, (int32_t *) objp)) {
196 return (FALSE);
198 return (TRUE);
201 bool_t
202 xdr_krb5_ui_4(XDR *xdrs, krb5_ui_4 *objp)
204 if (!xdr_u_int(xdrs, (uint32_t *) objp)) {
205 return (FALSE);
207 return (TRUE);
210 bool_t
211 xdr_krb5_int16(XDR *xdrs, krb5_int16 *objp)
213 int tmp;
215 tmp = (int) *objp;
217 if (!xdr_int(xdrs, &tmp))
218 return(FALSE);
220 *objp = (krb5_int16) tmp;
222 return(TRUE);
226 * Function: xdr_krb5_ui_2
228 * Purpose: XDR function which serves as a wrapper for xdr_u_int,
229 * to prevent compiler warnings about type clashes between u_int
230 * and krb5_ui_2.
232 bool_t
233 xdr_krb5_ui_2(XDR *xdrs, krb5_ui_2 *objp)
235 unsigned int tmp;
237 tmp = (unsigned int) *objp;
239 if (!xdr_u_int(xdrs, &tmp))
240 return(FALSE);
242 *objp = (krb5_ui_2) tmp;
244 return(TRUE);
249 bool_t xdr_krb5_key_data_nocontents(XDR *xdrs, krb5_key_data *objp)
252 * Note that this function intentionally DOES NOT tranfer key
253 * length or contents! xdr_krb5_key_data in adb_xdr.c does, but
254 * that is only for use within the server-side library.
256 unsigned int tmp;
258 if (xdrs->x_op == XDR_DECODE)
259 memset((char *) objp, 0, sizeof(krb5_key_data));
261 if (!xdr_krb5_int16(xdrs, &objp->key_data_ver)) {
262 return (FALSE);
264 if (!xdr_krb5_int16(xdrs, &objp->key_data_kvno)) {
265 return (FALSE);
267 if (!xdr_krb5_int16(xdrs, &objp->key_data_type[0])) {
268 return (FALSE);
270 if (objp->key_data_ver > 1) {
271 if (!xdr_krb5_int16(xdrs, &objp->key_data_type[1])) {
272 return (FALSE);
276 * kadm5_get_principal on the server side allocates and returns
277 * key contents when asked. Even though this function refuses to
278 * transmit that data, it still has to *free* the data at the
279 * appropriate time to avoid a memory leak.
281 if (xdrs->x_op == XDR_FREE) {
282 tmp = (unsigned int) objp->key_data_length[0];
283 if (!xdr_bytes(xdrs, (char **) &objp->key_data_contents[0],
284 &tmp, ~0))
285 return FALSE;
287 tmp = (unsigned int) objp->key_data_length[1];
288 if (!xdr_bytes(xdrs, (char **) &objp->key_data_contents[1],
289 &tmp, ~0))
290 return FALSE;
293 return (TRUE);
297 bool_t
298 xdr_krb5_key_salt_tuple(XDR *xdrs, krb5_key_salt_tuple *objp)
300 if (!xdr_krb5_enctype(xdrs, &objp->ks_enctype))
301 return FALSE;
302 if (!xdr_krb5_salttype(xdrs, &objp->ks_salttype))
303 return FALSE;
304 return TRUE;
307 bool_t xdr_krb5_tl_data(XDR *xdrs, krb5_tl_data **tl_data_head)
309 krb5_tl_data *tl, *tl2;
310 bool_t more;
311 unsigned int len;
313 switch (xdrs->x_op) {
314 case XDR_FREE:
315 tl = tl2 = *tl_data_head;
316 while (tl) {
317 tl2 = tl->tl_data_next;
318 free(tl->tl_data_contents);
319 free(tl);
320 tl = tl2;
322 break;
324 case XDR_ENCODE:
325 tl = *tl_data_head;
326 while (1) {
327 more = (tl != NULL);
328 if (!xdr_bool(xdrs, &more))
329 return FALSE;
330 if (tl == NULL)
331 break;
332 if (!xdr_krb5_int16(xdrs, &tl->tl_data_type))
333 return FALSE;
334 len = tl->tl_data_length;
335 if (!xdr_bytes(xdrs, (char **) &tl->tl_data_contents, &len, ~0))
336 return FALSE;
337 tl = tl->tl_data_next;
339 break;
341 case XDR_DECODE:
342 tl = NULL;
343 while (1) {
344 if (!xdr_bool(xdrs, &more))
345 return FALSE;
346 if (more == FALSE)
347 break;
348 tl2 = (krb5_tl_data *) malloc(sizeof(krb5_tl_data));
349 if (tl2 == NULL)
350 return FALSE;
351 memset((char *) tl2, 0, sizeof(krb5_tl_data));
352 if (!xdr_krb5_int16(xdrs, &tl2->tl_data_type))
353 return FALSE;
354 if (!xdr_bytes(xdrs, (char **)&tl2->tl_data_contents, &len, ~0))
355 return FALSE;
356 tl2->tl_data_length = len;
358 tl2->tl_data_next = tl;
359 tl = tl2;
362 *tl_data_head = tl;
363 break;
366 return TRUE;
369 bool_t
370 xdr_kadm5_ret_t(XDR *xdrs, kadm5_ret_t *objp)
372 uint32_t tmp;
374 if (xdrs->x_op == XDR_ENCODE)
375 tmp = (uint32_t) *objp;
377 if (!xdr_u_int(xdrs, &tmp))
378 return (FALSE);
380 if (xdrs->x_op == XDR_DECODE)
381 *objp = (kadm5_ret_t) tmp;
383 return (TRUE);
386 bool_t xdr_kadm5_principal_ent_rec_v1(XDR *xdrs,
387 kadm5_principal_ent_rec *objp)
389 return _xdr_kadm5_principal_ent_rec(xdrs, objp, KADM5_API_VERSION_1);
392 bool_t xdr_kadm5_principal_ent_rec(XDR *xdrs,
393 kadm5_principal_ent_rec *objp)
395 return _xdr_kadm5_principal_ent_rec(xdrs, objp, KADM5_API_VERSION_2);
398 static bool_t
399 _xdr_kadm5_principal_ent_rec(XDR *xdrs, kadm5_principal_ent_rec *objp,
400 int v)
402 unsigned int n;
404 if (!xdr_krb5_principal(xdrs, &objp->principal)) {
405 return (FALSE);
407 if (!xdr_krb5_timestamp(xdrs, &objp->princ_expire_time)) {
408 return (FALSE);
410 if (!xdr_krb5_timestamp(xdrs, &objp->last_pwd_change)) {
411 return (FALSE);
413 if (!xdr_krb5_timestamp(xdrs, &objp->pw_expiration)) {
414 return (FALSE);
416 if (!xdr_krb5_deltat(xdrs, &objp->max_life)) {
417 return (FALSE);
419 if (v == KADM5_API_VERSION_1) {
420 if (!xdr_krb5_principal(xdrs, &objp->mod_name)) {
421 return (FALSE);
423 } else {
424 if (!xdr_nulltype(xdrs, (void **) &objp->mod_name,
425 xdr_krb5_principal)) {
426 return (FALSE);
429 if (!xdr_krb5_timestamp(xdrs, &objp->mod_date)) {
430 return (FALSE);
432 if (!xdr_krb5_flags(xdrs, &objp->attributes)) {
433 return (FALSE);
435 if (!xdr_krb5_kvno(xdrs, &objp->kvno)) {
436 return (FALSE);
438 if (!xdr_krb5_kvno(xdrs, &objp->mkvno)) {
439 return (FALSE);
441 if (!xdr_nullstring(xdrs, &objp->policy)) {
442 return (FALSE);
444 if (!xdr_long(xdrs, &objp->aux_attributes)) {
445 return (FALSE);
447 if (v != KADM5_API_VERSION_1) {
448 if (!xdr_krb5_deltat(xdrs, &objp->max_renewable_life)) {
449 return (FALSE);
451 if (!xdr_krb5_timestamp(xdrs, &objp->last_success)) {
452 return (FALSE);
454 if (!xdr_krb5_timestamp(xdrs, &objp->last_failed)) {
455 return (FALSE);
457 if (!xdr_krb5_kvno(xdrs, &objp->fail_auth_count)) {
458 return (FALSE);
460 if (!xdr_krb5_int16(xdrs, &objp->n_key_data)) {
461 return (FALSE);
463 if (!xdr_krb5_int16(xdrs, &objp->n_tl_data)) {
464 return (FALSE);
466 if (!xdr_nulltype(xdrs, (void **) &objp->tl_data,
467 xdr_krb5_tl_data)) {
468 return FALSE;
470 n = objp->n_key_data;
471 if (!xdr_array(xdrs, (caddr_t *) &objp->key_data,
472 &n, ~0, sizeof(krb5_key_data),
473 xdr_krb5_key_data_nocontents)) {
474 return (FALSE);
477 return (TRUE);
480 bool_t
481 xdr_kadm5_policy_ent_rec(XDR *xdrs, kadm5_policy_ent_rec *objp)
483 if (!xdr_nullstring(xdrs, &objp->policy)) {
484 return (FALSE);
486 /* these all used to be u_int32, but it's stupid for sized types
487 to be exposed at the api, and they're the same as longs on the
488 wire. */
489 if (!xdr_long(xdrs, &objp->pw_min_life)) {
490 return (FALSE);
492 if (!xdr_long(xdrs, &objp->pw_max_life)) {
493 return (FALSE);
495 if (!xdr_long(xdrs, &objp->pw_min_length)) {
496 return (FALSE);
498 if (!xdr_long(xdrs, &objp->pw_min_classes)) {
499 return (FALSE);
501 if (!xdr_long(xdrs, &objp->pw_history_num)) {
502 return (FALSE);
504 if (!xdr_long(xdrs, &objp->policy_refcnt)) {
505 return (FALSE);
507 return (TRUE);
510 bool_t
511 xdr_cprinc_arg(XDR *xdrs, cprinc_arg *objp)
513 if (!xdr_ui_4(xdrs, &objp->api_version)) {
514 return (FALSE);
516 if (objp->api_version == KADM5_API_VERSION_1) {
517 if (!xdr_kadm5_principal_ent_rec_v1(xdrs, &objp->rec)) {
518 return (FALSE);
520 } else {
521 if (!xdr_kadm5_principal_ent_rec(xdrs, &objp->rec)) {
522 return (FALSE);
525 if (!xdr_long(xdrs, &objp->mask)) {
526 return (FALSE);
528 if (!xdr_nullstring(xdrs, &objp->passwd)) {
529 return (FALSE);
531 return (TRUE);
534 bool_t
535 xdr_cprinc3_arg(XDR *xdrs, cprinc3_arg *objp)
537 if (!xdr_ui_4(xdrs, &objp->api_version)) {
538 return (FALSE);
540 if (objp->api_version == KADM5_API_VERSION_1) {
541 if (!xdr_kadm5_principal_ent_rec_v1(xdrs, &objp->rec)) {
542 return (FALSE);
544 } else {
545 if (!xdr_kadm5_principal_ent_rec(xdrs, &objp->rec)) {
546 return (FALSE);
549 if (!xdr_long(xdrs, &objp->mask)) {
550 return (FALSE);
552 if (!xdr_array(xdrs, (caddr_t *)&objp->ks_tuple,
553 (unsigned int *)&objp->n_ks_tuple, ~0,
554 sizeof(krb5_key_salt_tuple),
555 xdr_krb5_key_salt_tuple)) {
556 return (FALSE);
558 if (!xdr_nullstring(xdrs, &objp->passwd)) {
559 return (FALSE);
561 return (TRUE);
564 bool_t
565 xdr_generic_ret(XDR *xdrs, generic_ret *objp)
567 if (!xdr_ui_4(xdrs, &objp->api_version)) {
568 return (FALSE);
570 if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
571 return (FALSE);
574 return(TRUE);
577 bool_t
578 xdr_dprinc_arg(XDR *xdrs, dprinc_arg *objp)
580 if (!xdr_ui_4(xdrs, &objp->api_version)) {
581 return (FALSE);
583 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
584 return (FALSE);
586 return (TRUE);
589 bool_t
590 xdr_mprinc_arg(XDR *xdrs, mprinc_arg *objp)
592 if (!xdr_ui_4(xdrs, &objp->api_version)) {
593 return (FALSE);
595 if (objp->api_version == KADM5_API_VERSION_1) {
596 if (!xdr_kadm5_principal_ent_rec_v1(xdrs, &objp->rec)) {
597 return (FALSE);
599 } else {
600 if (!xdr_kadm5_principal_ent_rec(xdrs, &objp->rec)) {
601 return (FALSE);
604 if (!xdr_long(xdrs, &objp->mask)) {
605 return (FALSE);
607 return (TRUE);
610 bool_t
611 xdr_rprinc_arg(XDR *xdrs, rprinc_arg *objp)
613 if (!xdr_ui_4(xdrs, &objp->api_version)) {
614 return (FALSE);
616 if (!xdr_krb5_principal(xdrs, &objp->src)) {
617 return (FALSE);
619 if (!xdr_krb5_principal(xdrs, &objp->dest)) {
620 return (FALSE);
622 return (TRUE);
625 bool_t
626 xdr_gprincs_arg(XDR *xdrs, gprincs_arg *objp)
628 if (!xdr_ui_4(xdrs, &objp->api_version)) {
629 return (FALSE);
631 if (!xdr_nullstring(xdrs, &objp->exp)) {
632 return (FALSE);
634 return (TRUE);
637 bool_t
638 xdr_gprincs_ret(XDR *xdrs, gprincs_ret *objp)
640 if (!xdr_ui_4(xdrs, &objp->api_version)) {
641 return (FALSE);
643 if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
644 return (FALSE);
646 if (objp->code == KADM5_OK) {
647 if (!xdr_int(xdrs, &objp->count)) {
648 return (FALSE);
650 if (!xdr_array(xdrs, (caddr_t *) &objp->princs,
651 (unsigned int *) &objp->count, ~0,
652 sizeof(char *), xdr_nullstring)) {
653 return (FALSE);
657 return (TRUE);
660 bool_t
661 xdr_chpass_arg(XDR *xdrs, chpass_arg *objp)
663 if (!xdr_ui_4(xdrs, &objp->api_version)) {
664 return (FALSE);
666 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
667 return (FALSE);
669 if (!xdr_nullstring(xdrs, &objp->pass)) {
670 return (FALSE);
672 return (TRUE);
675 bool_t
676 xdr_chpass3_arg(XDR *xdrs, chpass3_arg *objp)
678 if (!xdr_ui_4(xdrs, &objp->api_version)) {
679 return (FALSE);
681 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
682 return (FALSE);
684 if (!xdr_bool(xdrs, (bool_t *) &objp->keepold)) { /* SUNWresync121 XXX */
685 return (FALSE);
687 if (!xdr_array(xdrs, (caddr_t *)&objp->ks_tuple,
688 (unsigned int*)&objp->n_ks_tuple, ~0,
689 sizeof(krb5_key_salt_tuple),
690 xdr_krb5_key_salt_tuple)) {
691 return (FALSE);
693 if (!xdr_nullstring(xdrs, &objp->pass)) {
694 return (FALSE);
696 return (TRUE);
699 bool_t
700 xdr_setv4key_arg(XDR *xdrs, setv4key_arg *objp)
702 unsigned int n_keys = 1;
704 if (!xdr_ui_4(xdrs, &objp->api_version)) {
705 return (FALSE);
707 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
708 return (FALSE);
710 if (!xdr_array(xdrs, (caddr_t *) &objp->keyblock,
711 &n_keys, ~0,
712 sizeof(krb5_keyblock), xdr_krb5_keyblock)) {
713 return (FALSE);
715 return (TRUE);
718 bool_t
719 xdr_setkey_arg(XDR *xdrs, setkey_arg *objp)
721 if (!xdr_ui_4(xdrs, &objp->api_version)) {
722 return (FALSE);
724 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
725 return (FALSE);
727 if (!xdr_array(xdrs, (caddr_t *) &objp->keyblocks,
728 (unsigned int *) &objp->n_keys, ~0,
729 sizeof(krb5_keyblock), xdr_krb5_keyblock)) {
730 return (FALSE);
732 return (TRUE);
735 bool_t
736 xdr_setkey3_arg(XDR *xdrs, setkey3_arg *objp)
738 if (!xdr_ui_4(xdrs, &objp->api_version)) {
739 return (FALSE);
741 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
742 return (FALSE);
744 if (!xdr_bool(xdrs, (bool_t *) &objp->keepold)) { /* SUNWresync121 XXX */
745 return (FALSE);
747 if (!xdr_array(xdrs, (caddr_t *) &objp->ks_tuple,
748 (unsigned int *) &objp->n_ks_tuple, ~0,
749 sizeof(krb5_key_salt_tuple), xdr_krb5_key_salt_tuple)) {
750 return (FALSE);
752 if (!xdr_array(xdrs, (caddr_t *) &objp->keyblocks,
753 (unsigned int *) &objp->n_keys, ~0,
754 sizeof(krb5_keyblock), xdr_krb5_keyblock)) {
755 return (FALSE);
757 return (TRUE);
760 bool_t
761 xdr_chrand_arg(XDR *xdrs, chrand_arg *objp)
763 if (!xdr_ui_4(xdrs, &objp->api_version)) {
764 return (FALSE);
766 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
767 return (FALSE);
769 return (TRUE);
772 bool_t
773 xdr_chrand3_arg(XDR *xdrs, chrand3_arg *objp)
775 if (!xdr_ui_4(xdrs, &objp->api_version)) {
776 return (FALSE);
778 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
779 return (FALSE);
781 if (!xdr_bool(xdrs, (bool_t *) &objp->keepold)) { /* SUNWresync121 XXX */
782 return (FALSE);
784 if (!xdr_array(xdrs, (caddr_t *)&objp->ks_tuple,
785 (unsigned int*)&objp->n_ks_tuple, ~0,
786 sizeof(krb5_key_salt_tuple),
787 xdr_krb5_key_salt_tuple)) {
788 return (FALSE);
790 return (TRUE);
793 bool_t
794 xdr_chrand_ret(XDR *xdrs, chrand_ret *objp)
796 if (!xdr_ui_4(xdrs, &objp->api_version)) {
797 return (FALSE);
799 if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
800 return (FALSE);
802 if (objp->api_version == KADM5_API_VERSION_1) {
803 if(objp->code == KADM5_OK) {
804 if (!xdr_krb5_keyblock(xdrs, &objp->key)) {
805 return (FALSE);
808 } else {
809 if (objp->code == KADM5_OK) {
810 if (!xdr_array(xdrs, (char **)&objp->keys, (unsigned int *)&objp->n_keys, ~0,
811 sizeof(krb5_keyblock),
812 xdr_krb5_keyblock))
813 return FALSE;
817 return (TRUE);
820 bool_t
821 xdr_gprinc_arg(XDR *xdrs, gprinc_arg *objp)
823 if (!xdr_ui_4(xdrs, &objp->api_version)) {
824 return (FALSE);
826 if (!xdr_krb5_principal(xdrs, &objp->princ)) {
827 return (FALSE);
829 if ((objp->api_version > KADM5_API_VERSION_1) &&
830 !xdr_long(xdrs, &objp->mask)) {
831 return FALSE;
834 return (TRUE);
837 bool_t
838 xdr_gprinc_ret(XDR *xdrs, gprinc_ret *objp)
840 if (!xdr_ui_4(xdrs, &objp->api_version)) {
841 return (FALSE);
843 if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
844 return (FALSE);
846 if(objp->code == KADM5_OK) {
847 if (objp->api_version == KADM5_API_VERSION_1) {
848 if (!xdr_kadm5_principal_ent_rec_v1(xdrs, &objp->rec)) {
849 return (FALSE);
851 } else {
852 if (!xdr_kadm5_principal_ent_rec(xdrs, &objp->rec)) {
853 return (FALSE);
858 return (TRUE);
861 bool_t
862 xdr_cpol_arg(XDR *xdrs, cpol_arg *objp)
864 if (!xdr_ui_4(xdrs, &objp->api_version)) {
865 return (FALSE);
867 if (!xdr_kadm5_policy_ent_rec(xdrs, &objp->rec)) {
868 return (FALSE);
870 if (!xdr_long(xdrs, &objp->mask)) {
871 return (FALSE);
873 return (TRUE);
876 bool_t
877 xdr_dpol_arg(XDR *xdrs, dpol_arg *objp)
879 if (!xdr_ui_4(xdrs, &objp->api_version)) {
880 return (FALSE);
882 if (!xdr_nullstring(xdrs, &objp->name)) {
883 return (FALSE);
885 return (TRUE);
888 bool_t
889 xdr_mpol_arg(XDR *xdrs, mpol_arg *objp)
891 if (!xdr_ui_4(xdrs, &objp->api_version)) {
892 return (FALSE);
894 if (!xdr_kadm5_policy_ent_rec(xdrs, &objp->rec)) {
895 return (FALSE);
897 if (!xdr_long(xdrs, &objp->mask)) {
898 return (FALSE);
900 return (TRUE);
903 bool_t
904 xdr_gpol_arg(XDR *xdrs, gpol_arg *objp)
906 if (!xdr_ui_4(xdrs, &objp->api_version)) {
907 return (FALSE);
909 if (!xdr_nullstring(xdrs, &objp->name)) {
910 return (FALSE);
912 return (TRUE);
915 bool_t
916 xdr_gpol_ret(XDR *xdrs, gpol_ret *objp)
918 if (!xdr_ui_4(xdrs, &objp->api_version)) {
919 return (FALSE);
921 if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
922 return (FALSE);
924 if(objp->code == KADM5_OK) {
925 if (!xdr_kadm5_policy_ent_rec(xdrs, &objp->rec))
926 return (FALSE);
929 return (TRUE);
932 bool_t
933 xdr_gpols_arg(XDR *xdrs, gpols_arg *objp)
935 if (!xdr_ui_4(xdrs, &objp->api_version)) {
936 return (FALSE);
938 if (!xdr_nullstring(xdrs, &objp->exp)) {
939 return (FALSE);
941 return (TRUE);
944 bool_t
945 xdr_gpols_ret(XDR *xdrs, gpols_ret *objp)
947 if (!xdr_ui_4(xdrs, &objp->api_version)) {
948 return (FALSE);
950 if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
951 return (FALSE);
953 if (objp->code == KADM5_OK) {
954 if (!xdr_int(xdrs, &objp->count)) {
955 return (FALSE);
957 if (!xdr_array(xdrs, (caddr_t *) &objp->pols,
958 (unsigned int *) &objp->count, ~0,
959 sizeof(char *), xdr_nullstring)) {
960 return (FALSE);
964 return (TRUE);
967 bool_t xdr_getprivs_ret(XDR *xdrs, getprivs_ret *objp)
969 if (!xdr_ui_4(xdrs, &objp->api_version)) {
970 return (FALSE);
972 if (! xdr_kadm5_ret_t(xdrs, &objp->code) ||
973 ! xdr_long(xdrs, &objp->privs))
974 return FALSE;
976 return TRUE;
979 bool_t
980 xdr_krb5_principal(XDR *xdrs, krb5_principal *objp)
982 int ret;
983 char *p = NULL;
984 krb5_principal pr = NULL;
985 static krb5_context context = NULL;
987 /* using a static context here is ugly, but should work
988 ok, and the other solutions are even uglier */
990 if (!context &&
991 kadm5_init_krb5_context(&context))
992 return(FALSE);
994 switch(xdrs->x_op) {
995 case XDR_ENCODE:
996 if (*objp) {
997 if((ret = krb5_unparse_name(context, *objp, &p)) != 0)
998 return FALSE;
1000 if(!xdr_nullstring(xdrs, &p))
1001 return FALSE;
1002 free(p);
1003 break;
1004 case XDR_DECODE:
1005 if(!xdr_nullstring(xdrs, &p))
1006 return FALSE;
1007 if (p) {
1008 ret = krb5_parse_name(context, p, &pr);
1009 if(ret != 0)
1010 return FALSE;
1011 *objp = pr;
1012 free(p);
1013 } else
1014 *objp = NULL;
1015 break;
1016 case XDR_FREE:
1017 if(*objp != NULL)
1018 krb5_free_principal(context, *objp);
1019 break;
1021 return TRUE;
1024 bool_t
1025 xdr_krb5_octet(XDR *xdrs, krb5_octet *objp)
1027 if (!xdr_u_char(xdrs, objp))
1028 return (FALSE);
1029 return (TRUE);
1032 bool_t
1033 xdr_krb5_enctype(XDR *xdrs, krb5_enctype *objp)
1036 * This used to be xdr_krb5_keytype, but keytypes and enctypes have
1037 * been merged into only enctypes. However, randkey_principal
1038 * already ensures that only a key of ENCTYPE_DES_CBC_CRC will be
1039 * returned to v1 clients, and ENCTYPE_DES_CBC_CRC has the same
1040 * value as KEYTYPE_DES used too, which is what all v1 clients
1041 * expect. Therefore, IMHO, just encoding whatever enctype we get
1042 * is safe.
1045 if (!xdr_u_int(xdrs, (unsigned int *) objp))
1046 return (FALSE);
1047 return (TRUE);
1050 bool_t
1051 xdr_krb5_salttype(XDR *xdrs, krb5_int32 *objp)
1053 if (!xdr_int(xdrs, (int32_t *) objp))
1054 return FALSE;
1055 return TRUE;
1058 bool_t
1059 xdr_krb5_keyblock(XDR *xdrs, krb5_keyblock *objp)
1061 /* XXX This only works because free_keyblock assumes ->contents
1062 is allocated by malloc() */
1064 if(!xdr_krb5_enctype(xdrs, &objp->enctype))
1065 return FALSE;
1066 if(!xdr_bytes(xdrs, (char **) &objp->contents, (unsigned int *)
1067 &objp->length, ~0))
1068 return FALSE;
1069 return TRUE;