summaryrefslogtreecommitdiff
path: root/source3/lib/util.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2006-07-12 21:02:22 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:19:17 -0500
commit9846cf3daf83c309f51a3f93b9b34aa0ab5d6205 (patch)
tree8d4dcccd6a81e9841ca651abed38850c3ca157c9 /source3/lib/util.c
parentf8be59e0a6aa62e1a1c661fda5cc28b6ddcb22cc (diff)
downloadsamba-9846cf3daf83c309f51a3f93b9b34aa0ab5d6205.tar.gz
samba-9846cf3daf83c309f51a3f93b9b34aa0ab5d6205.tar.bz2
samba-9846cf3daf83c309f51a3f93b9b34aa0ab5d6205.zip
r16997: Simo's patch (based on repotr from Seth Elssworth of Quest) to try to be more robust in the precense of more broken /etc/hosts files when determining our fwdn
(This used to be commit 6413df8348829659807c0c30e6eaef511815e0ed)
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r--source3/lib/util.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 96263bf394..c75008e9a7 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -2830,9 +2830,28 @@ BOOL unix_wild_match(const char *pattern, const char *string)
void name_to_fqdn(fstring fqdn, const char *name)
{
struct hostent *hp = sys_gethostbyname(name);
+
if ( hp && hp->h_name && *hp->h_name ) {
- DEBUG(10,("name_to_fqdn: lookup for %s -> %s.\n", name, hp->h_name));
- fstrcpy(fqdn,hp->h_name);
+ char *full = NULL;
+
+ /* find out i fthe fqdn is returned as an alias
+ * to cope with /etc/hosts files where the first
+ * name is not the fqdn but the short name */
+ if (hp->h_aliases && (! strchr_m(hp->h_name, '.'))) {
+ int i;
+ for (i = 0; hp->h_aliases[i]; i++) {
+ if (strchr_m(hp->h_aliases[i], '.')) {
+ full = hp->h_aliases[i];
+ break;
+ }
+ }
+ }
+ if (!full) {
+ full = hp->h_name;
+ }
+
+ DEBUG(10,("name_to_fqdn: lookup for %s -> %s.\n", name, full));
+ fstrcpy(fqdn, full);
} else {
DEBUG(10,("name_to_fqdn: lookup for %s failed.\n", name));
fstrcpy(fqdn, name);