The cli_lsa_lookup_{names,sids} functions were returning useless
authorTim Potter <tpot@samba.org>
Sun, 14 Apr 2002 11:21:25 +0000 (11:21 +0000)
committerTim Potter <tpot@samba.org>
Sun, 14 Apr 2002 11:21:25 +0000 (11:21 +0000)
information when one or more of the names/sids being queried were not
resolvable.  We now return a list the same length as the parameters passed
instead of an array of just the resolvable names/sids.
(This used to be commit 245468dbabb7c849ce423cc3cb586fa913d0adfe)

source3/libsmb/cli_lsarpc.c
source3/nsswitch/winbindd_rpc.c
source3/rpcclient/cmd_lsarpc.c
source3/utils/smbcacls.c

index 32168546082bd26b9cb50589c6c35bb88834f227..1989169fd78a1b45dc64eaab23f1226c21562d3e 100644 (file)
@@ -230,7 +230,7 @@ NTSTATUS cli_lsa_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
 
 NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
                              POLICY_HND *pol, int num_sids, DOM_SID *sids, 
-                             char ***domains, char ***names, uint32 **types, int *num_names)
+                             char ***domains, char ***names, uint32 **types)
 {
        prs_struct qbuf, rbuf;
        LSA_Q_LOOKUP_SIDS q;
@@ -274,13 +274,13 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
        result = r.status;
 
        if (!NT_STATUS_IS_OK(result) &&
-               NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_FILES_OPEN)) {
+           NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
+         
                /* An actual error occured */
 
                goto done;
        }
 
-
        /* Return output parameters */
 
        if (r.mapped_count == 0) {
@@ -288,28 +288,28 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       (*num_names) = r.mapped_count;
-       result = NT_STATUS_OK;
-
-       if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) * r.mapped_count))) {
+       if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) *
+                                          num_sids))) {
                DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
                result = NT_STATUS_UNSUCCESSFUL;
                goto done;
        }
 
-       if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) * r.mapped_count))) {
+       if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) *
+                                        num_sids))) {
                DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
                result = NT_STATUS_UNSUCCESSFUL;
                goto done;
        }
 
-       if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.mapped_count))) {
+       if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
+                                         num_sids))) {
                DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
                result = NT_STATUS_UNSUCCESSFUL;
                goto done;
        }
                
-       for (i = 0; i < r.mapped_count; i++) {
+       for (i = 0; i < num_sids; i++) {
                fstring name, dom_name;
                uint32 dom_idx = t_names.name[i].domain_idx;
 
@@ -348,8 +348,9 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
 /** Lookup a list of names */
 
 NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
-                              POLICY_HND *pol, int num_names, const char **names, 
-                              DOM_SID **sids, uint32 **types, int *num_sids)
+                              POLICY_HND *pol, int num_names, 
+                             const char **names, DOM_SID **sids, 
+                             uint32 **types)
 {
        prs_struct qbuf, rbuf;
        LSA_Q_LOOKUP_NAMES q;
@@ -388,13 +389,14 @@ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
 
        result = r.status;
 
-       if (!NT_STATUS_IS_OK(result)) {
+       if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
+           NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
+
                /* An actual error occured */
 
                goto done;
        }
 
-
        /* Return output parameters */
 
        if (r.mapped_count == 0) {
@@ -402,22 +404,21 @@ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       (*num_sids) = r.mapped_count;
-       result = NT_STATUS_OK;
-
-       if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.mapped_count)))) {
+       if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
+                                        num_names)))) {
                DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
                result = NT_STATUS_UNSUCCESSFUL;
                goto done;
        }
 
-       if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.mapped_count)))) {
+       if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
+                                        num_names)))) {
                DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
                result = NT_STATUS_UNSUCCESSFUL;
                goto done;
        }
 
-       for (i = 0; i < r.mapped_count; i++) {
+       for (i = 0; i < num_names; i++) {
                DOM_RID2 *t_rids = r.dom_rid;
                uint32 dom_idx = t_rids[i].rid_idx;
                uint32 dom_rid = t_rids[i].rid;
index 5af42ee041bb1b5b3d8e3b37aaa5ac306f25417f..39433419b0b8f5740caad0cc72f5211614440143 100644 (file)
@@ -187,7 +187,6 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
        NTSTATUS status;
        DOM_SID *sids = NULL;
        uint32 *types = NULL;
-       int num_sids;
        const char *full_name;
 
        if (!(mem_ctx = talloc_init_named("name_to_sid[rpc] for [%s]\\[%s]", domain->name, name))) {
@@ -209,9 +208,10 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
        }
 
        status = cli_lsa_lookup_names(hnd->cli, mem_ctx, &hnd->pol, 1, 
-                                     &full_name, &sids, &types, &num_sids);
+                                     &full_name, &sids, &types);
         
-       /* Return rid and type if lookup successful */        
+       /* Return rid and type if lookup successful */
+
        if (NT_STATUS_IS_OK(status)) {
                sid_copy(sid, &sids[0]);
                *type = types[0];
@@ -234,15 +234,13 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain,
        char **domains;
        char **names;
        uint32 *types;
-       int num_names;
        NTSTATUS status;
 
        if (!(hnd = cm_get_lsa_handle(domain->name)))
                return NT_STATUS_UNSUCCESSFUL;
         
        status = cli_lsa_lookup_sids(hnd->cli, mem_ctx, &hnd->pol,
-                                    1, sid, &domains, &names, &types, 
-                                    &num_names);
+                                    1, sid, &domains, &names, &types);
 
        if (NT_STATUS_IS_OK(status)) {
                *type = types[0];
index 99f1fbc3ce3320b02b3bc508c6444e7ba2765be8..1f8b14ae04c2892027793306d3a996ee866e56e3 100644 (file)
@@ -78,7 +78,7 @@ static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
        DOM_SID *sids;
        uint32 *types;
-       int num_names, i;
+       int i;
 
        if (argc == 1) {
                printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
@@ -93,15 +93,17 @@ static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
                goto done;
 
        result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1, 
-                                     (const char**)(argv + 1), &sids, 
-                                     &types, &num_names);
+                                     (const char**)(argv + 1), &sids, &types);
 
-       if (!NT_STATUS_IS_OK(result))
+       if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) != 
+           NT_STATUS_V(STATUS_SOME_UNMAPPED))
                goto done;
 
+       result = NT_STATUS_OK;
+
        /* Print results */
 
-       for (i = 0; i < num_names; i++) {
+       for (i = 0; i < (argc - 1); i++) {
                fstring sid_str;
 
                sid_to_string(sid_str, &sids[i]);
@@ -124,7 +126,7 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
        char **domains;
        char **names;
        uint32 *types;
-       int num_names, i;
+       int i;
 
        if (argc == 1) {
                printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
@@ -153,18 +155,21 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
        /* Lookup the SIDs */
 
        result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids, 
-                                    &domains, &names, &types, &num_names);
+                                    &domains, &names, &types);
 
-       if (!NT_STATUS_IS_OK(result))
+       if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) != 
+           NT_STATUS_V(STATUS_SOME_UNMAPPED))
                goto done;
 
+       result = NT_STATUS_OK;
+
        /* Print results */
 
-       for (i = 0; i < num_names; i++) {
+       for (i = 0; i < (argc - 1); i++) {
                fstring sid_str;
 
                sid_to_string(sid_str, &sids[i]);
-               printf("%s [%s]\\[%s] (%d)\n", sid_str, 
+               printf("%s %s\\%s (%d)\n", sid_str, 
                       domains[i] ? domains[i] : "*unknown*", 
                       names[i] ? names[i] : "*unknown*", types[i]);
        }
@@ -446,6 +451,7 @@ static NTSTATUS cmd_lsa_lookupprivvalue(struct cli_state *cli,
                goto done;
 
        /* Print results */
+
        printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
 
  done:
index 8c0b2a4a72e192d9879a735cb7883f15de5efbb0..017f4035b07fe028b32055d45c8a3882e8491ec6 100644 (file)
@@ -108,7 +108,6 @@ static void SidToString(fstring str, DOM_SID *sid)
        char **domains = NULL;
        char **names = NULL;
        uint32 *types = NULL;
-       int num_names;
 
        sid_to_string(str, sid);
 
@@ -118,8 +117,8 @@ static void SidToString(fstring str, DOM_SID *sid)
 
        if (!cacls_open_policy_hnd() ||
            !NT_STATUS_IS_OK(cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx,  
-                                                &pol, 1, sid, &domains, &names, 
-                                                &types, &num_names)) ||
+                                                &pol, 1, sid, &domains, 
+                                                &names, &types)) ||
            !domains || !domains[0] || !names || !names[0]) {
                return;
        }
@@ -137,7 +136,6 @@ static BOOL StringToSid(DOM_SID *sid, const char *str)
 {
        uint32 *types = NULL;
        DOM_SID *sids = NULL;
-       int num_sids;
        BOOL result = True;
 
        if (strncmp(str, "S-", 2) == 0) {
@@ -145,9 +143,9 @@ static BOOL StringToSid(DOM_SID *sid, const char *str)
        }
 
        if (!cacls_open_policy_hnd() ||
-           !NT_STATUS_IS_OK(cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, 
-                                                 &str
-                                                 &sids, &types, &num_sids))) {
+           !NT_STATUS_IS_OK(cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, 
+                                                 &pol, 1, &str, &sids
+                                                 &types))) {
                result = False;
                goto done;
        }