*/
#include "includes.h"
-#include "nsswitch/libwbclient/wbc_async.h"
+#include "system/shmem.h"
+#include "wbc_async.h"
#include "torture/proto.h"
-#include "libcli/security/dom_sid.h"
+#include "libcli/security/security.h"
#include "tldap.h"
#include "tldap_util.h"
+#include "../librpc/gen_ndr/svcctl.h"
+#include "memcache.h"
+#include "nsswitch/winbind_client.h"
+#include "dbwrap.h"
+#include "talloc_dict.h"
+#include "async_smb.h"
+#include "libsmb/clirap.h"
+#include "trans2.h"
+#include "libsmb/nmblib.h"
+#include "../lib/util/tevent_ntstatus.h"
extern char *optarg;
extern int optind;
static bool use_multishare_conn = False;
static bool do_encrypt;
static const char *local_path = NULL;
+static int signing_state = Undefined;
bool torture_showall = False;
zero_sockaddr(&ss);
- if (!(c = cli_initialise())) {
+ if (!(c = cli_initialise_ex(signing_state))) {
printf("Failed initialize cli_struct to connect with %s\n", host);
return NULL;
}
return c;
}
+/****************************************************************************
+ Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
+****************************************************************************/
+
+static bool cli_bad_session_request(struct cli_state *cli,
+ struct nmb_name *calling, struct nmb_name *called)
+{
+ char *p;
+ int len = 4;
+ int namelen = 0;
+ char *tmp;
+
+ memcpy(&(cli->calling), calling, sizeof(*calling));
+ memcpy(&(cli->called ), called , sizeof(*called ));
+
+ /* put in the destination name */
+
+ tmp = name_mangle(talloc_tos(), cli->called.name,
+ cli->called.name_type);
+ if (tmp == NULL) {
+ return false;
+ }
+
+ p = cli->outbuf+len;
+ namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp));
+ if (namelen > 0) {
+ memcpy(p, tmp, namelen);
+ len += namelen;
+ }
+ TALLOC_FREE(tmp);
+
+ /* Deliberately corrupt the name len (first byte) */
+ *p = 100;
+
+ /* and my name */
+
+ tmp = name_mangle(talloc_tos(), cli->calling.name,
+ cli->calling.name_type);
+ if (tmp == NULL) {
+ return false;
+ }
+
+ p = cli->outbuf+len;
+ namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp));
+ if (namelen > 0) {
+ memcpy(p, tmp, namelen);
+ len += namelen;
+ }
+ TALLOC_FREE(tmp);
+ /* Deliberately corrupt the name len (first byte) */
+ *p = 100;
+
+ /* send a session request (RFC 1002) */
+ /* setup the packet length
+ * Remove four bytes from the length count, since the length
+ * field in the NBT Session Service header counts the number
+ * of bytes which follow. The cli_send_smb() function knows
+ * about this and accounts for those four bytes.
+ * CRH.
+ */
+ len -= 4;
+ _smb_setlen(cli->outbuf,len);
+ SCVAL(cli->outbuf,0,0x81);
+
+ cli_send_smb(cli);
+ DEBUG(5,("Sent session request\n"));
+
+ if (!cli_receive_smb(cli))
+ return False;
+
+ if (CVAL(cli->inbuf,0) != 0x82) {
+ /* This is the wrong place to put the error... JRA. */
+ cli->rap_error = CVAL(cli->inbuf,4);
+ return False;
+ }
+ return(True);
+}
+
+static struct cli_state *open_bad_nbt_connection(void)
+{
+ struct nmb_name called, calling;
+ struct sockaddr_storage ss;
+ struct cli_state *c;
+ NTSTATUS status;
+
+ make_nmb_name(&calling, myname, 0x0);
+ make_nmb_name(&called , host, 0x20);
+
+ zero_sockaddr(&ss);
+
+ if (!(c = cli_initialise_ex(signing_state))) {
+ printf("Failed initialize cli_struct to connect with %s\n", host);
+ return NULL;
+ }
+
+ c->port = 139;
+
+ status = cli_connect(c, host, &ss);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
+ return NULL;
+ }
+
+ c->timeout = 4000; /* set a short timeout (4 seconds) */
+
+ if (!cli_bad_session_request(c, &calling, &called)) {
+ printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
+ return NULL;
+ }
+
+ return c;
+}
+
+
/* Insert a NULL at the first separator of the given path and return a pointer
* to the remainder of the string.
*/
const char *hostname,
const char *sharename)
{
- bool retry;
int flags = 0;
NTSTATUS status;
hostname, NULL, port_to_use,
sharename, "?????",
username, workgroup,
- password, flags, Undefined, &retry);
+ password, flags, signing_state);
if (!NT_STATUS_IS_OK(status)) {
printf("failed to open share connection: //%s/%s port:%d - %s\n",
hostname, sharename, port_to_use, nt_errstr(status));
for (i=0;i<torture_numops;i++) {
unsigned n = (unsigned)sys_random()%10;
+
if (i % 10 == 0) {
printf("%d\r", i); fflush(stdout);
}
break;
}
- if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
- printf("write failed (%s)\n", cli_errstr(c));
+ status = cli_writeall(c, fnum, 0, (uint8_t *)&pid, 0,
+ sizeof(pid), NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("write failed (%s)\n", nt_errstr(status));
correct = False;
}
for (j=0;j<50;j++) {
- if (cli_write(c, fnum, 0, (char *)buf,
- sizeof(pid)+(j*sizeof(buf)),
- sizeof(buf)) != sizeof(buf)) {
- printf("write failed (%s)\n", cli_errstr(c));
+ status = cli_writeall(c, fnum, 0, (uint8_t *)buf,
+ sizeof(pid)+(j*sizeof(buf)),
+ sizeof(buf), NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("write failed (%s)\n",
+ nt_errstr(status));
correct = False;
}
}
correct = False;
}
- if (!NT_STATUS_IS_OK(cli_unlink(c, fname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink failed (%s)\n", cli_errstr(c));
correct = False;
}
}
cli_close(c, fnum2);
- cli_unlink(c, lockfname, aSYSTEM | aHIDDEN);
+ cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
printf("%d\n", i);
unsigned countprev = 0;
ssize_t sent = 0;
bool correct = True;
- NTSTATUS status;
+ NTSTATUS status = NT_STATUS_OK;
srandom(1);
for (i = 0; i < sizeof(buf); i += sizeof(uint32))
if (procnum == 0)
{
+ if (!NT_STATUS_IS_OK(cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
+ printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c));
+ }
+
if (!NT_STATUS_IS_OK(cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
DENY_NONE, &fnum))) {
printf("first open read/write of %s failed (%s)\n",
sent = sizeof(buf) - count;
}
- if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
- printf("write failed (%s)\n", cli_errstr(c));
+ status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
+ count, (size_t)sent, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("write failed (%s)\n",
+ nt_errstr(status));
correct = False;
}
}
bool correct = True;
ssize_t bytes_read;
- if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
}
for (i=0;i<torture_numops;i++)
{
+ NTSTATUS status;
size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
if (i % 10 == 0) {
printf("%d\r", i); fflush(stdout);
generate_random_buffer((unsigned char *)buf, buf_size);
- if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
- printf("write failed (%s)\n", cli_errstr(c1));
+ status = cli_writeall(c1, fnum1, 0, (uint8_t *)buf, 0,
+ buf_size, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("write failed (%s)\n", nt_errstr(status));
correct = False;
break;
}
correct = False;
}
- if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink failed (%s)\n", cli_errstr(c1));
correct = False;
}
return test;
}
-static bool run_readwritelarge(int dummy)
+static bool run_readwritelarge_internal(int max_xmit_k)
{
static struct cli_state *cli1;
uint16_t fnum1;
cli_sockopt(cli1, sockops);
memset(buf,'\0',sizeof(buf));
- cli1->max_xmit = 128*1024;
+ cli1->max_xmit = max_xmit_k*1024;
- printf("starting readwritelarge\n");
+ if (signing_state == Required) {
+ /* Horrible cheat to force
+ multiple signed outstanding
+ packets against a Samba server.
+ */
+ cli1->is_samba = false;
+ }
- cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN);
+ printf("starting readwritelarge_internal\n");
+
+ cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
return False;
}
- cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
+ cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
- if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
+ if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+ cli1, fnum1, NULL, &fsize, NULL, NULL,
+ NULL, NULL, NULL))) {
printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
correct = False;
}
if (fsize == sizeof(buf))
- printf("readwritelarge test 1 succeeded (size = %lx)\n",
+ printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
(unsigned long)fsize);
else {
- printf("readwritelarge test 1 failed (size = %lx)\n",
+ printf("readwritelarge_internal test 1 failed (size = %lx)\n",
(unsigned long)fsize);
correct = False;
}
correct = False;
}
- if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink failed (%s)\n", cli_errstr(cli1));
correct = False;
}
cli1->max_xmit = 4*1024;
- cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
+ cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
- if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
+ if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+ cli1, fnum1, NULL, &fsize, NULL, NULL,
+ NULL, NULL, NULL))) {
printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
correct = False;
}
if (fsize == sizeof(buf))
- printf("readwritelarge test 2 succeeded (size = %lx)\n",
+ printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
(unsigned long)fsize);
else {
- printf("readwritelarge test 2 failed (size = %lx)\n",
+ printf("readwritelarge_internal test 2 failed (size = %lx)\n",
(unsigned long)fsize);
correct = False;
}
printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
return False;
}
- if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
+ if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
+ NULL, NULL)) {
printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
correct = False;
}
return correct;
}
+static bool run_readwritelarge(int dummy)
+{
+ return run_readwritelarge_internal(128);
+}
+
+static bool run_readwritelarge_signtest(int dummy)
+{
+ bool ret;
+ signing_state = Required;
+ ret = run_readwritelarge_internal(2);
+ signing_state = Undefined;
+ return ret;
+}
+
int line_count = 0;
int nbio_id;
printf("starting locktest1\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
- if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink failed (%s)\n", cli_errstr(cli1));
return False;
}
printf("starting tcontest\n");
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
cnum1 = cli->cnum;
vuid1 = cli->vuid;
- if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
- printf("initial write failed (%s)", cli_errstr(cli));
+ status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("initial write failed (%s)", nt_errstr(status));
return False;
}
/* try a write with the wrong tid */
cli->cnum = cnum2;
- if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
+ status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+ if (NT_STATUS_IS_OK(status)) {
printf("* server allows write with wrong TID\n");
ret = False;
} else {
- printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
+ printf("server fails write with wrong TID : %s\n",
+ nt_errstr(status));
}
/* try a write with an invalid tid */
cli->cnum = cnum3;
- if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
+ status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+ if (NT_STATUS_IS_OK(status)) {
printf("* server allows write with invalid TID\n");
ret = False;
} else {
- printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
+ printf("server fails write with invalid TID : %s\n",
+ nt_errstr(status));
}
/* try a write with an invalid vuid */
cli->vuid = vuid2;
cli->cnum = cnum1;
- if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
+ status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+ if (NT_STATUS_IS_OK(status)) {
printf("* server allows write with invalid VUID\n");
ret = False;
} else {
- printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
+ printf("server fails write with invalid VUID : %s\n",
+ nt_errstr(status));
}
cli->cnum = cnum1;
status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
+ SAFE_FREE(service);
+
if (!NT_STATUS_IS_OK(status)) {
- printf("tcon2 failed : %s\n", cli_errstr(cli));
+ printf("tcon2 failed : %s\n", nt_errstr(status));
} else {
- printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
- (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
+ printf("tcon OK : max_xmit=%d cnum=%d\n",
+ (int)max_xmit, (int)cnum);
}
if (!torture_close_connection(cli)) {
static bool run_tcon_devtype_test(int dummy)
{
static struct cli_state *cli1 = NULL;
- bool retry;
int flags = 0;
NTSTATUS status;
bool ret = True;
host, NULL, port_to_use,
NULL, NULL,
username, workgroup,
- password, flags, Undefined, &retry);
+ password, flags, signing_state);
if (!NT_STATUS_IS_OK(status)) {
printf("could not open connection\n");
printf("starting locktest2\n");
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_setpid(cli, 1);
printf("starting locktest3\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
- if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink failed (%s)\n", cli_errstr(cli1));
return False;
}
bool ret;
char buf[1000];
bool correct = True;
+ NTSTATUS status;
if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
return False;
printf("starting locktest4\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
memset(buf, 0, sizeof(buf));
- if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
- printf("Failed to create file\n");
+ status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Failed to create file: %s\n", nt_errstr(status));
correct = False;
goto fail;
}
EXPECTED(ret, False);
printf("this server %s strict write locking\n", ret?"doesn't do":"does");
- ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
- (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
+ ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK);
+ if (ret) {
+ status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
+ NULL);
+ ret = NT_STATUS_IS_OK(status);
+ }
EXPECTED(ret, False);
printf("this server %s strict read locking\n", ret?"doesn't do":"does");
cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
(cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
- !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 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));
EXPECTED(ret, True);
printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
- (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
+ NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
+ 160, 4, NULL)) &&
(cli_read(cli2, fnum2, buf, 160, 4) == 4);
EXPECTED(ret, True);
printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
- (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
+ NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
+ 170, 4, NULL)) &&
(cli_read(cli2, fnum2, buf, 170, 4) == 4);
EXPECTED(ret, True);
printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
- !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
+ !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
+ 190, 4, NULL)) &&
(cli_read(cli2, fnum2, buf, 190, 4) == 4);
EXPECTED(ret, True);
printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
fail:
cli_close(cli1, fnum1);
cli_close(cli2, fnum2);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
torture_close_connection(cli1);
torture_close_connection(cli2);
bool ret;
char buf[1000];
bool correct = True;
+ NTSTATUS status;
if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
return False;
printf("starting locktest5\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
memset(buf, 0, sizeof(buf));
- if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
- printf("Failed to create file\n");
+ status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Failed to create file: %s\n", nt_errstr(status));
correct = False;
goto fail;
}
fail:
cli_close(cli1, fnum1);
cli_close(cli2, fnum2);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!torture_close_connection(cli1)) {
correct = False;
}
for (i=0;i<1;i++) {
printf("Testing %s\n", fname[i]);
- cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
cli_close(cli, fnum);
printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
- cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
}
torture_close_connection(cli);
uint16_t fnum1;
char buf[200];
bool correct = False;
+ NTSTATUS status;
if (!torture_open_connection(&cli1, 0)) {
return False;
printf("starting locktest7\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
memset(buf, 0, sizeof(buf));
- if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
- printf("Failed to create file\n");
+ status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Failed to create file: %s\n", nt_errstr(status));
goto fail;
}
printf("pid1 successfully read the range 130:4\n");
}
- if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
- printf("pid1 unable to write to 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_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("pid1 unable to write to 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;
}
printf("pid2 successfully read the range 130:4\n");
}
- if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
- printf("pid2 unable to write to 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_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("pid2 unable to write to 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;
}
printf("pid1 successfully read the range 130:4\n");
}
- if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
- printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
+ status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("pid1 unable to write to the range 130:4, error was "
+ "%s\n", nt_errstr(status));
goto fail;
} else {
printf("pid1 successfully wrote to the range 130:4\n");
goto fail;
}
- if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
- printf("pid2 unable to write to 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_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("pid2 unable to write to 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;
}
fail:
cli_close(cli1, fnum1);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
torture_close_connection(cli1);
printf("finished locktest7\n");
printf("starting locktest8\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
&fnum1);
fail:
cli_close(cli1, fnum1);
cli_close(cli1, fnum2);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
torture_close_connection(cli1);
printf("finished locktest8\n");
const char *fname = "\\fdpass.tst";
uint16_t fnum1;
char buf[1024];
+ NTSTATUS status;
if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
return False;
printf("starting fdpasstest\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
- if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
- printf("write failed (%s)\n", cli_errstr(cli1));
+ status = cli_writeall(cli1, fnum1, 0, (uint8_t *)"hello world\n", 0,
+ 13, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("write failed (%s)\n", nt_errstr(status));
return False;
}
}
cli_close(cli1, fnum1);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
torture_close_connection(cli1);
torture_close_connection(cli2);
uint16_t fnum2;
char buf[1024];
bool ret = True;
+ NTSTATUS status;
if (!torture_open_connection(&cli, 0))
return False;
printf("starting fdsesstest\n");
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
- cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
return False;
}
- if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
- printf("write failed (%s)\n", cli_errstr(cli));
+ status = cli_writeall(cli, fnum1, 0, (uint8_t *)"hello world\n", 0, 13,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("write failed (%s)\n", nt_errstr(status));
return False;
}
if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
printf("create with different vuid, same cnum succeeded.\n");
cli_close(cli, fnum2);
- cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
} else {
printf("create with different vuid, same cnum failed.\n");
printf("This will cause problems with service clients.\n");
cli->cnum = saved_cnum;
cli_close(cli, fnum1);
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
torture_close_connection(cli);
printf("starting unlink test\n");
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_setpid(cli, 1);
return False;
}
- if (NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
+ if (NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("error: server allowed unlink on an open file\n");
correct = False;
} else {
}
cli_close(cli, fnum);
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!torture_close_connection(cli)) {
correct = False;
for (;i>=0;i--) {
slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
cli_close(cli, fnums[i]);
- if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink of %s failed (%s)\n",
fname, cli_errstr(cli));
correct = False;
/* send smb negprot commands, not reading the response */
static bool run_negprot_nowait(int dummy)
{
+ struct tevent_context *ev;
int i;
- static struct cli_state *cli;
+ struct cli_state *cli;
bool correct = True;
printf("starting negprot nowait test\n");
+ ev = tevent_context_init(talloc_tos());
+ if (ev == NULL) {
+ return false;
+ }
+
if (!(cli = open_nbt_connection())) {
+ TALLOC_FREE(ev);
return False;
}
for (i=0;i<50000;i++) {
- cli_negprot_sendsync(cli);
+ struct tevent_req *req;
+
+ req = cli_negprot_send(ev, ev, cli);
+ if (req == NULL) {
+ TALLOC_FREE(ev);
+ return false;
+ }
+ if (!tevent_req_poll(req, ev)) {
+ d_fprintf(stderr, "tevent_req_poll failed: %s\n",
+ strerror(errno));
+ TALLOC_FREE(ev);
+ return false;
+ }
+ TALLOC_FREE(req);
}
- if (!torture_close_connection(cli)) {
+ if (torture_close_connection(cli)) {
correct = False;
}
return correct;
}
+/* send smb negprot commands, not reading the response */
+static bool run_bad_nbt_session(int dummy)
+{
+ static struct cli_state *cli;
+
+ printf("starting bad nbt session test\n");
+
+ if (!(cli = open_bad_nbt_connection())) {
+ return False;
+ }
+
+ cli_shutdown(cli);
+ printf("finished bad nbt session test\n");
+ return true;
+}
/* send random IPC commands */
static bool run_randomipc(int dummy)
return False;
}
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_open(cli, fname,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
cli_close(cli, fnum);
correct = True;
}
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!torture_close_connection(cli)) {
correct = False;
correct = false;
}
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_open(cli, fname,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
- if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
- &m_time_ts, NULL)) {
+ if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+ cli, fnum, NULL, &size, &c_time_ts,
+ &a_time_ts, &w_time_ts,
+ &m_time_ts, NULL))) {
printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
correct = False;
}
- if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
+ if (!NT_STATUS_IS_OK(cli_qfilename(cli, fnum, pname, sizeof(pname)))) {
printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
correct = False;
}
sleep(2);
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli, fname,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
}
cli_close(cli, fnum);
- if (!cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
- printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
+ status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
correct = False;
} else {
if (c_time != m_time) {
}
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_open(cli, fname,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
cli_close(cli, fnum);
- if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
- &m_time_ts, &size, NULL, NULL)) {
- printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+ status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
+ &m_time_ts, &size, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
correct = False;
} else {
if (w_time_ts.tv_sec < 60*60*24*2) {
}
}
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
/* check if the server updates the directory modification time
correct = False;
}
sleep(3);
- if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
- &m_time_ts, &size, NULL, NULL)) {
- printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+ status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
+ &w_time_ts, &m_time_ts, &size, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
correct = False;
}
cli_open(cli, fname2,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
- cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
+ cli_writeall(cli, fnum, 0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
cli_close(cli, fnum);
- if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
- &m_time2_ts, &size, NULL, NULL)) {
- printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+ status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
+ &w_time_ts, &m_time2_ts, &size, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
correct = False;
} else {
if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
correct = False;
}
}
- cli_unlink(cli, fname2, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_rmdir(cli, dname);
if (!torture_close_connection(cli)) {
This checks new W2K calls.
*/
-static bool new_trans(struct cli_state *pcli, int fnum, int level)
+static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
{
- char *buf = NULL;
+ uint8_t *buf = NULL;
uint32 len;
- bool correct = True;
+ NTSTATUS status;
- if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
- printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
- correct = False;
+ status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
+ pcli->max_xmit, &buf, &len);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
+ nt_errstr(status));
} else {
printf("qfileinfo: level %d, len = %u\n", level, len);
dump_data(0, (uint8 *)buf, len);
printf("\n");
}
- SAFE_FREE(buf);
- return correct;
+ TALLOC_FREE(buf);
+ return status;
}
static bool run_w2ktest(int dummy)
return False;
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_sockopt(cli1, sockops);
cli1->use_oplocks = False;
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
printf("close2 failed (%s)\n", cli_errstr(cli1));
return False;
}
- if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink failed (%s)\n", cli_errstr(cli1));
return False;
}
cli2->use_oplocks = True;
cli2->use_level_II_oplocks = True;
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_sockopt(cli1, sockops);
cli_sockopt(cli2, sockops);
cli_read(cli1, fnum1, buf, 0, 4);
-#if 0
- if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
- printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
- correct = False;
- }
-#endif
-
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
printf("close1 failed (%s)\n", cli_errstr(cli1));
correct = False;
sleep(4);
- if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink failed (%s)\n", cli_errstr(cli1));
correct = False;
}
sleep(2);
/* try to trigger a oplock break in parent */
cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
- cli_write(cli, fnum, 0, buf, 0, 4);
+ cli_writeall(cli, fnum, 0, (uint8_t *)buf, 0, 4, NULL);
exit(0);
}
}
cli_oplock_handler(cli, oplock3_handler);
cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
- cli_write(cli, fnum, 0, buf, 0, 4);
+ cli_writeall(cli, fnum, 0, (uint8_t *)buf, 0, 4, NULL);
cli_close(cli, fnum);
cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
cli->timeout = 20000;
/* What are we looking for here? What's sucess and what's FAILURE? */
}
+/* handler for oplock 4 tests */
+bool *oplock4_shared_correct;
+
+static NTSTATUS oplock4_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
+{
+ printf("got oplock break fnum=%d level=%d\n",
+ fnum, level);
+ *oplock4_shared_correct = true;
+ cli_oplock_ack(cli, fnum, level);
+ return NT_STATUS_UNSUCCESSFUL; /* Cause cli_receive_smb to return. */
+}
+
+static bool run_oplock4(int dummy)
+{
+ struct cli_state *cli1, *cli2;
+ const char *fname = "\\lockt4.lck";
+ const char *fname_ln = "\\lockt4_ln.lck";
+ uint16_t fnum1, fnum2;
+ int saved_use_oplocks = use_oplocks;
+ NTSTATUS status;
+ bool correct = true;
+
+ oplock4_shared_correct = (bool *)shm_setup(sizeof(bool));
+ *oplock4_shared_correct = false;
+
+ printf("starting oplock test 4\n");
+
+ if (!torture_open_connection(&cli1, 0)) {
+ use_level_II_oplocks = false;
+ use_oplocks = saved_use_oplocks;
+ return false;
+ }
+
+ if (!torture_open_connection(&cli2, 1)) {
+ use_level_II_oplocks = false;
+ use_oplocks = saved_use_oplocks;
+ return false;
+ }
+
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+ cli_sockopt(cli1, sockops);
+ cli_sockopt(cli2, sockops);
+
+ /* Create the file. */
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
+ printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+ return false;
+ }
+
+ if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
+ printf("close1 failed (%s)\n", cli_errstr(cli1));
+ return false;
+ }
+
+ /* Now create a hardlink. */
+ if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli1, fname, fname_ln))) {
+ printf("nt hardlink failed (%s)\n", cli_errstr(cli1));
+ return false;
+ }
+
+ /* Prove that opening hardlinks cause deny modes to conflict. */
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum1))) {
+ printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+ return false;
+ }
+
+ status = cli_open(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
+ if (NT_STATUS_IS_OK(status)) {
+ printf("open of %s succeeded - should fail with sharing violation.\n",
+ fname_ln);
+ return false;
+ }
+
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
+ printf("open of %s should fail with sharing violation. Got %s\n",
+ fname_ln, nt_errstr(status));
+ return false;
+ }
+
+ if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
+ printf("close1 failed (%s)\n", cli_errstr(cli1));
+ return false;
+ }
+
+ cli1->use_oplocks = true;
+ cli1->use_level_II_oplocks = true;
+
+ cli2->use_oplocks = true;
+ cli2->use_level_II_oplocks = true;
+
+ cli_oplock_handler(cli1, oplock4_handler);
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
+ printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+ return false;
+ }
+
+ if (fork() == 0) {
+ /* Child code */
+ if (!NT_STATUS_IS_OK(cli_open(cli2, fname_ln, O_RDWR, DENY_NONE, &fnum2))) {
+ printf("open of %s failed (%s)\n", fname_ln, cli_errstr(cli1));
+ *oplock4_shared_correct = false;
+ exit(0);
+ }
+
+ if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
+ printf("close2 failed (%s)\n", cli_errstr(cli1));
+ *oplock4_shared_correct = false;
+ }
+
+ exit(0);
+ }
+
+ sleep(2);
+
+ /* Process the oplock break. */
+ cli_receive_smb(cli1);
+
+ if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
+ printf("close1 failed (%s)\n", cli_errstr(cli1));
+ correct = false;
+ }
+
+ if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
+ printf("unlink failed (%s)\n", cli_errstr(cli1));
+ correct = false;
+ }
+ if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
+ printf("unlink failed (%s)\n", cli_errstr(cli1));
+ correct = false;
+ }
+
+ if (!torture_close_connection(cli1)) {
+ correct = false;
+ }
+
+ if (!*oplock4_shared_correct) {
+ correct = false;
+ }
+
+ printf("finished oplock test 4\n");
+
+ return correct;
+}
/*
/* Test 1 - this should delete the file on close. */
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
0, FILE_OVERWRITE_IF,
goto fail;
}
-#if 0 /* JRATEST */
- {
- uint32 *accinfo = NULL;
- uint32 len;
- cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
- if (accinfo)
- printf("access mode = 0x%lx\n", *accinfo);
- SAFE_FREE(accinfo);
- }
-#endif
-
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
printf("[1] close failed (%s)\n", cli_errstr(cli1));
correct = False;
/* Test 2 - this should delete the file on close. */
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
correct = False;
goto fail;
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
} else
printf("second delete on close test succeeded.\n");
/* Test 3 - ... */
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
printf("[3] close failed (%s)\n", cli_errstr(cli1));
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
correct = False;
goto fail;
} else
/* Test 4 ... */
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
/* Test 5 ... */
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1))) {
printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
/* Test 6 ... */
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
/* Test 7 ... */
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
/* Test 7 ... */
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!torture_open_connection(&cli2, 1)) {
printf("[8] failed to open second connection.\n");
printf("tenth delete on close test succeeded.\n");
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
/* What error do we get when attempting to open a read-only file with
delete access ? */
if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (cli1 && !torture_close_connection(cli1)) {
correct = False;
return correct;
}
+static bool run_deletetest_ln(int dummy)
+{
+ struct cli_state *cli;
+ const char *fname = "\\delete1";
+ const char *fname_ln = "\\delete1_ln";
+ uint16_t fnum;
+ uint16_t fnum1;
+ NTSTATUS status;
+ bool correct = true;
+ time_t t;
+
+ printf("starting deletetest-ln\n");
+
+ if (!torture_open_connection(&cli, 0)) {
+ return false;
+ }
+
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+ cli_sockopt(cli, sockops);
+
+ /* Create the file. */
+ if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
+ printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
+ return false;
+ }
+
+ if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
+ printf("close1 failed (%s)\n", cli_errstr(cli));
+ return false;
+ }
+
+ /* Now create a hardlink. */
+ if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli, fname, fname_ln))) {
+ printf("nt hardlink failed (%s)\n", cli_errstr(cli));
+ return false;
+ }
+
+ /* Open the original file. */
+ status = cli_ntcreate(cli, fname, 0, FILE_READ_DATA,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN_IF, 0, 0, &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
+ return false;
+ }
+
+ /* Unlink the hard link path. */
+ status = cli_ntcreate(cli, fname_ln, 0, DELETE_ACCESS,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN_IF, 0, 0, &fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
+ return false;
+ }
+ status = cli_nt_delete_on_close(cli, fnum1, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("(%s) failed to set delete_on_close %s: %s\n",
+ __location__, fname_ln, nt_errstr(status));
+ return false;
+ }
+
+ status = cli_close(cli, fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("close %s failed (%s)\n",
+ fname_ln, nt_errstr(status));
+ return false;
+ }
+
+ status = cli_close(cli, fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("close %s failed (%s)\n",
+ fname, nt_errstr(status));
+ return false;
+ }
+
+ /* Ensure the original file is still there. */
+ status = cli_getatr(cli, fname, NULL, NULL, &t);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("%s getatr on file %s failed (%s)\n",
+ __location__,
+ fname,
+ nt_errstr(status));
+ correct = False;
+ }
+
+ /* Ensure the link path is gone. */
+ status = cli_getatr(cli, fname_ln, NULL, NULL, &t);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ printf("%s, getatr for file %s returned wrong error code %s "
+ "- should have been deleted\n",
+ __location__,
+ fname_ln, nt_errstr(status));
+ correct = False;
+ }
+
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+ if (!torture_close_connection(cli)) {
+ correct = false;
+ }
+
+ printf("finished deletetest-ln\n");
+
+ return correct;
+}
/*
print out server properties
return False;
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("First open failed - %s\n", cli_errstr(cli1));
return False;
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
#if 0
FILE_SHARE_DELETE|FILE_SHARE_NONE,
return False;
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
return False;
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
/*----*/
return False;
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
/*--*/
}
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!torture_close_connection(cli1)) {
correct = False;
SMB_OFF_T fsize;
bool correct = True;
char *tmp_path;
+ NTSTATUS status;
printf("starting open test\n");
}
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_sockopt(cli1, sockops);
return False;
}
- if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, aRONLY, 0))) {
+ if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0))) {
printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
return False;
}
return False;
}
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
printf("finished open test 2\n");
memset(buf, '\0', 20);
- if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
- printf("write failed (%s)\n", cli_errstr(cli1));
+ status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, 20, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("write failed (%s)\n", nt_errstr(status));
correct = False;
}
}
printf("finished open test 3\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
-
- printf("testing ctemp\n");
+ printf("Do ctemp tests\n");
if (!NT_STATUS_IS_OK(cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path))) {
printf("ctemp failed (%s)\n", cli_errstr(cli1));
return False;
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
printf("close of temp failed (%s)\n", cli_errstr(cli1));
}
- if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
}
}
cli_setatr(cli2, fname, 0, 0);
- cli_unlink(cli2, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_sockopt(cli2, sockops);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
- printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
- printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
- printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
- printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
printf("non-io open test #1 passed.\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
printf("TEST #2 testing 2 non-io opens (first with delete)\n");
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
- printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
- printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
- printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #2 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
- printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #2 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
printf("non-io open test #2 passed.\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
printf("TEST #3 testing 2 non-io opens (second with delete)\n");
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
- printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
- printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
- printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
- printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
printf("non-io open test #3 passed.\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
printf("TEST #4 testing 2 non-io opens (both with delete)\n");
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
- printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
- printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
- printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
+ printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
- printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
printf("non-io open test #4 passed.\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
- printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
- printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
- printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
- printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
printf("TEST #6 testing 1 non-io open, one io open\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
- printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) {
- printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
- printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
- printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
printf("TEST #7 testing 1 non-io open, one io open with delete\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
- printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
- printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
+ printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
- printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
+ printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
- printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("TEST #7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
printf("non-io open test #7 passed.\n");
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+ printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
+ status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OVERWRITE_IF, 0, 0, &fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
+ correct = false;
+ goto out;
+ }
+
+ /* Write to ensure we have to update the file time. */
+ status = cli_writeall(cli1, fnum1, 0, (uint8_t *)"TEST DATA\n", 0, 10,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("TEST #8 cli_write failed: %s\n", nt_errstr(status));
+ correct = false;
+ goto out;
+ }
+
+ status = cli_close(cli1, fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("TEST #8 close of %s failed (%s)\n", fname, nt_errstr(status));
+ correct = false;
+ }
+
+ out:
if (!torture_close_connection(cli1)) {
correct = False;
}
/* Write some data into it. */
- if (cli_write(cli1, fnum1, 0, "TEST DATA\n", 0, 10) != 10) {
- printf("cli_write failed: %s\n", cli_errstr(cli1));
+ status = cli_writeall(cli1, fnum1, 0, (uint8_t *)"TEST DATA\n", 0, 10,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_write failed: %s\n", nt_errstr(status));
goto out;
}
for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
}
cli_setatr(cli1, fname, 0, 0);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
printf("open attr test %s.\n", correct ? "passed" : "failed");
return correct;
}
-static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
+static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
+ const char *name, void *state)
{
-
+ int *matched = (int *)state;
+ if (matched != NULL) {
+ *matched += 1;
+ }
+ return NT_STATUS_OK;
}
/*
uint16_t fnum;
struct timeval core_start;
bool correct = True;
+ int matched;
printf("starting directory test\n");
core_start = timeval_current();
- printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
- printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
- printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
+ matched = 0;
+ cli_list(cli, "a*.*", 0, list_fn, &matched);
+ printf("Matched %d\n", matched);
+
+ matched = 0;
+ cli_list(cli, "b*.*", 0, list_fn, &matched);
+ printf("Matched %d\n", matched);
+
+ matched = 0;
+ cli_list(cli, "xyzabc", 0, list_fn, &matched);
+ printf("Matched %d\n", matched);
printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
for (i=0;i<torture_numops;i++) {
fstring fname;
slprintf(fname, sizeof(fname), "\\%x", (int)random());
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
}
if (!torture_close_connection(cli)) {
return correct;
}
-static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
+static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
+ void *state)
{
struct cli_state *pcli = (struct cli_state *)state;
fstring fname;
slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
- return;
+ return NT_STATUS_OK;
- if (finfo->mode & aDIR) {
+ if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
printf("del_fn: failed to rmdir %s\n,", fname );
} else {
- if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
+ if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)))
printf("del_fn: failed to unlink %s\n,", fname );
}
+ return NT_STATUS_OK;
}
printf("starting ioctl test\n");
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
printf("ioctl job info: %s\n", nt_errstr(status));
for (device=0;device<0x100;device++) {
- printf("testing device=0x%x\n", device);
+ printf("ioctl test with device = 0x%x\n", device);
for (function=0;function<0x100;function++) {
uint32 code = (device<<16) | function;
/* cleanup from an old run */
cli_rmdir(cli, "\\chkpath.dir\\dir2");
- cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
+ cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_rmdir(cli, "\\chkpath.dir");
if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
}
cli_rmdir(cli, "\\chkpath.dir\\dir2");
- cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
+ cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_rmdir(cli, "\\chkpath.dir");
if (!torture_close_connection(cli)) {
size_t num_eas;
struct ea_struct *ea_list = NULL;
TALLOC_CTX *mem_ctx = talloc_init("eatest");
+ NTSTATUS status;
printf("starting eatest\n");
return False;
}
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
FILE_SHARE_NONE, FILE_OVERWRITE_IF,
slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
memset(ea_val, (char)i+1, i+1);
- if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
- printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+ status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ea_set of name %s failed - %s\n", ea_name,
+ nt_errstr(status));
talloc_destroy(mem_ctx);
return False;
}
slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
memset(ea_val, (char)i+1, i+1);
- if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
- printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+ status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ea_set of name %s failed - %s\n", ea_name,
+ nt_errstr(status));
talloc_destroy(mem_ctx);
return False;
}
}
- if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
- printf("ea_get list failed - %s\n", cli_errstr(cli));
+ status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ea_get list failed - %s\n", nt_errstr(status));
correct = False;
}
for (i = 0; i < 20; i++) {
fstring ea_name;
slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
- if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
- printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+ status = cli_set_ea_path(cli, fname, ea_name, "", 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ea_set of name %s failed - %s\n", ea_name,
+ nt_errstr(status));
talloc_destroy(mem_ctx);
return False;
}
}
#endif
- if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
- printf("ea_get list failed - %s\n", cli_errstr(cli));
+ status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ea_get list failed - %s\n", nt_errstr(status));
correct = False;
}
}
/* Try and delete a non existant EA. */
- if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
- printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
+ status = cli_set_ea_path(cli, fname, "foo", "", 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("deleting non-existant EA 'foo' should succeed. %s\n",
+ nt_errstr(status));
correct = False;
}
cli_sockopt(cli, sockops);
cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
- cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
+ cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
cli_rmdir(cli, "\\LISTDIR");
cli_mkdir(cli, "\\LISTDIR");
}
/* Now ensure that doing an old list sees both files and directories. */
- num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
+ num_seen = 0;
+ cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
printf("num_seen = %d\n", num_seen );
/* We should see 100 files + 1000 directories + . and .. */
if (num_seen != 2002)
/* Ensure if we have the "must have" bits we only see the
* relevent entries.
*/
- num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
+ num_seen = 0;
+ cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
printf("num_seen = %d\n", num_seen );
if (num_seen != 1002)
correct = False;
- num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
+ num_seen = 0;
+ cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
printf("num_seen = %d\n", num_seen );
if (num_seen != 1000)
correct = False;
/* Delete everything. */
cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
- cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
+ cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
cli_rmdir(cli, "\\LISTDIR");
#if 0
printf("starting chain2 test\n");
status = cli_start_connection(&cli1, global_myname(), host, NULL,
- port_to_use, Undefined, 0, NULL);
+ port_to_use, Undefined, 0);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
}
cli_close(cli, fnum);
- if (!cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
- &write_time, &size, &mode)) {
+ status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
+ &write_time, &size, &mode);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
- cli_errstr(cli));
+ nt_errstr(status));
return false;
}
start_time = timeval_current();
for (i=0; i<torture_numops; i++) {
- char c = 0;
+ uint8_t c = 0;
off_t start = i * torture_blocksize;
NTSTATUS status;
size_t to_pull = torture_blocksize - 1;
- if (cli_write(cli1, fnum, 0, &c,
- start + torture_blocksize - 1, 1) != 1) {
- printf("cli_write failed: %s\n", cli_errstr(cli1));
+ status = cli_writeall(cli1, fnum, 0, &c,
+ start + torture_blocksize - 1, 1, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_write failed: %s\n", nt_errstr(status));
goto fail;
}
ret = true;
fail:
cli_close(cli1, fnum);
- cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
torture_close_connection(cli1);
return ret;
}
cli->vuid = old_vuid;
/* Try an operation. */
- if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
- /* We expect bad uid. */
+ status = cli_mkdir(cli, "\\uid_reg_test");
+ if (NT_STATUS_IS_OK(status)) {
+ d_printf("(%s) cli_mkdir succeeded\n",
+ __location__);
+ correct = false;
+ goto out;
+ } else {
+ /* Should be bad uid. */
if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
- NT_STATUS_NO_SUCH_USER)) {
- return False;
+ NT_STATUS_USER_SESSION_DELETED)) {
+ correct = false;
+ goto out;
}
}
status = cli_tdis(cli);
if (NT_STATUS_IS_OK(status)) {
- printf("First tdis with invalid vuid should succeed.\n");
+ d_printf("First tdis with invalid vuid should succeed.\n");
} else {
- printf("First tdis failed (%s)\n", nt_errstr(status));
+ d_printf("First tdis failed (%s)\n", nt_errstr(status));
+ correct = false;
+ goto out;
}
cli->vuid = old_vuid;
/* This should fail. */
status = cli_tdis(cli);
if (NT_STATUS_IS_OK(status)) {
- printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
+ d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
+ correct = false;
+ goto out;
} else {
/* Should be bad tid. */
if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
NT_STATUS_NETWORK_NAME_DELETED)) {
- return False;
+ correct = false;
+ goto out;
}
}
static const char *illegal_chars = "*\\/?<>|\":";
static char force_shortname_chars[] = " +,.[];=\177";
-static void shortname_del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
+static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
+ const char *mask, void *state)
{
struct cli_state *pcli = (struct cli_state *)state;
fstring fname;
+ NTSTATUS status = NT_STATUS_OK;
+
slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
- return;
+ return NT_STATUS_OK;
- if (finfo->mode & aDIR) {
- if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
+ if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
+ status = cli_rmdir(pcli, fname);
+ if (!NT_STATUS_IS_OK(status)) {
printf("del_fn: failed to rmdir %s\n,", fname );
+ }
} else {
- if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
+ status = cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ if (!NT_STATUS_IS_OK(status)) {
printf("del_fn: failed to unlink %s\n,", fname );
+ }
}
+ return status;
}
struct sn_state {
+ int matched;
int i;
bool val;
};
-static void shortname_list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
+static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
+ const char *name, void *state)
{
struct sn_state *s = (struct sn_state *)state;
int i = s->i;
__location__, finfo->short_name, finfo->name);
s->val = true;
}
+ s->matched += 1;
+ return NT_STATUS_OK;
}
static bool run_shortname_test(int dummy)
cli_sockopt(cli, sockops);
cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
- cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
+ cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
cli_rmdir(cli, "\\shortname");
if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\shortname"))) {
goto out;
}
cli_close(cli, fnum);
- if (cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn, &s) != 1) {
+
+ s.matched = 0;
+ cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn,
+ &s);
+ if (s.matched != 1) {
d_printf("(%s) failed to list %s: %s\n",
__location__, fname, cli_errstr(cli));
correct = false;
goto out;
}
- if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
+ if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
d_printf("(%s) failed to delete %s: %s\n",
__location__, fname, cli_errstr(cli));
correct = false;
out:
cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
- cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
+ cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
cli_rmdir(cli, "\\shortname");
torture_close_connection(cli);
return correct;
return false;
}
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_rmdir(cli, dname);
status = cli_mkdir(cli, dname);
goto out;
}
- if (!cli_qpathinfo2(cli,
- dname,
- &create_time,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL)) {
- status = cli_nt_error(cli);
+ status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
printf("cli_qpathinfo2 returned %s\n",
nt_errstr(status));
goto out;
goto out;
}
- if (!cli_qpathinfo2(cli,
- dname,
- &create_time1,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL)) {
- status = cli_nt_error(cli);
+ status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
printf("cli_qpathinfo2 (2) returned %s\n",
nt_errstr(status));
goto out;
out:
- cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_rmdir(cli, dname);
if (!torture_close_connection(cli)) {
ret = false;
return false;
}
- cli_unlink(cli, "\\testdir\\*", aSYSTEM | aHIDDEN);
+ cli_unlink(cli, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_rmdir(cli, dname);
status = cli_mkdir(cli, dname);
return ret;
}
+
+/*
+ local test for character set functions
+
+ This is a very simple test for the functionality in convert_string_error()
+ */
+static bool run_local_convert_string(int dummy)
+{
+ TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+ const char *test_strings[2] = { "March", "M\303\244rz" };
+ char dst[7];
+ int i;
+
+ for (i=0; i<2; i++) {
+ const char *str = test_strings[i];
+ int len = strlen(str);
+ size_t converted_size;
+ bool ret;
+
+ memset(dst, 'X', sizeof(dst));
+
+ /* first try with real source length */
+ ret = convert_string_error(CH_UNIX, CH_UTF8,
+ str, len,
+ dst, sizeof(dst),
+ &converted_size);
+ if (ret != true) {
+ d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
+ goto failed;
+ }
+
+ if (converted_size != len) {
+ d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
+ str, len, (int)converted_size);
+ goto failed;
+ }
+
+ if (strncmp(str, dst, converted_size) != 0) {
+ d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
+ goto failed;
+ }
+
+ if (strlen(str) != converted_size) {
+ d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
+ (int)strlen(str), (int)converted_size);
+ goto failed;
+ }
+
+ if (dst[converted_size] != 'X') {
+ d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
+ goto failed;
+ }
+
+ /* now with srclen==-1, this causes the nul to be
+ * converted too */
+ ret = convert_string_error(CH_UNIX, CH_UTF8,
+ str, -1,
+ dst, sizeof(dst),
+ &converted_size);
+ if (ret != true) {
+ d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
+ goto failed;
+ }
+
+ if (converted_size != len+1) {
+ d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
+ str, len, (int)converted_size);
+ goto failed;
+ }
+
+ if (strncmp(str, dst, converted_size) != 0) {
+ d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
+ goto failed;
+ }
+
+ if (len+1 != converted_size) {
+ d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
+ len+1, (int)converted_size);
+ goto failed;
+ }
+
+ if (dst[converted_size] != 'X') {
+ d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
+ goto failed;
+ }
+
+ }
+
+
+ TALLOC_FREE(tmp_ctx);
+ return true;
+failed:
+ TALLOC_FREE(tmp_ctx);
+ return false;
+}
+
+
struct talloc_dict_test {
int content;
};
printf("could not parse S-1-5-32-545\n");
return false;
}
- if (!sid_equal(&sid, &global_sid_Builtin_Users)) {
+ if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
printf("mis-parsed S-1-5-32-545 as %s\n",
sid_string_tos(&sid));
return false;
return true;
}
+static bool run_local_binary_to_sid(int dummy) {
+ struct dom_sid *sid = talloc(NULL, struct dom_sid);
+ static const char good_binary_sid[] = {
+ 0x1, /* revision number */
+ 15, /* num auths */
+ 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+ 0x1, 0x1, 0x1, 0x1, /* auth[0] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[1] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[2] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[3] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[4] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[5] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[6] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[7] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[8] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[9] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[10] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[11] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[12] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[13] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[14] */
+ };
+
+ static const char long_binary_sid[] = {
+ 0x1, /* revision number */
+ 15, /* num auths */
+ 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+ 0x1, 0x1, 0x1, 0x1, /* auth[0] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[1] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[2] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[3] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[4] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[5] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[6] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[7] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[8] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[9] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[10] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[11] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[12] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[13] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[14] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[15] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[16] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[17] */
+ };
+
+ static const char long_binary_sid2[] = {
+ 0x1, /* revision number */
+ 32, /* num auths */
+ 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+ 0x1, 0x1, 0x1, 0x1, /* auth[0] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[1] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[2] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[3] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[4] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[5] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[6] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[7] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[8] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[9] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[10] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[11] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[12] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[13] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[14] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[15] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[16] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[17] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[18] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[19] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[20] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[21] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[22] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[23] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[24] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[25] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[26] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[27] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[28] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[29] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[30] */
+ 0x1, 0x1, 0x1, 0x1, /* auth[31] */
+ };
+
+ if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
+ return false;
+ }
+ if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
+ return false;
+ }
+ if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
+ return false;
+ }
+ return true;
+}
+
/* Split a path name into filename and stream name components. Canonicalise
* such that an implicit $DATA token is always explicit.
*
return true;
error:
- d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
+ d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
fname, expected_base ? expected_base : "<NULL>",
expected_stream ? expected_stream : "<NULL>",
nt_errstr(expected_status));
{"RANDOMIPC", run_randomipc, 0},
{"NEGNOWAIT", run_negprot_nowait, 0},
{"NBENCH", run_nbench, 0},
+ {"NBENCH2", run_nbench2, 0},
{"OPLOCK1", run_oplock1, 0},
{"OPLOCK2", run_oplock2, 0},
{"OPLOCK3", run_oplock3, 0},
+ {"OPLOCK4", run_oplock4, 0},
{"DIR", run_dirtest, 0},
{"DIR1", run_dirtest1, 0},
{"DIR-CREATETIME", run_dir_createtime, 0},
{"RW1", run_readwritetest, 0},
{"RW2", run_readwritemulti, FLAG_MULTIPROC},
{"RW3", run_readwritelarge, 0},
+ {"RW-SIGNING", run_readwritelarge_signtest, 0},
{"OPEN", run_opentest, 0},
{"POSIX", run_simple_posix_open_test, 0},
{"POSIX-APPEND", run_posix_append, 0},
+ {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
+ {"ASYNC-ECHO", run_async_echo, 0},
{ "UID-REGRESSION-TEST", run_uid_regression_test, 0},
{ "SHORTNAME-TEST", run_shortname_test, 0},
+ { "ADDRCHANGE", run_addrchange, 0},
#if 1
{"OPENATTR", run_openattrtest, 0},
#endif
{"XCOPY", run_xcopy, 0},
{"RENAME", run_rename, 0},
{"DELETE", run_deletetest, 0},
+ {"DELETE-LN", run_deletetest_ln, 0},
{"PROPERTIES", run_properties, 0},
{"MANGLE", torture_mangle, 0},
{"MANGLE1", run_mangle1, 0},
{ "TLDAP", run_tldap },
{ "STREAMERROR", run_streamerror },
{ "NOTIFY-BENCH", run_notify_bench },
+ { "BAD-NBT-SESSION", run_bad_nbt_session },
+ { "SMB-ANY-CONNECT", run_smb_any_connect },
{ "LOCAL-SUBSTITUTE", run_local_substitute, 0},
{ "LOCAL-GENCACHE", run_local_gencache, 0},
{ "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
{ "LOCAL-STREAM-NAME", run_local_stream_name, 0},
{ "LOCAL-WBCLIENT", run_local_wbclient, 0},
{ "LOCAL-string_to_sid", run_local_string_to_sid, 0},
+ { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
{ "LOCAL-DBTRANS", run_local_dbtrans, 0},
{ "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
+ { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
{NULL, NULL, 0}};
TALLOC_CTX *frame = talloc_stackframe();
int seed = time(NULL);
- dbf = x_stdout;
-
#ifdef HAVE_SETBUFFER
setbuffer(stdout, NULL, 0);
#endif
- load_case_tables();
+ setup_logging("smbtorture", DEBUG_STDOUT);
- setup_logging("smbtorture", true);
+ load_case_tables();
if (is_default_dyn_CONFIGFILE()) {
if(getenv("SMB_CONF_PATH")) {
torture_numops = atoi(optarg);
break;
case 'd':
- DEBUGLEVEL = atoi(optarg);
+ lp_set_cmdline("log level", optarg);
break;
case 'O':
sockops = optarg;