1 /* $NetBSD: send_recv.c,v 1.1.1.2 2014/04/24 12:45:49 pettai Exp $ */
2
3 /*
4 * Copyright (c) 1997-2003, 2006 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include "kadm5_locl.h"
37
38 __RCSID("NetBSD");
39
40 kadm5_ret_t
_kadm5_client_send(kadm5_client_context * context,krb5_storage * sp)41 _kadm5_client_send(kadm5_client_context *context, krb5_storage *sp)
42 {
43 krb5_data msg, out;
44 krb5_error_code ret;
45 size_t len;
46 krb5_storage *sock;
47
48 assert(context->sock != -1);
49
50 len = krb5_storage_seek(sp, 0, SEEK_CUR);
51 ret = krb5_data_alloc(&msg, len);
52 if (ret) {
53 krb5_clear_error_message(context->context);
54 return ret;
55 }
56 krb5_storage_seek(sp, 0, SEEK_SET);
57 krb5_storage_read(sp, msg.data, msg.length);
58
59 ret = krb5_mk_priv(context->context, context->ac, &msg, &out, NULL);
60 krb5_data_free(&msg);
61 if(ret)
62 return ret;
63
64 sock = krb5_storage_from_fd(context->sock);
65 if(sock == NULL) {
66 krb5_clear_error_message(context->context);
67 krb5_data_free(&out);
68 return ENOMEM;
69 }
70
71 ret = krb5_store_data(sock, out);
72 if (ret)
73 krb5_clear_error_message(context->context);
74 krb5_storage_free(sock);
75 krb5_data_free(&out);
76 return ret;
77 }
78
79 kadm5_ret_t
_kadm5_client_recv(kadm5_client_context * context,krb5_data * reply)80 _kadm5_client_recv(kadm5_client_context *context, krb5_data *reply)
81 {
82 krb5_error_code ret;
83 krb5_data data;
84 krb5_storage *sock;
85
86 sock = krb5_storage_from_fd(context->sock);
87 if(sock == NULL) {
88 krb5_clear_error_message(context->context);
89 return ENOMEM;
90 }
91 ret = krb5_ret_data(sock, &data);
92 krb5_storage_free(sock);
93 krb5_clear_error_message(context->context);
94 if(ret == KRB5_CC_END)
95 return KADM5_RPC_ERROR;
96 else if(ret)
97 return ret;
98
99 ret = krb5_rd_priv(context->context, context->ac, &data, reply, NULL);
100 krb5_data_free(&data);
101 return ret;
102 }
103
104