bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
{
- uint16 old_vuid = cli->vuid;
+ uint16_t old_vuid = cli_state_get_uid(cli);
fstring old_user_name;
size_t passlen = strlen(password);
NTSTATUS status;
bool ret;
fstrcpy(old_user_name, cli->user_name);
- cli->vuid = 0;
+ cli_state_set_uid(cli, 0);
ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
password, passlen,
password, passlen,
workgroup));
- *new_vuid = cli->vuid;
- cli->vuid = old_vuid;
+ *new_vuid = cli_state_get_uid(cli);
+ cli_state_set_uid(cli, old_vuid);
status = cli_set_username(cli, old_user_name);
if (!NT_STATUS_IS_OK(status)) {
return false;
char buf[131072];
char buf_rd[131072];
bool correct = True;
- ssize_t bytes_read;
+ size_t bytes_read;
NTSTATUS status;
status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
break;
}
- if ((bytes_read = cli_read_old(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
- printf("read failed (%s)\n", cli_errstr(c2));
- printf("read %d, expected %ld\n", (int)bytes_read,
+ status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
+ if(!NT_STATUS_IS_OK(status)) {
+ printf("read failed (%s)\n", nt_errstr(status));
+ correct = false;
+ break;
+ } else if (bytes_read != buf_size) {
+ printf("read failed\n");
+ printf("read %ld, expected %ld\n",
+ (unsigned long)bytes_read,
(unsigned long)buf_size);
correct = False;
break;
}
cnum1 = cli_state_get_tid(cli);
- vuid1 = cli->vuid;
+ vuid1 = cli_state_get_uid(cli);
status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
if (!NT_STATUS_IS_OK(status)) {
cnum2 = cli_state_get_tid(cli);
cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
- vuid2 = cli->vuid + 1;
+ vuid2 = cli_state_get_uid(cli) + 1;
/* try a write with the wrong tid */
cli_state_set_tid(cli, cnum2);
}
/* try a write with an invalid vuid */
- cli->vuid = vuid2;
+ cli_state_set_uid(cli, vuid2);
cli_state_set_tid(cli, cnum1);
status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
}
cli_state_set_tid(cli, cnum1);
- cli->vuid = vuid1;
+ cli_state_set_uid(cli, vuid1);
status = cli_close(cli, fnum1);
if (!NT_STATUS_IS_OK(status)) {
return correct;
}
+static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
+ char *buf, off_t offset, size_t size,
+ size_t *nread, size_t expect)
+{
+ NTSTATUS status;
+ size_t l_nread;
+
+ status = cli_read(cli, fnum, buf, offset, size, &l_nread);
+
+ if(!NT_STATUS_IS_OK(status)) {
+ return false;
+ } else if (l_nread != expect) {
+ return false;
+ }
+
+ if (nread) {
+ *nread = l_nread;
+ }
+
+ return true;
+}
+
#define EXPECTED(ret, v) if ((ret) != (v)) { \
printf("** "); correct = False; \
}
ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
- (cli_read_old(cli2, fnum2, buf, 120, 4) == 4);
+ test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
EXPECTED(ret, False);
printf("this server %s strict write locking\n", ret?"doesn't do":"does");
ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
- (cli_read_old(cli2, fnum2, buf, 150, 4) == 4) &&
+ test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
!(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
150, 4, NULL))) &&
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
160, 4, NULL)) &&
- (cli_read_old(cli2, fnum2, buf, 160, 4) == 4);
+ test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
EXPECTED(ret, True);
printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
170, 4, NULL)) &&
- (cli_read_old(cli2, fnum2, buf, 170, 4) == 4);
+ test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
EXPECTED(ret, True);
printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
!NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
190, 4, NULL)) &&
- (cli_read_old(cli2, fnum2, buf, 190, 4) == 4);
+ test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
EXPECTED(ret, True);
printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
uint16_t fnum1;
char buf[200];
bool correct = False;
+ size_t nread;
NTSTATUS status;
if (!torture_open_connection(&cli1, 0)) {
status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
if (!NT_STATUS_IS_OK(status)) {
- printf("Unable to apply read lock on range 130:4, error was %s\n", nt_errstr(status));
+ printf("Unable to apply read lock on range 130:4, "
+ "error was %s\n", nt_errstr(status));
goto fail;
} else {
printf("pid1 successfully locked range 130:4 for READ\n");
}
- if (cli_read_old(cli1, fnum1, buf, 130, 4) != 4) {
- printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
+ status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("pid1 unable to read the range 130:4, error was %s\n",
+ nt_errstr(status));
+ goto fail;
+ } else if (nread != 4) {
+ printf("pid1 unable to read the range 130:4, "
+ "recv %ld req %d\n", (unsigned long)nread, 4);
goto fail;
} else {
printf("pid1 successfully read the range 130:4\n");
cli_setpid(cli1, 2);
- if (cli_read_old(cli1, fnum1, buf, 130, 4) != 4) {
- printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
+ status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("pid2 unable to read the range 130:4, error was %s\n",
+ nt_errstr(status));
+ goto fail;
+ } else if (nread != 4) {
+ printf("pid2 unable to read the range 130:4, "
+ "recv %ld req %d\n", (unsigned long)nread, 4);
+ goto fail;
} else {
printf("pid2 successfully read the range 130:4\n");
}
printf("pid1 successfully locked range 130:4 for WRITE\n");
}
- if (cli_read_old(cli1, fnum1, buf, 130, 4) != 4) {
- printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
+ status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("pid1 unable to read the range 130:4, error was %s\n",
+ nt_errstr(status));
+ goto fail;
+ } else if (nread != 4) {
+ printf("pid1 unable to read the range 130:4, "
+ "recv %ld req %d\n", (unsigned long)nread, 4);
goto fail;
} else {
printf("pid1 successfully read the range 130:4\n");
cli_setpid(cli1, 2);
- if (cli_read_old(cli1, fnum1, buf, 130, 4) != 4) {
- printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
- if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
+ status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("pid2 unable to read the range 130:4, error was "
+ "%s\n", nt_errstr(status));
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
goto fail;
}
} else {
- printf("pid2 successfully read the range 130:4 (should be denied)\n");
+ printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
+ (unsigned long)nread);
goto fail;
}
*/
static bool got_alarm;
-static int alarm_fd;
+static struct cli_state *alarm_cli;
static void alarm_handler(int dummy)
{
static void alarm_handler_parent(int dummy)
{
- close(alarm_fd);
+ cli_state_disconnect(alarm_cli);
}
static void do_local_lock(int read_fd, int write_fd)
}
/* Wait 20 seconds for the lock. */
- alarm_fd = cli1->fd;
+ alarm_cli = cli1;
CatchSignal(SIGALRM, alarm_handler_parent);
alarm(20);
return False;
}
- cli2->vuid = cli1->vuid;
+ cli_state_set_uid(cli2, cli_state_get_uid(cli1));
cli_state_set_tid(cli2, cli_state_get_tid(cli1));
cli_setpid(cli2, cli_getpid(cli1));
- if (cli_read_old(cli2, fnum1, buf, 0, 13) == 13) {
- printf("read succeeded! nasty security hole [%s]\n",
- buf);
- return False;
+ if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
+ printf("read succeeded! nasty security hole [%s]\n", buf);
+ return false;
}
cli_close(cli1, fnum1);
return False;
}
- saved_vuid = cli->vuid;
- cli->vuid = new_vuid;
+ saved_vuid = cli_state_get_uid(cli);
+ cli_state_set_uid(cli, new_vuid);
- if (cli_read_old(cli, fnum1, buf, 0, 13) == 13) {
- printf("read succeeded with different vuid! nasty security hole [%s]\n",
- buf);
- ret = False;
+ if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
+ printf("read succeeded with different vuid! "
+ "nasty security hole [%s]\n", buf);
+ ret = false;
}
/* Try to open a file with different vuid, samba cnum. */
if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
ret = False;
}
- cli->vuid = saved_vuid;
+ cli_state_set_uid(cli, saved_vuid);
/* Try with same vuid, different cnum. */
cli_state_set_tid(cli, new_cnum);
- if (cli_read_old(cli, fnum1, buf, 0, 13) == 13) {
- printf("read succeeded with different cnum![%s]\n",
- buf);
- ret = False;
+ if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
+ printf("read succeeded with different cnum![%s]\n", buf);
+ ret = false;
}
cli_state_set_tid(cli, saved_cnum);
char buf[4];
bool correct = True;
volatile bool *shared_correct;
+ size_t nread;
NTSTATUS status;
shared_correct = (volatile bool *)shm_setup(sizeof(bool));
/* Ensure cli1 processes the break. Empty file should always return 0
* bytes. */
-
- if (cli_read_old(cli1, fnum1, buf, 0, 4) != 0) {
- printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
- correct = False;
+ status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("read on fnum1 failed (%s)\n", nt_errstr(status));
+ correct = false;
+ } else if (nread != 0) {
+ printf("read on empty fnum1 failed. recv %ld expected %d\n",
+ (unsigned long)nread, 0);
+ correct = false;
}
/* Should now be at level II. */
sleep(2);
- cli_read_old(cli1, fnum1, buf, 0, 4);
+ cli_read(cli1, fnum1, buf, 0, 4, NULL);
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
SMB_STRUCT_STAT sbuf;
bool correct = false;
NTSTATUS status;
+ size_t nread;
printf("Starting simple POSIX open test\n");
goto out;
}
- if (cli_read_old(cli1, fnum1, buf, 0, 10) != 10) {
- printf("POSIX read of %s failed (%s)\n", hname, cli_errstr(cli1));
+ status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("POSIX read of %s failed (%s)\n", hname,
+ nt_errstr(status));
+ goto out;
+ } else if (nread != 10) {
+ printf("POSIX read of %s failed. Received %ld, expected %d\n",
+ hname, (unsigned long)nread, 10);
goto out;
}
return false;
}
- d_printf("\r%d ", (int)c->vuid);
+ d_printf("\r%d ", (int)cli_state_get_uid(c));
status = cli_ulogoff(c);
if (!NT_STATUS_IS_OK(status)) {
__location__, nt_errstr(status));
return false;
}
- c->vuid = 0;
}
return true;
cli_sockopt(cli, sockops);
/* Ok - now save then logoff our current user. */
- old_vuid = cli->vuid;
+ old_vuid = cli_state_get_uid(cli);
status = cli_ulogoff(cli);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
- cli->vuid = old_vuid;
+ cli_state_set_uid(cli, old_vuid);
/* Try an operation. */
status = cli_mkdir(cli, "\\uid_reg_test");
old_cnum = cli_state_get_tid(cli);
/* Now try a SMBtdis with the invald vuid set to zero. */
- cli->vuid = 0;
+ cli_state_set_uid(cli, 0);
/* This should succeed. */
status = cli_tdis(cli);
goto out;
}
- cli->vuid = old_vuid;
+ cli_state_set_uid(cli, old_vuid);
cli_state_set_tid(cli, old_cnum);
/* This should fail. */