17c478bd9Sstevel@tonic-gate /*
2159d09a2SMark Phalan  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate 
77c478bd9Sstevel@tonic-gate /*
87c478bd9Sstevel@tonic-gate  * NAME
97c478bd9Sstevel@tonic-gate  *    cred.c
10*55fea89dSDan Cross  *
117c478bd9Sstevel@tonic-gate  * DESCRIPTION
127c478bd9Sstevel@tonic-gate  *    Provide an interface to assemble and disassemble krb5_cred
137c478bd9Sstevel@tonic-gate  *    structures.
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  */
16159d09a2SMark Phalan #include "k5-int.h"
177c478bd9Sstevel@tonic-gate #include "cleanup.h"
18159d09a2SMark Phalan #include "auth_con.h"
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate #include <stddef.h>           /* NULL */
217c478bd9Sstevel@tonic-gate #include <stdlib.h>           /* malloc */
227c478bd9Sstevel@tonic-gate #include <errno.h>            /* ENOMEM */
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /*-------------------- encrypt_credencpart --------------------*/
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*ARGSUSED*/
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * encrypt the enc_part of krb5_cred
297c478bd9Sstevel@tonic-gate  */
30*55fea89dSDan Cross static krb5_error_code
encrypt_credencpart(krb5_context context,krb5_cred_enc_part * pcredpart,krb5_keyblock * pkeyblock,krb5_enc_data * pencdata)31505d05c7Sgtb encrypt_credencpart(krb5_context context, krb5_cred_enc_part *pcredpart, krb5_keyblock *pkeyblock, krb5_enc_data *pencdata)
327c478bd9Sstevel@tonic-gate {
337c478bd9Sstevel@tonic-gate     krb5_error_code 	  retval;
347c478bd9Sstevel@tonic-gate     krb5_data 		* scratch;
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate     /* start by encoding to-be-encrypted part of the message */
377c478bd9Sstevel@tonic-gate     if ((retval = encode_krb5_enc_cred_part(pcredpart, &scratch)))
387c478bd9Sstevel@tonic-gate     	return retval;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate     /*
417c478bd9Sstevel@tonic-gate      * If the keyblock is NULL, just copy the data from the encoded
427c478bd9Sstevel@tonic-gate      * data to the ciphertext area.
437c478bd9Sstevel@tonic-gate      */
447c478bd9Sstevel@tonic-gate     if (pkeyblock == NULL) {
457c478bd9Sstevel@tonic-gate 	    pencdata->ciphertext.data = scratch->data;
467c478bd9Sstevel@tonic-gate 	    pencdata->ciphertext.length = scratch->length;
477c478bd9Sstevel@tonic-gate 	    krb5_xfree(scratch);
487c478bd9Sstevel@tonic-gate 	    return 0;
497c478bd9Sstevel@tonic-gate     }
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate     /* call the encryption routine */
527c478bd9Sstevel@tonic-gate     retval = krb5_encrypt_helper(context, pkeyblock,
537c478bd9Sstevel@tonic-gate 				 KRB5_KEYUSAGE_KRB_CRED_ENCPART,
547c478bd9Sstevel@tonic-gate 				 scratch, pencdata);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate     if (retval) {
577c478bd9Sstevel@tonic-gate     	memset(pencdata->ciphertext.data, 0, pencdata->ciphertext.length);
587c478bd9Sstevel@tonic-gate         free(pencdata->ciphertext.data);
597c478bd9Sstevel@tonic-gate         pencdata->ciphertext.length = 0;
607c478bd9Sstevel@tonic-gate         pencdata->ciphertext.data = 0;
617c478bd9Sstevel@tonic-gate     }
627c478bd9Sstevel@tonic-gate 
63*55fea89dSDan Cross     memset(scratch->data, 0, scratch->length);
647c478bd9Sstevel@tonic-gate     krb5_free_data(context, scratch);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate     return retval;
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*----------------------- krb5_mk_ncred_basic -----------------------*/
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate static krb5_error_code
krb5_mk_ncred_basic(krb5_context context,krb5_creds ** ppcreds,krb5_int32 nppcreds,krb5_keyblock * keyblock,krb5_replay_data * replaydata,krb5_address * local_addr,krb5_address * remote_addr,krb5_cred * pcred)72505d05c7Sgtb krb5_mk_ncred_basic(krb5_context context, krb5_creds **ppcreds, krb5_int32 nppcreds, krb5_keyblock *keyblock, krb5_replay_data *replaydata, krb5_address *local_addr, krb5_address *remote_addr, krb5_cred *pcred)
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate     krb5_cred_enc_part 	  credenc;
757c478bd9Sstevel@tonic-gate     krb5_error_code	  retval;
767c478bd9Sstevel@tonic-gate     size_t		  size;
777c478bd9Sstevel@tonic-gate     int			  i;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate     credenc.magic = KV5M_CRED_ENC_PART;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate     credenc.s_address = 0;
827c478bd9Sstevel@tonic-gate     credenc.r_address = 0;
837c478bd9Sstevel@tonic-gate     if (local_addr) krb5_copy_addr(context, local_addr, &credenc.s_address);
847c478bd9Sstevel@tonic-gate     if (remote_addr) krb5_copy_addr(context, remote_addr, &credenc.r_address);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate     credenc.nonce = replaydata->seq;
877c478bd9Sstevel@tonic-gate     credenc.usec = replaydata->usec;
887c478bd9Sstevel@tonic-gate     credenc.timestamp = replaydata->timestamp;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate     /* Get memory for creds and initialize it */
91505d05c7Sgtb     size = sizeof(krb5_cred_info *) * (nppcreds + 1);
92505d05c7Sgtb     credenc.ticket_info = (krb5_cred_info **) malloc(size);
937c478bd9Sstevel@tonic-gate     if (credenc.ticket_info == NULL)
947c478bd9Sstevel@tonic-gate 	return ENOMEM;
957c478bd9Sstevel@tonic-gate     memset(credenc.ticket_info, 0, size);
96*55fea89dSDan Cross 
977c478bd9Sstevel@tonic-gate     /*
987c478bd9Sstevel@tonic-gate      * For each credential in the list, initialize a cred info
997c478bd9Sstevel@tonic-gate      * structure and copy the ticket into the ticket list.
1007c478bd9Sstevel@tonic-gate      */
1017c478bd9Sstevel@tonic-gate     for (i = 0; i < nppcreds; i++) {
1027c478bd9Sstevel@tonic-gate     	credenc.ticket_info[i] = malloc(sizeof(krb5_cred_info));
1037c478bd9Sstevel@tonic-gate 	if (credenc.ticket_info[i] == NULL) {
1047c478bd9Sstevel@tonic-gate 	    retval = ENOMEM;
1057c478bd9Sstevel@tonic-gate 	    goto cleanup;
1067c478bd9Sstevel@tonic-gate 	}
1077c478bd9Sstevel@tonic-gate 	credenc.ticket_info[i+1] = NULL;
108*55fea89dSDan Cross 
1097c478bd9Sstevel@tonic-gate         credenc.ticket_info[i]->magic = KV5M_CRED_INFO;
1107c478bd9Sstevel@tonic-gate         credenc.ticket_info[i]->times = ppcreds[i]->times;
1117c478bd9Sstevel@tonic-gate         credenc.ticket_info[i]->flags = ppcreds[i]->ticket_flags;
1127c478bd9Sstevel@tonic-gate 
113*55fea89dSDan Cross     	if ((retval = decode_krb5_ticket(&ppcreds[i]->ticket,
1147c478bd9Sstevel@tonic-gate 					 &pcred->tickets[i])))
1157c478bd9Sstevel@tonic-gate 	    goto cleanup;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	if ((retval = krb5_copy_keyblock(context, &ppcreds[i]->keyblock,
1187c478bd9Sstevel@tonic-gate 					 &credenc.ticket_info[i]->session)))
1197c478bd9Sstevel@tonic-gate             goto cleanup;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate         if ((retval = krb5_copy_principal(context, ppcreds[i]->client,
1227c478bd9Sstevel@tonic-gate 					  &credenc.ticket_info[i]->client)))
1237c478bd9Sstevel@tonic-gate             goto cleanup;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate       	if ((retval = krb5_copy_principal(context, ppcreds[i]->server,
1267c478bd9Sstevel@tonic-gate 					  &credenc.ticket_info[i]->server)))
1277c478bd9Sstevel@tonic-gate             goto cleanup;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate       	if ((retval = krb5_copy_addresses(context, ppcreds[i]->addresses,
1307c478bd9Sstevel@tonic-gate 					  &credenc.ticket_info[i]->caddrs)))
1317c478bd9Sstevel@tonic-gate             goto cleanup;
1327c478bd9Sstevel@tonic-gate     }
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate     /*
1357c478bd9Sstevel@tonic-gate      * NULL terminate the lists.
1367c478bd9Sstevel@tonic-gate      */
1377c478bd9Sstevel@tonic-gate     pcred->tickets[i] = NULL;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate     /* encrypt the credential encrypted part */
1407c478bd9Sstevel@tonic-gate     retval = encrypt_credencpart(context, &credenc, keyblock,
1417c478bd9Sstevel@tonic-gate 				 &pcred->enc_part);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate cleanup:
1447c478bd9Sstevel@tonic-gate     krb5_free_cred_enc_part(context, &credenc);
1457c478bd9Sstevel@tonic-gate     return retval;
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*----------------------- krb5_mk_ncred -----------------------*/
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * This functions takes as input an array of krb5_credentials, and
1527c478bd9Sstevel@tonic-gate  * outputs an encoded KRB_CRED message suitable for krb5_rd_cred
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate krb5_error_code KRB5_CALLCONV
krb5_mk_ncred(krb5_context context,krb5_auth_context auth_context,krb5_creds ** ppcreds,krb5_data ** ppdata,krb5_replay_data * outdata)155505d05c7Sgtb krb5_mk_ncred(krb5_context context, krb5_auth_context auth_context, krb5_creds **ppcreds, krb5_data **ppdata, krb5_replay_data *outdata)
1567c478bd9Sstevel@tonic-gate {
157159d09a2SMark Phalan     krb5_address * premote_fulladdr = NULL;
158159d09a2SMark Phalan     krb5_address * plocal_fulladdr = NULL;
1597c478bd9Sstevel@tonic-gate     krb5_address remote_fulladdr;
1607c478bd9Sstevel@tonic-gate     krb5_address local_fulladdr;
1617c478bd9Sstevel@tonic-gate     krb5_error_code 	retval;
1627c478bd9Sstevel@tonic-gate     krb5_keyblock	 * keyblock;
1637c478bd9Sstevel@tonic-gate     krb5_replay_data    replaydata;
1647c478bd9Sstevel@tonic-gate     krb5_cred 		 * pcred;
1657c478bd9Sstevel@tonic-gate     krb5_int32		ncred;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate     local_fulladdr.contents = 0;
1687c478bd9Sstevel@tonic-gate     remote_fulladdr.contents = 0;
1697c478bd9Sstevel@tonic-gate     memset(&replaydata, 0, sizeof(krb5_replay_data));
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate     if (ppcreds == NULL) {
1727c478bd9Sstevel@tonic-gate     	return KRB5KRB_AP_ERR_BADADDR;
1737c478bd9Sstevel@tonic-gate     }
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate     /*
1767c478bd9Sstevel@tonic-gate      * Allocate memory for a NULL terminated list of tickets.
1777c478bd9Sstevel@tonic-gate      */
1787c478bd9Sstevel@tonic-gate     for (ncred = 0; ppcreds[ncred]; ncred++);
1797c478bd9Sstevel@tonic-gate 
180*55fea89dSDan Cross     if ((pcred = (krb5_cred *)malloc(sizeof(krb5_cred))) == NULL)
1817c478bd9Sstevel@tonic-gate         return ENOMEM;
1827c478bd9Sstevel@tonic-gate     memset(pcred, 0, sizeof(krb5_cred));
1837c478bd9Sstevel@tonic-gate 
184*55fea89dSDan Cross     if ((pcred->tickets
185505d05c7Sgtb       = (krb5_ticket **)malloc(sizeof(krb5_ticket *) * (ncred + 1))) == NULL) {
1867c478bd9Sstevel@tonic-gate 	retval = ENOMEM;
1877c478bd9Sstevel@tonic-gate 	free(pcred);
1887c478bd9Sstevel@tonic-gate     }
189505d05c7Sgtb     memset(pcred->tickets, 0, sizeof(krb5_ticket *) * (ncred +1));
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate     /* Get keyblock */
192*55fea89dSDan Cross     if ((keyblock = auth_context->send_subkey) == NULL)
193159d09a2SMark Phalan 	keyblock = auth_context->keyblock;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate     /* Get replay info */
1967c478bd9Sstevel@tonic-gate     if ((auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_DO_TIME) &&
1977c478bd9Sstevel@tonic-gate       (auth_context->rcache == NULL))
1987c478bd9Sstevel@tonic-gate         return KRB5_RC_REQUIRED;
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate     if (((auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_RET_TIME) ||
2017c478bd9Sstevel@tonic-gate       (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_RET_SEQUENCE)) &&
2027c478bd9Sstevel@tonic-gate       (outdata == NULL))
2037c478bd9Sstevel@tonic-gate         /* Need a better error */
2047c478bd9Sstevel@tonic-gate         return KRB5_RC_REQUIRED;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate     if ((retval = krb5_us_timeofday(context, &replaydata.timestamp,
2077c478bd9Sstevel@tonic-gate 				    &replaydata.usec)))
2087c478bd9Sstevel@tonic-gate 	return retval;
2097c478bd9Sstevel@tonic-gate     if (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_RET_TIME) {
2107c478bd9Sstevel@tonic-gate 	outdata->timestamp = replaydata.timestamp;
2117c478bd9Sstevel@tonic-gate 	outdata->usec = replaydata.usec;
2127c478bd9Sstevel@tonic-gate     }
2137c478bd9Sstevel@tonic-gate     if ((auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_DO_SEQUENCE) ||
2147c478bd9Sstevel@tonic-gate         (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_RET_SEQUENCE)) {
2157c478bd9Sstevel@tonic-gate         replaydata.seq = auth_context->local_seq_number;
2167c478bd9Sstevel@tonic-gate         if (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_DO_SEQUENCE) {
2177c478bd9Sstevel@tonic-gate             auth_context->local_seq_number++;
2187c478bd9Sstevel@tonic-gate         } else {
2197c478bd9Sstevel@tonic-gate             outdata->seq = replaydata.seq;
2207c478bd9Sstevel@tonic-gate         }
2217c478bd9Sstevel@tonic-gate     }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate     if (auth_context->local_addr) {
2247c478bd9Sstevel@tonic-gate     	if (auth_context->local_port) {
2257c478bd9Sstevel@tonic-gate             if ((retval = krb5_make_fulladdr(context, auth_context->local_addr,
226*55fea89dSDan Cross 					     auth_context->local_port,
2277c478bd9Sstevel@tonic-gate 					     &local_fulladdr)))
2287c478bd9Sstevel@tonic-gate 		goto error;
2297c478bd9Sstevel@tonic-gate 	    plocal_fulladdr = &local_fulladdr;
2307c478bd9Sstevel@tonic-gate 	} else {
2317c478bd9Sstevel@tonic-gate             plocal_fulladdr = auth_context->local_addr;
2327c478bd9Sstevel@tonic-gate         }
2337c478bd9Sstevel@tonic-gate     }
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate     if (auth_context->remote_addr) {
2367c478bd9Sstevel@tonic-gate     	if (auth_context->remote_port) {
2377c478bd9Sstevel@tonic-gate             if ((retval = krb5_make_fulladdr(context,auth_context->remote_addr,
238*55fea89dSDan Cross                                  	      auth_context->remote_port,
2397c478bd9Sstevel@tonic-gate 					      &remote_fulladdr)))
2407c478bd9Sstevel@tonic-gate 		goto error;
2417c478bd9Sstevel@tonic-gate 	    premote_fulladdr = &remote_fulladdr;
2427c478bd9Sstevel@tonic-gate 	} else {
2437c478bd9Sstevel@tonic-gate             premote_fulladdr = auth_context->remote_addr;
2447c478bd9Sstevel@tonic-gate         }
2457c478bd9Sstevel@tonic-gate     }
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate     /* Setup creds structure */
2487c478bd9Sstevel@tonic-gate     if ((retval = krb5_mk_ncred_basic(context, ppcreds, ncred, keyblock,
249*55fea89dSDan Cross 				      &replaydata, plocal_fulladdr,
2507c478bd9Sstevel@tonic-gate 				      premote_fulladdr, pcred))) {
2517c478bd9Sstevel@tonic-gate 	goto error;
2527c478bd9Sstevel@tonic-gate     }
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate     if (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_DO_TIME) {
2557c478bd9Sstevel@tonic-gate         krb5_donot_replay replay;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate         if ((retval = krb5_gen_replay_name(context, auth_context->local_addr,
2587c478bd9Sstevel@tonic-gate 					   "_forw", &replay.client)))
2597c478bd9Sstevel@tonic-gate             goto error;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate         replay.server = "";             /* XXX */
2627c478bd9Sstevel@tonic-gate         replay.cusec = replaydata.usec;
2637c478bd9Sstevel@tonic-gate         replay.ctime = replaydata.timestamp;
264159d09a2SMark Phalan         if ((retval = krb5_rc_store(context, auth_context->rcache, &replay))) {
2657c478bd9Sstevel@tonic-gate             /* should we really error out here? XXX */
2667c478bd9Sstevel@tonic-gate             krb5_xfree(replay.client);
2677c478bd9Sstevel@tonic-gate             goto error;
2687c478bd9Sstevel@tonic-gate         }
2697c478bd9Sstevel@tonic-gate         krb5_xfree(replay.client);
2707c478bd9Sstevel@tonic-gate     }
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate     /* Encode creds structure */
2737c478bd9Sstevel@tonic-gate     retval = encode_krb5_cred(pcred, ppdata);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate error:
2767c478bd9Sstevel@tonic-gate     if (local_fulladdr.contents)
2777c478bd9Sstevel@tonic-gate 	free(local_fulladdr.contents);
2787c478bd9Sstevel@tonic-gate     if (remote_fulladdr.contents)
2797c478bd9Sstevel@tonic-gate 	free(remote_fulladdr.contents);
2807c478bd9Sstevel@tonic-gate     krb5_free_cred(context, pcred);
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate     if (retval) {
283*55fea89dSDan Cross 	if ((auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_DO_SEQUENCE)
2847c478bd9Sstevel@tonic-gate 	 || (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_RET_SEQUENCE))
2857c478bd9Sstevel@tonic-gate             auth_context->local_seq_number--;
2867c478bd9Sstevel@tonic-gate     }
2877c478bd9Sstevel@tonic-gate     return retval;
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /*----------------------- krb5_mk_1cred -----------------------*/
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate /*
2937c478bd9Sstevel@tonic-gate  * A convenience function that calls krb5_mk_ncred.
2947c478bd9Sstevel@tonic-gate  */
2957c478bd9Sstevel@tonic-gate krb5_error_code KRB5_CALLCONV
krb5_mk_1cred(krb5_context context,krb5_auth_context auth_context,krb5_creds * pcreds,krb5_data ** ppdata,krb5_replay_data * outdata)296505d05c7Sgtb krb5_mk_1cred(krb5_context context, krb5_auth_context auth_context, krb5_creds *pcreds, krb5_data **ppdata, krb5_replay_data *outdata)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate     krb5_error_code retval;
299159d09a2SMark Phalan     krb5_creds **ppcreds;
3007c478bd9Sstevel@tonic-gate 
301159d09a2SMark Phalan     if ((ppcreds = (krb5_creds **)malloc(sizeof(*ppcreds) * 2)) == NULL) {
3027c478bd9Sstevel@tonic-gate 	return ENOMEM;
3037c478bd9Sstevel@tonic-gate     }
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate     ppcreds[0] = pcreds;
3067c478bd9Sstevel@tonic-gate     ppcreds[1] = NULL;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate     retval = krb5_mk_ncred(context, auth_context, ppcreds,
3097c478bd9Sstevel@tonic-gate 			   ppdata, outdata);
310*55fea89dSDan Cross 
3117c478bd9Sstevel@tonic-gate     free(ppcreds);
3127c478bd9Sstevel@tonic-gate     return retval;
3137c478bd9Sstevel@tonic-gate }
314159d09a2SMark Phalan 
315