Exemplo n.º 1
0
/********************************************************
 Resolve a name into an IP address. Use this function if
 the string is either an IP address, DNS or host name
 or NetBIOS name. This uses the name switch in the
 smb.conf to determine the order of name resolution.
*********************************************************/
BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
{
  int i;
  BOOL pure_address = True;
  pstring name_resolve_list;
  fstring tok;
  char *ptr;

  if (strcmp(name,"0.0.0.0") == 0) {
    return_ip->s_addr = 0;
    return True;
  }
  if (strcmp(name,"255.255.255.255") == 0) {
    return_ip->s_addr = 0xFFFFFFFF;
    return True;
  }
   
  for (i=0; pure_address && name[i]; i++)
    if (!(isdigit((int)name[i]) || name[i] == '.'))
      pure_address = False;
   
  /* if it's in the form of an IP address then get the lib to interpret it */
  if (pure_address) {
    return_ip->s_addr = inet_addr(name);
    return True;
  }

  pstrcpy(name_resolve_list, lp_name_resolve_order());
  if (name_resolve_list == NULL || *name_resolve_list == '\0')
    pstrcpy(name_resolve_list, "host");
  ptr = name_resolve_list;

  while (next_token(&ptr, tok, LIST_SEP, sizeof(tok))) {
	  if((strequal(tok, "host") || strequal(tok, "hosts"))) {
		  if (name_type == 0x20 && resolve_hosts(name, return_ip)) {
			  return True;
		  }
	  } else if(strequal( tok, "lmhosts")) {
		  if (resolve_lmhosts(name, return_ip, name_type)) {
			  return True;
		  }
	  } else if(strequal( tok, "wins")) {
		  /* don't resolve 1D via WINS */
		  if (name_type != 0x1D &&
		      resolve_wins(name, return_ip, name_type)) {
			  return True;
		  }
	  } else if(strequal( tok, "bcast")) {
		  if (resolve_bcast(name, return_ip, name_type)) {
			  return True;
		  }
	  } else {
		  DEBUG(0,("resolve_name: unknown name switch type %s\n", tok));
	  }
  }

  return False;
}
Exemplo n.º 2
0
struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx)
{
	const char **methods = lp_name_resolve_order(lp_ctx);
	int i;
	struct resolve_context *ret = resolve_context_init(lp_ctx);

	if (ret == NULL)
		return NULL;

	for (i = 0; methods != NULL && methods[i] != NULL; i++) {
		if (!strcmp(methods[i], "wins")) {
			resolve_context_add_wins_method_lp(ret, lp_ctx);
		} else if (!strcmp(methods[i], "bcast")) {
			resolve_context_add_bcast_method_lp(ret, lp_ctx);
		} else if (!strcmp(methods[i], "host")) {
			resolve_context_add_host_method(ret);
		} else {
			DEBUG(0, ("Unknown resolve method '%s'\n", methods[i]));
		}
	}

	return ret;
}