s4:torture/smb2: add smb2.notify.session-reconnect test
authorStefan Metzmacher <metze@samba.org>
Sat, 2 May 2015 07:57:03 +0000 (09:57 +0200)
committerKarolin Seeger <kseeger@samba.org>
Wed, 20 May 2015 14:34:29 +0000 (16:34 +0200)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=11182

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit f435c89d61385272bf5b79f82f6e1373908d2b94)

source4/torture/smb2/notify.c

index 6031d1653cb593c2326d34e62429cd91591eaf8e..d8b32c703e6162bbe16d1874145fb8de224a0e65 100644 (file)
@@ -1450,6 +1450,86 @@ done:
        return ret;
 }
 
+/*
+  basic testing of change notifies followed by a session reconnect
+*/
+
+static bool torture_smb2_notify_session_reconnect(struct torture_context *torture,
+                               struct smb2_tree *tree1)
+{
+       bool ret = true;
+       NTSTATUS status;
+       union smb_notify notify;
+       union smb_open io;
+       struct smb2_handle h1;
+       struct smb2_request *req;
+       uint64_t previous_session_id = 0;
+       struct smb2_session *session2 = NULL;
+
+       smb2_deltree(tree1, BASEDIR);
+       smb2_util_rmdir(tree1, BASEDIR);
+
+       torture_comment(torture, "TESTING CHANGE NOTIFY FOLLOWED BY SESSION RECONNECT\n");
+
+       /*
+         get a handle on the directory
+       */
+       ZERO_STRUCT(io.smb2);
+       io.generic.level = RAW_OPEN_SMB2;
+       io.smb2.in.create_flags = 0;
+       io.smb2.in.desired_access = SEC_FILE_ALL;
+       io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+       io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+                               NTCREATEX_SHARE_ACCESS_WRITE;
+       io.smb2.in.alloc_size = 0;
+       io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
+       io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
+       io.smb2.in.security_flags = 0;
+       io.smb2.in.fname = BASEDIR;
+
+       status = smb2_create(tree1, torture, &(io.smb2));
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
+       status = smb2_create(tree1, torture, &(io.smb2));
+       CHECK_STATUS(status, NT_STATUS_OK);
+       h1 = io.smb2.out.file.handle;
+
+       /* ask for a change notify,
+          on file or directory name changes */
+       ZERO_STRUCT(notify.smb2);
+       notify.smb2.level = RAW_NOTIFY_SMB2;
+       notify.smb2.in.buffer_size = 1000;
+       notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
+       notify.smb2.in.file.handle = h1;
+       notify.smb2.in.recursive = true;
+
+       req = smb2_notify_send(tree1, &(notify.smb2));
+
+       WAIT_FOR_ASYNC_RESPONSE(req);
+
+       previous_session_id = smb2cli_session_current_id(tree1->session->smbXcli);
+       torture_assert(torture, torture_smb2_session_setup(torture,
+                      tree1->session->transport,
+                      previous_session_id,
+                      torture, &session2),
+                      "session setup with previous_session_id failed");
+
+       status = smb2_notify_recv(req, torture, &(notify.smb2));
+       CHECK_STATUS(status, STATUS_NOTIFY_CLEANUP);
+       CHECK_VAL(notify.smb2.out.num_changes, 0);
+
+       status = smb2_logoff(tree1->session);
+       CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
+
+       status = smb2_logoff(session2);
+       CHECK_STATUS(status, NT_STATUS_OK);
+done:
+       smb2_deltree(tree1, BASEDIR);
+       return ret;
+}
+
 /*
   basic testing of change notifies followed by an invalid reauth
 */
@@ -2220,6 +2300,7 @@ struct torture_suite *torture_smb2_notify_init(void)
        torture_suite_add_2smb2_test(suite, "mask-change", torture_smb2_notify_mask_change);
        torture_suite_add_1smb2_test(suite, "close", torture_smb2_notify_close);
        torture_suite_add_1smb2_test(suite, "logoff", torture_smb2_notify_ulogoff);
+       torture_suite_add_1smb2_test(suite, "session-reconnect", torture_smb2_notify_session_reconnect);
        torture_suite_add_2smb2_test(suite, "invalid-reauth", torture_smb2_notify_invalid_reauth);
        torture_suite_add_1smb2_test(suite, "tree", torture_smb2_notify_tree);
        torture_suite_add_2smb2_test(suite, "basedir", torture_smb2_notify_basedir);