xref: /onnv-gate/usr/src/lib/krb5/kadm5/kadm_rpc_xdr.c (revision 7934:6aeeafc994de)
10Sstevel@tonic-gate /*
2*7934SMark.Phalan@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate 
70Sstevel@tonic-gate /*
80Sstevel@tonic-gate  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
90Sstevel@tonic-gate  *
100Sstevel@tonic-gate  *	Openvision retains the copyright to derivative works of
110Sstevel@tonic-gate  *	this source code.  Do *NOT* create a derivative of this
120Sstevel@tonic-gate  *	source code before consulting with your legal department.
130Sstevel@tonic-gate  *	Do *NOT* integrate *ANY* of this source code into another
140Sstevel@tonic-gate  *	product before consulting with your legal department.
150Sstevel@tonic-gate  *
160Sstevel@tonic-gate  *	For further information, read the top-level Openvision
170Sstevel@tonic-gate  *	copyright which is contained in the top-level MIT Kerberos
180Sstevel@tonic-gate  *	copyright.
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
210Sstevel@tonic-gate  *
220Sstevel@tonic-gate  */
230Sstevel@tonic-gate 
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate  * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <rpc/rpc.h>
30*7934SMark.Phalan@Sun.COM #include <errno.h>
310Sstevel@tonic-gate #include <kadm5/admin.h>
320Sstevel@tonic-gate #include <kadm5/kadm_rpc.h>
33*7934SMark.Phalan@Sun.COM #include <krb5.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate static bool_t
380Sstevel@tonic-gate _xdr_kadm5_principal_ent_rec(XDR *xdrs, kadm5_principal_ent_rec *objp,
390Sstevel@tonic-gate 			     int v);
400Sstevel@tonic-gate 
410Sstevel@tonic-gate bool_t
420Sstevel@tonic-gate xdr_krb5_salttype(XDR *xdrs, krb5_int32 *objp); /* SUNWresync121 XXX */
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * Function: xdr_ui_4
450Sstevel@tonic-gate  *
460Sstevel@tonic-gate  * Purpose: XDR function which serves as a wrapper for xdr_u_int,
470Sstevel@tonic-gate  * to prevent compiler warnings about type clashes between u_int32
480Sstevel@tonic-gate  * and krb5_ui_4.
490Sstevel@tonic-gate  */
xdr_ui_4(XDR * xdrs,krb5_ui_4 * objp)500Sstevel@tonic-gate bool_t xdr_ui_4(XDR *xdrs, krb5_ui_4 *objp)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate   /* Assumes that krb5_ui_4 and u_int32 are both four bytes long.
530Sstevel@tonic-gate      This should not be a harmful assumption. */
542881Smp153739   return xdr_u_int(xdrs, (uint32_t *) objp);
550Sstevel@tonic-gate }
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * Function: xdr_nullstring
600Sstevel@tonic-gate  *
610Sstevel@tonic-gate  * Purpose: XDR function for "strings" that are either NULL-terminated
620Sstevel@tonic-gate  * or NULL.
630Sstevel@tonic-gate  */
xdr_nullstring(XDR * xdrs,char ** objp)640Sstevel@tonic-gate bool_t xdr_nullstring(XDR *xdrs, char **objp)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate      u_int size;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate      if (xdrs->x_op == XDR_ENCODE) {
690Sstevel@tonic-gate 	  if (*objp == NULL)
700Sstevel@tonic-gate 	       size = 0;
710Sstevel@tonic-gate 	  else
720Sstevel@tonic-gate 	       size = strlen(*objp) + 1;
730Sstevel@tonic-gate      }
740Sstevel@tonic-gate      if (! xdr_u_int(xdrs, &size)) {
750Sstevel@tonic-gate 	  return FALSE;
760Sstevel@tonic-gate 	}
770Sstevel@tonic-gate      switch (xdrs->x_op) {
780Sstevel@tonic-gate      case XDR_DECODE:
790Sstevel@tonic-gate 	  if (size == 0) {
800Sstevel@tonic-gate 	       *objp = NULL;
810Sstevel@tonic-gate 	       return TRUE;
820Sstevel@tonic-gate 	  } else if (*objp == NULL) {
830Sstevel@tonic-gate 	       *objp = (char *) mem_alloc(size);
840Sstevel@tonic-gate 	       if (*objp == NULL) {
850Sstevel@tonic-gate 		    errno = ENOMEM;
860Sstevel@tonic-gate 		    return FALSE;
870Sstevel@tonic-gate 	       }
880Sstevel@tonic-gate 	  }
890Sstevel@tonic-gate 	  return (xdr_opaque(xdrs, *objp, size));
900Sstevel@tonic-gate 
910Sstevel@tonic-gate      case XDR_ENCODE:
920Sstevel@tonic-gate 	  if (size != 0)
930Sstevel@tonic-gate 	       return (xdr_opaque(xdrs, *objp, size));
940Sstevel@tonic-gate 	  return TRUE;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate      case XDR_FREE:
970Sstevel@tonic-gate 	  if (*objp != NULL)
980Sstevel@tonic-gate 	       mem_free(*objp, size);
990Sstevel@tonic-gate 	  *objp = NULL;
1000Sstevel@tonic-gate 	  return TRUE;
1010Sstevel@tonic-gate      }
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate      return FALSE;
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate /*
1070Sstevel@tonic-gate  * Function: xdr_nulltype
1080Sstevel@tonic-gate  *
1090Sstevel@tonic-gate  * Purpose: XDR function for arbitrary pointer types that are either
1100Sstevel@tonic-gate  * NULL or contain data.
1110Sstevel@tonic-gate  */
xdr_nulltype(XDR * xdrs,void ** objp,xdrproc_t proc)1120Sstevel@tonic-gate bool_t xdr_nulltype(XDR *xdrs, void **objp, xdrproc_t proc)
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate      bool_t null;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate      switch (xdrs->x_op) {
1170Sstevel@tonic-gate      case XDR_DECODE:
1180Sstevel@tonic-gate 	  if (!xdr_bool(xdrs, &null))
1190Sstevel@tonic-gate 	      return FALSE;
1200Sstevel@tonic-gate 	  if (null) {
1210Sstevel@tonic-gate 	       *objp = NULL;
1220Sstevel@tonic-gate 	       return TRUE;
1230Sstevel@tonic-gate 	  }
1240Sstevel@tonic-gate 	  return (*proc)(xdrs, objp);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate      case XDR_ENCODE:
1270Sstevel@tonic-gate 	  if (*objp == NULL)
1280Sstevel@tonic-gate 	       null = TRUE;
1290Sstevel@tonic-gate 	  else
1300Sstevel@tonic-gate 	       null = FALSE;
1310Sstevel@tonic-gate 	  if (!xdr_bool(xdrs, &null))
1320Sstevel@tonic-gate 	       return FALSE;
1330Sstevel@tonic-gate 	  if (null == FALSE)
1340Sstevel@tonic-gate 	       return (*proc)(xdrs, objp);
1350Sstevel@tonic-gate 	  return TRUE;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate      case XDR_FREE:
1380Sstevel@tonic-gate 	  if (*objp)
1390Sstevel@tonic-gate 	       return (*proc)(xdrs, objp);
1400Sstevel@tonic-gate 	  return TRUE;
1410Sstevel@tonic-gate      }
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate      return FALSE;
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate bool_t
xdr_krb5_timestamp(XDR * xdrs,krb5_timestamp * objp)1470Sstevel@tonic-gate xdr_krb5_timestamp(XDR *xdrs, krb5_timestamp *objp)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate   /* This assumes that int32 and krb5_timestamp are the same size.
1500Sstevel@tonic-gate      This shouldn't be a problem, since we've got a unit test which
1510Sstevel@tonic-gate      checks for this. */
1522881Smp153739 	if (!xdr_int(xdrs, (int32_t *) objp)) {
1530Sstevel@tonic-gate 		return (FALSE);
1540Sstevel@tonic-gate 	}
1550Sstevel@tonic-gate 	return (TRUE);
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate bool_t
xdr_krb5_kvno(XDR * xdrs,krb5_kvno * objp)1590Sstevel@tonic-gate xdr_krb5_kvno(XDR *xdrs, krb5_kvno *objp)
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate 	unsigned char tmp;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	tmp = '\0'; /* for purify, else xdr_u_char performs a umr */
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE)
1660Sstevel@tonic-gate 		tmp = (unsigned char) *objp;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	if (!xdr_u_char(xdrs, &tmp))
1690Sstevel@tonic-gate 		return (FALSE);
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE)
1720Sstevel@tonic-gate 		*objp = (krb5_kvno) tmp;
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	return (TRUE);
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate bool_t
xdr_krb5_deltat(XDR * xdrs,krb5_deltat * objp)1780Sstevel@tonic-gate xdr_krb5_deltat(XDR *xdrs, krb5_deltat *objp)
1790Sstevel@tonic-gate {
1800Sstevel@tonic-gate   /* This assumes that int32 and krb5_deltat are the same size.
1810Sstevel@tonic-gate      This shouldn't be a problem, since we've got a unit test which
1820Sstevel@tonic-gate      checks for this. */
1832881Smp153739 	if (!xdr_int(xdrs, (int32_t *) objp)) {
1840Sstevel@tonic-gate 		return (FALSE);
1850Sstevel@tonic-gate 	}
1860Sstevel@tonic-gate 	return (TRUE);
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate bool_t
xdr_krb5_flags(XDR * xdrs,krb5_flags * objp)1900Sstevel@tonic-gate xdr_krb5_flags(XDR *xdrs, krb5_flags *objp)
1910Sstevel@tonic-gate {
1920Sstevel@tonic-gate   /* This assumes that int32 and krb5_flags are the same size.
1930Sstevel@tonic-gate      This shouldn't be a problem, since we've got a unit test which
1940Sstevel@tonic-gate      checks for this. */
1952881Smp153739 	if (!xdr_int(xdrs, (int32_t *) objp)) {
1960Sstevel@tonic-gate 		return (FALSE);
1970Sstevel@tonic-gate 	}
1980Sstevel@tonic-gate 	return (TRUE);
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate bool_t
xdr_krb5_ui_4(XDR * xdrs,krb5_ui_4 * objp)2020Sstevel@tonic-gate xdr_krb5_ui_4(XDR *xdrs, krb5_ui_4 *objp)
2030Sstevel@tonic-gate {
2042881Smp153739 	if (!xdr_u_int(xdrs, (uint32_t *) objp)) {
2050Sstevel@tonic-gate 		return (FALSE);
2060Sstevel@tonic-gate 	}
2070Sstevel@tonic-gate 	return (TRUE);
2080Sstevel@tonic-gate }
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate bool_t
xdr_krb5_int16(XDR * xdrs,krb5_int16 * objp)2110Sstevel@tonic-gate xdr_krb5_int16(XDR *xdrs, krb5_int16 *objp)
2120Sstevel@tonic-gate {
2130Sstevel@tonic-gate     int tmp;
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate     tmp = (int) *objp;
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate     if (!xdr_int(xdrs, &tmp))
2180Sstevel@tonic-gate 	return(FALSE);
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate     *objp = (krb5_int16) tmp;
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate     return(TRUE);
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate 
2252881Smp153739 /*
2262881Smp153739  * Function: xdr_krb5_ui_2
2272881Smp153739  *
2282881Smp153739  * Purpose: XDR function which serves as a wrapper for xdr_u_int,
2292881Smp153739  * to prevent compiler warnings about type clashes between u_int
2302881Smp153739  * and krb5_ui_2.
2312881Smp153739  */
2322881Smp153739 bool_t
xdr_krb5_ui_2(XDR * xdrs,krb5_ui_2 * objp)2332881Smp153739 xdr_krb5_ui_2(XDR *xdrs, krb5_ui_2 *objp)
2342881Smp153739 {
2352881Smp153739     unsigned int tmp;
2362881Smp153739 
2372881Smp153739     tmp = (unsigned int) *objp;
2382881Smp153739 
2392881Smp153739     if (!xdr_u_int(xdrs, &tmp))
2402881Smp153739 	return(FALSE);
2412881Smp153739 
2422881Smp153739     *objp = (krb5_ui_2) tmp;
2432881Smp153739 
2442881Smp153739     return(TRUE);
2452881Smp153739 }
2462881Smp153739 
2472881Smp153739 
2482881Smp153739 
xdr_krb5_key_data_nocontents(XDR * xdrs,krb5_key_data * objp)2490Sstevel@tonic-gate bool_t xdr_krb5_key_data_nocontents(XDR *xdrs, krb5_key_data *objp)
2500Sstevel@tonic-gate {
2510Sstevel@tonic-gate      /*
2520Sstevel@tonic-gate       * Note that this function intentionally DOES NOT tranfer key
2530Sstevel@tonic-gate       * length or contents!  xdr_krb5_key_data in adb_xdr.c does, but
2540Sstevel@tonic-gate       * that is only for use within the server-side library.
2550Sstevel@tonic-gate       */
2560Sstevel@tonic-gate      unsigned int tmp;
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate      if (xdrs->x_op == XDR_DECODE)
2590Sstevel@tonic-gate 	  memset((char *) objp, 0, sizeof(krb5_key_data));
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate      if (!xdr_krb5_int16(xdrs, &objp->key_data_ver)) {
2620Sstevel@tonic-gate 	  return (FALSE);
2630Sstevel@tonic-gate      }
2640Sstevel@tonic-gate      if (!xdr_krb5_int16(xdrs, &objp->key_data_kvno)) {
2650Sstevel@tonic-gate 	  return (FALSE);
2660Sstevel@tonic-gate      }
2670Sstevel@tonic-gate      if (!xdr_krb5_int16(xdrs, &objp->key_data_type[0])) {
2680Sstevel@tonic-gate 	  return (FALSE);
2690Sstevel@tonic-gate      }
2700Sstevel@tonic-gate      if (objp->key_data_ver > 1) {
2710Sstevel@tonic-gate 	  if (!xdr_krb5_int16(xdrs, &objp->key_data_type[1])) {
2720Sstevel@tonic-gate 	       return (FALSE);
2730Sstevel@tonic-gate 	  }
2740Sstevel@tonic-gate      }
2750Sstevel@tonic-gate      /*
2760Sstevel@tonic-gate       * kadm5_get_principal on the server side allocates and returns
2770Sstevel@tonic-gate       * key contents when asked.  Even though this function refuses to
2780Sstevel@tonic-gate       * transmit that data, it still has to *free* the data at the
2790Sstevel@tonic-gate       * appropriate time to avoid a memory leak.
2800Sstevel@tonic-gate       */
2810Sstevel@tonic-gate      if (xdrs->x_op == XDR_FREE) {
2820Sstevel@tonic-gate 	  tmp = (unsigned int) objp->key_data_length[0];
2830Sstevel@tonic-gate 	  if (!xdr_bytes(xdrs, (char **) &objp->key_data_contents[0],
2840Sstevel@tonic-gate 			 &tmp, ~0))
2850Sstevel@tonic-gate 	       return FALSE;
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 	  tmp = (unsigned int) objp->key_data_length[1];
2880Sstevel@tonic-gate 	  if (!xdr_bytes(xdrs, (char **) &objp->key_data_contents[1],
2890Sstevel@tonic-gate 			 &tmp, ~0))
2900Sstevel@tonic-gate 	       return FALSE;
2910Sstevel@tonic-gate      }
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate      return (TRUE);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate bool_t
xdr_krb5_key_salt_tuple(XDR * xdrs,krb5_key_salt_tuple * objp)2980Sstevel@tonic-gate xdr_krb5_key_salt_tuple(XDR *xdrs, krb5_key_salt_tuple *objp)
2990Sstevel@tonic-gate {
3000Sstevel@tonic-gate     if (!xdr_krb5_enctype(xdrs, &objp->ks_enctype))
3010Sstevel@tonic-gate 	return FALSE;
3020Sstevel@tonic-gate     if (!xdr_krb5_salttype(xdrs, &objp->ks_salttype))
3030Sstevel@tonic-gate 	return FALSE;
3040Sstevel@tonic-gate     return TRUE;
3050Sstevel@tonic-gate }
3060Sstevel@tonic-gate 
xdr_krb5_tl_data(XDR * xdrs,krb5_tl_data ** tl_data_head)3070Sstevel@tonic-gate bool_t xdr_krb5_tl_data(XDR *xdrs, krb5_tl_data **tl_data_head)
3080Sstevel@tonic-gate {
3090Sstevel@tonic-gate      krb5_tl_data *tl, *tl2;
3100Sstevel@tonic-gate      bool_t more;
3112881Smp153739      unsigned int len;
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate      switch (xdrs->x_op) {
3140Sstevel@tonic-gate      case XDR_FREE:
3150Sstevel@tonic-gate 	  tl = tl2 = *tl_data_head;
3160Sstevel@tonic-gate 	  while (tl) {
3170Sstevel@tonic-gate 	       tl2 = tl->tl_data_next;
3180Sstevel@tonic-gate 	       free(tl->tl_data_contents);
3190Sstevel@tonic-gate 	       free(tl);
3200Sstevel@tonic-gate 	       tl = tl2;
3210Sstevel@tonic-gate 	  }
3220Sstevel@tonic-gate 	  break;
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate      case XDR_ENCODE:
3250Sstevel@tonic-gate 	  tl = *tl_data_head;
3260Sstevel@tonic-gate 	  while (1) {
3270Sstevel@tonic-gate 	       more = (tl != NULL);
3280Sstevel@tonic-gate 	       if (!xdr_bool(xdrs, &more))
3290Sstevel@tonic-gate 		    return FALSE;
3300Sstevel@tonic-gate 	       if (tl == NULL)
3310Sstevel@tonic-gate 		    break;
3320Sstevel@tonic-gate 	       if (!xdr_krb5_int16(xdrs, &tl->tl_data_type))
3330Sstevel@tonic-gate 		    return FALSE;
3340Sstevel@tonic-gate 	       len = tl->tl_data_length;
3350Sstevel@tonic-gate 	       if (!xdr_bytes(xdrs, (char **) &tl->tl_data_contents, &len, ~0))
3360Sstevel@tonic-gate 		    return FALSE;
3370Sstevel@tonic-gate 	       tl = tl->tl_data_next;
3380Sstevel@tonic-gate 	  }
3390Sstevel@tonic-gate 	  break;
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate      case XDR_DECODE:
3420Sstevel@tonic-gate 	  tl = NULL;
3430Sstevel@tonic-gate 	  while (1) {
3440Sstevel@tonic-gate 	       if (!xdr_bool(xdrs, &more))
3450Sstevel@tonic-gate 		    return FALSE;
3460Sstevel@tonic-gate 	       if (more == FALSE)
3470Sstevel@tonic-gate 		    break;
3480Sstevel@tonic-gate 	       tl2 = (krb5_tl_data *) malloc(sizeof(krb5_tl_data));
3490Sstevel@tonic-gate 	       if (tl2 == NULL)
3500Sstevel@tonic-gate 		    return FALSE;
3510Sstevel@tonic-gate 	       memset((char *) tl2, 0, sizeof(krb5_tl_data));
3520Sstevel@tonic-gate 	       if (!xdr_krb5_int16(xdrs, &tl2->tl_data_type))
3530Sstevel@tonic-gate 		    return FALSE;
3540Sstevel@tonic-gate 	       if (!xdr_bytes(xdrs, (char **)&tl2->tl_data_contents, &len, ~0))
3550Sstevel@tonic-gate 		    return FALSE;
3560Sstevel@tonic-gate 	       tl2->tl_data_length = len;
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 	       tl2->tl_data_next = tl;
3590Sstevel@tonic-gate 	       tl = tl2;
3600Sstevel@tonic-gate 	  }
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate 	  *tl_data_head = tl;
3630Sstevel@tonic-gate 	  break;
3640Sstevel@tonic-gate      }
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate      return TRUE;
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate bool_t
xdr_kadm5_ret_t(XDR * xdrs,kadm5_ret_t * objp)3700Sstevel@tonic-gate xdr_kadm5_ret_t(XDR *xdrs, kadm5_ret_t *objp)
3710Sstevel@tonic-gate {
3722881Smp153739 	uint32_t tmp;
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE)
3752881Smp153739 		tmp = (uint32_t) *objp;
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &tmp))
3780Sstevel@tonic-gate 		return (FALSE);
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE)
3810Sstevel@tonic-gate 		*objp = (kadm5_ret_t) tmp;
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 	return (TRUE);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate 
xdr_kadm5_principal_ent_rec_v1(XDR * xdrs,kadm5_principal_ent_rec * objp)3860Sstevel@tonic-gate bool_t xdr_kadm5_principal_ent_rec_v1(XDR *xdrs,
3870Sstevel@tonic-gate 				      kadm5_principal_ent_rec *objp)
3880Sstevel@tonic-gate {
3890Sstevel@tonic-gate      return _xdr_kadm5_principal_ent_rec(xdrs, objp, KADM5_API_VERSION_1);
3900Sstevel@tonic-gate }
3910Sstevel@tonic-gate 
xdr_kadm5_principal_ent_rec(XDR * xdrs,kadm5_principal_ent_rec * objp)3920Sstevel@tonic-gate bool_t xdr_kadm5_principal_ent_rec(XDR *xdrs,
3930Sstevel@tonic-gate 				   kadm5_principal_ent_rec *objp)
3940Sstevel@tonic-gate {
3950Sstevel@tonic-gate      return _xdr_kadm5_principal_ent_rec(xdrs, objp, KADM5_API_VERSION_2);
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate static bool_t
_xdr_kadm5_principal_ent_rec(XDR * xdrs,kadm5_principal_ent_rec * objp,int v)3990Sstevel@tonic-gate _xdr_kadm5_principal_ent_rec(XDR *xdrs, kadm5_principal_ent_rec *objp,
4000Sstevel@tonic-gate 			     int v)
4010Sstevel@tonic-gate {
4020Sstevel@tonic-gate      unsigned int n;
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->principal)) {
4050Sstevel@tonic-gate 		return (FALSE);
4060Sstevel@tonic-gate 	}
4070Sstevel@tonic-gate 	if (!xdr_krb5_timestamp(xdrs, &objp->princ_expire_time)) {
4080Sstevel@tonic-gate 		return (FALSE);
4090Sstevel@tonic-gate 	}
4100Sstevel@tonic-gate 	if (!xdr_krb5_timestamp(xdrs, &objp->last_pwd_change)) {
4110Sstevel@tonic-gate 		return (FALSE);
4120Sstevel@tonic-gate 	}
4130Sstevel@tonic-gate 	if (!xdr_krb5_timestamp(xdrs, &objp->pw_expiration)) {
4140Sstevel@tonic-gate 		return (FALSE);
4150Sstevel@tonic-gate 	}
4160Sstevel@tonic-gate 	if (!xdr_krb5_deltat(xdrs, &objp->max_life)) {
4170Sstevel@tonic-gate 		return (FALSE);
4180Sstevel@tonic-gate 	}
4190Sstevel@tonic-gate         if (v == KADM5_API_VERSION_1) {
4200Sstevel@tonic-gate 	     if (!xdr_krb5_principal(xdrs, &objp->mod_name)) {
4210Sstevel@tonic-gate 		  return (FALSE);
4220Sstevel@tonic-gate 	     }
4230Sstevel@tonic-gate 	} else {
4240Sstevel@tonic-gate 	     if (!xdr_nulltype(xdrs, (void **) &objp->mod_name,
4250Sstevel@tonic-gate 			       xdr_krb5_principal)) {
4260Sstevel@tonic-gate 		  return (FALSE);
4270Sstevel@tonic-gate 	     }
4280Sstevel@tonic-gate 	}
4290Sstevel@tonic-gate 	if (!xdr_krb5_timestamp(xdrs, &objp->mod_date)) {
4300Sstevel@tonic-gate 		return (FALSE);
4310Sstevel@tonic-gate 	}
4320Sstevel@tonic-gate 	if (!xdr_krb5_flags(xdrs, &objp->attributes)) {
4330Sstevel@tonic-gate 		return (FALSE);
4340Sstevel@tonic-gate 	}
4350Sstevel@tonic-gate 	if (!xdr_krb5_kvno(xdrs, &objp->kvno)) {
4360Sstevel@tonic-gate 		return (FALSE);
4370Sstevel@tonic-gate 	}
4380Sstevel@tonic-gate 	if (!xdr_krb5_kvno(xdrs, &objp->mkvno)) {
4390Sstevel@tonic-gate 		return (FALSE);
4400Sstevel@tonic-gate 	}
4410Sstevel@tonic-gate 	if (!xdr_nullstring(xdrs, &objp->policy)) {
4420Sstevel@tonic-gate 		return (FALSE);
4430Sstevel@tonic-gate 	}
4440Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->aux_attributes)) {
4450Sstevel@tonic-gate 		return (FALSE);
4460Sstevel@tonic-gate 	}
4470Sstevel@tonic-gate 	if (v != KADM5_API_VERSION_1) {
4480Sstevel@tonic-gate 	     if (!xdr_krb5_deltat(xdrs, &objp->max_renewable_life)) {
4490Sstevel@tonic-gate 		  return (FALSE);
4500Sstevel@tonic-gate 	     }
4510Sstevel@tonic-gate 	     if (!xdr_krb5_timestamp(xdrs, &objp->last_success)) {
4520Sstevel@tonic-gate 		  return (FALSE);
4530Sstevel@tonic-gate 	     }
4540Sstevel@tonic-gate 	     if (!xdr_krb5_timestamp(xdrs, &objp->last_failed)) {
4550Sstevel@tonic-gate 		  return (FALSE);
4560Sstevel@tonic-gate 	     }
4570Sstevel@tonic-gate 	     if (!xdr_krb5_kvno(xdrs, &objp->fail_auth_count)) {
4580Sstevel@tonic-gate 		  return (FALSE);
4590Sstevel@tonic-gate 	     }
4600Sstevel@tonic-gate 	     if (!xdr_krb5_int16(xdrs, &objp->n_key_data)) {
4610Sstevel@tonic-gate 		  return (FALSE);
4620Sstevel@tonic-gate 	     }
4630Sstevel@tonic-gate 	     if (!xdr_krb5_int16(xdrs, &objp->n_tl_data)) {
4640Sstevel@tonic-gate 		  return (FALSE);
4650Sstevel@tonic-gate 	     }
4660Sstevel@tonic-gate 	     if (!xdr_nulltype(xdrs, (void **) &objp->tl_data,
4670Sstevel@tonic-gate 			       xdr_krb5_tl_data)) {
4680Sstevel@tonic-gate 		  return FALSE;
4690Sstevel@tonic-gate 	     }
4700Sstevel@tonic-gate 	     n = objp->n_key_data;
4710Sstevel@tonic-gate 	     if (!xdr_array(xdrs, (caddr_t *) &objp->key_data,
4720Sstevel@tonic-gate 			    &n, ~0, sizeof(krb5_key_data),
4730Sstevel@tonic-gate 			    xdr_krb5_key_data_nocontents)) {
4740Sstevel@tonic-gate 		  return (FALSE);
4750Sstevel@tonic-gate 	     }
4760Sstevel@tonic-gate 	}
4770Sstevel@tonic-gate 	return (TRUE);
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate bool_t
xdr_kadm5_policy_ent_rec(XDR * xdrs,kadm5_policy_ent_rec * objp)4810Sstevel@tonic-gate xdr_kadm5_policy_ent_rec(XDR *xdrs, kadm5_policy_ent_rec *objp)
4820Sstevel@tonic-gate {
4830Sstevel@tonic-gate 	if (!xdr_nullstring(xdrs, &objp->policy)) {
4840Sstevel@tonic-gate 		return (FALSE);
4850Sstevel@tonic-gate 	}
4860Sstevel@tonic-gate 	/* these all used to be u_int32, but it's stupid for sized types
4870Sstevel@tonic-gate 	   to be exposed at the api, and they're the same as longs on the
4880Sstevel@tonic-gate 	   wire. */
4890Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->pw_min_life)) {
4900Sstevel@tonic-gate 		return (FALSE);
4910Sstevel@tonic-gate 	}
4920Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->pw_max_life)) {
4930Sstevel@tonic-gate 		return (FALSE);
4940Sstevel@tonic-gate 	}
4950Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->pw_min_length)) {
4960Sstevel@tonic-gate 		return (FALSE);
4970Sstevel@tonic-gate 	}
4980Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->pw_min_classes)) {
4990Sstevel@tonic-gate 		return (FALSE);
5000Sstevel@tonic-gate 	}
5010Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->pw_history_num)) {
5020Sstevel@tonic-gate 		return (FALSE);
5030Sstevel@tonic-gate 	}
5040Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->policy_refcnt)) {
5050Sstevel@tonic-gate 		return (FALSE);
5060Sstevel@tonic-gate 	}
5070Sstevel@tonic-gate 	return (TRUE);
5080Sstevel@tonic-gate }
5090Sstevel@tonic-gate 
5100Sstevel@tonic-gate bool_t
xdr_cprinc_arg(XDR * xdrs,cprinc_arg * objp)5110Sstevel@tonic-gate xdr_cprinc_arg(XDR *xdrs, cprinc_arg *objp)
5120Sstevel@tonic-gate {
5130Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
5140Sstevel@tonic-gate 		return (FALSE);
5150Sstevel@tonic-gate 	}
5160Sstevel@tonic-gate 	if (objp->api_version == KADM5_API_VERSION_1) {
5170Sstevel@tonic-gate 	     if (!xdr_kadm5_principal_ent_rec_v1(xdrs, &objp->rec)) {
5180Sstevel@tonic-gate 		  return (FALSE);
5190Sstevel@tonic-gate 	     }
5200Sstevel@tonic-gate 	} else {
5210Sstevel@tonic-gate 	     if (!xdr_kadm5_principal_ent_rec(xdrs, &objp->rec)) {
5220Sstevel@tonic-gate 		  return (FALSE);
5230Sstevel@tonic-gate 	     }
5240Sstevel@tonic-gate 	}
5250Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->mask)) {
5260Sstevel@tonic-gate 		return (FALSE);
5270Sstevel@tonic-gate 	}
5280Sstevel@tonic-gate 	if (!xdr_nullstring(xdrs, &objp->passwd)) {
5290Sstevel@tonic-gate 		return (FALSE);
5300Sstevel@tonic-gate 	}
5310Sstevel@tonic-gate 	return (TRUE);
5320Sstevel@tonic-gate }
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate bool_t
xdr_cprinc3_arg(XDR * xdrs,cprinc3_arg * objp)5350Sstevel@tonic-gate xdr_cprinc3_arg(XDR *xdrs, cprinc3_arg *objp)
5360Sstevel@tonic-gate {
5370Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
5380Sstevel@tonic-gate 		return (FALSE);
5390Sstevel@tonic-gate 	}
5400Sstevel@tonic-gate 	if (objp->api_version == KADM5_API_VERSION_1) {
5410Sstevel@tonic-gate 		if (!xdr_kadm5_principal_ent_rec_v1(xdrs, &objp->rec)) {
5420Sstevel@tonic-gate 			return (FALSE);
5430Sstevel@tonic-gate 		}
5440Sstevel@tonic-gate 	} else {
5450Sstevel@tonic-gate 		if (!xdr_kadm5_principal_ent_rec(xdrs, &objp->rec)) {
5460Sstevel@tonic-gate 			return (FALSE);
5470Sstevel@tonic-gate 		}
5480Sstevel@tonic-gate 	}
5490Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->mask)) {
5500Sstevel@tonic-gate 		return (FALSE);
5510Sstevel@tonic-gate 	}
5520Sstevel@tonic-gate 	if (!xdr_array(xdrs, (caddr_t *)&objp->ks_tuple,
5530Sstevel@tonic-gate 		       (unsigned int *)&objp->n_ks_tuple, ~0,
5540Sstevel@tonic-gate 		       sizeof(krb5_key_salt_tuple),
5550Sstevel@tonic-gate 		       xdr_krb5_key_salt_tuple)) {
5560Sstevel@tonic-gate 		return (FALSE);
5570Sstevel@tonic-gate 	}
5580Sstevel@tonic-gate 	if (!xdr_nullstring(xdrs, &objp->passwd)) {
5590Sstevel@tonic-gate 		return (FALSE);
5600Sstevel@tonic-gate 	}
5610Sstevel@tonic-gate 	return (TRUE);
5620Sstevel@tonic-gate }
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate bool_t
xdr_generic_ret(XDR * xdrs,generic_ret * objp)5650Sstevel@tonic-gate xdr_generic_ret(XDR *xdrs, generic_ret *objp)
5660Sstevel@tonic-gate {
5670Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
5680Sstevel@tonic-gate 		return (FALSE);
5690Sstevel@tonic-gate 	}
5700Sstevel@tonic-gate 	if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
5710Sstevel@tonic-gate 		return (FALSE);
5720Sstevel@tonic-gate 	}
573*7934SMark.Phalan@Sun.COM 
5740Sstevel@tonic-gate 	return(TRUE);
5750Sstevel@tonic-gate }
5760Sstevel@tonic-gate 
5770Sstevel@tonic-gate bool_t
xdr_dprinc_arg(XDR * xdrs,dprinc_arg * objp)5780Sstevel@tonic-gate xdr_dprinc_arg(XDR *xdrs, dprinc_arg *objp)
5790Sstevel@tonic-gate {
5800Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
5810Sstevel@tonic-gate 		return (FALSE);
5820Sstevel@tonic-gate 	}
5830Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
5840Sstevel@tonic-gate 		return (FALSE);
5850Sstevel@tonic-gate 	}
5860Sstevel@tonic-gate 	return (TRUE);
5870Sstevel@tonic-gate }
5880Sstevel@tonic-gate 
5890Sstevel@tonic-gate bool_t
xdr_mprinc_arg(XDR * xdrs,mprinc_arg * objp)5900Sstevel@tonic-gate xdr_mprinc_arg(XDR *xdrs, mprinc_arg *objp)
5910Sstevel@tonic-gate {
5920Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
5930Sstevel@tonic-gate 		return (FALSE);
5940Sstevel@tonic-gate 	}
5950Sstevel@tonic-gate 	if (objp->api_version == KADM5_API_VERSION_1) {
5960Sstevel@tonic-gate 	     if (!xdr_kadm5_principal_ent_rec_v1(xdrs, &objp->rec)) {
5970Sstevel@tonic-gate 		  return (FALSE);
5980Sstevel@tonic-gate 	     }
5990Sstevel@tonic-gate 	} else {
6000Sstevel@tonic-gate 	     if (!xdr_kadm5_principal_ent_rec(xdrs, &objp->rec)) {
6010Sstevel@tonic-gate 		  return (FALSE);
6020Sstevel@tonic-gate 	     }
6030Sstevel@tonic-gate 	}
6040Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->mask)) {
6050Sstevel@tonic-gate 		return (FALSE);
6060Sstevel@tonic-gate 	}
6070Sstevel@tonic-gate 	return (TRUE);
6080Sstevel@tonic-gate }
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate bool_t
xdr_rprinc_arg(XDR * xdrs,rprinc_arg * objp)6110Sstevel@tonic-gate xdr_rprinc_arg(XDR *xdrs, rprinc_arg *objp)
6120Sstevel@tonic-gate {
6130Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
6140Sstevel@tonic-gate 		return (FALSE);
6150Sstevel@tonic-gate 	}
6160Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->src)) {
6170Sstevel@tonic-gate 		return (FALSE);
6180Sstevel@tonic-gate 	}
6190Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->dest)) {
6200Sstevel@tonic-gate 		return (FALSE);
6210Sstevel@tonic-gate 	}
6220Sstevel@tonic-gate 	return (TRUE);
6230Sstevel@tonic-gate }
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate bool_t
xdr_gprincs_arg(XDR * xdrs,gprincs_arg * objp)6260Sstevel@tonic-gate xdr_gprincs_arg(XDR *xdrs, gprincs_arg *objp)
6270Sstevel@tonic-gate {
6280Sstevel@tonic-gate      if (!xdr_ui_4(xdrs, &objp->api_version)) {
6290Sstevel@tonic-gate 	  return (FALSE);
6300Sstevel@tonic-gate      }
6310Sstevel@tonic-gate      if (!xdr_nullstring(xdrs, &objp->exp)) {
6320Sstevel@tonic-gate 	  return (FALSE);
6330Sstevel@tonic-gate      }
6340Sstevel@tonic-gate      return (TRUE);
6350Sstevel@tonic-gate }
6360Sstevel@tonic-gate 
6370Sstevel@tonic-gate bool_t
xdr_gprincs_ret(XDR * xdrs,gprincs_ret * objp)6380Sstevel@tonic-gate xdr_gprincs_ret(XDR *xdrs, gprincs_ret *objp)
6390Sstevel@tonic-gate {
6400Sstevel@tonic-gate      if (!xdr_ui_4(xdrs, &objp->api_version)) {
6410Sstevel@tonic-gate 	  return (FALSE);
6420Sstevel@tonic-gate      }
6430Sstevel@tonic-gate      if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
6440Sstevel@tonic-gate 	  return (FALSE);
6450Sstevel@tonic-gate      }
6460Sstevel@tonic-gate      if (objp->code == KADM5_OK) {
6470Sstevel@tonic-gate 	  if (!xdr_int(xdrs, &objp->count)) {
6480Sstevel@tonic-gate 	       return (FALSE);
6490Sstevel@tonic-gate 	  }
6500Sstevel@tonic-gate 	  if (!xdr_array(xdrs, (caddr_t *) &objp->princs,
6510Sstevel@tonic-gate 			 (unsigned int *) &objp->count, ~0,
6520Sstevel@tonic-gate 			 sizeof(char *), xdr_nullstring)) {
6530Sstevel@tonic-gate 	       return (FALSE);
6540Sstevel@tonic-gate 	  }
6550Sstevel@tonic-gate      }
656*7934SMark.Phalan@Sun.COM 
6570Sstevel@tonic-gate      return (TRUE);
6580Sstevel@tonic-gate }
6590Sstevel@tonic-gate 
6600Sstevel@tonic-gate bool_t
xdr_chpass_arg(XDR * xdrs,chpass_arg * objp)6610Sstevel@tonic-gate xdr_chpass_arg(XDR *xdrs, chpass_arg *objp)
6620Sstevel@tonic-gate {
6630Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
6640Sstevel@tonic-gate 		return (FALSE);
6650Sstevel@tonic-gate 	}
6660Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
6670Sstevel@tonic-gate 		return (FALSE);
6680Sstevel@tonic-gate 	}
6690Sstevel@tonic-gate 	if (!xdr_nullstring(xdrs, &objp->pass)) {
6700Sstevel@tonic-gate 		return (FALSE);
6710Sstevel@tonic-gate 	}
6720Sstevel@tonic-gate 	return (TRUE);
6730Sstevel@tonic-gate }
6740Sstevel@tonic-gate 
6750Sstevel@tonic-gate bool_t
xdr_chpass3_arg(XDR * xdrs,chpass3_arg * objp)6760Sstevel@tonic-gate xdr_chpass3_arg(XDR *xdrs, chpass3_arg *objp)
6770Sstevel@tonic-gate {
6780Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
6790Sstevel@tonic-gate 		return (FALSE);
6800Sstevel@tonic-gate 	}
6810Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
6820Sstevel@tonic-gate 		return (FALSE);
6830Sstevel@tonic-gate 	}
6840Sstevel@tonic-gate 	if (!xdr_bool(xdrs, (bool_t *) &objp->keepold)) { /* SUNWresync121 XXX */
6850Sstevel@tonic-gate 		return (FALSE);
6860Sstevel@tonic-gate 	}
6870Sstevel@tonic-gate 	if (!xdr_array(xdrs, (caddr_t *)&objp->ks_tuple,
6880Sstevel@tonic-gate 		       (unsigned int*)&objp->n_ks_tuple, ~0,
6890Sstevel@tonic-gate 		       sizeof(krb5_key_salt_tuple),
6900Sstevel@tonic-gate 		       xdr_krb5_key_salt_tuple)) {
6910Sstevel@tonic-gate 		return (FALSE);
6920Sstevel@tonic-gate 	}
6930Sstevel@tonic-gate 	if (!xdr_nullstring(xdrs, &objp->pass)) {
6940Sstevel@tonic-gate 		return (FALSE);
6950Sstevel@tonic-gate 	}
6960Sstevel@tonic-gate 	return (TRUE);
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate bool_t
xdr_setv4key_arg(XDR * xdrs,setv4key_arg * objp)7000Sstevel@tonic-gate xdr_setv4key_arg(XDR *xdrs, setv4key_arg *objp)
7010Sstevel@tonic-gate {
7020Sstevel@tonic-gate 	unsigned int n_keys = 1;
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
7050Sstevel@tonic-gate 		return (FALSE);
7060Sstevel@tonic-gate 	}
7070Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
7080Sstevel@tonic-gate 		return (FALSE);
7090Sstevel@tonic-gate 	}
7100Sstevel@tonic-gate 	if (!xdr_array(xdrs, (caddr_t *) &objp->keyblock,
7110Sstevel@tonic-gate 		       &n_keys, ~0,
7120Sstevel@tonic-gate 		       sizeof(krb5_keyblock), xdr_krb5_keyblock)) {
7130Sstevel@tonic-gate 	        return (FALSE);
7140Sstevel@tonic-gate 	}
7150Sstevel@tonic-gate 	return (TRUE);
7160Sstevel@tonic-gate }
7170Sstevel@tonic-gate 
7180Sstevel@tonic-gate bool_t
xdr_setkey_arg(XDR * xdrs,setkey_arg * objp)7190Sstevel@tonic-gate xdr_setkey_arg(XDR *xdrs, setkey_arg *objp)
7200Sstevel@tonic-gate {
7210Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
7220Sstevel@tonic-gate 		return (FALSE);
7230Sstevel@tonic-gate 	}
7240Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
7250Sstevel@tonic-gate 		return (FALSE);
7260Sstevel@tonic-gate 	}
7270Sstevel@tonic-gate 	if (!xdr_array(xdrs, (caddr_t *) &objp->keyblocks,
7280Sstevel@tonic-gate 		       (unsigned int *) &objp->n_keys, ~0,
7290Sstevel@tonic-gate 		       sizeof(krb5_keyblock), xdr_krb5_keyblock)) {
7300Sstevel@tonic-gate 	        return (FALSE);
7310Sstevel@tonic-gate 	}
7320Sstevel@tonic-gate 	return (TRUE);
7330Sstevel@tonic-gate }
7340Sstevel@tonic-gate 
7350Sstevel@tonic-gate bool_t
xdr_setkey3_arg(XDR * xdrs,setkey3_arg * objp)7360Sstevel@tonic-gate xdr_setkey3_arg(XDR *xdrs, setkey3_arg *objp)
7370Sstevel@tonic-gate {
7380Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
7390Sstevel@tonic-gate 		return (FALSE);
7400Sstevel@tonic-gate 	}
7410Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
7420Sstevel@tonic-gate 		return (FALSE);
7430Sstevel@tonic-gate 	}
7440Sstevel@tonic-gate 	if (!xdr_bool(xdrs, (bool_t *) &objp->keepold)) { /* SUNWresync121 XXX */
7450Sstevel@tonic-gate 		return (FALSE);
7460Sstevel@tonic-gate 	}
7470Sstevel@tonic-gate 	if (!xdr_array(xdrs, (caddr_t *) &objp->ks_tuple,
7480Sstevel@tonic-gate 		       (unsigned int *) &objp->n_ks_tuple, ~0,
7490Sstevel@tonic-gate 		       sizeof(krb5_key_salt_tuple), xdr_krb5_key_salt_tuple)) {
7500Sstevel@tonic-gate 		return (FALSE);
7510Sstevel@tonic-gate 	}
7520Sstevel@tonic-gate 	if (!xdr_array(xdrs, (caddr_t *) &objp->keyblocks,
7530Sstevel@tonic-gate 		       (unsigned int *) &objp->n_keys, ~0,
7540Sstevel@tonic-gate 		       sizeof(krb5_keyblock), xdr_krb5_keyblock)) {
7550Sstevel@tonic-gate 		return (FALSE);
7560Sstevel@tonic-gate 	}
7570Sstevel@tonic-gate 	return (TRUE);
7580Sstevel@tonic-gate }
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate bool_t
xdr_chrand_arg(XDR * xdrs,chrand_arg * objp)7610Sstevel@tonic-gate xdr_chrand_arg(XDR *xdrs, chrand_arg *objp)
7620Sstevel@tonic-gate {
7630Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
7640Sstevel@tonic-gate 		return (FALSE);
7650Sstevel@tonic-gate 	}
7660Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
7670Sstevel@tonic-gate 		return (FALSE);
7680Sstevel@tonic-gate 	}
7690Sstevel@tonic-gate 	return (TRUE);
7700Sstevel@tonic-gate }
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate bool_t
xdr_chrand3_arg(XDR * xdrs,chrand3_arg * objp)7730Sstevel@tonic-gate xdr_chrand3_arg(XDR *xdrs, chrand3_arg *objp)
7740Sstevel@tonic-gate {
7750Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
7760Sstevel@tonic-gate 		return (FALSE);
7770Sstevel@tonic-gate 	}
7780Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
7790Sstevel@tonic-gate 		return (FALSE);
7800Sstevel@tonic-gate 	}
7810Sstevel@tonic-gate 	if (!xdr_bool(xdrs, (bool_t *) &objp->keepold)) { /* SUNWresync121 XXX */
7820Sstevel@tonic-gate 		return (FALSE);
7830Sstevel@tonic-gate 	}
7840Sstevel@tonic-gate 	if (!xdr_array(xdrs, (caddr_t *)&objp->ks_tuple,
7850Sstevel@tonic-gate 		       (unsigned int*)&objp->n_ks_tuple, ~0,
7860Sstevel@tonic-gate 		       sizeof(krb5_key_salt_tuple),
7870Sstevel@tonic-gate 		       xdr_krb5_key_salt_tuple)) {
7880Sstevel@tonic-gate 		return (FALSE);
7890Sstevel@tonic-gate 	}
7900Sstevel@tonic-gate 	return (TRUE);
7910Sstevel@tonic-gate }
7920Sstevel@tonic-gate 
7930Sstevel@tonic-gate bool_t
xdr_chrand_ret(XDR * xdrs,chrand_ret * objp)7940Sstevel@tonic-gate xdr_chrand_ret(XDR *xdrs, chrand_ret *objp)
7950Sstevel@tonic-gate {
7960Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
7970Sstevel@tonic-gate 		return (FALSE);
7980Sstevel@tonic-gate 	}
7990Sstevel@tonic-gate 	if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
8000Sstevel@tonic-gate 		return (FALSE);
8010Sstevel@tonic-gate 	}
8020Sstevel@tonic-gate 	if (objp->api_version == KADM5_API_VERSION_1) {
8030Sstevel@tonic-gate 	     if(objp->code == KADM5_OK) {
8040Sstevel@tonic-gate 		  if (!xdr_krb5_keyblock(xdrs, &objp->key)) {
8050Sstevel@tonic-gate 		       return (FALSE);
8060Sstevel@tonic-gate 		  }
8070Sstevel@tonic-gate 	     }
8080Sstevel@tonic-gate 	} else {
8090Sstevel@tonic-gate 	     if (objp->code == KADM5_OK) {
8100Sstevel@tonic-gate 		  if (!xdr_array(xdrs, (char **)&objp->keys, (unsigned int *)&objp->n_keys, ~0,
8110Sstevel@tonic-gate 				 sizeof(krb5_keyblock),
8120Sstevel@tonic-gate 				 xdr_krb5_keyblock))
8130Sstevel@tonic-gate 		       return FALSE;
8140Sstevel@tonic-gate 	     }
8150Sstevel@tonic-gate 	}
816*7934SMark.Phalan@Sun.COM 
8170Sstevel@tonic-gate 	return (TRUE);
8180Sstevel@tonic-gate }
8190Sstevel@tonic-gate 
8200Sstevel@tonic-gate bool_t
xdr_gprinc_arg(XDR * xdrs,gprinc_arg * objp)8210Sstevel@tonic-gate xdr_gprinc_arg(XDR *xdrs, gprinc_arg *objp)
8220Sstevel@tonic-gate {
8230Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
8240Sstevel@tonic-gate 		return (FALSE);
8250Sstevel@tonic-gate 	}
8260Sstevel@tonic-gate 	if (!xdr_krb5_principal(xdrs, &objp->princ)) {
8270Sstevel@tonic-gate 		return (FALSE);
8280Sstevel@tonic-gate 	}
8290Sstevel@tonic-gate 	if ((objp->api_version > KADM5_API_VERSION_1) &&
8300Sstevel@tonic-gate 	    !xdr_long(xdrs, &objp->mask)) {
8310Sstevel@tonic-gate 	     return FALSE;
8320Sstevel@tonic-gate 	}
8330Sstevel@tonic-gate 
8340Sstevel@tonic-gate 	return (TRUE);
8350Sstevel@tonic-gate }
8360Sstevel@tonic-gate 
8370Sstevel@tonic-gate bool_t
xdr_gprinc_ret(XDR * xdrs,gprinc_ret * objp)8380Sstevel@tonic-gate xdr_gprinc_ret(XDR *xdrs, gprinc_ret *objp)
8390Sstevel@tonic-gate {
8400Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
8410Sstevel@tonic-gate 		return (FALSE);
8420Sstevel@tonic-gate 	}
8430Sstevel@tonic-gate 	if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
8440Sstevel@tonic-gate 		return (FALSE);
8450Sstevel@tonic-gate 	}
8460Sstevel@tonic-gate 	if(objp->code == KADM5_OK)  {
8470Sstevel@tonic-gate 	     if (objp->api_version == KADM5_API_VERSION_1) {
8480Sstevel@tonic-gate 		  if (!xdr_kadm5_principal_ent_rec_v1(xdrs, &objp->rec)) {
8490Sstevel@tonic-gate 		       return (FALSE);
8500Sstevel@tonic-gate 		  }
8510Sstevel@tonic-gate 	     } else {
8520Sstevel@tonic-gate 		  if (!xdr_kadm5_principal_ent_rec(xdrs, &objp->rec)) {
8530Sstevel@tonic-gate 		       return (FALSE);
8540Sstevel@tonic-gate 		  }
8550Sstevel@tonic-gate 	     }
8560Sstevel@tonic-gate 	}
857*7934SMark.Phalan@Sun.COM 
8580Sstevel@tonic-gate 	return (TRUE);
8590Sstevel@tonic-gate }
8600Sstevel@tonic-gate 
8610Sstevel@tonic-gate bool_t
xdr_cpol_arg(XDR * xdrs,cpol_arg * objp)8620Sstevel@tonic-gate xdr_cpol_arg(XDR *xdrs, cpol_arg *objp)
8630Sstevel@tonic-gate {
8640Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
8650Sstevel@tonic-gate 		return (FALSE);
8660Sstevel@tonic-gate 	}
8670Sstevel@tonic-gate 	if (!xdr_kadm5_policy_ent_rec(xdrs, &objp->rec)) {
8680Sstevel@tonic-gate 		return (FALSE);
8690Sstevel@tonic-gate 	}
8700Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->mask)) {
8710Sstevel@tonic-gate 		return (FALSE);
8720Sstevel@tonic-gate 	}
8730Sstevel@tonic-gate 	return (TRUE);
8740Sstevel@tonic-gate }
8750Sstevel@tonic-gate 
8760Sstevel@tonic-gate bool_t
xdr_dpol_arg(XDR * xdrs,dpol_arg * objp)8770Sstevel@tonic-gate xdr_dpol_arg(XDR *xdrs, dpol_arg *objp)
8780Sstevel@tonic-gate {
8790Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
8800Sstevel@tonic-gate 		return (FALSE);
8810Sstevel@tonic-gate 	}
8820Sstevel@tonic-gate 	if (!xdr_nullstring(xdrs, &objp->name)) {
8830Sstevel@tonic-gate 		return (FALSE);
8840Sstevel@tonic-gate 	}
8850Sstevel@tonic-gate 	return (TRUE);
8860Sstevel@tonic-gate }
8870Sstevel@tonic-gate 
8880Sstevel@tonic-gate bool_t
xdr_mpol_arg(XDR * xdrs,mpol_arg * objp)8890Sstevel@tonic-gate xdr_mpol_arg(XDR *xdrs, mpol_arg *objp)
8900Sstevel@tonic-gate {
8910Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
8920Sstevel@tonic-gate 		return (FALSE);
8930Sstevel@tonic-gate 	}
8940Sstevel@tonic-gate 	if (!xdr_kadm5_policy_ent_rec(xdrs, &objp->rec)) {
8950Sstevel@tonic-gate 		return (FALSE);
8960Sstevel@tonic-gate 	}
8970Sstevel@tonic-gate 	if (!xdr_long(xdrs, &objp->mask)) {
8980Sstevel@tonic-gate 		return (FALSE);
8990Sstevel@tonic-gate 	}
9000Sstevel@tonic-gate 	return (TRUE);
9010Sstevel@tonic-gate }
9020Sstevel@tonic-gate 
9030Sstevel@tonic-gate bool_t
xdr_gpol_arg(XDR * xdrs,gpol_arg * objp)9040Sstevel@tonic-gate xdr_gpol_arg(XDR *xdrs, gpol_arg *objp)
9050Sstevel@tonic-gate {
9060Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
9070Sstevel@tonic-gate 		return (FALSE);
9080Sstevel@tonic-gate 	}
9090Sstevel@tonic-gate 	if (!xdr_nullstring(xdrs, &objp->name)) {
9100Sstevel@tonic-gate 		return (FALSE);
9110Sstevel@tonic-gate 	}
9120Sstevel@tonic-gate 	return (TRUE);
9130Sstevel@tonic-gate }
9140Sstevel@tonic-gate 
9150Sstevel@tonic-gate bool_t
xdr_gpol_ret(XDR * xdrs,gpol_ret * objp)9160Sstevel@tonic-gate xdr_gpol_ret(XDR *xdrs, gpol_ret *objp)
9170Sstevel@tonic-gate {
9180Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
9190Sstevel@tonic-gate 		return (FALSE);
9200Sstevel@tonic-gate 	}
9210Sstevel@tonic-gate 	if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
9220Sstevel@tonic-gate 		return (FALSE);
9230Sstevel@tonic-gate 	}
9240Sstevel@tonic-gate 	if(objp->code == KADM5_OK) {
9250Sstevel@tonic-gate 	    if (!xdr_kadm5_policy_ent_rec(xdrs, &objp->rec))
9260Sstevel@tonic-gate 		return (FALSE);
9270Sstevel@tonic-gate 	}
928*7934SMark.Phalan@Sun.COM 
9290Sstevel@tonic-gate 	return (TRUE);
9300Sstevel@tonic-gate }
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate bool_t
xdr_gpols_arg(XDR * xdrs,gpols_arg * objp)9330Sstevel@tonic-gate xdr_gpols_arg(XDR *xdrs, gpols_arg *objp)
9340Sstevel@tonic-gate {
9350Sstevel@tonic-gate      if (!xdr_ui_4(xdrs, &objp->api_version)) {
9360Sstevel@tonic-gate 	  return (FALSE);
9370Sstevel@tonic-gate      }
9380Sstevel@tonic-gate      if (!xdr_nullstring(xdrs, &objp->exp)) {
9390Sstevel@tonic-gate 	  return (FALSE);
9400Sstevel@tonic-gate      }
9410Sstevel@tonic-gate      return (TRUE);
9420Sstevel@tonic-gate }
9430Sstevel@tonic-gate 
9440Sstevel@tonic-gate bool_t
xdr_gpols_ret(XDR * xdrs,gpols_ret * objp)9450Sstevel@tonic-gate xdr_gpols_ret(XDR *xdrs, gpols_ret *objp)
9460Sstevel@tonic-gate {
9470Sstevel@tonic-gate      if (!xdr_ui_4(xdrs, &objp->api_version)) {
9480Sstevel@tonic-gate 	  return (FALSE);
9490Sstevel@tonic-gate      }
9500Sstevel@tonic-gate      if (!xdr_kadm5_ret_t(xdrs, &objp->code)) {
9510Sstevel@tonic-gate 	  return (FALSE);
9520Sstevel@tonic-gate      }
9530Sstevel@tonic-gate      if (objp->code == KADM5_OK) {
9540Sstevel@tonic-gate 	  if (!xdr_int(xdrs, &objp->count)) {
9550Sstevel@tonic-gate 	       return (FALSE);
9560Sstevel@tonic-gate 	  }
9570Sstevel@tonic-gate 	  if (!xdr_array(xdrs, (caddr_t *) &objp->pols,
9580Sstevel@tonic-gate 			 (unsigned int *) &objp->count, ~0,
9590Sstevel@tonic-gate 			 sizeof(char *), xdr_nullstring)) {
9600Sstevel@tonic-gate 	       return (FALSE);
9610Sstevel@tonic-gate 	  }
9620Sstevel@tonic-gate      }
963*7934SMark.Phalan@Sun.COM 
9640Sstevel@tonic-gate      return (TRUE);
9650Sstevel@tonic-gate }
9660Sstevel@tonic-gate 
xdr_getprivs_ret(XDR * xdrs,getprivs_ret * objp)9670Sstevel@tonic-gate bool_t xdr_getprivs_ret(XDR *xdrs, getprivs_ret *objp)
9680Sstevel@tonic-gate {
9690Sstevel@tonic-gate 	if (!xdr_ui_4(xdrs, &objp->api_version)) {
9700Sstevel@tonic-gate 		return (FALSE);
9710Sstevel@tonic-gate 	}
9720Sstevel@tonic-gate      if (! xdr_kadm5_ret_t(xdrs, &objp->code) ||
9730Sstevel@tonic-gate 	 ! xdr_long(xdrs, &objp->privs))
9740Sstevel@tonic-gate 	  return FALSE;
975*7934SMark.Phalan@Sun.COM 
9760Sstevel@tonic-gate      return TRUE;
9770Sstevel@tonic-gate }
9780Sstevel@tonic-gate 
9790Sstevel@tonic-gate bool_t
xdr_krb5_principal(XDR * xdrs,krb5_principal * objp)9800Sstevel@tonic-gate xdr_krb5_principal(XDR *xdrs, krb5_principal *objp)
9810Sstevel@tonic-gate {
9820Sstevel@tonic-gate     int	    ret;
9830Sstevel@tonic-gate     char	    *p = NULL;
9840Sstevel@tonic-gate     krb5_principal  pr = NULL;
9850Sstevel@tonic-gate     static krb5_context context = NULL;
9860Sstevel@tonic-gate 
9870Sstevel@tonic-gate     /* using a static context here is ugly, but should work
9880Sstevel@tonic-gate        ok, and the other solutions are even uglier */
9890Sstevel@tonic-gate 
9900Sstevel@tonic-gate     if (!context &&
991*7934SMark.Phalan@Sun.COM 	kadm5_init_krb5_context(&context))
9920Sstevel@tonic-gate        return(FALSE);
9930Sstevel@tonic-gate 
9940Sstevel@tonic-gate     switch(xdrs->x_op) {
9950Sstevel@tonic-gate     case XDR_ENCODE:
9960Sstevel@tonic-gate 	if (*objp) {
9970Sstevel@tonic-gate 	     if((ret = krb5_unparse_name(context, *objp, &p)) != 0)
9980Sstevel@tonic-gate 		  return FALSE;
9990Sstevel@tonic-gate 	}
10000Sstevel@tonic-gate 	if(!xdr_nullstring(xdrs, &p))
10010Sstevel@tonic-gate 	    return FALSE;
10020Sstevel@tonic-gate 	if (p) free(p);
10030Sstevel@tonic-gate 	break;
10040Sstevel@tonic-gate     case XDR_DECODE:
10050Sstevel@tonic-gate 	if(!xdr_nullstring(xdrs, &p))
10060Sstevel@tonic-gate 	    return FALSE;
10070Sstevel@tonic-gate 	if (p) {
10080Sstevel@tonic-gate 	     ret = krb5_parse_name(context, p, &pr);
10090Sstevel@tonic-gate 	     if(ret != 0)
10100Sstevel@tonic-gate 		  return FALSE;
10110Sstevel@tonic-gate 	     *objp = pr;
10120Sstevel@tonic-gate 	     free(p);
10130Sstevel@tonic-gate 	} else
10140Sstevel@tonic-gate 	     *objp = NULL;
10150Sstevel@tonic-gate 	break;
10160Sstevel@tonic-gate     case XDR_FREE:
10170Sstevel@tonic-gate 	if(*objp != NULL)
10180Sstevel@tonic-gate 	    krb5_free_principal(context, *objp);
10190Sstevel@tonic-gate 	break;
10200Sstevel@tonic-gate     }
10210Sstevel@tonic-gate     return TRUE;
10220Sstevel@tonic-gate }
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate bool_t
xdr_krb5_octet(XDR * xdrs,krb5_octet * objp)10250Sstevel@tonic-gate xdr_krb5_octet(XDR *xdrs, krb5_octet *objp)
10260Sstevel@tonic-gate {
10270Sstevel@tonic-gate    if (!xdr_u_char(xdrs, objp))
10280Sstevel@tonic-gate 	return (FALSE);
10290Sstevel@tonic-gate    return (TRUE);
10300Sstevel@tonic-gate }
10310Sstevel@tonic-gate 
10320Sstevel@tonic-gate bool_t
xdr_krb5_enctype(XDR * xdrs,krb5_enctype * objp)10330Sstevel@tonic-gate xdr_krb5_enctype(XDR *xdrs, krb5_enctype *objp)
10340Sstevel@tonic-gate {
10350Sstevel@tonic-gate    /*
10360Sstevel@tonic-gate     * This used to be xdr_krb5_keytype, but keytypes and enctypes have
10370Sstevel@tonic-gate     * been merged into only enctypes.  However, randkey_principal
10380Sstevel@tonic-gate     * already ensures that only a key of ENCTYPE_DES_CBC_CRC will be
10390Sstevel@tonic-gate     * returned to v1 clients, and ENCTYPE_DES_CBC_CRC has the same
10400Sstevel@tonic-gate     * value as KEYTYPE_DES used too, which is what all v1 clients
10410Sstevel@tonic-gate     * expect.  Therefore, IMHO, just encoding whatever enctype we get
10420Sstevel@tonic-gate     * is safe.
10430Sstevel@tonic-gate     */
10440Sstevel@tonic-gate 
10450Sstevel@tonic-gate    if (!xdr_u_int(xdrs, (unsigned int *) objp))
10460Sstevel@tonic-gate 	return (FALSE);
10470Sstevel@tonic-gate    return (TRUE);
10480Sstevel@tonic-gate }
10490Sstevel@tonic-gate 
10500Sstevel@tonic-gate bool_t
xdr_krb5_salttype(XDR * xdrs,krb5_int32 * objp)10510Sstevel@tonic-gate xdr_krb5_salttype(XDR *xdrs, krb5_int32 *objp)
10520Sstevel@tonic-gate {
1053*7934SMark.Phalan@Sun.COM     if (!xdr_int(xdrs, (int32_t *) objp))
10540Sstevel@tonic-gate 	return FALSE;
10550Sstevel@tonic-gate     return TRUE;
10560Sstevel@tonic-gate }
10570Sstevel@tonic-gate 
10580Sstevel@tonic-gate bool_t
xdr_krb5_keyblock(XDR * xdrs,krb5_keyblock * objp)10590Sstevel@tonic-gate xdr_krb5_keyblock(XDR *xdrs, krb5_keyblock *objp)
10600Sstevel@tonic-gate {
10610Sstevel@tonic-gate    /* XXX This only works because free_keyblock assumes ->contents
10620Sstevel@tonic-gate       is allocated by malloc() */
10630Sstevel@tonic-gate 
10640Sstevel@tonic-gate    if(!xdr_krb5_enctype(xdrs, &objp->enctype))
10650Sstevel@tonic-gate       return FALSE;
10660Sstevel@tonic-gate    if(!xdr_bytes(xdrs, (char **) &objp->contents, (unsigned int *)
10670Sstevel@tonic-gate 		 &objp->length, ~0))
10680Sstevel@tonic-gate       return FALSE;
10690Sstevel@tonic-gate    return TRUE;
10700Sstevel@tonic-gate }
1071