Esempio n. 1
0
/****************************************************************************
send out one query
****************************************************************************/
static BOOL query_one(char *lookup, unsigned int lookup_type)
{
	int j, count, flags;
	struct in_addr *ip_list=NULL;

	if (got_bcast) {
		printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr));
		ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast,
				     use_bcast?True:recursion_desired,
				     bcast_addr,&count, &flags);
	} else {
		struct in_addr *bcast;
		for (j=iface_count() - 1;
		     !ip_list && j >= 0;
		     j--) {
			bcast = iface_n_bcast(j);
			printf("querying %s on %s\n", 
			       lookup, inet_ntoa(*bcast));
			ip_list = name_query(ServerFD,lookup,lookup_type,
					     use_bcast,
					     use_bcast?True:recursion_desired,
					     *bcast,&count, &flags);
		}
	}

	if (give_flags)
		printf("Flags: %s\n", query_flags(flags));

	if (!ip_list) return False;

	for (j=0;j<count;j++) {
		if (translate_addresses) {
			struct hostent *host = gethostbyaddr((char *)&ip_list[j], sizeof(ip_list[j]), AF_INET);
			if (host) {
				printf("%s, ", host -> h_name);
			}
		}
		printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type);
	}

	/* We can only do find_status if the ip address returned
	   was valid - ie. name_query returned true.
	*/
	if (find_status) {
		do_node_status(ServerFD, lookup, lookup_type, ip_list[0]);
	}

	safe_free(ip_list);

	return (ip_list != NULL);
}
Esempio n. 2
0
static bool query_one(const char *lookup, unsigned int lookup_type)
{
	int j, count;
	uint8_t flags;
	struct sockaddr_storage *ip_list=NULL;
	NTSTATUS status = NT_STATUS_NOT_FOUND;

	if (got_bcast) {
		char addr[INET6_ADDRSTRLEN];
		print_sockaddr(addr, sizeof(addr), &bcast_addr);
		d_printf("querying %s on %s\n", lookup, addr);
		status = name_query(lookup,lookup_type,use_bcast,
				    use_bcast?true:recursion_desired,
				    &bcast_addr, talloc_tos(),
				    &ip_list, &count, &flags);
	} else {
		status = name_resolve_bcast(
			lookup, lookup_type,
			talloc_tos(), &ip_list, &count);
	}

	if (!NT_STATUS_IS_OK(status)) {
		return false;
	}

	if (give_flags) {
		d_printf("Flags: %s\n", query_flags(flags));
	}

	for (j=0;j<count;j++) {
		char addr[INET6_ADDRSTRLEN];
		if (translate_addresses) {
			char h_name[MAX_DNS_NAME_LENGTH];
			h_name[0] = '\0';
			if (sys_getnameinfo((const struct sockaddr *)&ip_list[j],
					sizeof(struct sockaddr_storage),
					h_name, sizeof(h_name),
					NULL, 0,
					NI_NAMEREQD)) {
				continue;
			}
			d_printf("%s, ", h_name);
		}
		print_sockaddr(addr, sizeof(addr), &ip_list[j]);
		d_printf("%s %s<%02x>\n", addr,lookup, lookup_type);
		/* We can only do find_status if the ip address returned
		   was valid - ie. name_query returned true.
		 */
		if (find_status) {
			if (!do_node_status(lookup, lookup_type, &ip_list[j])) {
				status = NT_STATUS_UNSUCCESSFUL;
			}
		}
	}

	TALLOC_FREE(ip_list);

	return NT_STATUS_IS_OK(status);
}
Esempio n. 3
0
static struct in_addr *lookup_byname_backend(const char *name, int *count)
{
	int fd;
	struct in_addr *ret = NULL;
	struct in_addr  p;
	int j, flags;

	*count = 0;

	fd = wins_lookup_open_socket_in();
	if (fd == -1)
		return NULL;

	p = wins_srv_ip();
	if( !is_zero_ip(p) ) {
		ret = name_query(fd,name,0x20,False,True, p, count, &flags);
		goto out;
	}

	if (lp_wins_support()) {
		/* we are our own WINS server */
		ret = name_query(fd,name,0x20,False,True, *interpret_addr2("127.0.0.1"), count, &flags);
		goto out;
	}

	/* uggh, we have to broadcast to each interface in turn */
	for (j=iface_count() - 1;
	     j >= 0;
	     j--) {
		struct in_addr *bcast = iface_n_bcast(j);
		ret = name_query(fd,name,0x20,True,True,*bcast,count, &flags);
		if (ret) break;
	}

 out:

	close(fd);
	return ret;
}
Esempio n. 4
0
/********************************************************
resolve via "wins" method
*********************************************************/
static BOOL
resolve_wins (const char *name, struct in_addr *return_ip, int name_type)
{
    int sock;
    struct in_addr wins_ip;
    BOOL wins_ismyip;

    /*
     * "wins" means do a unicast lookup to the WINS server.
     * Ignore if there is no WINS server specified or if the
     * WINS server is one of our interfaces (if we're being
     * called from within nmbd - we can't do this call as we
     * would then block).
     */

    DEBUG (3, ("resolve_name: Attempting wins lookup for name %s<0x%x>\n", name, name_type));

    if (!*lp_wins_server ())
    {
        DEBUG (3, ("resolve_name: WINS server resolution selected and no WINS server present.\n"));
        return False;
    }

    wins_ip = *interpret_addr2 (lp_wins_server ());
    wins_ismyip = ismyip (wins_ip);

    if ((wins_ismyip && !global_in_nmbd) || !wins_ismyip)
    {
        sock = open_socket_in (SOCK_DGRAM, 0, 3, interpret_addr (lp_socket_address ()), True);

        if (sock != -1)
        {
            struct in_addr *iplist = NULL;
            int count;
            iplist = name_query (sock, name, name_type, False, True, wins_ip, &count, NULL);
            if (iplist != NULL)
            {
                *return_ip = iplist[0];
                free ((char *) iplist);
                close (sock);
                return True;
            }
            close (sock);
        }
    }

    return False;
}
Esempio n. 5
0
static struct sockaddr_storage *lookup_byname_backend(TALLOC_CTX *mem_ctx,
						      const char *name,
						      int *count)
{
	struct ip_service *ret = NULL;
	struct sockaddr_storage *return_ss = NULL;
	int j, i;
	NTSTATUS status;

	*count = 0;

	/* always try with wins first */
	if (NT_STATUS_IS_OK(resolve_wins(name,0x20,&ret,count))) {
		if ( *count == 0 )
			return NULL;
		return_ss = TALLOC_ARRAY(mem_ctx, struct sockaddr_storage,
					 *count);
		if (return_ss == NULL ) {
			free( ret );
			return NULL;
		}

		/* copy the IP addresses */
		for ( i=0; i<(*count); i++ )
			return_ss[i] = ret[i].ss;

		free( ret );
		return return_ss;
	}

	/* uggh, we have to broadcast to each interface in turn */
	for (j=iface_count() - 1;
	     j >= 0;
	     j--) {
		const struct sockaddr_storage *bcast_ss = iface_n_bcast(j);
		if (!bcast_ss) {
			continue;
		}
		status = name_query(name, 0x20, True, True,bcast_ss,
				    mem_ctx, &return_ss, count, NULL);
		if (NT_STATUS_IS_OK(status)) {
			break;
		}
	}

	return return_ss;
}
Esempio n. 6
0
static struct in_addr *lookup_byname_backend(const char *name, int *count)
{
	int fd;
	struct ip_service *ret = NULL;
	struct in_addr *return_ip;
	int j, i, flags = 0;

	*count = 0;

	/* always try with wins first */
	if (resolve_wins(name,0x20,&ret,count)) {
		if ( count == 0 )
			return NULL;
		if ( (return_ip = (struct in_addr *)malloc((*count)*sizeof(struct in_addr))) == NULL ) {
			free( ret );
			return NULL;
		}

		/* copy the IP addresses */
		for ( i=0; i<(*count); i++ ) 
			return_ip[i] = ret[i].ip;
		
		free( ret );
		return return_ip;
	}

	fd = wins_lookup_open_socket_in();
	if (fd == -1) {
		return NULL;
	}

	/* uggh, we have to broadcast to each interface in turn */
	for (j=iface_count() - 1;
	     j >= 0;
	     j--) {
		struct in_addr *bcast = iface_n_bcast(j);
		return_ip = name_query(fd,name,0x20,True,True,*bcast,count, &flags, NULL);
		if (return_ip) break;
	}

	close(fd);
	return return_ip;
}
Esempio n. 7
0
/********************************************************
resolve via "bcast" method
*********************************************************/
static BOOL
resolve_bcast (const char *name, struct in_addr *return_ip, int name_type)
{
    int sock, i;

    /*
     * "bcast" means do a broadcast lookup on all the local interfaces.
     */

    DEBUG (3, ("resolve_name: Attempting broadcast lookup for name %s<0x%x>\n", name, name_type));

    sock = open_socket_in (SOCK_DGRAM, 0, 3, interpret_addr (lp_socket_address ()), True);

    if (sock != -1)
    {
        struct in_addr *iplist = NULL;
        int count;
        int num_interfaces = iface_count ();
        static char so_broadcast[] = "SO_BROADCAST";
        set_socket_options (sock, so_broadcast);
        /*
         * Lookup the name on all the interfaces, return on
         * the first successful match.
         */
        for (i = 0; i < num_interfaces; i++)
        {
            struct in_addr sendto_ip;
            /* Done this way to fix compiler error on IRIX 5.x */
            sendto_ip = *iface_bcast (*iface_n_ip (i));
            iplist = name_query (sock, name, name_type, True, True, sendto_ip, &count, NULL);
            if (iplist != NULL)
            {
                *return_ip = iplist[0];
                free ((char *) iplist);
                close (sock);
                return True;
            }
        }
        close (sock);
    }

    return False;
}
Esempio n. 8
0
/* check to see if nmbd is running on localhost by looking for a __SAMBA__
   response */
BOOL nmbd_running(void)
{
	int fd, count, flags;
	struct in_addr *ip_list;

	if ((fd = open_socket_in(SOCK_DGRAM, 0, 3,
				 interpret_addr("127.0.0.1"), True)) != -1) {
		if ((ip_list = name_query(fd, "__SAMBA__", 0, 
					  True, True, loopback_ip,
					  &count, &flags, NULL)) != NULL) {
			SAFE_FREE(ip_list);
			close(fd);
			return True;
		}
		close (fd);
	}

	return False;
}
Esempio n. 9
0
/* check to see if nmbd is running on localhost by looking for a __SAMBA__
   response */
bool nmbd_running(void)
{
	struct in_addr loopback_ip;
	int count;
	struct sockaddr_storage *ss_list;
	struct sockaddr_storage ss;
	NTSTATUS status;

	loopback_ip.s_addr = htonl(INADDR_LOOPBACK);
	in_addr_to_sockaddr_storage(&ss, loopback_ip);

	status = name_query("__SAMBA__", 0,
			    True, True, &ss,
			    talloc_tos(), &ss_list, &count,
			    NULL);
	if (NT_STATUS_IS_OK(status)) {
		TALLOC_FREE(ss_list);
		return True;
	}

	return False;
}
Esempio n. 10
0
static bool query_one(const char *lookup, unsigned int lookup_type)
{
	int j, count, flags = 0;
	struct sockaddr_storage *ip_list=NULL;

	if (got_bcast) {
		char addr[INET6_ADDRSTRLEN];
		print_sockaddr(addr, sizeof(addr), &bcast_addr);
		d_printf("querying %s on %s\n", lookup, addr);
		ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast,
				     use_bcast?true:recursion_desired,
				     &bcast_addr, &count, &flags, NULL);
	} else {
		const struct in_addr *bcast;
		for (j=iface_count() - 1;
		     !ip_list && j >= 0;
		     j--) {
			char addr[INET6_ADDRSTRLEN];
			struct sockaddr_storage bcast_ss;

			bcast = iface_n_bcast_v4(j);
			if (!bcast) {
				continue;
			}
			in_addr_to_sockaddr_storage(&bcast_ss, *bcast);
			print_sockaddr(addr, sizeof(addr), &bcast_ss);
			d_printf("querying %s on %s\n",
			       lookup, addr);
			ip_list = name_query(ServerFD,lookup,lookup_type,
					     use_bcast,
					     use_bcast?True:recursion_desired,
					     &bcast_ss,&count, &flags, NULL);
		}
	}

	if (!ip_list) {
		return false;
	}

	if (give_flags) {
		d_printf("Flags: %s\n", query_flags(flags));
	}

	for (j=0;j<count;j++) {
		char addr[INET6_ADDRSTRLEN];
		if (translate_addresses) {
			char h_name[MAX_DNS_NAME_LENGTH];
			h_name[0] = '\0';
			if (sys_getnameinfo((const struct sockaddr *)&ip_list[j],
					sizeof(struct sockaddr_storage),
					h_name, sizeof(h_name),
					NULL, 0,
					NI_NAMEREQD)) {
				continue;
			}
			d_printf("%s, ", h_name);
		}
		print_sockaddr(addr, sizeof(addr), &ip_list[j]);
		d_printf("%s %s<%02x>\n", addr,lookup, lookup_type);
		/* We can only do find_status if the ip address returned
		   was valid - ie. name_query returned true.
		 */
		if (find_status) {
			do_node_status(ServerFD, lookup,
					lookup_type, &ip_list[j]);
		}
	}

	free(ip_list);

	return (ip_list != NULL);
}
Esempio n. 11
0
    move_entry_t::move_entry_t(int version_id,
                               int move_id)
    {   
        CONNECT_TO_DB(db);
        if(not entries_created)
            create_none_invalid_entries();

        if(move_id == Moves::NONE)
        {
            *this = none_entry;
            return;
        }
        else if(move_id == Moves::INVALID)
        {
            *this = invalid_entry;
            return;
        }

        int generation = database::get_generation(version_id);

        std::ostringstream query_stream;
        query_stream << "SELECT generation_id FROM moves WHERE id=" << move_id;
        if(int(db->execAndGet(query_stream.str().c_str())) > generation)
            throw std::runtime_error("This move did not exist in this generation.");

        /*
         * The "moves" table should give us most things.
         */
        query_stream.str("");
        query_stream << "SELECT * FROM moves WHERE id=" << move_id;
        SQLite::Statement moves_query(*db, query_stream.str().c_str());
        moves_query.executeStep();

        name = database::get_move_name(move_id);
        type = database::get_type_name(moves_query.getColumn(3)); // type_id
        damage_class = database::get_move_damage_class_name(int(moves_query.getColumn(9))); // damage_class_id

        power = moves_query.getColumn(4); // power
        pp = moves_query.getColumn(5); // pp
        accuracy = float(moves_query.getColumn(6)) / float(100.0); // accuracy
        priority = moves_query.getColumn(7); // priority

        // effect = 
        effect_chance = float(moves_query.getColumn(11)) / float(100.0); // effect_chance

        /*
         * Description
         */
        query_stream.str("");
        query_stream << "SELECT flavor_text FROM move_flavor_text WHERE move_id="
                     << move_id << " AND language_id=9 AND version_group_id="
                     << database::get_version_group_id(version_id);
        SQLite::Statement flavor_text_query(*db, query_stream.str().c_str());
        try
        {
            description = get_pkstring_from_query(flavor_text_query);
        }
        catch(...)
        {
            description = "Unavailable";
        }

        /*
         * Target
         */
        query_stream.str("");
        query_stream << "SELECT name FROM move_target_prose WHERE move_target_id="
                     << moves_query.getColumn(8) << " AND local_language_id=9"; // target_id
        SQLite::Statement move_target_prose_query(*db, query_stream.str().c_str());
        target = get_pkstring_from_query(move_target_prose_query);

        /*
         * Effect
         * TODO: parse tokens in short_effect
         */
        query_stream.str("");
        query_stream << "SELECT short_effect FROM move_effect_prose WHERE move_effect_id="
                     << moves_query.getColumn(10);  // effect_id
        SQLite::Statement move_effect_prose_query(*db, query_stream.str().c_str());
        effect = get_pkstring_from_query(move_effect_prose_query);

        /*
         * Contest type
         */
        query_stream.str("");
        query_stream << "SELECT name FROM contest_type_names WHERE contest_type_id="
                     << moves_query.getColumn(12) << " AND local_language_id=9"; // contest_type_id
        SQLite::Statement contest_type_names_query(*db, query_stream.str().c_str());
        contest_type = get_pkstring_from_query(contest_type_names_query);

        /*
         * Contest effect
         */
        query_stream.str("");
        query_stream << "SELECT flavor_text FROM contest_effect_prose WHERE contest_effect_id="
                     << moves_query.getColumn(13) << " AND local_language_id=9"; // contest_effect_id
        SQLite::Statement contest_effect_prose_query(*db, query_stream.str().c_str());
        contest_effect = get_pkstring_from_query(contest_effect_prose_query);

        /*
         * Super Contest effect
         */
        query_stream.str("");
        query_stream << "SELECT flavor_text FROM super_contest_effect_prose"
                     << " WHERE super_contest_effect_id=" << moves_query.getColumn(14)
                     << " AND local_language_id=9"; // super_contest_effect_id
        SQLite::Statement super_contest_effect_prose_query(*db, query_stream.str().c_str());
        super_contest_effect = get_pkstring_from_query(super_contest_effect_prose_query);

        /*
         * Database values are valid for Generation VI, this fixes entries
         * from earlier generations.
         */
        if(generation < 6)
        {
            std::ostringstream query_stream;
            query_stream << "SELECT gen" << generation << "_accuracy FROM old_move_accuracies WHERE move_id=" << move_id;
            SQLite::Statement accuracy_query(*db, query_stream.str().c_str());
            if(accuracy_query.executeStep()) accuracy = float(accuracy_query.getColumn(0)) / 100.0;
        
            // Hypnosis varies in accuracy between games
            if(move_id == Moves::HYPNOSIS and (version_id == Versions::DIAMOND or version_id == Versions::PEARL))
                accuracy = 0.7f;

            query_stream.str("");
            query_stream << "SELECT gen" << generation << "_power FROM old_move_powers WHERE move_id=" << move_id;
            SQLite::Statement power_query(*db, query_stream.str().c_str());
            if(power_query.executeStep()) power = power_query.getColumn(0);

            // Shadow Rush varies in power between Gamecube games
            if(move_id == Moves::SHADOW_RUSH and version_id == Versions::COLOSSEUM)
                power = 90; 

            query_stream.str("");
            query_stream << "SELECT gen" << generation << "_pp FROM old_move_pps WHERE move_id=" << move_id;
            SQLite::Statement pp_query(*db, query_stream.str().c_str());
            if(pp_query.executeStep())
                pp = pp_query.getColumn(0);

            // Not enough type changes to warrant a database table
            if(generation == 1)
            {
                if(move_id == Moves::BITE or move_id == Moves::GUST or
                   move_id == Moves::KARATE_CHOP or move_id == Moves::SAND_ATTACK)
                    type = "Normal";
            }
            else if(move_id == Moves::CURSE and generation < 4)
                type = "???";
            else if(move_id == Moves::CHARM or move_id == Moves::MOONLIGHT or
                    move_id == Moves::SWEET_KISS)
                type = "Normal";

            // Only one move changes categories before Generation IV
            if(generation == 1 and move_id == Moves::BITE)
                damage_class = "Physical";
        
            // TODO: targeting changes, making contact

            query_stream.str("");
            query_stream << "SELECT gen" << generation << "_priority FROM old_move_priorities WHERE move_id=" << move_id;
            SQLite::Statement priority_query(*db, query_stream.str().c_str());
            if(priority_query.executeStep())
                priority = priority_query.getColumn(0);

            // Only one move changed name between Generation II-III
            if(move_id == Moves::CONVERSION_2 and generation < 3)
                name = "Conversion2";

            query_stream.str("");
            query_stream << "SELECT name FROM old_move_names WHERE move_id=" << move_id;
            SQLite::Statement name_query(*db, query_stream.str().c_str());
            if(name_query.executeStep())
                name = name_query.getColumn(0);

            if(generation != 4)
                super_contest_effect = "None";

            if(generation < 4)
            {
                query_stream.str("");
                query_stream << "SELECT name FROM move_damage_class_prose WHERE local_language_id=9"
                             << " AND move_damage_class_id=(SELECT damage_class_id FROM types WHERE"
                             << " id=" << database::get_type_id(type) << ")";
                std::string damage_class_name = db->execAndGet(query_stream.str().c_str());
                damage_class_name[0] = ::toupper(damage_class_name[0]);
                damage_class = damage_class_name;
            }

            if(generation < 3)
            {
                contest_type   = "None";
                contest_effect = "None";
            }
        }
    }