Пример #1
0
void sync_browse_lists(struct work_record *work,
		       char *name, int nm_type, 
		       struct in_addr ip, bool local, bool servers)
{
	struct sync_record *s;
	static int counter;

	START_PROFILE(sync_browse_lists);
	/* Check we're not trying to sync with ourselves. This can
	   happen if we are a domain *and* a local master browser. */
	if (ismyip_v4(ip)) {
done:
		END_PROFILE(sync_browse_lists);
		return;
	}

	s = SMB_MALLOC_P(struct sync_record);
	if (!s) goto done;

	ZERO_STRUCTP(s);

	unstrcpy(s->workgroup, work->work_group);
	unstrcpy(s->server, name);
	s->ip = ip;

	if (asprintf(&s->fname, "%s/sync.%d", lp_lockdir(), counter++) < 0) {
		SAFE_FREE(s);
		goto done;
	}
	/* Safe to use as 0 means no size change. */
	all_string_sub(s->fname,"//", "/", 0);

	DLIST_ADD(syncs, s);

	/* the parent forks and returns, leaving the child to do the
	   actual sync and call END_PROFILE*/
	CatchChild();
	if ((s->pid = sys_fork())) return;

	BlockSignals( False, SIGTERM );

	DEBUG(2,("Initiating browse sync for %s to %s(%s)\n",
		 work->work_group, name, inet_ntoa(ip)));

	fp = x_fopen(s->fname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
	if (!fp) {
		END_PROFILE(sync_browse_lists);
		_exit(1);
	}

	sync_child(name, nm_type, work->work_group, ip, local, servers,
		   s->fname);

	x_fclose(fp);
	END_PROFILE(sync_browse_lists);
	_exit(0);
}
Пример #2
0
static void find_all_domain_master_names_query_success(struct subnet_record *subrec,
        struct userdata_struct *userdata_in,
        struct nmb_name *q_name, struct in_addr answer_ip, struct res_rec *rrec)
{
    /*
     * We now have a list of all the domain master browsers for all workgroups
     * that have registered with the WINS server. Now do a node status request
     * to each one and look for the first 1b name in the reply. This will be
     * the workgroup name that we will add to the unicast subnet as a 'non-local'
     * workgroup.
     */

    struct nmb_name nmbname;
    struct in_addr send_ip;
    int i;

    if( DEBUGLVL( 5 ) ) {
        dbgtext( "find_all_domain_master_names_query_succes:\n" );
        dbgtext( "Got answer from WINS server of %d ", (rrec->rdlength / 6) );
        dbgtext( "IP addresses for Domain Master Browsers.\n" );
    }

    for(i = 0; i < rrec->rdlength / 6; i++) {
        /* Initiate the node status requests. */
        make_nmb_name(&nmbname, "*", 0);

        putip((char *)&send_ip, (char *)&rrec->rdata[(i*6) + 2]);

        /*
         * Don't send node status requests to ourself.
         */

        if(ismyip_v4( send_ip )) {
            if( DEBUGLVL( 5 ) ) {
                dbgtext( "find_all_domain_master_names_query_succes:\n" );
                dbgtext( "Not sending node status to our own IP " );
                dbgtext( "%s.\n", inet_ntoa(send_ip) );
            }
            continue;
        }

        if( DEBUGLVL( 5 ) ) {
            dbgtext( "find_all_domain_master_names_query_success:\n" );
            dbgtext( "Sending node status request to IP %s.\n", inet_ntoa(send_ip) );
        }

        node_status( subrec, &nmbname, send_ip,
                     get_domain_master_name_node_status_success,
                     get_domain_master_name_node_status_fail,
                     NULL);
    }
}
Пример #3
0
static void announce_local_master_browser_to_domain_master_browser( struct work_record *work)
{
	char outbuf[1024];
	unstring myname;
	unstring dmb_name;
	char *p;

	if(ismyip_v4(work->dmb_addr)) {
		if( DEBUGLVL( 2 ) ) {
			dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" );
			dbgtext( "We are both a domain and a local master browser for " );
			dbgtext( "workgroup %s.  ", work->work_group );
			dbgtext( "Do not announce to ourselves.\n" );
		}
		return;
	}

	memset(outbuf,'\0',sizeof(outbuf));
	p = outbuf;
	SCVAL(p,0,ANN_MasterAnnouncement);
	p++;

	unstrcpy(myname, lp_netbios_name());
	if (!strupper_m(myname)) {
		DEBUG(2,("strupper_m %s failed\n", myname));
		return;
	}
	myname[15]='\0';
	/* The call below does CH_UNIX -> CH_DOS conversion. JRA */
	push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE);

	p = skip_string(outbuf,sizeof(outbuf),p);

	if( DEBUGLVL( 4 ) ) {
		dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" );
		dbgtext( "Sending local master announce to " );
		dbgtext( "%s for workgroup %s.\n", nmb_namestr(&work->dmb_name),
					work->work_group );
	}

	/* Target name for send_mailslot must be in UNIX charset. */
	pull_ascii_nstring(dmb_name, sizeof(dmb_name), work->dmb_name.name);
	send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
		lp_netbios_name(), 0x0, dmb_name, 0x0,
		work->dmb_addr, FIRST_SUBNET->myip, DGRAM_PORT);
}