summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-07-03 23:29:49 +0200
committerVolker Lendecke <vl@samba.org>2008-07-05 12:19:13 +0200
commit81f334bd6da601a040f754c46705cfa2fd4f8c45 (patch)
tree28a2d28042226112376f1d2b57834d2117d6be90
parent0bf0434f22b0ea46fda3ccc4dd612adbc88dd4f2 (diff)
downloadsamba-81f334bd6da601a040f754c46705cfa2fd4f8c45.tar.gz
samba-81f334bd6da601a040f754c46705cfa2fd4f8c45.tar.xz
samba-81f334bd6da601a040f754c46705cfa2fd4f8c45.zip
Make use of ADD_TO_ARRAY
-rw-r--r--source/include/proto.h4
-rw-r--r--source/winbindd/idmap.c94
-rw-r--r--source/winbindd/idmap_util.c34
-rw-r--r--source/winbindd/winbindd_idmap.c4
4 files changed, 38 insertions, 98 deletions
diff --git a/source/include/proto.h b/source/include/proto.h
index bb10487b545..2a954f4efeb 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -10485,8 +10485,8 @@ NTSTATUS idmap_allocate_uid(struct unixid *id);
NTSTATUS idmap_allocate_gid(struct unixid *id);
NTSTATUS idmap_set_uid_hwm(struct unixid *id);
NTSTATUS idmap_set_gid_hwm(struct unixid *id);
-NTSTATUS idmap_unixids_to_sids(struct id_map **ids);
-NTSTATUS idmap_sids_to_unixids(struct id_map **ids);
+NTSTATUS idmap_unixids_to_sids(struct id_map **ids, int n_ids);
+NTSTATUS idmap_sids_to_unixids(struct id_map **ids, int n_ids);
NTSTATUS idmap_set_mapping(const struct id_map *id);
char *idmap_fetch_secret(const char *backend, bool alloc,
const char *domain, const char *identity);
diff --git a/source/winbindd/idmap.c b/source/winbindd/idmap.c
index db17245b920..504be222922 100644
--- a/source/winbindd/idmap.c
+++ b/source/winbindd/idmap.c
@@ -1177,7 +1177,8 @@ done:
return ret;
}
-static NTSTATUS idmap_backends_sids_to_unixids(struct id_map **ids)
+static NTSTATUS idmap_backends_sids_to_unixids(struct id_map **ids, int
+ num_ids)
{
struct id_map ***dom_ids;
struct idmap_domain *dom;
@@ -1205,7 +1206,7 @@ static NTSTATUS idmap_backends_sids_to_unixids(struct id_map **ids)
/* partition the requests by domain */
- for (i = 0; ids[i]; i++) {
+ for (i = 0; i < num_ids; i++) {
uint32 idx;
if ((dom = find_idmap_domain_from_sid(ids[i]->sid)) == NULL) {
@@ -1245,7 +1246,7 @@ static NTSTATUS idmap_backends_sids_to_unixids(struct id_map **ids)
/* ok all the backends have been contacted at this point */
/* let's see if we have any unmapped SID left and act accordingly */
- for (i = 0; ids[i]; i++) {
+ for (i = 0; i < num_ids; i++) {
/* NOTE: this will NOT touch ID_EXPIRED entries that the backend
* was not able to confirm/deny (offline mode) */
if (ids[i]->status == ID_UNKNOWN ||
@@ -1278,7 +1279,7 @@ done:
idmap interface functions
**************************************************************************/
-NTSTATUS idmap_unixids_to_sids(struct id_map **ids)
+NTSTATUS idmap_unixids_to_sids(struct id_map **ids, int n_ids)
{
TALLOC_CTX *ctx;
NTSTATUS ret;
@@ -1306,7 +1307,7 @@ NTSTATUS idmap_unixids_to_sids(struct id_map **ids)
bids = NULL;
bi = 0;
- for (i = 0; ids[i]; i++) {
+ for (i = 0; i < n_ids; i++) {
bool found, mapped, expired;
@@ -1331,38 +1332,12 @@ NTSTATUS idmap_unixids_to_sids(struct id_map **ids)
* Need to ask the backend
*/
- if ( ! bids) {
- /* alloc space for ids to be resolved by
- * backends (realloc ten by ten) */
- bids = TALLOC_ARRAY(ctx, struct id_map *, 10);
- if ( ! bids) {
- DEBUG(1, ("Out of memory!\n"));
- talloc_free(ctx);
- return NT_STATUS_NO_MEMORY;
- }
- bn = 10;
+ ADD_TO_ARRAY(ctx, struct id_map *, ids[i], &bids, &bn);
+ if (bids == NULL) {
+ DEBUG(1, ("Out of memory!\n"));
+ talloc_free(ctx);
+ return NT_STATUS_NO_MEMORY;
}
-
- /* add this id to the ones to be retrieved
- * from the backends */
- bids[bi] = ids[i];
- bi++;
-
- /* check if we need to allocate new space
- * on the rids array */
- if (bi == bn) {
- bn += 10;
- bids = talloc_realloc(ctx, bids,
- struct id_map *, bn);
- if ( ! bids) {
- DEBUG(1, ("Out of memory!\n"));
- talloc_free(ctx);
- return NT_STATUS_NO_MEMORY;
- }
- }
-
- /* make sure the last element is NULL */
- bids[bi] = NULL;
}
}
@@ -1408,12 +1383,12 @@ done:
return ret;
}
-NTSTATUS idmap_sids_to_unixids(struct id_map **ids)
+NTSTATUS idmap_sids_to_unixids(struct id_map **ids, int n_ids)
{
TALLOC_CTX *ctx;
NTSTATUS ret;
struct id_map **bids;
- int i, bi;
+ int i;
int bn = 0;
struct winbindd_domain *our_domain = find_our_domain();
@@ -1434,9 +1409,8 @@ NTSTATUS idmap_sids_to_unixids(struct id_map **ids)
/* no ids to be asked to the backends by default */
bids = NULL;
- bi = 0;
- for (i = 0; ids[i]; i++) {
+ for (i = 0; i < n_ids; i++) {
bool found, mapped, expired;
@@ -1461,38 +1435,12 @@ NTSTATUS idmap_sids_to_unixids(struct id_map **ids)
* Need to ask the backends
*/
- if ( ! bids) {
- /* alloc space for ids to be resolved
- by backends (realloc ten by ten) */
- bids = TALLOC_ARRAY(ctx, struct id_map *, 10);
- if ( ! bids) {
- DEBUG(1, ("Out of memory!\n"));
- talloc_free(ctx);
- return NT_STATUS_NO_MEMORY;
- }
- bn = 10;
- }
-
- /* add this id to the ones to be retrieved
- * from the backends */
- bids[bi] = ids[i];
- bi++;
-
- /* check if we need to allocate new space
- * on the ids array */
- if (bi == bn) {
- bn += 10;
- bids = talloc_realloc(ctx, bids,
- struct id_map *, bn);
- if ( ! bids) {
- DEBUG(1, ("Out of memory!\n"));
- talloc_free(ctx);
- return NT_STATUS_NO_MEMORY;
- }
+ ADD_TO_ARRAY(ctx, struct id_map *, ids[i], &bids, &bn);
+ if (bids == NULL) {
+ DEBUG(1, ("Out of memory!\n"));
+ talloc_free(ctx);
+ return NT_STATUS_NO_MEMORY;
}
-
- /* make sure the last element is NULL */
- bids[bi] = NULL;
}
}
@@ -1505,11 +1453,11 @@ NTSTATUS idmap_sids_to_unixids(struct id_map **ids)
goto done;
}
- ret = idmap_backends_sids_to_unixids(bids);
+ ret = idmap_backends_sids_to_unixids(bids, bn);
IDMAP_CHECK_RET(ret);
/* update the cache */
- for (i = 0; bids[i]; i++) {
+ for (i = 0; i < bn; i++) {
if (bids[i]->status == ID_MAPPED) {
ret = idmap_cache_set(bids[i]);
} else if (bids[i]->status == ID_EXPIRED) {
diff --git a/source/winbindd/idmap_util.c b/source/winbindd/idmap_util.c
index 78f4d13ec1e..9819fe15f0a 100644
--- a/source/winbindd/idmap_util.c
+++ b/source/winbindd/idmap_util.c
@@ -31,18 +31,16 @@ NTSTATUS idmap_uid_to_sid(DOM_SID *sid, uid_t uid)
{
NTSTATUS ret;
struct id_map map;
- struct id_map *maps[2];
+ struct id_map *maps;
DEBUG(10,("uid = [%lu]\n", (unsigned long)uid));
map.sid = sid;
map.xid.type = ID_TYPE_UID;
map.xid.id = uid;
+ maps = &map;
- maps[0] = &map;
- maps[1] = NULL;
-
- ret = idmap_unixids_to_sids(maps);
+ ret = idmap_unixids_to_sids(&maps, 1);
if ( ! NT_STATUS_IS_OK(ret)) {
DEBUG(10, ("error mapping uid [%lu]\n", (unsigned long)uid));
return ret;
@@ -65,18 +63,16 @@ NTSTATUS idmap_gid_to_sid(DOM_SID *sid, gid_t gid)
{
NTSTATUS ret;
struct id_map map;
- struct id_map *maps[2];
+ struct id_map *maps;
DEBUG(10,("gid = [%lu]\n", (unsigned long)gid));
map.sid = sid;
map.xid.type = ID_TYPE_GID;
map.xid.id = gid;
+ maps = &map;
- maps[0] = &map;
- maps[1] = NULL;
-
- ret = idmap_unixids_to_sids(maps);
+ ret = idmap_unixids_to_sids(&maps, 1);
if ( ! NT_STATUS_IS_OK(ret)) {
DEBUG(10, ("error mapping gid [%lu]\n", (unsigned long)gid));
return ret;
@@ -99,17 +95,15 @@ NTSTATUS idmap_sid_to_uid(DOM_SID *sid, uid_t *uid)
{
NTSTATUS ret;
struct id_map map;
- struct id_map *maps[2];
+ struct id_map *maps;
DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_dbg(sid)));
map.sid = sid;
- map.xid.type = ID_TYPE_UID;
-
- maps[0] = &map;
- maps[1] = NULL;
+ map.xid.type = ID_TYPE_UID;
+ maps = &map;
- ret = idmap_sids_to_unixids(maps);
+ ret = idmap_sids_to_unixids(&maps, 1);
if ( ! NT_STATUS_IS_OK(ret)) {
DEBUG(10, ("error mapping sid [%s] to uid\n",
sid_string_dbg(sid)));
@@ -139,17 +133,15 @@ NTSTATUS idmap_sid_to_gid(DOM_SID *sid, gid_t *gid)
{
NTSTATUS ret;
struct id_map map;
- struct id_map *maps[2];
+ struct id_map *maps;
DEBUG(10,("idmap_sid_to_gid: sid = [%s]\n", sid_string_dbg(sid)));
map.sid = sid;
map.xid.type = ID_TYPE_GID;
+ maps = &map;
- maps[0] = &map;
- maps[1] = NULL;
-
- ret = idmap_sids_to_unixids(maps);
+ ret = idmap_sids_to_unixids(&maps, 1);
if ( ! NT_STATUS_IS_OK(ret)) {
DEBUG(10, ("error mapping sid [%s] to gid\n",
sid_string_dbg(sid)));
diff --git a/source/winbindd/winbindd_idmap.c b/source/winbindd/winbindd_idmap.c
index 3c7aa2d0c22..98f8548083d 100644
--- a/source/winbindd/winbindd_idmap.c
+++ b/source/winbindd/winbindd_idmap.c
@@ -224,7 +224,7 @@ enum winbindd_result winbindd_dual_sids2xids(struct winbindd_domain *domain,
sids = (DOM_SID *)state->request.extra_data.data;
num = state->request.extra_len / sizeof(DOM_SID);
- ids = TALLOC_ZERO_ARRAY(state->mem_ctx, struct id_map *, num + 1);
+ ids = TALLOC_ARRAY(state->mem_ctx, struct id_map *, num);
if ( ! ids) {
DEBUG(0, ("Out of memory!\n"));
return WINBINDD_ERROR;
@@ -239,7 +239,7 @@ enum winbindd_result winbindd_dual_sids2xids(struct winbindd_domain *domain,
ids[i]->sid = &sids[i];
}
- result = idmap_sids_to_unixids(ids);
+ result = idmap_sids_to_unixids(ids, num);
if (NT_STATUS_IS_OK(result)) {