diff options
-rw-r--r-- | lib/libc/asr/asr.c | 25 | ||||
-rw-r--r-- | lib/libc/asr/asr_private.h | 3 |
2 files changed, 14 insertions, 14 deletions
diff --git a/lib/libc/asr/asr.c b/lib/libc/asr/asr.c index 32bb413899c..3260f6a9f58 100644 --- a/lib/libc/asr/asr.c +++ b/lib/libc/asr/asr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr.c,v 1.27 2013/06/01 09:21:09 eric Exp $ */ +/* $OpenBSD: asr.c,v 1.28 2013/06/01 12:38:29 eric Exp $ */ /* * Copyright (c) 2010-2012 Eric Faurot <eric@openbsd.org> * @@ -74,9 +74,6 @@ static int asr_parse_nameserver(struct sockaddr *, const char *); static int asr_ndots(const char *); static void pass0(char **, int, struct asr_ctx *); static int strsplit(char *, char **, int); -#if ASR_OPT_HOSTALIASES -static char *asr_hostalias(const char *, char *, size_t); -#endif #if ASR_OPT_ENVOPTS static void asr_ctx_envopts(struct asr_ctx *); #endif @@ -965,9 +962,8 @@ asr_iter_domain(struct async *as, const char *name, char * buf, size_t len) * If "name" has no dots, it might be an alias. If so, * That's also the only result. */ - if ((as->as_ctx->ac_options & RES_NOALIASES) == 0 && - asr_ndots(name) == 0 && - (alias = asr_hostalias(name, buf, len)) != NULL) { + alias = asr_hostalias(as->as_ctx, name, buf, len); + if (alias) { DPRINT("asr: asr_iter_domain(\"%s\") is alias \"%s\"\n", name, alias); as->as_dom_flags |= ASYNC_DOM_HOSTALIAS; @@ -1029,22 +1025,25 @@ asr_iter_domain(struct async *as, const char *name, char * buf, size_t len) } } -#if ASR_OPT_HOSTALIASES /* * Check if the hostname "name" is a user-defined alias as per hostname(7). * If so, copies the result in the buffer "abuf" of size "abufsz" and * return "abuf". Otherwise return NULL. */ -static char * -asr_hostalias(const char *name, char *abuf, size_t abufsz) +char * +asr_hostalias(struct asr_ctx *ac, const char *name, char *abuf, size_t abufsz) { +#if ASR_OPT_HOSTALIASES FILE *fp; size_t len; char *file, *buf, *tokens[2]; int ntok; - file = getenv("HOSTALIASES"); - if (file == NULL || issetugid() != 0 || (fp = fopen(file, "r")) == NULL) + if (ac->ac_options & RES_NOALIASES || + asr_ndots(name) != 0 || + issetugid() || + (file = getenv("HOSTALIASES")) == NULL || + (fp = fopen(file, "r")) == NULL) return (NULL); DPRINT("asr: looking up aliases in \"%s\"\n", file); @@ -1065,6 +1064,6 @@ asr_hostalias(const char *name, char *abuf, size_t abufsz) } fclose(fp); +#endif return (NULL); } -#endif diff --git a/lib/libc/asr/asr_private.h b/lib/libc/asr/asr_private.h index 57849ff51bc..9bbcc70c773 100644 --- a/lib/libc/asr/asr_private.h +++ b/lib/libc/asr/asr_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asr_private.h,v 1.19 2013/06/01 09:21:10 eric Exp $ */ +/* $OpenBSD: asr_private.h,v 1.20 2013/06/01 12:38:29 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -322,6 +322,7 @@ char *asr_strdname(const char *, char *, size_t); int asr_iter_db(struct async *); int asr_iter_domain(struct async *, const char *, char *, size_t); int asr_parse_namedb_line(FILE *, char **, int); +char *asr_hostalias(struct asr_ctx *, const char *, char *, size_t); /* <*>_async.h */ struct async *res_query_async_ctx(const char *, int, int, struct asr_ctx *); |