Annotation of src/usr.bin/ssh/radix.c, Revision 1.18
1.1 deraadt 1: /*
1.13 deraadt 2: * Copyright (c) 1999 Dug Song. All rights reserved.
1.18 ! markus 3: * Copyright (c) 2002 Markus Friedl. All rights reserved.
1.8 markus 4: *
1.13 deraadt 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.
1.5 deraadt 24: */
1.4 markus 25:
1.1 deraadt 26: #include "includes.h"
1.9 markus 27: #include "uuencode.h"
1.1 deraadt 28:
1.18 ! markus 29: RCSID("$OpenBSD: radix.c,v 1.17 2001/11/19 19:02:16 mpech Exp $");
1.12 djm 30:
1.1 deraadt 31: #ifdef AFS
32: #include <krb.h>
1.16 itojun 33:
34: #include <radix.h>
1.18 ! markus 35: #include "bufaux.h"
1.1 deraadt 36:
1.18 ! markus 37: int
! 38: creds_to_radix(CREDENTIALS *creds, u_char *buf, size_t buflen)
! 39: {
! 40: Buffer b;
! 41: int ret;
1.1 deraadt 42:
1.18 ! markus 43: buffer_init(&b);
1.1 deraadt 44:
1.18 ! markus 45: buffer_put_char(&b, 1); /* version */
1.1 deraadt 46:
1.18 ! markus 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');
1.1 deraadt 57:
1.4 markus 58: /* Null string to repeat the realm. */
1.18 ! markus 59: buffer_put_char(&b, '\0');
1.1 deraadt 60:
1.18 ! markus 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);
! 66:
! 67: /* 32 bit size + data */
! 68: buffer_put_string(&b, creds->ticket_st.dat,
! 69: sizeof(creds->ticket_st.length));
! 70:
! 71: ret = uuencode(buffer_ptr(&b), buffer_len(&b), (char *)buf, buflen);
! 72:
! 73: buffer_free(&b);
! 74: return ret;
! 75: }
! 76:
! 77: #define GETSTRING(b, t, tlen) \
! 78: do { \
! 79: int i; \
! 80: for (i = 0; i < tlen; i++) { \
! 81: if (buffer_len(b) == 0) \
! 82: goto done; \
! 83: t[i] = buffer_get_char(b); \
! 84: if (t[i] == '\0') \
! 85: break; \
! 86: } \
! 87: if (t[i] != '\0') \
! 88: goto done; \
! 89: } while(0)
1.1 deraadt 90:
1.8 markus 91: int
1.4 markus 92: radix_to_creds(const char *buf, CREDENTIALS *creds)
1.1 deraadt 93: {
1.18 ! markus 94: Buffer b;
! 95: char c, version, *space, *p;
! 96: u_int endTime;
! 97: int len, blen, ret;
1.1 deraadt 98:
1.18 ! markus 99: ret = 0;
! 100: blen = strlen(buf);
1.4 markus 101:
1.18 ! markus 102: /* sanity check for size */
! 103: if (blen > 8192)
1.4 markus 104: return 0;
105:
1.18 ! markus 106: buffer_init(&b);
! 107: space = buffer_append_space(&b, blen);
1.4 markus 108:
109: /* check version and length! */
1.18 ! markus 110: len = uudecode(buf, space, blen);
1.4 markus 111: if (len < 1)
1.18 ! markus 112: goto done;
! 113:
! 114: version = buffer_get_char(&b);
1.4 markus 115:
1.18 ! markus 116: GETSTRING(&b, creds->service, sizeof creds->service);
! 117: GETSTRING(&b, creds->instance, sizeof creds->instance);
! 118: GETSTRING(&b, creds->realm, sizeof creds->realm);
! 119: GETSTRING(&b, creds->pname, sizeof creds->pname);
! 120: GETSTRING(&b, creds->pinst, sizeof creds->pinst);
1.4 markus 121:
1.18 ! markus 122: if (buffer_len(&b) == 0)
! 123: goto done;
1.4 markus 124:
1.18 ! markus 125: /* Ignore possibly different realm. */
! 126: while (buffer_len(&b) > 0 && (c = buffer_get_char(&b)) != '\0')
! 127: ;
1.4 markus 128:
1.18 ! markus 129: if (buffer_len(&b) == 0)
! 130: goto done;
1.4 markus 131:
1.18 ! markus 132: creds->issue_date = buffer_get_int(&b);
1.4 markus 133:
1.18 ! markus 134: endTime = buffer_get_int(&b);
! 135: creds->lifetime = krb_time_to_life(creds->issue_date, endTime);
! 136:
! 137: len = buffer_len(&b);
! 138: if (len < sizeof(creds->session))
! 139: goto done;
! 140: memcpy(&creds->session, buffer_ptr(&b), sizeof(creds->session));
! 141: buffer_consume(&b, sizeof(creds->session));
! 142:
! 143: creds->kvno = buffer_get_short(&b);
! 144:
! 145: p = buffer_get_string(&b, &len);
! 146: if (len < 0 || len > sizeof(creds->ticket_st.dat))
! 147: goto done;
! 148: memcpy(&creds->ticket_st.dat, p, len);
! 149: creds->ticket_st.length = len;
! 150:
! 151: ret = 1;
! 152: done:
! 153: buffer_free(&b);
! 154: return ret;
1.1 deraadt 155: }
156: #endif /* AFS */