Beispiel #1
0
static void remove_permanent_name_from_unicast( struct subnet_record *subrec,
                                                struct nmb_name *nmbname )
{
	struct name_record *namerec;

	if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) != NULL) {
		/* Remove this broadcast subnet IP address from the name. */
		remove_ip_from_name_record( namerec, subrec->myip);
		if(namerec->data.num_ips == 0)
			remove_name_from_namelist( unicast_subnet, namerec);
	}
}
Beispiel #2
0
void run_elections(time_t t)
{
  static time_t lastime = 0;
  
  struct subnet_record *subrec;
  
  /* Send election packets once every 2 seconds - note */
  if (lastime && (t - lastime < 2))
    return;
  
  lastime = t;
  
  START_PROFILE(run_elections);
  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
  {
    struct work_record *work;

    for (work = subrec->workgrouplist; work; work = work->next)
    {
      if (work->RunningElection)
      {
        /*
         * We can only run an election for a workgroup if we have
         * registered the WORKGROUP<1e> name, as that's the name
         * we must listen to.
         */
        struct nmb_name nmbname;

        make_nmb_name(&nmbname, work->work_group, 0x1e);
        if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) {
          DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \
yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
          continue;
        }

        send_election_dgram(subrec, work->work_group, work->ElectionCriterion,
                      t - StartupTime, global_myname);
	      
        if (work->ElectionCount++ >= 4)
        {
          /* Won election (4 packets were sent out uncontested. */
          DEBUG(2,("run_elections: >>> Won election for workgroup %s on subnet %s <<<\n",
                    work->work_group, subrec->subnet_name ));

          work->RunningElection = False;

          become_local_master_browser(subrec, work);
        }
      }
    }
  }
Beispiel #3
0
BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp)
{
	struct name_record *namerec;

	*namerecp = NULL;

	if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, FIND_ANY_NAME))==NULL)
		return False;

	if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME))
		return False;

	*namerecp = namerec;
	return True;
}
Beispiel #4
0
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);
	}
}
Beispiel #5
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);
}