#define IPSTR_LIST_SEP ","
#define IPSTR_LIST_CHAR ','
-/**
- * Allocate and initialise an ipstr list using ip adresses
- * passed as arguments.
- *
- * @param ctx TALLOC_CTX to use
- * @param ip_list array of ip addresses to place in the list
- * @param ip_count number of addresses stored in ip_list
- * @return pointer to allocated ip string
- **/
-
-static char *ipstr_list_make(TALLOC_CTX *ctx,
- const struct ip_service *ip_list,
- size_t ip_count)
-{
- char *ipstr_list = NULL;
- size_t i;
-
- /* arguments checking */
- if (ip_list == NULL) {
- return NULL;
- }
-
- /* process ip addresses given as arguments */
- for (i = 0; i < ip_count; i++) {
- char addr_buf[INET6_ADDRSTRLEN];
- char *new_str = NULL;
-
- print_sockaddr(addr_buf,
- sizeof(addr_buf),
- &ip_list[i].ss);
-
- if (ip_list[i].ss.ss_family == AF_INET) {
- /* IPv4 */
- new_str = talloc_asprintf(ctx,
- "%s:%d",
- addr_buf,
- ip_list[i].port);
- } else {
- /* IPv6 */
- new_str = talloc_asprintf(ctx,
- "[%s]:%d",
- addr_buf,
- ip_list[i].port);
- }
- if (new_str == NULL) {
- TALLOC_FREE(ipstr_list);
- return NULL;
- }
-
- if (ipstr_list == NULL) {
- /* First ip address. */
- ipstr_list = new_str;
- } else {
- /*
- * Append the separator "," and then the new
- * ip address to the existing list.
- *
- * The efficiency here is horrible, but
- * ip_count should be small enough we can
- * live with it.
- */
- char *tmp = talloc_asprintf(ctx,
- "%s%s%s",
- ipstr_list,
- IPSTR_LIST_SEP,
- new_str);
- if (tmp == NULL) {
- TALLOC_FREE(new_str);
- TALLOC_FREE(ipstr_list);
- return NULL;
- }
- TALLOC_FREE(new_str);
- TALLOC_FREE(ipstr_list);
- ipstr_list = tmp;
- }
- }
-
- return ipstr_list;
-}
-
/**
* Allocate and initialise an ipstr list using samba_sockaddr ip adresses
* passed as arguments.
name_type);
}
-/**
- * Store a name(s) in the name cache
- *
- * @param name netbios names array
- * @param name_type integer netbios name type
- * @param num_names number of names being stored
- * @param ip_list array of in_addr structures containing
- * ip addresses being stored
- **/
-
-bool namecache_store(const char *name,
- int name_type,
- size_t num_names,
- struct ip_service *ip_list)
-{
- time_t expiry;
- char *key = NULL;
- char *value_string = NULL;
- size_t i;
- bool ret = false;
- TALLOC_CTX *frame = talloc_stackframe();
-
- if (name_type > 255) {
- /* Don't store non-real name types. */
- goto out;
- }
-
- if ( DEBUGLEVEL >= 5 ) {
- char *addr = NULL;
-
- DBG_INFO("storing %zu address%s for %s#%02x: ",
- num_names, num_names == 1 ? "": "es", name, name_type);
-
- for (i = 0; i < num_names; i++) {
- addr = print_canonical_sockaddr(frame,
- &ip_list[i].ss);
- if (!addr) {
- continue;
- }
- DEBUGADD(5, ("%s%s", addr,
- (i == (num_names - 1) ? "" : ",")));
-
- }
- DEBUGADD(5, ("\n"));
- }
-
- key = namecache_key(frame, name, name_type);
- if (!key) {
- goto out;
- }
-
- expiry = time(NULL) + lp_name_cache_timeout();
-
- /*
- * Generate string representation of ip addresses list
- */
- value_string = ipstr_list_make(frame, ip_list, num_names);
- if (value_string == NULL) {
- goto out;
- }
-
- /* set the entry */
- ret = gencache_set(key, value_string, expiry);
-
- out:
-
- TALLOC_FREE(key);
- TALLOC_FREE(value_string);
- TALLOC_FREE(frame);
- return ret;
-}
-
/**
* Store a name(s) in the name cache - samba_sockaddr version.
*