4 * Dug Song <dugsong@UMICH.EDU>
13 typedef unsigned char my_u_char;
14 typedef unsigned int my_u_int32_t;
15 typedef unsigned short my_u_short;
17 /* Nasty macros from BIND-4.9.2 */
19 #define GETSHORT(s, cp) { \
20 register my_u_char *t_cp = (my_u_char*)(cp); \
21 (s) = (((my_u_short)t_cp[0]) << 8) \
22 | (((my_u_short)t_cp[1])) \
27 #define GETLONG(l, cp) { \
28 register my_u_char *t_cp = (my_u_char*)(cp); \
29 (l) = (((my_u_int32_t)t_cp[0]) << 24) \
30 | (((my_u_int32_t)t_cp[1]) << 16) \
31 | (((my_u_int32_t)t_cp[2]) << 8) \
32 | (((my_u_int32_t)t_cp[3])) \
37 #define PUTSHORT(s, cp) { \
38 register my_u_short t_s = (my_u_short)(s); \
39 register my_u_char *t_cp = (my_u_char*)(cp); \
45 #define PUTLONG(l, cp) { \
46 register my_u_int32_t t_l = (my_u_int32_t)(l); \
47 register my_u_char *t_cp = (my_u_char*)(cp); \
48 *t_cp++ = t_l >> 24; \
49 *t_cp++ = t_l >> 16; \
55 #define GETSTRING(s, p, p_l) { \
56 register char* p_targ = (p) + p_l; \
57 register char* s_c = (s); \
58 register char* p_c = (p); \
59 while (*p_c && (p_c < p_targ)) { \
62 if (p_c == p_targ) { \
66 (p_l) = (p_l) - (p_c - (p)); \
72 creds_to_radix(CREDENTIALS *creds, unsigned char *buf, size_t buflen)
79 *p++ = 1; /* version */
101 /* Null string to repeat the realm. */
104 PUTLONG(creds->issue_date, p);
106 unsigned int endTime;
107 endTime = (unsigned int) krb_life_to_time(creds->issue_date,
112 memcpy(p, &creds->session, sizeof(creds->session));
113 p += sizeof(creds->session);
115 PUTSHORT(creds->kvno, p);
116 PUTLONG(creds->ticket_st.length, p);
118 memcpy(p, creds->ticket_st.dat, creds->ticket_st.length);
119 p += creds->ticket_st.length;
122 return (uuencode((unsigned char *)temp, len, (char *)buf, buflen));
126 radix_to_creds(const char *buf, CREDENTIALS *creds)
134 len = uudecode(buf, (unsigned char *)temp, sizeof(temp));
140 /* check version and length! */
147 GETSTRING(creds->service, p, len);
148 GETSTRING(creds->instance, p, len);
149 GETSTRING(creds->realm, p, len);
151 GETSTRING(creds->pname, p, len);
152 GETSTRING(creds->pinst, p, len);
153 /* Ignore possibly different realm. */
160 /* Enough space for remaining fixed-length parts? */
161 if (len < (4 + 4 + sizeof(creds->session) + 2 + 4))
164 GETLONG(creds->issue_date, p);
167 unsigned int endTime;
170 creds->lifetime = krb_time_to_life(creds->issue_date, endTime);
173 memcpy(&creds->session, p, sizeof(creds->session));
174 p += sizeof(creds->session);
175 len -= sizeof(creds->session);
177 GETSHORT(creds->kvno, p);
179 GETLONG(creds->ticket_st.length, p);
182 tl = creds->ticket_st.length;
183 if (tl < 0 || tl > len || tl > sizeof(creds->ticket_st.dat))
186 memcpy(creds->ticket_st.dat, p, tl);