trusted domains n+4 and related stuff

Rafal Szczesniak mimir at diament.ists.pwr.wroc.pl
Thu Nov 21 22:27:01 GMT 2002


This patch contains:
 - new namecache implementation
 - new ip string list handling routines
 - trustdom_cache implementation (libsmb/trustdom_cache.c)
 - fix to establishing trust (ie. net rpc trustdom establish)
 - small enhancement to rpcclient trustdom enumeration
 - small extension to gencache entries iterating
 - extension to 'net cache' functionality


As always, feedback and comments are welcome :)


-- 
cheers,
+------------------------------------------------------------+
|Rafal 'Mimir' Szczesniak <mimir at diament.ists.pwr.wroc.pl>   |
|*BSD, GNU/Linux and Samba                                  /
|__________________________________________________________/
-------------- next part --------------
Index: Makefile.in
===================================================================
RCS file: /cvsroot/samba/source/Makefile.in,v
retrieving revision 1.576
diff -u -r1.576 Makefile.in
--- Makefile.in	15 Nov 2002 17:01:23 -0000	1.576
+++ Makefile.in	21 Nov 2002 22:03:55 -0000
@@ -176,7 +176,7 @@
              libsmb/smberr.o libsmb/credentials.o libsmb/pwd_cache.o \
 	     libsmb/clioplock.o libsmb/errormap.o libsmb/clirap2.o \
 	     libsmb/passchange.o libsmb/unexpected.o libsmb/doserr.o \
-	     libsmb/namecache.o $(RPC_PARSE_OBJ1)
+	     libsmb/namecache.o libsmb/trustdom_cache.o $(RPC_PARSE_OBJ1)
 
 LIBMSRPC_OBJ = rpc_client/cli_lsarpc.o rpc_client/cli_samr.o \
 	       rpc_client/cli_netlogon.o rpc_client/cli_srvsvc.o \
Index: lib/gencache.c
===================================================================
RCS file: /cvsroot/samba/source/lib/gencache.c,v
retrieving revision 1.1
diff -u -r1.1 gencache.c
--- lib/gencache.c	11 Sep 2002 14:07:15 -0000	1.1
+++ lib/gencache.c	21 Nov 2002 22:04:02 -0000
@@ -92,7 +92,6 @@
 
 /**
  * Add one entry to the cache file.
- * (it part of tridge's proposed API)
  *
  * @param key string that represents a key of this entry
  * @param value text representation value being cached
@@ -133,7 +132,6 @@
 
 /**
  * Set existing entry to the cache file.
- * (it part of tridge's proposed API)
  *
  * @param key string that represents a key of this entry
  * @param value text representation value being cached
@@ -189,7 +187,6 @@
 
 /**
  * Delete one entry from the cache file.
- * (it part of tridge's proposed API)
  *
  * @param key string that represents a key of this entry
  *
@@ -219,11 +216,10 @@
 
 /**
  * Get existing entry from the cache file.
- * (it part of tridge's proposed API)
  *
  * @param key string that represents a key of this entry
  * @param value buffer that is allocated and filled with the entry value
- *        buffer's disposing is done outside
+ *        buffer's disposing must be done outside
  * @param timeout pointer to a time_t that is filled with entry's
  *        timeout
  *
@@ -269,12 +265,14 @@
  *
  * @param fn pointer to the function that will be supplied with each single
  *        matching cache entry (key, value and timeout) as an arguments
+ * @param data void pointer to an arbitrary data that is passed directly to the fn
+ *        function on each call
  * @param keystr_pattern pattern the existing entries' keys are matched to
  *
  **/
 
-void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout),
-                      const char* keystr_pattern)
+void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr),
+                      void* data, const char* keystr_pattern)
 {
 	TDB_LIST_NODE *node, *first_node;
 	TDB_DATA databuf;
@@ -286,7 +284,7 @@
 
 	if (!gencache_init()) return;
 
-	DEBUG(5, ("Searching cache keys with pattern %s", keystr_pattern));
+	DEBUG(5, ("Searching cache keys with pattern %s\n", keystr_pattern));
 	node = tdb_search_keys(cache, keystr_pattern);
 	first_node = node;
 	
@@ -306,7 +304,7 @@
 		
 		DEBUG(10, ("Calling function with arguments (key = %s, value = %s, timeout = %s)\n",
 		           keystr, valstr, ctime(&timeout)));
-		fn(keystr, valstr, timeout);
+		fn(keystr, valstr, timeout, data);
 		
 		SAFE_FREE(valstr);
 		SAFE_FREE(entry);
@@ -315,5 +313,4 @@
 	
 	tdb_search_list_free(first_node);
 }
-
 
Index: lib/util_str.c
===================================================================
RCS file: /cvsroot/samba/source/lib/util_str.c,v
retrieving revision 1.66
diff -u -r1.66 util_str.c
--- lib/util_str.c	12 Nov 2002 23:15:49 -0000	1.66
+++ lib/util_str.c	21 Nov 2002 22:04:05 -0000
@@ -1366,3 +1366,141 @@
 	
 	return True;
 }
+
+
+/**
+ * Add ip string representation to ipstr list. Used also
+ * as part of @function ipstr_list_make
+ *
+ * @param ipstr_list pointer to string containing ip list;
+ *        MUST BE already allocated and IS reallocated if necessary
+ * @param ipstr_size pointer to current size of ipstr_list (might be changed
+ *        as a result of reallocation)
+ * @param ip IP address which is to be added to list
+ * @return pointer to string appended with new ip and possibly
+ *         reallocated to new length
+ **/
+
+char* ipstr_list_add(char** ipstr_list, int *ipstr_size, const struct in_addr *ip)
+{
+	int ipstr_len, ipstr_chunk;
+	fstring ipstr;
+	
+	/* arguments checking */
+	if (!ipstr_list || !ip) return NULL;
+
+	/* set initial values */
+	ipstr_chunk = *ipstr_size / (FSTRING_LEN / 8);
+	ipstr_len = strlen(*ipstr_list);
+			
+	/* attempt to convert ip to a string and append colon separator to it */
+	safe_strcpy(ipstr, inet_ntoa(*ip), sizeof(ipstr));
+	if (ipstr)
+		safe_strcat(ipstr, ":", sizeof(ipstr));
+	else
+		return NULL;
+	
+	/* calculate new size of the string and reallocate it if needed */
+	ipstr_len += strlen(ipstr);
+	if (ipstr_len >= *ipstr_size) {
+		*ipstr_size = ++ipstr_chunk * (FSTRING_LEN / 8);
+		*ipstr_list = (char*)Realloc((void*)(*ipstr_list),
+		                             sizeof(char) * (*ipstr_size));
+	}
+	
+	/* append new ip string to the list */
+	safe_strcat(*ipstr_list, ipstr, *ipstr_size);
+	
+	return *ipstr_list;
+}
+
+
+/**
+ * Allocate and initialise an ipstr list using ip adresses
+ * passed as arguments.
+ *
+ * @param ipstr_list pointer to string meant to be allocated and set
+ * @param ip_list array of ip addresses to place in the list
+ * @param ip_count number of addresses stored in ip_list
+ * @return length of allocated ip string
+ **/
+ 
+int ipstr_list_make(char** ipstr_list, const struct in_addr* ip_list, int ip_count)
+{
+	int i, alloc_size;
+	
+	/* arguments checking */
+	if (!ip_list && !ipstr_list) return 0;
+
+	alloc_size = FSTRING_LEN / 8;	/* chosen emprically */
+	*ipstr_list = NULL;
+	
+	/* allocate initial list string and clear it if allocated correctly */
+	*ipstr_list = (char*)malloc(sizeof(char) * alloc_size);
+	if (! *ipstr_list) return 0;
+	memset((void*)(*ipstr_list), 0, alloc_size);
+	
+	/* process ip addresses given as arguments */
+	for (i = 0; i < ip_count; i++)
+		*ipstr_list = ipstr_list_add(ipstr_list, &alloc_size, &ip_list[i]);
+	
+	return alloc_size;
+}
+
+
+/**
+ * Parse given ip string list into array of ip addresses
+ * (as in_addr structures)
+ *
+ * @param ipstr ip string list to be parsed 
+ * @param ip_list pointer to array of ip addresses which is
+ *        allocated by this function and must be freed by caller
+ * @return number of succesfully parsed addresses
+ **/
+ 
+int ipstr_list_parse(const char* ipstr_list, struct in_addr** ip_list)
+{
+	fstring token_str;
+	int chunk_size, chunk, i;
+
+	i = 0;
+	chunk_size = 4;
+	chunk = 1;
+	
+	if (!ipstr_list || !ip_list) return 0;
+	
+	/* allocate some place for returned ip addresses */
+	*ip_list = (struct in_addr*)malloc(sizeof(struct in_addr)
+	                                   * chunk_size * chunk);
+	if (!*ip_list) return 0;
+	
+	/* ip_str must be empty at the begin */
+	token_str[i] = 0;
+	
+	while (next_token(&ipstr_list, token_str, ":", FSTRING_LEN)) {
+		/* realloc array of ip addresses if needed */
+		if (i >= chunk_size * chunk) {
+			*ip_list = (struct in_addr*)Realloc(*ip_list, sizeof(struct in_addr)
+			                                    * chunk_size * ++chunk);
+			if (!*ip_list) return 0;
+		}
+
+		/* convert single token to ip address */
+		inet_aton(token_str, &(*ip_list)[i++]);
+	}
+	
+	return i;
+}
+
+
+/**
+ * Safely free ip string list
+ *
+ * @param ipstr_list ip string list to be freed
+ **/
+
+void ipstr_list_free(char* ipstr_list)
+{
+	SAFE_FREE(ipstr_list);
+}
+
Index: libsmb/cliconnect.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/cliconnect.c,v
retrieving revision 1.115
diff -u -r1.115 cliconnect.c
--- libsmb/cliconnect.c	12 Nov 2002 23:15:49 -0000	1.115
+++ libsmb/cliconnect.c	21 Nov 2002 22:04:08 -0000
@@ -1013,7 +1013,7 @@
          * about this and accounts for those four bytes.
          * CRH.
          */
-        len -= 4;
+	len -= 4;
 	_smb_setlen(cli->outbuf,len);
 	SCVAL(cli->outbuf,0,0x81);
 
Index: libsmb/namecache.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/namecache.c,v
retrieving revision 1.8
diff -u -r1.8 namecache.c
--- libsmb/namecache.c	28 Aug 2002 00:17:11 -0000	1.8
+++ libsmb/namecache.c	21 Nov 2002 22:04:09 -0000
@@ -1,9 +1,10 @@
 /* 
    Unix SMB/CIFS implementation.
 
-   NetBIOS name cache module.
-
-   Copyright (C) Tim Potter, 2002
+   NetBIOS name cache module on top of gencache mechanism.
+   
+   Copyright (C) Tim Potter         2002
+   Copyright (C) Rafal Szczesniak   2002
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -22,242 +23,232 @@
 
 #include "includes.h"
 
-static BOOL done_namecache_init;
-static BOOL enable_namecache;
-static TDB_CONTEXT *namecache_tdb;
-
-struct nc_value {
-	time_t expiry;		     /* When entry expires */
-	int count;		     /* Number of addresses */
-	struct in_addr ip_list[1];   /* Address list */
-};
+#define NBTKEY_FMT  "NBT/%s#%02X"
+
 
-/* Initialise namecache system */
+/**
+ * Initialise namecache system. Function calls gencache
+ * initialisation function to perform necessary actions
+ * 
+ * @return true upon successful initialisation of the cache or
+ *         false on failure
+ **/
 
 BOOL namecache_enable(void)
 {
-	/* Check if we have been here before, or name caching disabled
-           by setting the name cache timeout to zero. */ 
-
-	if (done_namecache_init)
-		return False;
-
-	done_namecache_init = True;
+	/*
+	 * Check if name caching disabled by setting the name cache
+	 * timeout to zero.
+	 */ 
 
 	if (lp_name_cache_timeout() == 0) {
-		DEBUG(5, ("namecache_init: disabling netbios name cache\n"));
+		DEBUG(5, ("namecache_enable: disabling netbios name cache\n"));
 		return False;
 	}
 
-	/* Open namecache tdb in read/write or readonly mode */
+	/* Init namecache by calling gencache initialisation */
 
-	namecache_tdb = tdb_open_log(
-		lock_path("namecache.tdb"), 0,
-		TDB_DEFAULT, O_RDWR | O_CREAT, 0644);
-
-	if (!namecache_tdb) {
-		DEBUG(5, ("namecache_init: could not open %s\n",
-			  lock_path("namecache.tdb")));
+	if (!gencache_init()) {
+		DEBUG(2, ("namecache_enable: Couldn't initialise namecache on top of gencache.\n"));
 		return False;
 	}
 
-	DEBUG(5, ("namecache_init: enabling netbios namecache, timeout %d "
+	/* I leave it for now, though I don't think we really need this (mimir, 27.09.2002) */
+	DEBUG(5, ("namecache_enable: enabling netbios namecache, timeout %d "
 		  "seconds\n", lp_name_cache_timeout()));
 
-	enable_namecache = True;
-
 	return True;
 }
 
-/* Return a key for a name and name type.  The caller must free
-   retval.dptr when finished. */
 
-static TDB_DATA namecache_key(const char *name, int name_type)
+/**
+ * Shutdown namecache. Routine calls gencache close function
+ * to safely close gencache file.
+ *
+ * @return true upon successful shutdown of the cache or
+ *         false on failure
+ **/
+ 
+BOOL namecache_shutdown(void)
 {
-	TDB_DATA retval;
-	char *keystr;
-
-	asprintf(&keystr, "%s#%02X", strupper_static(name), name_type);
-
-	retval.dsize = strlen(keystr) + 1;
-	retval.dptr = keystr;
-
-	return retval;
+	if (!gencache_shutdown()) {
+		DEBUG(2, ("namecache_shutdown: Couldn't close namecache on top of gencache.\n"));
+		return False;
+	}
+	
+	DEBUG(5, ("namecache_shutdown: netbios namecache closed successfully.\n"));
+	return True;
 }
 
-/* Return a data value for an IP list.  The caller must free
-   retval.dptr when finished. */
-
-static TDB_DATA namecache_value(struct in_addr *ip_list, int num_names, 
-				time_t expiry)
-{
-	TDB_DATA retval;
-	struct nc_value *value;
-	int size = sizeof(struct nc_value);
-
-	if (num_names > 0)
-		size += sizeof(struct in_addr) * (num_names-1);
-
-	value = (struct nc_value *)malloc(size);
-
-	memset(value, 0, size);
 
-	value->expiry = expiry;
-	value->count = num_names;
+/**
+ * Generates a key for netbios name lookups on basis of
+ * netbios name and type.
+ * The caller must free returned key string when finished.
+ *
+ * @param name netbios name string (case insensitive)
+ * @param name_type netbios type of the name being looked up
+ *
+ * @return string consisted of uppercased name and appended
+ *         type number
+ */
 
-	if (ip_list)
-		memcpy(value->ip_list, ip_list, sizeof(struct in_addr) * num_names);
-
-	retval.dptr = (char *)value;
-	retval.dsize = size;
+static char* namecache_key(const char *name, int name_type)
+{
+	char *keystr;
+	asprintf(&keystr, NBTKEY_FMT, strupper_static(name), name_type);
 
-	return retval;
+	return keystr;
 }
 
-/* Store a name in the name cache */
 
-void namecache_store(const char *name, int name_type,
-		     int num_names, struct in_addr *ip_list)
+/**
+ * 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,
+                     int num_names, struct in_addr *ip_list)
 {
-	TDB_DATA key, value;
 	time_t expiry;
-	int i;
+	char *key, *value_string;
+	int i, value_len;
 
-	if (!enable_namecache)
-		return;
+	/*
+	 * we use gecache call to avoid annoying debug messages about
+	 * initialised namecache again and again...
+	 */
+	if (!gencache_init()) return False;
 
 	DEBUG(5, ("namecache_store: storing %d address%s for %s#%02x: ",
-		  num_names, num_names == 1 ? "": "es", name, name_type));
+	          num_names, num_names == 1 ? "": "es", name, name_type));
 
 	for (i = 0; i < num_names; i++) 
 		DEBUGADD(5, ("%s%s", inet_ntoa(ip_list[i]),
-			     i == (num_names - 1) ? "" : ", "));
+		             i == (num_names - 1) ? "" : ", "));
 
 	DEBUGADD(5, ("\n"));
 
 	key = namecache_key(name, name_type);
 
-	/* Cache pdc location or dc lists for only a little while
-	   otherwise if we lock on to a bad DC we can potentially be
-	   out of action for the entire cache timeout time! */
+	/* 
+	 * Cache pdc location or dc lists for only a little while
+	 * otherwise if we lock on to a bad DC we can potentially be
+	 * out of action for the entire cache timeout time!
+	 */
 
 	if (name_type != 0x1b || name_type != 0x1c)
 		expiry = time(NULL) + 10;
 	else
 		expiry = time(NULL) + lp_name_cache_timeout();
 
-	value = namecache_value(ip_list, num_names, expiry);
-
-	tdb_store(namecache_tdb, key, value, TDB_REPLACE);
-
-	free(key.dptr);
-	free(value.dptr);
+	/*
+	 * Generate string representation of ip addresses list
+	 * First, store the number of ip addresses and then
+	 * place each single ip
+	 */
+	
+	value_len = ipstr_list_make(&value_string, ip_list, num_names);
+	
+	/*
+	 * if an attempt to set fails, then perhaps there's no such
+	 * entry and it's better to add i
+	 */
+	 
+	if (!gencache_set(key, value_string, expiry))
+		return (gencache_add(key, value_string, expiry));
+	
+	return True;
 }
 
-/* Look up a name in the name cache.  Return a mallocated list of IP
-   addresses if the name is contained in the cache. */
+
+/**
+ * Look up a name in the cache.
+ *
+ * @param name netbios name to look up for
+ * @param name_type netbios name type of @param name
+ * @param ip_list mallocated list of IP addresses if found in the cache,
+ *        NULL otherwise
+ * @param num_names number of entries found
+ *
+ * @return true upon successful fetch or
+ *         false if name isn't found in the cache or has expired
+ **/
 
 BOOL namecache_fetch(const char *name, int name_type, struct in_addr **ip_list,
-		     int *num_names)
+                     int *num_names)
 {
-	TDB_DATA key, value;
-	struct nc_value *data;
-	time_t now;
-	int i;
+	char *key, *value;
+	time_t timeout;
 
-	*ip_list = NULL;
 	*num_names = 0;
 
-	if (!enable_namecache)
-		return False;
+	/* exit now if null pointers were passed as they're required further */
+	if (!ip_list || !num_names) return False;
 
-	/* Read value */
+	if (!gencache_init())
+		return False;
 
+	/* 
+	 * Use gencache interface - lookup the key
+	 */
 	key = namecache_key(name, name_type);
 
-	value = tdb_fetch(namecache_tdb, key);
-	
-	if (!value.dptr) {
-		DEBUG(5, ("namecache_fetch: %s#%02x not found\n",
-			  name, name_type));
-		goto done;
-	}
-
-	data = (struct nc_value *)value.dptr;
-
-	/* Check expiry time */
-
-	now = time(NULL);
-
-	if (now > data->expiry) {
-
-		DEBUG(5, ("namecache_fetch: entry for %s#%02x expired\n",
-			  name, name_type));
-
-		tdb_delete(namecache_tdb, key);
-
-		value = tdb_null;
-
-		goto done;
-	}
-
-	if ((data->expiry - now) > lp_name_cache_timeout()) {
-
-		/* Someone may have changed the system time on us */
-
-		DEBUG(5, ("namecache_fetch: entry for %s#%02x has bad expiry\n",
-			  name, name_type));
-
-		tdb_delete(namecache_tdb, key);
-
-		value = tdb_null;
-
-		goto done;
-	}
-
-	/* Extract and return namelist */
-
-	DEBUG(5, ("namecache_fetch: returning %d address%s for %s#%02x: ",
-		  data->count, data->count == 1 ? "" : "es", name, name_type));
-
-	if (data->count) {
-
-		*ip_list = (struct in_addr *)malloc(
-			sizeof(struct in_addr) * data->count);
-		
-		memcpy(*ip_list, data->ip_list, sizeof(struct in_addr) * data->count);
-		
-		*num_names = data->count;
-		
-		for (i = 0; i < *num_names; i++)
-			DEBUGADD(5, ("%s%s", inet_ntoa((*ip_list)[i]),
-				     i == (*num_names - 1) ? "" : ", "));
-
+	if (!gencache_get(key, &value, &timeout)) {
+		DEBUG(5, ("no entry for %s#%02X found.\n", name, name_type));
+		SAFE_FREE(key);
+		return False;
+	} else {
+		DEBUG(5, ("name %s#%02X found.\n", name, name_type));
 	}
+	
+	/*
+	 * Split up the stored value into the list of IP adresses
+	 */
+	*num_names = ipstr_list_parse(value, ip_list);
+	
+	SAFE_FREE(key);
+	SAFE_FREE(value);		 
+	return *num_names > 0;		/* true only if some ip has been fetched */
+}
 
-	DEBUGADD(5, ("\n"));
 
-done:
-	SAFE_FREE(key.dptr);
-	SAFE_FREE(value.dptr);
+/**
+ * Delete single namecache entry. Look at the
+ * gencache_iterate definition.
+ *
+ **/
 
-	return value.dsize > 0;
+static void flush_netbios_name(const char* key, const char *value, time_t timeout, void* dptr)
+{
+	gencache_del(key);
+	DEBUG(5, ("Deleting entry %s\n", key));
 }
 
-/* Flush all names from the name cache */
+
+/**
+ * Flush all names from the name cache.
+ * It's done by gencache_iterate()
+ *
+ * @return True upon successful deletion or
+ *         False in case of an error
+ **/
 
 void namecache_flush(void)
 {
-	int result;
-
-	if (!namecache_tdb)
+	if (!gencache_init())
 		return;
 
-	result = tdb_traverse(namecache_tdb, tdb_traverse_delete_fn, NULL);
-
-	if (result == -1)
-		DEBUG(5, ("namecache_flush: error deleting cache entries\n"));
-	else
-		DEBUG(5, ("namecache_flush: deleted %d cache entr%s\n", 
-			  result, result == 1 ? "y" : "ies"));
+	/* 
+	 * iterate through each NBT cache's entry and flush it
+	 * by flush_netbios_name function
+	 */
+	gencache_iterate(flush_netbios_name, NULL, "NBT/*");
+	DEBUG(5, ("Namecache flushed\n"));
 }
+
Index: libsmb/namequery.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/namequery.c,v
retrieving revision 1.113
diff -u -r1.113 namequery.c
--- libsmb/namequery.c	12 Nov 2002 23:15:49 -0000	1.113
+++ libsmb/namequery.c	21 Nov 2002 22:04:12 -0000
@@ -837,11 +838,6 @@
 			  if (resolve_hosts(name, return_iplist, return_count)) {
 				  result = True;
 				  goto done;
-			  } else {
-
-				  /* Store negative lookup result */
-
-				  namecache_store(name, name_type, 0, NULL);
 			  }
 		  }
 	  } else if(strequal( tok, "lmhosts")) {
@@ -916,7 +912,10 @@
   }
  
   /* Save in name cache */
-
+  for (i = 0; i < *return_count && DEBUGLEVEL == 100; i++)
+    DEBUG(100, ("Storing name %s of type %d (ip: %s)\n", name,
+                name_type, inet_ntoa(*return_iplist[i])));
+    
   namecache_store(name, name_type, *return_count, *return_iplist);
 
   /* Display some debugging info */
Index: nsswitch/winbindd.c
===================================================================
RCS file: /cvsroot/samba/source/nsswitch/winbindd.c,v
retrieving revision 1.75
diff -u -r1.75 winbindd.c
--- nsswitch/winbindd.c	18 Nov 2002 22:46:45 -0000	1.75
+++ nsswitch/winbindd.c	21 Nov 2002 22:04:15 -0000
@@ -863,6 +863,7 @@
 
 	process_loop();
 
+	trustdom_cache_shutdown();
 	uni_group_cache_shutdown();
 	return 0;
 }
Index: nsswitch/winbindd_rpc.c
Index: nsswitch/winbindd_util.c
===================================================================
RCS file: /cvsroot/samba/source/nsswitch/winbindd_util.c,v
retrieving revision 1.88
diff -u -r1.88 winbindd_util.c
--- nsswitch/winbindd_util.c	12 Nov 2002 23:15:50 -0000	1.88
+++ nsswitch/winbindd_util.c	21 Nov 2002 22:04:18 -0000
@@ -178,7 +178,7 @@
 		int i;
 
 		result = domain->methods->trusted_domains(domain, mem_ctx, &num_domains,
-							  &names, &alt_names, &dom_sids);
+		                                          &names, &alt_names, &dom_sids);
 		if (!NT_STATUS_IS_OK(result)) {
 			continue;
 		}
@@ -187,9 +187,12 @@
 		   the access methods of its parent */
 		for(i = 0; i < num_domains; i++) {
 			DEBUG(10,("Found domain %s\n", names[i]));
-			add_trusted_domain(names[i], 
-					   alt_names?alt_names[i]:NULL, 
-					   domain->methods, &dom_sids[i]);
+			add_trusted_domain(names[i], alt_names?alt_names[i]:NULL,
+			                   domain->methods, &dom_sids[i]);
+			
+			/* store trusted domain in the cache */
+			trustdom_cache_store(names[i], alt_names ? alt_names[i] : NULL,
+			                     &dom_sids[i], t + WINBINDD_RESCAN_FREQ);
 		}
 	}
 
@@ -209,8 +212,10 @@
 	/* Add ourselves as the first entry */
 	domain = add_trusted_domain(lp_workgroup(), NULL, &cache_methods, NULL);
 
-	/* Now we *must* get the domain sid for our primary domain. Go into
-	   a holding pattern until that is available */
+	/* 
+	 * Now we *must* get the domain sid for our primary domain. Go into
+	 * a holding pattern until that is available
+	 */
 
 	result = cache_methods.domain_sid(domain, &domain->sid);
 	while (!NT_STATUS_IS_OK(result)) {
Index: rpc_client/cli_lsarpc.c
===================================================================
RCS file: /cvsroot/samba/source/rpc_client/cli_lsarpc.c,v
retrieving revision 1.69
diff -u -r1.69 cli_lsarpc.c
--- rpc_client/cli_lsarpc.c	4 Oct 2002 03:51:43 -0000	1.69
+++ rpc_client/cli_lsarpc.c	21 Nov 2002 22:04:22 -0000
@@ -648,7 +648,7 @@
 	/* Marshall data and send request */
 
 	/* 64k is enough for about 2000 trusted domains */
-        init_q_enum_trust_dom(&q, pol, *enum_ctx, 0x10000);
+	init_q_enum_trust_dom(&q, pol, *enum_ctx, 0x10000);
 
 	if (!lsa_io_q_enum_trust_dom("", &q, &qbuf, 0) ||
 	    !rpc_api_pipe_req(cli, LSA_ENUMTRUSTDOM, &qbuf, &rbuf)) {
Index: rpcclient/cmd_lsarpc.c
===================================================================
RCS file: /cvsroot/samba/source/rpcclient/cmd_lsarpc.c,v
retrieving revision 1.66
diff -u -r1.66 cmd_lsarpc.c
--- rpcclient/cmd_lsarpc.c	4 Oct 2002 19:11:36 -0000	1.66
+++ rpcclient/cmd_lsarpc.c	21 Nov 2002 22:04:30 -0000
@@ -218,18 +218,16 @@
 	uint32 num_domains = 0;
 	int i;
 
-	if (argc > 2) {
-		printf("Usage: %s [enum context (0)]\n", argv[0]);
+	if (argc > 3) {
+		printf("Usage: %s [enum context (0)] [max size (5)]\n", argv[0]);
 		return NT_STATUS_OK;
 	}
 
-	if (argc == 2 && argv[1]) {
-		enum_ctx = atoi(argv[2]);
-	}	
-
+	if (argc >= 2 && argv[1]) enum_ctx = atoi(argv[1]);
+	if (argc == 3 && argv[2]) num_domains = atoi(argv[2]);
+	
 	result = cli_lsa_open_policy(cli, mem_ctx, True, 
-				     POLICY_VIEW_LOCAL_INFORMATION,
-				     &pol);
+	                             POLICY_VIEW_LOCAL_INFORMATION, &pol);
 
 	if (!NT_STATUS_IS_OK(result))
 		goto done;
Index: smbd/server.c
===================================================================
RCS file: /cvsroot/samba/source/smbd/server.c,v
retrieving revision 1.399
diff -u -r1.399 server.c
--- smbd/server.c	13 Nov 2002 19:04:17 -0000	1.399
+++ smbd/server.c	21 Nov 2002 22:04:33 -0000
@@ -849,6 +849,7 @@
 	smbd_process();
 	
 	uni_group_cache_shutdown();
+	namecache_shutdown();
 	exit_server("normal exit");
 	return(0);
 }
Index: utils/net_cache.c
===================================================================
RCS file: /cvsroot/samba/source/utils/net_cache.c,v
retrieving revision 1.1
diff -u -r1.1 net_cache.c
--- utils/net_cache.c	11 Sep 2002 14:07:21 -0000	1.1
+++ utils/net_cache.c	21 Nov 2002 22:04:34 -0000
@@ -34,15 +34,34 @@
  * (print_cache_entry) and to flush it (delete_cache_entry).
  * Both of them are defined by first arg of gencache_iterate() routine.
  */
-static void print_cache_entry(const char* keystr, const char* datastr, const time_t timeout)
+static void print_cache_entry(const char* keystr, const char* datastr,
+                              const time_t timeout, void* dptr)
 {
-	char* timeout_str = ctime(&timeout);
-	timeout_str[strlen(timeout_str) - 1] = '\0';
-	d_printf("Key: %s\t\t Value: %s\t\t Timeout: %s %s\n", keystr, datastr,
-	         timeout_str, timeout > time(NULL) ? "": "(expired)");
+	char* timeout_str;
+	time_t now_t = time(NULL);
+	struct tm timeout_tm, *now_tm;
+	/* localtime returns statically allocated pointer, so timeout_tm
+	   has to be copied somewhere else */
+	memcpy(&timeout_tm, localtime(&timeout), sizeof(struct tm));
+	now_tm = localtime(&now_t);
+
+	/* form up timeout string depending whether it's today's date or not */
+	if (timeout_tm.tm_year != now_tm->tm_year ||
+	    timeout_tm.tm_mon != now_tm->tm_mon ||
+	    timeout_tm.tm_mday != now_tm->tm_mday) {
+	    
+	    timeout_str = asctime(&timeout_tm);
+	    timeout_str[strlen(timeout_str) - 1] = '\0';	/* remove tailing CR */
+	} else
+		asprintf(&timeout_str, "%.2d:%.2d:%.2d", timeout_tm.tm_hour,
+		         timeout_tm.tm_min, timeout_tm.tm_sec);
+	
+	d_printf("Key: %s\t Timeout: %s\t Value: %s  %s\n", keystr,
+	         timeout_str, datastr, timeout > now_t ? "": "(expired)");
 }
 
-static void delete_cache_entry(const char* keystr, const char* datastr, const time_t timeout)
+static void delete_cache_entry(const char* keystr, const char* datastr,
+                               const time_t timeout, void* dptr)
 {
 	if (!gencache_del(keystr))
 		d_printf("Couldn't delete entry! key = %s", keystr);
@@ -92,8 +111,8 @@
 	case 'h': timeout *= 60*60; break;
 	case 'd': timeout *= 60*60*24; break;
 	case 'w': timeout *= 60*60*24*7; break;  /* that's fair enough, I think :) */
-	}
+	};
 	
 	switch (sign) {
 	case '!': timeout = time(NULL) - timeout; break;
@@ -226,6 +245,6 @@
 	}
 	
 	if (gencache_get(keystr, &valuestr, &timeout)) {
-		print_cache_entry(keystr, valuestr, timeout);
+		print_cache_entry(keystr, valuestr, timeout, NULL);
 		return 0;
@@ -251,7 +270,7 @@
 	}
 	
 	pattern = argv[0];
-	gencache_iterate(print_cache_entry, pattern);
+	gencache_iterate(print_cache_entry, NULL, pattern);
 	return 0;
 }
 
@@ -265,7 +284,7 @@
 static int net_cache_list(int argc, const char **argv)
 {
 	const char* pattern = "*";
-	gencache_iterate(print_cache_entry, pattern);
+	gencache_iterate(print_cache_entry, NULL, pattern);
 	gencache_shutdown();
 	return 0;
 }
@@ -280,7 +299,7 @@
 static int net_cache_flush(int argc, const char **argv)
 {
 	const char* pattern = "*";
-	gencache_iterate(delete_cache_entry, pattern);
+	gencache_iterate(delete_cache_entry, NULL, pattern);
 	gencache_shutdown();
 	return 0;
 }
@@ -294,7 +313,7 @@
  **/
 static int net_cache_usage(int argc, const char **argv)
 {
-	d_printf("  net cache add \t add add new cache entry\n");
+	d_printf("  net cache add \t add new cache entry\n");
 	d_printf("  net cache set \t set new value for existing cache entry\n");
 	d_printf("  net cache del \t delete existing cache entry by key\n");
 	d_printf("  net cache flush \t delete all entries existing in the cache\n");
@@ -302,7 +321,41 @@
 	d_printf("  net cache search \t search for entries in the cache, by given pattern\n");
 	d_printf("  net cache list \t list all cache entries (just like search for \"*\")\n");
 	return -1;
-}
+};
+
+
+/**
+ * Verbose help
+ *
+ * @param argv ignored here
+ * @return always returns -1
+ **/
+static int net_cache_help(int argc, const char **argv)
+{
+	const char* help_topic = argv[0];
+	if (help_topic) {
+		/* detailed description of command asked about */
+		if (strequal(help_topic, "add")) {
+		}
+		if (strequal(help_topic, "set")) {
+		}
+		if (strequal(help_topic, "del")) {
+		}
+		if (strequal(help_topic, "flush")) {
+		}
+		if (strequal(help_topic, "get")) {
+		}
+		if (strequal(help_topic, "search")) {
+		}
+		if (strequal(help_topic, "list")) {
+		}
+
+		return -1;
+	}
+	
+	/* in case of just 'net cache help' use net_cache_usage */
+	return net_cache_usage(argc, argv);	
+};
 
 
 /**
@@ -321,8 +374,10 @@
 		{"search", net_cache_search},
 		{"list", net_cache_list},
 		{"flush", net_cache_flush},
+		{"help", net_cache_help},
 		{NULL, NULL}
 	};
 
 	return net_run_function(argc, argv, func, net_cache_usage);
 }
+
Index: utils/net_rpc.c
===================================================================
RCS file: /cvsroot/samba/source/utils/net_rpc.c,v
retrieving revision 1.43
diff -u -r1.43 net_rpc.c
--- utils/net_rpc.c	15 Nov 2002 21:28:33 -0000	1.43
+++ utils/net_rpc.c	21 Nov 2002 22:04:37 -0000
@@ -1659,6 +1659,10 @@
 
 	domain_name = smb_xstrdup(argv[0]);
 	strupper(domain_name);
+
+	/* account name used at first is our domain's name with '$' */
+	asprintf(&acct_name, "%s$", lp_workgroup());
+	strupper(acct_name);
 	
 	/*
 	 * opt_workgroup will be used by connection functions further,
@@ -1669,9 +1673,6 @@
 		opt_workgroup = smb_xstrdup(domain_name);
 	};
 	
-	asprintf(&acct_name, "%s$", lp_workgroup());
-	strupper(acct_name);
-	
 	opt_user_name = acct_name;
 
 	/* find the domain controller */
@@ -2036,7 +2037,7 @@
 	 
 	enum_ctx = 0;	/* reset enumeration context from last enumeration */
 	do {
-			
+		
 		nt_status = cli_samr_enum_dom_users(cli, mem_ctx, &domain_hnd,
 		                                    &enum_ctx, ACB_DOMTRUST, 0xffff,
 		                                    &trusting_dom_names, &trusting_dom_rids,
@@ -2048,7 +2049,7 @@
 		};
 		
 		for (i = 0; i < num_domains; i++) {
-
+		
 			/*
 			 * get each single domain's sid (do we _really_ need this ?):
 			 *  1) connect to domain's pdc


More information about the samba-technical mailing list