winbind: Introduce id_map_ptrs_init
authorVolker Lendecke <vl@samba.org>
Fri, 4 Mar 2016 13:23:51 +0000 (14:23 +0100)
committerVolker Lendecke <vl@samba.org>
Wed, 30 Mar 2016 12:27:23 +0000 (14:27 +0200)
This simplifies _wbint_Sids2UnixIDs a bit and will be re-used in _wbint_UnixIDs2Sids

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/winbindd/idmap_proto.h
source3/winbindd/idmap_util.c
source3/winbindd/winbindd_dual_srv.c

index a12e5b48ea60575d17e3ad1c154094e25010345f..0e124cd8755d717de60f7c356ac4e2407658cb80 100644 (file)
@@ -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
 
index f90565f6a6caea997ffa674c59467e8839ff81ec..75915306a14c92fa0e5850097252a7461b21f5c6 100644 (file)
@@ -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; i<num_ids; i++) {
+               maps[i] = (struct id_map) { .sid = &sids[i] };
+               ptrs[i] = &maps[i];
+       }
+       ptrs[num_ids] = NULL;
+
+       return ptrs;
+}
index e42dce526a5e62f6260c09bf61dc0676665c411e..7c415e68f83c773f7009ddb20b71de141741d92c 100644 (file)
@@ -127,9 +127,7 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
        struct wbint_TransID *ids;
        uint32_t num_ids;
 
-       struct id_map *id_maps = NULL;
        struct id_map **id_map_ptrs = NULL;
-       struct dom_sid *sids = NULL;
        struct idmap_domain *dom;
        NTSTATUS status = NT_STATUS_NO_MEMORY;
 
@@ -157,18 +155,10 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
                return NT_STATUS_OK;
        }
 
-       id_maps = talloc_array(talloc_tos(), struct id_map, num_ids);
-       if (id_maps == NULL) {
-               goto nomem;
-       }
-       id_map_ptrs = talloc_array(talloc_tos(), struct id_map *, num_ids+1);
+       id_map_ptrs = id_map_ptrs_init(talloc_tos(), num_ids);
        if (id_map_ptrs == NULL) {
                goto nomem;
        }
-       sids = talloc_array(talloc_tos(), struct dom_sid, num_ids);
-       if (sids == NULL) {
-               goto nomem;
-       }
 
        /*
         * Convert the input data into a list of id_map structs
@@ -177,18 +167,12 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
         */
 
        for (i=0; i<num_ids; i++) {
+               struct id_map *m = id_map_ptrs[i];
 
-               sid_compose(&sids[i], d->sid, 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; i<num_ids; i++) {
+               struct id_map *m = id_map_ptrs[i];
 
-               if (id_maps[i].status == ID_MAPPED) {
-                       ids[i].xid = id_maps[i].xid;
+               if (m->status == 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;
 }