summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2002-11-26 11:57:30 +0000
committerAndrew Bartlett <abartlet@samba.org>2002-11-26 11:57:30 +0000
commit65643516d760c4e61ba6f4406f442f7e9bd10f2f (patch)
tree0cf648ed7049ddbcb66d7f7b722ca31aa74cd445 /source3/utils
parent585e8a8c02f78a072b98f681fda5748c3d9924ab (diff)
downloadsamba-65643516d760c4e61ba6f4406f442f7e9bd10f2f.tar.gz
samba-65643516d760c4e61ba6f4406f442f7e9bd10f2f.tar.bz2
samba-65643516d760c4e61ba6f4406f442f7e9bd10f2f.zip
Having waited for *way* too long, this is mimir's namecache and trusted domain
cache code. This uses gencache, mimir's new caching code that stores at text-based cache of various data. Mimir has done a *lot* of work on this patch, and it is finally time to get it in CVS. Andrew Bartlett (This used to be commit 47f3bfe9564e7f3aff60cefaefd599e0abb30a31)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_cache.c56
-rw-r--r--source3/utils/net_rpc.c7
2 files changed, 42 insertions, 21 deletions
diff --git a/source3/utils/net_cache.c b/source3/utils/net_cache.c
index 359c06d1aa..93c4f1aa1d 100644
--- a/source3/utils/net_cache.c
+++ b/source3/utils/net_cache.c
@@ -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);
@@ -106,7 +125,7 @@ static time_t parse_timeout(const char* timeout_str)
/**
- * Add an entry to the cache
+ * Add an entry to the cache. If it does exist, then set it.
*
* @param argv key, value and timeout are passed in command line
* @return 0 on success, otherwise failure
@@ -132,12 +151,12 @@ static int net_cache_add(int argc, const char **argv)
return -1;
}
- if (gencache_add(keystr, datastr, timeout)) {
+ if (gencache_set(keystr, datastr, timeout)) {
d_printf("New cache entry stored successfully.\n");
gencache_shutdown();
return 0;
- }
-
+ }
+
d_printf("Entry couldn't be added. Perhaps there's already such a key.\n");
gencache_shutdown();
return -1;
@@ -145,7 +164,8 @@ static int net_cache_add(int argc, const char **argv)
/**
- * Set new value of an existing entry in the cache
+ * Set new value of an existing entry in the cache. Fail If the entry doesn't
+ * exist.
*
* @param argv key being searched and new value and timeout to set in the entry
* @return 0 on success, otherwise failure
@@ -171,7 +191,7 @@ static int net_cache_set(int argc, const char **argv)
return -1;
}
- if (gencache_set(keystr, datastr, timeout)) {
+ if (gencache_set_only(keystr, datastr, timeout)) {
d_printf("Cache entry set successfully.\n");
gencache_shutdown();
return 0;
@@ -201,7 +221,7 @@ static int net_cache_del(int argc, const char **argv)
if(gencache_del(keystr)) {
d_printf("Entry deleted.\n");
return 0;
- }
+ }
d_printf("Couldn't delete specified entry\n");
return -1;
@@ -226,9 +246,9 @@ static int net_cache_get(int argc, const char **argv)
}
if (gencache_get(keystr, &valuestr, &timeout)) {
- print_cache_entry(keystr, valuestr, timeout);
+ print_cache_entry(keystr, valuestr, timeout, NULL);
return 0;
- }
+ }
d_printf("Failed to find entry\n");
return -1;
@@ -251,7 +271,7 @@ static int net_cache_search(int argc, const char **argv)
}
pattern = argv[0];
- gencache_iterate(print_cache_entry, pattern);
+ gencache_iterate(print_cache_entry, NULL, pattern);
return 0;
}
@@ -265,7 +285,7 @@ static int net_cache_search(int argc, const char **argv)
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 +300,7 @@ static int net_cache_list(int argc, const char **argv)
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;
}
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index d5af6e3fb8..092d625ae5 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -1659,6 +1659,10 @@ static int rpc_trustdom_establish(int argc, const char **argv)
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 @@ static int rpc_trustdom_establish(int argc, const char **argv)
opt_workgroup = smb_xstrdup(domain_name);
};
- asprintf(&acct_name, "%s$", lp_workgroup());
- strupper(acct_name);
-
opt_user_name = acct_name;
/* find the domain controller */