[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / rpcclient / cmd_lsarpc.c
index e3fe57e127f110f4e2a113ad511f816bb64b34db..31a8e2bdfd130ba1d4682eb3c0fd30c963baef08 100644 (file)
@@ -7,7 +7,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -87,7 +86,7 @@ static void display_query_info_3(DOM_QUERY_3 d)
 {
        fstring name;
 
-       unistr2_to_ascii(name, &d.uni_domain_name, d.uni_dom_max_len);
+       unistr2_to_ascii(name, &d.uni_domain_name, sizeof(name));
 
        d_printf("Domain Name: %s\n", name);
        d_printf("Domain Sid: %s\n", sid_string_static(&d.dom_sid.sid));
@@ -97,7 +96,7 @@ static void display_query_info_5(DOM_QUERY_5 d)
 {
        fstring name;
 
-       unistr2_to_ascii(name, &d.uni_domain_name, d.uni_dom_max_len);
+       unistr2_to_ascii(name, &d.uni_domain_name, sizeof(name));
 
        d_printf("Domain Name: %s\n", name);
        d_printf("Domain Sid: %s\n", sid_string_static(&d.dom_sid.sid));
@@ -119,9 +118,9 @@ static void display_query_info_12(DOM_QUERY_12 d)
 {
        fstring dom_name, dns_dom_name, forest_name;
 
-       unistr2_to_ascii(dom_name, &d.uni_nb_dom_name, d.hdr_nb_dom_name.uni_max_len);
-       unistr2_to_ascii(dns_dom_name, &d.uni_dns_dom_name, d.hdr_dns_dom_name.uni_max_len);
-       unistr2_to_ascii(forest_name, &d.uni_forest_name, d.hdr_forest_name.uni_max_len);
+       unistr2_to_ascii(dom_name, &d.uni_nb_dom_name, sizeof(dom_name));
+       unistr2_to_ascii(dns_dom_name, &d.uni_dns_dom_name, sizeof(dns_dom_name));
+       unistr2_to_ascii(forest_name, &d.uni_forest_name, sizeof(forest_name));
 
        d_printf("Domain NetBios Name: %s\n", dom_name);
        d_printf("Domain DNS Name: %s\n", dns_dom_name);
@@ -262,6 +261,57 @@ static NTSTATUS cmd_lsa_lookup_names(struct rpc_pipe_client *cli,
        return result;
 }
 
+/* Resolve a list of names to a list of sids */
+
+static NTSTATUS cmd_lsa_lookup_names_level(struct rpc_pipe_client *cli, 
+                                          TALLOC_CTX *mem_ctx, int argc, 
+                                          const char **argv)
+{
+       POLICY_HND pol;
+       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+       DOM_SID *sids;
+       enum lsa_SidType *types;
+       int i, level;
+
+       if (argc < 3) {
+               printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv[0]);
+               return NT_STATUS_OK;
+       }
+
+       result = rpccli_lsa_open_policy(cli, mem_ctx, True, 
+                                    SEC_RIGHTS_MAXIMUM_ALLOWED,
+                                    &pol);
+
+       if (!NT_STATUS_IS_OK(result))
+               goto done;
+
+       level = atoi(argv[1]);
+
+       result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 2, 
+                                     (const char**)(argv + 2), NULL, level, &sids, &types);
+
+       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 < (argc - 2); i++) {
+               fstring sid_str;
+               sid_to_string(sid_str, &sids[i]);
+               printf("%s %s (%s: %d)\n", argv[i + 2], sid_str,
+                      sid_type_lookup(types[i]), types[i]);
+       }
+
+       rpccli_lsa_Close(cli, mem_ctx, &pol);
+
+ done:
+       return result;
+}
+
+
 /* Resolve a list of SIDs to a list of names */
 
 static NTSTATUS cmd_lsa_lookup_sids(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
@@ -1047,6 +1097,7 @@ struct cmd_set lsarpc_commands[] = {
        { "lsaquery",            RPC_RTYPE_NTSTATUS, cmd_lsa_query_info_policy,  NULL, PI_LSARPC, NULL, "Query info policy",                    "" },
        { "lookupsids",          RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_sids,        NULL, PI_LSARPC, NULL, "Convert SIDs to names",                "" },
        { "lookupnames",         RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_names,       NULL, PI_LSARPC, NULL, "Convert names to SIDs",                "" },
+       { "lookupnames_level",   RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_names_level, NULL, PI_LSARPC, NULL, "Convert names to SIDs",                "" },
        { "enumtrust",           RPC_RTYPE_NTSTATUS, cmd_lsa_enum_trust_dom,     NULL, PI_LSARPC, NULL, "Enumerate trusted domains",            "Usage: [preferred max number] [enum context (0)]" },
        { "enumprivs",           RPC_RTYPE_NTSTATUS, cmd_lsa_enum_privilege,     NULL, PI_LSARPC, NULL, "Enumerate privileges",                 "" },
        { "getdispname",         RPC_RTYPE_NTSTATUS, cmd_lsa_get_dispname,       NULL, PI_LSARPC, NULL, "Get the privilege name",               "" },