#include "libcli/raw/interfaces.h"
#include "lib/cmdline/popt_common.h"
#include "auth/credentials/credentials.h"
+#include "param/param.h"
+#include "libcli/resolve/resolve.h"
/* Size (in bytes) of the required fields in the SMBwhoami response. */
#define WHOAMI_REQUIRED_SIZE 40
struct dom_sid ** sid_list;
};
-static struct smbcli_state *connect_to_server(void *mem_ctx,
+static struct smbcli_state *connect_to_server(struct torture_context *tctx,
struct cli_credentials *creds)
{
NTSTATUS status;
struct smbcli_state *cli;
- const char *host = lp_parm_string(-1, "torture", "host");
- const char *share = lp_parm_string(-1, "torture", "share");
+ const char *host = torture_setting_string(tctx, "host", NULL);
+ const char *share = torture_setting_string(tctx, "share", NULL);
- status = smbcli_full_connection(mem_ctx, &cli,
- host, share, NULL,
- creds, NULL);
+ status = smbcli_full_connection(tctx, &cli, host,
+ lp_smb_ports(tctx->lp_ctx),
+ share, NULL,
+ creds, lp_resolve_context(tctx->lp_ctx),
+ NULL);
if (!NT_STATUS_IS_OK(status)) {
printf("failed to connect to //%s/%s: %s\n",
return cli;
}
-static BOOL sid_parse(void *mem_ctx,
+static bool sid_parse(void *mem_ctx,
struct torture_context *torture,
DATA_BLOB *data, size_t *offset,
struct dom_sid **psid)
(*offset) += 4;
}
- return True;
+ return true;
}
-static BOOL smb_raw_query_posix_whoami(void *mem_ctx,
+static bool smb_raw_query_posix_whoami(void *mem_ctx,
struct torture_context *torture,
struct smbcli_state *cli,
struct smb_whoami *whoami,
printf("\tmapping_flags=0x%08x mapping_mask=0x%08x\n",
whoami->mapping_flags, whoami->mapping_mask);
- printf("\tserver UID=%lld GID=%lld\n",
- whoami->server_uid, whoami->server_gid);
+ printf("\tserver UID=%llu GID=%llu\n",
+ (unsigned long long)whoami->server_uid, (unsigned long long)whoami->server_gid);
printf("\t%u GIDs, %u SIDs, %u SID bytes\n",
whoami->num_gids, whoami->num_sids,
whoami->num_sid_bytes);
"invalid SID count");
torture_assert_int_equal(torture, whoami->num_sid_bytes, 0,
"invalid SID byte count");
- return True;
+ return true;
}
if (whoami->num_gids != 0) {
if (tp.out.data.length == offset) {
torture_assert_int_equal(torture, whoami->num_sids, 0,
"invalid SID count");
- return True;
+ return true;
}
/* All the remaining bytes must be the SID list. */
if (!sid_parse(mem_ctx, torture,
&tp.out.data, &offset,
&whoami->sid_list[i])) {
- return False;
+ return false;
}
}
torture_assert_int_equal(torture, tp.out.data.length, offset,
"trailing garbage bytes");
- return True;
+ return true;
}
-BOOL torture_unix_whoami(struct torture_context *torture)
+bool torture_unix_whoami(struct torture_context *torture)
{
struct smbcli_state *cli;
struct cli_credentials *anon_credentials;
struct smb_whoami whoami;
- void *mem_ctx;
- mem_ctx = talloc_init("smb_query_posix_whoami");
- torture_assert(torture, mem_ctx != NULL, "malloc failed");
-
- if (!(cli = connect_to_server(mem_ctx, cmdline_credentials))) {
- goto fail;
+ if (!(cli = connect_to_server(torture, cmdline_credentials))) {
+ return false;
}
/* Test basic authenticated mapping. */
printf("calling SMB_QFS_POSIX_WHOAMI on an authenticated connection\n");
- if (!smb_raw_query_posix_whoami(mem_ctx, torture,
+ if (!smb_raw_query_posix_whoami(torture, torture,
cli, &whoami, 0xFFFF)) {
smbcli_tdis(cli);
- goto fail;
+ return false;
}
/* Test that the server drops the UID and GID list. */
printf("calling SMB_QFS_POSIX_WHOAMI with a small buffer\n");
- if (!smb_raw_query_posix_whoami(mem_ctx, torture,
+ if (!smb_raw_query_posix_whoami(torture, torture,
cli, &whoami, 0x40)) {
smbcli_tdis(cli);
- goto fail;
+ return false;
}
torture_assert_int_equal(torture, whoami.num_gids, 0,
smbcli_tdis(cli);
printf("calling SMB_QFS_POSIX_WHOAMI on an anonymous connection\n");
- anon_credentials = cli_credentials_init_anon(mem_ctx);
+ anon_credentials = cli_credentials_init_anon(torture);
- if (!(cli = connect_to_server(mem_ctx, anon_credentials))) {
- goto fail;
+ if (!(cli = connect_to_server(torture, anon_credentials))) {
+ return false;
}
- if (!smb_raw_query_posix_whoami(mem_ctx, torture,
+ if (!smb_raw_query_posix_whoami(torture, torture,
cli, &whoami, 0xFFFF)) {
smbcli_tdis(cli);
- goto fail;
+ return false;
}
smbcli_tdis(cli);
printf("server does not support SMB_WHOAMI_GUEST flag\n");
}
- talloc_free(mem_ctx);
- return True;
-
-fail:
- talloc_free(mem_ctx);
- return False;
-
+ return true;
}
/* vim: set sts=8 sw=8 : */