17c478bd9Sstevel@tonic-gate /*
2cc35afbcSMark Phalan * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
3*80ac04ddSGordon Ross * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
47c478bd9Sstevel@tonic-gate */
57c478bd9Sstevel@tonic-gate
6ba7b222eSGlenn Barry #include "mglueP.h"
75e01956fSGlenn Barry #include "gssapiP_generic.h"
87c478bd9Sstevel@tonic-gate #include <stdio.h>
9ba7b222eSGlenn Barry #ifdef HAVE_STDLIB_H
107c478bd9Sstevel@tonic-gate #include <stdlib.h>
11ba7b222eSGlenn Barry #endif
12ba7b222eSGlenn Barry #include <string.h>
137c478bd9Sstevel@tonic-gate #include <errno.h>
147c478bd9Sstevel@tonic-gate
15ba7b222eSGlenn Barry #include "k5-platform-store_32.h"
16ba7b222eSGlenn Barry #include "k5-platform-store_16.h"
17ba7b222eSGlenn Barry /*
18ba7b222eSGlenn Barry * SUNW17PACresync
19ba7b222eSGlenn Barry * MIT has diff names for these GSS utilities. Solaris needs to change
20ba7b222eSGlenn Barry * them globally to get in sync w/MIT.
21ba7b222eSGlenn Barry * Revisit for full 1.7 resync.
22ba7b222eSGlenn Barry */
23ba7b222eSGlenn Barry #define gssint_get_modOptions __gss_get_modOptions
24ba7b222eSGlenn Barry #define gssint_der_length_size der_length_size
25ba7b222eSGlenn Barry #define gssint_get_der_length get_der_length
26ba7b222eSGlenn Barry #define gssint_put_der_length put_der_length
27ba7b222eSGlenn Barry #define gssint_get_mechanism __gss_get_mechanism
28ba7b222eSGlenn Barry #define gssint_get_mechanism_cred __gss_get_mechanism_cred
29ba7b222eSGlenn Barry #define gssint_copy_oid_set gss_copy_oid_set
30ba7b222eSGlenn Barry #define gssint_get_mech_type __gss_get_mech_type
31ba7b222eSGlenn Barry #define gssint_export_internal_name __gss_export_internal_name
32ba7b222eSGlenn Barry #define gssint_release_internal_name __gss_release_internal_name
33ba7b222eSGlenn Barry #define gssint_convert_name_to_union_name __gss_convert_name_to_union_name
34ba7b222eSGlenn Barry #define gssint_import_internal_name __gss_import_internal_name
35ba7b222eSGlenn Barry #define gssint_display_internal_name __gss_display_internal_name
36ba7b222eSGlenn Barry
37ba7b222eSGlenn Barry
387c478bd9Sstevel@tonic-gate #define MSO_BIT (8*(sizeof (int) - 1)) /* Most significant octet bit */
397c478bd9Sstevel@tonic-gate
40ba7b222eSGlenn Barry extern gss_mechanism *gssint_mechs_array;
41ba7b222eSGlenn Barry
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * This file contains the support routines for the glue layer.
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate * get_der_length: Givin a pointer to a buffer that contains a DER encoded
487c478bd9Sstevel@tonic-gate * length, decode the length updating the buffer to point to the character
497c478bd9Sstevel@tonic-gate * after the DER encoding. The parameter bytes will point to the number of
507c478bd9Sstevel@tonic-gate * bytes that made up the DER encoding of the length originally pointed to
517c478bd9Sstevel@tonic-gate * by the buffer. Note we return -1 on error.
527c478bd9Sstevel@tonic-gate */
537c478bd9Sstevel@tonic-gate int
gssint_get_der_length(unsigned char ** buf,unsigned int buf_len,unsigned int * bytes)54ba7b222eSGlenn Barry gssint_get_der_length(unsigned char **buf, unsigned int buf_len, unsigned int *bytes)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate /* p points to the beginning of the buffer */
577c478bd9Sstevel@tonic-gate unsigned char *p = *buf;
587c478bd9Sstevel@tonic-gate int length, new_length;
59ba7b222eSGlenn Barry unsigned int octets;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate if (buf_len < 1)
627c478bd9Sstevel@tonic-gate return (-1);
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate /* We should have at least one byte */
657c478bd9Sstevel@tonic-gate *bytes = 1;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate * If the High order bit is not set then the length is just the value
697c478bd9Sstevel@tonic-gate * of *p.
707c478bd9Sstevel@tonic-gate */
717c478bd9Sstevel@tonic-gate if (*p < 128) {
727c478bd9Sstevel@tonic-gate *buf = p+1; /* Advance the buffer */
737c478bd9Sstevel@tonic-gate return (*p); /* return the length */
747c478bd9Sstevel@tonic-gate }
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate * if the High order bit is set, then the low order bits represent
787c478bd9Sstevel@tonic-gate * the number of bytes that contain the DER encoding of the length.
797c478bd9Sstevel@tonic-gate */
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate octets = *p++ & 0x7f;
827c478bd9Sstevel@tonic-gate *bytes += octets;
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate /* See if the supplied buffer contains enough bytes for the length. */
857c478bd9Sstevel@tonic-gate if (octets > buf_len - 1)
867c478bd9Sstevel@tonic-gate return (-1);
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate * Calculate a multibyte length. The length is encoded as an
907c478bd9Sstevel@tonic-gate * unsigned integer base 256.
917c478bd9Sstevel@tonic-gate */
927c478bd9Sstevel@tonic-gate for (length = 0; octets; octets--) {
937c478bd9Sstevel@tonic-gate new_length = (length << 8) + *p++;
947c478bd9Sstevel@tonic-gate if (new_length < length) /* overflow */
957c478bd9Sstevel@tonic-gate return (-1);
967c478bd9Sstevel@tonic-gate length = new_length;
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate *buf = p; /* Advance the buffer */
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate return (length);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate * der_length_size: Return the number of bytes to encode a given length.
1067c478bd9Sstevel@tonic-gate */
1077c478bd9Sstevel@tonic-gate unsigned int
gssint_der_length_size(unsigned int len)108ba7b222eSGlenn Barry gssint_der_length_size(unsigned int len)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate int i;
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate if (len < 128)
1137c478bd9Sstevel@tonic-gate return (1);
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate for (i = 0; len; i++) {
1167c478bd9Sstevel@tonic-gate len >>= 8;
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate return (i+1);
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate * put_der_length: Encode the supplied length into the buffer pointed to
1247c478bd9Sstevel@tonic-gate * by buf. max_length represents the maximum length of the buffer pointed
1257c478bd9Sstevel@tonic-gate * to by buff. We will advance buf to point to the character after the newly
1267c478bd9Sstevel@tonic-gate * DER encoded length. We return 0 on success or -l it the length cannot
1277c478bd9Sstevel@tonic-gate * be encoded in max_len characters.
1287c478bd9Sstevel@tonic-gate */
1297c478bd9Sstevel@tonic-gate int
gssint_put_der_length(unsigned int length,unsigned char ** buf,unsigned int max_len)130ba7b222eSGlenn Barry gssint_put_der_length(unsigned int length, unsigned char **buf, unsigned int max_len)
1317c478bd9Sstevel@tonic-gate {
132ba7b222eSGlenn Barry unsigned char *s, *p;
1337c478bd9Sstevel@tonic-gate unsigned int buf_len = 0;
1347c478bd9Sstevel@tonic-gate int i, first;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /* Oops */
1377c478bd9Sstevel@tonic-gate if (buf == 0 || max_len < 1)
1387c478bd9Sstevel@tonic-gate return (-1);
1397c478bd9Sstevel@tonic-gate
140ba7b222eSGlenn Barry s = *buf;
141ba7b222eSGlenn Barry
1427c478bd9Sstevel@tonic-gate /* Single byte is the length */
1437c478bd9Sstevel@tonic-gate if (length < 128) {
1447c478bd9Sstevel@tonic-gate *s++ = length;
1457c478bd9Sstevel@tonic-gate *buf = s;
1467c478bd9Sstevel@tonic-gate return (0);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /* First byte contains the number of octets */
1507c478bd9Sstevel@tonic-gate p = s + 1;
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate /* Running total of the DER encoding length */
1537c478bd9Sstevel@tonic-gate buf_len = 0;
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate * Encode MSB first. We do the encoding by setting a shift
1577c478bd9Sstevel@tonic-gate * factor to MSO_BIT (24 for 32 bit words) and then shifting the length
1587c478bd9Sstevel@tonic-gate * by the factor. We then encode the resulting low order byte.
1597c478bd9Sstevel@tonic-gate * We subtract 8 from the shift factor and repeat to ecnode the next
1607c478bd9Sstevel@tonic-gate * byte. We stop when the shift factor is zero or we've run out of
1617c478bd9Sstevel@tonic-gate * buffer to encode into.
1627c478bd9Sstevel@tonic-gate */
1637c478bd9Sstevel@tonic-gate first = 0;
1647c478bd9Sstevel@tonic-gate for (i = MSO_BIT; i >= 0 && buf_len <= max_len; i -= 8) {
1657c478bd9Sstevel@tonic-gate unsigned int v;
1667c478bd9Sstevel@tonic-gate v = (length >> i) & 0xff;
1677c478bd9Sstevel@tonic-gate if ((v) || first) {
1687c478bd9Sstevel@tonic-gate buf_len += 1;
1697c478bd9Sstevel@tonic-gate *p++ = v;
1707c478bd9Sstevel@tonic-gate first = 1;
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate if (i >= 0) /* buffer overflow */
1747c478bd9Sstevel@tonic-gate return (-1);
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate * We go back now and set the first byte to be the length with
1787c478bd9Sstevel@tonic-gate * the high order bit set.
1797c478bd9Sstevel@tonic-gate */
1807c478bd9Sstevel@tonic-gate *s = buf_len | 0x80;
1817c478bd9Sstevel@tonic-gate *buf = p;
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate return (0);
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate * glue routine for get_mech_type
1897c478bd9Sstevel@tonic-gate *
1907c478bd9Sstevel@tonic-gate */
191ba7b222eSGlenn Barry
gssint_get_mech_type_oid(OID,token)192ba7b222eSGlenn Barry OM_uint32 gssint_get_mech_type_oid(OID, token)
1937c478bd9Sstevel@tonic-gate gss_OID OID;
194ba7b222eSGlenn Barry gss_buffer_t token;
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate unsigned char * buffer_ptr;
1977c478bd9Sstevel@tonic-gate int length;
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate /*
2007c478bd9Sstevel@tonic-gate * This routine reads the prefix of "token" in order to determine
2017c478bd9Sstevel@tonic-gate * its mechanism type. It assumes the encoding suggested in
2027c478bd9Sstevel@tonic-gate * Appendix B of RFC 1508. This format starts out as follows :
2037c478bd9Sstevel@tonic-gate *
2047c478bd9Sstevel@tonic-gate * tag for APPLICATION 0, Sequence[constructed, definite length]
2057c478bd9Sstevel@tonic-gate * length of remainder of token
2067c478bd9Sstevel@tonic-gate * tag of OBJECT IDENTIFIER
2077c478bd9Sstevel@tonic-gate * length of mechanism OID
2087c478bd9Sstevel@tonic-gate * encoding of mechanism OID
2097c478bd9Sstevel@tonic-gate * <the rest of the token>
2107c478bd9Sstevel@tonic-gate *
2117c478bd9Sstevel@tonic-gate * Numerically, this looks like :
2127c478bd9Sstevel@tonic-gate *
2137c478bd9Sstevel@tonic-gate * 0x60
2147c478bd9Sstevel@tonic-gate * <length> - could be multiple bytes
2157c478bd9Sstevel@tonic-gate * 0x06
2167c478bd9Sstevel@tonic-gate * <length> - assume only one byte, hence OID length < 127
2177c478bd9Sstevel@tonic-gate * <mech OID bytes>
2187c478bd9Sstevel@tonic-gate *
2197c478bd9Sstevel@tonic-gate * The routine fills in the OID value and returns an error as necessary.
2207c478bd9Sstevel@tonic-gate */
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate if (OID == NULL)
2237c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_WRITE);
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate if ((token == NULL) || (token->value == NULL))
2267c478bd9Sstevel@tonic-gate return (GSS_S_DEFECTIVE_TOKEN);
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate /* Skip past the APP/Sequnce byte and the token length */
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate buffer_ptr = (unsigned char *) token->value;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate if (*(buffer_ptr++) != 0x60)
2337c478bd9Sstevel@tonic-gate return (GSS_S_DEFECTIVE_TOKEN);
2347c478bd9Sstevel@tonic-gate length = *buffer_ptr++;
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate /* check if token length is null */
2377c478bd9Sstevel@tonic-gate if (length == 0)
2387c478bd9Sstevel@tonic-gate return (GSS_S_DEFECTIVE_TOKEN);
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate if (length & 0x80) {
2417c478bd9Sstevel@tonic-gate if ((length & 0x7f) > 4)
2427c478bd9Sstevel@tonic-gate return (GSS_S_DEFECTIVE_TOKEN);
2437c478bd9Sstevel@tonic-gate buffer_ptr += length & 0x7f;
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate if (*(buffer_ptr++) != 0x06)
2477c478bd9Sstevel@tonic-gate return (GSS_S_DEFECTIVE_TOKEN);
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate OID->length = (OM_uint32) *(buffer_ptr++);
2507c478bd9Sstevel@tonic-gate OID->elements = (void *) buffer_ptr;
2517c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE);
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate
254ba7b222eSGlenn Barry /*
255ba7b222eSGlenn Barry * The following mechanisms do not always identify themselves
256ba7b222eSGlenn Barry * per the GSS-API specification, when interoperating with MS
257ba7b222eSGlenn Barry * peers. We include the OIDs here so we do not have to link
258ba7b222eSGlenn Barry * with the mechanism.
259ba7b222eSGlenn Barry */
260*80ac04ddSGordon Ross static const gss_OID_desc gss_ntlm_mechanism_oid_desc =
261*80ac04ddSGordon Ross {10, "\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a"};
262*80ac04ddSGordon Ross static const gss_OID_desc gss_spnego_mechanism_oid_desc =
263*80ac04ddSGordon Ross {6, "\x2b\x06\x01\x05\x05\x02"};
264*80ac04ddSGordon Ross static const gss_OID_desc gss_krb5_mechanism_oid_desc =
265*80ac04ddSGordon Ross {9, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02"};
266*80ac04ddSGordon Ross const gss_OID_desc * const gss_mech_krb5 =
267*80ac04ddSGordon Ross &gss_krb5_mechanism_oid_desc;
268ba7b222eSGlenn Barry
269ba7b222eSGlenn Barry #define NTLMSSP_SIGNATURE "NTLMSSP"
270ba7b222eSGlenn Barry
gssint_get_mech_type(OID,token)271ba7b222eSGlenn Barry OM_uint32 gssint_get_mech_type(OID, token)
272ba7b222eSGlenn Barry gss_OID OID;
273ba7b222eSGlenn Barry gss_buffer_t token;
274ba7b222eSGlenn Barry {
275ba7b222eSGlenn Barry /* Check for interoperability exceptions */
276ba7b222eSGlenn Barry if (token->length >= sizeof(NTLMSSP_SIGNATURE) &&
277ba7b222eSGlenn Barry memcmp(token->value, NTLMSSP_SIGNATURE,
278ba7b222eSGlenn Barry sizeof(NTLMSSP_SIGNATURE)) == 0) {
279ba7b222eSGlenn Barry *OID = gss_ntlm_mechanism_oid_desc;
280ba7b222eSGlenn Barry } else if (token->length != 0 &&
281ba7b222eSGlenn Barry ((char *)token->value)[0] == 0x6E) {
282ba7b222eSGlenn Barry /* Could be a raw AP-REQ (check for APPLICATION tag) */
283ba7b222eSGlenn Barry *OID = gss_krb5_mechanism_oid_desc;
284ba7b222eSGlenn Barry } else if (token->length == 0) {
285ba7b222eSGlenn Barry *OID = gss_spnego_mechanism_oid_desc;
286ba7b222eSGlenn Barry } else {
287ba7b222eSGlenn Barry return gssint_get_mech_type_oid(OID, token);
288ba7b222eSGlenn Barry }
289ba7b222eSGlenn Barry
290ba7b222eSGlenn Barry return (GSS_S_COMPLETE);
291ba7b222eSGlenn Barry }
292ba7b222eSGlenn Barry
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate /*
2957c478bd9Sstevel@tonic-gate * Internal routines to get and release an internal mechanism name
2967c478bd9Sstevel@tonic-gate */
297ba7b222eSGlenn Barry
298ba7b222eSGlenn Barry #if 0 /* SUNW17PACresync */
299ba7b222eSGlenn Barry #include "mglueP.h"
300ba7b222eSGlenn Barry #endif
301ba7b222eSGlenn Barry
gssint_import_internal_name(minor_status,mech_type,union_name,internal_name)302ba7b222eSGlenn Barry OM_uint32 gssint_import_internal_name (minor_status, mech_type, union_name,
3037c478bd9Sstevel@tonic-gate internal_name)
3047c478bd9Sstevel@tonic-gate OM_uint32 *minor_status;
305ba7b222eSGlenn Barry gss_OID mech_type;
3067c478bd9Sstevel@tonic-gate gss_union_name_t union_name;
3077c478bd9Sstevel@tonic-gate gss_name_t *internal_name;
3087c478bd9Sstevel@tonic-gate {
3097c478bd9Sstevel@tonic-gate OM_uint32 status;
3107c478bd9Sstevel@tonic-gate gss_mechanism mech;
3117c478bd9Sstevel@tonic-gate
312ba7b222eSGlenn Barry mech = gssint_get_mechanism (mech_type);
3137c478bd9Sstevel@tonic-gate if (mech) {
314ba7b222eSGlenn Barry if (mech->gss_import_name) {
3157c478bd9Sstevel@tonic-gate status = mech->gss_import_name (
316ba7b222eSGlenn Barry mech->context, /* SUNW17PACresync */
3177c478bd9Sstevel@tonic-gate minor_status,
3187c478bd9Sstevel@tonic-gate union_name->external_name,
3197c478bd9Sstevel@tonic-gate union_name->name_type,
3207c478bd9Sstevel@tonic-gate internal_name);
321ba7b222eSGlenn Barry if (status != GSS_S_COMPLETE)
322ba7b222eSGlenn Barry map_error(minor_status, mech);
323ba7b222eSGlenn Barry } else
3247c478bd9Sstevel@tonic-gate status = GSS_S_UNAVAILABLE;
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate return (status);
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate return (GSS_S_BAD_MECH);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate
gssint_export_internal_name(minor_status,mech_type,internal_name,name_buf)332ba7b222eSGlenn Barry OM_uint32 gssint_export_internal_name(minor_status, mech_type,
3337c478bd9Sstevel@tonic-gate internal_name, name_buf)
3347c478bd9Sstevel@tonic-gate OM_uint32 *minor_status;
3357c478bd9Sstevel@tonic-gate const gss_OID mech_type;
3367c478bd9Sstevel@tonic-gate const gss_name_t internal_name;
3377c478bd9Sstevel@tonic-gate gss_buffer_t name_buf;
3387c478bd9Sstevel@tonic-gate {
3397c478bd9Sstevel@tonic-gate OM_uint32 status;
3407c478bd9Sstevel@tonic-gate gss_mechanism mech;
3417c478bd9Sstevel@tonic-gate gss_buffer_desc dispName;
3427c478bd9Sstevel@tonic-gate gss_OID nameOid;
3437c478bd9Sstevel@tonic-gate unsigned char *buf = NULL;
3447c478bd9Sstevel@tonic-gate const unsigned char tokId[] = "\x04\x01";
345ba7b222eSGlenn Barry const unsigned int tokIdLen = 2;
3467c478bd9Sstevel@tonic-gate const int mechOidLenLen = 2, mechOidTagLen = 1, nameLenLen = 4;
3477c478bd9Sstevel@tonic-gate int mechOidDERLen = 0;
3487c478bd9Sstevel@tonic-gate int mechOidLen = 0;
3497c478bd9Sstevel@tonic-gate
350ba7b222eSGlenn Barry mech = gssint_get_mechanism(mech_type);
3517c478bd9Sstevel@tonic-gate if (!mech)
3527c478bd9Sstevel@tonic-gate return (GSS_S_BAD_MECH);
3537c478bd9Sstevel@tonic-gate
354ba7b222eSGlenn Barry if (mech->gss_export_name) {
355ba7b222eSGlenn Barry status = mech->gss_export_name(
356ba7b222eSGlenn Barry mech->context, /* SUNW17PACresync */
3577c478bd9Sstevel@tonic-gate minor_status,
3587c478bd9Sstevel@tonic-gate internal_name,
359ba7b222eSGlenn Barry name_buf);
360ba7b222eSGlenn Barry if (status != GSS_S_COMPLETE)
361ba7b222eSGlenn Barry map_error(minor_status, mech);
362ba7b222eSGlenn Barry return status;
363ba7b222eSGlenn Barry }
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate * if we are here it is because the mechanism does not provide
3677c478bd9Sstevel@tonic-gate * a gss_export_name so we will use our implementation. We
3687c478bd9Sstevel@tonic-gate * do required that the mechanism define a gss_display_name.
3697c478bd9Sstevel@tonic-gate */
3707c478bd9Sstevel@tonic-gate if (!mech->gss_display_name)
3717c478bd9Sstevel@tonic-gate return (GSS_S_UNAVAILABLE);
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate /*
3747c478bd9Sstevel@tonic-gate * NOTE: RFC2743 (section 3.2) governs the format of the outer
3757c478bd9Sstevel@tonic-gate * wrapper of exported names; the mechanisms' specs govern
3767c478bd9Sstevel@tonic-gate * the format of the inner portion of the exported name
3777c478bd9Sstevel@tonic-gate * and, for some (e.g., RFC1964, the Kerberos V mech), a
3787c478bd9Sstevel@tonic-gate * generic default as implemented here will do.
3797c478bd9Sstevel@tonic-gate *
3807c478bd9Sstevel@tonic-gate * The outer wrapper of an exported MN is: 2-octet tok Id
3817c478bd9Sstevel@tonic-gate * (0x0401) + 2-octet network-byte order mech OID length + mech
3827c478bd9Sstevel@tonic-gate * oid (in DER format, including DER tag and DER length) +
3837c478bd9Sstevel@tonic-gate * 4-octet network-byte order length of inner portion + inner
3847c478bd9Sstevel@tonic-gate * portion.
3857c478bd9Sstevel@tonic-gate *
3867c478bd9Sstevel@tonic-gate * For the Kerberos V mechanism the inner portion of an exported
3877c478bd9Sstevel@tonic-gate * MN is the display name string and ignores the name type OID
3887c478bd9Sstevel@tonic-gate * altogether. And we hope this will be so for any future
3897c478bd9Sstevel@tonic-gate * mechanisms also, so that factoring name export/import out of
3907c478bd9Sstevel@tonic-gate * the mech and into libgss pays off.
3917c478bd9Sstevel@tonic-gate */
392ba7b222eSGlenn Barry if ((status = mech->gss_display_name(
393ba7b222eSGlenn Barry mech->context,
3947c478bd9Sstevel@tonic-gate minor_status,
3957c478bd9Sstevel@tonic-gate internal_name,
3967c478bd9Sstevel@tonic-gate &dispName,
3977c478bd9Sstevel@tonic-gate &nameOid))
398ba7b222eSGlenn Barry != GSS_S_COMPLETE) {
399ba7b222eSGlenn Barry map_error(minor_status, mech);
4007c478bd9Sstevel@tonic-gate return (status);
401ba7b222eSGlenn Barry }
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate /* determine the size of the buffer needed */
404ba7b222eSGlenn Barry mechOidDERLen = gssint_der_length_size(mech_type->length);
4057c478bd9Sstevel@tonic-gate name_buf->length = tokIdLen + mechOidLenLen +
4067c478bd9Sstevel@tonic-gate mechOidTagLen + mechOidDERLen +
4077c478bd9Sstevel@tonic-gate mech_type->length +
4087c478bd9Sstevel@tonic-gate nameLenLen + dispName.length;
4097c478bd9Sstevel@tonic-gate if ((name_buf->value = (void*)malloc(name_buf->length)) ==
4107c478bd9Sstevel@tonic-gate (void*)NULL) {
4117c478bd9Sstevel@tonic-gate name_buf->length = 0;
4127c478bd9Sstevel@tonic-gate (void) gss_release_buffer(&status, &dispName);
4137c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE);
4147c478bd9Sstevel@tonic-gate }
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate /* now create the name ..... */
4177c478bd9Sstevel@tonic-gate buf = (unsigned char *)name_buf->value;
4187c478bd9Sstevel@tonic-gate (void) memset(name_buf->value, 0, name_buf->length);
4197c478bd9Sstevel@tonic-gate (void) memcpy(buf, tokId, tokIdLen);
4207c478bd9Sstevel@tonic-gate buf += tokIdLen;
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate /* spec allows only 2 bytes for the mech oid length */
4237c478bd9Sstevel@tonic-gate mechOidLen = mechOidDERLen + mechOidTagLen + mech_type->length;
424ba7b222eSGlenn Barry store_16_be(mechOidLen, buf);
425ba7b222eSGlenn Barry buf += 2;
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate /*
4287c478bd9Sstevel@tonic-gate * DER Encoding of mech OID contains OID Tag (0x06), length and
4297c478bd9Sstevel@tonic-gate * mech OID value
4307c478bd9Sstevel@tonic-gate */
4317c478bd9Sstevel@tonic-gate *buf++ = 0x06;
432ba7b222eSGlenn Barry if (gssint_put_der_length(mech_type->length, &buf,
4337c478bd9Sstevel@tonic-gate (name_buf->length - tokIdLen -2)) != 0) {
4347c478bd9Sstevel@tonic-gate name_buf->length = 0;
4357c478bd9Sstevel@tonic-gate free(name_buf->value);
4367c478bd9Sstevel@tonic-gate (void) gss_release_buffer(&status, &dispName);
4377c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE);
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate (void) memcpy(buf, mech_type->elements, mech_type->length);
4417c478bd9Sstevel@tonic-gate buf += mech_type->length;
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate /* spec designates the next 4 bytes for the name length */
444ba7b222eSGlenn Barry store_32_be(dispName.length, buf);
445ba7b222eSGlenn Barry buf += 4;
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate /* for the final ingredient - add the name from gss_display_name */
4487c478bd9Sstevel@tonic-gate (void) memcpy(buf, dispName.value, dispName.length);
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate /* release the buffer obtained from gss_display_name */
4517c478bd9Sstevel@tonic-gate (void) gss_release_buffer(minor_status, &dispName);
4527c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE);
453ba7b222eSGlenn Barry } /* gssint_export_internal_name */
4547c478bd9Sstevel@tonic-gate
gssint_display_internal_name(minor_status,mech_type,internal_name,external_name,name_type)455ba7b222eSGlenn Barry OM_uint32 gssint_display_internal_name (minor_status, mech_type, internal_name,
4567c478bd9Sstevel@tonic-gate external_name, name_type)
4577c478bd9Sstevel@tonic-gate OM_uint32 *minor_status;
458ba7b222eSGlenn Barry gss_OID mech_type;
459ba7b222eSGlenn Barry gss_name_t internal_name;
4607c478bd9Sstevel@tonic-gate gss_buffer_t external_name;
4617c478bd9Sstevel@tonic-gate gss_OID *name_type;
4627c478bd9Sstevel@tonic-gate {
4637c478bd9Sstevel@tonic-gate OM_uint32 status;
4647c478bd9Sstevel@tonic-gate gss_mechanism mech;
4657c478bd9Sstevel@tonic-gate
466ba7b222eSGlenn Barry mech = gssint_get_mechanism (mech_type);
4677c478bd9Sstevel@tonic-gate if (mech) {
468ba7b222eSGlenn Barry if (mech->gss_display_name) {
4697c478bd9Sstevel@tonic-gate status = mech->gss_display_name (
4707c478bd9Sstevel@tonic-gate mech->context,
4717c478bd9Sstevel@tonic-gate minor_status,
4727c478bd9Sstevel@tonic-gate internal_name,
4737c478bd9Sstevel@tonic-gate external_name,
4747c478bd9Sstevel@tonic-gate name_type);
475ba7b222eSGlenn Barry if (status != GSS_S_COMPLETE)
476ba7b222eSGlenn Barry map_error(minor_status, mech);
477ba7b222eSGlenn Barry } else
4787c478bd9Sstevel@tonic-gate status = GSS_S_UNAVAILABLE;
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate return (status);
4817c478bd9Sstevel@tonic-gate }
4827c478bd9Sstevel@tonic-gate
4837c478bd9Sstevel@tonic-gate return (GSS_S_BAD_MECH);
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate
gssint_release_internal_name(minor_status,mech_type,internal_name)486ba7b222eSGlenn Barry OM_uint32 gssint_release_internal_name (minor_status, mech_type, internal_name)
4877c478bd9Sstevel@tonic-gate OM_uint32 *minor_status;
488ba7b222eSGlenn Barry gss_OID mech_type;
4897c478bd9Sstevel@tonic-gate gss_name_t *internal_name;
4907c478bd9Sstevel@tonic-gate {
4917c478bd9Sstevel@tonic-gate OM_uint32 status;
4927c478bd9Sstevel@tonic-gate gss_mechanism mech;
4937c478bd9Sstevel@tonic-gate
494ba7b222eSGlenn Barry mech = gssint_get_mechanism (mech_type);
4957c478bd9Sstevel@tonic-gate if (mech) {
496ba7b222eSGlenn Barry if (mech->gss_release_name) {
4977c478bd9Sstevel@tonic-gate status = mech->gss_release_name (
4987c478bd9Sstevel@tonic-gate mech->context,
4997c478bd9Sstevel@tonic-gate minor_status,
5007c478bd9Sstevel@tonic-gate internal_name);
501ba7b222eSGlenn Barry if (status != GSS_S_COMPLETE)
502ba7b222eSGlenn Barry map_error(minor_status, mech);
503ba7b222eSGlenn Barry } else
5047c478bd9Sstevel@tonic-gate status = GSS_S_UNAVAILABLE;
5057c478bd9Sstevel@tonic-gate
5067c478bd9Sstevel@tonic-gate return (status);
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate
5097c478bd9Sstevel@tonic-gate return (GSS_S_BAD_MECH);
5107c478bd9Sstevel@tonic-gate }
5117c478bd9Sstevel@tonic-gate
gssint_delete_internal_sec_context(minor_status,mech_type,internal_ctx,output_token)512ba7b222eSGlenn Barry OM_uint32 gssint_delete_internal_sec_context (minor_status,
513ba7b222eSGlenn Barry mech_type,
514ba7b222eSGlenn Barry internal_ctx,
515ba7b222eSGlenn Barry output_token)
516ba7b222eSGlenn Barry OM_uint32 *minor_status;
517ba7b222eSGlenn Barry gss_OID mech_type;
518ba7b222eSGlenn Barry gss_ctx_id_t *internal_ctx;
519ba7b222eSGlenn Barry gss_buffer_t output_token;
520ba7b222eSGlenn Barry {
521ba7b222eSGlenn Barry OM_uint32 status;
522ba7b222eSGlenn Barry gss_mechanism mech;
523ba7b222eSGlenn Barry
524ba7b222eSGlenn Barry mech = gssint_get_mechanism (mech_type);
525ba7b222eSGlenn Barry if (mech) {
526ba7b222eSGlenn Barry if (mech->gss_delete_sec_context)
527ba7b222eSGlenn Barry status = mech->gss_delete_sec_context (
528ba7b222eSGlenn Barry mech->context, /* SUNW17PACresync */
529ba7b222eSGlenn Barry minor_status,
530ba7b222eSGlenn Barry internal_ctx,
531ba7b222eSGlenn Barry output_token);
532ba7b222eSGlenn Barry else
533ba7b222eSGlenn Barry /* SUNW17PACresync - map error here? */
534ba7b222eSGlenn Barry status = GSS_S_UNAVAILABLE;
535ba7b222eSGlenn Barry
536ba7b222eSGlenn Barry return (status);
537ba7b222eSGlenn Barry }
538ba7b222eSGlenn Barry
539ba7b222eSGlenn Barry return (GSS_S_BAD_MECH);
540ba7b222eSGlenn Barry }
5417c478bd9Sstevel@tonic-gate
5427c478bd9Sstevel@tonic-gate /*
5437c478bd9Sstevel@tonic-gate * This function converts an internal gssapi name to a union gssapi
5447c478bd9Sstevel@tonic-gate * name. Note that internal_name should be considered "consumed" by
5457c478bd9Sstevel@tonic-gate * this call, whether or not we return an error.
5467c478bd9Sstevel@tonic-gate */
gssint_convert_name_to_union_name(minor_status,mech,internal_name,external_name)547ba7b222eSGlenn Barry OM_uint32 gssint_convert_name_to_union_name(minor_status, mech,
5487c478bd9Sstevel@tonic-gate internal_name, external_name)
5497c478bd9Sstevel@tonic-gate OM_uint32 *minor_status;
5507c478bd9Sstevel@tonic-gate gss_mechanism mech;
5517c478bd9Sstevel@tonic-gate gss_name_t internal_name;
5527c478bd9Sstevel@tonic-gate gss_name_t *external_name;
5537c478bd9Sstevel@tonic-gate {
5547c478bd9Sstevel@tonic-gate OM_uint32 major_status,tmp;
5557c478bd9Sstevel@tonic-gate gss_union_name_t union_name;
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate union_name = (gss_union_name_t) malloc (sizeof(gss_union_name_desc));
5587c478bd9Sstevel@tonic-gate if (!union_name) {
559ba7b222eSGlenn Barry major_status = GSS_S_FAILURE;
560ba7b222eSGlenn Barry *minor_status = ENOMEM;
561ba7b222eSGlenn Barry map_errcode(minor_status);
5627c478bd9Sstevel@tonic-gate goto allocation_failure;
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate union_name->mech_type = 0;
5657c478bd9Sstevel@tonic-gate union_name->mech_name = internal_name;
5667c478bd9Sstevel@tonic-gate union_name->name_type = 0;
5677c478bd9Sstevel@tonic-gate union_name->external_name = 0;
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate major_status = generic_gss_copy_oid(minor_status, &mech->mech_type,
5707c478bd9Sstevel@tonic-gate &union_name->mech_type);
571ba7b222eSGlenn Barry if (major_status != GSS_S_COMPLETE) {
572ba7b222eSGlenn Barry map_errcode(minor_status);
5737c478bd9Sstevel@tonic-gate goto allocation_failure;
574ba7b222eSGlenn Barry }
5757c478bd9Sstevel@tonic-gate
5767c478bd9Sstevel@tonic-gate union_name->external_name =
5777c478bd9Sstevel@tonic-gate (gss_buffer_t) malloc(sizeof(gss_buffer_desc));
5787c478bd9Sstevel@tonic-gate if (!union_name->external_name) {
579ba7b222eSGlenn Barry major_status = GSS_S_FAILURE;
580ba7b222eSGlenn Barry *minor_status = ENOMEM;
5817c478bd9Sstevel@tonic-gate goto allocation_failure;
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate
584cc35afbcSMark Phalan union_name->external_name->length = 0;
585cc35afbcSMark Phalan union_name->external_name->value = 0;
586cc35afbcSMark Phalan
587ba7b222eSGlenn Barry major_status = mech->gss_display_name(
588ba7b222eSGlenn Barry mech->context, /* SUNW17PACresync */
589ba7b222eSGlenn Barry minor_status,
5907c478bd9Sstevel@tonic-gate internal_name,
5917c478bd9Sstevel@tonic-gate union_name->external_name,
5927c478bd9Sstevel@tonic-gate &union_name->name_type);
593ba7b222eSGlenn Barry if (major_status != GSS_S_COMPLETE) {
594ba7b222eSGlenn Barry map_error(minor_status, mech);
5957c478bd9Sstevel@tonic-gate goto allocation_failure;
596ba7b222eSGlenn Barry }
5977c478bd9Sstevel@tonic-gate
598ba7b222eSGlenn Barry union_name->loopback = union_name;
5997c478bd9Sstevel@tonic-gate *external_name = (gss_name_t) union_name;
6007c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE);
6017c478bd9Sstevel@tonic-gate
6027c478bd9Sstevel@tonic-gate allocation_failure:
6037c478bd9Sstevel@tonic-gate if (union_name) {
6047c478bd9Sstevel@tonic-gate if (union_name->external_name) {
6057c478bd9Sstevel@tonic-gate if (union_name->external_name->value)
6067c478bd9Sstevel@tonic-gate free(union_name->external_name->value);
6077c478bd9Sstevel@tonic-gate free(union_name->external_name);
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate if (union_name->name_type)
6107c478bd9Sstevel@tonic-gate (void) gss_release_oid(&tmp, &union_name->name_type);
6117c478bd9Sstevel@tonic-gate if (union_name->mech_type)
6127c478bd9Sstevel@tonic-gate (void) gss_release_oid(&tmp, &union_name->mech_type);
6137c478bd9Sstevel@tonic-gate free(union_name);
6147c478bd9Sstevel@tonic-gate }
6157c478bd9Sstevel@tonic-gate /*
6167c478bd9Sstevel@tonic-gate * do as the top comment says - since we are now owners of
6177c478bd9Sstevel@tonic-gate * internal_name, we must clean it up
6187c478bd9Sstevel@tonic-gate */
6197c478bd9Sstevel@tonic-gate if (internal_name)
620ba7b222eSGlenn Barry (void) gssint_release_internal_name(&tmp, &mech->mech_type,
6217c478bd9Sstevel@tonic-gate &internal_name);
6227c478bd9Sstevel@tonic-gate return (major_status);
6237c478bd9Sstevel@tonic-gate }
6247c478bd9Sstevel@tonic-gate
6257c478bd9Sstevel@tonic-gate /*
6267c478bd9Sstevel@tonic-gate * Glue routine for returning the mechanism-specific credential from a
6277c478bd9Sstevel@tonic-gate * external union credential.
6287c478bd9Sstevel@tonic-gate */
6297c478bd9Sstevel@tonic-gate gss_cred_id_t
gssint_get_mechanism_cred(union_cred,mech_type)630ba7b222eSGlenn Barry gssint_get_mechanism_cred(union_cred, mech_type)
631ba7b222eSGlenn Barry gss_union_cred_t union_cred;
632ba7b222eSGlenn Barry gss_OID mech_type;
6337c478bd9Sstevel@tonic-gate {
6347c478bd9Sstevel@tonic-gate int i;
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate if (union_cred == (gss_union_cred_t) GSS_C_NO_CREDENTIAL)
637ba7b222eSGlenn Barry return GSS_C_NO_CREDENTIAL;
638ba7b222eSGlenn Barry
639ba7b222eSGlenn Barry /*
640ba7b222eSGlenn Barry * SUNW17PACresync
641ba7b222eSGlenn Barry * Disable this block as it causes problems for gss_add_cred
642ba7b222eSGlenn Barry * for HTTP SSO (and also probably causes STC gss.13 to fail too).
643ba7b222eSGlenn Barry */
644ba7b222eSGlenn Barry #if 0
645ba7b222eSGlenn Barry /* SPNEGO mechanism will again call into GSSAPI */
646ba7b222eSGlenn Barry if (g_OID_equal(&gss_spnego_mechanism_oid_desc, mech_type))
647ba7b222eSGlenn Barry return (gss_cred_id_t)union_cred;
648ba7b222eSGlenn Barry #endif
6497c478bd9Sstevel@tonic-gate
6507c478bd9Sstevel@tonic-gate for (i=0; i < union_cred->count; i++) {
6517c478bd9Sstevel@tonic-gate if (g_OID_equal(mech_type, &union_cred->mechs_array[i]))
652ba7b222eSGlenn Barry return union_cred->cred_array[i];
653ba7b222eSGlenn Barry
654ba7b222eSGlenn Barry /* for SPNEGO, check the next-lower set of creds */
655ba7b222eSGlenn Barry if (g_OID_equal(&gss_spnego_mechanism_oid_desc, &union_cred->mechs_array[i])) {
656ba7b222eSGlenn Barry gss_union_cred_t candidate_cred;
657ba7b222eSGlenn Barry gss_cred_id_t sub_cred;
658ba7b222eSGlenn Barry
659ba7b222eSGlenn Barry candidate_cred = (gss_union_cred_t)union_cred->cred_array[i];
660ba7b222eSGlenn Barry sub_cred = gssint_get_mechanism_cred(candidate_cred, mech_type);
661ba7b222eSGlenn Barry
662ba7b222eSGlenn Barry if(sub_cred != GSS_C_NO_CREDENTIAL)
663ba7b222eSGlenn Barry return sub_cred;
6647c478bd9Sstevel@tonic-gate }
6657c478bd9Sstevel@tonic-gate }
6667c478bd9Sstevel@tonic-gate
667ba7b222eSGlenn Barry return GSS_C_NO_CREDENTIAL;
668ba7b222eSGlenn Barry }
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate /*
6717c478bd9Sstevel@tonic-gate * Routine to create and copy the gss_buffer_desc structure.
6727c478bd9Sstevel@tonic-gate * Both space for the structure and the data is allocated.
6737c478bd9Sstevel@tonic-gate */
6747c478bd9Sstevel@tonic-gate OM_uint32
gssint_create_copy_buffer(srcBuf,destBuf,addNullChar)675ab9b2e15Sgtb gssint_create_copy_buffer(srcBuf, destBuf, addNullChar)
6767c478bd9Sstevel@tonic-gate const gss_buffer_t srcBuf;
6777c478bd9Sstevel@tonic-gate gss_buffer_t *destBuf;
6787c478bd9Sstevel@tonic-gate int addNullChar;
6797c478bd9Sstevel@tonic-gate {
6807c478bd9Sstevel@tonic-gate gss_buffer_t aBuf;
681ba7b222eSGlenn Barry unsigned int len;
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate if (destBuf == NULL)
6847c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_WRITE);
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate *destBuf = 0;
6877c478bd9Sstevel@tonic-gate
6887c478bd9Sstevel@tonic-gate aBuf = (gss_buffer_t)malloc(sizeof (gss_buffer_desc));
6897c478bd9Sstevel@tonic-gate if (!aBuf)
6907c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE);
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate if (addNullChar)
6937c478bd9Sstevel@tonic-gate len = srcBuf->length + 1;
6947c478bd9Sstevel@tonic-gate else
6957c478bd9Sstevel@tonic-gate len = srcBuf->length;
6967c478bd9Sstevel@tonic-gate
6977c478bd9Sstevel@tonic-gate if (!(aBuf->value = (void*)malloc(len))) {
6987c478bd9Sstevel@tonic-gate free(aBuf);
6997c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE);
7007c478bd9Sstevel@tonic-gate }
7017c478bd9Sstevel@tonic-gate
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate (void) memcpy(aBuf->value, srcBuf->value, srcBuf->length);
7047c478bd9Sstevel@tonic-gate aBuf->length = srcBuf->length;
7057c478bd9Sstevel@tonic-gate *destBuf = aBuf;
7067c478bd9Sstevel@tonic-gate
7077c478bd9Sstevel@tonic-gate /* optionally add a NULL character */
7087c478bd9Sstevel@tonic-gate if (addNullChar)
7097c478bd9Sstevel@tonic-gate ((char *)aBuf->value)[aBuf->length] = '\0';
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE);
712ba7b222eSGlenn Barry } /* ****** gssint_create_copy_buffer ****** */
713ba7b222eSGlenn Barry
714