[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Tue May 12 15:36:05 MDT 2015


The branch, master has been updated
       via  6e08bfb Add IPv6 support for determining FQDN during ADS join.
       via  c324d79 Add IPv6 support to ADS client side LDAP connects. Corrected format for IPv6 LDAP URI. Signed-off-by: David Holder <david.holder at erion.co.uk>
      from  bc62dfa Convert all uint32/16/8 to _t in a couple of include files.

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 6e08bfb4441022a00d0c29205e835a4858a3a57f
Author: David Holder <david.holder at erion.co.uk>
Date:   Tue May 12 17:40:29 2015 +0100

    Add IPv6 support for determining FQDN during ADS join.
    
    Signed-off-by: David Holder <david.holder at erion.co.uk>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Böhme <rb at sernet.de>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Tue May 12 23:35:32 CEST 2015 on sn-devel-104

commit c324d7901c991a6700abdc3ee701920fea5e5819
Author: David Holder <david.holder at erion.co.uk>
Date:   Tue May 12 16:09:54 2015 +0100

    Add IPv6 support to ADS client side LDAP connects. Corrected format for IPv6 LDAP URI. Signed-off-by: David Holder <david.holder at erion.co.uk>
    
    Signed-off-by: David Holder <david.holder at erion.co.uk>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Böhme <rb at sernet.de>

-----------------------------------------------------------------------

Summary of changes:
 source3/lib/util.c    | 54 +++++++++++++++++++++++++++++++--------------------
 source3/libads/ldap.c |  8 +++++++-
 2 files changed, 40 insertions(+), 22 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/lib/util.c b/source3/lib/util.c
index ec0757e..1d76820 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1836,48 +1836,60 @@ bool unix_wild_match(const char *pattern, const char *string)
 }
 
 /**********************************************************************
- Converts a name to a fully qualified domain name.
- Returns true if lookup succeeded, false if not (then fqdn is set to name)
- Note we deliberately use gethostbyname here, not getaddrinfo as we want
- to examine the h_aliases and I don't know how to do that with getaddrinfo.
-***********************************************************************/
+  Converts a name to a fully qualified domain name.
+  Returns true if lookup succeeded, false if not (then fqdn is set to name)
+  Uses getaddrinfo() with AI_CANONNAME flag to obtain the official
+  canonical name of the host. getaddrinfo() may use a variety of sources
+  including /etc/hosts to obtain the domainname. It expects aliases in
+  /etc/hosts to NOT be the FQDN. The FQDN should come first.
+************************************************************************/
 
 bool name_to_fqdn(fstring fqdn, const char *name)
 {
 	char *full = NULL;
-	struct hostent *hp = gethostbyname(name);
+	struct addrinfo hints;
+	struct addrinfo *result;
+	int s;
+
+	/* Configure hints to obtain canonical name */
+
+	memset(&hints, 0, sizeof(struct addrinfo));
+	hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
+	hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
+	hints.ai_flags = AI_CANONNAME;  /* Get host's FQDN */
+	hints.ai_protocol = 0;          /* Any protocol */
 
-	if (!hp || !hp->h_name || !*hp->h_name) {
+	s = getaddrinfo(name, NULL, &hints, &result);
+	if (s != 0) {
+		DEBUG(1, ("getaddrinfo: %s\n", gai_strerror(s)));
 		DEBUG(10,("name_to_fqdn: lookup for %s failed.\n", name));
 		fstrcpy(fqdn, name);
 		return false;
 	}
+	full = result->ai_canonname;
 
-	/* Find out if the fqdn is returned as an alias
+	/* Find out if the 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;
-			}
-		}
+	 * name is not the FQDN but the short name.
+	 * getaddrinfo provides no easy way of handling aliases
+	 * in /etc/hosts. Users should make sure the FQDN
+	 * comes first in /etc/hosts. */
+	if (full && (! strchr_m(full, '.'))) {
+		DEBUG(1, ("WARNING: your /etc/hosts file may be broken!\n"));
+		DEBUGADD(1, ("    Full qualified domain names (FQDNs) should not be specified\n"));
+		DEBUGADD(1, ("    as an alias in /etc/hosts. FQDN should be the first name\n"));
+		DEBUGADD(1, ("    prior to any aliases.\n"));
 	}
 	if (full && (strcasecmp_m(full, "localhost.localdomain") == 0)) {
 		DEBUG(1, ("WARNING: your /etc/hosts file may be broken!\n"));
 		DEBUGADD(1, ("    Specifying the machine hostname for address 127.0.0.1 may lead\n"));
 		DEBUGADD(1, ("    to Kerberos authentication problems as localhost.localdomain\n"));
 		DEBUGADD(1, ("    may end up being used instead of the real machine FQDN.\n"));
-		full = hp->h_name;
-	}
-	if (!full) {
-		full = hp->h_name;
 	}
 
 	DEBUG(10,("name_to_fqdn: lookup for %s -> %s.\n", name, full));
 	fstrcpy(fqdn, full);
+	freeaddrinfo(result);           /* No longer needed */
 	return true;
 }
 
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index 3f5302f..2ad9bfd 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -79,7 +79,13 @@ static void gotalarm_sig(int signum)
 		/* End setup timeout. */
 	}
 
-	uri = talloc_asprintf(talloc_tos(), "ldap://%s:%u", server, port);
+	if ( strchr_m(server, ':') ) {
+		/* IPv6 URI */
+		uri = talloc_asprintf(talloc_tos(), "ldap://[%s]:%u", server, port);
+	} else {
+		/* IPv4 URI */
+		uri = talloc_asprintf(talloc_tos(), "ldap://%s:%u", server, port);
+	}
 	if (uri == NULL) {
 		return NULL;
 	}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list