1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-13 13:18:06 +03:00

r21983: make use of tdb_*_bystring() and string_term_tdb_data()

to avoid creating the TDB_DATA struct from strings "by hand"

metze
This commit is contained in:
Stefan Metzmacher 2007-03-27 10:46:20 +00:00 committed by Gerald (Jerry) Carter
parent 9ebaa4c573
commit 5a5579d842

View File

@ -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;
}