Path: blob/main/crypto/heimdal/lib/krb5/eai_to_heim_errno.c
34878 views
/*1* Copyright (c) 2000 - 2001 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "krb5_locl.h"3435/**36* Convert the getaddrinfo() error code to a Kerberos et error code.37*38* @param eai_errno contains the error code from getaddrinfo().39* @param system_error should have the value of errno after the failed getaddrinfo().40*41* @return Kerberos error code representing the EAI errors.42*43* @ingroup krb5_error44*/4546KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL47krb5_eai_to_heim_errno(int eai_errno, int system_error)48{49switch(eai_errno) {50case EAI_NOERROR:51return 0;52#ifdef EAI_ADDRFAMILY53case EAI_ADDRFAMILY:54return HEIM_EAI_ADDRFAMILY;55#endif56case EAI_AGAIN:57return HEIM_EAI_AGAIN;58case EAI_BADFLAGS:59return HEIM_EAI_BADFLAGS;60case EAI_FAIL:61return HEIM_EAI_FAIL;62case EAI_FAMILY:63return HEIM_EAI_FAMILY;64case EAI_MEMORY:65return HEIM_EAI_MEMORY;66#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME67case EAI_NODATA:68return HEIM_EAI_NODATA;69#endif70#ifdef WSANO_DATA71case WSANO_DATA:72return HEIM_EAI_NODATA;73#endif74case EAI_NONAME:75return HEIM_EAI_NONAME;76case EAI_SERVICE:77return HEIM_EAI_SERVICE;78case EAI_SOCKTYPE:79return HEIM_EAI_SOCKTYPE;80#ifdef EAI_SYSTEM81case EAI_SYSTEM:82return system_error;83#endif84default:85return HEIM_EAI_UNKNOWN; /* XXX */86}87}8889/**90* Convert the gethostname() error code (h_error) to a Kerberos et91* error code.92*93* @param eai_errno contains the error code from gethostname().94*95* @return Kerberos error code representing the gethostname errors.96*97* @ingroup krb5_error98*/99100KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL101krb5_h_errno_to_heim_errno(int eai_errno)102{103switch(eai_errno) {104case 0:105return 0;106case HOST_NOT_FOUND:107return HEIM_EAI_NONAME;108case TRY_AGAIN:109return HEIM_EAI_AGAIN;110case NO_RECOVERY:111return HEIM_EAI_FAIL;112case NO_DATA:113return HEIM_EAI_NONAME;114default:115return HEIM_EAI_UNKNOWN; /* XXX */116}117}118119120