read_message.c revision 72445
1246853Sdes/* 2246853Sdes * Copyright (c) 1997, 1998 Kungliga Tekniska H�gskolan 3246853Sdes * (Royal Institute of Technology, Stockholm, Sweden). 4246853Sdes * All rights reserved. 5246853Sdes * 6246853Sdes * Redistribution and use in source and binary forms, with or without 7246853Sdes * modification, are permitted provided that the following conditions 8246853Sdes * are met: 9246853Sdes * 10246853Sdes * 1. Redistributions of source code must retain the above copyright 11246853Sdes * notice, this list of conditions and the following disclaimer. 12246853Sdes * 13246853Sdes * 2. Redistributions in binary form must reproduce the above copyright 14246853Sdes * notice, this list of conditions and the following disclaimer in the 15246853Sdes * documentation and/or other materials provided with the distribution. 16246853Sdes * 17246853Sdes * 3. Neither the name of the Institute nor the names of its contributors 18246853Sdes * may be used to endorse or promote products derived from this software 19246853Sdes * without specific prior written permission. 20246853Sdes * 21246853Sdes * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22246853Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23246853Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24246853Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25246853Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26246854Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27266114Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28266114Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29266114Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30246853Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31246853Sdes * SUCH DAMAGE. 32246853Sdes */ 33246853Sdes 34246853Sdes#include "krb5_locl.h" 35246853Sdes 36246853SdesRCSID("$Id: read_message.c,v 1.7 2000/07/21 22:54:09 joda Exp $"); 37246853Sdes 38246853Sdeskrb5_error_code 39246853Sdeskrb5_read_message (krb5_context context, 40246853Sdes krb5_pointer p_fd, 41246853Sdes krb5_data *data) 42246853Sdes{ 43246853Sdes krb5_error_code ret; 44246853Sdes u_int32_t len; 45246853Sdes u_int8_t buf[4]; 46246853Sdes 47246853Sdes ret = krb5_net_read (context, p_fd, buf, 4); 48246853Sdes if(ret == -1) 49246853Sdes return errno; 50246853Sdes if(ret < 4) { 51246853Sdes data->length = 0; 52246853Sdes return HEIM_ERR_EOF; 53246853Sdes } 54246853Sdes len = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; 55246853Sdes ret = krb5_data_alloc (data, len); 56246853Sdes if (ret) 57246853Sdes return ret; 58246853Sdes if (krb5_net_read (context, p_fd, data->data, len) != len) { 59246853Sdes krb5_data_free (data); 60246853Sdes return errno; 61246853Sdes } 62246853Sdes return 0; 63246853Sdes} 64246853Sdes 65246853Sdeskrb5_error_code 66246853Sdeskrb5_read_priv_message(krb5_context context, 67246853Sdes krb5_auth_context ac, 68246853Sdes krb5_pointer p_fd, 69246853Sdes krb5_data *data) 70246853Sdes{ 71246853Sdes krb5_error_code ret; 72246854Sdes krb5_data packet; 73246854Sdes 74246854Sdes ret = krb5_read_message(context, p_fd, &packet); 75246854Sdes if(ret) 76246853Sdes return ret; 77 ret = krb5_rd_priv (context, ac, &packet, data, NULL); 78 krb5_data_free(&packet); 79 if(ret) 80 return ret; 81 return ret; 82} 83 84krb5_error_code 85krb5_read_safe_message(krb5_context context, 86 krb5_auth_context ac, 87 krb5_pointer p_fd, 88 krb5_data *data) 89{ 90 krb5_error_code ret; 91 krb5_data packet; 92 93 ret = krb5_read_message(context, p_fd, &packet); 94 if(ret) 95 return ret; 96 ret = krb5_rd_safe (context, ac, &packet, data, NULL); 97 krb5_data_free(&packet); 98 if(ret) 99 return ret; 100 return ret; 101} 102