1999-10-27 03:42:43 +00:00
|
|
|
/*
|
2000-09-16 02:29:08 +00:00
|
|
|
* Copyright (c) 1999 Dug Song. All rights reserved.
|
2002-04-23 10:46:56 +00:00
|
|
|
* Copyright (c) 2002 Markus Friedl. All rights reserved.
|
2000-04-16 01:18:38 +00:00
|
|
|
*
|
2000-09-16 02:29:08 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1999-11-24 13:26:21 +00:00
|
|
|
*/
|
1999-10-27 03:42:43 +00:00
|
|
|
|
|
|
|
#include "includes.h"
|
2000-04-29 13:57:08 +00:00
|
|
|
#include "uuencode.h"
|
1999-10-27 03:42:43 +00:00
|
|
|
|
2002-04-23 14:35:15 +00:00
|
|
|
RCSID("$OpenBSD: radix.c,v 1.20 2002/04/23 12:58:26 markus Exp $");
|
2000-06-23 00:16:38 +00:00
|
|
|
|
1999-10-27 03:42:43 +00:00
|
|
|
#ifdef AFS
|
|
|
|
#include <krb.h>
|
|
|
|
|
2001-06-25 05:01:22 +00:00
|
|
|
#include <radix.h>
|
2002-04-23 10:46:56 +00:00
|
|
|
#include "bufaux.h"
|
2001-06-25 05:01:22 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
int
|
|
|
|
creds_to_radix(CREDENTIALS *creds, u_char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
Buffer b;
|
|
|
|
int ret;
|
1999-10-27 03:42:43 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
buffer_init(&b);
|
1999-10-27 03:42:43 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
buffer_put_char(&b, 1); /* version */
|
1999-10-27 03:42:43 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
buffer_append(&b, creds->service, strlen(creds->service));
|
|
|
|
buffer_put_char(&b, '\0');
|
|
|
|
buffer_append(&b, creds->instance, strlen(creds->instance));
|
|
|
|
buffer_put_char(&b, '\0');
|
|
|
|
buffer_append(&b, creds->realm, strlen(creds->realm));
|
|
|
|
buffer_put_char(&b, '\0');
|
|
|
|
buffer_append(&b, creds->pname, strlen(creds->pname));
|
|
|
|
buffer_put_char(&b, '\0');
|
|
|
|
buffer_append(&b, creds->pinst, strlen(creds->pinst));
|
|
|
|
buffer_put_char(&b, '\0');
|
1999-10-27 03:42:43 +00:00
|
|
|
|
1999-11-24 13:26:21 +00:00
|
|
|
/* Null string to repeat the realm. */
|
2002-04-23 10:46:56 +00:00
|
|
|
buffer_put_char(&b, '\0');
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
buffer_put_int(&b, creds->issue_date);
|
|
|
|
buffer_put_int(&b, krb_life_to_time(creds->issue_date,
|
|
|
|
creds->lifetime));
|
|
|
|
buffer_append(&b, creds->session, sizeof(creds->session));
|
|
|
|
buffer_put_short(&b, creds->kvno);
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
/* 32 bit size + data */
|
2002-04-23 14:35:15 +00:00
|
|
|
buffer_put_string(&b, creds->ticket_st.dat, creds->ticket_st.length);
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
ret = uuencode(buffer_ptr(&b), buffer_len(&b), (char *)buf, buflen);
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
buffer_free(&b);
|
|
|
|
return ret;
|
1999-10-27 03:42:43 +00:00
|
|
|
}
|
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
#define GETSTRING(b, t, tlen) \
|
|
|
|
do { \
|
2002-04-23 11:00:33 +00:00
|
|
|
int i, found = 0; \
|
2002-04-23 10:46:56 +00:00
|
|
|
for (i = 0; i < tlen; i++) { \
|
|
|
|
if (buffer_len(b) == 0) \
|
|
|
|
goto done; \
|
|
|
|
t[i] = buffer_get_char(b); \
|
2002-04-23 11:00:33 +00:00
|
|
|
if (t[i] == '\0') { \
|
|
|
|
found = 1; \
|
2002-04-23 10:46:56 +00:00
|
|
|
break; \
|
2002-04-23 11:00:33 +00:00
|
|
|
} \
|
2002-04-23 10:46:56 +00:00
|
|
|
} \
|
2002-04-23 11:00:33 +00:00
|
|
|
if (!found) \
|
2002-04-23 10:46:56 +00:00
|
|
|
goto done; \
|
|
|
|
} while(0)
|
|
|
|
|
2000-04-16 01:18:38 +00:00
|
|
|
int
|
1999-11-24 13:26:21 +00:00
|
|
|
radix_to_creds(const char *buf, CREDENTIALS *creds)
|
1999-10-27 03:42:43 +00:00
|
|
|
{
|
2002-04-23 10:46:56 +00:00
|
|
|
Buffer b;
|
|
|
|
char c, version, *space, *p;
|
|
|
|
u_int endTime;
|
|
|
|
int len, blen, ret;
|
1999-10-27 03:42:43 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
ret = 0;
|
|
|
|
blen = strlen(buf);
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
/* sanity check for size */
|
|
|
|
if (blen > 8192)
|
1999-11-24 13:26:21 +00:00
|
|
|
return 0;
|
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
buffer_init(&b);
|
|
|
|
space = buffer_append_space(&b, blen);
|
1999-11-24 13:26:21 +00:00
|
|
|
|
|
|
|
/* check version and length! */
|
2002-04-23 10:46:56 +00:00
|
|
|
len = uudecode(buf, space, blen);
|
1999-11-24 13:26:21 +00:00
|
|
|
if (len < 1)
|
2002-04-23 10:46:56 +00:00
|
|
|
goto done;
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
version = buffer_get_char(&b);
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
GETSTRING(&b, creds->service, sizeof creds->service);
|
|
|
|
GETSTRING(&b, creds->instance, sizeof creds->instance);
|
|
|
|
GETSTRING(&b, creds->realm, sizeof creds->realm);
|
|
|
|
GETSTRING(&b, creds->pname, sizeof creds->pname);
|
|
|
|
GETSTRING(&b, creds->pinst, sizeof creds->pinst);
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
if (buffer_len(&b) == 0)
|
|
|
|
goto done;
|
1999-11-24 13:26:21 +00:00
|
|
|
|
2002-04-23 10:46:56 +00:00
|
|
|
/* Ignore possibly different realm. */
|
|
|
|
while (buffer_len(&b) > 0 && (c = buffer_get_char(&b)) != '\0')
|
|
|
|
;
|
|
|
|
|
|
|
|
if (buffer_len(&b) == 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
creds->issue_date = buffer_get_int(&b);
|
|
|
|
|
|
|
|
endTime = buffer_get_int(&b);
|
|
|
|
creds->lifetime = krb_time_to_life(creds->issue_date, endTime);
|
|
|
|
|
|
|
|
len = buffer_len(&b);
|
|
|
|
if (len < sizeof(creds->session))
|
|
|
|
goto done;
|
|
|
|
memcpy(&creds->session, buffer_ptr(&b), sizeof(creds->session));
|
|
|
|
buffer_consume(&b, sizeof(creds->session));
|
|
|
|
|
|
|
|
creds->kvno = buffer_get_short(&b);
|
|
|
|
|
|
|
|
p = buffer_get_string(&b, &len);
|
|
|
|
if (len < 0 || len > sizeof(creds->ticket_st.dat))
|
|
|
|
goto done;
|
|
|
|
memcpy(&creds->ticket_st.dat, p, len);
|
|
|
|
creds->ticket_st.length = len;
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
done:
|
|
|
|
buffer_free(&b);
|
|
|
|
return ret;
|
1999-11-24 13:26:21 +00:00
|
|
|
}
|
1999-10-27 03:42:43 +00:00
|
|
|
#endif /* AFS */
|