xref: /freebsd/crypto/heimdal/lib/krb5/eai_to_heim_errno.c (revision 6a068746777241722b2b32c5d0bc443a2a64d80b)
15e9cd1aeSAssar Westerlund /*
2ae771770SStanislav Sedov  * Copyright (c) 2000 - 2001 Kungliga Tekniska Högskolan
35e9cd1aeSAssar Westerlund  * (Royal Institute of Technology, Stockholm, Sweden).
45e9cd1aeSAssar Westerlund  * All rights reserved.
55e9cd1aeSAssar Westerlund  *
65e9cd1aeSAssar Westerlund  * Redistribution and use in source and binary forms, with or without
75e9cd1aeSAssar Westerlund  * modification, are permitted provided that the following conditions
85e9cd1aeSAssar Westerlund  * are met:
95e9cd1aeSAssar Westerlund  *
105e9cd1aeSAssar Westerlund  * 1. Redistributions of source code must retain the above copyright
115e9cd1aeSAssar Westerlund  *    notice, this list of conditions and the following disclaimer.
125e9cd1aeSAssar Westerlund  *
135e9cd1aeSAssar Westerlund  * 2. Redistributions in binary form must reproduce the above copyright
145e9cd1aeSAssar Westerlund  *    notice, this list of conditions and the following disclaimer in the
155e9cd1aeSAssar Westerlund  *    documentation and/or other materials provided with the distribution.
165e9cd1aeSAssar Westerlund  *
175e9cd1aeSAssar Westerlund  * 3. Neither the name of the Institute nor the names of its contributors
185e9cd1aeSAssar Westerlund  *    may be used to endorse or promote products derived from this software
195e9cd1aeSAssar Westerlund  *    without specific prior written permission.
205e9cd1aeSAssar Westerlund  *
215e9cd1aeSAssar Westerlund  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
225e9cd1aeSAssar Westerlund  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
235e9cd1aeSAssar Westerlund  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
245e9cd1aeSAssar Westerlund  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
255e9cd1aeSAssar Westerlund  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
265e9cd1aeSAssar Westerlund  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
275e9cd1aeSAssar Westerlund  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
285e9cd1aeSAssar Westerlund  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
295e9cd1aeSAssar Westerlund  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
305e9cd1aeSAssar Westerlund  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
315e9cd1aeSAssar Westerlund  * SUCH DAMAGE.
325e9cd1aeSAssar Westerlund  */
335e9cd1aeSAssar Westerlund 
34ae771770SStanislav Sedov #include "krb5_locl.h"
35adb0ddaeSAssar Westerlund 
36c19800e8SDoug Rabson /**
37c19800e8SDoug Rabson  * Convert the getaddrinfo() error code to a Kerberos et error code.
38c19800e8SDoug Rabson  *
39c19800e8SDoug Rabson  * @param eai_errno contains the error code from getaddrinfo().
40c19800e8SDoug Rabson  * @param system_error should have the value of errno after the failed getaddrinfo().
41c19800e8SDoug Rabson  *
42c19800e8SDoug Rabson  * @return Kerberos error code representing the EAI errors.
43c19800e8SDoug Rabson  *
44c19800e8SDoug Rabson  * @ingroup krb5_error
45adb0ddaeSAssar Westerlund  */
465e9cd1aeSAssar Westerlund 
47ae771770SStanislav Sedov KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_eai_to_heim_errno(int eai_errno,int system_error)48adb0ddaeSAssar Westerlund krb5_eai_to_heim_errno(int eai_errno, int system_error)
495e9cd1aeSAssar Westerlund {
505e9cd1aeSAssar Westerlund     switch(eai_errno) {
515e9cd1aeSAssar Westerlund     case EAI_NOERROR:
525e9cd1aeSAssar Westerlund 	return 0;
531c43270aSJacques Vidrine #ifdef EAI_ADDRFAMILY
545e9cd1aeSAssar Westerlund     case EAI_ADDRFAMILY:
555e9cd1aeSAssar Westerlund 	return HEIM_EAI_ADDRFAMILY;
561c43270aSJacques Vidrine #endif
575e9cd1aeSAssar Westerlund     case EAI_AGAIN:
585e9cd1aeSAssar Westerlund 	return HEIM_EAI_AGAIN;
595e9cd1aeSAssar Westerlund     case EAI_BADFLAGS:
605e9cd1aeSAssar Westerlund 	return HEIM_EAI_BADFLAGS;
615e9cd1aeSAssar Westerlund     case EAI_FAIL:
625e9cd1aeSAssar Westerlund 	return HEIM_EAI_FAIL;
635e9cd1aeSAssar Westerlund     case EAI_FAMILY:
645e9cd1aeSAssar Westerlund 	return HEIM_EAI_FAMILY;
655e9cd1aeSAssar Westerlund     case EAI_MEMORY:
665e9cd1aeSAssar Westerlund 	return HEIM_EAI_MEMORY;
671c43270aSJacques Vidrine #if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME
685e9cd1aeSAssar Westerlund     case EAI_NODATA:
695e9cd1aeSAssar Westerlund 	return HEIM_EAI_NODATA;
701c43270aSJacques Vidrine #endif
71*cf771f22SStanislav Sedov #ifdef WSANO_DATA
72*cf771f22SStanislav Sedov     case WSANO_DATA:
73*cf771f22SStanislav Sedov 	return HEIM_EAI_NODATA;
74*cf771f22SStanislav Sedov #endif
755e9cd1aeSAssar Westerlund     case EAI_NONAME:
765e9cd1aeSAssar Westerlund 	return HEIM_EAI_NONAME;
775e9cd1aeSAssar Westerlund     case EAI_SERVICE:
785e9cd1aeSAssar Westerlund 	return HEIM_EAI_SERVICE;
795e9cd1aeSAssar Westerlund     case EAI_SOCKTYPE:
805e9cd1aeSAssar Westerlund 	return HEIM_EAI_SOCKTYPE;
81ae771770SStanislav Sedov #ifdef EAI_SYSTEM
825e9cd1aeSAssar Westerlund     case EAI_SYSTEM:
83adb0ddaeSAssar Westerlund 	return system_error;
84ae771770SStanislav Sedov #endif
85adb0ddaeSAssar Westerlund     default:
86adb0ddaeSAssar Westerlund 	return HEIM_EAI_UNKNOWN; /* XXX */
87adb0ddaeSAssar Westerlund     }
88adb0ddaeSAssar Westerlund }
89adb0ddaeSAssar Westerlund 
90c19800e8SDoug Rabson /**
91c19800e8SDoug Rabson  * Convert the gethostname() error code (h_error) to a Kerberos et
92c19800e8SDoug Rabson  * error code.
93c19800e8SDoug Rabson  *
94c19800e8SDoug Rabson  * @param eai_errno contains the error code from gethostname().
95c19800e8SDoug Rabson  *
96c19800e8SDoug Rabson  * @return Kerberos error code representing the gethostname errors.
97c19800e8SDoug Rabson  *
98c19800e8SDoug Rabson  * @ingroup krb5_error
99c19800e8SDoug Rabson  */
100c19800e8SDoug Rabson 
101ae771770SStanislav Sedov KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_h_errno_to_heim_errno(int eai_errno)102adb0ddaeSAssar Westerlund krb5_h_errno_to_heim_errno(int eai_errno)
103adb0ddaeSAssar Westerlund {
104adb0ddaeSAssar Westerlund     switch(eai_errno) {
105adb0ddaeSAssar Westerlund     case 0:
106adb0ddaeSAssar Westerlund 	return 0;
107adb0ddaeSAssar Westerlund     case HOST_NOT_FOUND:
108adb0ddaeSAssar Westerlund 	return HEIM_EAI_NONAME;
109adb0ddaeSAssar Westerlund     case TRY_AGAIN:
110adb0ddaeSAssar Westerlund 	return HEIM_EAI_AGAIN;
111adb0ddaeSAssar Westerlund     case NO_RECOVERY:
112adb0ddaeSAssar Westerlund 	return HEIM_EAI_FAIL;
113adb0ddaeSAssar Westerlund     case NO_DATA:
114adb0ddaeSAssar Westerlund 	return HEIM_EAI_NONAME;
1155e9cd1aeSAssar Westerlund     default:
1165e9cd1aeSAssar Westerlund 	return HEIM_EAI_UNKNOWN; /* XXX */
1175e9cd1aeSAssar Westerlund     }
1185e9cd1aeSAssar Westerlund }
119