s3: Correctly calculate the wbinfo -s result
[kai/samba.git] / source3 / rpc_client / cli_lsarpc.c
index d49fa47f57a3cf0b8f4abee6f466134e74202e9a..29cb09cdddd86bf764589620c3bf527dbc34f048 100644 (file)
 */
 
 #include "includes.h"
+#include "../librpc/gen_ndr/cli_lsa.h"
+#include "rpc_client/cli_lsarpc.h"
+#include "rpc_client/init_lsa.h"
+#include "../libcli/security/security.h"
 
 /** @defgroup lsa LSA - Local Security Architecture
  *  @ingroup rpc_client
@@ -111,7 +115,7 @@ static NTSTATUS rpccli_lsa_lookup_sids_noalloc(struct rpc_pipe_client *cli,
                                               TALLOC_CTX *mem_ctx,
                                               struct policy_handle *pol,
                                               int num_sids,
-                                              const DOM_SID *sids,
+                                              const struct dom_sid *sids,
                                               char **domains,
                                               char **names,
                                               enum lsa_SidType *types,
@@ -142,7 +146,7 @@ static NTSTATUS rpccli_lsa_lookup_sids_noalloc(struct rpc_pipe_client *cli,
        }
 
        for (i = 0; i<num_sids; i++) {
-               sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sids[i]);
+               sid_array.sids[i].sid = dom_sid_dup(mem_ctx, &sids[i]);
                if (!sid_array.sids[i].sid) {
                        return NT_STATUS_NO_MEMORY;
                }
@@ -223,7 +227,7 @@ static NTSTATUS rpccli_lsa_lookup_sids_noalloc(struct rpc_pipe_client *cli,
                        name = lsa_names.names[i].name.string;
 
                        if (name) {
-                               (names)[i] = talloc_strdup(mem_ctx, name);
+                               (names)[i] = talloc_strdup(names, name);
                                if ((names)[i] == NULL) {
                                        DEBUG(0, ("cli_lsa_lookup_sids_noalloc(): out of memory\n"));
                                        result = NT_STATUS_UNSUCCESSFUL;
@@ -232,7 +236,8 @@ static NTSTATUS rpccli_lsa_lookup_sids_noalloc(struct rpc_pipe_client *cli,
                        } else {
                                (names)[i] = NULL;
                        }
-                       (domains)[i] = talloc_strdup(mem_ctx, dom_name);
+                       domains[i] = talloc_strdup(domains,
+                                                  dom_name ? dom_name : "");
                        (types)[i] = lsa_names.names[i].sid_type;
                        if (((domains)[i] == NULL)) {
                                DEBUG(0, ("cli_lsa_lookup_sids_noalloc(): out of memory\n"));
@@ -268,7 +273,7 @@ static NTSTATUS rpccli_lsa_lookup_sids_generic(struct rpc_pipe_client *cli,
                                               TALLOC_CTX *mem_ctx,
                                               struct policy_handle *pol,
                                               int num_sids,
-                                              const DOM_SID *sids,
+                                              const struct dom_sid *sids,
                                               char ***pdomains,
                                               char ***pnames,
                                               enum lsa_SidType **ptypes,
@@ -277,13 +282,15 @@ static NTSTATUS rpccli_lsa_lookup_sids_generic(struct rpc_pipe_client *cli,
        NTSTATUS result = NT_STATUS_OK;
        int sids_left = 0;
        int sids_processed = 0;
-       const DOM_SID *hunk_sids = sids;
+       const struct dom_sid *hunk_sids = sids;
        char **hunk_domains;
        char **hunk_names;
        enum lsa_SidType *hunk_types;
        char **domains = NULL;
        char **names = NULL;
        enum lsa_SidType *types = NULL;
+       bool have_mapped = false;
+       bool have_unmapped = false;
 
        if (num_sids) {
                if (!(domains = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
@@ -343,14 +350,21 @@ static NTSTATUS rpccli_lsa_lookup_sids_generic(struct rpc_pipe_client *cli,
                        goto fail;
                }
 
-               /* adapt overall result */
-               if (( NT_STATUS_IS_OK(result) &&
-                    !NT_STATUS_IS_OK(hunk_result))
-                   ||
-                   ( NT_STATUS_EQUAL(result, NT_STATUS_NONE_MAPPED) &&
-                    !NT_STATUS_EQUAL(hunk_result, NT_STATUS_NONE_MAPPED)))
-               {
-                       result = STATUS_SOME_UNMAPPED;
+               if (NT_STATUS_IS_OK(hunk_result)) {
+                       have_mapped = true;
+               }
+               if (NT_STATUS_EQUAL(hunk_result, NT_STATUS_NONE_MAPPED)) {
+                       have_unmapped = true;
+               }
+               if (NT_STATUS_EQUAL(hunk_result, STATUS_SOME_UNMAPPED)) {
+                       int i;
+                       for (i=0; i<hunk_num_sids; i++) {
+                               if (hunk_types[i] == SID_NAME_UNKNOWN) {
+                                       have_unmapped = true;
+                               } else {
+                                       have_mapped = true;
+                               }
+                       }
                }
 
                sids_left -= hunk_num_sids;
@@ -364,7 +378,14 @@ static NTSTATUS rpccli_lsa_lookup_sids_generic(struct rpc_pipe_client *cli,
        *pdomains = domains;
        *pnames = names;
        *ptypes = types;
-       return result;
+
+       if (!have_mapped) {
+               return NT_STATUS_NONE_MAPPED;
+       }
+       if (have_unmapped) {
+               return STATUS_SOME_UNMAPPED;
+       }
+       return NT_STATUS_OK;
 
 fail:
        TALLOC_FREE(domains);
@@ -377,7 +398,7 @@ NTSTATUS rpccli_lsa_lookup_sids(struct rpc_pipe_client *cli,
                                TALLOC_CTX *mem_ctx,
                                struct policy_handle *pol,
                                int num_sids,
-                               const DOM_SID *sids,
+                               const struct dom_sid *sids,
                                char ***pdomains,
                                char ***pnames,
                                enum lsa_SidType **ptypes)
@@ -390,7 +411,7 @@ NTSTATUS rpccli_lsa_lookup_sids3(struct rpc_pipe_client *cli,
                                 TALLOC_CTX *mem_ctx,
                                 struct policy_handle *pol,
                                 int num_sids,
-                                const DOM_SID *sids,
+                                const struct dom_sid *sids,
                                 char ***pdomains,
                                 char ***pnames,
                                 enum lsa_SidType **ptypes)
@@ -407,7 +428,7 @@ static NTSTATUS rpccli_lsa_lookup_names_generic(struct rpc_pipe_client *cli,
                                                const char **names,
                                                const char ***dom_names,
                                                int level,
-                                               DOM_SID **sids,
+                                               struct dom_sid **sids,
                                                enum lsa_SidType **types,
                                                bool use_lookupnames4)
 {
@@ -468,7 +489,7 @@ static NTSTATUS rpccli_lsa_lookup_names_generic(struct rpc_pipe_client *cli,
        }
 
        if (num_names) {
-               if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
+               if (!((*sids = TALLOC_ARRAY(mem_ctx, struct dom_sid, num_names)))) {
                        DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
                        result = NT_STATUS_NO_MEMORY;
                        goto done;
@@ -498,7 +519,7 @@ static NTSTATUS rpccli_lsa_lookup_names_generic(struct rpc_pipe_client *cli,
 
        for (i = 0; i < num_names; i++) {
                uint32_t dom_idx;
-               DOM_SID *sid = &(*sids)[i];
+               struct dom_sid *sid = &(*sids)[i];
 
                if (use_lookupnames4) {
                        dom_idx         = sid_array3.sids[i].sid_index;
@@ -545,7 +566,7 @@ NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
                                 const char **names,
                                 const char ***dom_names,
                                 int level,
-                                DOM_SID **sids,
+                                struct dom_sid **sids,
                                 enum lsa_SidType **types)
 {
        return rpccli_lsa_lookup_names_generic(cli, mem_ctx, pol, num_names,
@@ -559,7 +580,7 @@ NTSTATUS rpccli_lsa_lookup_names4(struct rpc_pipe_client *cli,
                                  const char **names,
                                  const char ***dom_names,
                                  int level,
-                                 DOM_SID **sids,
+                                 struct dom_sid **sids,
                                  enum lsa_SidType **types)
 {
        return rpccli_lsa_lookup_names_generic(cli, mem_ctx, pol, num_names,