How about this new patch (as in the attachment).  The change I made from your 
patch, is to add the while loop in pull_c_zero_string which was adopted from 
pull_dotted_string.  Now my domains are all happy.  Otherwise, a grandchild 
domain complains.

I am posting this to samba-technical list, since I though it was what you 
intended to do, and we might get more testing of this.

Chere


On Monday 24 February 2003 01:21 pm, Anthony Liguori wrote:
> Lotus Notes won't let me send patches to the samba-technical list anymore
> (I've got to get a forwarding account it seems) but I haven't tested this
> patch enough to apply it to HEAD anyway.
>
> I know it works with your traffic though as I used your dumps as test data.
> This patch gives a _lot_ more information and makes various fixes.
>
> Note: the patch you submitted to the list doesn't actually work for domain
> controllers without forests.  The 0xc0 stuff are deliminators for these
> strings.
>
> Let me know how this patch works out for you:
>
> (See attached file: net_ads_lookup.patch)
>
> Anthony Liguori
> Linux/Active Directory Interoperability
> Linux Technology Center (LTC) - IBM Austin
> E-mail: [EMAIL PROTECTED]
> Phone: (512) 838-1208
> Tie Line: 678-1208
>
>
>
--- utils/net_ads_cldap.c.orig	Mon Feb 24 14:27:29 2003
+++ utils/net_ads_cldap.c	Tue Feb 25 11:27:50 2003
@@ -24,15 +24,25 @@
 #ifdef HAVE_ADS
 
 struct cldap_netlogon_reply {
-	uint32 version;
+	uint32 type;
 	uint32 flags;
 	GUID guid;
 	char *domain;
-	char *server_name;
-	char *domain_flatname;
-	char *server_flatname;
-	char *dns_name;
-	uint32 unknown2[2];
+
+	char *dns_domain;
+	uint8 domain_flag;
+	char *dns_hostname;
+	uint8 hostname_flag;
+	
+	char *netbios_domain;
+	char *netbios_hostname;
+
+	char *user_name;
+	char *site_name;
+
+	uint32 version;
+	uint16 lmnt_token;
+	uint16 lm20_token;
 };
 
 
@@ -76,6 +86,33 @@
 	return total_len + 1;
 }
 
+static unsigned pull_c_zero_string(char **ret, uint8 *flag, 
+				   const unsigned char *p)
+{
+	unsigned len = 0, total_len=0;
+	char *s;
+
+	*ret = NULL;
+
+	/* TODO: see what happends when a domain controller name == 0xc0 */
+	while (*p != 0xc0) {
+		len = pull_len_string(&s, p);
+                if (total_len) {
+                        char *s2;
+                        asprintf(&s2, "%s.%s", *ret, s);
+                        SAFE_FREE(*ret);
+                        (*ret) = s2;
+                } else {
+                        (*ret) = s;
+                }
+                total_len += len;
+                p += len;
+	}
+
+	*flag = p[1];
+
+	return (total_len + 2);
+}
 
 /*
   do a cldap netlogon query
@@ -190,19 +227,27 @@
 
 	p = os3.data;
 
-	reply->version = IVAL(p, 0); p += 4;
+	reply->type = IVAL(p, 0); p += 4;
 	reply->flags = IVAL(p, 0); p += 4;
+
 	memcpy(&reply->guid.info, p, GUID_SIZE);
 	p += GUID_SIZE;
 	p += pull_dotted_string(&reply->domain, p);
-	p += 2; /* 0xc018 - whats this? */
-	p += pull_len_string(&reply->server_name, p);
-	p += 2; /* 0xc018 - whats this? */
-	p += pull_len_string(&reply->domain_flatname, p);
-	p += 1;
-	p += pull_len_string(&reply->server_flatname, p);
-	p += 2;
-	p += pull_len_string(&reply->dns_name, p);
+
+	p += pull_c_zero_string(&reply->dns_domain, &reply->domain_flag, p);
+	p += pull_c_zero_string(&reply->dns_hostname, &reply->hostname_flag,p);
+
+	p += pull_dotted_string(&reply->netbios_domain, p);
+	p += pull_dotted_string(&reply->netbios_hostname, p);
+
+	p += pull_len_string(&reply->user_name, p);
+	p += pull_len_string(&reply->site_name, p);
+
+	p += 2; /* is this two empty strings? */
+
+	reply->version = IVAL(p, 0);
+	reply->lmnt_token = SVAL(p, 4);
+	reply->lm20_token = SVAL(p, 6);
 
 	data_blob_free(&os1);
 	data_blob_free(&os2);
@@ -219,10 +264,12 @@
 static void cldap_reply_free(struct cldap_netlogon_reply *reply)
 {
 	SAFE_FREE(reply->domain);
-	SAFE_FREE(reply->server_name);
-	SAFE_FREE(reply->domain_flatname);
-	SAFE_FREE(reply->server_flatname);
-	SAFE_FREE(reply->dns_name);
+	SAFE_FREE(reply->dns_domain);
+	SAFE_FREE(reply->dns_hostname);
+	SAFE_FREE(reply->netbios_domain);
+	SAFE_FREE(reply->netbios_hostname);
+	SAFE_FREE(reply->user_name);
+	SAFE_FREE(reply->site_name);
 }
 
 /*
@@ -246,7 +293,6 @@
 	if (ret != 0) {
 		return ret;
 	}
-
 	ret = recv_cldap_netlogon(sock, &reply);
 	close(sock);
 
@@ -254,15 +300,51 @@
 		return -1;
 	}
 
-	d_printf("Version: 0x%x\n", reply.version);
+	d_printf("Response Type: 0x%x\n", reply.type);
 	d_printf("GUID: "); 
 	print_guid(&reply.guid);
-	d_printf("Flags:   0x%x\n", reply.flags);
-	d_printf("Domain: %s\n", reply.domain);
-	d_printf("Server Name: %s\n", reply.server_name);
-	d_printf("Flatname: %s\n", reply.domain_flatname);
-	d_printf("Server Name2: %s\n", reply.server_flatname);
-	d_printf("DNS Name: %s\n", reply.dns_name);
+	d_printf("Flags:\n"
+		 "\tIs a PDC:                                   %s\n"
+		 "\tIs a GC of the forest:                      %s\n"
+		 "\tIs an LDAP server:                          %s\n"
+		 "\tSupports DS:                                %s\n"
+		 "\tIs running a KDC:                           %s\n"
+		 "\tIs running time services:                   %s\n"
+		 "\tIs the closest DC:                          %s\n"
+		 "\tIs writable:                                %s\n"
+		 "\tHas a hardware clock:                       %s\n"
+		 "\tIs a non-domain NC serviced by LDAP server: %s\n",
+		 (reply.flags & ADS_PDC) ? "yes" : "no",
+		 (reply.flags & ADS_GC) ? "yes" : "no",
+		 (reply.flags & ADS_LDAP) ? "yes" : "no",
+		 (reply.flags & ADS_DS) ? "yes" : "no",
+		 (reply.flags & ADS_KDC) ? "yes" : "no",
+		 (reply.flags & ADS_TIMESERV) ? "yes" : "no",
+		 (reply.flags & ADS_CLOSEST) ? "yes" : "no",
+		 (reply.flags & ADS_WRITABLE) ? "yes" : "no",
+		 (reply.flags & ADS_GOOD_TIMESERV) ? "yes" : "no",
+		 (reply.flags & ADS_NDNC) ? "yes" : "no");
+
+	d_printf("Fully Qualified Domain: %s\n", reply.domain);
+
+	if (reply.dns_domain) {
+		d_printf("DNS Domain (%d): %s\n", reply.domain_flag,
+			 reply.dns_domain);
+	}
+	d_printf("DNS Hostname (%d): %s\n", reply.hostname_flag, 
+		 reply.dns_hostname);
+	d_printf("NetBIOS Domain: %s\n", reply.netbios_domain);
+	d_printf("NetBIOS Hostname: %s\n", reply.netbios_hostname);
+
+	if (reply.user_name) {
+		d_printf("User name: %s\n", reply.user_name);
+	}
+
+	d_printf("Site Name: %s\n", reply.site_name);
+
+	d_printf("DC NT Version: %d\n", reply.version);
+	d_printf("LMNT Token: %0.2x\n", reply.lmnt_token);
+	d_printf("LM20 Token: %0.2x\n", reply.lm20_token);
 
 	cldap_reply_free(&reply);
 	

Reply via email to