Replace sid_string_static by sid_string_dbg in DEBUGs
[tprouty/samba.git] / source / rpc_client / cli_samr.c
index 7a4d9fd58abbf076277362e559da75916fc42591..bf8313816cbbb90b274cfb2996cefac191576cfc 100644 (file)
@@ -8,7 +8,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
    
    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,
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    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"
 */
 
 #include "includes.h"
@@ -52,6 +51,9 @@ NTSTATUS rpccli_samr_connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *connect_pol = r.connect_pol;
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *connect_pol = r.connect_pol;
+#ifdef __INSURE__
+               connect_pol->marker = malloc(1);
+#endif
        }
 
        return result;
        }
 
        return result;
@@ -85,6 +87,9 @@ NTSTATUS rpccli_samr_connect4(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *connect_pol = r.connect_pol;
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *connect_pol = r.connect_pol;
+#ifdef __INSURE__
+               connect_pol->marker = malloc(1);
+#endif
        }
 
        return result;
        }
 
        return result;
@@ -119,6 +124,9 @@ NTSTATUS rpccli_samr_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
        /* Return output parameters */
 
        if (NT_STATUS_IS_OK(result = r.status)) {
        /* Return output parameters */
 
        if (NT_STATUS_IS_OK(result = r.status)) {
+#ifdef __INSURE__
+               SAFE_FREE(connect_pol->marker);
+#endif
                *connect_pol = r.pol;
        }
 
                *connect_pol = r.pol;
        }
 
@@ -137,7 +145,8 @@ NTSTATUS rpccli_samr_open_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ct
        SAMR_R_OPEN_DOMAIN r;
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 
        SAMR_R_OPEN_DOMAIN r;
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 
-       DEBUG(10,("cli_samr_open_domain with sid %s\n", sid_string_static(domain_sid) ));
+       DEBUG(10,("cli_samr_open_domain with sid %s\n",
+                 sid_string_dbg(domain_sid) ));
 
        ZERO_STRUCT(q);
        ZERO_STRUCT(r);
 
        ZERO_STRUCT(q);
        ZERO_STRUCT(r);
@@ -157,6 +166,9 @@ NTSTATUS rpccli_samr_open_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ct
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *domain_pol = r.domain_pol;
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *domain_pol = r.domain_pol;
+#ifdef __INSURE__
+               domain_pol->marker = malloc(1);
+#endif
        }
 
        return result;
        }
 
        return result;
@@ -192,6 +204,9 @@ NTSTATUS rpccli_samr_open_user(struct rpc_pipe_client *cli,
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *user_pol = r.user_pol;
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *user_pol = r.user_pol;
+#ifdef __INSURE__
+               user_pol->marker = malloc(1);
+#endif
        }
 
        return result;
        }
 
        return result;
@@ -229,6 +244,9 @@ NTSTATUS rpccli_samr_open_group(struct rpc_pipe_client *cli,
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *group_pol = r.pol;
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *group_pol = r.pol;
+#ifdef __INSURE__
+               group_pol->marker = malloc(1);
+#endif
        }
 
        return result;
        }
 
        return result;
@@ -536,10 +554,14 @@ NTSTATUS rpccli_samr_query_useraliases(struct rpc_pipe_client *cli,
        ZERO_STRUCT(q);
        ZERO_STRUCT(r);
 
        ZERO_STRUCT(q);
        ZERO_STRUCT(r);
 
-       sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
-       if (sid_ptrs == NULL)
-               return NT_STATUS_NO_MEMORY;
-
+       if (num_sids) {
+               sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
+               if (sid_ptrs == NULL)
+                       return NT_STATUS_NO_MEMORY;
+       } else {
+               sid_ptrs = NULL;
+       }
+       
        for (i=0; i<num_sids; i++)
                sid_ptrs[i] = 1;
 
        for (i=0; i<num_sids; i++)
                sid_ptrs[i] = 1;
 
@@ -680,7 +702,7 @@ NTSTATUS rpccli_samr_enum_dom_users(struct rpc_pipe_client *cli, TALLOC_CTX *mem
                        fstring conv_buf;
                        
                        (*rids)[i] = r.sam[i].rid;
                        fstring conv_buf;
                        
                        (*rids)[i] = r.sam[i].rid;
-                       unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1);
+                       unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf));
                        (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
                }
        }
                        (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
                }
        }
@@ -748,7 +770,7 @@ NTSTATUS rpccli_samr_enum_dom_groups(struct rpc_pipe_client *cli,
                if (r.sam[i].hdr_name.buffer) {
                        unistr2_to_ascii((*dom_groups)[i].acct_name,
                                         &r.uni_grp_name[name_idx],
                if (r.sam[i].hdr_name.buffer) {
                        unistr2_to_ascii((*dom_groups)[i].acct_name,
                                         &r.uni_grp_name[name_idx],
-                                        sizeof(fstring) - 1);
+                                        sizeof((*dom_groups)[i].acct_name));
                        name_idx++;
                }
 
                        name_idx++;
                }
 
@@ -819,7 +841,7 @@ NTSTATUS rpccli_samr_enum_als_groups(struct rpc_pipe_client *cli,
                if (r.sam[i].hdr_name.buffer) {
                        unistr2_to_ascii((*dom_aliases)[i].acct_name,
                                         &r.uni_grp_name[name_idx],
                if (r.sam[i].hdr_name.buffer) {
                        unistr2_to_ascii((*dom_aliases)[i].acct_name,
                                         &r.uni_grp_name[name_idx],
-                                        sizeof(fstring) - 1);
+                                        sizeof((*dom_aliases)[i].acct_name));
                        name_idx++;
                }
 
                        name_idx++;
                }
 
@@ -918,6 +940,9 @@ NTSTATUS rpccli_samr_open_alias(struct rpc_pipe_client *cli,
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *alias_pol = r.pol;
 
        if (NT_STATUS_IS_OK(result = r.status)) {
                *alias_pol = r.pol;
+#ifdef __INSURE__
+               alias_pol->marker = malloc(1);
+#endif
        }
 
        return result;
        }
 
        return result;
@@ -1267,28 +1292,24 @@ NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli,
        return result;
 }
 
        return result;
 }
 
-/* User change passwd with auth crap */
+/* User change password given blobs */
 
 NTSTATUS rpccli_samr_chng_pswd_auth_crap(struct rpc_pipe_client *cli,
 
 NTSTATUS rpccli_samr_chng_pswd_auth_crap(struct rpc_pipe_client *cli,
-                                        TALLOC_CTX *mem_ctx, 
-                                        const char *username, 
-                                        DATA_BLOB new_nt_password,
-                                        DATA_BLOB old_nt_hash_enc,
-                                        DATA_BLOB new_lm_password,
-                                        DATA_BLOB old_lm_hash_enc)
+                                   TALLOC_CTX *mem_ctx, 
+                                   const char *username, 
+                                   DATA_BLOB new_nt_password,
+                                   DATA_BLOB old_nt_hash_enc,
+                                   DATA_BLOB new_lm_password,
+                                   DATA_BLOB old_lm_hash_enc)
 {
        prs_struct qbuf, rbuf;
        SAMR_Q_CHGPASSWD_USER q;
        SAMR_R_CHGPASSWD_USER r;
 {
        prs_struct qbuf, rbuf;
        SAMR_Q_CHGPASSWD_USER q;
        SAMR_R_CHGPASSWD_USER r;
-       char *srv_name_slash;
+       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 
 
-       if (!(srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s",
-                                              cli->cli->desthost))) {
-               return NT_STATUS_NO_MEMORY;
-       }
+       char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost);
 
 
-       DEBUG(5,("rpccli_samr_chng_pswd_auth_crap on server: %s\n",
-                srv_name_slash));
+       DEBUG(10,("rpccli_samr_chng_pswd_auth_crap\n"));
 
        ZERO_STRUCT(q);
        ZERO_STRUCT(r);
 
        ZERO_STRUCT(q);
        ZERO_STRUCT(r);
@@ -1298,19 +1319,28 @@ NTSTATUS rpccli_samr_chng_pswd_auth_crap(struct rpc_pipe_client *cli,
        init_samr_q_chgpasswd_user(&q, srv_name_slash, username, 
                                   new_nt_password.data, 
                                   old_nt_hash_enc.data, 
        init_samr_q_chgpasswd_user(&q, srv_name_slash, username, 
                                   new_nt_password.data, 
                                   old_nt_hash_enc.data, 
-                                  new_lm_password.data, 
+                                  new_lm_password.data,
                                   old_lm_hash_enc.data);
 
        CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
                                   old_lm_hash_enc.data);
 
        CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER,
-                  q, r,
-                  qbuf, rbuf,
-                  samr_io_q_chgpasswd_user,
-                  samr_io_r_chgpasswd_user,
-                  NT_STATUS_UNSUCCESSFUL);
+               q, r,
+               qbuf, rbuf,
+               samr_io_q_chgpasswd_user,
+               samr_io_r_chgpasswd_user,
+               NT_STATUS_UNSUCCESSFUL); 
 
 
-       return r.status;
+       /* Return output parameters */
+
+       if (!NT_STATUS_IS_OK(result = r.status)) {
+               goto done;
+       }
+
+ done:
+
+       return result;
 }
 
 }
 
+
 /* change password 3 */
 
 NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli,
 /* change password 3 */
 
 NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli,
@@ -1459,59 +1489,7 @@ NTSTATUS rpccli_samr_query_dispinfo(struct rpc_pipe_client *cli,
 
        /* Return output parameters */
 
 
        /* Return output parameters */
 
-       result = r.status;
-
-       if (!NT_STATUS_IS_OK(result) &&
-           NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
-               goto done;
-       }
-
-       *num_entries = r.num_entries;
-       *start_idx += r.num_entries;  /* No next_idx in this structure! */
-
- done:
-       return result;
-}
-
-
-/* Query display info2 */
-
-NTSTATUS rpccli_samr_query_dispinfo2(struct rpc_pipe_client *cli,
-                                    TALLOC_CTX *mem_ctx, 
-                                    POLICY_HND *domain_pol, uint32 *start_idx,
-                                    uint16 switch_value, uint32 *num_entries,
-                                    uint32 max_entries, uint32 max_size,
-                                    SAM_DISPINFO_CTR *ctr)
-{
-       prs_struct qbuf, rbuf;
-       SAMR_Q_QUERY_DISPINFO q;
-       SAMR_R_QUERY_DISPINFO r;
-       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
-       DEBUG(10,("cli_samr_query_dispinfo2 for start_idx = %u\n", *start_idx));
-
-       ZERO_STRUCT(q);
-       ZERO_STRUCT(r);
-
-       *num_entries = 0;
-
-       /* Marshall data and send request */
-
-       init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
-                                  *start_idx, max_entries, max_size);
-
-       r.ctr = ctr;
-
-       CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO2,
-               q, r,
-               qbuf, rbuf,
-               samr_io_q_query_dispinfo,
-               samr_io_r_query_dispinfo,
-               NT_STATUS_UNSUCCESSFUL); 
-
-       /* Return output parameters */
-
-       result = r.status;
+        result = r.status;
 
        if (!NT_STATUS_IS_OK(result) &&
            NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
 
        if (!NT_STATUS_IS_OK(result) &&
            NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
@@ -1525,142 +1503,6 @@ NTSTATUS rpccli_samr_query_dispinfo2(struct rpc_pipe_client *cli,
        return result;
 }
 
        return result;
 }
 
-/* Query display info */
-
-NTSTATUS rpccli_samr_query_dispinfo3(struct rpc_pipe_client *cli,
-                                    TALLOC_CTX *mem_ctx, 
-                                    POLICY_HND *domain_pol, uint32 *start_idx,
-                                    uint16 switch_value, uint32 *num_entries,
-                                    uint32 max_entries, uint32 max_size,
-                                    SAM_DISPINFO_CTR *ctr)
-{
-       prs_struct qbuf, rbuf;
-       SAMR_Q_QUERY_DISPINFO q;
-       SAMR_R_QUERY_DISPINFO r;
-       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
-       DEBUG(10,("cli_samr_query_dispinfo3 for start_idx = %u\n", *start_idx));
-
-       ZERO_STRUCT(q);
-       ZERO_STRUCT(r);
-
-       *num_entries = 0;
-
-       /* Marshall data and send request */
-
-       init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
-                                  *start_idx, max_entries, max_size);
-
-       r.ctr = ctr;
-
-       CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DISPINFO3,
-               q, r,
-               qbuf, rbuf,
-               samr_io_q_query_dispinfo,
-               samr_io_r_query_dispinfo,
-               NT_STATUS_UNSUCCESSFUL); 
-
-       /* Return output parameters */
-
-       result = r.status;
-
-       if (!NT_STATUS_IS_OK(result) &&
-           NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
-               goto done;
-       }
-
-       *num_entries = r.num_entries;
-       *start_idx += r.num_entries;  /* No next_idx in this structure! */
-
- done:
-       return result;
-}
-
-/* Query display info index */
-
-NTSTATUS rpccli_samr_get_dispenum_index(struct rpc_pipe_client *cli,
-                                       TALLOC_CTX *mem_ctx, 
-                                       POLICY_HND *domain_pol,
-                                       uint16 switch_value,
-                                       const char *name,
-                                       uint32 *idx)
-{
-       prs_struct qbuf, rbuf;
-       SAMR_Q_GET_DISPENUM_INDEX q;
-       SAMR_R_GET_DISPENUM_INDEX r;
-       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
-       DEBUG(10,("cli_samr_get_dispenum_index for name = %s\n", name));
-
-       ZERO_STRUCT(q);
-       ZERO_STRUCT(r);
-
-       /* Marshall data and send request */
-
-       init_samr_q_get_dispenum_index(&q, domain_pol, switch_value, name);
-
-       CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DISPENUM_INDEX,
-               q, r,
-               qbuf, rbuf,
-               samr_io_q_get_dispenum_index,
-               samr_io_r_get_dispenum_index,
-               NT_STATUS_UNSUCCESSFUL); 
-
-       /* Return output parameters */
-
-       *idx = 0;
-
-       result = r.status;
-
-       if (!NT_STATUS_IS_ERR(result)) {
-               *idx = r.idx;
-       }
-
-       return result;
-}
-
-NTSTATUS rpccli_samr_get_dispenum_index2(struct rpc_pipe_client *cli,
-                                        TALLOC_CTX *mem_ctx, 
-                                        POLICY_HND *domain_pol,
-                                        uint16 switch_value,
-                                        const char *name,
-                                        uint32 *idx)
-{
-       prs_struct qbuf, rbuf;
-       SAMR_Q_GET_DISPENUM_INDEX q;
-       SAMR_R_GET_DISPENUM_INDEX r;
-       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
-       DEBUG(10,("cli_samr_get_dispenum_index2 for name = %s\n", name));
-
-       ZERO_STRUCT(q);
-       ZERO_STRUCT(r);
-
-       /* Marshall data and send request */
-
-       init_samr_q_get_dispenum_index(&q, domain_pol, switch_value, name);
-
-       CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_GET_DISPENUM_INDEX2,
-               q, r,
-               qbuf, rbuf,
-               samr_io_q_get_dispenum_index,
-               samr_io_r_get_dispenum_index,
-               NT_STATUS_UNSUCCESSFUL); 
-
-       /* Return output parameters */
-
-       *idx = 0;
-
-       result = r.status;
-
-       if (!NT_STATUS_IS_ERR(result)) {
-               *idx = r.idx;
-       }
-
-       return result;
-}
-
-
 /* Lookup rids.  Note that NT4 seems to crash if more than ~1000 rids are
    looked up in one packet. */
 
 /* Lookup rids.  Note that NT4 seems to crash if more than ~1000 rids are
    looked up in one packet. */
 
@@ -1725,7 +1567,7 @@ NTSTATUS rpccli_samr_lookup_rids(struct rpc_pipe_client *cli,
        for (i = 0; i < r.num_names1; i++) {
                fstring tmp;
 
        for (i = 0; i < r.num_names1; i++) {
                fstring tmp;
 
-               unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
+               unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp));
                (*names)[i] = talloc_strdup(mem_ctx, tmp);
                (*name_types)[i] = r.type[i];
        }
                (*names)[i] = talloc_strdup(mem_ctx, tmp);
                (*name_types)[i] = r.type[i];
        }
@@ -1801,7 +1643,7 @@ NTSTATUS rpccli_samr_lookup_names(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c
 
 NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, 
                                   POLICY_HND *domain_pol, const char *acct_name,
 
 NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, 
                                   POLICY_HND *domain_pol, const char *acct_name,
-                                  uint32 acb_info, uint32 unknown, 
+                                  uint32 acb_info, uint32 access_mask,
                                   POLICY_HND *user_pol, uint32 *rid)
 {
        prs_struct qbuf, rbuf;
                                   POLICY_HND *user_pol, uint32 *rid)
 {
        prs_struct qbuf, rbuf;
@@ -1816,7 +1658,7 @@ NTSTATUS rpccli_samr_create_dom_user(struct rpc_pipe_client *cli, TALLOC_CTX *me
 
        /* Marshall data and send request */
 
 
        /* Marshall data and send request */
 
-       init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
+       init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, access_mask);
 
        CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_USER,
                q, r,
 
        CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_USER,
                q, r,