[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / rpc_client / cli_lsarpc.c
index 0f66f1428873a20040ef179d0318d27d337ca087..be85e49476a8c8a4318d0181ddb84e989638a615 100644 (file)
@@ -5,6 +5,7 @@
    Copyright (C) Andrew Tridgell              1992-1997,2000,
    Copyright (C) Rafal Szczesniak                       2002
    Copyright (C) Jeremy Allison                                2005.
+   Copyright (C) Michael Adam                          2007.
 
    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
@@ -138,7 +139,7 @@ static NTSTATUS rpccli_lsa_lookup_sids_noalloc(struct rpc_pipe_client *cli,
                                               const DOM_SID *sids,
                                               char **domains,
                                               char **names,
-                                              enum lsa_SidType *types)
+                                              uint32 *types)
 {
        prs_struct qbuf, rbuf;
        LSA_Q_LOOKUP_SIDS q;
@@ -212,7 +213,7 @@ static NTSTATUS rpccli_lsa_lookup_sids_noalloc(struct rpc_pipe_client *cli,
 
                        (names)[i] = talloc_strdup(mem_ctx, name);
                        (domains)[i] = talloc_strdup(mem_ctx, dom_name);
-                       (types)[i] = (enum lsa_SidType)r.names.name[i].sid_name_use;
+                       (types)[i] = r.names.name[i].sid_name_use;
 
                        if (((names)[i] == NULL) || ((domains)[i] == NULL)) {
                                DEBUG(0, ("cli_lsa_lookup_sids_noalloc(): out of memory\n"));
@@ -244,14 +245,14 @@ done:
  * at 20480 for win2k3, but we keep it at a save 1000 for now. */
 #define LOOKUP_SIDS_HUNK_SIZE 1000
 
-NTSTATUS rpccli_lsa_lookup_sids_all(struct rpc_pipe_client *cli,
-                                   TALLOC_CTX *mem_ctx,
-                                   POLICY_HND *pol,
-                                   int num_sids,
-                                   const DOM_SID *sids,
-                                   char ***domains,
-                                   char ***names,
-                                   enum lsa_SidType **types)
+NTSTATUS rpccli_lsa_lookup_sids(struct rpc_pipe_client *cli,
+                               TALLOC_CTX *mem_ctx,
+                               POLICY_HND *pol,
+                               int num_sids,
+                               const DOM_SID *sids,
+                               char ***domains,
+                               char ***names,
+                               uint32 **types)
 {
        NTSTATUS result = NT_STATUS_OK;
        int sids_left = 0;
@@ -259,23 +260,23 @@ NTSTATUS rpccli_lsa_lookup_sids_all(struct rpc_pipe_client *cli,
        const DOM_SID *hunk_sids = sids;
        char **hunk_domains = NULL;
        char **hunk_names = NULL;
-       enum lsa_SidType *hunk_types = NULL;
+       uint32 *hunk_types = NULL;
 
        if (num_sids) {
                if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
-                       DEBUG(0, ("rpccli_lsa_lookup_sids_all(): out of memory\n"));
+                       DEBUG(0, ("rpccli_lsa_lookup_sids(): out of memory\n"));
                        result = NT_STATUS_NO_MEMORY;
                        goto fail;
                }
 
                if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
-                       DEBUG(0, ("rpccli_lsa_lookup_sids_all(): out of memory\n"));
+                       DEBUG(0, ("rpccli_lsa_lookup_sids(): out of memory\n"));
                        result = NT_STATUS_NO_MEMORY;
                        goto fail;
                }
 
                if (!((*types) = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_sids))) {
-                       DEBUG(0, ("rpccli_lsa_lookup_sids_all(): out of memory\n"));
+                       DEBUG(0, ("rpccli_lsa_lookup_sids(): out of memory\n"));
                        result = NT_STATUS_NO_MEMORY;
                        goto fail;
                }
@@ -298,7 +299,7 @@ NTSTATUS rpccli_lsa_lookup_sids_all(struct rpc_pipe_client *cli,
                                ? LOOKUP_SIDS_HUNK_SIZE
                                : sids_left);
 
-               DEBUG(10, ("rpccli_lsa_lookup_sids_all: processing items "
+               DEBUG(10, ("rpccli_lsa_lookup_sids: processing items "
                           "%d -- %d of %d.\n",
                           sids_processed,
                           sids_processed + hunk_num_sids - 1,
@@ -349,114 +350,6 @@ fail:
        return result;
 }
 
-/** Lookup a list of sids */
-
-NTSTATUS rpccli_lsa_lookup_sids(struct rpc_pipe_client *cli,
-                               TALLOC_CTX *mem_ctx,
-                               POLICY_HND *pol, int num_sids,
-                               const DOM_SID *sids,
-                               char ***domains,
-                               char ***names,
-                               enum lsa_SidType **types)
-{
-       prs_struct qbuf, rbuf;
-       LSA_Q_LOOKUP_SIDS q;
-       LSA_R_LOOKUP_SIDS r;
-       DOM_R_REF ref;
-       NTSTATUS result = NT_STATUS_OK;
-       int i;
-
-       ZERO_STRUCT(q);
-       ZERO_STRUCT(r);
-
-       init_q_lookup_sids(mem_ctx, &q, pol, num_sids, sids, 1);
-
-       ZERO_STRUCT(ref);
-
-       r.dom_ref = &ref;
-
-       CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_LOOKUPSIDS,
-                       q, r,
-                       qbuf, rbuf,
-                       lsa_io_q_lookup_sids,
-                       lsa_io_r_lookup_sids,
-                       NT_STATUS_UNSUCCESSFUL );
-
-       if (!NT_STATUS_IS_OK(r.status) &&
-           !NT_STATUS_EQUAL(r.status, STATUS_SOME_UNMAPPED)) {
-
-               /* An actual error occured */
-               result = r.status;
-
-               goto done;
-       }
-
-       /* Return output parameters */
-
-       if (r.mapped_count == 0) {
-               result = NT_STATUS_NONE_MAPPED;
-               goto done;
-       }
-
-       if (num_sids) {
-               if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
-                       DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-                       result = NT_STATUS_NO_MEMORY;
-                       goto done;
-               }
-
-               if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
-                       DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-                       result = NT_STATUS_NO_MEMORY;
-                       goto done;
-               }
-
-               if (!((*types) = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_sids))) {
-                       DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-                       result = NT_STATUS_NO_MEMORY;
-                       goto done;
-               }
-       } else {
-               (*domains) = NULL;
-               (*names) = NULL;
-               (*types) = NULL;
-       }
-
-       for (i = 0; i < num_sids; i++) {
-               fstring name, dom_name;
-               uint32 dom_idx = r.names.name[i].domain_idx;
-
-               /* Translate optimised name through domain index array */
-
-               if (dom_idx != 0xffffffff) {
-
-                       rpcstr_pull_unistr2_fstring(
-                                dom_name, &ref.ref_dom[dom_idx].uni_dom_name);
-                       rpcstr_pull_unistr2_fstring(
-                                name, &r.names.uni_name[i]);
-
-                       (*names)[i] = talloc_strdup(mem_ctx, name);
-                       (*domains)[i] = talloc_strdup(mem_ctx, dom_name);
-                       (*types)[i] = (enum lsa_SidType)r.names.name[i].sid_name_use;
-
-                       if (((*names)[i] == NULL) || ((*domains)[i] == NULL)) {
-                               DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-                               result = NT_STATUS_UNSUCCESSFUL;
-                               goto done;
-                       }
-
-               } else {
-                       (*names)[i] = NULL;
-                       (*domains)[i] = NULL;
-                       (*types)[i] = SID_NAME_UNKNOWN;
-               }
-       }
-
- done:
-
-       return result;
-}
-
 /** Lookup a list of names */
 
 NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
@@ -466,7 +359,7 @@ NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
                                 const char ***dom_names,
                                 int level,
                                 DOM_SID **sids,
-                                enum lsa_SidType **types)
+                                uint32 **types)
 {
        prs_struct qbuf, rbuf;
        LSA_Q_LOOKUP_NAMES q;
@@ -514,7 +407,7 @@ NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
                        goto done;
                }
 
-               if (!((*types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_names)))) {
+               if (!((*types = TALLOC_ARRAY(mem_ctx, uint32, num_names)))) {
                        DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
                        result = NT_STATUS_NO_MEMORY;
                        goto done;
@@ -557,7 +450,7 @@ NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
                        sid_append_rid(sid, dom_rid);
                }
 
-               (*types)[i] = (enum lsa_SidType)t_rids[i].type;
+               (*types)[i] = t_rids[i].type;
 
                if (dom_names == NULL) {
                        continue;
@@ -1482,43 +1375,43 @@ done:
 BOOL fetch_domain_sid( char *domain, char *remote_machine, DOM_SID *psid)
 {
        extern pstring global_myname;
-       struct cli_state *cli;
+       struct cli_state cli;
        NTSTATUS result;
        POLICY_HND lsa_pol;
        BOOL ret = False;
 
        ZERO_STRUCT(cli);
-       if((cli = cli_initialise()) == NULL) {
+       if(cli_initialise(&cli) == False) {
                DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n"));
                return False;
        }
 
-       if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) {
+       if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
                DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
                goto done;
        }
 
-       if (!cli_connect(cli, remote_machine, &cli->dest_ip)) {
+       if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
                DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
-machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
+machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
                goto done;
        }
 
-       if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) {
+       if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
                DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n",
                        remote_machine));
                goto done;
        }
 
-       cli->protocol = PROTOCOL_NT1;
+       cli.protocol = PROTOCOL_NT1;
 
-       if (!cli_negprot(cli)) {
+       if (!cli_negprot(&cli)) {
                DEBUG(0,("fetch_domain_sid: machine %s rejected the negotiate protocol. \
-Error was : %s.\n", remote_machine, cli_errstr(cli) ));
+Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
                goto done;
        }
 
-       if (cli->protocol != PROTOCOL_NT1) {
+       if (cli.protocol != PROTOCOL_NT1) {
                DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n",
                        remote_machine));
                goto done;
@@ -1528,39 +1421,39 @@ Error was : %s.\n", remote_machine, cli_errstr(cli) ));
         * Do an anonymous session setup.
         */
 
-       if (!cli_session_setup(cli, "", "", 0, "", 0, "")) {
+       if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
                DEBUG(0,("fetch_domain_sid: machine %s rejected the session setup. \
-Error was : %s.\n", remote_machine, cli_errstr(cli) ));
+Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
                goto done;
        }
 
-       if (!(cli->sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) {
+       if (!(cli.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) {
                DEBUG(0,("fetch_domain_sid: machine %s isn't in user level security mode\n",
                        remote_machine));
                goto done;
        }
 
-       if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
+       if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
                DEBUG(0,("fetch_domain_sid: machine %s rejected the tconX on the IPC$ share. \
-Error was : %s.\n", remote_machine, cli_errstr(cli) ));
+Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
                goto done;
        }
 
        /* Fetch domain sid */
 
-       if (!cli_nt_session_open(cli, PI_LSARPC)) {
+       if (!cli_nt_session_open(&cli, PI_LSARPC)) {
                DEBUG(0, ("fetch_domain_sid: Error connecting to SAM pipe\n"));
                goto done;
        }
 
-       result = cli_lsa_open_policy(cli, cli->mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol);
+       result = cli_lsa_open_policy(&cli, cli.mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol);
        if (!NT_STATUS_IS_OK(result)) {
                DEBUG(0, ("fetch_domain_sid: Error opening lsa policy handle. %s\n",
                        nt_errstr(result) ));
                goto done;
        }
 
-       result = cli_lsa_query_info_policy(cli, cli->mem_ctx, &lsa_pol, 5, domain, psid);
+       result = cli_lsa_query_info_policy(&cli, cli.mem_ctx, &lsa_pol, 5, domain, psid);
        if (!NT_STATUS_IS_OK(result)) {
                DEBUG(0, ("fetch_domain_sid: Error querying lsa policy handle. %s\n",
                        nt_errstr(result) ));
@@ -1571,7 +1464,7 @@ Error was : %s.\n", remote_machine, cli_errstr(cli) ));
 
   done:
 
-       cli_shutdown(cli);
+       cli_shutdown(&cli);
        return ret;
 }