-/*
+/*f
Unix SMB/CIFS implementation.
dcerpc torture tests, designed to walk Samba3 code paths
it under the terms of the GNU General Public License as published by
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,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/raw/raw_proto.h"
-#include "libcli/rap/rap.h"
-#include "torture/torture.h"
#include "torture/util.h"
-#include "torture/rap/proto.h"
-#include "librpc/gen_ndr/ndr_lsa.h"
+#include "libcli/rap/rap.h"
#include "librpc/gen_ndr/ndr_lsa_c.h"
-#include "librpc/gen_ndr/ndr_samr.h"
#include "librpc/gen_ndr/ndr_samr_c.h"
-#include "librpc/gen_ndr/ndr_netlogon.h"
#include "librpc/gen_ndr/ndr_netlogon_c.h"
-#include "librpc/gen_ndr/ndr_srvsvc.h"
#include "librpc/gen_ndr/ndr_srvsvc_c.h"
-#include "librpc/gen_ndr/ndr_spoolss.h"
#include "librpc/gen_ndr/ndr_spoolss_c.h"
-#include "librpc/gen_ndr/ndr_winreg.h"
#include "librpc/gen_ndr/ndr_winreg_c.h"
-#include "librpc/gen_ndr/ndr_wkssvc.h"
#include "librpc/gen_ndr/ndr_wkssvc_c.h"
#include "lib/cmdline/popt_common.h"
-#include "librpc/rpc/dcerpc.h"
-#include "torture/rpc/rpc.h"
+#include "torture/rpc/torture_rpc.h"
#include "libcli/libcli.h"
-#include "libcli/composite/composite.h"
#include "libcli/smb_composite/smb_composite.h"
#include "libcli/auth/libcli_auth.h"
#include "../lib/crypto/crypto.h"
-#include "auth/ntlmssp/ntlmssp.h"
#include "libcli/security/security.h"
#include "param/param.h"
#include "lib/registry/registry.h"
#include "libcli/resolve/resolve.h"
+#include "torture/ndr/ndr.h"
+#include "libcli/smb2/smb2.h"
+#include "libcli/smb2/smb2_calls.h"
+#include "librpc/rpc/dcerpc.h"
+#include "librpc/rpc/dcerpc_proto.h"
/*
* This tests a RPC call using an invalid vuid
*/
-bool torture_bind_authcontext(struct torture_context *torture)
+bool torture_bind_authcontext(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx;
NTSTATUS status;
struct smbcli_session *session2;
struct smbcli_state *cli;
struct dcerpc_pipe *lsa_pipe;
+ struct dcerpc_binding_handle *lsa_handle;
struct cli_credentials *anon_creds;
struct smb_composite_sesssetup setup;
struct smbcli_options options;
mem_ctx = talloc_init("torture_bind_authcontext");
if (mem_ctx == NULL) {
- d_printf("talloc_init failed\n");
+ torture_comment(torture, "talloc_init failed\n");
return false;
}
- lp_smbcli_options(torture->lp_ctx, &options);
- lp_smbcli_session_options(torture->lp_ctx, &session_options);
+ lpcfg_smbcli_options(torture->lp_ctx, &options);
+ lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
status = smbcli_full_connection(mem_ctx, &cli,
torture_setting_string(torture, "host", NULL),
- lp_smb_ports(torture->lp_ctx),
- "IPC$", NULL,
- lp_socket_options(torture->lp_ctx),
+ lpcfg_smb_ports(torture->lp_ctx),
+ "IPC$", NULL,
+ lpcfg_socket_options(torture->lp_ctx),
cmdline_credentials,
- lp_resolve_context(torture->lp_ctx),
+ lpcfg_resolve_context(torture->lp_ctx),
torture->ev, &options, &session_options,
- lp_iconv_convenience(torture->lp_ctx),
- lp_gensec_settings(torture, torture->lp_ctx));
+ lpcfg_gensec_settings(torture, torture->lp_ctx));
if (!NT_STATUS_IS_OK(status)) {
- d_printf("smbcli_full_connection failed: %s\n",
+ torture_comment(torture, "smbcli_full_connection failed: %s\n",
nt_errstr(status));
goto done;
}
- lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx,
- lp_iconv_convenience(torture->lp_ctx));
+ lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
if (lsa_pipe == NULL) {
- d_printf("dcerpc_pipe_init failed\n");
+ torture_comment(torture, "dcerpc_pipe_init failed\n");
goto done;
}
+ lsa_handle = lsa_pipe->binding_handle;
status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
+ torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
nt_errstr(status));
goto done;
}
status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_bind_auth_none failed: %s\n",
+ torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
nt_errstr(status));
goto done;
}
openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
openpolicy.out.handle = &handle;
- status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
+ status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
+ torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
+ torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
+ nt_errstr(openpolicy.out.result));
+ goto done;
+ }
close_handle.in.handle = &handle;
close_handle.out.handle = &handle;
- status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
+ status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_lsa_Close failed: %s\n",
+ torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(close_handle.out.result)) {
+ torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
+ nt_errstr(close_handle.out.result));
+ goto done;
+ }
session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
if (session2 == NULL) {
- d_printf("smbcli_session_init failed\n");
+ torture_comment(torture, "smbcli_session_init failed\n");
goto done;
}
if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
- d_printf("create_anon_creds failed\n");
+ torture_comment(torture, "create_anon_creds failed\n");
goto done;
}
setup.in.capabilities = cli->transport->negotiate.capabilities;
setup.in.workgroup = "";
setup.in.credentials = anon_creds;
- setup.in.gensec_settings = lp_gensec_settings(torture, torture->lp_ctx);
+ setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
status = smb_composite_sesssetup(session2, &setup);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("anon session setup failed: %s\n",
+ torture_comment(torture, "anon session setup failed: %s\n",
nt_errstr(status));
goto done;
}
tmp = cli->tree->session;
cli->tree->session = session2;
- status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
+ status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
cli->tree->session = tmp;
talloc_free(lsa_pipe);
lsa_pipe = NULL;
if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
- d_printf("dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
+ torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
"expected NT_STATUS_INVALID_HANDLE\n",
nt_errstr(status));
goto done;
* Bind to lsa using a specific auth method
*/
-static bool bindtest(struct smbcli_state *cli,
+static bool bindtest(struct torture_context *tctx,
+ struct smbcli_state *cli,
struct cli_credentials *credentials,
- struct loadparm_context *lp_ctx,
uint8_t auth_type, uint8_t auth_level)
{
TALLOC_CTX *mem_ctx;
NTSTATUS status;
struct dcerpc_pipe *lsa_pipe;
+ struct dcerpc_binding_handle *lsa_handle;
struct lsa_ObjectAttribute objectattr;
struct lsa_OpenPolicy2 openpolicy;
struct lsa_QueryInfoPolicy query;
struct lsa_Close close_handle;
if ((mem_ctx = talloc_init("bindtest")) == NULL) {
- d_printf("talloc_init failed\n");
+ torture_comment(tctx, "talloc_init failed\n");
return false;
}
- lsa_pipe = dcerpc_pipe_init(mem_ctx,
- cli->transport->socket->event.ctx,
- lp_iconv_convenience(lp_ctx));
+ lsa_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
if (lsa_pipe == NULL) {
- d_printf("dcerpc_pipe_init failed\n");
+ torture_comment(tctx, "dcerpc_pipe_init failed\n");
goto done;
}
+ lsa_handle = lsa_pipe->binding_handle;
status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
+ torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
nt_errstr(status));
goto done;
}
status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
- credentials, lp_gensec_settings(lp_ctx, lp_ctx), auth_type, auth_level,
+ credentials, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
NULL);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
+ torture_comment(tctx, "dcerpc_bind_auth failed: %s\n", nt_errstr(status));
goto done;
}
openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
openpolicy.out.handle = &handle;
- status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
+ status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
+ torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
+ torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
+ nt_errstr(openpolicy.out.result));
+ goto done;
+ }
query.in.handle = &handle;
query.in.level = LSA_POLICY_INFO_DOMAIN;
query.out.info = &info;
- status = dcerpc_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx, &query);
+ status = dcerpc_lsa_QueryInfoPolicy_r(lsa_handle, mem_ctx, &query);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_lsa_QueryInfoPolicy failed: %s\n",
+ torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(query.out.result)) {
+ torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
+ nt_errstr(query.out.result));
+ goto done;
+ }
close_handle.in.handle = &handle;
close_handle.out.handle = &handle;
- status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
+ status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_lsa_Close failed: %s\n",
+ torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(close_handle.out.result)) {
+ torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
+ nt_errstr(close_handle.out.result));
+ goto done;
+ }
+
ret = true;
done:
* test authenticated RPC binds with the variants Samba3 does support
*/
-bool torture_bind_samba3(struct torture_context *torture)
+static bool torture_bind_samba3(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx;
NTSTATUS status;
mem_ctx = talloc_init("torture_bind_authcontext");
if (mem_ctx == NULL) {
- d_printf("talloc_init failed\n");
+ torture_comment(torture, "talloc_init failed\n");
return false;
}
- lp_smbcli_options(torture->lp_ctx, &options);
- lp_smbcli_session_options(torture->lp_ctx, &session_options);
+ lpcfg_smbcli_options(torture->lp_ctx, &options);
+ lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
status = smbcli_full_connection(mem_ctx, &cli,
torture_setting_string(torture, "host", NULL),
- lp_smb_ports(torture->lp_ctx),
- "IPC$", NULL,
- lp_socket_options(torture->lp_ctx),
+ lpcfg_smb_ports(torture->lp_ctx),
+ "IPC$", NULL,
+ lpcfg_socket_options(torture->lp_ctx),
cmdline_credentials,
- lp_resolve_context(torture->lp_ctx),
+ lpcfg_resolve_context(torture->lp_ctx),
torture->ev, &options, &session_options,
- lp_iconv_convenience(torture->lp_ctx),
- lp_gensec_settings(torture, torture->lp_ctx));
+ lpcfg_gensec_settings(torture, torture->lp_ctx));
if (!NT_STATUS_IS_OK(status)) {
- d_printf("smbcli_full_connection failed: %s\n",
+ torture_comment(torture, "smbcli_full_connection failed: %s\n",
nt_errstr(status));
goto done;
}
ret = true;
- ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
+ ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
DCERPC_AUTH_LEVEL_INTEGRITY);
- ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
+ ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
DCERPC_AUTH_LEVEL_PRIVACY);
- ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
+ ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
DCERPC_AUTH_LEVEL_INTEGRITY);
- ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
+ ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
DCERPC_AUTH_LEVEL_PRIVACY);
done:
* Lookup or create a user and return all necessary info
*/
-static NTSTATUS get_usr_handle(struct smbcli_state *cli,
- TALLOC_CTX *mem_ctx,
- struct loadparm_context *lp_ctx,
- struct cli_credentials *admin_creds,
- uint8_t auth_type,
- uint8_t auth_level,
- const char *username,
- char **domain,
- struct dcerpc_pipe **result_pipe,
- struct policy_handle **result_handle,
- struct dom_sid **sid_p)
+static bool get_usr_handle(struct torture_context *tctx,
+ struct smbcli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ struct cli_credentials *admin_creds,
+ uint8_t auth_type,
+ uint8_t auth_level,
+ const char *username,
+ char **domain,
+ struct dcerpc_pipe **result_pipe,
+ struct policy_handle **result_handle,
+ struct dom_sid **sid_p)
{
struct dcerpc_pipe *samr_pipe;
+ struct dcerpc_binding_handle *samr_handle;
NTSTATUS status;
struct policy_handle conn_handle;
struct policy_handle domain_handle;
struct samr_CreateUser2 c;
uint32_t user_rid,access_granted;
- samr_pipe = dcerpc_pipe_init(mem_ctx,
- cli->transport->socket->event.ctx,
- lp_iconv_convenience(lp_ctx));
- if (samr_pipe == NULL) {
- d_printf("dcerpc_pipe_init failed\n");
- status = NT_STATUS_NO_MEMORY;
- goto fail;
- }
+ samr_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
+ torture_assert(tctx, samr_pipe, "dcerpc_pipe_init failed");
- status = dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr");
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
+ samr_handle = samr_pipe->binding_handle;
+
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr"),
+ "dcerpc_pipe_open_smb failed");
if (admin_creds != NULL) {
- status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
- admin_creds, lp_gensec_settings(lp_ctx, lp_ctx), auth_type, auth_level,
- NULL);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_bind_auth failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
+ admin_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
+ NULL),
+ "dcerpc_bind_auth failed");
} else {
/* We must have an authenticated SMB connection */
- status = dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_bind_auth_none failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr),
+ "dcerpc_bind_auth_none failed");
}
conn.in.system_name = talloc_asprintf(
conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
conn.out.connect_handle = &conn_handle;
- status = dcerpc_samr_Connect2(samr_pipe, mem_ctx, &conn);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_Connect2 failed: %s\n", nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_samr_Connect2_r(samr_handle, mem_ctx, &conn),
+ "samr_Connect2 failed");
+ torture_assert_ntstatus_ok(tctx, conn.out.result,
+ "samr_Connect2 failed");
enumdom.in.connect_handle = &conn_handle;
enumdom.in.resume_handle = &resume_handle;
enumdom.out.num_entries = &num_entries;
enumdom.out.sam = &sam;
- status = dcerpc_samr_EnumDomains(samr_pipe, mem_ctx, &enumdom);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_EnumDomains failed: %s\n", nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_samr_EnumDomains_r(samr_handle, mem_ctx, &enumdom),
+ "samr_EnumDomains failed");
+ torture_assert_ntstatus_ok(tctx, enumdom.out.result,
+ "samr_EnumDomains failed");
- if (*enumdom.out.num_entries != 2) {
- d_printf("samr_EnumDomains returned %d entries, expected 2\n",
- *enumdom.out.num_entries);
- status = NT_STATUS_UNSUCCESSFUL;
- goto fail;
- }
+ torture_assert_int_equal(tctx, *enumdom.out.num_entries, 2,
+ "samr_EnumDomains returned unexpected num_entries");
dom_idx = strequal(sam->entries[0].name.string,
"builtin") ? 1:0;
l.in.domain_name = &domain_name;
l.out.sid = &sid;
- status = dcerpc_samr_LookupDomain(samr_pipe, mem_ctx, &l);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_LookupDomain failed: %s\n", nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_samr_LookupDomain_r(samr_handle, mem_ctx, &l),
+ "samr_LookupDomain failed");
+ torture_assert_ntstatus_ok(tctx, l.out.result,
+ "samr_LookupDomain failed");
o.in.connect_handle = &conn_handle;
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
o.in.sid = *l.out.sid;
o.out.domain_handle = &domain_handle;
- status = dcerpc_samr_OpenDomain(samr_pipe, mem_ctx, &o);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_OpenDomain failed: %s\n", nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_samr_OpenDomain_r(samr_handle, mem_ctx, &o),
+ "samr_OpenDomain failed");
+ torture_assert_ntstatus_ok(tctx, o.out.result,
+ "samr_OpenDomain failed");
c.in.domain_handle = &domain_handle;
user_name.string = username;
c.out.access_granted = &access_granted;
c.out.rid = &user_rid;
- status = dcerpc_samr_CreateUser2(samr_pipe, mem_ctx, &c);
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_samr_CreateUser2_r(samr_handle, mem_ctx, &c),
+ "samr_CreateUser2 failed");
- if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
+ if (NT_STATUS_EQUAL(c.out.result, NT_STATUS_USER_EXISTS)) {
struct samr_LookupNames ln;
struct samr_OpenUser ou;
struct samr_Ids rids, types;
ln.out.rids = &rids;
ln.out.types = &types;
- status = dcerpc_samr_LookupNames(samr_pipe, mem_ctx, &ln);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_LookupNames failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_samr_LookupNames_r(samr_handle, mem_ctx, &ln),
+ "samr_LookupNames failed");
+ torture_assert_ntstatus_ok(tctx, ln.out.result,
+ "samr_LookupNames failed");
ou.in.domain_handle = &domain_handle;
ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
user_rid = ou.in.rid = ln.out.rids->ids[0];
ou.out.user_handle = user_handle;
- status = dcerpc_samr_OpenUser(samr_pipe, mem_ctx, &ou);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_OpenUser failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_samr_OpenUser_r(samr_handle, mem_ctx, &ou),
+ "samr_OpenUser failed");
+ status = ou.out.result;
+ } else {
+ status = c.out.result;
}
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_CreateUser failed: %s\n", nt_errstr(status));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx, status,
+ "samr_CreateUser failed");
*result_pipe = samr_pipe;
*result_handle = user_handle;
if (sid_p != NULL) {
*sid_p = dom_sid_add_rid(mem_ctx, *l.out.sid, user_rid);
}
- return NT_STATUS_OK;
+ return true;
- fail:
- return status;
}
/*
* Create a test user
*/
-static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
- struct loadparm_context *lp_ctx,
+static bool create_user(struct torture_context *tctx,
+ TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
struct cli_credentials *admin_creds,
const char *username, const char *password,
char **domain_name,
TALLOC_CTX *tmp_ctx;
NTSTATUS status;
struct dcerpc_pipe *samr_pipe;
+ struct dcerpc_binding_handle *samr_handle;
struct policy_handle *wks_handle;
bool ret = false;
if (!(tmp_ctx = talloc_new(mem_ctx))) {
- d_printf("talloc_init failed\n");
+ torture_comment(tctx, "talloc_init failed\n");
return false;
}
- status = get_usr_handle(cli, tmp_ctx, lp_ctx, admin_creds,
- DCERPC_AUTH_TYPE_NTLMSSP,
- DCERPC_AUTH_LEVEL_INTEGRITY,
- username, domain_name, &samr_pipe, &wks_handle,
- user_sid);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("get_usr_handle failed: %s\n", nt_errstr(status));
+ ret = get_usr_handle(tctx, cli, tmp_ctx, admin_creds,
+ DCERPC_AUTH_TYPE_NTLMSSP,
+ DCERPC_AUTH_LEVEL_INTEGRITY,
+ username, domain_name, &samr_pipe, &wks_handle,
+ user_sid);
+ if (ret == false) {
+ torture_comment(tctx, "get_usr_handle failed\n");
goto done;
}
+ samr_handle = samr_pipe->binding_handle;
{
struct samr_SetUserInfo2 sui2;
status = dcerpc_fetch_session_key(samr_pipe, &session_key);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_fetch_session_key failed\n");
+ torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
goto done;
}
arcfour_crypt_blob(u_info.info23.password.data, 516,
sui2.in.info = &u_info;
sui2.in.level = 23;
- status = dcerpc_samr_SetUserInfo2(samr_pipe, tmp_ctx, &sui2);
+ status = dcerpc_samr_SetUserInfo2_r(samr_handle, tmp_ctx, &sui2);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_SetUserInfo(23) failed: %s\n",
+ torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(sui2.out.result)) {
+ torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
+ nt_errstr(sui2.out.result));
+ goto done;
+ }
u_info.info16.acct_flags = ACB_NORMAL;
sui.in.user_handle = wks_handle;
sui.in.info = &u_info;
sui.in.level = 16;
- status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_SetUserInfo(16) failed\n");
+ status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
+ if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
+ torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
goto done;
}
qui.in.level = 21;
qui.out.info = &info;
- status = dcerpc_samr_QueryUserInfo(samr_pipe, tmp_ctx, &qui);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_QueryUserInfo(21) failed\n");
+ status = dcerpc_samr_QueryUserInfo_r(samr_handle, tmp_ctx, &qui);
+ if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(qui.out.result)) {
+ torture_comment(tctx, "samr_QueryUserInfo(21) failed\n");
goto done;
}
sui.in.info = &u_info;
sui.in.level = 21;
- status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_SetUserInfo(21) failed\n");
+ status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
+ if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
+ torture_comment(tctx, "samr_SetUserInfo(21) failed\n");
goto done;
}
}
* Delete a test user
*/
-static bool delete_user(struct smbcli_state *cli,
- struct loadparm_context *lp_ctx,
+static bool delete_user(struct torture_context *tctx,
+ struct smbcli_state *cli,
struct cli_credentials *admin_creds,
const char *username)
{
NTSTATUS status;
char *dom_name;
struct dcerpc_pipe *samr_pipe;
+ struct dcerpc_binding_handle *samr_handle;
struct policy_handle *user_handle;
bool ret = false;
if ((mem_ctx = talloc_init("leave")) == NULL) {
- d_printf("talloc_init failed\n");
+ torture_comment(tctx, "talloc_init failed\n");
return false;
}
- status = get_usr_handle(cli, mem_ctx, lp_ctx, admin_creds,
- DCERPC_AUTH_TYPE_NTLMSSP,
- DCERPC_AUTH_LEVEL_INTEGRITY,
- username, &dom_name, &samr_pipe,
- &user_handle, NULL);
-
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
+ ret = get_usr_handle(tctx, cli, mem_ctx, admin_creds,
+ DCERPC_AUTH_TYPE_NTLMSSP,
+ DCERPC_AUTH_LEVEL_INTEGRITY,
+ username, &dom_name, &samr_pipe,
+ &user_handle, NULL);
+ if (ret == false) {
+ torture_comment(tctx, "get_wks_handle failed\n");
goto done;
}
+ samr_handle = samr_pipe->binding_handle;
{
struct samr_DeleteUser d;
d.in.user_handle = user_handle;
d.out.user_handle = user_handle;
- status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d);
+ status = dcerpc_samr_DeleteUser_r(samr_handle, mem_ctx, &d);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_DeleteUser failed %s\n", nt_errstr(status));
+ torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(status));
+ goto done;
+ }
+ if (!NT_STATUS_IS_OK(d.out.result)) {
+ torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(d.out.result));
goto done;
}
+
}
ret = true;
* Do a Samba3-style join
*/
-static bool join3(struct smbcli_state *cli,
- struct loadparm_context *lp_ctx,
+static bool join3(struct torture_context *tctx,
+ struct smbcli_state *cli,
bool use_level25,
struct cli_credentials *admin_creds,
struct cli_credentials *wks_creds)
NTSTATUS status;
char *dom_name;
struct dcerpc_pipe *samr_pipe;
+ struct dcerpc_binding_handle *samr_handle;
struct policy_handle *wks_handle;
bool ret = false;
NTTIME last_password_change;
if ((mem_ctx = talloc_init("join3")) == NULL) {
- d_printf("talloc_init failed\n");
+ torture_comment(tctx, "talloc_init failed\n");
return false;
}
- status = get_usr_handle(
- cli, mem_ctx, lp_ctx, admin_creds,
+ ret = get_usr_handle(
+ tctx, cli, mem_ctx, admin_creds,
DCERPC_AUTH_TYPE_NTLMSSP,
DCERPC_AUTH_LEVEL_PRIVACY,
talloc_asprintf(mem_ctx, "%s$",
cli_credentials_get_workstation(wks_creds)),
&dom_name, &samr_pipe, &wks_handle, NULL);
-
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
+ if (ret == false) {
+ torture_comment(tctx, "get_wks_handle failed\n");
goto done;
}
+ samr_handle = samr_pipe->binding_handle;
{
struct samr_QueryUserInfo q;
q.in.level = 21;
q.out.info = &info;
- status = dcerpc_samr_QueryUserInfo(samr_pipe, mem_ctx, &q);
+ status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) QueryUserInfo failed: %s\n",
- __location__, nt_errstr(status));
+ torture_warning(tctx, "QueryUserInfo failed: %s\n",
+ nt_errstr(status));
+ goto done;
+ }
+ if (!NT_STATUS_IS_OK(q.out.result)) {
+ torture_warning(tctx, "QueryUserInfo failed: %s\n",
+ nt_errstr(q.out.result));
goto done;
}
+
last_password_change = info->info21.last_password_change;
}
STR_UNICODE);
status = dcerpc_fetch_session_key(samr_pipe, &session_key);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_fetch_session_key failed: %s\n",
+ torture_comment(tctx, "dcerpc_fetch_session_key failed: %s\n",
nt_errstr(status));
goto done;
}
sui2.in.level = 25;
sui2.in.info = &u_info;
- status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
+ status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_SetUserInfo2(25) failed: %s\n",
+ torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(sui2.out.result)) {
+ torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
+ nt_errstr(sui2.out.result));
+ goto done;
+ }
} else {
struct samr_SetUserInfo2 sui2;
struct samr_SetUserInfo sui;
status = dcerpc_fetch_session_key(samr_pipe, &session_key);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_fetch_session_key failed\n");
+ torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
goto done;
}
arcfour_crypt_blob(u_info.info24.password.data, 516,
sui2.in.info = &u_info;
sui2.in.level = 24;
- status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
+ status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_SetUserInfo(24) failed: %s\n",
+ torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(sui2.out.result)) {
+ torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
+ nt_errstr(sui2.out.result));
+ goto done;
+ }
u_info.info16.acct_flags = ACB_WSTRUST;
sui.in.user_handle = wks_handle;
sui.in.info = &u_info;
sui.in.level = 16;
- status = dcerpc_samr_SetUserInfo(samr_pipe, mem_ctx, &sui);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("samr_SetUserInfo(16) failed\n");
+ status = dcerpc_samr_SetUserInfo_r(samr_handle, mem_ctx, &sui);
+ if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
+ torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
goto done;
}
}
q.in.level = 21;
q.out.info = &info;
- status = dcerpc_samr_QueryUserInfo(samr_pipe, mem_ctx, &q);
+ status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) QueryUserInfo failed: %s\n",
- __location__, nt_errstr(status));
+ torture_warning(tctx, "QueryUserInfo failed: %s\n",
+ nt_errstr(status));
+ goto done;
+ }
+ if (!NT_STATUS_IS_OK(q.out.result)) {
+ torture_warning(tctx, "QueryUserInfo failed: %s\n",
+ nt_errstr(q.out.result));
goto done;
}
if (use_level25) {
if (last_password_change
== info->info21.last_password_change) {
- d_printf("(%s) last_password_change unchanged "
+ torture_warning(tctx, "last_password_change unchanged "
"during join, level25 must change "
- "it\n", __location__);
+ "it\n");
goto done;
}
}
else {
if (last_password_change
!= info->info21.last_password_change) {
- d_printf("(%s) last_password_change changed "
+ torture_warning(tctx, "last_password_change changed "
"during join, level24 doesn't "
- "change it\n", __location__);
+ "change it\n");
goto done;
}
}
* Do a ReqChallenge/Auth2 and get the wks creds
*/
-static bool auth2(struct smbcli_state *cli,
- struct loadparm_context *lp_ctx,
+static bool auth2(struct torture_context *tctx,
+ struct smbcli_state *cli,
struct cli_credentials *wks_cred)
{
TALLOC_CTX *mem_ctx;
struct dcerpc_pipe *net_pipe;
+ struct dcerpc_binding_handle *net_handle;
bool result = false;
NTSTATUS status;
struct netr_ServerReqChallenge r;
struct netr_Credential netr_srv_creds;
uint32_t negotiate_flags;
struct netr_ServerAuthenticate2 a;
- struct creds_CredentialState *creds_state;
+ struct netlogon_creds_CredentialState *creds_state;
struct netr_Credential netr_cred;
struct samr_Password mach_pw;
mem_ctx = talloc_new(NULL);
if (mem_ctx == NULL) {
- d_printf("talloc_new failed\n");
+ torture_comment(tctx, "talloc_new failed\n");
return false;
}
- net_pipe = dcerpc_pipe_init(mem_ctx,
- cli->transport->socket->event.ctx,
- lp_iconv_convenience(lp_ctx));
+ net_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
if (net_pipe == NULL) {
- d_printf("dcerpc_pipe_init failed\n");
+ torture_comment(tctx, "dcerpc_pipe_init failed\n");
goto done;
}
+ net_handle = net_pipe->binding_handle;
status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
+ torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
nt_errstr(status));
goto done;
}
status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_bind_auth_none failed: %s\n",
+ torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n",
nt_errstr(status));
goto done;
}
r.in.server_name = talloc_asprintf(
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
if (r.in.server_name == NULL) {
- d_printf("talloc_asprintf failed\n");
+ torture_comment(tctx, "talloc_asprintf failed\n");
goto done;
}
generate_random_buffer(netr_cli_creds.data,
r.in.credentials = &netr_cli_creds;
r.out.return_credentials = &netr_srv_creds;
- status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
+ status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("netr_ServerReqChallenge failed: %s\n",
+ torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(r.out.result)) {
+ torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
+ nt_errstr(r.out.result));
+ goto done;
+ }
negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
- creds_state = talloc(mem_ctx, struct creds_CredentialState);
- creds_client_init(creds_state, r.in.credentials,
- r.out.return_credentials, &mach_pw,
- &netr_cred, negotiate_flags);
-
a.in.server_name = talloc_asprintf(
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
a.in.account_name = talloc_asprintf(
a.in.credentials = &netr_cred;
a.out.return_credentials = &netr_cred;
- status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
+ creds_state = netlogon_creds_client_init(mem_ctx,
+ a.in.account_name,
+ a.in.computer_name,
+ r.in.credentials,
+ r.out.return_credentials, &mach_pw,
+ &netr_cred, negotiate_flags);
+
+ status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("netr_ServerServerAuthenticate2 failed: %s\n",
+ torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(a.out.result)) {
+ torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
+ nt_errstr(a.out.result));
+ goto done;
+ }
- if (!creds_client_check(creds_state, a.out.return_credentials)) {
- d_printf("creds_client_check failed\n");
+ if (!netlogon_creds_client_check(creds_state, a.out.return_credentials)) {
+ torture_comment(tctx, "creds_client_check failed\n");
goto done;
}
* login, and change the wks password
*/
-static bool schan(struct smbcli_state *cli,
- struct loadparm_context *lp_ctx,
+static bool schan(struct torture_context *tctx,
+ struct smbcli_state *cli,
struct cli_credentials *wks_creds,
struct cli_credentials *user_creds)
{
NTSTATUS status;
bool ret = false;
struct dcerpc_pipe *net_pipe;
+ struct dcerpc_binding_handle *net_handle;
int i;
-
+
mem_ctx = talloc_new(NULL);
if (mem_ctx == NULL) {
- d_printf("talloc_new failed\n");
+ torture_comment(tctx, "talloc_new failed\n");
return false;
}
- net_pipe = dcerpc_pipe_init(mem_ctx,
- cli->transport->socket->event.ctx,
- lp_iconv_convenience(lp_ctx));
+ net_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
if (net_pipe == NULL) {
- d_printf("dcerpc_pipe_init failed\n");
+ torture_comment(tctx, "dcerpc_pipe_init failed\n");
goto done;
}
+ net_handle = net_pipe->binding_handle;
status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
+ torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
nt_errstr(status));
goto done;
}
#if 1
net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
- wks_creds, lp_gensec_settings(lp_ctx, lp_ctx), DCERPC_AUTH_TYPE_SCHANNEL,
+ wks_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), DCERPC_AUTH_TYPE_SCHANNEL,
DCERPC_AUTH_LEVEL_PRIVACY,
NULL);
#else
status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
#endif
if (!NT_STATUS_IS_OK(status)) {
- d_printf("schannel bind failed: %s\n", nt_errstr(status));
+ torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
goto done;
}
for (i=2; i<4; i++) {
int flags;
DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
- struct creds_CredentialState *creds_state;
+ struct netlogon_creds_CredentialState *creds_state;
struct netr_Authenticator netr_auth, netr_auth2;
struct netr_NetworkInfo ninfo;
struct netr_PasswordInfo pinfo;
chal = data_blob_talloc(mem_ctx, NULL, 8);
if (chal.data == NULL) {
- d_printf("data_blob_talloc failed\n");
+ torture_comment(tctx, "data_blob_talloc failed\n");
goto done;
}
generate_random_buffer(chal.data, chal.length);
names_blob = NTLMv2_generate_names_blob(
- mem_ctx,
+ mem_ctx,
cli_credentials_get_workstation(user_creds),
cli_credentials_get_domain(user_creds));
status = cli_credentials_get_ntlm_response(
user_creds, mem_ctx, &flags, chal, names_blob,
&lm_resp, &nt_resp, NULL, NULL);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("cli_credentials_get_ntlm_response failed:"
+ torture_comment(tctx, "cli_credentials_get_ntlm_response failed:"
" %s\n", nt_errstr(status));
goto done;
}
creds_state = cli_credentials_get_netlogon_creds(wks_creds);
- creds_client_authenticator(creds_state, &netr_auth);
+ netlogon_creds_client_authenticator(creds_state, &netr_auth);
ninfo.identity_info.account_name.string =
cli_credentials_get_username(user_creds);
r.out.authoritative = &authoritative;
r.out.return_authenticator = &return_authenticator;
- status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
+ status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("netr_LogonSamLogon failed: %s\n",
+ torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(r.out.result)) {
+ torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
+ nt_errstr(r.out.result));
+ goto done;
+ }
if ((r.out.return_authenticator == NULL) ||
- (!creds_client_check(creds_state,
+ (!netlogon_creds_client_check(creds_state,
&r.out.return_authenticator->cred))) {
- d_printf("Credentials check failed!\n");
+ torture_comment(tctx, "Credentials check failed!\n");
goto done;
}
- creds_client_authenticator(creds_state, &netr_auth);
+ netlogon_creds_client_authenticator(creds_state, &netr_auth);
pinfo.identity_info = ninfo.identity_info;
ZERO_STRUCT(pinfo.lmpassword.hash);
r.in.logon = &logon;
r.out.return_authenticator = &return_authenticator;
- status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
+ status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("netr_LogonSamLogon failed: %s\n",
+ torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(r.out.result)) {
+ torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
+ nt_errstr(r.out.result));
+ goto done;
+ }
if ((r.out.return_authenticator == NULL) ||
- (!creds_client_check(creds_state,
+ (!netlogon_creds_client_check(creds_state,
&r.out.return_authenticator->cred))) {
- d_printf("Credentials check failed!\n");
+ torture_comment(tctx, "Credentials check failed!\n");
goto done;
}
}
{
struct netr_ServerPasswordSet s;
- char *password = generate_random_str(wks_creds, 8);
- struct creds_CredentialState *creds_state;
+ char *password = generate_random_password(wks_creds, 8, 255);
+ struct netlogon_creds_CredentialState *creds_state;
struct netr_Authenticator credential, return_authenticator;
struct samr_Password new_password;
E_md4hash(password, new_password.hash);
creds_state = cli_credentials_get_netlogon_creds(wks_creds);
- creds_des_encrypt(creds_state, &new_password);
- creds_client_authenticator(creds_state, &credential);
+ netlogon_creds_des_encrypt(creds_state, &new_password);
+ netlogon_creds_client_authenticator(creds_state, &credential);
- status = dcerpc_netr_ServerPasswordSet(net_pipe, mem_ctx, &s);
+ status = dcerpc_netr_ServerPasswordSet_r(net_handle, mem_ctx, &s);
if (!NT_STATUS_IS_OK(status)) {
- printf("ServerPasswordSet - %s\n", nt_errstr(status));
+ torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(status));
+ goto done;
+ }
+ if (!NT_STATUS_IS_OK(s.out.result)) {
+ torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(s.out.result));
goto done;
}
- if (!creds_client_check(creds_state,
- &s.out.return_authenticator->cred)) {
- printf("Credential chaining failed\n");
+ if (!netlogon_creds_client_check(creds_state,
+ &s.out.return_authenticator->cred)) {
+ torture_comment(tctx, "Credential chaining failed\n");
}
cli_credentials_set_password(wks_creds, password,
* Delete the wks account again
*/
-static bool leave(struct smbcli_state *cli,
- struct loadparm_context *lp_ctx,
+static bool leave(struct torture_context *tctx,
+ struct smbcli_state *cli,
struct cli_credentials *admin_creds,
struct cli_credentials *wks_creds)
{
NULL, "%s$", cli_credentials_get_workstation(wks_creds));
bool ret;
- ret = delete_user(cli, lp_ctx, admin_creds, wks_name);
+ ret = delete_user(tctx, cli, admin_creds, wks_name);
talloc_free(wks_name);
return ret;
}
* Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
*/
-bool torture_netlogon_samba3(struct torture_context *torture)
+static bool torture_netlogon_samba3(struct torture_context *torture)
{
- TALLOC_CTX *mem_ctx;
NTSTATUS status;
- bool ret = false;
struct smbcli_state *cli;
struct cli_credentials *anon_creds;
struct cli_credentials *wks_creds;
wks_name = get_myname(torture);
}
- mem_ctx = talloc_init("torture_netlogon_samba3");
-
- if (mem_ctx == NULL) {
- d_printf("talloc_init failed\n");
- return false;
- }
-
- if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
- d_printf("create_anon_creds failed\n");
- goto done;
+ if (!(anon_creds = cli_credentials_init_anon(torture))) {
+ torture_fail(torture, "create_anon_creds failed\n");
}
- lp_smbcli_options(torture->lp_ctx, &options);
- lp_smbcli_session_options(torture->lp_ctx, &session_options);
+ lpcfg_smbcli_options(torture->lp_ctx, &options);
+ lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
- status = smbcli_full_connection(mem_ctx, &cli,
+ status = smbcli_full_connection(torture, &cli,
torture_setting_string(torture, "host", NULL),
- lp_smb_ports(torture->lp_ctx),
- "IPC$", NULL,
- lp_socket_options(torture->lp_ctx),
- anon_creds,
- lp_resolve_context(torture->lp_ctx),
+ lpcfg_smb_ports(torture->lp_ctx),
+ "IPC$", NULL,
+ lpcfg_socket_options(torture->lp_ctx),
+ anon_creds,
+ lpcfg_resolve_context(torture->lp_ctx),
torture->ev, &options, &session_options,
- lp_iconv_convenience(torture->lp_ctx),
- lp_gensec_settings(torture, torture->lp_ctx));
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("smbcli_full_connection failed: %s\n",
- nt_errstr(status));
- goto done;
- }
+ lpcfg_gensec_settings(torture, torture->lp_ctx));
+ torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
- wks_creds = cli_credentials_init(mem_ctx);
+ wks_creds = cli_credentials_init(torture);
if (wks_creds == NULL) {
- d_printf("cli_credentials_init failed\n");
- goto done;
+ torture_fail(torture, "cli_credentials_init failed\n");
}
cli_credentials_set_conf(wks_creds, torture->lp_ctx);
cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
cli_credentials_set_password(wks_creds,
- generate_random_str(wks_creds, 8),
+ generate_random_password(wks_creds, 8, 255),
CRED_SPECIFIED);
- if (!join3(cli, torture->lp_ctx, false, cmdline_credentials, wks_creds)) {
- d_printf("join failed\n");
- goto done;
- }
+ torture_assert(torture,
+ join3(torture, cli, false, cmdline_credentials, wks_creds),
+ "join failed");
cli_credentials_set_domain(
cmdline_credentials, cli_credentials_get_domain(wks_creds),
int j;
- if (!auth2(cli, torture->lp_ctx, wks_creds)) {
- d_printf("auth2 failed\n");
- goto done;
- }
+ torture_assert(torture,
+ auth2(torture, cli, wks_creds),
+ "auth2 failed");
for (j=0; j<2; j++) {
- if (!schan(cli, torture->lp_ctx, wks_creds, cmdline_credentials)) {
- d_printf("schan failed\n");
- goto done;
- }
+ torture_assert(torture,
+ schan(torture, cli, wks_creds, cmdline_credentials),
+ "schan failed");
}
}
- if (!leave(cli, torture->lp_ctx, cmdline_credentials, wks_creds)) {
- d_printf("leave failed\n");
- goto done;
- }
-
- ret = true;
+ torture_assert(torture,
+ leave(torture, cli, cmdline_credentials, wks_creds),
+ "leave failed");
- done:
- talloc_free(mem_ctx);
- return ret;
+ return true;
}
/*
const char *wks_name)
{
NTSTATUS status;
- bool ret = false;
struct smbcli_state *cli;
struct cli_credentials *wks_creds;
struct smbcli_options options;
struct smbcli_session_options session_options;
- lp_smbcli_options(tctx->lp_ctx, &options);
- lp_smbcli_session_options(tctx->lp_ctx, &session_options);
+ lpcfg_smbcli_options(tctx->lp_ctx, &options);
+ lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
status = smbcli_full_connection(tctx, &cli,
torture_setting_string(tctx, "host", NULL),
- lp_smb_ports(tctx->lp_ctx),
- "IPC$", NULL, lp_socket_options(tctx->lp_ctx),
- smb_creds, lp_resolve_context(tctx->lp_ctx),
+ lpcfg_smb_ports(tctx->lp_ctx),
+ "IPC$", NULL, lpcfg_socket_options(tctx->lp_ctx),
+ smb_creds, lpcfg_resolve_context(tctx->lp_ctx),
tctx->ev, &options, &session_options,
- lp_iconv_convenience(tctx->lp_ctx),
- lp_gensec_settings(tctx, tctx->lp_ctx));
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("smbcli_full_connection failed: %s\n",
- nt_errstr(status));
- goto done;
- }
+ lpcfg_gensec_settings(tctx, tctx->lp_ctx));
+ torture_assert_ntstatus_ok(tctx, status,
+ "smbcli_full_connection failed");
wks_creds = cli_credentials_init(cli);
- if (wks_creds == NULL) {
- d_printf("cli_credentials_init failed\n");
- goto done;
- }
+ torture_assert(tctx, wks_creds, "cli_credentials_init failed");
cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
cli_credentials_set_password(wks_creds,
- generate_random_str(wks_creds, 8),
+ generate_random_password(wks_creds, 8, 255),
CRED_SPECIFIED);
- if (!join3(cli, tctx->lp_ctx, use_level25, samr_creds, wks_creds)) {
- d_printf("join failed\n");
- goto done;
- }
+ torture_assert(tctx,
+ join3(tctx, cli, use_level25, samr_creds, wks_creds),
+ "join failed");
cli_credentials_set_domain(
cmdline_credentials, cli_credentials_get_domain(wks_creds),
CRED_SPECIFIED);
- if (!auth2(cli, tctx->lp_ctx, wks_creds)) {
- d_printf("auth2 failed\n");
- goto done;
- }
+ torture_assert(tctx,
+ auth2(tctx, cli, wks_creds),
+ "auth2 failed");
- if (!leave(cli, tctx->lp_ctx, samr_creds, wks_creds)) {
- d_printf("leave failed\n");
- goto done;
- }
+ torture_assert(tctx,
+ leave(tctx, cli, samr_creds, wks_creds),
+ "leave failed");
talloc_free(cli);
- ret = true;
-
- done:
- return ret;
+ return true;
}
/*
* session key in the setpassword routine. Test the join by doing the auth2.
*/
-bool torture_samba3_sessionkey(struct torture_context *torture)
+static bool torture_samba3_sessionkey(struct torture_context *torture)
{
- bool ret = false;
struct cli_credentials *anon_creds;
const char *wks_name;
wks_name = torture_setting_string(torture, "wksname", get_myname(torture));
if (!(anon_creds = cli_credentials_init_anon(torture))) {
- d_printf("create_anon_creds failed\n");
- goto done;
+ torture_fail(torture, "create_anon_creds failed\n");
}
cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
- ret = true;
if (!torture_setting_bool(torture, "samba3", false)) {
* to fix :-) */
if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
- d_printf("join using anonymous bind on an anonymous smb "
+ torture_fail(torture, "join using anonymous bind on an anonymous smb "
"connection succeeded -- HUH??\n");
- ret = false;
}
}
- if (!test_join3(torture, false, anon_creds, cmdline_credentials,
- wks_name)) {
- d_printf("join using ntlmssp bind on an anonymous smb "
- "connection failed\n");
- ret = false;
- }
+ torture_assert(torture,
+ test_join3(torture, false, anon_creds, cmdline_credentials, wks_name),
+ "join using ntlmssp bind on an anonymous smb connection failed");
- if (!test_join3(torture, false, cmdline_credentials, NULL, wks_name)) {
- d_printf("join using anonymous bind on an authenticated smb "
- "connection failed\n");
- ret = false;
- }
+ torture_assert(torture,
+ test_join3(torture, false, cmdline_credentials, NULL, wks_name),
+ "join using anonymous bind on an authenticated smb connection failed");
- if (!test_join3(torture, false, cmdline_credentials,
- cmdline_credentials,
- wks_name)) {
- d_printf("join using ntlmssp bind on an authenticated smb "
- "connection failed\n");
- ret = false;
- }
+ torture_assert(torture,
+ test_join3(torture, false, cmdline_credentials, cmdline_credentials, wks_name),
+ "join using ntlmssp bind on an authenticated smb connection failed");
/*
* The following two are tests for setuserinfolevel 25
*/
- if (!test_join3(torture, true, anon_creds, cmdline_credentials,
- wks_name)) {
- d_printf("join using ntlmssp bind on an anonymous smb "
- "connection failed\n");
- ret = false;
- }
-
- if (!test_join3(torture, true, cmdline_credentials, NULL, wks_name)) {
- d_printf("join using anonymous bind on an authenticated smb "
- "connection failed\n");
- ret = false;
- }
+ torture_assert(torture,
+ test_join3(torture, true, anon_creds, cmdline_credentials, wks_name),
+ "join using ntlmssp bind on an anonymous smb connection failed");
- done:
+ torture_assert(torture,
+ test_join3(torture, true, cmdline_credentials, NULL, wks_name),
+ "join using anonymous bind on an authenticated smb connection failed");
- return ret;
+ return true;
}
/*
* open pipe and bind, given an IPC$ context
*/
-static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
- struct loadparm_context *lp_ctx,
+static NTSTATUS pipe_bind_smb(struct torture_context *tctx,
+ TALLOC_CTX *mem_ctx,
struct smbcli_tree *tree,
const char *pipe_name,
const struct ndr_interface_table *iface,
struct dcerpc_pipe *result;
NTSTATUS status;
- if (!(result = dcerpc_pipe_init(
- mem_ctx, tree->session->transport->socket->event.ctx,
- lp_iconv_convenience(lp_ctx)))) {
+ if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) {
return NT_STATUS_NO_MEMORY;
}
status = dcerpc_pipe_open_smb(result, tree, pipe_name);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
+ torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
nt_errstr(status));
talloc_free(result);
return status;
status = dcerpc_bind_auth_none(result, iface);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("schannel bind failed: %s\n", nt_errstr(status));
+ torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
talloc_free(result);
return status;
}
* Sane wrapper around lsa_LookupNames
*/
-static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
+static struct dom_sid *name2sid(struct torture_context *tctx,
+ TALLOC_CTX *mem_ctx,
struct dcerpc_pipe *p,
const char *name,
const char *domain)
uint32_t count = 0;
struct dom_sid *result;
TALLOC_CTX *tmp_ctx;
+ struct dcerpc_binding_handle *b = p->binding_handle;
if (!(tmp_ctx = talloc_new(mem_ctx))) {
return NULL;
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
r.out.handle = &handle;
- status = dcerpc_lsa_OpenPolicy2(p, tmp_ctx, &r);
+ status = dcerpc_lsa_OpenPolicy2_r(b, tmp_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
+ torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(status));
+ talloc_free(tmp_ctx);
+ return NULL;
+ }
+ if (!NT_STATUS_IS_OK(r.out.result)) {
+ torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(r.out.result));
talloc_free(tmp_ctx);
return NULL;
}
l.out.sids = &sids;
l.out.domains = &domains;
- status = dcerpc_lsa_LookupNames(p, tmp_ctx, &l);
+ status = dcerpc_lsa_LookupNames_r(b, tmp_ctx, &l);
if (!NT_STATUS_IS_OK(status)) {
- printf("LookupNames of %s failed - %s\n", lsa_name.string,
+ torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
nt_errstr(status));
talloc_free(tmp_ctx);
return NULL;
}
+ if (!NT_STATUS_IS_OK(l.out.result)) {
+ torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
+ nt_errstr(l.out.result));
+ talloc_free(tmp_ctx);
+ return NULL;
+ }
result = dom_sid_add_rid(mem_ctx, domains->domains[0].sid,
l.out.sids->sids[0].rid);
c.in.handle = &handle;
c.out.handle = &handle;
- status = dcerpc_lsa_Close(p, tmp_ctx, &c);
+ status = dcerpc_lsa_Close_r(b, tmp_ctx, &c);
if (!NT_STATUS_IS_OK(status)) {
- printf("dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
+ torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
+ talloc_free(tmp_ctx);
+ return NULL;
+ }
+ if (!NT_STATUS_IS_OK(c.out.result)) {
+ torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c.out.result));
talloc_free(tmp_ctx);
return NULL;
}
-
+
talloc_free(tmp_ctx);
return result;
}
* Find out the user SID on this connection
*/
-static struct dom_sid *whoami(TALLOC_CTX *mem_ctx,
- struct loadparm_context *lp_ctx,
+static struct dom_sid *whoami(struct torture_context *tctx,
+ TALLOC_CTX *mem_ctx,
struct smbcli_tree *tree)
{
struct dcerpc_pipe *lsa;
+ struct dcerpc_binding_handle *lsa_handle;
struct lsa_GetUserName r;
NTSTATUS status;
struct lsa_String *authority_name_p = NULL;
struct lsa_String *account_name_p = NULL;
struct dom_sid *result;
- status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\lsarpc",
+ status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\lsarpc",
&ndr_table_lsarpc, &lsa);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) Could not bind to LSA: %s\n",
- __location__, nt_errstr(status));
+ torture_warning(tctx, "Could not bind to LSA: %s\n",
+ nt_errstr(status));
return NULL;
}
+ lsa_handle = lsa->binding_handle;
r.in.system_name = "\\";
r.in.account_name = &account_name_p;
r.in.authority_name = &authority_name_p;
r.out.account_name = &account_name_p;
- status = dcerpc_lsa_GetUserName(lsa, mem_ctx, &r);
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
authority_name_p = *r.out.authority_name;
if (!NT_STATUS_IS_OK(status)) {
- printf("(%s) GetUserName failed - %s\n",
- __location__, nt_errstr(status));
+ torture_warning(tctx, "GetUserName failed - %s\n",
+ nt_errstr(status));
+ talloc_free(lsa);
+ return NULL;
+ }
+ if (!NT_STATUS_IS_OK(r.out.result)) {
+ torture_warning(tctx, "GetUserName failed - %s\n",
+ nt_errstr(r.out.result));
talloc_free(lsa);
return NULL;
}
- result = name2sid(mem_ctx, lsa, account_name_p->string,
+ result = name2sid(tctx, mem_ctx, lsa, account_name_p->string,
authority_name_p->string);
talloc_free(lsa);
* Do a tcon, given a session
*/
-NTSTATUS secondary_tcon(TALLOC_CTX *mem_ctx,
- struct smbcli_session *session,
- const char *sharename,
- struct smbcli_tree **res)
+static NTSTATUS secondary_tcon(struct torture_context *tctx,
+ TALLOC_CTX *mem_ctx,
+ struct smbcli_session *session,
+ const char *sharename,
+ struct smbcli_tree **res)
{
struct smbcli_tree *result;
TALLOC_CTX *tmp_ctx;
status = smb_raw_tcon(result, tmp_ctx, &tcon);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) smb_raw_tcon failed: %s\n", __location__,
+ torture_warning(tctx, "smb_raw_tcon failed: %s\n",
nt_errstr(status));
talloc_free(tmp_ctx);
return status;
* Test the getusername behaviour
*/
-bool torture_samba3_rpc_getusername(struct torture_context *torture)
+static bool torture_samba3_rpc_getusername(struct torture_context *torture)
{
NTSTATUS status;
struct smbcli_state *cli;
- TALLOC_CTX *mem_ctx;
bool ret = true;
struct dom_sid *user_sid;
struct dom_sid *created_sid;
struct smbcli_options options;
struct smbcli_session_options session_options;
- if (!(mem_ctx = talloc_new(torture))) {
- return false;
- }
-
- lp_smbcli_options(torture->lp_ctx, &options);
- lp_smbcli_session_options(torture->lp_ctx, &session_options);
+ lpcfg_smbcli_options(torture->lp_ctx, &options);
+ lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
status = smbcli_full_connection(
- mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
- lp_smb_ports(torture->lp_ctx),
- "IPC$", NULL, lp_socket_options(torture->lp_ctx), cmdline_credentials,
- lp_resolve_context(torture->lp_ctx),
- torture->ev, &options, &session_options,
- lp_iconv_convenience(torture->lp_ctx),
- lp_gensec_settings(torture, torture->lp_ctx));
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) smbcli_full_connection failed: %s\n",
- __location__, nt_errstr(status));
- ret = false;
- goto done;
- }
+ torture, &cli, torture_setting_string(torture, "host", NULL),
+ lpcfg_smb_ports(torture->lp_ctx),
+ "IPC$", NULL, lpcfg_socket_options(torture->lp_ctx), cmdline_credentials,
+ lpcfg_resolve_context(torture->lp_ctx), torture->ev, &options,
+ &session_options, lpcfg_gensec_settings(torture, torture->lp_ctx));
+ torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
- if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
- d_printf("(%s) whoami on auth'ed connection failed\n",
- __location__);
- ret = false;
+ if (!(user_sid = whoami(torture, torture, cli->tree))) {
+ torture_fail(torture, "whoami on auth'ed connection failed\n");
}
talloc_free(cli);
- if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
- d_printf("(%s) create_anon_creds failed\n", __location__);
- ret = false;
- goto done;
+ if (!(anon_creds = cli_credentials_init_anon(torture))) {
+ torture_fail(torture, "create_anon_creds failed\n");
}
status = smbcli_full_connection(
- mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
- lp_smb_ports(torture->lp_ctx), "IPC$", NULL,
- lp_socket_options(torture->lp_ctx), anon_creds,
- lp_resolve_context(torture->lp_ctx),
+ torture, &cli, torture_setting_string(torture, "host", NULL),
+ lpcfg_smb_ports(torture->lp_ctx), "IPC$", NULL,
+ lpcfg_socket_options(torture->lp_ctx), anon_creds,
+ lpcfg_resolve_context(torture->lp_ctx),
torture->ev, &options, &session_options,
- lp_iconv_convenience(torture->lp_ctx),
- lp_gensec_settings(torture, torture->lp_ctx));
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) anon smbcli_full_connection failed: %s\n",
- __location__, nt_errstr(status));
- ret = false;
- goto done;
- }
+ lpcfg_gensec_settings(torture, torture->lp_ctx));
+ torture_assert_ntstatus_ok(torture, status, "anon smbcli_full_connection failed\n");
- if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
- d_printf("(%s) whoami on anon connection failed\n",
- __location__);
- ret = false;
- goto done;
+ if (!(user_sid = whoami(torture, torture, cli->tree))) {
+ torture_fail(torture, "whoami on anon connection failed\n");
}
- if (!dom_sid_equal(user_sid,
- dom_sid_parse_talloc(mem_ctx, "s-1-5-7"))) {
- d_printf("(%s) Anon lsa_GetUserName returned %s, expected "
- "S-1-5-7", __location__,
- dom_sid_string(mem_ctx, user_sid));
- ret = false;
- }
+ torture_assert_sid_equal(torture, user_sid, dom_sid_parse_talloc(torture, "s-1-5-7"),
+ "Anon lsa_GetUserName returned unexpected SID");
- if (!(user_creds = cli_credentials_init(mem_ctx))) {
- d_printf("(%s) cli_credentials_init failed\n", __location__);
- ret = false;
- goto done;
+ if (!(user_creds = cli_credentials_init(torture))) {
+ torture_fail(torture, "cli_credentials_init failed\n");
}
cli_credentials_set_conf(user_creds, torture->lp_ctx);
cli_credentials_set_username(user_creds, "torture_username",
CRED_SPECIFIED);
cli_credentials_set_password(user_creds,
- generate_random_str(user_creds, 8),
+ generate_random_password(user_creds, 8, 255),
CRED_SPECIFIED);
- if (!create_user(mem_ctx, cli, torture->lp_ctx, cmdline_credentials,
+ if (!create_user(torture, torture, cli, cmdline_credentials,
cli_credentials_get_username(user_creds),
cli_credentials_get_password(user_creds),
&domain_name, &created_sid)) {
- d_printf("(%s) create_user failed\n", __location__);
- ret = false;
- goto done;
+ torture_fail(torture, "create_user failed\n");
}
cli_credentials_set_domain(user_creds, domain_name,
struct smb_composite_sesssetup setup;
struct smbcli_tree *tree;
- session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
+ session2 = smbcli_session_init(cli->transport, torture, false, session_options);
if (session2 == NULL) {
- d_printf("(%s) smbcli_session_init failed\n",
- __location__);
- goto done;
+ torture_fail(torture, "smbcli_session_init failed\n");
}
setup.in.sesskey = cli->transport->negotiate.sesskey;
setup.in.capabilities = cli->transport->negotiate.capabilities;
setup.in.workgroup = "";
setup.in.credentials = user_creds;
- setup.in.gensec_settings = lp_gensec_settings(torture, torture->lp_ctx);
+ setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
status = smb_composite_sesssetup(session2, &setup);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) session setup with new user failed: "
- "%s\n", __location__, nt_errstr(status));
- ret = false;
- goto done;
- }
+ torture_assert_ntstatus_ok(torture, status, "session setup with new user failed");
+
session2->vuid = setup.out.vuid;
- if (!NT_STATUS_IS_OK(secondary_tcon(mem_ctx, session2,
+ if (!NT_STATUS_IS_OK(secondary_tcon(torture, torture, session2,
"IPC$", &tree))) {
- d_printf("(%s) secondary_tcon failed\n",
- __location__);
- ret = false;
- goto done;
+ torture_fail(torture, "secondary_tcon failed\n");
}
- if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, tree))) {
- d_printf("(%s) whoami on user connection failed\n",
- __location__);
+ if (!(user_sid = whoami(torture, torture, tree))) {
+ torture_fail_goto(torture, del, "whoami on user connection failed\n");
ret = false;
goto del;
}
talloc_free(tree);
}
- d_printf("Created %s, found %s\n",
- dom_sid_string(mem_ctx, created_sid),
- dom_sid_string(mem_ctx, user_sid));
+ torture_comment(torture, "Created %s, found %s\n",
+ dom_sid_string(torture, created_sid),
+ dom_sid_string(torture, user_sid));
if (!dom_sid_equal(created_sid, user_sid)) {
ret = false;
}
del:
- if (!delete_user(cli, torture->lp_ctx,
+ if (!delete_user(torture, cli,
cmdline_credentials,
cli_credentials_get_username(user_creds))) {
- d_printf("(%s) delete_user failed\n", __location__);
- ret = false;
+ torture_fail(torture, "delete_user failed\n");
}
- done:
- talloc_free(mem_ctx);
return ret;
}
-static bool test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+static bool test_NetShareGetInfo(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
const char *sharename)
{
NTSTATUS status;
uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
int i;
bool ret = true;
+ struct dcerpc_binding_handle *b = p->binding_handle;
- r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
+ r.in.server_unc = talloc_asprintf(tctx, "\\\\%s",
dcerpc_server_name(p));
r.in.share_name = sharename;
r.out.info = &info;
for (i=0;i<ARRAY_SIZE(levels);i++) {
r.in.level = levels[i];
- printf("testing NetShareGetInfo level %u on share '%s'\n",
+ torture_comment(tctx, "Testing NetShareGetInfo level %u on share '%s'\n",
r.in.level, r.in.share_name);
- status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
+ status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- printf("NetShareGetInfo level %u on share '%s' failed"
+ torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed"
" - %s\n", r.in.level, r.in.share_name,
nt_errstr(status));
ret = false;
continue;
}
if (!W_ERROR_IS_OK(r.out.result)) {
- printf("NetShareGetInfo level %u on share '%s' failed "
+ torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed "
"- %s\n", r.in.level, r.in.share_name,
win_errstr(r.out.result));
ret = false;
return ret;
}
-static bool test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+static bool test_NetShareEnum(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
const char **one_sharename)
{
NTSTATUS status;
uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
int i;
bool ret = true;
+ struct dcerpc_binding_handle *b = p->binding_handle;
ZERO_STRUCT(info_ctr);
- r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
+ r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
r.in.info_ctr = &info_ctr;
r.in.max_buffer = (uint32_t)-1;
r.in.resume_handle = NULL;
break;
}
- printf("testing NetShareEnum level %u\n", info_ctr.level);
- status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
+ torture_comment(tctx, "Testing NetShareEnum level %u\n", info_ctr.level);
+
+ status = dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- printf("NetShareEnum level %u failed - %s\n",
+ torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
info_ctr.level, nt_errstr(status));
ret = false;
continue;
}
if (!W_ERROR_IS_OK(r.out.result)) {
- printf("NetShareEnum level %u failed - %s\n",
+ torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
info_ctr.level, win_errstr(r.out.result));
continue;
}
return ret;
}
-bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
+static bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
{
struct dcerpc_pipe *p;
- TALLOC_CTX *mem_ctx;
- bool ret = true;
const char *sharename = NULL;
- struct smbcli_state *cli;
- NTSTATUS status;
-
- if (!(mem_ctx = talloc_new(torture))) {
- return false;
- }
-
- if (!(torture_open_connection_share(
- mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
- "IPC$", torture->ev))) {
- talloc_free(mem_ctx);
- return false;
- }
+ bool ret = true;
- status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree,
- "\\pipe\\srvsvc", &ndr_table_srvsvc, &p);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) could not bind to srvsvc pipe: %s\n",
- __location__, nt_errstr(status));
- ret = false;
- goto done;
- }
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &p, &ndr_table_srvsvc),
+ "failed to open srvsvc");
- ret &= test_NetShareEnum(p, mem_ctx, &sharename);
+ ret &= test_NetShareEnum(torture, p, &sharename);
if (sharename == NULL) {
- printf("did not get sharename\n");
+ torture_comment(torture, "did not get sharename\n");
} else {
- ret &= test_NetShareGetInfo(p, mem_ctx, sharename);
+ ret &= test_NetShareGetInfo(torture, p, sharename);
}
- done:
- talloc_free(mem_ctx);
return ret;
}
* NT_STATUS_NO_SAM_ACCOUNT
*/
-bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
+static bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx;
struct dcerpc_pipe *net_pipe;
+ struct dcerpc_binding_handle *net_handle;
char *wksname;
bool result = false;
NTSTATUS status;
struct netr_Credential netr_srv_creds;
uint32_t negotiate_flags;
struct netr_ServerAuthenticate2 a;
- struct creds_CredentialState *creds_state;
+ struct netlogon_creds_CredentialState *creds_state;
struct netr_Credential netr_cred;
struct samr_Password mach_pw;
struct smbcli_state *cli;
if (!(mem_ctx = talloc_new(torture))) {
- d_printf("talloc_new failed\n");
+ torture_comment(torture, "talloc_new failed\n");
return false;
}
if (!(wksname = generate_random_str_list(
mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
- d_printf("generate_random_str_list failed\n");
+ torture_comment(torture, "generate_random_str_list failed\n");
goto done;
}
mem_ctx, &cli,
torture, torture_setting_string(torture, "host", NULL),
"IPC$", torture->ev))) {
- d_printf("IPC$ connection failed\n");
+ torture_comment(torture, "IPC$ connection failed\n");
goto done;
}
- if (!(net_pipe = dcerpc_pipe_init(
- mem_ctx, cli->transport->socket->event.ctx,
- lp_iconv_convenience(torture->lp_ctx)))) {
- d_printf("dcerpc_pipe_init failed\n");
+ if (!(net_pipe = dcerpc_pipe_init(mem_ctx, torture->ev))) {
+ torture_comment(torture, "dcerpc_pipe_init failed\n");
goto done;
}
+ net_handle = net_pipe->binding_handle;
status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
+ torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
nt_errstr(status));
goto done;
}
status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_bind_auth_none failed: %s\n",
+ torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
nt_errstr(status));
goto done;
}
r.in.server_name = talloc_asprintf(
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
if (r.in.server_name == NULL) {
- d_printf("talloc_asprintf failed\n");
+ torture_comment(torture, "talloc_asprintf failed\n");
goto done;
}
generate_random_buffer(netr_cli_creds.data,
r.in.credentials = &netr_cli_creds;
r.out.return_credentials = &netr_srv_creds;
- status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
+ status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("netr_ServerReqChallenge failed: %s\n",
+ torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
nt_errstr(status));
goto done;
}
+ if (!NT_STATUS_IS_OK(r.out.result)) {
+ torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
+ nt_errstr(r.out.result));
+ goto done;
+ }
negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
E_md4hash("foobar", mach_pw.hash);
- creds_state = talloc(mem_ctx, struct creds_CredentialState);
- creds_client_init(creds_state, r.in.credentials,
- r.out.return_credentials, &mach_pw,
- &netr_cred, negotiate_flags);
-
a.in.server_name = talloc_asprintf(
mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
a.in.account_name = talloc_asprintf(
a.in.credentials = &netr_cred;
a.out.return_credentials = &netr_cred;
- status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
+ creds_state = netlogon_creds_client_init(mem_ctx,
+ a.in.account_name,
+ a.in.computer_name,
+ r.in.credentials,
+ r.out.return_credentials, &mach_pw,
+ &netr_cred, negotiate_flags);
+
- if (!NT_STATUS_EQUAL(status, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
- d_printf("dcerpc_netr_ServerAuthenticate2 returned %s, "
+ status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+ if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
+ torture_comment(torture, "dcerpc_netr_ServerAuthenticate2 returned %s, "
"expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
- nt_errstr(status));
+ nt_errstr(a.out.result));
goto done;
}
return result;
}
-static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
- struct loadparm_context *lp_ctx,
+static struct security_descriptor *get_sharesec(struct torture_context *tctx,
+ TALLOC_CTX *mem_ctx,
struct smbcli_session *sess,
const char *sharename)
{
struct smbcli_tree *tree;
TALLOC_CTX *tmp_ctx;
struct dcerpc_pipe *p;
+ struct dcerpc_binding_handle *b;
NTSTATUS status;
struct srvsvc_NetShareGetInfo r;
union srvsvc_NetShareInfo info;
struct security_descriptor *result;
if (!(tmp_ctx = talloc_new(mem_ctx))) {
- d_printf("talloc_new failed\n");
+ torture_comment(tctx, "talloc_new failed\n");
return NULL;
}
- if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
- d_printf("secondary_tcon failed\n");
+ if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
+ torture_comment(tctx, "secondary_tcon failed\n");
talloc_free(tmp_ctx);
return NULL;
}
- status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\srvsvc",
+ status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
&ndr_table_srvsvc, &p);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) could not bind to srvsvc pipe: %s\n",
- __location__, nt_errstr(status));
+ torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
+ nt_errstr(status));
talloc_free(tmp_ctx);
return NULL;
}
+ b = p->binding_handle;
#if 0
p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
r.in.level = 502;
r.out.info = &info;
- status = dcerpc_srvsvc_NetShareGetInfo(p, tmp_ctx, &r);
+ status = dcerpc_srvsvc_NetShareGetInfo_r(b, tmp_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("srvsvc_NetShareGetInfo failed: %s\n",
+ torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
nt_errstr(status));
talloc_free(tmp_ctx);
return NULL;
}
+ if (!W_ERROR_IS_OK(r.out.result)) {
+ torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
+ win_errstr(r.out.result));
+ talloc_free(tmp_ctx);
+ return NULL;
+ }
result = talloc_steal(mem_ctx, info.info502->sd_buf.sd);
talloc_free(tmp_ctx);
return result;
}
-static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
- struct loadparm_context *lp_ctx,
+static NTSTATUS set_sharesec(struct torture_context *tctx,
+ TALLOC_CTX *mem_ctx,
struct smbcli_session *sess,
const char *sharename,
struct security_descriptor *sd)
struct smbcli_tree *tree;
TALLOC_CTX *tmp_ctx;
struct dcerpc_pipe *p;
+ struct dcerpc_binding_handle *b;
NTSTATUS status;
struct sec_desc_buf i;
struct srvsvc_NetShareSetInfo r;
uint32_t error = 0;
if (!(tmp_ctx = talloc_new(mem_ctx))) {
- d_printf("talloc_new failed\n");
+ torture_comment(tctx, "talloc_new failed\n");
return NT_STATUS_NO_MEMORY;
}
- if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
- d_printf("secondary_tcon failed\n");
+ if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
+ torture_comment(tctx, "secondary_tcon failed\n");
talloc_free(tmp_ctx);
return NT_STATUS_UNSUCCESSFUL;
}
- status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\srvsvc",
+ status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
&ndr_table_srvsvc, &p);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) could not bind to srvsvc pipe: %s\n",
- __location__, nt_errstr(status));
+ torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
+ nt_errstr(status));
talloc_free(tmp_ctx);
return NT_STATUS_UNSUCCESSFUL;
}
+ b = p->binding_handle;
#if 0
p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
r.in.info = &info;
r.in.parm_error = &error;
- status = dcerpc_srvsvc_NetShareSetInfo(p, tmp_ctx, &r);
+ status = dcerpc_srvsvc_NetShareSetInfo_r(b, tmp_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("srvsvc_NetShareSetInfo failed: %s\n",
+ torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
nt_errstr(status));
}
-
+ if (!W_ERROR_IS_OK(r.out.result)) {
+ torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
+ win_errstr(r.out.result));
+ status = werror_to_ntstatus(r.out.result);
+ }
talloc_free(tmp_ctx);
return status;
}
-bool try_tcon(TALLOC_CTX *mem_ctx,
- struct loadparm_context *lp_ctx,
+bool try_tcon(struct torture_context *tctx,
+ TALLOC_CTX *mem_ctx,
struct security_descriptor *orig_sd,
struct smbcli_session *session,
const char *sharename, const struct dom_sid *user_sid,
bool ret = true;
if (!(tmp_ctx = talloc_new(mem_ctx))) {
- d_printf("talloc_new failed\n");
+ torture_comment(tctx, "talloc_new failed\n");
return false;
}
- status = secondary_tcon(tmp_ctx, session, sharename, &rmdir_tree);
+ status = secondary_tcon(tctx, tmp_ctx, session, sharename, &rmdir_tree);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("first tcon to delete dir failed\n");
+ torture_comment(tctx, "first tcon to delete dir failed\n");
talloc_free(tmp_ctx);
return false;
}
if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
&domain_sid, &rid))) {
- d_printf("dom_sid_split_rid failed\n");
+ torture_comment(tctx, "dom_sid_split_rid failed\n");
talloc_free(tmp_ctx);
return false;
}
dom_sid_string(mem_ctx, user_sid),
SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
if (sd == NULL) {
- d_printf("security_descriptor_dacl_create failed\n");
+ torture_comment(tctx, "security_descriptor_dacl_create failed\n");
talloc_free(tmp_ctx);
return false;
}
- status = set_sharesec(mem_ctx, lp_ctx, session, sharename, sd);
+ status = set_sharesec(tctx, mem_ctx, session, sharename, sd);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("custom set_sharesec failed: %s\n",
+ torture_comment(tctx, "custom set_sharesec failed: %s\n",
nt_errstr(status));
talloc_free(tmp_ctx);
return false;
}
- status = secondary_tcon(tmp_ctx, session, sharename, &tree);
+ status = secondary_tcon(tctx, tmp_ctx, session, sharename, &tree);
if (!NT_STATUS_EQUAL(status, expected_tcon)) {
- d_printf("Expected %s, got %s\n", nt_errstr(expected_tcon),
+ torture_comment(tctx, "Expected %s, got %s\n", nt_errstr(expected_tcon),
nt_errstr(status));
ret = false;
goto done;
status = smbcli_mkdir(tree, "sharesec_testdir");
if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
- d_printf("(%s) Expected %s, got %s\n", __location__,
+ torture_warning(tctx, "Expected %s, got %s\n",
nt_errstr(expected_mkdir), nt_errstr(status));
ret = false;
}
done:
smbcli_rmdir(rmdir_tree, "sharesec_testdir");
- status = set_sharesec(mem_ctx, lp_ctx, session, sharename, orig_sd);
+ status = set_sharesec(tctx, mem_ctx, session, sharename, orig_sd);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("custom set_sharesec failed: %s\n",
+ torture_comment(tctx, "custom set_sharesec failed: %s\n",
nt_errstr(status));
talloc_free(tmp_ctx);
return false;
return ret;
}
-bool torture_samba3_rpc_sharesec(struct torture_context *torture)
+static bool torture_samba3_rpc_sharesec(struct torture_context *torture)
{
- TALLOC_CTX *mem_ctx;
- bool ret = true;
struct smbcli_state *cli;
struct security_descriptor *sd;
struct dom_sid *user_sid;
- if (!(mem_ctx = talloc_new(torture))) {
- return false;
- }
-
if (!(torture_open_connection_share(
- mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
+ torture, &cli, torture, torture_setting_string(torture, "host", NULL),
"IPC$", torture->ev))) {
- d_printf("IPC$ connection failed\n");
- talloc_free(mem_ctx);
- return false;
+ torture_fail(torture, "IPC$ connection failed\n");
}
- if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
- d_printf("whoami failed\n");
- talloc_free(mem_ctx);
- return false;
+ if (!(user_sid = whoami(torture, torture, cli->tree))) {
+ torture_fail(torture, "whoami failed\n");
}
- sd = get_sharesec(mem_ctx, torture->lp_ctx, cli->session,
+ sd = get_sharesec(torture, torture, cli->session,
torture_setting_string(torture, "share", NULL));
- ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
+ torture_assert(torture, try_tcon(
+ torture, torture, sd, cli->session,
torture_setting_string(torture, "share", NULL),
- user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK);
+ user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK),
+ "failed to test tcon with 0 access_mask");
- ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
+ torture_assert(torture, try_tcon(
+ torture, torture, sd, cli->session,
torture_setting_string(torture, "share", NULL),
user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
- NT_STATUS_MEDIA_WRITE_PROTECTED);
+ NT_STATUS_MEDIA_WRITE_PROTECTED),
+ "failed to test tcon with SEC_FILE_READ_DATA access_mask");
- ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
+ torture_assert(torture, try_tcon(
+ torture, torture, sd, cli->session,
torture_setting_string(torture, "share", NULL),
- user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK);
+ user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK),
+ "failed to test tcon with SEC_FILE_ALL access_mask")
- talloc_free(mem_ctx);
- return ret;
+ return true;
}
-bool torture_samba3_rpc_lsa(struct torture_context *torture)
+static bool torture_samba3_rpc_lsa(struct torture_context *torture)
{
- TALLOC_CTX *mem_ctx;
- bool ret = true;
- struct smbcli_state *cli;
struct dcerpc_pipe *p;
+ struct dcerpc_binding_handle *b;
struct policy_handle lsa_handle;
- NTSTATUS status;
- struct dom_sid *domain_sid;
-
- if (!(mem_ctx = talloc_new(torture))) {
- return false;
- }
- if (!(torture_open_connection_share(
- mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
- "IPC$", torture->ev))) {
- d_printf("IPC$ connection failed\n");
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &p, &ndr_table_lsarpc),
+ "failed to setup lsarpc");
- status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\lsarpc",
- &ndr_table_lsarpc, &p);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
- nt_errstr(status));
- talloc_free(mem_ctx);
- return false;
- }
+ b = p->binding_handle;
{
struct lsa_ObjectAttribute attr;
struct lsa_OpenPolicy2 o;
o.in.system_name = talloc_asprintf(
- mem_ctx, "\\\\%s", dcerpc_server_name(p));
+ torture, "\\\\%s", dcerpc_server_name(p));
ZERO_STRUCT(attr);
o.in.attr = &attr;
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
o.out.handle = &lsa_handle;
- status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &o);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) dcerpc_lsa_OpenPolicy2 failed: %s\n",
- __location__, nt_errstr(status));
- talloc_free(mem_ctx);
- return false;
- }
- }
-#if 0
- p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
-#endif
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_lsa_OpenPolicy2_r(b, torture, &o),
+ "dcerpc_lsa_OpenPolicy2 failed");
+ torture_assert_ntstatus_ok(torture, o.out.result,
+ "dcerpc_lsa_OpenPolicy2 failed");
+ }
{
int i;
r.in.handle = &lsa_handle;
r.in.level = levels[i];
r.out.info = &info;
- status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) dcerpc_lsa_QueryInfoPolicy %d "
- "failed: %s\n", __location__,
- levels[i], nt_errstr(status));
- talloc_free(mem_ctx);
- return false;
- }
- if (levels[i] == 5) {
- domain_sid = info->account_domain.sid;
- }
+
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_lsa_QueryInfoPolicy_r(b, torture, &r),
+ talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
+ torture_assert_ntstatus_ok(torture, r.out.result,
+ talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
}
}
- return ret;
+ return true;
}
static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
- struct smb_iconv_convenience *iconv_convenience,
char **name)
{
struct rap_WserverGetInfo r;
NTSTATUS status;
char servername[17];
+ size_t converted_size;
r.in.level = 0;
r.in.bufsize = 0xffff;
- status = smbcli_rap_netservergetinfo(tree, iconv_convenience, mem_ctx, &r);
+ status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
memcpy(servername, r.out.info.info0.name, 16);
servername[16] = '\0';
- if (!pull_ascii_talloc(mem_ctx, name, servername, NULL)) {
+ if (!pull_ascii_talloc(mem_ctx, name, servername, &converted_size)) {
return NT_STATUS_NO_MEMORY;
}
return NT_STATUS_OK;
}
+static bool rap_get_servername(struct torture_context *tctx,
+ char **servername)
+{
+ struct smbcli_state *cli;
-static NTSTATUS find_printers(TALLOC_CTX *ctx, struct loadparm_context *lp_ctx,
- struct smbcli_tree *tree,
- const char ***printers, int *num_printers)
+ torture_assert(tctx,
+ torture_open_connection_share(tctx, &cli, tctx, torture_setting_string(tctx, "host", NULL),
+ "IPC$", tctx->ev),
+ "IPC$ connection failed");
+
+ torture_assert_ntstatus_ok(tctx,
+ get_servername(tctx, cli->tree, servername),
+ "get_servername failed");
+
+ talloc_free(cli);
+
+ return true;
+}
+
+static bool find_printers(struct torture_context *tctx,
+ struct dcerpc_pipe *p,
+ const char ***printers,
+ int *num_printers)
{
- TALLOC_CTX *mem_ctx;
- NTSTATUS status;
- struct dcerpc_pipe *p;
struct srvsvc_NetShareEnum r;
struct srvsvc_NetShareInfoCtr info_ctr;
struct srvsvc_NetShareCtr1 c1_in;
struct srvsvc_NetShareCtr1 *c1;
uint32_t totalentries = 0;
int i;
-
- mem_ctx = talloc_new(ctx);
- if (mem_ctx == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- status = pipe_bind_smb(mem_ctx, lp_ctx,
- tree, "\\srvsvc", &ndr_table_srvsvc,
- &p);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("could not bind to srvsvc pipe\n");
- talloc_free(mem_ctx);
- return status;
- }
+ struct dcerpc_binding_handle *b = p->binding_handle;
ZERO_STRUCT(c1_in);
info_ctr.level = 1;
info_ctr.ctr.ctr1 = &c1_in;
r.in.server_unc = talloc_asprintf(
- mem_ctx, "\\\\%s", dcerpc_server_name(p));
+ tctx, "\\\\%s", dcerpc_server_name(p));
r.in.info_ctr = &info_ctr;
r.in.max_buffer = (uint32_t)-1;
r.in.resume_handle = NULL;
r.out.totalentries = &totalentries;
r.out.info_ctr = &info_ctr;
- status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("NetShareEnum level %u failed - %s\n",
- info_ctr.level, nt_errstr(status));
- talloc_free(mem_ctx);
- return status;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r),
+ "NetShareEnum level 1 failed");
+ torture_assert_werr_ok(tctx, r.out.result,
+ "NetShareEnum level 1 failed");
*printers = NULL;
*num_printers = 0;
if (c1->array[i].type != STYPE_PRINTQ) {
continue;
}
- if (!add_string_to_array(ctx, c1->array[i].name,
+ if (!add_string_to_array(tctx, c1->array[i].name,
printers, num_printers)) {
- talloc_free(ctx);
- return NT_STATUS_NO_MEMORY;
+ return false;
}
}
- talloc_free(mem_ctx);
- return NT_STATUS_OK;
+ return true;
}
-static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
+static bool enumprinters(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
const char *servername, int level, int *num_printers)
{
struct spoolss_EnumPrinters r;
- NTSTATUS status;
DATA_BLOB blob;
uint32_t needed;
uint32_t count;
union spoolss_PrinterInfo *info;
r.in.flags = PRINTER_ENUM_LOCAL;
- r.in.server = talloc_asprintf(mem_ctx, "\\\\%s", servername);
+ r.in.server = talloc_asprintf(tctx, "\\\\%s", servername);
r.in.level = level;
r.in.buffer = NULL;
r.in.offered = 0;
r.out.count = &count;
r.out.info = &info;
- status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s\n",
- __location__, nt_errstr(status));
- return false;
- }
-
- if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
- d_printf("(%s) EnumPrinters unexpected return code %s, should "
- "be WERR_INSUFFICIENT_BUFFER\n", __location__,
- win_errstr(r.out.result));
- return false;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
+ "dcerpc_spoolss_EnumPrinters failed");
+ torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
+ "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
- blob = data_blob_talloc_zero(mem_ctx, needed);
+ blob = data_blob_talloc_zero(tctx, needed);
if (blob.data == NULL) {
- d_printf("(%s) data_blob_talloc failed\n", __location__);
return false;
}
r.in.buffer = &blob;
r.in.offered = needed;
- status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s, "
- "%s\n", __location__, nt_errstr(status),
- win_errstr(r.out.result));
- return false;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
+ "dcerpc_spoolss_EnumPrinters failed");
+ torture_assert_werr_ok(tctx, r.out.result,
+ "dcerpc_spoolss_EnumPrinters failed");
*num_printers = count;
return true;
}
-static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
- struct policy_handle *handle, int level,
- union spoolss_PrinterInfo **res)
+static bool getprinterinfo(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ struct policy_handle *handle, int level,
+ union spoolss_PrinterInfo **res)
{
- TALLOC_CTX *mem_ctx;
struct spoolss_GetPrinter r;
DATA_BLOB blob;
- NTSTATUS status;
uint32_t needed;
- mem_ctx = talloc_new(ctx);
- if (mem_ctx == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
r.in.handle = handle;
r.in.level = level;
r.in.buffer = NULL;
r.in.offered = 0;
r.out.needed = &needed;
- status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s\n",
- __location__, nt_errstr(status));
- talloc_free(mem_ctx);
- return status;
- }
-
- if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
- printf("GetPrinter unexpected return code %s, should "
- "be WERR_INSUFFICIENT_BUFFER\n",
- win_errstr(r.out.result));
- talloc_free(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
+ "dcerpc_spoolss_GetPrinter failed");
+ torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
+ "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
r.in.handle = handle;
r.in.level = level;
- blob = data_blob_talloc(mem_ctx, NULL, needed);
+ blob = data_blob_talloc_zero(tctx, needed);
if (blob.data == NULL) {
- talloc_free(mem_ctx);
- return NT_STATUS_NO_MEMORY;
+ return false;
}
- memset(blob.data, 0, blob.length);
r.in.buffer = &blob;
r.in.offered = needed;
- status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s, "
- "%s\n", __location__, nt_errstr(status),
- win_errstr(r.out.result));
- talloc_free(mem_ctx);
- return NT_STATUS_IS_OK(status) ?
- NT_STATUS_UNSUCCESSFUL : status;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
+ "dcerpc_spoolss_GetPrinter failed");
+ torture_assert_werr_ok(tctx, r.out.result,
+ "dcerpc_spoolss_GetPrinter failed");
if (res != NULL) {
- *res = talloc_steal(ctx, r.out.info);
+ *res = talloc_steal(tctx, r.out.info);
}
- talloc_free(mem_ctx);
- return NT_STATUS_OK;
+ return true;
}
-bool torture_samba3_rpc_spoolss(struct torture_context *torture)
+static bool torture_samba3_rpc_spoolss(struct torture_context *torture)
{
- TALLOC_CTX *mem_ctx;
- bool ret = true;
- struct smbcli_state *cli;
- struct dcerpc_pipe *p;
- NTSTATUS status;
+ struct dcerpc_pipe *p, *p2;
+ struct dcerpc_binding_handle *b;
struct policy_handle server_handle, printer_handle;
const char **printers;
int num_printers;
struct spoolss_UserLevel1 userlevel1;
char *servername;
- if (!(mem_ctx = talloc_new(torture))) {
- return false;
- }
+ torture_assert(torture,
+ rap_get_servername(torture, &servername),
+ "failed to rap servername");
- if (!(torture_open_connection_share(
- mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
- "IPC$", torture->ev))) {
- d_printf("IPC$ connection failed\n");
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &p2, &ndr_table_srvsvc),
+ "failed to setup srvsvc");
- status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "(%s) get_servername returned %s\n",
- __location__, nt_errstr(status));
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert(torture,
+ find_printers(torture, p2, &printers, &num_printers),
+ "failed to find printers via srvsvc");
- if (!NT_STATUS_IS_OK(find_printers(mem_ctx, torture->lp_ctx, cli->tree,
- &printers, &num_printers))) {
- talloc_free(mem_ctx);
- return false;
- }
+ talloc_free(p2);
if (num_printers == 0) {
- d_printf("Did not find printers\n");
- talloc_free(mem_ctx);
+ torture_skip(torture, "Did not find printers\n");
return true;
}
- status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\spoolss",
- &ndr_table_spoolss, &p);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
- nt_errstr(status));
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &p, &ndr_table_spoolss),
+ "failed to setup spoolss");
+
+ b = p->binding_handle;
ZERO_STRUCT(userlevel1);
userlevel1.client = talloc_asprintf(
- mem_ctx, "\\\\%s", lp_netbios_name(torture->lp_ctx));
+ torture, "\\\\%s", lpcfg_netbios_name(torture->lp_ctx));
userlevel1.user = cli_credentials_get_username(cmdline_credentials);
userlevel1.build = 2600;
userlevel1.major = 3;
struct spoolss_OpenPrinterEx r;
ZERO_STRUCT(r);
- r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s",
+ r.in.printername = talloc_asprintf(torture, "\\\\%s",
servername);
r.in.datatype = NULL;
r.in.access_mask = 0;
r.in.userlevel.level1 = &userlevel1;
r.out.handle = &server_handle;
- status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) dcerpc_spoolss_OpenPrinterEx failed: "
- "%s, %s\n", __location__, nt_errstr(status),
- win_errstr(r.out.result));
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
+ "dcerpc_spoolss_OpenPrinterEx failed");
+ torture_assert_werr_ok(torture, r.out.result,
+ "dcerpc_spoolss_OpenPrinterEx failed");
}
{
r.in.handle = &server_handle;
r.out.handle = &server_handle;
- status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
- "%s, %s\n", __location__, nt_errstr(status),
- win_errstr(r.out.result));
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
+ "dcerpc_spoolss_ClosePrinter failed");
+ torture_assert_werr_ok(torture, r.out.result,
+ "dcerpc_spoolss_ClosePrinter failed");
}
{
ZERO_STRUCT(r);
r.in.printername = talloc_asprintf(
- mem_ctx, "\\\\%s\\%s", servername, printers[0]);
+ torture, "\\\\%s\\%s", servername, printers[0]);
r.in.datatype = NULL;
r.in.access_mask = 0;
r.in.level = 1;
r.in.userlevel.level1 = &userlevel1;
r.out.handle = &printer_handle;
- status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) dcerpc_spoolss_OpenPrinterEx failed: "
- "%s, %s\n", __location__, nt_errstr(status),
- win_errstr(r.out.result));
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
+ "dcerpc_spoolss_OpenPrinterEx failed");
+ torture_assert_werr_ok(torture, r.out.result,
+ "dcerpc_spoolss_OpenPrinterEx failed");
}
{
int i;
for (i=0; i<8; i++) {
- status = getprinterinfo(mem_ctx, p, &printer_handle,
- i, NULL);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) getprinterinfo %d failed: %s\n",
- __location__, i, nt_errstr(status));
- ret = false;
- }
+ torture_assert(torture,
+ getprinterinfo(torture, b, &printer_handle, i, NULL),
+ talloc_asprintf(torture, "getprinterinfo %d failed", i));
}
}
r.in.handle = &printer_handle;
r.out.handle = &printer_handle;
- status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
- "%s\n", __location__, nt_errstr(status));
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
+ "dcerpc_spoolss_ClosePrinter failed");
+ torture_assert_werr_ok(torture, r.out.result,
+ "dcerpc_spoolss_ClosePrinter failed");
}
{
int num_enumerated;
- if (!enumprinters(mem_ctx, p, servername, 1,
- &num_enumerated)) {
- d_printf("(%s) enumprinters failed\n", __location__);
- talloc_free(mem_ctx);
- return false;
- }
- if (num_printers != num_enumerated) {
- d_printf("(%s) netshareenum gave %d printers, "
- "enumprinters lvl 1 gave %d\n", __location__,
- num_printers, num_enumerated);
- talloc_free(mem_ctx);
- return false;
- }
+
+ torture_assert(torture,
+ enumprinters(torture, b, servername, 1, &num_enumerated),
+ "enumprinters failed");
+
+ torture_assert_int_equal(torture, num_printers, num_enumerated,
+ "netshareenum / enumprinters lvl 1 numprinter mismatch");
}
{
int num_enumerated;
- if (!enumprinters(mem_ctx, p, servername, 2,
- &num_enumerated)) {
- d_printf("(%s) enumprinters failed\n", __location__);
- talloc_free(mem_ctx);
- return false;
- }
- if (num_printers != num_enumerated) {
- d_printf("(%s) netshareenum gave %d printers, "
- "enumprinters lvl 2 gave %d\n", __location__,
- num_printers, num_enumerated);
- talloc_free(mem_ctx);
- return false;
- }
- }
- talloc_free(mem_ctx);
+ torture_assert(torture,
+ enumprinters(torture, b, servername, 2, &num_enumerated),
+ "enumprinters failed");
- return ret;
+ torture_assert_int_equal(torture, num_printers, num_enumerated,
+ "netshareenum / enumprinters lvl 2 numprinter mismatch");
+ }
+
+ return true;
}
-bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
+static bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
{
- TALLOC_CTX *mem_ctx;
- struct smbcli_state *cli;
struct dcerpc_pipe *p;
- NTSTATUS status;
+ struct dcerpc_binding_handle *b;
char *servername;
- if (!(mem_ctx = talloc_new(torture))) {
- return false;
- }
-
- if (!(torture_open_connection_share(
- mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
- "IPC$", torture->ev))) {
- d_printf("IPC$ connection failed\n");
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert(torture,
+ rap_get_servername(torture, &servername),
+ "failed to rap servername");
- status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "(%s) get_servername returned %s\n",
- __location__, nt_errstr(status));
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &p, &ndr_table_wkssvc),
+ "failed to setup wkssvc");
- status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\wkssvc",
- &ndr_table_wkssvc, &p);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
- nt_errstr(status));
- talloc_free(mem_ctx);
- return false;
- }
+ b = p->binding_handle;
{
struct wkssvc_NetWkstaInfo100 wks100;
info.info100 = &wks100;
r.out.info = &info;
- status = dcerpc_wkssvc_NetWkstaGetInfo(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) dcerpc_wkssvc_NetWksGetInfo failed: "
- "%s, %s\n", __location__, nt_errstr(status),
- win_errstr(r.out.result));
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_wkssvc_NetWkstaGetInfo_r(b, torture, &r),
+ "dcerpc_wkssvc_NetWksGetInfo failed");
+ torture_assert_werr_ok(torture, r.out.result,
+ "dcerpc_wkssvc_NetWksGetInfo failed");
- if (strcmp(servername,
- r.out.info->info100->server_name) != 0) {
- d_printf("(%s) servername inconsistency: RAP=%s, "
- "dcerpc_wkssvc_NetWksGetInfo=%s",
- __location__, servername,
- r.out.info->info100->server_name);
- talloc_free(mem_ctx);
- return false;
- }
+ torture_assert_str_equal(torture, servername, r.out.info->info100->server_name,
+ "servername RAP / DCERPC inconsistency");
}
- talloc_free(mem_ctx);
return true;
}
-static NTSTATUS winreg_close(struct dcerpc_pipe *p,
- struct policy_handle *handle)
+static bool winreg_close(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ struct policy_handle *handle)
{
struct winreg_CloseKey c;
- NTSTATUS status;
- TALLOC_CTX *mem_ctx;
c.in.handle = c.out.handle = handle;
- if (!(mem_ctx = talloc_new(p))) {
- return NT_STATUS_NO_MEMORY;
- }
-
- status = dcerpc_winreg_CloseKey(p, mem_ctx, &c);
- talloc_free(mem_ctx);
-
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
- if (!W_ERROR_IS_OK(c.out.result)) {
- return werror_to_ntstatus(c.out.result);
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_winreg_CloseKey_r(b, tctx, &c),
+ "winreg_CloseKey failed");
+ torture_assert_werr_ok(tctx, c.out.result,
+ "winreg_CloseKey failed");
- return NT_STATUS_OK;
+ return true;
}
-static NTSTATUS enumvalues(struct dcerpc_pipe *p, struct policy_handle *handle,
- TALLOC_CTX *mem_ctx)
+static bool enumvalues(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ struct policy_handle *handle)
{
uint32_t enum_index = 0;
uint8_t buf8[1024];
NTSTATUS status;
uint32_t size, length;
-
+
r.in.handle = handle;
r.in.enum_index = enum_index;
name.name = "";
r.in.size = &size;
r.in.length = &length;
- status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
+ status = dcerpc_winreg_EnumValue_r(b, tctx, &r);
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- return NT_STATUS_OK;
+ return true;
}
enum_index += 1;
}
}
-static NTSTATUS enumkeys(struct dcerpc_pipe *p, struct policy_handle *handle,
- TALLOC_CTX *mem_ctx, int depth)
+static bool enumkeys(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ struct policy_handle *handle,
+ int depth)
{
struct winreg_EnumKey r;
struct winreg_StringBuf kclass, name;
NTTIME t = 0;
if (depth <= 0) {
- return NT_STATUS_OK;
+ return true;
}
kclass.name = "";
r.in.last_changed_time = &t;
do {
- TALLOC_CTX *tmp_ctx;
struct winreg_OpenKey o;
struct policy_handle key_handle;
int i;
- if (!(tmp_ctx = talloc_new(mem_ctx))) {
- return NT_STATUS_NO_MEMORY;
- }
-
name.name = NULL;
name.size = 1024;
- status = dcerpc_winreg_EnumKey(p, tmp_ctx, &r);
+ status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
/* We're done enumerating */
- talloc_free(tmp_ctx);
- return NT_STATUS_OK;
+ return true;
}
- for (i=0; i<10-depth; i++)
- printf(" ");
- printf("%s\n", r.out.name->name);
-
+ for (i=0; i<10-depth; i++) {
+ torture_comment(tctx, " ");
+ }
+ torture_comment(tctx, "%s\n", r.out.name->name);
o.in.parent_handle = handle;
o.in.keyname.name = r.out.name->name;
- o.in.unknown = 0;
+ o.in.options = 0;
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
o.out.handle = &key_handle;
- status = dcerpc_winreg_OpenKey(p, tmp_ctx, &o);
+ status = dcerpc_winreg_OpenKey_r(b, tctx, &o);
if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
- enumkeys(p, &key_handle, tmp_ctx, depth-1);
- enumvalues(p, &key_handle, tmp_ctx);
- status = winreg_close(p, &key_handle);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ enumkeys(tctx, b, &key_handle, depth-1);
+ enumvalues(tctx, b, &key_handle);
+ torture_assert(tctx, winreg_close(tctx, b, &key_handle), "");
}
- talloc_free(tmp_ctx);
-
r.in.enum_index += 1;
} while(true);
- return NT_STATUS_OK;
+ return true;
}
-typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
+typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
-static bool test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+static bool test_Open3(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
const char *name, winreg_open_fn open_fn)
{
struct policy_handle handle;
struct winreg_OpenHKLM r;
- NTSTATUS status;
r.in.system_name = 0;
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
r.out.handle = &handle;
-
- status = open_fn(p, mem_ctx, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) %s failed: %s, %s\n", __location__, name,
- nt_errstr(status), win_errstr(r.out.result));
- return false;
- }
- enumkeys(p, &handle, mem_ctx, 4);
+ torture_assert_ntstatus_ok(tctx,
+ open_fn(b, tctx, &r),
+ talloc_asprintf(tctx, "%s failed", name));
+ torture_assert_werr_ok(tctx, r.out.result,
+ talloc_asprintf(tctx, "%s failed", name));
- status = winreg_close(p, &handle);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("(%s) dcerpc_CloseKey failed: %s\n",
- __location__, nt_errstr(status));
- return false;
- }
+ enumkeys(tctx, b, &handle, 4);
+
+ torture_assert(tctx,
+ winreg_close(tctx, b, &handle),
+ "dcerpc_CloseKey failed");
return true;
}
-bool torture_samba3_rpc_winreg(struct torture_context *torture)
+static bool torture_samba3_rpc_winreg(struct torture_context *torture)
{
- NTSTATUS status;
struct dcerpc_pipe *p;
- TALLOC_CTX *mem_ctx;
+ struct dcerpc_binding_handle *b;
bool ret = true;
struct {
const char *name;
winreg_open_fn fn;
} open_fns[] = {
- {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM },
- {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU },
- {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD },
- {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT },
- {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR }};
+ {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM_r },
+ {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU_r },
+ {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD_r },
+ {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT_r },
+ {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR_r }};
#if 0
int i;
#endif
- mem_ctx = talloc_init("torture_rpc_winreg");
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &p, &ndr_table_winreg),
+ "failed to setup winreg");
- status = torture_rpc_connection(torture, &p, &ndr_table_winreg);
-
- if (!NT_STATUS_IS_OK(status)) {
- talloc_free(mem_ctx);
- return false;
- }
+ b = p->binding_handle;
#if 1
- ret = test_Open3(p, mem_ctx, open_fns[0].name, open_fns[0].fn);
+ ret = test_Open3(torture, b, open_fns[0].name, open_fns[0].fn);
#else
for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
- if (!test_Open3(p, mem_ctx, open_fns[i].name, open_fns[i].fn))
+ if (!test_Open3(torture, b, open_fns[i].name, open_fns[i].fn))
ret = false;
}
#endif
-
- talloc_free(mem_ctx);
-
return ret;
}
-static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
- struct loadparm_context *lp_ctx,
- struct smbcli_state *cli,
- const char *share,
- struct srvsvc_NetShareInfo502 **info502)
+static bool get_shareinfo(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ const char *servername,
+ const char *share,
+ struct srvsvc_NetShareInfo502 **info502)
{
- struct smbcli_tree *ipc;
- struct dcerpc_pipe *p;
struct srvsvc_NetShareGetInfo r;
union srvsvc_NetShareInfo info;
- NTSTATUS status;
-
- if (!(p = dcerpc_pipe_init(cli,
- cli->transport->socket->event.ctx,
- lp_iconv_convenience(lp_ctx)))) {
- status = NT_STATUS_NO_MEMORY;
- goto fail;
- }
-
- status = secondary_tcon(p, cli->session, "IPC$", &ipc);
- if (!NT_STATUS_IS_OK(status)) {
- goto fail;
- }
- status = dcerpc_pipe_open_smb(p, ipc, "\\pipe\\srvsvc");
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
-
- status = dcerpc_bind_auth_none(p, &ndr_table_srvsvc);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_bind_auth_none failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
-
- r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
- dcerpc_server_name(p));
+ r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", servername);
r.in.share_name = share;
r.in.level = 502;
r.out.info = &info;
- status = dcerpc_srvsvc_NetShareGetInfo(p, p, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) srvsvc_NetShareGetInfo failed: %s, %s\n", __location__,
- nt_errstr(status), win_errstr(r.out.result));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r),
+ "srvsvc_NetShareGetInfo failed");
+ torture_assert_werr_ok(tctx, r.out.result,
+ "srvsvc_NetShareGetInfo failed");
- *info502 = talloc_move(mem_ctx, &info.info502);
- return NT_STATUS_OK;
+ *info502 = talloc_move(tctx, &info.info502);
- fail:
- talloc_free(p);
- return status;
+ return true;
}
/*
* Get us a handle on HKLM\
*/
-static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
- struct smbcli_state *cli,
- struct smb_iconv_convenience *iconv_convenience,
- struct dcerpc_pipe **pipe_p,
- struct policy_handle **handle)
+static bool get_hklm_handle(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ struct policy_handle *handle)
{
- struct smbcli_tree *ipc;
- struct dcerpc_pipe *p;
struct winreg_OpenHKLM r;
- NTSTATUS status;
- struct policy_handle *result;
-
- result = talloc(mem_ctx, struct policy_handle);
-
- if (result == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- if (!(p = dcerpc_pipe_init(result,
- cli->transport->socket->event.ctx,
- iconv_convenience))) {
- status = NT_STATUS_NO_MEMORY;
- goto fail;
- }
-
- status = secondary_tcon(p, cli->session, "IPC$", &ipc);
- if (!NT_STATUS_IS_OK(status)) {
- goto fail;
- }
-
- status = dcerpc_pipe_open_smb(p, ipc, "\\winreg");
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_pipe_open_smb failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
-
- status = dcerpc_bind_auth_none(p, &ndr_table_winreg);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("dcerpc_bind_auth_none failed: %s\n",
- nt_errstr(status));
- goto fail;
- }
+ struct policy_handle result;
r.in.system_name = 0;
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
- r.out.handle = result;
+ r.out.handle = &result;
- status = dcerpc_winreg_OpenHKLM(p, p, &r);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
- nt_errstr(status), win_errstr(r.out.result));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
+ "OpenHKLM failed");
+ torture_assert_werr_ok(tctx, r.out.result,
+ "OpenHKLM failed");
- *pipe_p = p;
*handle = result;
- return NT_STATUS_OK;
- fail:
- talloc_free(result);
- return status;
+ return true;
}
-static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
- struct smb_iconv_convenience *iconv_convenience,
- const char *sharename)
+static bool torture_samba3_createshare(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ const char *sharename)
{
- struct dcerpc_pipe *p;
- struct policy_handle *hklm = NULL;
+ struct policy_handle hklm;
struct policy_handle new_handle;
struct winreg_CreateKey c;
struct winreg_CloseKey cl;
enum winreg_CreateAction action_taken;
- NTSTATUS status;
- TALLOC_CTX *mem_ctx;
-
- mem_ctx = talloc_new(cli);
- NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
- status = get_hklm_handle(mem_ctx, cli, iconv_convenience, &p, &hklm);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
- goto fail;
- }
-
- c.in.handle = hklm;
+ c.in.handle = &hklm;
c.in.name.name = talloc_asprintf(
- mem_ctx, "software\\samba\\smbconf\\%s", sharename);
- if (c.in.name.name == NULL) {
- d_printf("talloc_asprintf failed\n");
- status = NT_STATUS_NO_MEMORY;
- goto fail;
- }
+ tctx, "software\\samba\\smbconf\\%s", sharename);
+ torture_assert(tctx, c.in.name.name, "talloc_asprintf failed");
+
c.in.keyclass.name = "";
c.in.options = 0;
c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
c.out.new_handle = &new_handle;
c.out.action_taken = &action_taken;
- status = dcerpc_winreg_CreateKey(p, p, &c);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(c.out.result)) {
- d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
- nt_errstr(status), win_errstr(c.out.result));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_winreg_CreateKey_r(b, tctx, &c),
+ "OpenKey failed");
+ torture_assert_werr_ok(tctx, c.out.result,
+ "OpenKey failed");
cl.in.handle = &new_handle;
cl.out.handle = &new_handle;
- status = dcerpc_winreg_CloseKey(p, p, &cl);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(cl.out.result)) {
- d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
- nt_errstr(status), win_errstr(cl.out.result));
- goto fail;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_winreg_CloseKey_r(b, tctx, &cl),
+ "CloseKey failed");
+ torture_assert_werr_ok(tctx, cl.out.result,
+ "CloseKey failed");
- fail:
- talloc_free(mem_ctx);
- return status;
+ return true;
}
-static NTSTATUS torture_samba3_deleteshare(struct torture_context *torture,
- struct smbcli_state *cli,
- const char *sharename)
+static bool torture_samba3_deleteshare(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ const char *sharename)
{
- struct dcerpc_pipe *p;
- struct policy_handle *hklm = NULL;
+ struct policy_handle hklm;
struct winreg_DeleteKey d;
- NTSTATUS status;
- TALLOC_CTX *mem_ctx;
- mem_ctx = talloc_new(cli);
- NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
+ torture_assert(tctx,
+ get_hklm_handle(tctx, b, &hklm),
+ "get_hklm_handle failed");
- status = get_hklm_handle(cli, cli, lp_iconv_convenience(torture->lp_ctx),
- &p, &hklm);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
- goto fail;
- }
-
- d.in.handle = hklm;
+ d.in.handle = &hklm;
d.in.key.name = talloc_asprintf(
- mem_ctx, "software\\samba\\smbconf\\%s", sharename);
- if (d.in.key.name == NULL) {
- d_printf("talloc_asprintf failed\n");
- status = NT_STATUS_NO_MEMORY;
- goto fail;
- }
- status = dcerpc_winreg_DeleteKey(p, p, &d);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(d.out.result)) {
- d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
- nt_errstr(status), win_errstr(d.out.result));
- goto fail;
- }
+ tctx, "software\\samba\\smbconf\\%s", sharename);
+ torture_assert(tctx, d.in.key.name, "talloc_asprintf failed");
- fail:
- talloc_free(mem_ctx);
- return status;
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_winreg_DeleteKey_r(b, tctx, &d),
+ "DeleteKey failed");
+ torture_assert_werr_ok(tctx, d.out.result,
+ "DeleteKey failed");
+
+ return true;
}
-static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
- struct loadparm_context *lp_ctx,
- const char *sharename,
- const char *parameter,
- const char *value)
+static bool torture_samba3_setconfig(struct torture_context *tctx,
+ struct dcerpc_binding_handle *b,
+ const char *sharename,
+ const char *parameter,
+ const char *value)
{
- struct dcerpc_pipe *p = NULL;
- struct policy_handle *hklm = NULL, key_handle;
+ struct policy_handle hklm, key_handle;
struct winreg_OpenKey o;
struct winreg_SetValue s;
uint32_t type;
DATA_BLOB val;
- NTSTATUS status;
- status = get_hklm_handle(cli, cli, lp_iconv_convenience(lp_ctx), &p, &hklm);
- if (!NT_STATUS_IS_OK(status)) {
- d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
- return status;;
- }
+ torture_assert(tctx,
+ get_hklm_handle(tctx, b, &hklm),
+ "get_hklm_handle failed");
- o.in.parent_handle = hklm;
+ o.in.parent_handle = &hklm;
o.in.keyname.name = talloc_asprintf(
- hklm, "software\\samba\\smbconf\\%s", sharename);
- if (o.in.keyname.name == NULL) {
- d_printf("talloc_asprintf failed\n");
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
- o.in.unknown = 0;
+ tctx, "software\\samba\\smbconf\\%s", sharename);
+ torture_assert(tctx, o.in.keyname.name, "talloc_asprintf failed");
+
+ o.in.options = 0;
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
o.out.handle = &key_handle;
- status = dcerpc_winreg_OpenKey(p, p, &o);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(o.out.result)) {
- d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
- nt_errstr(status), win_errstr(o.out.result));
- goto done;
- }
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_winreg_OpenKey_r(b, tctx, &o),
+ "OpenKey failed");
+ torture_assert_werr_ok(tctx, o.out.result,
+ "OpenKey failed");
- if (!reg_string_to_val(hklm, lp_iconv_convenience(lp_ctx), "REG_SZ",
- value, &type, &val)) {
- d_printf("(%s) reg_string_to_val failed\n", __location__);
- goto done;
- }
+ torture_assert(tctx,
+ reg_string_to_val(tctx, "REG_SZ", value, &type, &val),
+ "reg_string_to_val failed");
s.in.handle = &key_handle;
s.in.name.name = parameter;
s.in.data = val.data;
s.in.size = val.length;
- status = dcerpc_winreg_SetValue(p, p, &s);
- if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(s.out.result)) {
- d_printf("(%s) SetValue failed: %s, %s\n", __location__,
- nt_errstr(status), win_errstr(s.out.result));
- goto done;
+ torture_assert_ntstatus_ok(tctx,
+ dcerpc_winreg_SetValue_r(b, tctx, &s),
+ "SetValue failed");
+ torture_assert_werr_ok(tctx, s.out.result,
+ "SetValue failed");
+
+ return true;
+}
+
+static bool torture_samba3_regconfig(struct torture_context *torture)
+{
+ struct srvsvc_NetShareInfo502 *i = NULL;
+ const char *comment = "Dummer Kommentar";
+ struct dcerpc_pipe *srvsvc_pipe, *winreg_pipe;
+
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &srvsvc_pipe, &ndr_table_srvsvc),
+ "failed to setup srvsvc");
+
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &winreg_pipe, &ndr_table_winreg),
+ "failed to setup winreg");
+
+ torture_assert(torture,
+ torture_samba3_createshare(torture, winreg_pipe->binding_handle, "blubber"),
+ "torture_samba3_createshare failed");
+
+ torture_assert(torture,
+ torture_samba3_setconfig(torture, winreg_pipe->binding_handle, "blubber", "comment", comment),
+ "torture_samba3_setconfig failed");
+
+ torture_assert(torture,
+ get_shareinfo(torture, srvsvc_pipe->binding_handle, dcerpc_server_name(srvsvc_pipe), "blubber", &i),
+ "get_shareinfo failed");
+
+ torture_assert_str_equal(torture, comment, i->comment,
+ "got unexpected comment");
+
+ torture_assert(torture,
+ torture_samba3_deleteshare(torture, winreg_pipe->binding_handle, "blubber"),
+ "torture_samba3_deleteshare failed");
+
+ return true;
+}
+
+/*
+ * Test that even with a result of 0 rids the array is returned as a
+ * non-NULL pointer. Yes, XP does notice.
+ */
+
+bool torture_samba3_getaliasmembership_0(struct torture_context *torture)
+{
+ struct dcerpc_pipe *p;
+ struct dcerpc_binding_handle *b;
+ struct samr_Connect2 c;
+ struct samr_OpenDomain o;
+ struct dom_sid sid;
+ struct lsa_SidPtr ptr;
+ struct lsa_SidArray sids;
+ struct samr_GetAliasMembership g;
+ struct samr_Ids rids;
+ struct policy_handle samr, domain;
+
+ torture_assert_ntstatus_ok(torture,
+ torture_rpc_connection(torture, &p, &ndr_table_samr),
+ "failed to setup samr");
+
+ b = p->binding_handle;
+
+ c.in.system_name = NULL;
+ c.in.access_mask = SAMR_ACCESS_LOOKUP_DOMAIN;
+ c.out.connect_handle = &samr;
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_samr_Connect2_r(b, torture, &c),
+ "");
+ torture_assert_ntstatus_ok(torture, c.out.result,
+ "");
+ dom_sid_parse("S-1-5-32", &sid);
+ o.in.connect_handle = &samr;
+ o.in.access_mask = SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS;
+ o.in.sid = &sid;
+ o.out.domain_handle = &domain;
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_samr_OpenDomain_r(b, torture, &o),
+ "");
+ torture_assert_ntstatus_ok(torture, o.out.result,
+ "");
+ dom_sid_parse("S-1-2-3-4-5", &sid);
+ ptr.sid = &sid;
+ sids.num_sids = 1;
+ sids.sids = &ptr;
+ g.in.domain_handle = &domain;
+ g.in.sids = &sids;
+ g.out.rids = &rids;
+ torture_assert_ntstatus_ok(torture,
+ dcerpc_samr_GetAliasMembership_r(b, torture, &g),
+ "");
+ torture_assert_ntstatus_ok(torture, g.out.result,
+ "");
+ if (rids.ids == NULL) {
+ /* This is the piece to test here */
+ torture_fail(torture,
+ "torture_samba3_getaliasmembership_0: "
+ "Server returns NULL rids array\n");
}
- done:
- talloc_free(hklm);
- return status;
+ return true;
}
-bool torture_samba3_regconfig(struct torture_context *torture)
+/**
+ * Test smb reauthentication while rpc pipe is in use.
+ */
+static bool torture_rpc_smb_reauth1(struct torture_context *torture)
{
+ TALLOC_CTX *mem_ctx;
+ NTSTATUS status;
+ bool ret = false;
struct smbcli_state *cli;
- struct srvsvc_NetShareInfo502 *i = NULL;
+ struct smbcli_options options;
+ struct smbcli_session_options session_options;
+
+ struct dcerpc_pipe *lsa_pipe;
+ struct dcerpc_binding_handle *lsa_handle;
+ struct lsa_GetUserName r;
+ struct lsa_String *authority_name_p = NULL;
+ char *authority_name_saved = NULL;
+ struct lsa_String *account_name_p = NULL;
+ char *account_name_saved = NULL;
+ struct cli_credentials *anon_creds = NULL;
+ struct smb_composite_sesssetup io;
+
+ mem_ctx = talloc_init("torture_samba3_reauth");
+ torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
+
+ lpcfg_smbcli_options(torture->lp_ctx, &options);
+ lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
+
+ status = smbcli_full_connection(mem_ctx, &cli,
+ torture_setting_string(torture, "host", NULL),
+ lpcfg_smb_ports(torture->lp_ctx),
+ "IPC$", NULL,
+ lpcfg_socket_options(torture->lp_ctx),
+ cmdline_credentials,
+ lpcfg_resolve_context(torture->lp_ctx),
+ torture->ev, &options, &session_options,
+ lpcfg_gensec_settings(torture, torture->lp_ctx));
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "smbcli_full_connection failed");
+
+ lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
+ torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
+ "dcerpc_pipe_init failed");
+ lsa_handle = lsa_pipe->binding_handle;
+
+ status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "dcerpc_pipe_open failed");
+
+ status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "dcerpc_bind_auth_none failed");
+
+ /* lsa getusername */
+
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
+ authority_name_p->string,
+ account_name_p->string);
+
+ account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
+ torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
+ "talloc failed");
+ authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
+ torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
+ "talloc failed");
+
+ /* smb re-authenticate as anonymous */
+
+ anon_creds = cli_credentials_init_anon(mem_ctx);
+
+ ZERO_STRUCT(io);
+ io.in.sesskey = cli->transport->negotiate.sesskey;
+ io.in.capabilities = cli->transport->negotiate.capabilities;
+ io.in.credentials = anon_creds;
+ io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
+ io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
+
+ status = smb_composite_sesssetup(cli->session, &io);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "session reauth to anon failed");
+
+ /* re-do lsa getusername after reauth */
+
+ TALLOC_FREE(authority_name_p);
+ TALLOC_FREE(account_name_p);
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
+ ret, done, "authority_name not equal after reauth to anon");
+ torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
+ ret, done, "account_name not equal after reauth to anon");
+
+ /* smb re-auth again to the original user */
+
+ ZERO_STRUCT(io);
+ io.in.sesskey = cli->transport->negotiate.sesskey;
+ io.in.capabilities = cli->transport->negotiate.capabilities;
+ io.in.credentials = cmdline_credentials;
+ io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
+ io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
+
+ status = smb_composite_sesssetup(cli->session, &io);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "session reauth to anon failed");
+
+ /* re-do lsa getusername */
+
+ TALLOC_FREE(authority_name_p);
+ TALLOC_FREE(account_name_p);
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
+ ret, done, "authority_name not equal after reauth to anon");
+ torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
+ ret, done, "account_name not equal after reauth to anon");
+
+ ret = true;
+
+done:
+ talloc_free(mem_ctx);
+ return ret;
+}
+
+/**
+ * Test smb reauthentication while rpc pipe is in use.
+ * Open a second lsa bind after reauth to anon.
+ * Do lsa getusername on that second bind.
+ */
+static bool torture_rpc_smb_reauth2(struct torture_context *torture)
+{
+ TALLOC_CTX *mem_ctx;
NTSTATUS status;
bool ret = false;
- const char *comment = "Dummer Kommentar";
+ struct smbcli_state *cli;
+ struct smbcli_options options;
+ struct smbcli_session_options session_options;
- if (!(torture_open_connection(&cli, torture, 0))) {
- return false;
- }
+ struct dcerpc_pipe *lsa_pipe;
+ struct dcerpc_binding_handle *lsa_handle;
+ struct lsa_GetUserName r;
+ struct lsa_String *authority_name_p = NULL;
+ char *authority_name_saved = NULL;
+ struct lsa_String *account_name_p = NULL;
+ char *account_name_saved = NULL;
+ struct cli_credentials *anon_creds = NULL;
+ struct smb_composite_sesssetup io;
- status = torture_samba3_createshare(cli, lp_iconv_convenience(torture->lp_ctx), "blubber");
- if (!NT_STATUS_IS_OK(status)) {
- torture_warning(torture, "torture_samba3_createshare failed: "
- "%s\n", nt_errstr(status));
- goto done;
- }
+ mem_ctx = talloc_init("torture_samba3_reauth");
+ torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
- status = torture_samba3_setconfig(cli, torture->lp_ctx, "blubber", "comment", comment);
- if (!NT_STATUS_IS_OK(status)) {
- torture_warning(torture, "torture_samba3_setconfig failed: "
- "%s\n", nt_errstr(status));
- goto done;
- }
+ lpcfg_smbcli_options(torture->lp_ctx, &options);
+ lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
- status = get_shareinfo(torture, torture->lp_ctx, cli, "blubber", &i);
- if (!NT_STATUS_IS_OK(status)) {
- torture_warning(torture, "get_shareinfo failed: "
- "%s\n", nt_errstr(status));
- goto done;
- }
+ status = smbcli_full_connection(mem_ctx, &cli,
+ torture_setting_string(torture, "host", NULL),
+ lpcfg_smb_ports(torture->lp_ctx),
+ "IPC$", NULL,
+ lpcfg_socket_options(torture->lp_ctx),
+ cmdline_credentials,
+ lpcfg_resolve_context(torture->lp_ctx),
+ torture->ev, &options, &session_options,
+ lpcfg_gensec_settings(torture, torture->lp_ctx));
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "smbcli_full_connection failed");
- if (strcmp(comment, i->comment) != 0) {
- torture_warning(torture, "Expected comment [%s], got [%s]\n",
- comment, i->comment);
- goto done;
- }
+ /* smb re-authenticate as anonymous */
- status = torture_samba3_deleteshare(torture, cli, "blubber");
- if (!NT_STATUS_IS_OK(status)) {
- torture_warning(torture, "torture_samba3_deleteshare failed: "
- "%s\n", nt_errstr(status));
- goto done;
- }
+ anon_creds = cli_credentials_init_anon(mem_ctx);
+
+ ZERO_STRUCT(io);
+ io.in.sesskey = cli->transport->negotiate.sesskey;
+ io.in.capabilities = cli->transport->negotiate.capabilities;
+ io.in.credentials = anon_creds;
+ io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
+ io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
+
+ status = smb_composite_sesssetup(cli->session, &io);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "session reauth to anon failed");
+
+ /* open the lsa pipe */
+
+ lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
+ torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
+ "dcerpc_pipe_init failed");
+ lsa_handle = lsa_pipe->binding_handle;
+
+ status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "dcerpc_pipe_open failed");
+
+ status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "dcerpc_bind_auth_none failed");
+
+ /* lsa getusername */
+
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
+ authority_name_p->string,
+ account_name_p->string);
+
+ account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
+ torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
+ "talloc failed");
+ authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
+ torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
+ "talloc failed");
+
+ /* smb re-auth again to the original user */
+
+ ZERO_STRUCT(io);
+ io.in.sesskey = cli->transport->negotiate.sesskey;
+ io.in.capabilities = cli->transport->negotiate.capabilities;
+ io.in.credentials = cmdline_credentials;
+ io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
+ io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
+
+ status = smb_composite_sesssetup(cli->session, &io);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "session reauth to anon failed");
+
+ /* re-do lsa getusername after reauth */
+
+ TALLOC_FREE(authority_name_p);
+ TALLOC_FREE(account_name_p);
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
+ ret, done, "authority_name not equal after reauth to anon");
+ torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
+ ret, done, "account_name not equal after reauth to anon");
ret = true;
- done:
- talloc_free(cli);
+
+done:
+ talloc_free(mem_ctx);
+ return ret;
+}
+
+/**
+ * Test smb2 reauthentication while rpc pipe is in use.
+ */
+static bool torture_rpc_smb2_reauth1(struct torture_context *torture)
+{
+ TALLOC_CTX *mem_ctx;
+ NTSTATUS status;
+ bool ret = false;
+ struct smbcli_options options;
+
+ struct dcerpc_pipe *lsa_pipe;
+ struct dcerpc_binding_handle *lsa_handle;
+ struct lsa_GetUserName r;
+ struct lsa_String *authority_name_p = NULL;
+ char *authority_name_saved = NULL;
+ struct lsa_String *account_name_p = NULL;
+ char *account_name_saved = NULL;
+ struct cli_credentials *anon_creds = NULL;
+ const char *host = torture_setting_string(torture, "host", NULL);
+ struct smb2_tree *tree;
+
+ mem_ctx = talloc_init("torture_samba3_reauth");
+ torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
+
+ lpcfg_smbcli_options(torture->lp_ctx, &options);
+
+ status = smb2_connect(mem_ctx,
+ host,
+ lpcfg_smb_ports(torture->lp_ctx),
+ "IPC$",
+ lpcfg_resolve_context(torture->lp_ctx),
+ cmdline_credentials,
+ &tree,
+ torture->ev,
+ &options,
+ lpcfg_socket_options(torture->lp_ctx),
+ lpcfg_gensec_settings(torture, torture->lp_ctx)
+ );
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "smb2_connect failed");
+
+ lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
+ torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
+ "dcerpc_pipe_init failed");
+ lsa_handle = lsa_pipe->binding_handle;
+
+ status = dcerpc_pipe_open_smb2(lsa_pipe, tree, "lsarpc");
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "dcerpc_pipe_open_smb2 failed");
+
+ status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "dcerpc_bind_auth_none failed");
+
+ /* lsa getusername */
+
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
+ authority_name_p->string,
+ account_name_p->string);
+
+ account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
+ torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
+ "talloc failed");
+ authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
+ torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
+ "talloc failed");
+
+ /* smb re-authenticate as anonymous */
+
+ anon_creds = cli_credentials_init_anon(mem_ctx);
+
+ status = smb2_session_setup_spnego(tree->session,
+ anon_creds,
+ 0 /* previous_session_id */);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "session reauth to anon failed");
+
+ /* re-do lsa getusername after reauth */
+
+ TALLOC_FREE(authority_name_p);
+ TALLOC_FREE(account_name_p);
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
+ ret, done, "authority_name not equal after reauth to anon");
+ torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
+ ret, done, "account_name not equal after reauth to anon");
+
+ /* smb re-auth again to the original user */
+
+ status = smb2_session_setup_spnego(tree->session,
+ cmdline_credentials,
+ 0 /* previous_session_id */);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "session reauth to anon failed");
+
+ /* re-do lsa getusername */
+
+ TALLOC_FREE(authority_name_p);
+ TALLOC_FREE(account_name_p);
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
+ ret, done, "authority_name not equal after reauth to anon");
+ torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
+ ret, done, "account_name not equal after reauth to anon");
+
+ ret = true;
+
+done:
+ talloc_free(mem_ctx);
return ret;
}
+
+/**
+ * Test smb2reauthentication while rpc pipe is in use.
+ * Open a second lsa bind after reauth to anon.
+ * Do lsa getusername on that second bind.
+ */
+static bool torture_rpc_smb2_reauth2(struct torture_context *torture)
+{
+ TALLOC_CTX *mem_ctx;
+ NTSTATUS status;
+ bool ret = false;
+ struct smbcli_options options;
+
+ struct dcerpc_pipe *lsa_pipe;
+ struct dcerpc_binding_handle *lsa_handle;
+ struct lsa_GetUserName r;
+ struct lsa_String *authority_name_p = NULL;
+ char *authority_name_saved = NULL;
+ struct lsa_String *account_name_p = NULL;
+ char *account_name_saved = NULL;
+ struct cli_credentials *anon_creds = NULL;
+ const char *host = torture_setting_string(torture, "host", NULL);
+ struct smb2_tree *tree;
+
+ mem_ctx = talloc_init("torture_samba3_reauth");
+ torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
+
+ lpcfg_smbcli_options(torture->lp_ctx, &options);
+
+ status = smb2_connect(mem_ctx,
+ host,
+ lpcfg_smb_ports(torture->lp_ctx),
+ "IPC$",
+ lpcfg_resolve_context(torture->lp_ctx),
+ cmdline_credentials,
+ &tree,
+ torture->ev,
+ &options,
+ lpcfg_socket_options(torture->lp_ctx),
+ lpcfg_gensec_settings(torture, torture->lp_ctx)
+ );
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "smb2_connect failed");
+
+ /* smb re-authenticate as anonymous */
+
+ anon_creds = cli_credentials_init_anon(mem_ctx);
+
+ status = smb2_session_setup_spnego(tree->session,
+ anon_creds,
+ 0 /* previous_session_id */);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "session reauth to anon failed");
+
+ /* open the lsa pipe */
+
+ lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
+ torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
+ "dcerpc_pipe_init failed");
+ lsa_handle = lsa_pipe->binding_handle;
+
+ status = dcerpc_pipe_open_smb2(lsa_pipe, tree, "lsarpc");
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "dcerpc_pipe_open_smb2 failed");
+
+ status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "dcerpc_bind_auth_none failed");
+
+ /* lsa getusername */
+
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
+ authority_name_p->string,
+ account_name_p->string);
+
+ account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
+ torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
+ "talloc failed");
+ authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
+ torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
+ "talloc failed");
+
+ /* smb re-auth again to the original user */
+
+ status = smb2_session_setup_spnego(tree->session,
+ cmdline_credentials,
+ 0 /* previous_session_id */);
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "session reauth to anon failed");
+
+ /* re-do lsa getusername */
+
+ TALLOC_FREE(authority_name_p);
+ TALLOC_FREE(account_name_p);
+ ZERO_STRUCT(r);
+ r.in.system_name = "\\";
+ r.in.account_name = &account_name_p;
+ r.in.authority_name = &authority_name_p;
+ r.out.account_name = &account_name_p;
+
+ status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
+
+ authority_name_p = *r.out.authority_name;
+
+ torture_assert_ntstatus_ok_goto(torture, status, ret, done,
+ "GetUserName failed");
+ torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
+ "GetUserName failed");
+
+ torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
+ ret, done, "authority_name not equal after reauth to anon");
+ torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
+ ret, done, "account_name not equal after reauth to anon");
+
+ ret = true;
+
+done:
+ talloc_free(mem_ctx);
+ return ret;
+}
+
+struct torture_suite *torture_rpc_samba3(TALLOC_CTX *mem_ctx)
+{
+ struct torture_suite *suite = torture_suite_create(mem_ctx, "samba3");
+
+ torture_suite_add_simple_test(suite, "bind", torture_bind_samba3);
+ torture_suite_add_simple_test(suite, "netlogon", torture_netlogon_samba3);
+ torture_suite_add_simple_test(suite, "sessionkey", torture_samba3_sessionkey);
+ torture_suite_add_simple_test(suite, "srvsvc", torture_samba3_rpc_srvsvc);
+ torture_suite_add_simple_test(suite, "sharesec", torture_samba3_rpc_sharesec);
+ torture_suite_add_simple_test(suite, "getusername", torture_samba3_rpc_getusername);
+ torture_suite_add_simple_test(suite, "randomauth2", torture_samba3_rpc_randomauth2);
+ torture_suite_add_simple_test(suite, "lsa", torture_samba3_rpc_lsa);
+ torture_suite_add_simple_test(suite, "spoolss", torture_samba3_rpc_spoolss);
+ torture_suite_add_simple_test(suite, "wkssvc", torture_samba3_rpc_wkssvc);
+ torture_suite_add_simple_test(suite, "winreg", torture_samba3_rpc_winreg);
+ torture_suite_add_simple_test(suite, "getaliasmembership-0", torture_samba3_getaliasmembership_0);
+ torture_suite_add_simple_test(suite, "regconfig", torture_samba3_regconfig);
+ torture_suite_add_simple_test(suite, "smb-reauth1", torture_rpc_smb_reauth1);
+ torture_suite_add_simple_test(suite, "smb-reauth2", torture_rpc_smb_reauth2);
+ torture_suite_add_simple_test(suite, "smb2-reauth1", torture_rpc_smb2_reauth1);
+ torture_suite_add_simple_test(suite, "smb2-reauth2", torture_rpc_smb2_reauth2);
+
+ suite->description = talloc_strdup(suite, "samba3 DCERPC interface tests");
+
+ return suite;
+}