X-Git-Url: http://git.samba.org/?p=samba.git;a=blobdiff_plain;f=source4%2Ftorture%2Futil_smb.c;h=216927ce70dcc3c527a32d59e38061ccb47ac5d7;hp=c1a20094f385e520828823fd1c414df8f9d7c330;hb=8edab1b96c47e75b2f2c61739f9283fa2ecf5cfe;hpb=68a2c547d00d7a8d0c15744172489d9d010c31a3 diff --git a/source4/torture/util_smb.c b/source4/torture/util_smb.c index c1a20094f38..216927ce70d 100644 --- a/source4/torture/util_smb.c +++ b/source4/torture/util_smb.c @@ -28,12 +28,12 @@ #include "system/shmem.h" #include "system/wait.h" #include "system/time.h" -#include "torture/ui.h" #include "torture/torture.h" -#include "util/dlinklist.h" -#include "auth/credentials/credentials.h" +#include "../lib/util/dlinklist.h" #include "libcli/resolve/resolve.h" #include "param/param.h" +#include "libcli/security/security.h" +#include "libcli/util/clilsa.h" /** @@ -62,12 +62,12 @@ NTSTATUS create_directory_handle(struct smbcli_tree *tree, const char *dname, in mem_ctx = talloc_named_const(tree, 0, "create_directory_handle"); io.generic.level = RAW_OPEN_NTCREATEX; - io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.flags = 0; io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; - io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE; + io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE; io.ntcreatex.in.alloc_size = 0; io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF; io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; @@ -129,14 +129,17 @@ _PUBLIC_ int create_complex_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, } } - /* make sure all the timestamps aren't the same, and are also - in different DST zones*/ - setfile.generic.level = RAW_SFILEINFO_SETATTRE; + /* make sure all the timestamps aren't the same */ + ZERO_STRUCT(setfile); + setfile.generic.level = RAW_SFILEINFO_BASIC_INFO; setfile.generic.in.file.fnum = fnum; - setfile.setattre.in.create_time = t + 9*30*24*60*60; - setfile.setattre.in.access_time = t + 6*30*24*60*60; - setfile.setattre.in.write_time = t + 3*30*24*60*60; + unix_to_nt_time(&setfile.basic_info.in.create_time, + t + 9*30*24*60*60); + unix_to_nt_time(&setfile.basic_info.in.access_time, + t + 6*30*24*60*60); + unix_to_nt_time(&setfile.basic_info.in.write_time, + t + 3*30*24*60*60); status = smb_raw_setfileinfo(cli->tree, &setfile); if (!NT_STATUS_IS_OK(status)) { @@ -144,7 +147,7 @@ _PUBLIC_ int create_complex_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, } /* make sure all the timestamps aren't the same */ - fileinfo.generic.level = RAW_FILEINFO_GETATTRE; + fileinfo.generic.level = RAW_FILEINFO_BASIC_INFO; fileinfo.generic.in.file.fnum = fnum; status = smb_raw_fileinfo(cli->tree, mem_ctx, &fileinfo); @@ -152,13 +155,13 @@ _PUBLIC_ int create_complex_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, printf("Failed to query file times - %s\n", nt_errstr(status)); } - if (setfile.setattre.in.create_time != fileinfo.getattre.out.create_time) { + if (setfile.basic_info.in.create_time != fileinfo.basic_info.out.create_time) { printf("create_time not setup correctly\n"); } - if (setfile.setattre.in.access_time != fileinfo.getattre.out.access_time) { + if (setfile.basic_info.in.access_time != fileinfo.basic_info.out.access_time) { printf("access_time not setup correctly\n"); } - if (setfile.setattre.in.write_time != fileinfo.getattre.out.write_time) { + if (setfile.basic_info.in.write_time != fileinfo.basic_info.out.write_time) { printf("write_time not setup correctly\n"); } @@ -206,14 +209,17 @@ int create_complex_dir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char } } - /* make sure all the timestamps aren't the same, and are also - in different DST zones*/ - setfile.generic.level = RAW_SFILEINFO_SETATTRE; + /* make sure all the timestamps aren't the same */ + ZERO_STRUCT(setfile); + setfile.generic.level = RAW_SFILEINFO_BASIC_INFO; setfile.generic.in.file.fnum = fnum; - setfile.setattre.in.create_time = t + 9*30*24*60*60; - setfile.setattre.in.access_time = t + 6*30*24*60*60; - setfile.setattre.in.write_time = t + 3*30*24*60*60; + unix_to_nt_time(&setfile.basic_info.in.create_time, + t + 9*30*24*60*60); + unix_to_nt_time(&setfile.basic_info.in.access_time, + t + 6*30*24*60*60); + unix_to_nt_time(&setfile.basic_info.in.write_time, + t + 3*30*24*60*60); status = smb_raw_setfileinfo(cli->tree, &setfile); if (!NT_STATUS_IS_OK(status)) { @@ -221,7 +227,7 @@ int create_complex_dir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char } /* make sure all the timestamps aren't the same */ - fileinfo.generic.level = RAW_FILEINFO_GETATTRE; + fileinfo.generic.level = RAW_FILEINFO_BASIC_INFO; fileinfo.generic.in.file.fnum = fnum; status = smb_raw_fileinfo(cli->tree, mem_ctx, &fileinfo); @@ -229,13 +235,13 @@ int create_complex_dir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char printf("Failed to query file times - %s\n", nt_errstr(status)); } - if (setfile.setattre.in.create_time != fileinfo.getattre.out.create_time) { + if (setfile.basic_info.in.create_time != fileinfo.basic_info.out.create_time) { printf("create_time not setup correctly\n"); } - if (setfile.setattre.in.access_time != fileinfo.getattre.out.access_time) { + if (setfile.basic_info.in.access_time != fileinfo.basic_info.out.access_time) { printf("access_time not setup correctly\n"); } - if (setfile.setattre.in.write_time != fileinfo.getattre.out.write_time) { + if (setfile.basic_info.in.write_time != fileinfo.basic_info.out.write_time) { printf("write_time not setup correctly\n"); } @@ -258,6 +264,23 @@ void *shm_setup(int size) int shmid; void *ret; +#ifdef __QNXNTO__ + shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + if (shmid == -1) { + printf("can't get shared memory\n"); + exit(1); + } + shm_unlink("private"); + if (ftruncate(shmid, size) == -1) { + printf("can't set shared memory size\n"); + exit(1); + } + ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0); + if (ret == MAP_FAILED) { + printf("can't map shared memory\n"); + exit(1); + } +#else shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W); if (shmid == -1) { printf("can't get shared memory\n"); @@ -276,6 +299,7 @@ void *shm_setup(int size) See Stevens "advanced programming in unix env" for details */ shmctl(shmid, IPC_RMID, 0); +#endif return ret; } @@ -471,13 +495,15 @@ _PUBLIC_ bool torture_open_connection_share(TALLOC_CTX *mem_ctx, struct torture_context *tctx, const char *hostname, const char *sharename, - struct event_context *ev) + struct tevent_context *ev) { NTSTATUS status; 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); options.use_oplocks = torture_setting_bool(tctx, "use_oplocks", true); options.use_level2_oplocks = torture_setting_bool(tctx, "use_level2_oplocks", true); @@ -485,9 +511,12 @@ _PUBLIC_ bool torture_open_connection_share(TALLOC_CTX *mem_ctx, status = smbcli_full_connection(mem_ctx, c, hostname, lp_smb_ports(tctx->lp_ctx), sharename, NULL, + lp_socket_options(tctx->lp_ctx), cmdline_credentials, lp_resolve_context(tctx->lp_ctx), - ev, &options); + ev, &options, &session_options, + lp_iconv_convenience(tctx->lp_ctx), + lp_gensec_settings(tctx, tctx->lp_ctx)); if (!NT_STATUS_IS_OK(status)) { printf("Failed to open connection - %s\n", nt_errstr(status)); return false; @@ -513,14 +542,17 @@ _PUBLIC_ bool torture_get_conn_index(int conn_index, return true; } - unc_list = file_lines_load(p, &num_unc_names, NULL); + unc_list = file_lines_load(p, &num_unc_names, 0, NULL); if (!unc_list || num_unc_names <= 0) { DEBUG(0,("Failed to load unc names list from '%s'\n", p)); return false; } - if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names], - mem_ctx, host, share)) { + p = unc_list[conn_index % num_unc_names]; + if (p[0] != '/' && p[0] != '\\') { + /* allow UNC lists of hosts */ + (*host) = talloc_strdup(mem_ctx, p); + } else if (!smbcli_parse_unc(p, mem_ctx, host, share)) { DEBUG(0, ("Failed to parse UNC name %s\n", unc_list[conn_index % num_unc_names])); return false; @@ -535,7 +567,7 @@ _PUBLIC_ bool torture_get_conn_index(int conn_index, _PUBLIC_ bool torture_open_connection_ev(struct smbcli_state **c, int conn_index, struct torture_context *tctx, - struct event_context *ev) + struct tevent_context *ev) { char *host, *share; bool ret; @@ -579,10 +611,10 @@ _PUBLIC_ bool check_error(const char *location, struct smbcli_state *c, status = smbcli_nt_error(c->tree); if (NT_STATUS_IS_DOS(status)) { - int class, num; - class = NT_STATUS_DOS_CLASS(status); + int classnum, num; + classnum = NT_STATUS_DOS_CLASS(status); num = NT_STATUS_DOS_CODE(status); - if (eclass != class || ecode != num) { + if (eclass != classnum || ecode != num) { printf("unexpected error code %s\n", nt_errstr(status)); printf(" expected %s or %s (at %s)\n", nt_errstr(NT_STATUS_DOS(eclass, ecode)), @@ -652,7 +684,10 @@ double torture_create_procs(struct torture_context *tctx, pid_t mypid = getpid(); srandom(((int)mypid) ^ ((int)time(NULL))); - asprintf(&myname, "CLIENT%d", i); + if (asprintf(&myname, "CLIENT%d", i) == -1) { + printf("asprintf failed\n"); + return -1; + } lp_set_cmdline(tctx->lp_ctx, "netbios name", myname); free(myname); @@ -902,3 +937,37 @@ NTSTATUS torture_second_tcon(TALLOC_CTX *mem_ctx, talloc_free(tmp_ctx); return NT_STATUS_OK; } + +/* + a wrapper around smblsa_sid_check_privilege, that tries to take + account of the fact that the lsa privileges calls don't expand + group memberships, using an explicit check for administrator. There + must be a better way ... + */ +NTSTATUS torture_check_privilege(struct smbcli_state *cli, + const char *sid_str, + const char *privilege) +{ + struct dom_sid *sid; + TALLOC_CTX *tmp_ctx = talloc_new(cli); + uint32_t rid; + NTSTATUS status; + + sid = dom_sid_parse_talloc(tmp_ctx, sid_str); + if (sid == NULL) { + talloc_free(tmp_ctx); + return NT_STATUS_INVALID_SID; + } + + status = dom_sid_split_rid(tmp_ctx, sid, NULL, &rid); + NT_STATUS_NOT_OK_RETURN_AND_FREE(status, tmp_ctx); + + if (rid == DOMAIN_RID_ADMINISTRATOR) { + /* assume the administrator has them all */ + return NT_STATUS_OK; + } + + talloc_free(tmp_ctx); + + return smblsa_sid_check_privilege(cli, sid_str, privilege); +}