Commit f5b4721d authored by Jeremy Allison's avatar Jeremy Allison Committed by Gerald (Jerry) Carter
Browse files

r1326: Modification to get_dc_list to check negative cache. From "Joe Meadows"...

r1326: Modification to get_dc_list to check negative cache. From "Joe Meadows" <jameadows@webopolis.com>.
Jeremy.
(This used to be commit 4cc38b8aea51b55cc449cd2144f18de7d4819637)
parent c531f726
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -154,5 +154,3 @@ void flush_negative_conn_cache( void )
	}

}

+203 −188
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ static struct node_status *parse_node_status(char *p, int *num_names, struct nod
		return NULL;

	ret = (struct node_status *)malloc(sizeof(struct node_status)* (*num_names));
	if (!ret) return NULL;
	if (!ret)
		return NULL;

	p++;
	for (i=0;i< *num_names;i++) {
@@ -566,11 +567,13 @@ BOOL getlmhostsent( XFILE *fp, pstring name, int *name_type, struct in_addr *ipa

		*name_type = -1;

    if (!fgets_slash(line,sizeof(pstring),fp))
		if (!fgets_slash(line,sizeof(pstring),fp)) {
			continue;
		}

    if (*line == '#')
		if (*line == '#') {
			continue;
		}

		pstrcpy(ip,"");
		pstrcpy(name,"");
@@ -590,22 +593,19 @@ BOOL getlmhostsent( XFILE *fp, pstring name, int *name_type, struct in_addr *ipa
		if (count <= 0)
			continue;

    if (count > 0 && count < 2)
    {
		if (count > 0 && count < 2) {
			DEBUG(0,("getlmhostsent: Ill formed hosts line [%s]\n",line));
			continue;
		}

    if (count >= 4)
    {
		if (count >= 4) {
			DEBUG(0,("getlmhostsent: too many columns in lmhosts file (obsolete syntax)\n"));
			continue;
		}

		DEBUG(4, ("getlmhostsent: lmhost entry: %s %s %s\n", ip, name, flags));

    if (strchr_m(flags,'G') || strchr_m(flags,'S'))
    {
		if (strchr_m(flags,'G') || strchr_m(flags,'S')) {
			DEBUG(0,("getlmhostsent: group flag in lmhosts ignored (obsolete)\n"));
			continue;
		}
@@ -614,15 +614,12 @@ BOOL getlmhostsent( XFILE *fp, pstring name, int *name_type, struct in_addr *ipa

		/* Extra feature. If the name ends in '#XX', where XX is a hex number,
			then only add that name type. */
    if((ptr1 = strchr_m(name, '#')) != NULL)
    {
		if((ptr1 = strchr_m(name, '#')) != NULL) {
			char *endptr;

      			ptr1++;
      *name_type = (int)strtol(ptr1, &endptr, 16);

      if(!*ptr1 || (endptr == ptr1))
      {
			*name_type = (int)strtol(ptr1, &endptr, 16);
			if(!*ptr1 || (endptr == ptr1)) {
				DEBUG(0,("getlmhostsent: invalid name %s containing '#'.\n", name));
				continue;
			}
@@ -1049,15 +1046,16 @@ static BOOL internal_resolve_name(const char *name, int name_type,
		return False;
	}
  
  if ( !resolve_order )
	if ( !resolve_order ) {
		pstrcpy(name_resolve_list, lp_name_resolve_order());
  else
	} else {
		pstrcpy(name_resolve_list, resolve_order);

  if ( !name_resolve_list[0] )
		if ( !name_resolve_list[0] ) {
			ptr = "host";
  else
		} else {
			ptr = name_resolve_list;
		}

		/* iterate through the name resolution backends */
  
@@ -1082,8 +1080,7 @@ static BOOL internal_resolve_name(const char *name, int name_type,
				}
			} else if(strequal( tok, "wins")) {
				/* don't resolve 1D via WINS */
		  if (name_type != 0x1D &&
		      resolve_wins(name, name_type, return_iplist, return_count)) {
				if (name_type != 0x1D && resolve_wins(name, name_type, return_iplist, return_count)) {
					result = True;
					goto done;
				}
@@ -1127,14 +1124,14 @@ static BOOL internal_resolve_name(const char *name, int name_type,
		/* Display some debugging info */

		if ( DEBUGLEVEL >= 10 ) {
    DEBUG(10, ("internal_resolve_name: returning %d addresses: ", 
   	       *return_count));
			DEBUG(10, ("internal_resolve_name: returning %d addresses: ", *return_count));

    for (i = 0; i < *return_count; i++)
			for (i = 0; i < *return_count; i++) {
				DEBUGADD(10, ("%s:%d ", inet_ntoa((*return_iplist)[i].ip), (*return_iplist)[i].port));

			}
			DEBUG(10, ("\n"));
		}
	}
  
	return result;
}
@@ -1218,8 +1215,9 @@ BOOL get_pdc_ip(const char *domain, struct in_addr *ip)

	/* Look up #1B name */

	if (!internal_resolve_name(domain, 0x1b, &ip_list, &count, lp_name_resolve_order()))
	if (!internal_resolve_name(domain, 0x1b, &ip_list, &count, lp_name_resolve_order())) {
		return False;
	}

	/* if we get more than 1 IP back we have to assume it is a
	   multi-homed PDC and not a mess up */
@@ -1298,16 +1296,17 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
					num_addresses += auto_count;
				done_auto_lookup = True;
				DEBUG(8,("Adding %d DC's from auto lookup\n", auto_count));
			}
			else 
			} else  {
				num_addresses++;
			}
		}

		/* if we have no addresses and haven't done the auto lookup, then
		   just return the list of DC's */
		   
		if ( (num_addresses == 0) && !done_auto_lookup )
		if ( (num_addresses == 0) && !done_auto_lookup ) {
			return internal_resolve_name(domain, 0x1C, ip_list, count, resolve_order);
		}

		/* maybe we just failed? */
		
@@ -1317,8 +1316,7 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
		}
		
		if ( (return_iplist = (struct ip_service *)
			malloc(num_addresses * sizeof(struct ip_service))) == NULL ) 
		{
				malloc(num_addresses * sizeof(struct ip_service))) == NULL ) {
			DEBUG(3,("get_dc_list: malloc fail !\n"));
			return False;
		}
@@ -1335,6 +1333,13 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
			
			if ( strequal(name, "*") ) {
				for ( j=0; j<auto_count; j++ ) {
					/* Check for and don't copy any known bad DC IP's. */
					if(!NT_STATUS_IS_OK(check_negative_conn_cache(domain, 
							inet_ntoa(auto_ip_list[j].ip)))) {
						DEBUG(5,("get_dc_list: negative entry %s removed from DC list\n",
							inet_ntoa(auto_ip_list[j].ip) ));
						continue;
					}
					return_iplist[local_count].ip   = auto_ip_list[j].ip;
					return_iplist[local_count].port = auto_ip_list[j].port;
					local_count++;
@@ -1356,6 +1361,13 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,

			/* explicit lookup; resolve_name() will handle names & IP addresses */
			if ( resolve_name( name, &name_ip, 0x20 ) ) {

				/* Check for and don't copy any known bad DC IP's. */
				if( !NT_STATUS_IS_OK(check_negative_conn_cache(domain, inet_ntoa(name_ip))) ) {
					DEBUG(5,("get_dc_list: negative entry %s removed from DC list\n",name ));
					continue;
				}

				return_iplist[local_count].ip 	= name_ip;
				return_iplist[local_count].port = port;
				local_count++;
@@ -1368,8 +1380,9 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
		/* need to remove duplicates in the list if we have any 
		   explicit password servers */
		   
		if ( local_count )
		if ( local_count ) {
			local_count = remove_duplicate_addrs2( return_iplist, local_count );
		}
		
		if ( DEBUGLEVEL >= 4 ) {
			DEBUG(4,("get_dc_list: returning %d ip addresses in an %sordered list\n", local_count, 
@@ -1392,8 +1405,9 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
}

/*********************************************************************
 small wrapper function to get the DC list and sort it if neccessary 
 Small wrapper function to get the DC list and sort it if neccessary.
*********************************************************************/

BOOL get_sorted_dc_list( const char *domain, struct ip_service **ip_list, int *count, BOOL ads_only )
{
	BOOL ordered;
@@ -1401,13 +1415,14 @@ BOOL get_sorted_dc_list( const char *domain, struct ip_service **ip_list, int *c
	DEBUG(8,("get_sorted_dc_list: attempting lookup using [%s]\n",
		(ads_only ? "ads" : lp_name_resolve_order())));
	
	if ( !get_dc_list(domain, ip_list, count, ads_only, &ordered) )
	if ( !get_dc_list(domain, ip_list, count, ads_only, &ordered) ) {
		return False; 
	}
		
	/* only sort if we don't already have an ordered list */
	if ( !ordered )
	if ( !ordered ) {
		sort_ip_list2( *ip_list, *count );
	}
		
	return True;
}