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;
/* 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) {
/* 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 ||
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;
bids = NULL;
bi = 0;
- for (i = 0; ids[i]; i++) {
+ for (i = 0; i < n_ids; i++) {
bool found, mapped, expired;
* 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;
}
}
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();
/* 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;
* 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;
}
}
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) {
{
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 = ↦
- maps[0] = ↦
- 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;
{
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 = ↦
- maps[0] = ↦
- 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;
{
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] = ↦
- maps[1] = NULL;
+ map.xid.type = ID_TYPE_UID;
+ maps = ↦
- 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)));
{
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 = ↦
- maps[0] = ↦
- 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)));