summaryrefslogtreecommitdiff
path: root/source3/winbindd
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-07-03 04:57:30 +0200
committerVolker Lendecke <vl@samba.org>2008-07-03 21:19:09 +0200
commit8857affd3cf9466466f1eeb2ccd8085d087bb2f2 (patch)
tree0b9faa3fb1ec9fa6a30102e78b1d5fce108bd49b /source3/winbindd
parent1fb1c67fb9392364887ba8963f18d10b27d1cfa0 (diff)
downloadsamba-8857affd3cf9466466f1eeb2ccd8085d087bb2f2.tar.gz
samba-8857affd3cf9466466f1eeb2ccd8085d087bb2f2.tar.bz2
samba-8857affd3cf9466466f1eeb2ccd8085d087bb2f2.zip
Simplify idmap_cache_build_[s]idkey a bit
(This used to be commit 80932c0266ef73b8d0462c078a053444fff47f32)
Diffstat (limited to 'source3/winbindd')
-rw-r--r--source3/winbindd/idmap_cache.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/source3/winbindd/idmap_cache.c b/source3/winbindd/idmap_cache.c
index b724ba0c59..0b3c22eb20 100644
--- a/source3/winbindd/idmap_cache.c
+++ b/source3/winbindd/idmap_cache.c
@@ -70,33 +70,19 @@ struct idmap_cache_ctx *idmap_cache_init(TALLOC_CTX *memctx)
return cache;
}
-static NTSTATUS idmap_cache_build_sidkey(TALLOC_CTX *ctx, char **sidkey,
- const struct id_map *id)
+static char *idmap_cache_sidkey(TALLOC_CTX *ctx, const DOM_SID *sid)
{
fstring sidstr;
- *sidkey = talloc_asprintf(ctx, "IDMAP/SID/%s",
- sid_to_fstring(sidstr, id->sid));
- if ( ! *sidkey) {
- DEBUG(1, ("failed to build sidkey, OOM?\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
- return NT_STATUS_OK;
+ return talloc_asprintf(ctx, "IDMAP/SID/%s",
+ sid_to_fstring(sidstr, sid));
}
-static NTSTATUS idmap_cache_build_idkey(TALLOC_CTX *ctx, char **idkey,
- const struct id_map *id)
+static char *idmap_cache_idkey(TALLOC_CTX *ctx, const struct id_map *id)
{
- *idkey = talloc_asprintf(ctx, "IDMAP/%s/%lu",
- (id->xid.type==ID_TYPE_UID)?"UID":"GID",
- (unsigned long)id->xid.id);
- if ( ! *idkey) {
- DEBUG(1, ("failed to build idkey, OOM?\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
- return NT_STATUS_OK;
+ return talloc_asprintf(ctx, "IDMAP/%s/%lu",
+ (id->xid.type==ID_TYPE_UID)?"UID":"GID",
+ (unsigned long)id->xid.id);
}
NTSTATUS idmap_cache_set(struct idmap_cache_ctx *cache, const struct id_map *id)
@@ -120,12 +106,15 @@ NTSTATUS idmap_cache_set(struct idmap_cache_ctx *cache, const struct id_map *id)
return NT_STATUS_OK;
}
- ret = idmap_cache_build_sidkey(cache, &sidkey, id);
- if (!NT_STATUS_IS_OK(ret)) return ret;
+ sidkey = idmap_cache_sidkey(cache, id->sid);
+ if (sidkey == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
/* use sidkey as the local memory ctx */
- ret = idmap_cache_build_idkey(sidkey, &idkey, id);
- if (!NT_STATUS_IS_OK(ret)) {
+ idkey = idmap_cache_idkey(sidkey, id);
+ if (idkey == NULL) {
+ ret = NT_STATUS_NO_MEMORY;
goto done;
}
@@ -182,14 +171,16 @@ done:
NTSTATUS idmap_cache_set_negative_sid(struct idmap_cache_ctx *cache, const struct id_map *id)
{
- NTSTATUS ret;
+ NTSTATUS ret = NT_STATUS_OK;
time_t timeout = time(NULL) + lp_idmap_negative_cache_time();
TDB_DATA databuf;
char *sidkey;
char *valstr;
- ret = idmap_cache_build_sidkey(cache, &sidkey, id);
- if (!NT_STATUS_IS_OK(ret)) return ret;
+ sidkey = idmap_cache_sidkey(cache, id->sid);
+ if (sidkey == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
/* use sidkey as the local memory ctx */
valstr = talloc_asprintf(sidkey, IDMAP_CACHE_DATA_FMT, (int)timeout, "IDMAP/NEGATIVE");
@@ -218,14 +209,16 @@ done:
NTSTATUS idmap_cache_set_negative_id(struct idmap_cache_ctx *cache, const struct id_map *id)
{
- NTSTATUS ret;
+ NTSTATUS ret = NT_STATUS_OK;
time_t timeout = time(NULL) + lp_idmap_negative_cache_time();
TDB_DATA databuf;
char *idkey;
char *valstr;
- ret = idmap_cache_build_idkey(cache, &idkey, id);
- if (!NT_STATUS_IS_OK(ret)) return ret;
+ idkey = idmap_cache_idkey(cache, id);
+ if (idkey == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
/* use idkey as the local memory ctx */
valstr = talloc_asprintf(idkey, IDMAP_CACHE_DATA_FMT, (int)timeout, "IDMAP/NEGATIVE");
@@ -317,7 +310,7 @@ failed:
NTSTATUS idmap_cache_map_sid(struct idmap_cache_ctx *cache, struct id_map *id)
{
- NTSTATUS ret;
+ NTSTATUS ret = NT_STATUS_OK;
TDB_DATA databuf;
time_t t;
char *sidkey;
@@ -328,8 +321,10 @@ NTSTATUS idmap_cache_map_sid(struct idmap_cache_ctx *cache, struct id_map *id)
/* make sure it is marked as not mapped by default */
id->status = ID_UNKNOWN;
- ret = idmap_cache_build_sidkey(cache, &sidkey, id);
- if (!NT_STATUS_IS_OK(ret)) return ret;
+ sidkey = idmap_cache_sidkey(cache, id->sid);
+ if (sidkey == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
databuf = tdb_fetch_bystring(cache->tdb, sidkey);
@@ -438,8 +433,10 @@ NTSTATUS idmap_cache_map_id(struct idmap_cache_ctx *cache, struct id_map *id)
/* make sure it is marked as unknown by default */
id->status = ID_UNKNOWN;
- ret = idmap_cache_build_idkey(cache, &idkey, id);
- if (!NT_STATUS_IS_OK(ret)) return ret;
+ idkey = idmap_cache_idkey(cache, id);
+ if (idkey == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
databuf = tdb_fetch_bystring(cache->tdb, idkey);