r23792: convert Samba4 to GPLv3
[bbaumbach/samba-autobuild/.git] / source4 / torture / raw / notify.c
index 74f33f0dbd9b485c9ca2b2bd5c4afde05f12905c..5be1b612d3ba4676146d38ef7d92bb7bf3400ea1 100644 (file)
@@ -5,7 +5,7 @@
    
    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,
@@ -14,8 +14,7 @@
    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"
@@ -137,6 +136,7 @@ static BOOL test_notify_dir(struct smbcli_state *cli, struct smbcli_state *cli2,
        smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
        smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
        smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
+       msleep(200);
        req = smb_raw_changenotify_send(cli->tree, &notify);
        status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -291,8 +291,6 @@ static BOOL check_rename_reply(struct smbcli_state *cli,
        return False;
 }
 
-
-
 /* 
    testing of recursive change notify
 */
@@ -424,6 +422,124 @@ done:
        return ret;
 }
 
+/* 
+   testing of change notify mask change
+*/
+static BOOL test_notify_mask_change(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+       BOOL ret = True;
+       NTSTATUS status;
+       union smb_notify notify;
+       union smb_open io;
+       int fnum;
+       struct smbcli_request *req1, *req2;
+       union smb_setfileinfo sfinfo;
+
+       printf("TESTING CHANGE NOTIFY WITH MASK CHANGE\n");
+
+       /*
+         get a handle on the directory
+       */
+       io.generic.level = RAW_OPEN_NTCREATEX;
+       io.ntcreatex.in.root_fid = 0;
+       io.ntcreatex.in.flags = 0;
+       io.ntcreatex.in.access_mask = SEC_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.alloc_size = 0;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+       io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+       io.ntcreatex.in.security_flags = 0;
+       io.ntcreatex.in.fname = BASEDIR;
+
+       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       fnum = io.ntcreatex.out.file.fnum;
+
+       /* ask for a change notify, on file or directory name
+          changes. Setup both with and without recursion */
+       notify.nttrans.level = RAW_NOTIFY_NTTRANS;
+       notify.nttrans.in.buffer_size = 1000;
+       notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
+       notify.nttrans.in.file.fnum = fnum;
+
+       notify.nttrans.in.recursive = True;
+       req1 = smb_raw_changenotify_send(cli->tree, &notify);
+
+       notify.nttrans.in.recursive = False;
+       req2 = smb_raw_changenotify_send(cli->tree, &notify);
+
+       /* cancel initial requests so the buffer is setup */
+       smb_raw_ntcancel(req1);
+       status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);
+       CHECK_STATUS(status, NT_STATUS_CANCELLED);
+
+       smb_raw_ntcancel(req2);
+       status = smb_raw_changenotify_recv(req2, mem_ctx, &notify);
+       CHECK_STATUS(status, NT_STATUS_CANCELLED);
+
+       notify.nttrans.in.recursive = True;
+       req1 = smb_raw_changenotify_send(cli->tree, &notify);
+
+       /* Set to hidden then back again. */
+       smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));
+       smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
+       smbcli_unlink(cli->tree, BASEDIR "\\tname1");
+
+       status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       CHECK_VAL(notify.nttrans.out.num_changes, 1);
+       CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
+       CHECK_WSTR(notify.nttrans.out.changes[0].name, "tname1", STR_UNICODE);
+
+       /* Now try and change the mask to include other events.
+        * This should not work - once the mask is set on a directory
+        * fnum it seems to be fixed until the fnum is closed. */
+
+       notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
+       notify.nttrans.in.recursive = True;
+       req1 = smb_raw_changenotify_send(cli->tree, &notify);
+
+       notify.nttrans.in.recursive = False;
+       req2 = smb_raw_changenotify_send(cli->tree, &notify);
+
+       smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
+       smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
+       smbcli_close(cli->tree, 
+                    smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
+       smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
+       smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
+       smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
+
+       smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
+       smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
+       smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
+
+       status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       CHECK_VAL(notify.nttrans.out.num_changes, 1);
+       CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
+       CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname2-r", STR_UNICODE);
+
+       status = smb_raw_changenotify_recv(req2, mem_ctx, &notify);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       CHECK_VAL(notify.nttrans.out.num_changes, 1);
+       CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
+       CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname3-r", STR_UNICODE);
+
+       if (!ret) {
+               goto done;
+       }
+
+done:
+       smb_raw_exit(cli->session);
+       return ret;
+}
+
 
 /* 
    testing of mask bits for change notify
@@ -1189,6 +1305,7 @@ BOOL torture_raw_notify(struct torture_context *torture)
        ret &= test_notify_dir(cli, cli2, mem_ctx);
        ret &= test_notify_mask(cli, mem_ctx);
        ret &= test_notify_recursive(cli, mem_ctx);
+       ret &= test_notify_mask_change(cli, mem_ctx);
        ret &= test_notify_file(cli, mem_ctx);
        ret &= test_notify_tdis(mem_ctx);
        ret &= test_notify_exit(mem_ctx);