Exemple #1
0
void load_lmhosts_file(const char *fname)
{
	char *name = NULL;
	int name_type;
	struct sockaddr_storage ss;
	TALLOC_CTX *ctx = talloc_init("load_lmhosts_file");
	FILE *fp = startlmhosts( fname );

	if (!fp) {
		DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
			fname, strerror(errno)));
		TALLOC_FREE(ctx);
		return;
	}

	while (getlmhostsent(ctx, fp, &name, &name_type, &ss) ) {
		struct in_addr ipaddr;
		struct subnet_record *subrec = NULL;
		enum name_source source = LMHOSTS_NAME;

		if (ss.ss_family != AF_INET) {
			TALLOC_FREE(name);
			continue;
		}

		ipaddr = ((struct sockaddr_in *)&ss)->sin_addr;

		/* We find a relevent subnet to put this entry on, then add it. */
		/* Go through all the broadcast subnets and see if the mask matches. */
		for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
			if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip))
				break;
		}

		/* If none match add the name to the remote_broadcast_subnet. */
		if(subrec == NULL)
			subrec = remote_broadcast_subnet;

		if(name_type == -1) {
			/* Add the (0) and (0x20) names directly into the namelist for this subnet. */
			(void)add_name_to_subnet(subrec,name,0x00,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
			(void)add_name_to_subnet(subrec,name,0x20,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
		} else {
			/* Add the given name type to the subnet namelist. */
			(void)add_name_to_subnet(subrec,name,name_type,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
		}
	}

	TALLOC_FREE(ctx);
	endlmhosts(fp);
}
Exemple #2
0
/****************************************************************************
Load a lmhosts file.
****************************************************************************/
void load_lmhosts_file(char *fname)
{  
  pstring name;
  int name_type;
  struct in_addr ipaddr;
  FILE *fp = startlmhosts( fname );

  if (!fp) {
    DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
             fname, strerror(errno)));
    return;
  }
   
  while (getlmhostsent(fp, name, &name_type, &ipaddr) )
  {
    struct subnet_record *subrec = NULL;
    enum name_source source = LMHOSTS_NAME;

    /* We find a relevent subnet to put this entry on, then add it. */
    /* Go through all the broadcast subnets and see if the mask matches. */
    for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
    {
      if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
        break;
    }
  
    /* If none match add the name to the remote_broadcast_subnet. */
    if(subrec == NULL)
      subrec = remote_broadcast_subnet;

    if(name_type == -1)
    {
      /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
      (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
      (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
    }
    else
    {
      /* Add the given name type to the subnet namelist. */
      (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
    }
  }
   
  endlmhosts(fp);
}
static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr)
{
  int name_type = question->name_type;
  char *qname = question->name;
  
  
  if (!addr.s_addr) {
    /* add the fail to WINS cache of names. give it 1 hour in the cache */
    DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname));
    (void)add_name_to_subnet( wins_server_subnet, qname, name_type,
                              NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr );
    return( NULL );
  }

  /* add it to our WINS cache of names. give it 2 hours in the cache */
  DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr)));

  return( add_name_to_subnet( wins_server_subnet, qname, name_type,
                              NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr ) );
}
Exemple #4
0
static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr)
{
	int name_type = question->name_type;
	unstring qname;

	pull_ascii_nstring(qname, sizeof(qname), question->name);
  
	if (!addr.s_addr) {
		/* add the fail to WINS cache of names. give it 1 hour in the cache */
		DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname));
		add_name_to_subnet( wins_server_subnet, qname, name_type,
				NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr );
		return NULL;
	}

	/* add it to our WINS cache of names. give it 2 hours in the cache */
	DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr)));

	add_name_to_subnet( wins_server_subnet, qname, name_type,
                              NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr);

	return find_name_on_subnet(wins_server_subnet, question, FIND_ANY_NAME);
}
void insert_permanent_name_into_unicast( struct subnet_record *subrec, 
                                                struct nmb_name *nmbname, uint16 nb_type )
{
	unstring name;
	struct name_record *namerec;

	if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) {
		pull_ascii_nstring(name, sizeof(name), nmbname->name);
		/* The name needs to be created on the unicast subnet. */
		(void)add_name_to_subnet( unicast_subnet, name,
				nmbname->name_type, nb_type,
				PERMANENT_TTL, PERMANENT_NAME, 1, &subrec->myip);
	} else {
		/* The name already exists on the unicast subnet. Add our local
		IP for the given broadcast subnet to the name. */
		add_ip_to_name_record( namerec, subrec->myip);
	}
}
static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags,
				     register_name_success_function success_fn,
				     register_name_fail_function fail_fn)
{
	/*
	  If we are adding a group name, we just send multiple
	  register name packets to the WINS server (this is an
	  internet group name.

	  If we are adding a unique name, We need first to add 
	  our names to the unicast subnet namelist. This is 
	  because when a WINS server receives a multihomed 
	  registration request, the first thing it does is to 
	  send a name query to the registering machine, to see 
	  if it has put the name in it's local namelist.
	  We need the name there so the query response code in
	  nmbd_incomingrequests.c will find it.

	  We are adding this name prematurely (we don't really
	  have it yet), but as this is on the unicast subnet
	  only we will get away with this (only the WINS server
	  will ever query names from us on this subnet).
	*/
	int num_ips=0;
	int i, t;
	struct subnet_record *subrec;
	char **wins_tags;
	struct in_addr *ip_list;
	unstring name;

	for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) )
		num_ips++;
	
	if((ip_list = SMB_MALLOC_ARRAY(struct in_addr, num_ips))==NULL) {
		DEBUG(0,("multihomed_register_name: malloc fail !\n"));
		return;
	}

	for (subrec = FIRST_SUBNET, i = 0; 
	     subrec;
	     subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec), i++ ) {
		ip_list[i] = subrec->myip;
	}

	pull_ascii_nstring(name, sizeof(name), nmbname->name);
	add_name_to_subnet(unicast_subnet, name, nmbname->name_type,
			   nb_flags, lp_max_ttl(), SELF_NAME,
			   num_ips, ip_list);

	/* get the list of wins tags - we try to register for each of them */
	wins_tags = wins_srv_tags();

	/* Now try and register the name for each wins tag.  Note that
	   at this point we only register our first IP with each wins
	   group. We will register the rest from
	   wins_next_registration() when we get the reply for this
	   one. That follows the way W2K does things (tridge)
	*/
	for (t=0; wins_tags && wins_tags[t]; t++) {
		multihomed_register_one(nmbname, nb_flags,
					success_fn, fail_fn,
					ip_list[0],
					wins_tags[t]);
	}

	wins_srv_tags_free(wins_tags);
	
	SAFE_FREE(ip_list);
}