2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2000 The Regents of the University of Michigan.
7 * Copyright (c) 2000 Dug Song <dugsong@UMICH.EDU>.
8 * All rights reserved, all wrongs reversed.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <gssapi/gssapi.h>
45 gss_oid_to_str(OM_uint32 *minor_status, gss_OID oid, gss_buffer_t oid_str)
56 _gss_buffer_zero(oid_str);
58 if (oid == GSS_C_NULL_OID)
59 return (GSS_S_FAILURE);
61 /* Decoded according to krb5/gssapi_krb5.c */
63 /* First determine the size of the string */
67 cp = (unsigned char *) oid->elements;
68 number = (unsigned long) cp[0];
69 sprintf(numstr, "%ld ", number/40);
70 string_length += strlen(numstr);
71 sprintf(numstr, "%ld ", number%40);
72 string_length += strlen(numstr);
73 for (i=1; i<oid->length; i++) {
74 if ( (size_t) (numshift+7) < (sizeof(unsigned long)*8)) {
75 number = (number << 7) | (cp[i] & 0x7f);
80 return(GSS_S_FAILURE);
82 if ((cp[i] & 0x80) == 0) {
83 sprintf(numstr, "%ld ", number);
84 string_length += strlen(numstr);
90 * If we get here, we've calculated the length of "n n n ... n ".
91 * Add 4 here for "{ " and "}\0".
94 if ((bp = (char *) malloc(string_length))) {
96 number = (unsigned long) cp[0];
97 sprintf(numstr, "%ld ", number/40);
99 sprintf(numstr, "%ld ", number%40);
102 cp = (unsigned char *) oid->elements;
103 for (i=1; i<oid->length; i++) {
104 number = (number << 7) | (cp[i] & 0x7f);
105 if ((cp[i] & 0x80) == 0) {
106 sprintf(numstr, "%ld ", number);
112 oid_str->length = strlen(bp)+1;
113 oid_str->value = (void *) bp;
115 return(GSS_S_COMPLETE);
117 *minor_status = ENOMEM;
118 return(GSS_S_FAILURE);