From 61f3e6740765c92cd84c28ee69fe410c18b548fc Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 21 Mar 2019 14:00:16 +0100 Subject: idmap_hash: mirror the NT_STATUS_NONE_MAPPED/STATUS_SOME_UNMAPPED logic from idmap_autorid BUG: https://bugzilla.samba.org/show_bug.cgi?id=15319 Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison (cherry picked from commit 14102b05f3744c67178bd719d41e67fc3e049ee4) --- source3/winbindd/idmap_hash/idmap_hash.c | 36 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/source3/winbindd/idmap_hash/idmap_hash.c b/source3/winbindd/idmap_hash/idmap_hash.c index 7b849aa0259..ff9f86b6676 100644 --- a/source3/winbindd/idmap_hash/idmap_hash.c +++ b/source3/winbindd/idmap_hash/idmap_hash.c @@ -188,11 +188,14 @@ static NTSTATUS unixids_to_sids(struct idmap_domain *dom, { struct sid_hash_table *hashed_domains = talloc_get_type_abort( dom->private_data, struct sid_hash_table); - int i; + size_t i; + size_t num_tomap = 0; + size_t num_mapped = 0; - /* initialize the status to avoid suprise */ + /* initialize the status to avoid surprise */ for (i = 0; ids[i]; i++) { ids[i]->status = ID_UNKNOWN; + num_tomap++; } for (i=0; ids[i]; i++) { @@ -211,9 +214,16 @@ static NTSTATUS unixids_to_sids(struct idmap_domain *dom, ids[i]->xid.type = ID_TYPE_BOTH; sid_compose(ids[i]->sid, hashed_domains[h_domain].sid, h_rid); ids[i]->status = ID_MAPPED; + num_mapped++; } - return NT_STATUS_OK; + if (num_tomap == num_mapped) { + return NT_STATUS_OK; + } else if (num_mapped == 0) { + return NT_STATUS_NONE_MAPPED; + } + + return STATUS_SOME_UNMAPPED; } /********************************************************************* @@ -222,11 +232,15 @@ static NTSTATUS unixids_to_sids(struct idmap_domain *dom, static NTSTATUS sids_to_unixids(struct idmap_domain *dom, struct id_map **ids) { - int i; + size_t i; + size_t num_tomap = 0; + size_t num_mapped = 0; + size_t num_required = 0; - /* initialize the status to avoid suprise */ + /* initialize the status to avoid surprise */ for (i = 0; ids[i]; i++) { ids[i]->status = ID_UNKNOWN; + num_tomap++; } for (i=0; ids[i]; i++) { @@ -252,6 +266,7 @@ static NTSTATUS sids_to_unixids(struct idmap_domain *dom, * if the domain is not known yet. */ ids[i]->status = ID_REQUIRE_TYPE; + num_required++; continue; } @@ -282,10 +297,19 @@ static NTSTATUS sids_to_unixids(struct idmap_domain *dom, ids[i]->xid.type = ID_TYPE_BOTH; ids[i]->xid.id = combine_hashes(h_domain, h_rid); ids[i]->status = ID_MAPPED; + num_mapped++; } } - return NT_STATUS_OK; + if (num_tomap == num_mapped) { + return NT_STATUS_OK; + } else if (num_required > 0) { + return STATUS_SOME_UNMAPPED; + } else if (num_mapped == 0) { + return NT_STATUS_NONE_MAPPED; + } + + return STATUS_SOME_UNMAPPED; } /********************************************************************* -- cgit v1.2.1