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 2 of the License, or
+ 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,
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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "libcli/raw/interfaces.h"
#include "lib/cmdline/popt_common.h"
#include "auth/credentials/credentials.h"
-
-#define SMB_QUERY_POSIX_WHOAMI 0x202
+#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,
- cmdline_credentials, 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,
tp.in.max_data = (uint16_t)max_data;
tp.in.setup = &setup;
tp.in.trans_name = NULL;
- SSVAL(&info_level, 0, SMB_QUERY_POSIX_WHOAMI);
+ SSVAL(&info_level, 0, SMB_QFS_POSIX_WHOAMI);
tp.in.params = data_blob_talloc(mem_ctx, &info_level, 2);
tp.in.data = data_blob_talloc(mem_ctx, NULL, 0);
status = smb_raw_trans2(cli->tree, mem_ctx, &tp);
torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK,
- "doing SMB_QUERY_POSIX_WHOAMI");
+ "doing SMB_QFS_POSIX_WHOAMI");
/* Make sure we got back all the required fields. */
torture_assert(torture, tp.out.params.length == 0,
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))) {
- goto fail;
+ if (!(cli = connect_to_server(torture, cmdline_credentials))) {
+ return false;
}
/* Test basic authenticated mapping. */
- printf("calling SMB_QUERY_POSIX_WHOAMI on an authenticated connection\n");
- if (!smb_raw_query_posix_whoami(mem_ctx, torture,
+ printf("calling SMB_QFS_POSIX_WHOAMI on an authenticated connection\n");
+ 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_QUERY_POSIX_WHOAMI with a small buffer\n");
- if (!smb_raw_query_posix_whoami(mem_ctx, torture,
+ printf("calling SMB_QFS_POSIX_WHOAMI with a small buffer\n");
+ 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,
"invalid SID bytes count");
smbcli_tdis(cli);
- cli_credentials_set_anonymous(cmdline_credentials);
- if (!(cli = connect_to_server(mem_ctx))) {
- goto fail;
+ printf("calling SMB_QFS_POSIX_WHOAMI on an anonymous connection\n");
+ anon_credentials = cli_credentials_init_anon(torture);
+
+ if (!(cli = connect_to_server(torture, anon_credentials))) {
+ return false;
}
- printf("calling SMB_QUERY_POSIX_WHOAMI on an anonymous 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;
}
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 : */