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.
37 #include <gssapi/gssapi.h>
46 gss_oid_to_str(OM_uint32 *minor_status, gss_OID oid, gss_buffer_t oid_str)
57 _gss_buffer_zero(oid_str);
59 if (oid == GSS_C_NULL_OID)
60 return (GSS_S_FAILURE);
62 /* Decoded according to krb5/gssapi_krb5.c */
64 /* First determine the size of the string */
68 cp = (unsigned char *) oid->elements;
69 number = (unsigned long) cp[0];
70 sprintf(numstr, "%ld ", number/40);
71 string_length += strlen(numstr);
72 sprintf(numstr, "%ld ", number%40);
73 string_length += strlen(numstr);
74 for (i=1; i<oid->length; i++) {
75 if ( (size_t) (numshift+7) < (sizeof(unsigned long)*8)) {
76 number = (number << 7) | (cp[i] & 0x7f);
81 return(GSS_S_FAILURE);
83 if ((cp[i] & 0x80) == 0) {
84 sprintf(numstr, "%ld ", number);
85 string_length += strlen(numstr);
91 * If we get here, we've calculated the length of "n n n ... n ".
92 * Add 4 here for "{ " and "}\0".
95 if ((bp = (char *) malloc(string_length))) {
97 number = (unsigned long) cp[0];
98 sprintf(numstr, "%ld ", number/40);
100 sprintf(numstr, "%ld ", number%40);
103 cp = (unsigned char *) oid->elements;
104 for (i=1; i<oid->length; i++) {
105 number = (number << 7) | (cp[i] & 0x7f);
106 if ((cp[i] & 0x80) == 0) {
107 sprintf(numstr, "%ld ", number);
113 oid_str->length = strlen(bp)+1;
114 oid_str->value = (void *) bp;
116 return(GSS_S_COMPLETE);
118 *minor_status = ENOMEM;
119 return(GSS_S_FAILURE);