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