svn commit: samba r21984 - in branches/SAMBA_3_0/source/nsswitch: .
metze at samba.org
metze at samba.org
Tue Mar 27 10:50:35 GMT 2007
Author: metze
Date: 2007-03-27 10:50:32 +0000 (Tue, 27 Mar 2007)
New Revision: 21984
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=21984
Log:
make use of tdb_*_bystring() and string_term_tdb_data()
to avoid creating the TDB_DATA struct from strings "by hand"
metze
Modified:
branches/SAMBA_3_0/source/nsswitch/idmap_cache.c
Changeset:
Modified: branches/SAMBA_3_0/source/nsswitch/idmap_cache.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/idmap_cache.c 2007-03-27 10:46:20 UTC (rev 21983)
+++ branches/SAMBA_3_0/source/nsswitch/idmap_cache.c 2007-03-27 10:50:32 UTC (rev 21984)
@@ -104,7 +104,7 @@
{
NTSTATUS ret;
time_t timeout = time(NULL) + lp_idmap_cache_time();
- TDB_DATA keybuf, databuf;
+ TDB_DATA databuf;
char *sidkey;
char *idkey;
char *valstr;
@@ -128,16 +128,13 @@
goto done;
}
- keybuf.dptr = sidkey;
- keybuf.dsize = strlen(sidkey)+1;
- databuf.dptr = valstr;
- databuf.dsize = strlen(valstr)+1;
+ databuf = string_term_tdb_data(valstr);
DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
- " %s (%d seconds %s)\n", keybuf.dptr, valstr , ctime(&timeout),
+ " %s (%d seconds %s)\n", sidkey, valstr , ctime(&timeout),
(int)(timeout - time(NULL)),
timeout > time(NULL) ? "ahead" : "in the past"));
- if (tdb_store(cache->tdb, keybuf, databuf, TDB_REPLACE) != 0) {
+ if (tdb_store_bystring(cache->tdb, sidkey, databuf, TDB_REPLACE) != 0) {
DEBUG(3, ("Failed to store cache entry!\n"));
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
@@ -153,16 +150,13 @@
goto done;
}
- keybuf.dptr = idkey;
- keybuf.dsize = strlen(idkey)+1;
- databuf.dptr = valstr;
- databuf.dsize = strlen(valstr)+1;
+ databuf = string_term_tdb_data(valstr);
DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
- " %s (%d seconds %s)\n", keybuf.dptr, valstr, ctime(&timeout),
+ " %s (%d seconds %s)\n", idkey, valstr, ctime(&timeout),
(int)(timeout - time(NULL)),
timeout > time(NULL) ? "ahead" : "in the past"));
- if (tdb_store(cache->tdb, keybuf, databuf, TDB_REPLACE) != 0) {
+ if (tdb_store_bystring(cache->tdb, idkey, databuf, TDB_REPLACE) != 0) {
DEBUG(3, ("Failed to store cache entry!\n"));
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
@@ -178,7 +172,6 @@
NTSTATUS idmap_cache_del(struct idmap_cache_ctx *cache, const struct id_map *id)
{
NTSTATUS ret;
- TDB_DATA keybuf;
char *sidkey = NULL;
char *idkey = NULL;
@@ -192,21 +185,17 @@
/* delete SID */
- keybuf.dptr = sidkey;
- keybuf.dsize = strlen(sidkey)+1;
- DEBUG(10, ("Deleting cache entry (key = %s)\n", keybuf.dptr));
+ DEBUG(10, ("Deleting cache entry (key = %s)\n", sidkey));
- if (tdb_delete(cache->tdb, keybuf) != 0) {
+ if (tdb_delete_bystring(cache->tdb, sidkey) != 0) {
DEBUG(3, ("Failed to delete cache entry!\n"));
}
/* delete ID */
- keybuf.dptr = idkey;
- keybuf.dsize = strlen(idkey)+1;
- DEBUG(10, ("Deleting cache entry (key = %s)\n", keybuf.dptr));
+ DEBUG(10, ("Deleting cache entry (key = %s)\n", idkey));
- if (tdb_delete(cache->tdb, keybuf) != 0) {
+ if (tdb_delete_bystring(cache->tdb, idkey) != 0) {
DEBUG(3, ("Failed to delete cache entry!\n"));
}
@@ -220,7 +209,7 @@
{
NTSTATUS ret;
time_t timeout = time(NULL) + lp_idmap_negative_cache_time();
- TDB_DATA keybuf, databuf;
+ TDB_DATA databuf;
char *sidkey;
char *valstr;
@@ -235,16 +224,13 @@
goto done;
}
- keybuf.dptr = sidkey;
- keybuf.dsize = strlen(sidkey)+1;
- databuf.dptr = valstr;
- databuf.dsize = strlen(valstr)+1;
+ databuf = string_term_tdb_data(valstr);
DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
- " %s (%d seconds %s)\n", keybuf.dptr, valstr, ctime(&timeout),
+ " %s (%d seconds %s)\n", sidkey, valstr, ctime(&timeout),
(int)(timeout - time(NULL)),
timeout > time(NULL) ? "ahead" : "in the past"));
- if (tdb_store(cache->tdb, keybuf, databuf, TDB_REPLACE) != 0) {
+ if (tdb_store_bystring(cache->tdb, sidkey, databuf, TDB_REPLACE) != 0) {
DEBUG(3, ("Failed to store cache entry!\n"));
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
@@ -259,7 +245,7 @@
{
NTSTATUS ret;
time_t timeout = time(NULL) + lp_idmap_negative_cache_time();
- TDB_DATA keybuf, databuf;
+ TDB_DATA databuf;
char *idkey;
char *valstr;
@@ -274,16 +260,13 @@
goto done;
}
- keybuf.dptr = idkey;
- keybuf.dsize = strlen(idkey)+1;
- databuf.dptr = valstr;
- databuf.dsize = strlen(valstr)+1;
+ databuf = string_term_tdb_data(valstr);
DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
- " %s (%d seconds %s)\n", keybuf.dptr, valstr, ctime(&timeout),
+ " %s (%d seconds %s)\n", idkey, valstr, ctime(&timeout),
(int)(timeout - time(NULL)),
timeout > time(NULL) ? "ahead" : "in the past"));
- if (tdb_store(cache->tdb, keybuf, databuf, TDB_REPLACE) != 0) {
+ if (tdb_store_bystring(cache->tdb, idkey, databuf, TDB_REPLACE) != 0) {
DEBUG(3, ("Failed to store cache entry!\n"));
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
@@ -369,7 +352,7 @@
NTSTATUS idmap_cache_map_sid(struct idmap_cache_ctx *cache, struct id_map *id)
{
NTSTATUS ret;
- TDB_DATA keybuf, databuf;
+ TDB_DATA databuf;
time_t t;
char *sidkey;
char *endptr;
@@ -380,11 +363,8 @@
ret = idmap_cache_build_sidkey(cache, &sidkey, id);
if (!NT_STATUS_IS_OK(ret)) return ret;
- keybuf.dptr = sidkey;
- keybuf.dsize = strlen(sidkey)+1;
+ databuf = tdb_fetch_bystring(cache->tdb, sidkey);
- databuf = tdb_fetch(cache->tdb, keybuf);
-
if (databuf.dptr == NULL) {
DEBUG(10, ("Cache entry with key = %s couldn't be found\n", sidkey));
return NT_STATUS_NONE_MAPPED;
@@ -395,7 +375,7 @@
if ((endptr == NULL) || (*endptr != '/')) {
DEBUG(2, ("Invalid gencache data format: %s\n", databuf.dptr));
/* remove the entry */
- tdb_delete(cache->tdb, keybuf);
+ tdb_delete_bystring(cache->tdb, sidkey);
ret = NT_STATUS_NONE_MAPPED;
goto done;
}
@@ -411,7 +391,7 @@
ret = idmap_cache_fill_map(id, endptr+1);
if ( ! NT_STATUS_IS_OK(ret)) {
/* if not valid form delete the entry */
- tdb_delete(cache->tdb, keybuf);
+ tdb_delete_bystring(cache->tdb, sidkey);
ret = NT_STATUS_NONE_MAPPED;
goto done;
}
@@ -444,7 +424,7 @@
} else {
/* We're expired, delete the entry and return
not mapped */
- tdb_delete(cache->tdb, keybuf);
+ tdb_delete_bystring(cache->tdb, sidkey);
ret = NT_STATUS_NONE_MAPPED;
}
} else {
@@ -479,7 +459,7 @@
NTSTATUS idmap_cache_map_id(struct idmap_cache_ctx *cache, struct id_map *id)
{
NTSTATUS ret;
- TDB_DATA keybuf, databuf;
+ TDB_DATA databuf;
time_t t;
char *idkey;
char *endptr;
@@ -490,11 +470,8 @@
ret = idmap_cache_build_idkey(cache, &idkey, id);
if (!NT_STATUS_IS_OK(ret)) return ret;
- keybuf.dptr = idkey;
- keybuf.dsize = strlen(idkey)+1;
+ databuf = tdb_fetch_bystring(cache->tdb, idkey);
- databuf = tdb_fetch(cache->tdb, keybuf);
-
if (databuf.dptr == NULL) {
DEBUG(10, ("Cache entry with key = %s couldn't be found\n", idkey));
return NT_STATUS_NONE_MAPPED;
@@ -505,7 +482,7 @@
if ((endptr == NULL) || (*endptr != '/')) {
DEBUG(2, ("Invalid gencache data format: %s\n", databuf.dptr));
/* remove the entry */
- tdb_delete(cache->tdb, keybuf);
+ tdb_delete_bystring(cache->tdb, idkey);
ret = NT_STATUS_NONE_MAPPED;
goto done;
}
@@ -521,7 +498,7 @@
ret = idmap_cache_fill_map(id, endptr+1);
if ( ! NT_STATUS_IS_OK(ret)) {
/* if not valid form delete the entry */
- tdb_delete(cache->tdb, keybuf);
+ tdb_delete_bystring(cache->tdb, idkey);
ret = NT_STATUS_NONE_MAPPED;
goto done;
}
@@ -554,7 +531,7 @@
} else {
/* We're expired, delete the entry and
return not mapped */
- tdb_delete(cache->tdb, keybuf);
+ tdb_delete_bystring(cache->tdb, idkey);
ret = NT_STATUS_NONE_MAPPED;
}
} else {
More information about the samba-cvs
mailing list