From 50aef48e18e7e0a265c348d2486f687ddad839a0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 4 Mar 2016 14:23:51 +0100 Subject: [PATCH 1/1] winbind: Introduce id_map_ptrs_init This simplifies _wbint_Sids2UnixIDs a bit and will be re-used in _wbint_UnixIDs2Sids Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/winbindd/idmap_proto.h | 2 ++ source3/winbindd/idmap_util.c | 31 ++++++++++++++++++++++++++ source3/winbindd/winbindd_dual_srv.c | 33 +++++++--------------------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/source3/winbindd/idmap_proto.h b/source3/winbindd/idmap_proto.h index a12e5b48ea6..0e124cd8755 100644 --- a/source3/winbindd/idmap_proto.h +++ b/source3/winbindd/idmap_proto.h @@ -59,6 +59,8 @@ struct id_map *idmap_find_map_by_sid(struct id_map **maps, struct dom_sid *sid); char *idmap_fetch_secret(const char *backend, const char *domain, const char *identity); +struct id_map **id_map_ptrs_init(TALLOC_CTX *mem_ctx, size_t num_ids); + /* max number of ids requested per LDAP batch query */ #define IDMAP_LDAP_MAX_IDS 30 diff --git a/source3/winbindd/idmap_util.c b/source3/winbindd/idmap_util.c index f90565f6a6c..75915306a14 100644 --- a/source3/winbindd/idmap_util.c +++ b/source3/winbindd/idmap_util.c @@ -238,3 +238,34 @@ char *idmap_fetch_secret(const char *backend, const char *domain, return ret; } + +struct id_map **id_map_ptrs_init(TALLOC_CTX *mem_ctx, size_t num_ids) +{ + struct id_map **ptrs; + struct id_map *maps; + struct dom_sid *sids; + size_t i; + + ptrs = talloc_array(mem_ctx, struct id_map *, num_ids+1); + if (ptrs == NULL) { + return NULL; + } + maps = talloc_array(ptrs, struct id_map, num_ids); + if (maps == NULL) { + TALLOC_FREE(ptrs); + return NULL; + } + sids = talloc_zero_array(ptrs, struct dom_sid, num_ids); + if (sids == NULL) { + TALLOC_FREE(ptrs); + return NULL; + } + + for (i=0; isid, ids[i].rid); - - id_maps[i] = (struct id_map) { - .sid = &sids[i], - .xid.type = ids[i].type, - .status = ID_UNKNOWN - }; - - id_map_ptrs[i] = &id_maps[i]; + sid_compose(m->sid, d->sid, ids[i].rid); + m->status = ID_UNKNOWN; + m->xid = (struct unixid) { .type = ids[i].type }; } - id_map_ptrs[num_ids] = NULL; status = dom->methods->sids_to_unixids(dom, id_map_ptrs); @@ -203,9 +187,10 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p, */ for (i=0; istatus == ID_MAPPED) { + ids[i].xid = m->xid; } else { ids[i].xid.id = UINT32_MAX; ids[i].xid.type = ID_TYPE_NOT_SPECIFIED; @@ -216,9 +201,7 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p, nomem: status = NT_STATUS_NO_MEMORY; done: - TALLOC_FREE(id_maps); TALLOC_FREE(id_map_ptrs); - TALLOC_FREE(sids); return status; } -- 2.34.1