void nb_write(int handle, int size, int offset) { int i; if (buf[0] == 0) memset(buf, 1, sizeof(buf)); for (i=0;i<MAX_FILES;i++) { if (ftable[i].handle == handle) break; } if (i == MAX_FILES) { #if NBDEBUG printf("(%d) nb_write: handle %d was not open size=%d ofs=%d\n", line_count, handle, size, offset); #endif return; } if (cli_smbwrite(c, ftable[i].fd, buf, offset, size) != size) { printf("(%d) write failed on handle %d\n", line_count, handle); } }
bool run_cleanup2(int dummy) { struct cli_state *cli1, *cli2, *cli3; const char *fname = "\\cleanup2"; uint16_t fnum1, fnum2, fnum3; NTSTATUS status; char buf; printf("CLEANUP2: Checking that a conflicting brlock is cleaned up\n"); if (!torture_open_connection(&cli1, 0)) { return false; } status = cli_ntcreate( cli1, fname, 0, FILE_GENERIC_READ|FILE_GENERIC_WRITE, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); if (!NT_STATUS_IS_OK(status)) { printf("open of %s failed (%s)\n", fname, nt_errstr(status)); return false; } status = cli_lock32(cli1, fnum1, 0, 1, 0, WRITE_LOCK); if (!NT_STATUS_IS_OK(status)) { printf("lock failed (%s)\n", nt_errstr(status)); return false; } if (!torture_open_connection(&cli3, 1)) { return false; } status = cli_ntcreate( cli3, fname, 0, FILE_GENERIC_READ|FILE_GENERIC_WRITE, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum3, NULL); if (!NT_STATUS_IS_OK(status)) { printf("open of %s failed (%s)\n", fname, nt_errstr(status)); return false; } status = cli_lock32(cli3, fnum3, 1, 1, 0, WRITE_LOCK); if (!NT_STATUS_IS_OK(status)) { printf("lock failed (%s)\n", nt_errstr(status)); return false; } status = cli_lock32(cli1, fnum1, 2, 1, 0, WRITE_LOCK); if (!NT_STATUS_IS_OK(status)) { printf("lock failed (%s)\n", nt_errstr(status)); return false; } /* * Check the file is indeed locked */ if (!torture_open_connection(&cli2, 1)) { return false; } status = cli_ntcreate( cli2, fname, 0, FILE_GENERIC_READ|FILE_GENERIC_WRITE, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2, NULL); if (!NT_STATUS_IS_OK(status)) { printf("open of %s failed (%s)\n", fname, nt_errstr(status)); return false; } buf = 'x'; status = cli_smbwrite(cli2, fnum2, &buf, 0, 1, NULL); if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) { printf("write succeeded\n"); return false; } /* * Kill the lock holder */ status = smbXcli_conn_samba_suicide(cli1->conn, 1); if (!NT_STATUS_IS_OK(status)) { printf("smbXcli_conn_samba_suicide failed: %s\n", nt_errstr(status)); return false; } /* * Give the suicidal smbd a bit of time to really pass away */ smb_msleep(1000); status = cli_smbwrite(cli2, fnum2, &buf, 0, 1, NULL); if (!NT_STATUS_IS_OK(status)) { printf("write failed: %s\n", nt_errstr(status)); return false; } return true; }