summaryrefslogtreecommitdiff
path: root/source3/nsswitch/idmap_rid.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2006-12-13 16:39:50 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:16:27 -0500
commit25fe484101a589d6d15df21456060888aaaa149a (patch)
tree76cc054fe51f5b2794461c8dfdc989d7943a12b9 /source3/nsswitch/idmap_rid.c
parent050534827f7dcbc9cd78683e477aaa6dd2ba9394 (diff)
downloadsamba-25fe484101a589d6d15df21456060888aaaa149a.tar.gz
samba-25fe484101a589d6d15df21456060888aaaa149a.tar.bz2
samba-25fe484101a589d6d15df21456060888aaaa149a.zip
r20150: better memory handling for some functions, make sure we don't
leak memory by using the wrong(long lived) mem context (This used to be commit a28cdd6e742cb72a728bd337546ee95fd4160ed8)
Diffstat (limited to 'source3/nsswitch/idmap_rid.c')
-rw-r--r--source3/nsswitch/idmap_rid.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/source3/nsswitch/idmap_rid.c b/source3/nsswitch/idmap_rid.c
index 0cbfd75196..bbba1bd011 100644
--- a/source3/nsswitch/idmap_rid.c
+++ b/source3/nsswitch/idmap_rid.c
@@ -81,12 +81,12 @@ failed:
return ret;
}
-static NTSTATUS idmap_rid_id_to_sid(struct idmap_rid_context *ctx, struct id_map *map)
+static NTSTATUS idmap_rid_id_to_sid(TALLOC_CTX *memctx, struct idmap_rid_context *ctx, struct id_map *map)
{
char *domname, *name;
enum lsa_SidType sid_type;
- if (!ctx || !map) {
+ if (!memctx || !ctx || !map) {
return NT_STATUS_INVALID_PARAMETER;
}
@@ -99,7 +99,7 @@ static NTSTATUS idmap_rid_id_to_sid(struct idmap_rid_context *ctx, struct id_map
sid_compose(map->sid, &ctx->dom_sid, map->xid.id - ctx->low_id + ctx->base_rid);
- if (winbindd_lookup_name_by_sid(ctx, map->sid, &domname, &name, &sid_type)) {
+ if (winbindd_lookup_name_by_sid(memctx, map->sid, &domname, &name, &sid_type)) {
switch (sid_type) {
case SID_NAME_USER:
if (map->xid.type != ID_TYPE_UID) {
@@ -136,13 +136,13 @@ static NTSTATUS idmap_rid_id_to_sid(struct idmap_rid_context *ctx, struct id_map
Single sid to id lookup function.
**********************************/
-static NTSTATUS idmap_rid_sid_to_id(struct idmap_rid_context *ctx, struct id_map *map)
+static NTSTATUS idmap_rid_sid_to_id(TALLOC_CTX *memctx, struct idmap_rid_context *ctx, struct id_map *map)
{
char *domname, *name;
enum lsa_SidType sid_type;
uint32_t rid;
- if (!ctx || !map) {
+ if (!memctx || !ctx || !map) {
return NT_STATUS_INVALID_PARAMETER;
}
@@ -150,7 +150,7 @@ static NTSTATUS idmap_rid_sid_to_id(struct idmap_rid_context *ctx, struct id_map
map->xid.id = rid - ctx->base_rid + ctx->low_id;
/* check if this is a valid SID and set the type */
- if (winbindd_lookup_name_by_sid(ctx, map->sid, &domname, &name, &sid_type)) {
+ if (winbindd_lookup_name_by_sid(memctx, map->sid, &domname, &name, &sid_type)) {
switch (sid_type) {
case SID_NAME_USER:
map->xid.type = ID_TYPE_UID;
@@ -188,17 +188,24 @@ static NTSTATUS idmap_rid_sid_to_id(struct idmap_rid_context *ctx, struct id_map
static NTSTATUS idmap_rid_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids)
{
- struct idmap_rid_context *ctx;
+ struct idmap_rid_context *ridctx;
+ TALLOC_CTX *ctx;
NTSTATUS ret;
int i;
- ctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
+ ridctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
+
+ ctx = talloc_new(dom);
+ if ( ! ctx) {
+ DEBUG(0, ("Out of memory!\n"));
+ return NT_STATUS_NO_MEMORY;
+ }
for (i = 0; ids[i]; i++) {
/* make sure it is marked as unmapped before resolveing */
ids[i]->mapped = False;
- ret = idmap_rid_id_to_sid(ctx, ids[i]);
+ ret = idmap_rid_id_to_sid(ctx, ridctx, ids[i]);
if (( ! NT_STATUS_IS_OK(ret)) &&
( ! NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
@@ -207,6 +214,7 @@ static NTSTATUS idmap_rid_unixids_to_sids(struct idmap_domain *dom, struct id_ma
}
}
+ talloc_free(ctx);
return NT_STATUS_OK;
}
@@ -216,17 +224,24 @@ static NTSTATUS idmap_rid_unixids_to_sids(struct idmap_domain *dom, struct id_ma
static NTSTATUS idmap_rid_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
{
- struct idmap_rid_context *ctx;
+ struct idmap_rid_context *ridctx;
+ TALLOC_CTX *ctx;
NTSTATUS ret;
int i;
- ctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
+ ridctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
+
+ ctx = talloc_new(dom);
+ if ( ! ctx) {
+ DEBUG(0, ("Out of memory!\n"));
+ return NT_STATUS_NO_MEMORY;
+ }
for (i = 0; ids[i]; i++) {
/* make sure it is marked as unmapped before resolveing */
ids[i]->mapped = False;
- ret = idmap_rid_sid_to_id(ctx, ids[i]);
+ ret = idmap_rid_sid_to_id(ctx, ridctx, ids[i]);
if (( ! NT_STATUS_IS_OK(ret)) &&
( ! NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
@@ -236,6 +251,7 @@ static NTSTATUS idmap_rid_sids_to_unixids(struct idmap_domain *dom, struct id_ma
}
}
+ talloc_free(ctx);
return NT_STATUS_OK;
}