/*
Unix SMB/CIFS implementation.
test suite for wkssvc rpc operations
Copyright (C) Andrew Tridgell 2003
Copyright (C) Günther Deschner 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
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 .
*/
#include "includes.h"
#include "torture/torture.h"
#include "librpc/gen_ndr/ndr_wkssvc_c.h"
#include "torture/rpc/rpc.h"
#include "lib/cmdline/popt_common.h"
#include "param/param.h"
#define SMBTORTURE_MACHINE_NAME "smbtrt_name"
#define SMBTORTURE_ALTERNATE_NAME "smbtrt_altname"
#define SMBTORTURE_TRANSPORT_NAME "\\Device\\smbtrt_transport_name"
#define SMBTORTURE_USE_NAME "S:"
#define SMBTORTURE_MESSAGE "You are currently tortured by Samba"
static bool test_NetWkstaGetInfo(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
NTSTATUS status;
struct wkssvc_NetWkstaGetInfo r;
union wkssvc_NetWkstaInfo info;
uint16_t levels[] = {100, 101, 102, 502};
int i;
r.in.server_name = dcerpc_server_name(p);
r.out.info = &info;
for (i=0;iinfo0 = &info0;
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
r.in.level = 0;
r.in.ctr = ctr;
r.in.parm_err = r.out.parm_err = &parm_err;
torture_comment(tctx, "testing NetrUseAdd level %u\n",
r.in.level);
status = dcerpc_wkssvc_NetrUseAdd(p, tctx, &r);
torture_assert_ntstatus_ok(tctx, status,
"NetrUseAdd failed");
torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL,
"NetrUseAdd failed");
ZERO_STRUCT(r);
ZERO_STRUCT(info1);
info1.local = SMBTORTURE_USE_NAME;
info1.remote = "\\\\localhost\\sysvol";
info1.password = NULL;
ctr->info1 = &info1;
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
r.in.level = 1;
r.in.ctr = ctr;
r.in.parm_err = r.out.parm_err = &parm_err;
torture_comment(tctx, "testing NetrUseAdd level %u\n",
r.in.level);
status = dcerpc_wkssvc_NetrUseAdd(p, tctx, &r);
torture_assert_ntstatus_ok(tctx, status,
"NetrUseAdd failed");
torture_assert_werr_ok(tctx, r.out.result,
"NetrUseAdd failed");
return true;
}
static bool test_NetrUseDel(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
NTSTATUS status;
struct wkssvc_NetrUseDel r;
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
r.in.use_name = SMBTORTURE_USE_NAME;
r.in.force_cond = 0;
torture_comment(tctx, "testing NetrUseDel\n");
status = dcerpc_wkssvc_NetrUseDel(p, tctx, &r);
torture_assert_ntstatus_ok(tctx, status,
"NetrUseDel failed");
torture_assert_werr_ok(tctx, r.out.result,
"NetrUseDel failed");
return true;
}
static bool test_NetrUseGetInfo_level(struct torture_context *tctx,
struct dcerpc_pipe *p,
const char *use_name,
uint32_t level,
WERROR werr)
{
NTSTATUS status;
struct wkssvc_NetrUseGetInfo r;
union wkssvc_NetrUseGetInfoCtr ctr;
ZERO_STRUCT(ctr);
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
r.in.use_name = use_name;
r.in.level = level;
r.out.ctr = &ctr;
status = dcerpc_wkssvc_NetrUseGetInfo(p, tctx, &r);
torture_assert_ntstatus_ok(tctx, status,
"NetrUseGetInfo failed");
torture_assert_werr_equal(tctx, r.out.result, werr,
"NetrUseGetInfo failed");
return true;
}
static bool test_NetrUseGetInfo(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
NTSTATUS status;
struct wkssvc_NetrUseEnum r;
uint32_t handle = 0;
uint32_t entries_read = 0;
struct wkssvc_NetrUseEnumInfo info;
struct wkssvc_NetrUseEnumCtr0 *use0;
uint32_t levels[] = { 0, 1, 2 };
const char *use_name = NULL;
int i, k;
ZERO_STRUCT(info);
info.level = 0;
use0 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr0);
info.ctr.ctr0 = use0;
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
r.in.prefmaxlen = (uint32_t)-1;
r.in.info = r.out.info = &info;
r.in.resume_handle = r.out.resume_handle = &handle;
r.out.entries_read = &entries_read;
status = dcerpc_wkssvc_NetrUseEnum(p, tctx, &r);
torture_assert_ntstatus_ok(tctx, status,
"NetrUseEnum failed");
torture_assert_werr_ok(tctx, r.out.result,
"NetrUseEnum failed");
for (k=0; k < r.out.info->ctr.ctr0->count; k++) {
use_name = r.out.info->ctr.ctr0->array[k].local;
for (i=0; ictr.ctr0->array[k].remote;
for (i=0; icount != 1) {
torture_comment(tctx,
"NetrEnumerateComputerNames did not return one "
"name but %u\n", ctr->count);
return false;
}
if (names && num_names) {
*num_names = 0;
*names = NULL;
for (i=0; icount; i++) {
if (!add_string_to_array(tctx,
ctr->computer_name[i].string,
names,
num_names))
{
return false;
}
}
}
return true;
}
static bool test_NetrEnumerateComputerNames(struct torture_context *tctx,
struct dcerpc_pipe *p)
{
uint16_t levels[] = {0,1,2};
int i;
for (i=0; idangerous = true;
test = torture_rpc_tcase_add_test(tcase, "NetrRenameMachineInDomain",
test_NetrRenameMachineInDomain);
test->dangerous = true;
test = torture_rpc_tcase_add_test(tcase, "NetrRenameMachineInDomain2",
test_NetrRenameMachineInDomain2);
test->dangerous = true;
torture_rpc_tcase_add_test(tcase, "NetrEnumerateComputerNames",
test_NetrEnumerateComputerNames);
torture_rpc_tcase_add_test(tcase, "NetrGetJoinInformation",
test_NetrGetJoinInformation);
torture_rpc_tcase_add_test(tcase, "NetrGetJoinableOus",
test_NetrGetJoinableOus);
torture_rpc_tcase_add_test(tcase, "NetrGetJoinableOus2",
test_NetrGetJoinableOus2);
torture_rpc_tcase_add_test(tcase, "NetrWorkstationStatisticsGet",
test_NetrWorkstationStatisticsGet);
torture_rpc_tcase_add_test(tcase, "NetrMessageBufferSend",
test_NetrMessageBufferSend);
return suite;
}