s3-net: Fix the return codes. 0 on success, -1 on failure
[mat/samba.git] / source3 / utils / net_rpc.c
index 05da68dbd18de353c1c3de183809d6a494831143..ef017ec9dc02ba6c8e50fdebd4b8330b1e1d3496 100644 (file)
@@ -351,7 +351,7 @@ static NTSTATUS rpc_oldjoin_internals(struct net_context *c,
        if (!NT_STATUS_IS_OK(result)) {
                DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
                        "error was %s\n",
-                       cli->desthost,
+                       cli_state_remote_name(cli),
                        nt_errstr(result) ));
                return result;
        }
@@ -366,7 +366,7 @@ static NTSTATUS rpc_oldjoin_internals(struct net_context *c,
                sec_channel_type = get_sec_channel_type(NULL);
        }
 
-       fstrcpy(trust_passwd, global_myname());
+       fstrcpy(trust_passwd, lp_netbios_name());
        strlower_m(trust_passwd);
 
        /*
@@ -379,7 +379,7 @@ static NTSTATUS rpc_oldjoin_internals(struct net_context *c,
        E_md4hash(trust_passwd, orig_trust_passwd_hash);
 
        result = trust_pw_change_and_store_it(pipe_hnd, mem_ctx, c->opt_target_workgroup,
-                                             global_myname(),
+                                             lp_netbios_name(),
                                              orig_trust_passwd_hash,
                                              sec_channel_type);
 
@@ -481,10 +481,10 @@ int net_rpc_join(struct net_context *c, int argc, const char **argv)
                return -1;
        }
 
-       if (strlen(global_myname()) > 15) {
+       if (strlen(lp_netbios_name()) > 15) {
                d_printf(_("Our netbios name can be at most 15 chars long, "
                           "\"%s\" is %u chars long\n"),
-                        global_myname(), (unsigned int)strlen(global_myname()));
+                        lp_netbios_name(), (unsigned int)strlen(lp_netbios_name()));
                return -1;
        }
 
@@ -1977,7 +1977,7 @@ static NTSTATUS get_sid_from_name(struct cli_state *cli,
                TALLOC_FREE(pipe_hnd);
        }
 
-       if (!NT_STATUS_IS_OK(status) && (StrnCaseCmp(name, "S-", 2) == 0)) {
+       if (!NT_STATUS_IS_OK(status) && (strncasecmp_m(name, "S-", 2) == 0)) {
 
                /* Try as S-1-5-whatever */
 
@@ -2957,7 +2957,7 @@ static NTSTATUS rpc_list_alias_members(struct net_context *c,
                return result;
        }
 
-       alias_sids = TALLOC_ZERO_ARRAY(mem_ctx, struct dom_sid, num_members);
+       alias_sids = talloc_zero_array(mem_ctx, struct dom_sid, num_members);
        if (!alias_sids) {
                d_fprintf(stderr, _("Out of memory\n"));
                TALLOC_FREE(lsa_pipe);
@@ -3431,7 +3431,7 @@ static WERROR get_share_info(struct net_context *c,
        {
                struct srvsvc_NetShareCtr1 *ctr1;
 
-               ctr1 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr1);
+               ctr1 = talloc_zero(mem_ctx, struct srvsvc_NetShareCtr1);
                W_ERROR_HAVE_NO_MEMORY(ctr1);
 
                ctr1->count = 1;
@@ -3445,7 +3445,7 @@ static WERROR get_share_info(struct net_context *c,
        {
                struct srvsvc_NetShareCtr2 *ctr2;
 
-               ctr2 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr2);
+               ctr2 = talloc_zero(mem_ctx, struct srvsvc_NetShareCtr2);
                W_ERROR_HAVE_NO_MEMORY(ctr2);
 
                ctr2->count = 1;
@@ -3459,7 +3459,7 @@ static WERROR get_share_info(struct net_context *c,
        {
                struct srvsvc_NetShareCtr502 *ctr502;
 
-               ctr502 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr502);
+               ctr502 = talloc_zero(mem_ctx, struct srvsvc_NetShareCtr502);
                W_ERROR_HAVE_NO_MEMORY(ctr502);
 
                ctr502->count = 1;
@@ -3527,7 +3527,7 @@ static bool check_share_availability(struct cli_state *cli, const char *netname)
 {
        NTSTATUS status;
 
-       status = cli_tcon_andx(cli, netname, "A:", "", 0);
+       status = cli_tree_connect(cli, netname, "A:", "", 0);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf(_("skipping   [%s]: not a file share.\n"), netname);
                return false;
@@ -3827,12 +3827,14 @@ static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask)
 
        DEBUG(3,("calling cli_list with mask: %s\n", mask));
 
-       if ( !cli_resolve_path(talloc_tos(), "", NULL, cp_clistate->cli_share_src,
-                               mask, &targetcli, &targetpath ) ) {
+       status = cli_resolve_path(talloc_tos(), "", NULL,
+                                 cp_clistate->cli_share_src,
+                                 mask, &targetcli, &targetpath);
+       if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, _("cli_resolve_path %s failed with error: "
                                    "%s\n"),
-                       mask, cli_errstr(cp_clistate->cli_share_src));
-               return cli_nt_error(cp_clistate->cli_share_src);
+                       mask, nt_errstr(status));
+               return status;
        }
 
        status = cli_list(targetcli, targetpath, cp_clistate->attribute,
@@ -3974,7 +3976,8 @@ static NTSTATUS rpc_share_migrate_files_internals(struct net_context *c,
 
                /* open share source */
                nt_status = connect_to_service(c, &cp_clistate.cli_share_src,
-                                              &cli->dest_ss, cli->desthost,
+                                              cli_state_remote_sockaddr(cli),
+                                              cli_state_remote_name(cli),
                                               info502.name, "A:");
                if (!NT_STATUS_IS_OK(nt_status))
                        goto done;
@@ -4469,7 +4472,7 @@ static NTSTATUS rpc_aliaslist_dump(struct net_context *c,
 
                for (j=0; j<alias->num_members; j++)
                        DEBUG(1, ("%s\\%s (%d); ",
-                                 domains[j] ? domains[j] : "*unknown*", 
+                                 domains[j] ? domains[j] : "*unknown*",
                                  names[j] ? names[j] : "*unknown*",types[j]));
                DEBUG(1, ("\n"));
        }
@@ -4808,7 +4811,7 @@ static bool get_user_tokens_from_file(FILE *f,
                token->token.sids = NULL;
                continue;
        }
-       
+
        return false;
 }
 
@@ -4853,15 +4856,15 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd,
                          netname));
        }
 
-       cnum = cli->cnum;
+       cnum = cli_state_get_tid(cli);
 
-       if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, netname, "A:", "", 0))) {
+       if (!NT_STATUS_IS_OK(cli_tree_connect(cli, netname, "A:", "", 0))) {
                return;
        }
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli, "\\", 0, READ_CONTROL_ACCESS, 0,
                        FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
-               root_sd = cli_query_secdesc(cli, fnum, mem_ctx);
+               cli_query_secdesc(cli, fnum, mem_ctx, &root_sd);
        }
 
        for (i=0; i<num_tokens; i++) {
@@ -4897,8 +4900,8 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd,
        if (fnum != (uint16_t)-1)
                cli_close(cli, fnum);
        cli_tdis(cli);
-       cli->cnum = cnum;
-       
+       cli_state_set_tid(cli, cnum);
+
        return;
 }
 
@@ -5059,7 +5062,7 @@ int net_usersidlist(struct net_context *c, int argc, const char **argv)
 
        if (!get_user_tokens(c, &num_tokens, &tokens)) {
                DEBUG(0, ("Could not get the user/sid list\n"));
-               return 0;
+               return -1;
        }
 
        for (i=0; i<num_tokens; i++) {
@@ -5068,7 +5071,7 @@ int net_usersidlist(struct net_context *c, int argc, const char **argv)
        }
 
        SAFE_FREE(tokens);
-       return 1;
+       return 0;
 }
 
 int net_usersidlist_usage(struct net_context *c, int argc, const char **argv)
@@ -6144,7 +6147,7 @@ static NTSTATUS rpc_trustdom_get_pdc(struct net_context *c,
        b = netr->binding_handle;
 
        status = dcerpc_netr_GetDcName(b, mem_ctx,
-                                      cli->desthost,
+                                      netr->desthost,
                                       domain_name,
                                       &buffer,
                                       &result);
@@ -6433,8 +6436,7 @@ static NTSTATUS vampire_trusted_domain(struct rpc_pipe_client *pipe_hnd,
        NTSTATUS nt_status, result;
        union lsa_TrustedDomainInfo *info = NULL;
        char *cleartextpwd = NULL;
-       uint8_t session_key[16];
-       DATA_BLOB session_key_blob;
+       DATA_BLOB session_key;
        DATA_BLOB data = data_blob_null;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
@@ -6459,13 +6461,14 @@ static NTSTATUS vampire_trusted_domain(struct rpc_pipe_client *pipe_hnd,
        data = data_blob(info->password.password->data,
                         info->password.password->length);
 
-       if (!rpccli_get_pwd_hash(pipe_hnd, session_key)) {
-               DEBUG(0, ("Could not retrieve password hash\n"));
+       nt_status = cli_get_session_key(mem_ctx, pipe_hnd, &session_key);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(nt_status)));
                goto done;
        }
 
-       session_key_blob = data_blob_const(session_key, sizeof(session_key));
-       cleartextpwd = sess_decrypt_string(mem_ctx, &data, &session_key_blob);
+       cleartextpwd = sess_decrypt_string(mem_ctx, &data, &session_key);
+       data_blob_free(&session_key);
 
        if (cleartextpwd == NULL) {
                DEBUG(0,("retrieved NULL password\n"));
@@ -6501,7 +6504,6 @@ static int rpc_trustdom_vampire(struct net_context *c, int argc,
        struct rpc_pipe_client *pipe_hnd = NULL;
        NTSTATUS nt_status, result;
        const char *domain_name = NULL;
-       struct dom_sid *queried_dom_sid;
        struct policy_handle connect_hnd;
        union lsa_PolicyInformation *info = NULL;
 
@@ -6532,11 +6534,11 @@ static int rpc_trustdom_vampire(struct net_context *c, int argc,
         * or to remote one given in command line
         */
 
-       if (StrCaseCmp(c->opt_workgroup, lp_workgroup())) {
+       if (strcasecmp_m(c->opt_workgroup, lp_workgroup())) {
                domain_name = c->opt_workgroup;
                c->opt_target_workgroup = c->opt_workgroup;
        } else {
-               fstrcpy(pdc_name, global_myname());
+               fstrcpy(pdc_name, lp_netbios_name());
                domain_name = talloc_strdup(mem_ctx, lp_workgroup());
                c->opt_target_workgroup = domain_name;
        };
@@ -6594,8 +6596,6 @@ static int rpc_trustdom_vampire(struct net_context *c, int argc,
                return -1;
        }
 
-       queried_dom_sid = info->account_domain.sid;
-
        /*
         * Keep calling LsaEnumTrustdom over opened pipe until
         * the end of enumeration is reached
@@ -6632,7 +6632,7 @@ static int rpc_trustdom_vampire(struct net_context *c, int argc,
                        print_trusted_domain(dom_list.domains[i].sid,
                                             dom_list.domains[i].name.string);
 
-                       nt_status = vampire_trusted_domain(pipe_hnd, mem_ctx, &connect_hnd, 
+                       nt_status = vampire_trusted_domain(pipe_hnd, mem_ctx, &connect_hnd,
                                                           *dom_list.domains[i].sid,
                                                           dom_list.domains[i].name.string);
                        if (!NT_STATUS_IS_OK(nt_status)) {
@@ -6712,11 +6712,11 @@ static int rpc_trustdom_list(struct net_context *c, int argc, const char **argv)
         * or to remote one given in command line
         */
 
-       if (StrCaseCmp(c->opt_workgroup, lp_workgroup())) {
+       if (strcasecmp_m(c->opt_workgroup, lp_workgroup())) {
                domain_name = c->opt_workgroup;
                c->opt_target_workgroup = c->opt_workgroup;
        } else {
-               fstrcpy(pdc_name, global_myname());
+               fstrcpy(pdc_name, lp_netbios_name());
                domain_name = talloc_strdup(mem_ctx, lp_workgroup());
                c->opt_target_workgroup = domain_name;
        };
@@ -6751,7 +6751,7 @@ static int rpc_trustdom_list(struct net_context *c, int argc, const char **argv)
                talloc_destroy(mem_ctx);
                return -1;
        };
-       
+
        /* query info level 5 to obtain sid of a domain being queried */
        nt_status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
                                               &connect_hnd,
@@ -6834,13 +6834,13 @@ static int rpc_trustdom_list(struct net_context *c, int argc, const char **argv)
                talloc_destroy(mem_ctx);
                return -1;
        };
-       
+
        TALLOC_FREE(pipe_hnd);
 
        /*
         * Listing trusting domains (stored in passdb backend, if local)
         */
-       
+
        d_printf(_("\nTrusting domains list:\n\n"));
 
        /*
@@ -7091,20 +7091,16 @@ bool net_rpc_check(struct net_context *c, unsigned flags)
        if (!net_find_server(c, NULL, flags, &server_ss, &server_name))
                return false;
 
-       if ((cli = cli_initialise()) == NULL) {
+       status = cli_connect_nb(server_name, &server_ss, 0, 0x20,
+                               lp_netbios_name(), SMB_SIGNING_DEFAULT,
+                               0, &cli);
+       if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
-
-       status = cli_connect(cli, server_name, &server_ss);
+       status = cli_negprot(cli, PROTOCOL_NT1);
        if (!NT_STATUS_IS_OK(status))
                goto done;
-       if (!attempt_netbios_session_request(&cli, global_myname(),
-                                            server_name, &server_ss))
-               goto done;
-       status = cli_negprot(cli);
-       if (!NT_STATUS_IS_OK(status))
-               goto done;
-       if (cli->protocol < PROTOCOL_NT1)
+       if (cli_state_protocol(cli) < PROTOCOL_NT1)
                goto done;
 
        ret = true;
@@ -8006,6 +8002,14 @@ int net_rpc(struct net_context *c, int argc, const char **argv)
                        N_("net rpc trust\n"
                           "    Manage trusts")
                },
+               {
+                       "conf",
+                       net_rpc_conf,
+                       NET_TRANSPORT_RPC,
+                       N_("Configure a remote samba server"),
+                       N_("net rpc conf\n"
+                          "    Configure a remote samba server")
+               },
                {NULL, NULL, 0, NULL, NULL}
        };