Replace sid_string_static by sid_string_dbg in DEBUGs
[amitay/samba.git] / source3 / utils / net_rpc.c
index 5c5bb97bf654b8df00a02f4f705273aaeed52d61..1dd37888cdec4737d8e7ea3c5b256af797220cff 100644 (file)
@@ -24,6 +24,7 @@
 #include "utils/net.h"
 
 static int net_mode_share;
+static bool sync_files(struct copy_clistate *cp_clistate, const char *mask);
 
 /**
  * @file net_rpc.c
@@ -465,7 +466,7 @@ NTSTATUS rpc_info_internals(const DOM_SID *domain_sid,
                                         2, &ctr);
        if (NT_STATUS_IS_OK(result)) {
                TALLOC_CTX *ctx = talloc_init("rpc_info_internals");
-               d_printf("Domain Name: %s\n", unistr2_tdup(ctx, &ctr.info.inf2.uni_domain));
+               d_printf("Domain Name: %s\n", unistr2_to_ascii_talloc(ctx, &ctr.info.inf2.uni_domain));
                d_printf("Domain SID: %s\n", sid_str);
                d_printf("Sequence number: %llu\n", (unsigned long long)ctr.info.inf2.seq_num);
                d_printf("Num users: %u\n", ctr.info.inf2.num_domain_usrs);
@@ -586,7 +587,7 @@ static NTSTATUS rpc_user_add_internals(const DOM_SID *domain_sid,
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
        const char *acct_name;
        uint32 acb_info;
-       uint32 unknown, user_rid;
+       uint32 access_mask, user_rid;
 
        if (argc < 1) {
                d_printf("User must be specified\n");
@@ -616,10 +617,10 @@ static NTSTATUS rpc_user_add_internals(const DOM_SID *domain_sid,
        /* Create domain user */
 
        acb_info = ACB_NORMAL;
-       unknown = 0xe005000b; /* No idea what this is - a permission mask? */
+       access_mask = 0xe005000b;
 
        result = rpccli_samr_create_dom_user(pipe_hnd, mem_ctx, &domain_pol,
-                                         acct_name, acb_info, unknown,
+                                         acct_name, acb_info, access_mask,
                                          &user_pol, &user_rid);
        if (!NT_STATUS_IS_OK(result)) {
                goto done;
@@ -2563,7 +2564,7 @@ static NTSTATUS rpc_group_list_internals(const DOM_SID *domain_sid,
                                                                               &ctr))) &&
                                    (NT_STATUS_IS_OK(rpccli_samr_close(pipe_hnd, mem_ctx,
                                                                    &alias_pol)))) {
-                                       description = unistr2_tdup(mem_ctx,
+                                       description = unistr2_to_ascii_talloc(mem_ctx,
                                                                   ctr.alias.info3.description.string);
                                }
                        }
@@ -2618,7 +2619,7 @@ static NTSTATUS rpc_group_list_internals(const DOM_SID *domain_sid,
                                                                               &ctr))) &&
                                    (NT_STATUS_IS_OK(rpccli_samr_close(pipe_hnd, mem_ctx,
                                                                    &alias_pol)))) {
-                                       description = unistr2_tdup(mem_ctx,
+                                       description = unistr2_to_ascii_talloc(mem_ctx,
                                                                   ctr.alias.info3.description.string);
                                }
                        }
@@ -3181,11 +3182,11 @@ static WERROR get_share_info(struct rpc_pipe_client *pipe_hnd,
 
                /* Duplicate strings */
 
-               s = unistr2_tdup(mem_ctx, &info.share.info1.info_1_str.uni_netname);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info1.info_1_str.uni_netname);
                if (s)
                        init_unistr2(&info1->info_1_str.uni_netname, s, UNI_STR_TERMINATE);
 
-               s = unistr2_tdup(mem_ctx, &info.share.info1.info_1_str.uni_remark);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info1.info_1_str.uni_remark);
                if (s)
                        init_unistr2(&info1->info_1_str.uni_remark, s, UNI_STR_TERMINATE);
        }
@@ -3209,19 +3210,19 @@ static WERROR get_share_info(struct rpc_pipe_client *pipe_hnd,
 
                /* Duplicate strings */
 
-               s = unistr2_tdup(mem_ctx, &info.share.info2.info_2_str.uni_netname);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info2.info_2_str.uni_netname);
                if (s)
                        init_unistr2(&info2->info_2_str.uni_netname, s, UNI_STR_TERMINATE);
 
-               s = unistr2_tdup(mem_ctx, &info.share.info2.info_2_str.uni_remark);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info2.info_2_str.uni_remark);
                if (s)
                        init_unistr2(&info2->info_2_str.uni_remark, s, UNI_STR_TERMINATE);
 
-               s = unistr2_tdup(mem_ctx, &info.share.info2.info_2_str.uni_path);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info2.info_2_str.uni_path);
                if (s)
                        init_unistr2(&info2->info_2_str.uni_path, s, UNI_STR_TERMINATE);
 
-               s = unistr2_tdup(mem_ctx, &info.share.info2.info_2_str.uni_passwd);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info2.info_2_str.uni_passwd);
                if (s)
                        init_unistr2(&info2->info_2_str.uni_passwd, s, UNI_STR_TERMINATE);
        }
@@ -3245,19 +3246,19 @@ static WERROR get_share_info(struct rpc_pipe_client *pipe_hnd,
 
                /* Duplicate strings */
 
-               s = unistr2_tdup(mem_ctx, &info.share.info502.info_502_str.uni_netname);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info502.info_502_str.uni_netname);
                if (s)
                        init_unistr2(&info502->info_502_str.uni_netname, s, UNI_STR_TERMINATE);
 
-               s = unistr2_tdup(mem_ctx, &info.share.info502.info_502_str.uni_remark);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info502.info_502_str.uni_remark);
                if (s)
                        init_unistr2(&info502->info_502_str.uni_remark, s, UNI_STR_TERMINATE);
 
-               s = unistr2_tdup(mem_ctx, &info.share.info502.info_502_str.uni_path);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info502.info_502_str.uni_path);
                if (s)
                        init_unistr2(&info502->info_502_str.uni_path, s, UNI_STR_TERMINATE);
 
-               s = unistr2_tdup(mem_ctx, &info.share.info502.info_502_str.uni_passwd);
+               s = unistr2_to_ascii_talloc(mem_ctx, &info.share.info502.info_502_str.uni_passwd);
                if (s)
                        init_unistr2(&info502->info_502_str.uni_passwd, s, UNI_STR_TERMINATE);
 
@@ -3588,14 +3589,15 @@ static void copy_fn(const char *mnt, file_info *f, const char *mask, void *state
  *
  * @return             Boolean result
  **/
-bool sync_files(struct copy_clistate *cp_clistate, pstring mask)
+static bool sync_files(struct copy_clistate *cp_clistate, const char *mask)
 {
        struct cli_state *targetcli;
-       pstring targetpath;
+       char *targetpath = NULL;
 
        DEBUG(3,("calling cli_list with mask: %s\n", mask));
 
-       if ( !cli_resolve_path( "", cp_clistate->cli_share_src, mask, &targetcli, targetpath ) ) {
+       if ( !cli_resolve_path(talloc_tos(), "", cp_clistate->cli_share_src,
+                               mask, &targetcli, &targetpath ) ) {
                d_fprintf(stderr, "cli_resolve_path %s failed with error: %s\n", 
                        mask, cli_errstr(cp_clistate->cli_share_src));
                return False;
@@ -3679,7 +3681,7 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid,
        struct copy_clistate cp_clistate;
        bool got_src_share = False;
        bool got_dst_share = False;
-       pstring mask = "\\*";
+       const char *mask = "\\*";
        char *dst = NULL;
 
        dst = SMB_STRDUP(opt_destination?opt_destination:"127.0.0.1");
@@ -4357,9 +4359,10 @@ static bool get_user_tokens(int *num_tokens, struct user_token **user_tokens)
        struct winbindd_request request;
        struct winbindd_response response;
        const char *extra_data;
-       fstring name;
+       char *name;
        int i;
        struct user_token *result;
+       TALLOC_CTX *frame = NULL;
 
        if (lp_winbind_use_default_domain() &&
            (opt_target_workgroup == NULL)) {
@@ -4372,7 +4375,7 @@ static bool get_user_tokens(int *num_tokens, struct user_token **user_tokens)
 
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
-       
+
        if (winbindd_request_response(WINBINDD_LIST_USERS, &request, &response) !=
            NSS_STATUS_SUCCESS)
                return False;
@@ -4385,7 +4388,8 @@ static bool get_user_tokens(int *num_tokens, struct user_token **user_tokens)
        extra_data = (const char *)response.extra_data.data;
        *num_tokens = 0;
 
-       while(next_token(&extra_data, name, ",", sizeof(fstring))) {
+       frame = talloc_stackframe();
+       while(next_token_talloc(frame, &extra_data, &name, ",")) {
                *num_tokens += 1;
        }
 
@@ -4393,14 +4397,14 @@ static bool get_user_tokens(int *num_tokens, struct user_token **user_tokens)
 
        if (result == NULL) {
                DEBUG(1, ("Could not malloc sid array\n"));
+               TALLOC_FREE(frame);
                return False;
        }
 
        extra_data = (const char *)response.extra_data.data;
        i=0;
 
-       while(next_token(&extra_data, name, ",", sizeof(fstring))) {
-
+       while(next_token_talloc(frame, &extra_data, &name, ",")) {
                fstring domain, user;
                char *p;
 
@@ -4423,7 +4427,7 @@ static bool get_user_tokens(int *num_tokens, struct user_token **user_tokens)
                get_user_sids(domain, user, &(result[i].token));
                i+=1;
        }
-       
+       TALLOC_FREE(frame);
        SAFE_FREE(response.extra_data.data);
 
        *user_tokens = result;
@@ -4920,7 +4924,7 @@ static NTSTATUS rpc_file_close_internals(const DOM_SID *domain_sid,
 {
        return rpccli_srvsvc_NetFileClose(pipe_hnd, mem_ctx, 
                                            pipe_hnd->cli->desthost, 
-                                           atoi(argv[0]));
+                                           atoi(argv[0]), NULL);
 }
 
 /** 
@@ -5090,7 +5094,7 @@ static NTSTATUS rpc_shutdown_abort_internals(const DOM_SID *domain_sid,
 {
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
        
-       result = rpccli_initshutdown_Abort(pipe_hnd, mem_ctx, NULL);
+       result = rpccli_initshutdown_Abort(pipe_hnd, mem_ctx, NULL, NULL);
        
        if (NT_STATUS_IS_OK(result)) {
                d_printf("\nShutdown successfully aborted\n");
@@ -5127,7 +5131,7 @@ static NTSTATUS rpc_reg_shutdown_abort_internals(const DOM_SID *domain_sid,
 {
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
        
-       result = rpccli_winreg_AbortSystemShutdown(pipe_hnd, mem_ctx, NULL);
+       result = rpccli_winreg_AbortSystemShutdown(pipe_hnd, mem_ctx, NULL, NULL);
        
        if (NT_STATUS_IS_OK(result)) {
                d_printf("\nShutdown successfully aborted\n");
@@ -5180,7 +5184,7 @@ static int rpc_shutdown_abort(int argc, const char **argv)
  * @return Normal NTSTATUS return.
  **/
 
-static NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid, 
+NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid,
                                                const char *domain_name, 
                                                struct cli_state *cli, 
                                                struct rpc_pipe_client *pipe_hnd,
@@ -5206,7 +5210,7 @@ static NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid,
 
        /* create an entry */
        result = rpccli_initshutdown_Init(pipe_hnd, mem_ctx, NULL,
-                       &msg_string, timeout, opt_force, opt_reboot);
+                       &msg_string, timeout, opt_force, opt_reboot, NULL);
 
        if (NT_STATUS_IS_OK(result)) {
                d_printf("\nShutdown of remote machine succeeded\n");
@@ -5233,7 +5237,7 @@ static NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid,
  * @return Normal NTSTATUS return.
  **/
 
-static NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid, 
+NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid,
                                                const char *domain_name, 
                                                struct cli_state *cli, 
                                                struct rpc_pipe_client *pipe_hnd,
@@ -5246,6 +5250,7 @@ static NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid,
        struct initshutdown_String msg_string;
        struct initshutdown_String_sub s;
        NTSTATUS result;
+       WERROR werr;
 
        if (opt_comment) {
                msg = opt_comment;
@@ -5259,16 +5264,16 @@ static NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid,
 
        /* create an entry */
        result = rpccli_winreg_InitiateSystemShutdown(pipe_hnd, mem_ctx, NULL,
-                       &msg_string, timeout, opt_force, opt_reboot);
+                       &msg_string, timeout, opt_force, opt_reboot, &werr);
 
        if (NT_STATUS_IS_OK(result)) {
                d_printf("\nShutdown of remote machine succeeded\n");
        } else {
                d_fprintf(stderr, "\nShutdown of remote machine failed\n");
-               if ( W_ERROR_EQUAL(ntstatus_to_werror(result),WERR_MACHINE_LOCKED) )
+               if ( W_ERROR_EQUAL(werr, WERR_MACHINE_LOCKED) )
                        d_fprintf(stderr, "\nMachine locked, use -f switch to force\n");
                else
-                       d_fprintf(stderr, "\nresult was: %s\n", nt_errstr(result));
+                       d_fprintf(stderr, "\nresult was: %s\n", dos_errstr(werr));
        }
 
        return result;
@@ -5601,6 +5606,7 @@ static int rpc_trustdom_establish(int argc, const char **argv)
        char* domain_name_pol;
        char* acct_name;
        fstring pdc_name;
+       char *dc_name;
 
        /*
         * Connect to \\server\ipc$ as 'our domain' account with password
@@ -5653,7 +5659,7 @@ static int rpc_trustdom_establish(int argc, const char **argv)
         */
 
        nt_status = connect_to_ipc_anonymous(&cli, &server_ss, (char*)pdc_name);
-       
+
        if (NT_STATUS_IS_ERR(nt_status)) {
                DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
                        domain_name, nt_errstr(nt_status)));
@@ -5663,13 +5669,14 @@ static int rpc_trustdom_establish(int argc, const char **argv)
        /*
         * Use NetServerEnum2 to make sure we're talking to a proper server
         */
-        
-       if (!cli_get_pdc_name(cli, domain_name, (char*)pdc_name)) {
+
+       if (!cli_get_pdc_name(cli, domain_name, &dc_name)) {
                DEBUG(0, ("NetServerEnum2 error: Couldn't find primary domain controller\
                         for domain %s\n", domain_name));
                cli_shutdown(cli);
                return -1;
        }
+       SAFE_FREE(dc_name);
         
        if (!(mem_ctx = talloc_init("establishing trust relationship to "
                                    "domain %s", domain_name))) {
@@ -5871,8 +5878,9 @@ static NTSTATUS vampire_trusted_domain(struct rpc_pipe_client *pipe_hnd,
        }
 
 #ifdef DEBUG_PASSWORD
-       DEBUG(100,("sucessfully vampired trusted domain [%s], sid: [%s], password: [%s]\n",  
-               trusted_dom_name, sid_string_static(&dom_sid), cleartextpwd));
+       DEBUG(100,("sucessfully vampired trusted domain [%s], sid: [%s], "
+                  "password: [%s]\n", trusted_dom_name,
+                  sid_string_dbg(&dom_sid), cleartextpwd));
 #endif
 
 done: