2 * Copyright (c) 1997 - 1999, 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 RCSID("$Id: common.c,v 1.14 2002/02/18 20:01:05 joda Exp $");
37 #if defined(KRB4) || defined(KRB5)
46 if (auth_method == AUTH_KRB4) {
47 return des_enc_read (fd, buf, sz, schedule, &iv);
51 if(auth_method == AUTH_KRB5) {
53 u_int32_t len, outer_len;
58 ret = krb5_net_read (context, &fd, &len, 4);
64 outer_len = krb5_get_wrapped_length (context, crypto, len);
65 edata = malloc (outer_len);
67 errx (1, "malloc: cannot allocate %u bytes", outer_len);
68 ret = krb5_net_read (context, &fd, edata, outer_len);
72 status = krb5_decrypt(context, crypto, KRB5_KU_OTHER_ENCRYPTED,
73 edata, outer_len, &data);
77 errx (1, "%s", krb5_get_err_text (context, status));
78 memcpy (buf, data.data, len);
79 krb5_data_free (&data);
85 return read (fd, buf, sz);
89 do_write (int fd, void *buf, size_t sz)
93 if(auth_method == AUTH_KRB4) {
94 return des_enc_write (fd, buf, sz, schedule, &iv);
98 if(auth_method == AUTH_KRB5) {
99 krb5_error_code status;
104 status = krb5_encrypt(context, crypto, KRB5_KU_OTHER_ENCRYPTED,
108 errx (1, "%s", krb5_get_err_text(context, status));
110 assert (krb5_get_wrapped_length (context, crypto,
114 ret = krb5_net_write (context, &fd, &len, 4);
117 ret = krb5_net_write (context, &fd, data.data, data.length);
118 if (ret != data.length)
126 return write (fd, buf, sz);
128 #endif /* KRB4 || KRB5 */