]> andersk Git - openssh.git/blame - radix.c
- stevesk@cvs.openbsd.org 2002/08/21 19:38:06
[openssh.git] / radix.c
CommitLineData
8efc0c15 1/*
bcbf86ec 2 * Copyright (c) 1999 Dug Song. All rights reserved.
3b358a0e 3 * Copyright (c) 2002 Markus Friedl. All rights reserved.
6ae2364d 4 *
bcbf86ec 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5260325f 24 */
8efc0c15 25
8efc0c15 26#include "includes.h"
a306f2dd 27#include "uuencode.h"
8efc0c15 28
7203d6bb 29RCSID("$OpenBSD: radix.c,v 1.21 2002/06/19 00:27:55 deraadt Exp $");
e5a0294f 30
8efc0c15 31#ifdef AFS
32#include <krb.h>
33
396c147e 34#include <radix.h>
3b358a0e 35#include "bufaux.h"
396c147e 36
3b358a0e 37int
38creds_to_radix(CREDENTIALS *creds, u_char *buf, size_t buflen)
39{
40 Buffer b;
41 int ret;
8efc0c15 42
3b358a0e 43 buffer_init(&b);
8efc0c15 44
3b358a0e 45 buffer_put_char(&b, 1); /* version */
8efc0c15 46
3b358a0e 47 buffer_append(&b, creds->service, strlen(creds->service));
48 buffer_put_char(&b, '\0');
49 buffer_append(&b, creds->instance, strlen(creds->instance));
50 buffer_put_char(&b, '\0');
51 buffer_append(&b, creds->realm, strlen(creds->realm));
52 buffer_put_char(&b, '\0');
53 buffer_append(&b, creds->pname, strlen(creds->pname));
54 buffer_put_char(&b, '\0');
55 buffer_append(&b, creds->pinst, strlen(creds->pinst));
56 buffer_put_char(&b, '\0');
8efc0c15 57
5260325f 58 /* Null string to repeat the realm. */
3b358a0e 59 buffer_put_char(&b, '\0');
5260325f 60
3b358a0e 61 buffer_put_int(&b, creds->issue_date);
62 buffer_put_int(&b, krb_life_to_time(creds->issue_date,
63 creds->lifetime));
64 buffer_append(&b, creds->session, sizeof(creds->session));
65 buffer_put_short(&b, creds->kvno);
5260325f 66
3b358a0e 67 /* 32 bit size + data */
9a41fe10 68 buffer_put_string(&b, creds->ticket_st.dat, creds->ticket_st.length);
5260325f 69
3b358a0e 70 ret = uuencode(buffer_ptr(&b), buffer_len(&b), (char *)buf, buflen);
5260325f 71
3b358a0e 72 buffer_free(&b);
73 return ret;
8efc0c15 74}
75
3b358a0e 76#define GETSTRING(b, t, tlen) \
77 do { \
afb8fdb4 78 int i, found = 0; \
3b358a0e 79 for (i = 0; i < tlen; i++) { \
80 if (buffer_len(b) == 0) \
81 goto done; \
82 t[i] = buffer_get_char(b); \
afb8fdb4 83 if (t[i] == '\0') { \
84 found = 1; \
3b358a0e 85 break; \
afb8fdb4 86 } \
3b358a0e 87 } \
afb8fdb4 88 if (!found) \
3b358a0e 89 goto done; \
90 } while(0)
91
6ae2364d 92int
5260325f 93radix_to_creds(const char *buf, CREDENTIALS *creds)
8efc0c15 94{
3b358a0e 95 Buffer b;
96 char c, version, *space, *p;
97 u_int endTime;
98 int len, blen, ret;
8efc0c15 99
3b358a0e 100 ret = 0;
101 blen = strlen(buf);
5260325f 102
3b358a0e 103 /* sanity check for size */
104 if (blen > 8192)
5260325f 105 return 0;
106
3b358a0e 107 buffer_init(&b);
108 space = buffer_append_space(&b, blen);
5260325f 109
110 /* check version and length! */
3b358a0e 111 len = uudecode(buf, space, blen);
5260325f 112 if (len < 1)
3b358a0e 113 goto done;
5260325f 114
3b358a0e 115 version = buffer_get_char(&b);
5260325f 116
3b358a0e 117 GETSTRING(&b, creds->service, sizeof creds->service);
118 GETSTRING(&b, creds->instance, sizeof creds->instance);
119 GETSTRING(&b, creds->realm, sizeof creds->realm);
120 GETSTRING(&b, creds->pname, sizeof creds->pname);
121 GETSTRING(&b, creds->pinst, sizeof creds->pinst);
5260325f 122
3b358a0e 123 if (buffer_len(&b) == 0)
124 goto done;
5260325f 125
3b358a0e 126 /* Ignore possibly different realm. */
127 while (buffer_len(&b) > 0 && (c = buffer_get_char(&b)) != '\0')
128 ;
129
130 if (buffer_len(&b) == 0)
131 goto done;
132
133 creds->issue_date = buffer_get_int(&b);
134
135 endTime = buffer_get_int(&b);
136 creds->lifetime = krb_time_to_life(creds->issue_date, endTime);
137
138 len = buffer_len(&b);
139 if (len < sizeof(creds->session))
140 goto done;
141 memcpy(&creds->session, buffer_ptr(&b), sizeof(creds->session));
142 buffer_consume(&b, sizeof(creds->session));
143
144 creds->kvno = buffer_get_short(&b);
145
146 p = buffer_get_string(&b, &len);
147 if (len < 0 || len > sizeof(creds->ticket_st.dat))
148 goto done;
149 memcpy(&creds->ticket_st.dat, p, len);
150 creds->ticket_st.length = len;
7203d6bb 151
3b358a0e 152 ret = 1;
153done:
154 buffer_free(&b);
155 return ret;
5260325f 156}
8efc0c15 157#endif /* AFS */
This page took 0.177813 seconds and 5 git commands to generate.