diff options
Diffstat (limited to 'other/openssh-reverse/radix.c')
| -rw-r--r-- | other/openssh-reverse/radix.c | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/other/openssh-reverse/radix.c b/other/openssh-reverse/radix.c new file mode 100644 index 0000000..7e668ea --- /dev/null +++ b/other/openssh-reverse/radix.c | |||
| @@ -0,0 +1,194 @@ | |||
| 1 | /* | ||
| 2 | * radix.c | ||
| 3 | * | ||
| 4 | * Dug Song <dugsong@UMICH.EDU> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "includes.h" | ||
| 8 | #include "uuencode.h" | ||
| 9 | |||
| 10 | RCSID("$OpenBSD: radix.c,v 1.12 2000/06/22 23:55:00 djm Exp $"); | ||
| 11 | |||
| 12 | #ifdef AFS | ||
| 13 | #include <krb.h> | ||
| 14 | |||
| 15 | typedef unsigned char my_u_char; | ||
| 16 | typedef unsigned int my_u_int32_t; | ||
| 17 | typedef unsigned short my_u_short; | ||
| 18 | |||
| 19 | /* Nasty macros from BIND-4.9.2 */ | ||
| 20 | |||
| 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])) \ | ||
| 25 | ; \ | ||
| 26 | (cp) += 2; \ | ||
| 27 | } | ||
| 28 | |||
| 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])) \ | ||
| 35 | ; \ | ||
| 36 | (cp) += 4; \ | ||
| 37 | } | ||
| 38 | |||
| 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); \ | ||
| 42 | *t_cp++ = t_s >> 8; \ | ||
| 43 | *t_cp = t_s; \ | ||
| 44 | (cp) += 2; \ | ||
| 45 | } | ||
| 46 | |||
| 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; \ | ||
| 52 | *t_cp++ = t_l >> 8; \ | ||
| 53 | *t_cp = t_l; \ | ||
| 54 | (cp) += 4; \ | ||
| 55 | } | ||
| 56 | |||
| 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)) { \ | ||
| 62 | *s_c++ = *p_c++; \ | ||
| 63 | } \ | ||
| 64 | if (p_c == p_targ) { \ | ||
| 65 | return 1; \ | ||
| 66 | } \ | ||
| 67 | *s_c = *p_c++; \ | ||
| 68 | (p_l) = (p_l) - (p_c - (p)); \ | ||
| 69 | (p) = p_c; \ | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | int | ||
| 74 | creds_to_radix(CREDENTIALS *creds, unsigned char *buf, size_t buflen) | ||
| 75 | { | ||
| 76 | char *p, *s; | ||
| 77 | int len; | ||
| 78 | char temp[2048]; | ||
| 79 | |||
| 80 | p = temp; | ||
| 81 | *p++ = 1; /* version */ | ||
| 82 | s = creds->service; | ||
| 83 | while (*s) | ||
| 84 | *p++ = *s++; | ||
| 85 | *p++ = *s; | ||
| 86 | s = creds->instance; | ||
| 87 | while (*s) | ||
| 88 | *p++ = *s++; | ||
| 89 | *p++ = *s; | ||
| 90 | s = creds->realm; | ||
| 91 | while (*s) | ||
| 92 | *p++ = *s++; | ||
| 93 | *p++ = *s; | ||
| 94 | |||
| 95 | s = creds->pname; | ||
| 96 | while (*s) | ||
| 97 | *p++ = *s++; | ||
| 98 | *p++ = *s; | ||
| 99 | s = creds->pinst; | ||
| 100 | while (*s) | ||
| 101 | *p++ = *s++; | ||
| 102 | *p++ = *s; | ||
| 103 | /* Null string to repeat the realm. */ | ||
| 104 | *p++ = '\0'; | ||
| 105 | |||
| 106 | PUTLONG(creds->issue_date, p); | ||
| 107 | { | ||
| 108 | unsigned int endTime; | ||
| 109 | endTime = (unsigned int) krb_life_to_time(creds->issue_date, | ||
| 110 | creds->lifetime); | ||
| 111 | PUTLONG(endTime, p); | ||
| 112 | } | ||
| 113 | |||
| 114 | memcpy(p, &creds->session, sizeof(creds->session)); | ||
| 115 | p += sizeof(creds->session); | ||
| 116 | |||
| 117 | PUTSHORT(creds->kvno, p); | ||
| 118 | PUTLONG(creds->ticket_st.length, p); | ||
| 119 | |||
| 120 | memcpy(p, creds->ticket_st.dat, creds->ticket_st.length); | ||
| 121 | p += creds->ticket_st.length; | ||
| 122 | len = p - temp; | ||
| 123 | |||
| 124 | return (uuencode((unsigned char *)temp, len, (char *)buf, buflen)); | ||
| 125 | } | ||
| 126 | |||
| 127 | int | ||
| 128 | radix_to_creds(const char *buf, CREDENTIALS *creds) | ||
| 129 | { | ||
| 130 | |||
| 131 | char *p; | ||
| 132 | int len, tl; | ||
| 133 | char version; | ||
| 134 | char temp[2048]; | ||
| 135 | |||
| 136 | len = uudecode(buf, (unsigned char *)temp, sizeof(temp)); | ||
| 137 | if (len < 0) | ||
| 138 | return 0; | ||
| 139 | |||
| 140 | p = temp; | ||
| 141 | |||
| 142 | /* check version and length! */ | ||
| 143 | if (len < 1) | ||
| 144 | return 0; | ||
| 145 | version = *p; | ||
| 146 | p++; | ||
| 147 | len--; | ||
| 148 | |||
| 149 | GETSTRING(creds->service, p, len); | ||
| 150 | GETSTRING(creds->instance, p, len); | ||
| 151 | GETSTRING(creds->realm, p, len); | ||
| 152 | |||
| 153 | GETSTRING(creds->pname, p, len); | ||
| 154 | GETSTRING(creds->pinst, p, len); | ||
| 155 | /* Ignore possibly different realm. */ | ||
| 156 | while (*p && len) | ||
| 157 | p++, len--; | ||
| 158 | if (len == 0) | ||
| 159 | return 0; | ||
| 160 | p++, len--; | ||
| 161 | |||
| 162 | /* Enough space for remaining fixed-length parts? */ | ||
| 163 | if (len < (4 + 4 + sizeof(creds->session) + 2 + 4)) | ||
| 164 | return 0; | ||
| 165 | |||
| 166 | GETLONG(creds->issue_date, p); | ||
| 167 | len -= 4; | ||
| 168 | { | ||
| 169 | unsigned int endTime; | ||
| 170 | GETLONG(endTime, p); | ||
| 171 | len -= 4; | ||
| 172 | creds->lifetime = krb_time_to_life(creds->issue_date, endTime); | ||
| 173 | } | ||
| 174 | |||
| 175 | memcpy(&creds->session, p, sizeof(creds->session)); | ||
| 176 | p += sizeof(creds->session); | ||
| 177 | len -= sizeof(creds->session); | ||
| 178 | |||
| 179 | GETSHORT(creds->kvno, p); | ||
| 180 | len -= 2; | ||
| 181 | GETLONG(creds->ticket_st.length, p); | ||
| 182 | len -= 4; | ||
| 183 | |||
| 184 | tl = creds->ticket_st.length; | ||
| 185 | if (tl < 0 || tl > len || tl > sizeof(creds->ticket_st.dat)) | ||
| 186 | return 0; | ||
| 187 | |||
| 188 | memcpy(creds->ticket_st.dat, p, tl); | ||
| 189 | p += tl; | ||
| 190 | len -= tl; | ||
| 191 | |||
| 192 | return 1; | ||
| 193 | } | ||
| 194 | #endif /* AFS */ | ||
