summaryrefslogtreecommitdiff
path: root/source3/passdb
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-03-27 10:46:20 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:18:56 -0500
commite6fda8cbd0cab7c1a3fd97a9714eb6b0d60f409e (patch)
tree4cee2cc3d786fbe8760761b335aaefdc444b4745 /source3/passdb
parenta3a4d6721b451807d55e9c5199275aad57db26fb (diff)
downloadsamba-e6fda8cbd0cab7c1a3fd97a9714eb6b0d60f409e.tar.gz
samba-e6fda8cbd0cab7c1a3fd97a9714eb6b0d60f409e.tar.bz2
samba-e6fda8cbd0cab7c1a3fd97a9714eb6b0d60f409e.zip
r21983: make use of tdb_*_bystring() and string_term_tdb_data()
to avoid creating the TDB_DATA struct from strings "by hand" metze (This used to be commit 5a5579d8429e6f76805a093133ba29c7f8321512)
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/login_cache.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/source3/passdb/login_cache.c b/source3/passdb/login_cache.c
index 7fd3b47826..5231af8a82 100644
--- a/source3/passdb/login_cache.c
+++ b/source3/passdb/login_cache.c
@@ -66,7 +66,8 @@ BOOL login_cache_shutdown(void)
/* if we can't read the cache, oh well, no need to return anything */
LOGIN_CACHE * login_cache_read(struct samu *sampass)
{
- TDB_DATA keybuf, databuf;
+ char *keystr;
+ TDB_DATA databuf;
LOGIN_CACHE *entry;
if (!login_cache_init())
@@ -76,17 +77,16 @@ LOGIN_CACHE * login_cache_read(struct samu *sampass)
return NULL;
}
- keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
- if (!keybuf.dptr || !strlen(keybuf.dptr)) {
- SAFE_FREE(keybuf.dptr);
+ keystr = SMB_STRDUP(pdb_get_nt_username(sampass));
+ if (!keystr || !keystr[0]) {
+ SAFE_FREE(keystr);
return NULL;
}
- keybuf.dsize = strlen(keybuf.dptr) + 1;
DEBUG(7, ("Looking up login cache for user %s\n",
- keybuf.dptr));
- databuf = tdb_fetch(cache, keybuf);
- SAFE_FREE(keybuf.dptr);
+ keystr));
+ databuf = tdb_fetch_bystring(cache, keystr);
+ SAFE_FREE(keystr);
if (!(entry = SMB_MALLOC_P(LOGIN_CACHE))) {
DEBUG(1, ("Unable to allocate cache entry buffer!\n"));
@@ -114,8 +114,8 @@ LOGIN_CACHE * login_cache_read(struct samu *sampass)
BOOL login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
{
-
- TDB_DATA keybuf, databuf;
+ char *keystr;
+ TDB_DATA databuf;
BOOL ret;
if (!login_cache_init())
@@ -125,12 +125,11 @@ BOOL login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
return False;
}
- keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
- if (!keybuf.dptr || !strlen(keybuf.dptr)) {
- SAFE_FREE(keybuf.dptr);
+ keystr = SMB_STRDUP(pdb_get_nt_username(sampass));
+ if (!keystr || !keystr[0]) {
+ SAFE_FREE(keystr);
return False;
}
- keybuf.dsize = strlen(keybuf.dptr) + 1;
entry.entry_timestamp = time(NULL);
@@ -142,7 +141,7 @@ BOOL login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
entry.bad_password_time);
databuf.dptr = SMB_MALLOC_ARRAY(char, databuf.dsize);
if (!databuf.dptr) {
- SAFE_FREE(keybuf.dptr);
+ SAFE_FREE(keystr);
return False;
}
@@ -152,13 +151,13 @@ BOOL login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
entry.bad_password_count,
entry.bad_password_time)
!= databuf.dsize) {
- SAFE_FREE(keybuf.dptr);
+ SAFE_FREE(keystr);
SAFE_FREE(databuf.dptr);
return False;
}
- ret = tdb_store(cache, keybuf, databuf, 0);
- SAFE_FREE(keybuf.dptr);
+ ret = tdb_store_bystring(cache, keystr, databuf, 0);
+ SAFE_FREE(keystr);
SAFE_FREE(databuf.dptr);
return ret == 0;
}
@@ -166,7 +165,7 @@ BOOL login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
BOOL login_cache_delentry(const struct samu *sampass)
{
int ret;
- TDB_DATA keybuf;
+ char *keystr;
if (!login_cache_init())
return False;
@@ -175,17 +174,16 @@ BOOL login_cache_delentry(const struct samu *sampass)
return False;
}
- keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
- if (!keybuf.dptr || !strlen(keybuf.dptr)) {
- SAFE_FREE(keybuf.dptr);
+ keystr = SMB_STRDUP(pdb_get_nt_username(sampass));
+ if (!keystr || !keystr[0]) {
+ SAFE_FREE(keystr);
return False;
}
- keybuf.dsize = strlen(keybuf.dptr) + 1;
- DEBUG(9, ("About to delete entry for %s\n", keybuf.dptr));
- ret = tdb_delete(cache, keybuf);
+
+ DEBUG(9, ("About to delete entry for %s\n", keystr));
+ ret = tdb_delete_bystring(cache, keystr);
DEBUG(9, ("tdb_delete returned %d\n", ret));
- SAFE_FREE(keybuf.dptr);
+ SAFE_FREE(keystr);
return ret == 0;
}
-