1/*
2 * Copyright (c) 1999 - 2000 Kungliga Tekniska H�gskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
--- 19 unchanged lines hidden (view full) ---
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
31 * SUCH DAMAGE.
32 */
33
34#include "krb5_locl.h"
35
36RCSID("$Id: expand_hostname.c,v 1.7 2000/02/02 04:42:57 assar Exp $");
37
38static krb5_error_code
39copy_hostname(krb5_context context,
40 const char *orig_hostname,
41 char **new_hostname)
42{
43 *new_hostname = strdup (orig_hostname);
44 if (*new_hostname == NULL)
--- 31 unchanged lines hidden (view full) ---
76 return 0;
77 }
78 }
79 freeaddrinfo (ai);
80 return copy_hostname (context, orig_hostname, new_hostname);
81}
82
83/*
84 * expand `hostname' to a name we believe to be a hostname in newly
85 * allocated space in `host' and return realms in `realms'.
86 */
87
88krb5_error_code
89krb5_expand_hostname_realms (krb5_context context,
90 const char *orig_hostname,
91 char **new_hostname,
92 char ***realms)
93{
94 struct addrinfo *ai, *a, hints;
95 int error;
96 krb5_error_code ret = 0;
97
98 memset (&hints, 0, sizeof(hints));
99 hints.ai_flags = AI_CANONNAME;
100
101 error = getaddrinfo (orig_hostname, NULL, &hints, &ai);
102 if (error)
103 return copy_hostname (context, orig_hostname, new_hostname);
104 for (a = ai; a != NULL; a = a->ai_next) {
105 if (a->ai_canonname != NULL) {
106 ret = copy_hostname (context, orig_hostname, new_hostname);
107 if (ret)
108 goto out;
109 strlwr (*new_hostname);
110 ret = krb5_get_host_realm (context, *new_hostname, realms);
111 if (ret == 0)
112 goto out;
113 free (*new_hostname);
114 }
115 }
116 ret = copy_hostname (context, orig_hostname, new_hostname);
117 out:
118 freeaddrinfo (ai);
119 return ret;
120}
2 * Copyright (c) 1999 - 2000 Kungliga Tekniska H�gskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
--- 19 unchanged lines hidden (view full) ---
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
31 * SUCH DAMAGE.
32 */
33
34#include "krb5_locl.h"
35
36RCSID("$Id: expand_hostname.c,v 1.7 2000/02/02 04:42:57 assar Exp $");
37
38static krb5_error_code
39copy_hostname(krb5_context context,
40 const char *orig_hostname,
41 char **new_hostname)
42{
43 *new_hostname = strdup (orig_hostname);
44 if (*new_hostname == NULL)
--- 31 unchanged lines hidden (view full) ---
76 return 0;
77 }
78 }
79 freeaddrinfo (ai);
80 return copy_hostname (context, orig_hostname, new_hostname);
81}
82
83/*
84 * expand `hostname' to a name we believe to be a hostname in newly
85 * allocated space in `host' and return realms in `realms'.
86 */
87
88krb5_error_code
89krb5_expand_hostname_realms (krb5_context context,
90 const char *orig_hostname,
91 char **new_hostname,
92 char ***realms)
93{
94 struct addrinfo *ai, *a, hints;
95 int error;
96 krb5_error_code ret = 0;
97
98 memset (&hints, 0, sizeof(hints));
99 hints.ai_flags = AI_CANONNAME;
100
101 error = getaddrinfo (orig_hostname, NULL, &hints, &ai);
102 if (error)
103 return copy_hostname (context, orig_hostname, new_hostname);
104 for (a = ai; a != NULL; a = a->ai_next) {
105 if (a->ai_canonname != NULL) {
106 ret = copy_hostname (context, orig_hostname, new_hostname);
107 if (ret)
108 goto out;
109 strlwr (*new_hostname);
110 ret = krb5_get_host_realm (context, *new_hostname, realms);
111 if (ret == 0)
112 goto out;
113 free (*new_hostname);
114 }
115 }
116 ret = copy_hostname (context, orig_hostname, new_hostname);
117 out:
118 freeaddrinfo (ai);
119 return ret;
120}