2 * Copyright (c) 1999 Dug Song. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 RCSID("$OpenBSD: radix.c,v 1.16 2001/06/23 15:12:19 itojun Exp $");
35 typedef u_char my_u_char;
36 typedef u_int my_u_int32_t;
37 typedef u_short my_u_short;
39 /* Nasty macros from BIND-4.9.2 */
41 #define GETSHORT(s, cp) { \
42 register my_u_char *t_cp = (my_u_char *)(cp); \
43 (s) = (((my_u_short)t_cp[0]) << 8) \
44 | (((my_u_short)t_cp[1])) \
49 #define GETLONG(l, cp) { \
50 register my_u_char *t_cp = (my_u_char *)(cp); \
51 (l) = (((my_u_int32_t)t_cp[0]) << 24) \
52 | (((my_u_int32_t)t_cp[1]) << 16) \
53 | (((my_u_int32_t)t_cp[2]) << 8) \
54 | (((my_u_int32_t)t_cp[3])) \
59 #define PUTSHORT(s, cp) { \
60 register my_u_short t_s = (my_u_short)(s); \
61 register my_u_char *t_cp = (my_u_char *)(cp); \
67 #define PUTLONG(l, cp) { \
68 register my_u_int32_t t_l = (my_u_int32_t)(l); \
69 register my_u_char *t_cp = (my_u_char *)(cp); \
70 *t_cp++ = t_l >> 24; \
71 *t_cp++ = t_l >> 16; \
77 #define GETSTRING(s, p, p_l) { \
78 register char *p_targ = (p) + p_l; \
79 register char *s_c = (s); \
80 register char *p_c = (p); \
81 while (*p_c && (p_c < p_targ)) { \
84 if (p_c == p_targ) { \
88 (p_l) = (p_l) - (p_c - (p)); \
94 creds_to_radix(CREDENTIALS *creds, u_char *buf, size_t buflen)
101 *p++ = 1; /* version */
123 /* Null string to repeat the realm. */
126 PUTLONG(creds->issue_date, p);
129 endTime = (u_int) krb_life_to_time(creds->issue_date,
134 memcpy(p, &creds->session, sizeof(creds->session));
135 p += sizeof(creds->session);
137 PUTSHORT(creds->kvno, p);
138 PUTLONG(creds->ticket_st.length, p);
140 memcpy(p, creds->ticket_st.dat, creds->ticket_st.length);
141 p += creds->ticket_st.length;
144 return (uuencode((u_char *)temp, len, (char *)buf, buflen));
148 radix_to_creds(const char *buf, CREDENTIALS *creds)
156 len = uudecode(buf, (u_char *)temp, sizeof(temp));
162 /* check version and length! */
169 GETSTRING(creds->service, p, len);
170 GETSTRING(creds->instance, p, len);
171 GETSTRING(creds->realm, p, len);
173 GETSTRING(creds->pname, p, len);
174 GETSTRING(creds->pinst, p, len);
175 /* Ignore possibly different realm. */
182 /* Enough space for remaining fixed-length parts? */
183 if (len < (4 + 4 + sizeof(creds->session) + 2 + 4))
186 GETLONG(creds->issue_date, p);
192 creds->lifetime = krb_time_to_life(creds->issue_date, endTime);
195 memcpy(&creds->session, p, sizeof(creds->session));
196 p += sizeof(creds->session);
197 len -= sizeof(creds->session);
199 GETSHORT(creds->kvno, p);
201 GETLONG(creds->ticket_st.length, p);
204 tl = creds->ticket_st.length;
205 if (tl < 0 || tl > len || tl > sizeof(creds->ticket_st.dat))
208 memcpy(creds->ticket_st.dat, p, tl);