4 * Dug Song <dugsong@UMICH.EDU>
10 RCSID("$OpenBSD: radix.c,v 1.12 2000/06/22 23:55:00 djm Exp $");
15 typedef unsigned char my_u_char;
16 typedef unsigned int my_u_int32_t;
17 typedef unsigned short my_u_short;
19 /* Nasty macros from BIND-4.9.2 */
21 #define GETSHORT(s, cp) { \
22 register my_u_char *t_cp = (my_u_char*)(cp); \
23 (s) = (((my_u_short)t_cp[0]) << 8) \
24 | (((my_u_short)t_cp[1])) \
29 #define GETLONG(l, cp) { \
30 register my_u_char *t_cp = (my_u_char*)(cp); \
31 (l) = (((my_u_int32_t)t_cp[0]) << 24) \
32 | (((my_u_int32_t)t_cp[1]) << 16) \
33 | (((my_u_int32_t)t_cp[2]) << 8) \
34 | (((my_u_int32_t)t_cp[3])) \
39 #define PUTSHORT(s, cp) { \
40 register my_u_short t_s = (my_u_short)(s); \
41 register my_u_char *t_cp = (my_u_char*)(cp); \
47 #define PUTLONG(l, cp) { \
48 register my_u_int32_t t_l = (my_u_int32_t)(l); \
49 register my_u_char *t_cp = (my_u_char*)(cp); \
50 *t_cp++ = t_l >> 24; \
51 *t_cp++ = t_l >> 16; \
57 #define GETSTRING(s, p, p_l) { \
58 register char* p_targ = (p) + p_l; \
59 register char* s_c = (s); \
60 register char* p_c = (p); \
61 while (*p_c && (p_c < p_targ)) { \
64 if (p_c == p_targ) { \
68 (p_l) = (p_l) - (p_c - (p)); \
74 creds_to_radix(CREDENTIALS *creds, unsigned char *buf, size_t buflen)
81 *p++ = 1; /* version */
103 /* Null string to repeat the realm. */
106 PUTLONG(creds->issue_date, p);
108 unsigned int endTime;
109 endTime = (unsigned int) krb_life_to_time(creds->issue_date,
114 memcpy(p, &creds->session, sizeof(creds->session));
115 p += sizeof(creds->session);
117 PUTSHORT(creds->kvno, p);
118 PUTLONG(creds->ticket_st.length, p);
120 memcpy(p, creds->ticket_st.dat, creds->ticket_st.length);
121 p += creds->ticket_st.length;
124 return (uuencode((unsigned char *)temp, len, (char *)buf, buflen));
128 radix_to_creds(const char *buf, CREDENTIALS *creds)
136 len = uudecode(buf, (unsigned char *)temp, sizeof(temp));
142 /* check version and length! */
149 GETSTRING(creds->service, p, len);
150 GETSTRING(creds->instance, p, len);
151 GETSTRING(creds->realm, p, len);
153 GETSTRING(creds->pname, p, len);
154 GETSTRING(creds->pinst, p, len);
155 /* Ignore possibly different realm. */
162 /* Enough space for remaining fixed-length parts? */
163 if (len < (4 + 4 + sizeof(creds->session) + 2 + 4))
166 GETLONG(creds->issue_date, p);
169 unsigned int endTime;
172 creds->lifetime = krb_time_to_life(creds->issue_date, endTime);
175 memcpy(&creds->session, p, sizeof(creds->session));
176 p += sizeof(creds->session);
177 len -= sizeof(creds->session);
179 GETSHORT(creds->kvno, p);
181 GETLONG(creds->ticket_st.length, p);
184 tl = creds->ticket_st.length;
185 if (tl < 0 || tl > len || tl > sizeof(creds->ticket_st.dat))
188 memcpy(creds->ticket_st.dat, p, tl);