]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3/passdb: add winbind_lookup_name_ex()
authorRalph Boehme <slow@samba.org>
Thu, 8 Feb 2024 17:20:15 +0000 (18:20 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 26 Jul 2024 10:06:31 +0000 (10:06 +0000)
Differs from winbind_lookup_name() by

- returning NTSTATUS instead of bool, so callers can distinguish between
STATUS_NAME_NOT_FOUND lookup results and real errors.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/lib/winbind_util.c
source3/lib/winbind_util.h

index 7e3f8ab9eb81c2a98eca3f3b2a49f606aff42bcc..0852c3d02814889c978101e0538e7ef897758a82 100644 (file)
@@ -83,6 +83,46 @@ bool winbind_lookup_name(const char *dom_name, const char *name, struct dom_sid
        return true;
 }
 
+/* Same as winbind_lookup_name(), but returning NTSTATUS instead of bool */
+
+_PRIVATE_
+NTSTATUS winbind_lookup_name_ex(const char *dom_name,
+                               const char *name,
+                               struct dom_sid *sid,
+                               enum lsa_SidType *name_type)
+{
+       struct wbcDomainSid dom_sid;
+       wbcErr result;
+       enum wbcSidType type;
+       NTSTATUS status;
+
+       result = wbcLookupName(dom_name, name, &dom_sid, &type);
+
+       status = map_nt_error_from_wbcErr(result);
+       if (!NT_STATUS_IS_OK(status)) {
+               if ((lp_security() < SEC_DOMAIN) &&
+                   NT_STATUS_EQUAL(status, NT_STATUS_SERVER_DISABLED))
+               {
+                       /*
+                        * If we're not a domain member and winbind is not
+                        * running, treat this as not mapped.
+                        */
+                       status = NT_STATUS_NONE_MAPPED;
+               }
+               if (!NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
+                       return status;
+               }
+               *name_type = SID_NAME_UNKNOWN;
+               ZERO_STRUCTP(sid);
+               return NT_STATUS_OK;
+       }
+
+       memcpy(sid, &dom_sid, sizeof(struct dom_sid));
+       *name_type = (enum lsa_SidType)type;
+
+       return NT_STATUS_OK;
+}
+
 /* Call winbindd to convert sid to name */
 
 bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
index 6056190d7a4ae3b08edbe4df9544c1a1a9fcfa0b..0a3a460ce05a89cc90d6850975d72abffc36bb40 100644 (file)
 
 bool winbind_lookup_name(const char *dom_name, const char *name, struct dom_sid *sid,
                          enum lsa_SidType *name_type);
+NTSTATUS winbind_lookup_name_ex(const char *dom_name,
+                               const char *name,
+                               struct dom_sid *sid,
+                               enum lsa_SidType *name_type);
 bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
                        const char **domain, const char **name,
                         enum lsa_SidType *name_type);