summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-04-30 15:26:43 -0700
committerJeremy Allison <jra@samba.org>2009-04-30 15:26:43 -0700
commit8cf78ff55312768d0b454b1d7e0560e04e6296da (patch)
tree0a2180f063e3bb9872c2565c92075dfb5dccac81 /source3
parentab4b8c9c0438bc5afca17e3ebf05dde6f98bc0aa (diff)
downloadsamba-8cf78ff55312768d0b454b1d7e0560e04e6296da.tar.gz
samba-8cf78ff55312768d0b454b1d7e0560e04e6296da.tar.bz2
samba-8cf78ff55312768d0b454b1d7e0560e04e6296da.zip
Get medieval on our ass about SMB1 file descriptors being 16 bits, not an int.
Convert all uses of cli_open(), cli_nt_createXXX to NTSTATUS versions. This is smaller than it looks, it just fixes a lot of old code. Next up, ensure all cli_XX functions return NTSTATUS. Jeremy.
Diffstat (limited to 'source3')
-rw-r--r--source3/client/client.c38
-rw-r--r--source3/client/clitar.c11
-rw-r--r--source3/client/smbspool.c5
-rw-r--r--source3/include/client.h2
-rw-r--r--source3/include/proto.h72
-rw-r--r--source3/libgpo/gpo_filesync.c6
-rw-r--r--source3/libsmb/clientgen.c2
-rw-r--r--source3/libsmb/clifile.c63
-rw-r--r--source3/libsmb/clioplock.c7
-rw-r--r--source3/libsmb/cliprint.c2
-rw-r--r--source3/libsmb/cliquota.c12
-rw-r--r--source3/libsmb/clirap.c6
-rw-r--r--source3/libsmb/clireadwrite.c12
-rw-r--r--source3/libsmb/clisecdesc.c4
-rw-r--r--source3/libsmb/libsmb_file.c16
-rw-r--r--source3/libsmb/libsmb_xattr.c21
-rw-r--r--source3/torture/denytest.c34
-rw-r--r--source3/torture/locktest.c35
-rw-r--r--source3/torture/locktest2.c8
-rw-r--r--source3/torture/mangle_test.c8
-rw-r--r--source3/torture/masktest.c5
-rw-r--r--source3/torture/nbio.c18
-rw-r--r--source3/torture/scanner.c22
-rw-r--r--source3/torture/torture.c580
-rw-r--r--source3/torture/utable.c17
-rw-r--r--source3/utils/net_rpc.c7
-rw-r--r--source3/utils/net_rpc_printer.c31
-rw-r--r--source3/utils/smbcacls.c33
-rw-r--r--source3/utils/smbcquotas.c4
29 files changed, 482 insertions, 599 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index 7dda981800..becb066153 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -535,12 +535,12 @@ static void display_finfo(file_info *finfo, const char *dir)
dir_total += finfo->size;
} else {
char *afname = NULL;
- int fnum;
+ uint16_t fnum;
/* skip if this is . or .. */
if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
return;
- /* create absolute filename for cli_nt_create() FIXME */
+ /* create absolute filename for cli_ntcreate() FIXME */
afname = talloc_asprintf(ctx,
"%s%s%s",
dir,
@@ -554,8 +554,9 @@ static void display_finfo(file_info *finfo, const char *dir)
d_printf( "MODE:%s\n", attrib_string(finfo->mode));
d_printf( "SIZE:%.0f\n", (double)finfo->size);
d_printf( "MTIME:%s", time_to_asc(t));
- fnum = cli_nt_create(finfo->cli, afname, CREATE_ACCESS_READ);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(finfo->cli, afname, 0,
+ CREATE_ACCESS_READ, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN, 0x0, 0x0, &fnum))) {
DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
afname,
cli_errstr( finfo->cli)));
@@ -999,7 +1000,8 @@ static NTSTATUS writefile_sink(char *buf, size_t n, void *priv)
static int do_get(const char *rname, const char *lname_in, bool reget)
{
TALLOC_CTX *ctx = talloc_tos();
- int handle = 0, fnum;
+ int handle = 0;
+ uint16_t fnum;
bool newhandle = false;
struct timeval tp_start;
uint16 attr;
@@ -1028,9 +1030,7 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
GetTimeOfDay(&tp_start);
- fnum = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum))) {
d_printf("%s opening remote file %s\n",cli_errstr(cli),rname);
return 1;
}
@@ -1618,7 +1618,7 @@ static int cmd_allinfo(void)
static int do_put(const char *rname, const char *lname, bool reput)
{
TALLOC_CTX *ctx = talloc_tos();
- int fnum;
+ uint16_t fnum;
XFILE *f;
SMB_OFF_T start = 0;
int rc = 0;
@@ -1636,8 +1636,8 @@ static int do_put(const char *rname, const char *lname, bool reput)
GetTimeOfDay(&tp_start);
if (reput) {
- fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE);
- if (fnum >= 0) {
+ status = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
+ if (NT_STATUS_IS_OK(status)) {
if (!cli_qfileinfo(targetcli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) &&
!cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL)) {
d_printf("getattrib: %s\n",cli_errstr(cli));
@@ -1645,10 +1645,10 @@ static int do_put(const char *rname, const char *lname, bool reput)
}
}
} else {
- fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
+ status = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum);
}
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname);
return 1;
}
@@ -2207,7 +2207,7 @@ static int cmd_open(void)
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- int fnum;
+ uint16_t fnum = (uint16_t)-1;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("open <filename>\n");
@@ -2226,10 +2226,12 @@ static int cmd_open(void)
return 1;
}
- fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA|FILE_WRITE_DATA);
- if (fnum == -1) {
- fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA);
- if (fnum != -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetname, 0,
+ FILE_READ_DATA|FILE_WRITE_DATA, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
+ if (NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetname, 0,
+ FILE_READ_DATA, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
d_printf("open file %s: for read/write fnum %d\n", targetname, fnum);
} else {
d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index fd375769e4..3cc1a25dbb 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -613,7 +613,7 @@ append one remote file to the tar file
static void do_atar(const char *rname_in,char *lname,file_info *finfo1)
{
- int fnum = -1;
+ uint16_t fnum = (uint16_t)-1;
uint64_t nread=0;
char ftype;
file_info2 finfo;
@@ -660,9 +660,7 @@ static void do_atar(const char *rname_in,char *lname,file_info *finfo1)
goto cleanup;
}
- fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, rname, O_RDONLY, DENY_NONE, &fnum))) {
DEBUG(0,("%s opening remote file %s (%s)\n",
cli_errstr(cli),rname, client_get_cur_dir()));
goto cleanup;
@@ -998,13 +996,14 @@ static int skip_file(int skipsize)
static int get_file(file_info2 finfo)
{
- int fnum = -1, pos = 0, dsize = 0, bpos = 0;
+ uint16_t fnum;
+ int pos = 0, dsize = 0, bpos = 0;
uint64_t rsize = 0;
DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size));
if (ensurepath(finfo.name) &&
- (fnum=cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) {
+ (!NT_STATUS_IS_OK(cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,&fnum)))) {
DEBUG(0, ("abandoning restore\n"));
return(False);
}
diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c
index a276353a87..6b099dbc0b 100644
--- a/source3/client/smbspool.c
+++ b/source3/client/smbspool.c
@@ -553,7 +553,7 @@ smb_print(struct cli_state * cli, /* I - SMB connection */
char *title, /* I - Title/job name */
FILE * fp)
{ /* I - File to print */
- int fnum; /* File number */
+ uint16_t fnum; /* File number */
int nbytes, /* Number of bytes read */
tbytes; /* Total bytes read */
char buffer[8192], /* Buffer for copy */
@@ -574,8 +574,7 @@ smb_print(struct cli_state * cli, /* I - SMB connection */
* Open the printer device...
*/
- fnum = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
fprintf(stderr, "ERROR: %s opening remote spool %s\n",
cli_errstr(cli), title);
return (get_exit_code(cli, cli_nt_error(cli)));
diff --git a/source3/include/client.h b/source3/include/client.h
index 6d84f482c2..6f56468274 100644
--- a/source3/include/client.h
+++ b/source3/include/client.h
@@ -259,7 +259,7 @@ struct cli_state {
bool use_level_II_oplocks; /* should we use level II oplocks? */
/* a oplock break request handler */
- bool (*oplock_handler)(struct cli_state *cli, int fnum, unsigned char level);
+ NTSTATUS (*oplock_handler)(struct cli_state *cli, uint16_t fnum, unsigned char level);
bool force_dos_errors;
bool case_sensitive; /* False by default. */
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 11fd45ed5e..f60fc9d89c 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2375,12 +2375,7 @@ struct tevent_req *cli_rmdir_send(TALLOC_CTX *mem_ctx,
const char *dname);
NTSTATUS cli_rmdir_recv(struct tevent_req *req);
NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname);
-int cli_nt_delete_on_close(struct cli_state *cli, int fnum, bool flag);
-int cli_nt_create_full(struct cli_state *cli, const char *fname,
- uint32_t CreatFlags, uint32_t DesiredAccess,
- uint32_t FileAttributes, uint32_t ShareAccess,
- uint32_t CreateDisposition, uint32_t CreateOptions,
- uint8_t SecuityFlags);
+int cli_nt_delete_on_close(struct cli_state *cli, uint16_t fnum, bool flag);
struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
struct event_context *ev,
struct cli_state *cli,
@@ -2403,7 +2398,6 @@ NTSTATUS cli_ntcreate(struct cli_state *cli,
uint32_t CreateOptions,
uint8_t SecurityFlags,
uint16_t *pfid);
-int cli_nt_create(struct cli_state *cli, const char *fname, uint32_t DesiredAccess);
uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str,
size_t str_len, size_t *pconverted_size);
struct tevent_req *cli_open_create(TALLOC_CTX *mem_ctx,
@@ -2414,32 +2408,32 @@ struct tevent_req *cli_open_create(TALLOC_CTX *mem_ctx,
struct tevent_req *cli_open_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
struct cli_state *cli, const char *fname,
int flags, int share_mode);
-NTSTATUS cli_open_recv(struct tevent_req *req, int *fnum);
-int cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode);
+NTSTATUS cli_open_recv(struct tevent_req *req, uint16_t *fnum);
+NTSTATUS cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode, uint16_t *pfnum);
struct tevent_req *cli_close_create(TALLOC_CTX *mem_ctx,
struct event_context *ev,
- struct cli_state *cli, int fnum,
+ struct cli_state *cli, uint16_t fnum,
struct tevent_req **psubreq);
struct tevent_req *cli_close_send(TALLOC_CTX *mem_ctx,
struct event_context *ev,
- struct cli_state *cli, int fnum);
+ struct cli_state *cli, uint16_t fnum);
NTSTATUS cli_close_recv(struct tevent_req *req);
-bool cli_close(struct cli_state *cli, int fnum);
-bool cli_ftruncate(struct cli_state *cli, int fnum, uint64_t size);
-NTSTATUS cli_locktype(struct cli_state *cli, int fnum,
+bool cli_close(struct cli_state *cli, uint16_t fnum);
+bool cli_ftruncate(struct cli_state *cli, uint16_t fnum, uint64_t size);
+NTSTATUS cli_locktype(struct cli_state *cli, uint16_t fnum,
uint32_t offset, uint32_t len,
int timeout, unsigned char locktype);
-bool cli_lock(struct cli_state *cli, int fnum,
+bool cli_lock(struct cli_state *cli, uint16_t fnum,
uint32_t offset, uint32_t len, int timeout, enum brl_type lock_type);
-bool cli_unlock(struct cli_state *cli, int fnum, uint32_t offset, uint32_t len);
-bool cli_lock64(struct cli_state *cli, int fnum,
+bool cli_unlock(struct cli_state *cli, uint16_t fnum, uint32_t offset, uint32_t len);
+bool cli_lock64(struct cli_state *cli, uint16_t fnum,
uint64_t offset, uint64_t len, int timeout, enum brl_type lock_type);
-bool cli_unlock64(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len);
-bool cli_posix_lock(struct cli_state *cli, int fnum,
+bool cli_unlock64(struct cli_state *cli, uint16_t fnum, uint64_t offset, uint64_t len);
+bool cli_posix_lock(struct cli_state *cli, uint16_t fnum,
uint64_t offset, uint64_t len,
bool wait_lock, enum brl_type lock_type);
-bool cli_posix_unlock(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len);
-bool cli_posix_getlock(struct cli_state *cli, int fnum, uint64_t *poffset, uint64_t *plen);
+bool cli_posix_unlock(struct cli_state *cli, uint16_t fnum, uint64_t offset, uint64_t len);
+bool cli_posix_getlock(struct cli_state *cli, uint16_t fnum, uint64_t *poffset, uint64_t *plen);
bool cli_getattrE(struct cli_state *cli, int fd,
uint16_t *attr, SMB_OFF_T *size,
time_t *change_time,
@@ -2465,14 +2459,14 @@ NTSTATUS cli_dskattr_recv(struct tevent_req *req, int *bsize, int *total,
int *avail);
NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path);
-NTSTATUS cli_raw_ioctl(struct cli_state *cli, int fnum, uint32_t code, DATA_BLOB *blob);
+NTSTATUS cli_raw_ioctl(struct cli_state *cli, uint16_t fnum, uint32_t code, DATA_BLOB *blob);
bool cli_set_ea_path(struct cli_state *cli, const char *path, const char *ea_name, const char *ea_val, size_t ea_len);
-bool cli_set_ea_fnum(struct cli_state *cli, int fnum, const char *ea_name, const char *ea_val, size_t ea_len);
+bool cli_set_ea_fnum(struct cli_state *cli, uint16_t fnum, const char *ea_name, const char *ea_val, size_t ea_len);
bool cli_get_ea_list_path(struct cli_state *cli, const char *path,
TALLOC_CTX *ctx,
size_t *pnum_eas,
struct ea_struct **pea_list);
-bool cli_get_ea_list_fnum(struct cli_state *cli, int fnum,
+bool cli_get_ea_list_fnum(struct cli_state *cli, uint16_t fnum,
TALLOC_CTX *ctx,
size_t *pnum_eas,
struct ea_struct **pea_list);
@@ -2564,9 +2558,9 @@ struct tevent_req *cli_oplock_ack_send(TALLOC_CTX *mem_ctx,
struct cli_state *cli,
uint16_t fnum, uint8_t level);
NTSTATUS cli_oplock_ack_recv(struct tevent_req *req);
-bool cli_oplock_ack(struct cli_state *cli, int fnum, unsigned char level);
+NTSTATUS cli_oplock_ack(struct cli_state *cli, uint16_t fnum, unsigned char level);
void cli_oplock_handler(struct cli_state *cli,
- bool (*handler)(struct cli_state *, int, unsigned char));
+ NTSTATUS (*handler)(struct cli_state *, uint16_t, unsigned char));
/* The following definitions come from libsmb/cliprint.c */
@@ -2574,11 +2568,11 @@ int cli_print_queue(struct cli_state *cli,
void (*fn)(struct print_job_info *));
int cli_printjob_del(struct cli_state *cli, int job);
int cli_spl_open(struct cli_state *cli, const char *fname, int flags, int share_mode);
-bool cli_spl_close(struct cli_state *cli, int fnum);
+bool cli_spl_close(struct cli_state *cli, uint16_t fnum);
/* The following definitions come from libsmb/cliquota.c */
-bool cli_get_quota_handle(struct cli_state *cli, int *quota_fnum);
+NTSTATUS cli_get_quota_handle(struct cli_state *cli, uint16_t *quota_fnum);
void free_ntquota_list(SMB_NTQUOTA_LIST **qt_list);
bool cli_get_user_quota(struct cli_state *cli, int quota_fnum, SMB_NTQUOTA_STRUCT *pqt);
bool cli_set_user_quota(struct cli_state *cli, int quota_fnum, SMB_NTQUOTA_STRUCT *pqt);
@@ -2626,8 +2620,8 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
TALLOC_CTX *mem_ctx,
unsigned int *pnum_streams,
struct stream_struct **pstreams);
-bool cli_qfilename(struct cli_state *cli, int fnum, char *name, size_t namelen);
-bool cli_qfileinfo(struct cli_state *cli, int fnum,
+bool cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name, size_t namelen);
+bool cli_qfileinfo(struct cli_state *cli, uint16_t fnum,
uint16 *mode, SMB_OFF_T *size,
struct timespec *create_time,
struct timespec *access_time,
@@ -2636,7 +2630,7 @@ bool cli_qfileinfo(struct cli_state *cli, int fnum,
SMB_INO_T *ino);
bool cli_qpathinfo_basic( struct cli_state *cli, const char *name,
SMB_STRUCT_STAT *sbuf, uint32 *attributes );
-bool cli_qfileinfo_test(struct cli_state *cli, int fnum, int level, char **poutdata, uint32 *poutlen);
+bool cli_qfileinfo_test(struct cli_state *cli, uint16_t fnum, int level, char **poutdata, uint32 *poutlen);
NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstring alt_name);
/* The following definitions come from libsmb/clirap2.c */
@@ -2693,12 +2687,12 @@ int cli_NetConnectionEnum(struct cli_state *cli, const char *qualifier,
struct tevent_req *cli_read_andx_create(TALLOC_CTX *mem_ctx,
struct event_context *ev,
- struct cli_state *cli, int fnum,
+ struct cli_state *cli, uint16_t fnum,
off_t offset, size_t size,
struct tevent_req **psmbreq);
struct tevent_req *cli_read_andx_send(TALLOC_CTX *mem_ctx,
struct event_context *ev,
- struct cli_state *cli, int fnum,
+ struct cli_state *cli, uint16_t fnum,
off_t offset, size_t size);
NTSTATUS cli_read_andx_recv(struct tevent_req *req, ssize_t *received,
uint8_t **rcvbuf);
@@ -2715,14 +2709,14 @@ NTSTATUS cli_pull(struct cli_state *cli, uint16_t fnum,
off_t start_offset, SMB_OFF_T size, size_t window_size,
NTSTATUS (*sink)(char *buf, size_t n, void *priv),
void *priv, SMB_OFF_T *received);
-ssize_t cli_read(struct cli_state *cli, int fnum, char *buf,
+ssize_t cli_read(struct cli_state *cli, uint16_t fnum, char *buf,
off_t offset, size_t size);
-ssize_t cli_readraw(struct cli_state *cli, int fnum, char *buf, off_t offset, size_t size);
+ssize_t cli_readraw(struct cli_state *cli, uint16_t fnum, char *buf, off_t offset, size_t size);
ssize_t cli_write(struct cli_state *cli,
- int fnum, uint16 write_mode,
+ uint16_t fnum, uint16 write_mode,
const char *buf, off_t offset, size_t size);
ssize_t cli_smbwrite(struct cli_state *cli,
- int fnum, char *buf, off_t offset, size_t size1);
+ uint16_t fnum, char *buf, off_t offset, size_t size1);
struct tevent_req *cli_write_andx_create(TALLOC_CTX *mem_ctx,
struct event_context *ev,
struct cli_state *cli, uint16_t fnum,
@@ -2753,9 +2747,9 @@ NTSTATUS cli_push(struct cli_state *cli, uint16_t fnum, uint16_t mode,
/* The following definitions come from libsmb/clisecdesc.c */
-SEC_DESC *cli_query_secdesc(struct cli_state *cli, int fnum,
+SEC_DESC *cli_query_secdesc(struct cli_state *cli, uint16_t fnum,
TALLOC_CTX *mem_ctx);
-bool cli_set_secdesc(struct cli_state *cli, int fnum, SEC_DESC *sd);
+bool cli_set_secdesc(struct cli_state *cli, uint16_t fnum, SEC_DESC *sd);
/* The following definitions come from libsmb/clispnego.c */
diff --git a/source3/libgpo/gpo_filesync.c b/source3/libgpo/gpo_filesync.c
index 6d64d7b968..d4b623ad6e 100644
--- a/source3/libgpo/gpo_filesync.c
+++ b/source3/libgpo/gpo_filesync.c
@@ -39,15 +39,15 @@ NTSTATUS gpo_copy_file(TALLOC_CTX *mem_ctx,
const char *unix_path)
{
NTSTATUS result;
- int fnum;
+ uint16_t fnum;
int fd = 0;
char *data = NULL;
static int io_bufsize = 64512;
int read_size = io_bufsize;
off_t nread = 0;
- if ((fnum = cli_open(cli, nt_path, O_RDONLY, DENY_NONE)) == -1) {
- result = NT_STATUS_NO_SUCH_FILE;
+ result = cli_open(cli, nt_path, O_RDONLY, DENY_NONE, &fnum);
+ if (!NT_STATUS_IS_OK(result)) {
goto out;
}
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 45addc2163..b06a6fa187 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -234,7 +234,7 @@ bool cli_receive_smb(struct cli_state *cli)
if (cli->oplock_handler) {
int fnum = SVAL(cli->inbuf,smb_vwv2);
unsigned char level = CVAL(cli->inbuf,smb_vwv3+1);
- if (!cli->oplock_handler(cli, fnum, level)) {
+ if (!NT_STATUS_IS_OK(cli->oplock_handler(cli, fnum, level))) {
return false;
}
}
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 54c59473e6..05730413b0 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -1083,7 +1083,7 @@ NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname)
Set or clear the delete on close flag.
****************************************************************************/
-int cli_nt_delete_on_close(struct cli_state *cli, int fnum, bool flag)
+int cli_nt_delete_on_close(struct cli_state *cli, uint16_t fnum, bool flag)
{
unsigned int data_len = 1;
unsigned int param_len = 6;
@@ -1125,6 +1125,7 @@ int cli_nt_delete_on_close(struct cli_state *cli, int fnum, bool flag)
Used in smbtorture.
****************************************************************************/
+#if 0
int cli_nt_create_full(struct cli_state *cli, const char *fname,
uint32_t CreatFlags, uint32_t DesiredAccess,
uint32_t FileAttributes, uint32_t ShareAccess,
@@ -1181,6 +1182,7 @@ int cli_nt_create_full(struct cli_state *cli, const char *fname,
return SVAL(cli->inbuf,smb_vwv2 + 1);
}
+#endif
struct cli_ntcreate_state {
uint16_t vwv[24];
@@ -1344,6 +1346,7 @@ NTSTATUS cli_ntcreate(struct cli_state *cli,
return status;
}
+#if 0
/****************************************************************************
Open a file.
****************************************************************************/
@@ -1353,6 +1356,7 @@ int cli_nt_create(struct cli_state *cli, const char *fname, uint32_t DesiredAcce
return cli_nt_create_full(cli, fname, 0, DesiredAccess, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0);
}
+#endif
uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2,
const char *str, size_t str_len,
@@ -1411,7 +1415,7 @@ uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2,
struct cli_open_state {
uint16_t vwv[15];
- int fnum;
+ uint16_t fnum;
struct iovec bytes;
};
@@ -1544,7 +1548,7 @@ static void cli_open_done(struct tevent_req *subreq)
tevent_req_done(req);
}
-NTSTATUS cli_open_recv(struct tevent_req *req, int *fnum)
+NTSTATUS cli_open_recv(struct tevent_req *req, uint16_t *pfnum)
{
struct cli_open_state *state = tevent_req_data(
req, struct cli_open_state);
@@ -1553,18 +1557,17 @@ NTSTATUS cli_open_recv(struct tevent_req *req, int *fnum)
if (tevent_req_is_nterror(req, &status)) {
return status;
}
- *fnum = state->fnum;
+ *pfnum = state->fnum;
return NT_STATUS_OK;
}
-int cli_open(struct cli_state *cli, const char *fname, int flags,
- int share_mode)
+NTSTATUS cli_open(struct cli_state *cli, const char *fname, int flags,
+ int share_mode, uint16_t *pfnum)
{
TALLOC_CTX *frame = talloc_stackframe();
struct event_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_OK;
- int result = -1;
if (cli_has_async_calls(cli)) {
/*
@@ -1591,13 +1594,13 @@ int cli_open(struct cli_state *cli, const char *fname, int flags,
goto fail;
}
- cli_open_recv(req, &result);
+ status = cli_open_recv(req, pfnum);
fail:
TALLOC_FREE(frame);
if (!NT_STATUS_IS_OK(status)) {
cli_set_error(cli, status);
}
- return result;
+ return status;
}
/****************************************************************************
@@ -1611,9 +1614,10 @@ struct cli_close_state {
static void cli_close_done(struct tevent_req *subreq);
struct tevent_req *cli_close_create(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
- struct cli_state *cli, int fnum,
- struct tevent_req **psubreq)
+ struct event_context *ev,
+ struct cli_state *cli,
+ uint16_t fnum,
+ struct tevent_req **psubreq)
{
struct tevent_req *req, *subreq;
struct cli_close_state *state;
@@ -1637,8 +1641,9 @@ struct tevent_req *cli_close_create(TALLOC_CTX *mem_ctx,
}
struct tevent_req *cli_close_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
- struct cli_state *cli, int fnum)
+ struct event_context *ev,
+ struct cli_state *cli,
+ uint16_t fnum)
{
struct tevent_req *req, *subreq;
@@ -1670,7 +1675,7 @@ NTSTATUS cli_close_recv(struct tevent_req *req)
return tevent_req_simple_recv_ntstatus(req);
}
-bool cli_close(struct cli_state *cli, int fnum)
+bool cli_close(struct cli_state *cli, uint16_t fnum)
{
TALLOC_CTX *frame = talloc_stackframe();
struct event_context *ev;
@@ -1716,7 +1721,7 @@ bool cli_close(struct cli_state *cli, int fnum)
Truncate a file to a specified size
****************************************************************************/
-bool cli_ftruncate(struct cli_state *cli, int fnum, uint64_t size)
+bool cli_ftruncate(struct cli_state *cli, uint16_t fnum, uint64_t size)
{
unsigned int param_len = 6;
unsigned int data_len = 8;
@@ -1766,7 +1771,7 @@ bool cli_ftruncate(struct cli_state *cli, int fnum, uint64_t size)
this is used for testing LOCKING_ANDX_CANCEL_LOCK
****************************************************************************/
-NTSTATUS cli_locktype(struct cli_state *cli, int fnum,
+NTSTATUS cli_locktype(struct cli_state *cli, uint16_t fnum,
uint32_t offset, uint32_t len,
int timeout, unsigned char locktype)
{
@@ -1819,7 +1824,7 @@ NTSTATUS cli_locktype(struct cli_state *cli, int fnum,
note that timeout is in units of 2 milliseconds
****************************************************************************/
-bool cli_lock(struct cli_state *cli, int fnum,
+bool cli_lock(struct cli_state *cli, uint16_t fnum,
uint32_t offset, uint32_t len, int timeout, enum brl_type lock_type)
{
char *p;
@@ -1874,7 +1879,7 @@ bool cli_lock(struct cli_state *cli, int fnum,
Unlock a file.
****************************************************************************/
-bool cli_unlock(struct cli_state *cli, int fnum, uint32_t offset, uint32_t len)
+bool cli_unlock(struct cli_state *cli, uint16_t fnum, uint32_t offset, uint32_t len)
{
char *p;
@@ -1916,7 +1921,7 @@ bool cli_unlock(struct cli_state *cli, int fnum, uint32_t offset, uint32_t len)
Lock a file with 64 bit offsets.
****************************************************************************/
-bool cli_lock64(struct cli_state *cli, int fnum,
+bool cli_lock64(struct cli_state *cli, uint16_t fnum,
uint64_t offset, uint64_t len, int timeout, enum brl_type lock_type)
{
char *p;
@@ -1977,7 +1982,7 @@ bool cli_lock64(struct cli_state *cli, int fnum,
Unlock a file with 64 bit offsets.
****************************************************************************/
-bool cli_unlock64(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len)
+bool cli_unlock64(struct cli_state *cli, uint16_t fnum, uint64_t offset, uint64_t len)
{
char *p;
@@ -2023,7 +2028,7 @@ bool cli_unlock64(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len
Get/unlock a POSIX lock on a file - internal function.
****************************************************************************/
-static bool cli_posix_lock_internal(struct cli_state *cli, int fnum,
+static bool cli_posix_lock_internal(struct cli_state *cli, uint16_t fnum,
uint64_t offset, uint64_t len, bool wait_lock, enum brl_type lock_type)
{
unsigned int param_len = 4;
@@ -2094,7 +2099,7 @@ static bool cli_posix_lock_internal(struct cli_state *cli, int fnum,
POSIX Lock a file.
****************************************************************************/
-bool cli_posix_lock(struct cli_state *cli, int fnum,
+bool cli_posix_lock(struct cli_state *cli, uint16_t fnum,
uint64_t offset, uint64_t len,
bool wait_lock, enum brl_type lock_type)
{
@@ -2108,7 +2113,7 @@ bool cli_posix_lock(struct cli_state *cli, int fnum,
POSIX Unlock a file.
****************************************************************************/
-bool cli_posix_unlock(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len)
+bool cli_posix_unlock(struct cli_state *cli, uint16_t fnum, uint64_t offset, uint64_t len)
{
return cli_posix_lock_internal(cli, fnum, offset, len, False, UNLOCK_LOCK);
}
@@ -2117,7 +2122,7 @@ bool cli_posix_unlock(struct cli_state *cli, int fnum, uint64_t offset, uint64_t
POSIX Get any lock covering a file.
****************************************************************************/
-bool cli_posix_getlock(struct cli_state *cli, int fnum, uint64_t *poffset, uint64_t *plen)
+bool cli_posix_getlock(struct cli_state *cli, uint16_t fnum, uint64_t *poffset, uint64_t *plen)
{
return True;
}
@@ -2603,7 +2608,7 @@ int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path)
/*
send a raw ioctl - used by the torture code
*/
-NTSTATUS cli_raw_ioctl(struct cli_state *cli, int fnum, uint32_t code, DATA_BLOB *blob)
+NTSTATUS cli_raw_ioctl(struct cli_state *cli, uint16_t fnum, uint32_t code, DATA_BLOB *blob)
{
memset(cli->outbuf,'\0',smb_size);
memset(cli->inbuf,'\0',smb_size);
@@ -2725,7 +2730,7 @@ bool cli_set_ea_path(struct cli_state *cli, const char *path, const char *ea_nam
Set an extended attribute on an fnum.
*********************************************************/
-bool cli_set_ea_fnum(struct cli_state *cli, int fnum, const char *ea_name, const char *ea_val, size_t ea_len)
+bool cli_set_ea_fnum(struct cli_state *cli, uint16_t fnum, const char *ea_name, const char *ea_val, size_t ea_len)
{
char param[6];
uint16_t setup = TRANSACT2_SETFILEINFO;
@@ -2898,7 +2903,7 @@ bool cli_get_ea_list_path(struct cli_state *cli, const char *path,
Get an extended attribute list from an fnum.
*********************************************************/
-bool cli_get_ea_list_fnum(struct cli_state *cli, int fnum,
+bool cli_get_ea_list_fnum(struct cli_state *cli, uint16_t fnum,
TALLOC_CTX *ctx,
size_t *pnum_eas,
struct ea_struct **pea_list)
@@ -2979,7 +2984,7 @@ static int cli_posix_open_internal(struct cli_state *cli, const char *fname, int
char data[18];
char *rparam=NULL, *rdata=NULL;
char *p;
- int fnum = -1;
+ uint16_t fnum = (uint16_t)-1;
uint32_t wire_flags = open_flags_to_wire(flags);
size_t srclen = 2*(strlen(fname)+1);
diff --git a/source3/libsmb/clioplock.c b/source3/libsmb/clioplock.c
index e3fb66aba0..7350c4aaa3 100644
--- a/source3/libsmb/clioplock.c
+++ b/source3/libsmb/clioplock.c
@@ -80,7 +80,7 @@ NTSTATUS cli_oplock_ack_recv(struct tevent_req *req)
return tevent_req_simple_recv_ntstatus(req);
}
-bool cli_oplock_ack(struct cli_state *cli, int fnum, unsigned char level)
+NTSTATUS cli_oplock_ack(struct cli_state *cli, uint16_t fnum, unsigned char level)
{
TALLOC_CTX *frame = talloc_stackframe();
struct event_context *ev;
@@ -118,14 +118,15 @@ bool cli_oplock_ack(struct cli_state *cli, int fnum, unsigned char level)
if (!NT_STATUS_IS_OK(status)) {
cli_set_error(cli, status);
}
- return NT_STATUS_IS_OK(status);
+ return status;
}
/****************************************************************************
set the oplock handler for a connection
****************************************************************************/
+
void cli_oplock_handler(struct cli_state *cli,
- bool (*handler)(struct cli_state *, int, unsigned char))
+ NTSTATUS (*handler)(struct cli_state *, uint16_t, unsigned char))
{
cli->oplock_handler = handler;
}
diff --git a/source3/libsmb/cliprint.c b/source3/libsmb/cliprint.c
index 223ddb4186..e78930c1d5 100644
--- a/source3/libsmb/cliprint.c
+++ b/source3/libsmb/cliprint.c
@@ -237,7 +237,7 @@ int cli_spl_open(struct cli_state *cli, const char *fname, int flags, int share_
Close a file.
****************************************************************************/
-bool cli_spl_close(struct cli_state *cli, int fnum)
+bool cli_spl_close(struct cli_state *cli, uint16_t fnum)
{
memset(cli->outbuf,'\0',smb_size);
memset(cli->inbuf,'\0',smb_size);
diff --git a/source3/libsmb/cliquota.c b/source3/libsmb/cliquota.c
index e40dac368d..a8b1aa19fd 100644
--- a/source3/libsmb/cliquota.c
+++ b/source3/libsmb/cliquota.c
@@ -19,18 +19,12 @@
#include "includes.h"
-bool cli_get_quota_handle(struct cli_state *cli, int *quota_fnum)
+NTSTATUS cli_get_quota_handle(struct cli_state *cli, uint16_t *quota_fnum)
{
- *quota_fnum = cli_nt_create_full(cli, FAKE_FILE_NAME_QUOTA_WIN32,
+ return cli_ntcreate(cli, FAKE_FILE_NAME_QUOTA_WIN32,
0x00000016, DESIRED_ACCESS_PIPE,
0x00000000, FILE_SHARE_READ|FILE_SHARE_WRITE,
- FILE_OPEN, 0x00000000, 0x03);
-
- if (*quota_fnum == (-1)) {
- return False;
- }
-
- return True;
+ FILE_OPEN, 0x00000000, 0x03, quota_fnum);
}
void free_ntquota_list(SMB_NTQUOTA_LIST **qt_list)
diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c
index 976e184e9c..1771e8fd25 100644
--- a/source3/libsmb/clirap.c
+++ b/source3/libsmb/clirap.c
@@ -919,7 +919,7 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
Send a qfileinfo QUERY_FILE_NAME_INFO call.
****************************************************************************/
-bool cli_qfilename(struct cli_state *cli, int fnum, char *name, size_t namelen)
+bool cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name, size_t namelen)
{
unsigned int data_len = 0;
unsigned int param_len = 0;
@@ -966,7 +966,7 @@ bool cli_qfilename(struct cli_state *cli, int fnum, char *name, size_t namelen)
Send a qfileinfo call.
****************************************************************************/
-bool cli_qfileinfo(struct cli_state *cli, int fnum,
+bool cli_qfileinfo(struct cli_state *cli, uint16_t fnum,
uint16 *mode, SMB_OFF_T *size,
struct timespec *create_time,
struct timespec *access_time,
@@ -1121,7 +1121,7 @@ bool cli_qpathinfo_basic( struct cli_state *cli, const char *name,
Send a qfileinfo call.
****************************************************************************/
-bool cli_qfileinfo_test(struct cli_state *cli, int fnum, int level, char **poutdata, uint32 *poutlen)
+bool cli_qfileinfo_test(struct cli_state *cli, uint16_t fnum, int level, char **poutdata, uint32 *poutlen)
{
unsigned int data_len = 0;
unsigned int param_len = 0;
diff --git a/source3/libsmb/clireadwrite.c b/source3/libsmb/clireadwrite.c
index 1d2f5f79ec..07d438fd25 100644
--- a/source3/libsmb/clireadwrite.c
+++ b/source3/libsmb/clireadwrite.c
@@ -82,7 +82,7 @@ static void cli_read_andx_done(struct tevent_req *subreq);
struct tevent_req *cli_read_andx_create(TALLOC_CTX *mem_ctx,
struct event_context *ev,
- struct cli_state *cli, int fnum,
+ struct cli_state *cli, uint16_t fnum,
off_t offset, size_t size,
struct tevent_req **psmbreq)
{
@@ -135,7 +135,7 @@ struct tevent_req *cli_read_andx_create(TALLOC_CTX *mem_ctx,
struct tevent_req *cli_read_andx_send(TALLOC_CTX *mem_ctx,
struct event_context *ev,
- struct cli_state *cli, int fnum,
+ struct cli_state *cli, uint16_t fnum,
off_t offset, size_t size)
{
struct tevent_req *req, *subreq;
@@ -554,7 +554,7 @@ static NTSTATUS cli_read_sink(char *buf, size_t n, void *priv)
return NT_STATUS_OK;
}
-ssize_t cli_read(struct cli_state *cli, int fnum, char *buf,
+ssize_t cli_read(struct cli_state *cli, uint16_t fnum, char *buf,
off_t offset, size_t size)
{
NTSTATUS status;
@@ -574,7 +574,7 @@ ssize_t cli_read(struct cli_state *cli, int fnum, char *buf,
****************************************************************************/
static bool cli_issue_write(struct cli_state *cli,
- int fnum,
+ uint16_t fnum,
off_t offset,
uint16 mode,
const char *buf,
@@ -674,7 +674,7 @@ static bool cli_issue_write(struct cli_state *cli,
****************************************************************************/
ssize_t cli_write(struct cli_state *cli,
- int fnum, uint16 write_mode,
+ uint16_t fnum, uint16 write_mode,
const char *buf, off_t offset, size_t size)
{
ssize_t bwritten = 0;
@@ -735,7 +735,7 @@ ssize_t cli_write(struct cli_state *cli,
****************************************************************************/
ssize_t cli_smbwrite(struct cli_state *cli,
- int fnum, char *buf, off_t offset, size_t size1)
+ uint16_t fnum, char *buf, off_t offset, size_t size1)
{
char *p;
ssize_t total = 0;
diff --git a/source3/libsmb/clisecdesc.c b/source3/libsmb/clisecdesc.c
index f0b786c899..1c87eabafe 100644
--- a/source3/libsmb/clisecdesc.c
+++ b/source3/libsmb/clisecdesc.c
@@ -22,7 +22,7 @@
/****************************************************************************
query the security descriptor for a open file
****************************************************************************/
-SEC_DESC *cli_query_secdesc(struct cli_state *cli, int fnum,
+SEC_DESC *cli_query_secdesc(struct cli_state *cli, uint16_t fnum,
TALLOC_CTX *mem_ctx)
{
uint8_t param[8];
@@ -70,7 +70,7 @@ SEC_DESC *cli_query_secdesc(struct cli_state *cli, int fnum,
/****************************************************************************
set the security descriptor for a open file
****************************************************************************/
-bool cli_set_secdesc(struct cli_state *cli, int fnum, SEC_DESC *sd)
+bool cli_set_secdesc(struct cli_state *cli, uint16_t fnum, SEC_DESC *sd)
{
char param[8];
char *rparam=NULL, *rdata=NULL;
diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c
index aa02807092..4724658fe3 100644
--- a/source3/libsmb/libsmb_file.c
+++ b/source3/libsmb/libsmb_file.c
@@ -47,7 +47,8 @@ SMBC_open_ctx(SMBCCTX *context,
struct cli_state *targetcli = NULL;
SMBCSRV *srv = NULL;
SMBCFILE *file = NULL;
- int fd;
+ uint16_t fd;
+ NTSTATUS status = NT_STATUS_OBJECT_PATH_INVALID;
TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) {
@@ -102,7 +103,7 @@ SMBC_open_ctx(SMBCCTX *context,
/* Hmmm, the test for a directory is suspect here ... FIXME */
if (strlen(path) > 0 && path[strlen(path) - 1] == '\\') {
- fd = -1;
+ status = NT_STATUS_OBJECT_PATH_INVALID;
} else {
file = SMB_MALLOC_P(SMBCFILE);
@@ -126,8 +127,9 @@ SMBC_open_ctx(SMBCCTX *context,
}
/*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/
- if ((fd = cli_open(targetcli, targetpath, flags,
- context->internal->share_mode)) < 0) {
+ status = cli_open(targetcli, targetpath, flags,
+ context->internal->share_mode, &fd);
+ if (!NT_STATUS_IS_OK(status)) {
/* Handle the error ... */
@@ -186,7 +188,7 @@ SMBC_open_ctx(SMBCCTX *context,
/* Check if opendir needed ... */
- if (fd == -1) {
+ if (!NT_STATUS_IS_OK(status)) {
int eno = 0;
eno = SMBC_errno(context, srv->cli);
@@ -627,7 +629,7 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
time_t change_time,
uint16 mode)
{
- int fd;
+ uint16_t fd;
int ret;
TALLOC_CTX *frame = talloc_stackframe();
@@ -659,7 +661,7 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
srv->no_pathinfo = True;
/* Open the file */
- if ((fd = cli_open(srv->cli, path, O_RDWR, DENY_NONE)) < 0) {
+ if (!NT_STATUS_IS_OK(cli_open(srv->cli, path, O_RDWR, DENY_NONE, &fd))) {
errno = SMBC_errno(context, srv->cli);
TALLOC_FREE(frame);
diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c
index e4a0a05586..a152830c5d 100644
--- a/source3/libsmb/libsmb_xattr.c
+++ b/source3/libsmb/libsmb_xattr.c
@@ -730,7 +730,7 @@ cacl_get(SMBCCTX *context,
bool exclude_dos_inode = False;
bool numeric = True;
bool determine_size = (bufsize == 0);
- int fnum = -1;
+ uint16_t fnum;
SEC_DESC *sd;
fstring sidstr;
fstring name_sandbox;
@@ -901,9 +901,8 @@ cacl_get(SMBCCTX *context,
}
/* ... then obtain any NT attributes which were requested */
- fnum = cli_nt_create(targetcli, targetpath, CREATE_ACCESS_READ);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetpath, 0, CREATE_ACCESS_READ, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
DEBUG(5, ("cacl_get failed to open %s: %s\n",
targetpath, cli_errstr(targetcli)));
errno = 0;
@@ -1507,7 +1506,7 @@ cacl_set(SMBCCTX *context,
int mode,
int flags)
{
- int fnum;
+ uint16_t fnum = (uint16_t)-1;
int err = 0;
SEC_DESC *sd = NULL, *old;
SEC_ACL *dacl = NULL;
@@ -1560,9 +1559,8 @@ cacl_set(SMBCCTX *context,
/* The desired access below is the only one I could find that works
with NT4, W2KP and Samba */
- fnum = cli_nt_create(targetcli, targetpath, CREATE_ACCESS_READ);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetpath, 0, CREATE_ACCESS_READ, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
DEBUG(5, ("cacl_set failed to open %s: %s\n",
targetpath, cli_errstr(targetcli)));
errno = 0;
@@ -1666,10 +1664,9 @@ cacl_set(SMBCCTX *context,
sd = make_sec_desc(ctx, old->revision, SEC_DESC_SELF_RELATIVE,
owner_sid, group_sid, NULL, dacl, &sd_size);
- fnum = cli_nt_create(targetcli, targetpath,
- WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetpath, 0,
+ WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
DEBUG(5, ("cacl_set failed to open %s: %s\n",
targetpath, cli_errstr(targetcli)));
errno = 0;
diff --git a/source3/torture/denytest.c b/source3/torture/denytest.c
index cbcbf320f8..1360fc2ef4 100644
--- a/source3/torture/denytest.c
+++ b/source3/torture/denytest.c
@@ -1406,9 +1406,10 @@ static void progress_bar(unsigned i, unsigned total)
bool torture_denytest1(int dummy)
{
struct cli_state *cli1;
- int fnum1, fnum2;
+ uint16_t fnum1, fnum2;
int i;
bool correct = True;
+ NTSTATUS ret1, ret2;
const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"};
if (!torture_open_connection(&cli1, 0)) {
@@ -1419,7 +1420,7 @@ bool torture_denytest1(int dummy)
for (i=0;i<2;i++) {
cli_unlink(cli1, fnames[i], aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
+ cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
cli_write(cli1, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
cli_close(cli1, fnum1);
}
@@ -1432,16 +1433,16 @@ bool torture_denytest1(int dummy)
progress_bar(i, ARRAY_SIZE(denytable1));
- fnum1 = cli_open(cli1, fname,
+ ret1 = cli_open(cli1, fname,
denytable1[i].mode1,
- denytable1[i].deny1);
- fnum2 = cli_open(cli1, fname,
+ denytable1[i].deny1, &fnum1);
+ ret2 = cli_open(cli1, fname,
denytable1[i].mode2,
- denytable1[i].deny2);
+ denytable1[i].deny2, &fnum2);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(ret1)) {
res = A_X;
- } else if (fnum2 == -1) {
+ } else if (!NT_STATUS_IS_OK(ret2)) {
res = A_0;
} else {
char x = 1;
@@ -1492,9 +1493,10 @@ bool torture_denytest1(int dummy)
bool torture_denytest2(int dummy)
{
static struct cli_state *cli1, *cli2;
- int fnum1, fnum2;
+ uint16_t fnum1, fnum2;
int i;
bool correct = True;
+ NTSTATUS ret1, ret2;
const char *fnames[2] = {"\\denytest2.dat", "\\denytest2.exe"};
if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
@@ -1505,7 +1507,7 @@ bool torture_denytest2(int dummy)
for (i=0;i<2;i++) {
cli_unlink(cli1, fnames[i], aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
+ cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
cli_write(cli1, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
cli_close(cli1, fnum1);
}
@@ -1516,16 +1518,16 @@ bool torture_denytest2(int dummy)
progress_bar(i, ARRAY_SIZE(denytable2));
- fnum1 = cli_open(cli1, fname,
+ ret1 = cli_open(cli1, fname,
denytable2[i].mode1,
- denytable2[i].deny1);
- fnum2 = cli_open(cli2, fname,
+ denytable2[i].deny1, &fnum1);
+ ret2 = cli_open(cli2, fname,
denytable2[i].mode2,
- denytable2[i].deny2);
+ denytable2[i].deny2, &fnum2);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(ret1)) {
res = A_X;
- } else if (fnum2 == -1) {
+ } else if (!NT_STATUS_IS_OK(ret2)) {
res = A_0;
} else {
char x = 1;
diff --git a/source3/torture/locktest.c b/source3/torture/locktest.c
index 67c9516fb0..30b84c073d 100644
--- a/source3/torture/locktest.c
+++ b/source3/torture/locktest.c
@@ -273,7 +273,7 @@ static struct cli_state *connect_one(char *share, int snum)
}
-static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES],
+static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES],
char *share[NSERVERS])
{
int server, conn, f;
@@ -282,9 +282,9 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NS
for (conn=0;conn<NCONNECTIONS;conn++) {
if (cli[server][conn]) {
for (f=0;f<NFILES;f++) {
- if (fnum[server][conn][f] != -1) {
+ if (fnum[server][conn][f] != (uint16_t)-1) {
cli_close(cli[server][conn], fnum[server][conn][f]);
- fnum[server][conn][f] = -1;
+ fnum[server][conn][f] = (uint16_t)-1;
}
}
cli_ulogoff(cli[server][conn]);
@@ -301,7 +301,7 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NS
static bool test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
- int fnum[NSERVERS][NCONNECTIONS][NFILES],
+ uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES],
struct record *rec)
{
unsigned conn = rec->conn;
@@ -362,13 +362,13 @@ static bool test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
/* reopen the file */
for (server=0;server<NSERVERS;server++) {
cli_close(cli[server][conn], fnum[server][conn][f]);
- fnum[server][conn][f] = -1;
+ fnum[server][conn][f] = (uint16_t)-1;
}
for (server=0;server<NSERVERS;server++) {
- fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME,
+ fnum[server][conn][f] = (uint16_t)-1;
+ if (!NT_STATUS_IS_OK(cli_open(cli[server][conn], FILENAME,
O_RDWR|O_CREAT,
- DENY_NONE);
- if (fnum[server][conn][f] == -1) {
+ DENY_NONE, &fnum[server][conn][f]))) {
printf("failed to reopen on share%d\n", server);
return False;
}
@@ -385,16 +385,16 @@ static bool test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
}
static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
- int fnum[NSERVERS][NCONNECTIONS][NFILES])
+ uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES])
{
int server, conn, f;
for (server=0;server<NSERVERS;server++)
for (conn=0;conn<NCONNECTIONS;conn++)
for (f=0;f<NFILES;f++) {
- if (fnum[server][conn][f] != -1) {
+ if (fnum[server][conn][f] != (uint16_t)-1) {
cli_close(cli[server][conn], fnum[server][conn][f]);
- fnum[server][conn][f] = -1;
+ fnum[server][conn][f] = (uint16_t)-1;
}
}
for (server=0;server<NSERVERS;server++) {
@@ -403,17 +403,18 @@ static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
}
static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
- int fnum[NSERVERS][NCONNECTIONS][NFILES])
+ uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES])
{
int server, conn, f;
for (server=0;server<NSERVERS;server++)
for (conn=0;conn<NCONNECTIONS;conn++)
for (f=0;f<NFILES;f++) {
- fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME,
+ fnum[server][conn][f] = (uint16_t)-1;
+ if (!NT_STATUS_IS_OK(cli_open(cli[server][conn], FILENAME,
O_RDWR|O_CREAT,
- DENY_NONE);
- if (fnum[server][conn][f] == -1) {
+ DENY_NONE,
+ &fnum[server][conn][f]))) {
fprintf(stderr,"Failed to open fnum[%u][%u][%u]\n",
server, conn, f);
exit(1);
@@ -423,7 +424,7 @@ static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS],
- int fnum[NSERVERS][NCONNECTIONS][NFILES],
+ uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES],
int n)
{
int i;
@@ -449,7 +450,7 @@ static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS],
static void test_locks(char *share[NSERVERS])
{
struct cli_state *cli[NSERVERS][NCONNECTIONS];
- int fnum[NSERVERS][NCONNECTIONS][NFILES];
+ uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES];
int n, i, n1, skip, r1, r2;
ZERO_STRUCT(fnum);
diff --git a/source3/torture/locktest2.c b/source3/torture/locktest2.c
index 10e2cbe772..9cb531450c 100644
--- a/source3/torture/locktest2.c
+++ b/source3/torture/locktest2.c
@@ -68,7 +68,13 @@ static int try_open(struct cli_state *c, char *nfs, int fstype, const char *fnam
switch (fstype) {
case FSTYPE_SMB:
- return cli_open(c, fname, flags, DENY_NONE);
+ {
+ uint16_t fd;
+ if (!NT_STATUS_IS_OK(cli_open(c, fname, flags, DENY_NONE, &fd))) {
+ return -1;
+ }
+ return fd;
+ }
case FSTYPE_NFS:
if (asprintf(&path, "%s%s", nfs, fname) > 0) {
diff --git a/source3/torture/mangle_test.c b/source3/torture/mangle_test.c
index e4468945c1..6ea6c5732c 100644
--- a/source3/torture/mangle_test.c
+++ b/source3/torture/mangle_test.c
@@ -29,7 +29,7 @@ static unsigned total, collisions, failures;
static bool test_one(struct cli_state *cli, const char *name)
{
- int fnum;
+ uint16_t fnum;
fstring shortname;
fstring name2;
NTSTATUS status;
@@ -37,8 +37,7 @@ static bool test_one(struct cli_state *cli, const char *name)
total++;
- fnum = cli_open(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
printf("open of %s failed (%s)\n", name, cli_errstr(cli));
return False;
}
@@ -63,8 +62,7 @@ static bool test_one(struct cli_state *cli, const char *name)
}
/* recreate by short name */
- fnum = cli_open(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
printf("open2 of %s failed (%s)\n", name2, cli_errstr(cli));
return False;
}
diff --git a/source3/torture/masktest.c b/source3/torture/masktest.c
index e80f9cd665..768323b9f7 100644
--- a/source3/torture/masktest.c
+++ b/source3/torture/masktest.c
@@ -311,7 +311,7 @@ static void get_real_name(struct cli_state *cli,
static void testpair(struct cli_state *cli, const char *mask, const char *file)
{
- int fnum;
+ uint16_t fnum;
fstring res1;
char *res2;
static int count;
@@ -322,8 +322,7 @@ static void testpair(struct cli_state *cli, const char *mask, const char *file)
fstrcpy(res1, "---");
- fnum = cli_open(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0, &fnum))) {
DEBUG(0,("Can't create %s\n", file));
return;
}
diff --git a/source3/torture/nbio.c b/source3/torture/nbio.c
index 1542a8ffb4..c5a5388f08 100644
--- a/source3/torture/nbio.c
+++ b/source3/torture/nbio.c
@@ -140,7 +140,9 @@ void nb_unlink(const char *fname)
void nb_createx(const char *fname,
unsigned create_options, unsigned create_disposition, int handle)
{
- int fd, i;
+ uint16_t fd = (uint16_t)-1;
+ int i;
+ NTSTATUS status;
uint32 desired_access;
if (create_options & FILE_DIRECTORY_FILE) {
@@ -149,22 +151,22 @@ void nb_createx(const char *fname,
desired_access = FILE_READ_DATA | FILE_WRITE_DATA;
}
- fd = cli_nt_create_full(c, fname, 0,
+ status = cli_ntcreate(c, fname, 0,
desired_access,
0x0,
FILE_SHARE_READ|FILE_SHARE_WRITE,
create_disposition,
- create_options, 0);
- if (fd == -1 && handle != -1) {
- printf("ERROR: cli_nt_create_full failed for %s - %s\n",
+ create_options, 0, &fd);
+ if (!NT_STATUS_IS_OK(status) && handle != -1) {
+ printf("ERROR: cli_ntcreate failed for %s - %s\n",
fname, cli_errstr(c));
exit(1);
}
- if (fd != -1 && handle == -1) {
- printf("ERROR: cli_nt_create_full succeeded for %s\n", fname);
+ if (NT_STATUS_IS_OK(status) && handle == -1) {
+ printf("ERROR: cli_ntcreate succeeded for %s\n", fname);
exit(1);
}
- if (fd == -1) return;
+ if (fd == (uint16_t)-1) return;
for (i=0;i<MAX_FILES;i++) {
if (ftable[i].handle == 0) break;
diff --git a/source3/torture/scanner.c b/source3/torture/scanner.c
index 3e9a24f121..e42e80abca 100644
--- a/source3/torture/scanner.c
+++ b/source3/torture/scanner.c
@@ -194,7 +194,7 @@ bool torture_trans2_scan(int dummy)
static struct cli_state *cli;
int op, level;
const char *fname = "\\scanner.dat";
- int fnum, dnum;
+ uint16_t fnum, dnum;
printf("starting trans2 scan test\n");
@@ -202,9 +202,15 @@ bool torture_trans2_scan(int dummy)
return False;
}
- fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
- DENY_NONE);
- dnum = cli_open(cli, "\\", O_RDONLY, DENY_NONE);
+ if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
+ DENY_NONE, &fnum))) {
+ printf("open of %s failed\n", fname);
+ return false;
+ }
+ if (!NT_STATUS_IS_OK(cli_open(cli, "\\", O_RDONLY, DENY_NONE, &dnum))) {
+ printf("open of \\ failed\n");
+ return false;
+ }
for (op=OP_MIN; op<=OP_MAX; op++) {
printf("Scanning op=%d\n", op);
@@ -396,7 +402,7 @@ bool torture_nttrans_scan(int dummy)
static struct cli_state *cli;
int op, level;
const char *fname = "\\scanner.dat";
- int fnum, dnum;
+ uint16_t fnum, dnum;
printf("starting nttrans scan test\n");
@@ -404,9 +410,9 @@ bool torture_nttrans_scan(int dummy)
return False;
}
- fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
- DENY_NONE);
- dnum = cli_open(cli, "\\", O_RDONLY, DENY_NONE);
+ cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
+ DENY_NONE, &fnum);
+ cli_open(cli, "\\", O_RDONLY, DENY_NONE, &dnum);
for (op=OP_MIN; op<=OP_MAX; op++) {
printf("Scanning op=%d\n", op);
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 1f9d5dbb02..e06a7629af 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -419,25 +419,26 @@ static bool rw_torture(struct cli_state *c)
{
const char *lockfname = "\\torture.lck";
fstring fname;
- int fnum;
- int fnum2;
+ uint16_t fnum;
+ uint16_t fnum2;
pid_t pid2, pid = getpid();
int i, j;
char buf[1024];
bool correct = True;
+ NTSTATUS status;
memset(buf, '\0', sizeof(buf));
- fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
- DENY_NONE);
- if (fnum2 == -1)
- fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
- if (fnum2 == -1) {
+ status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
+ DENY_NONE, &fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
+ }
+ if (!NT_STATUS_IS_OK(status)) {
printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
return False;
}
-
for (i=0;i<torture_numops;i++) {
unsigned n = (unsigned)sys_random()%10;
if (i % 10 == 0) {
@@ -449,8 +450,7 @@ static bool rw_torture(struct cli_state *c)
return False;
}
- fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL, &fnum))) {
printf("open failed (%s)\n", cli_errstr(c));
correct = False;
break;
@@ -526,7 +526,7 @@ static bool run_torture(int dummy)
static bool rw_torture3(struct cli_state *c, char *lockfname)
{
- int fnum = -1;
+ uint16_t fnum = (uint16_t)-1;
unsigned int i = 0;
char buf[131072];
char buf_rd[131072];
@@ -534,6 +534,7 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
unsigned countprev = 0;
ssize_t sent = 0;
bool correct = True;
+ NTSTATUS status;
srandom(1);
for (i = 0; i < sizeof(buf); i += sizeof(uint32))
@@ -543,9 +544,8 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
if (procnum == 0)
{
- fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
- DENY_NONE);
- if (fnum == -1) {
+ 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",
lockfname, cli_errstr(c));
return False;
@@ -555,11 +555,14 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
{
for (i = 0; i < 500 && fnum == -1; i++)
{
- fnum = cli_open(c, lockfname, O_RDONLY,
- DENY_NONE);
+ status = cli_open(c, lockfname, O_RDONLY,
+ DENY_NONE, &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ break;
+ }
smb_msleep(10);
}
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(status)) {
printf("second open read-only of %s failed (%s)\n",
lockfname, cli_errstr(c));
return False;
@@ -626,8 +629,8 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
{
const char *lockfname = "\\torture2.lck";
- int fnum1;
- int fnum2;
+ uint16_t fnum1;
+ uint16_t fnum2;
int i;
char buf[131072];
char buf_rd[131072];
@@ -638,16 +641,14 @@ static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
}
- fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
- DENY_NONE);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
+ DENY_NONE, &fnum1))) {
printf("first open read/write of %s failed (%s)\n",
lockfname, cli_errstr(c1));
return False;
}
- fnum2 = cli_open(c2, lockfname, O_RDONLY,
- DENY_NONE);
- if (fnum2 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(c2, lockfname, O_RDONLY,
+ DENY_NONE, &fnum2))) {
printf("second open read-only of %s failed (%s)\n",
lockfname, cli_errstr(c2));
cli_close(c1, fnum1);
@@ -756,7 +757,7 @@ static bool run_readwritemulti(int dummy)
static bool run_readwritelarge(int dummy)
{
static struct cli_state *cli1;
- int fnum1;
+ uint16_t fnum1;
const char *lockfname = "\\large.dat";
SMB_OFF_T fsize;
char buf[126*1024];
@@ -774,8 +775,7 @@ static bool run_readwritelarge(int dummy)
cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
@@ -806,8 +806,7 @@ static bool run_readwritelarge(int dummy)
correct = False;
}
- fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
@@ -990,7 +989,7 @@ static bool run_locktest1(int dummy)
{
struct cli_state *cli1, *cli2;
const char *fname = "\\lockt1.lck";
- int fnum1, fnum2, fnum3;
+ uint16_t fnum1, fnum2, fnum3;
time_t t1, t2;
unsigned lock_timeout;
@@ -1004,18 +1003,15 @@ static bool run_locktest1(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
- fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
- if (fnum2 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2))) {
printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
- fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
- if (fnum3 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3))) {
printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
@@ -1103,7 +1099,7 @@ static bool run_tcon_test(int dummy)
{
static struct cli_state *cli;
const char *fname = "\\tcontest.tmp";
- int fnum1;
+ uint16 fnum1;
uint16 cnum1, cnum2, cnum3;
uint16 vuid1, vuid2;
char buf[4];
@@ -1121,8 +1117,7 @@ static bool run_tcon_test(int dummy)
cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
@@ -1367,7 +1362,7 @@ static bool run_locktest2(int dummy)
{
static struct cli_state *cli;
const char *fname = "\\lockt2.lck";
- int fnum1, fnum2, fnum3;
+ uint16_t fnum1, fnum2, fnum3;
bool correct = True;
if (!torture_open_connection(&cli, 0)) {
@@ -1382,22 +1377,19 @@ static bool run_locktest2(int dummy)
cli_setpid(cli, 1);
- fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
- fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
- if (fnum2 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2))) {
printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
return False;
}
cli_setpid(cli, 2);
- fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
- if (fnum3 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3))) {
printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
return False;
}
@@ -1503,7 +1495,8 @@ static bool run_locktest3(int dummy)
{
static struct cli_state *cli1, *cli2;
const char *fname = "\\lockt3.lck";
- int fnum1, fnum2, i;
+ uint16_t fnum1, fnum2;
+ int i;
uint32 offset;
bool correct = True;
@@ -1519,13 +1512,11 @@ static bool run_locktest3(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
- fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
- if (fnum2 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
return False;
}
@@ -1628,7 +1619,7 @@ static bool run_locktest4(int dummy)
{
static struct cli_state *cli1, *cli2;
const char *fname = "\\lockt4.lck";
- int fnum1, fnum2, f;
+ uint16_t fnum1, fnum2, f;
bool ret;
char buf[1000];
bool correct = True;
@@ -1644,8 +1635,8 @@ static bool run_locktest4(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
+ 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));
@@ -1769,12 +1760,12 @@ static bool run_locktest4(int dummy)
cli_close(cli1, fnum1);
cli_close(cli2, fnum2);
- fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
- f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
+ cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
+ cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
cli_close(cli1, fnum1) &&
- ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
+ (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) &&
cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
cli_close(cli1, f);
cli_close(cli1, fnum1);
@@ -1799,7 +1790,7 @@ static bool run_locktest5(int dummy)
{
static struct cli_state *cli1, *cli2;
const char *fname = "\\lockt5.lck";
- int fnum1, fnum2, fnum3;
+ uint16_t fnum1, fnum2, fnum3;
bool ret;
char buf[1000];
bool correct = True;
@@ -1815,9 +1806,9 @@ static bool run_locktest5(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
- fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
+ cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
+ cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
+ cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
memset(buf, 0, sizeof(buf));
@@ -1831,12 +1822,12 @@ static bool run_locktest5(int dummy)
ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
cli_close(cli1, fnum1);
- fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
+ cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
EXPECTED(ret, True);
printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
cli_close(cli1, fnum1);
- fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
+ cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
cli_unlock(cli1, fnum3, 0, 1);
ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
@@ -1924,7 +1915,7 @@ static bool run_locktest6(int dummy)
static struct cli_state *cli;
const char *fname[1] = { "\\lock6.txt" };
int i;
- int fnum;
+ uint16_t fnum;
NTSTATUS status;
if (!torture_open_connection(&cli, 0)) {
@@ -1940,12 +1931,12 @@ static bool run_locktest6(int dummy)
cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
- fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+ 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("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
- fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
+ cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
cli_close(cli, fnum);
printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
@@ -1963,7 +1954,7 @@ static bool run_locktest7(int dummy)
{
struct cli_state *cli1;
const char *fname = "\\lockt7.lck";
- int fnum1;
+ uint16_t fnum1;
char buf[200];
bool correct = False;
@@ -1977,7 +1968,7 @@ static bool run_locktest7(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+ cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
memset(buf, 0, sizeof(buf));
@@ -2100,7 +2091,7 @@ static bool run_fdpasstest(int dummy)
{
struct cli_state *cli1, *cli2;
const char *fname = "\\fdpass.tst";
- int fnum1;
+ uint16_t fnum1;
char buf[1024];
if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
@@ -2113,8 +2104,7 @@ static bool run_fdpasstest(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
@@ -2153,8 +2143,8 @@ static bool run_fdsesstest(int dummy)
uint16 saved_cnum;
const char *fname = "\\fdsess.tst";
const char *fname1 = "\\fdsess1.tst";
- int fnum1;
- int fnum2;
+ uint16_t fnum1;
+ uint16_t fnum2;
char buf[1024];
bool ret = True;
@@ -2176,8 +2166,7 @@ static bool run_fdsesstest(int dummy)
cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
@@ -2196,8 +2185,7 @@ static bool run_fdsesstest(int dummy)
ret = False;
}
/* Try to open a file with different vuid, samba cnum. */
- fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum2 != -1) {
+ 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);
@@ -2237,7 +2225,7 @@ static bool run_unlinktest(int dummy)
{
struct cli_state *cli;
const char *fname = "\\unlink.tst";
- int fnum;
+ uint16_t fnum;
bool correct = True;
if (!torture_open_connection(&cli, 0)) {
@@ -2252,8 +2240,7 @@ static bool run_unlinktest(int dummy)
cli_setpid(cli, 1);
- fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum == -1) {
+ 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;
}
@@ -2287,7 +2274,8 @@ static bool run_maxfidtest(int dummy)
struct cli_state *cli;
const char *ftemplate = "\\maxfid.%d.%d";
fstring fname;
- int fnums[0x11000], i;
+ uint16_t fnums[0x11000];
+ int i;
int retries=4;
bool correct = True;
@@ -2302,9 +2290,8 @@ static bool run_maxfidtest(int dummy)
for (i=0; i<0x11000; i++) {
slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
- if ((fnums[i] = cli_open(cli, fname,
- O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
- -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, fname,
+ O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) {
printf("open of %s failed (%s)\n",
fname, cli_errstr(cli));
printf("maximum fnum is %d\n", i);
@@ -2469,7 +2456,7 @@ static bool run_browsetest(int dummy)
static bool run_attrtest(int dummy)
{
struct cli_state *cli;
- int fnum;
+ uint16_t fnum;
time_t t, t2;
const char *fname = "\\attrib123456789.tst";
bool correct = True;
@@ -2481,8 +2468,8 @@ static bool run_attrtest(int dummy)
}
cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
- fnum = cli_open(cli, fname,
- O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
+ cli_open(cli, fname,
+ O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
cli_close(cli, fnum);
if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
printf("getatr failed (%s)\n", cli_errstr(cli));
@@ -2533,7 +2520,7 @@ static bool run_attrtest(int dummy)
static bool run_trans2test(int dummy)
{
struct cli_state *cli;
- int fnum;
+ uint16_t fnum;
SMB_OFF_T size;
time_t c_time, a_time, m_time;
struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
@@ -2550,8 +2537,8 @@ static bool run_trans2test(int dummy)
}
cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
- fnum = cli_open(cli, fname,
- O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
+ 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)) {
printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
@@ -2574,9 +2561,8 @@ static bool run_trans2test(int dummy)
sleep(2);
cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
- fnum = cli_open(cli, fname,
- O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
- if (fnum == -1) {
+ 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));
return False;
}
@@ -2605,8 +2591,8 @@ static bool run_trans2test(int dummy)
cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
- fnum = cli_open(cli, fname,
- O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
+ 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)) {
@@ -2636,8 +2622,8 @@ static bool run_trans2test(int dummy)
correct = False;
}
- fnum = cli_open(cli, fname2,
- O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
+ cli_open(cli, fname2,
+ O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
cli_close(cli, fnum);
if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
@@ -2688,7 +2674,7 @@ static bool new_trans(struct cli_state *pcli, int fnum, int level)
static bool run_w2ktest(int dummy)
{
struct cli_state *cli;
- int fnum;
+ uint16_t fnum;
const char *fname = "\\w2ktest\\w2k.tst";
int level;
bool correct = True;
@@ -2699,8 +2685,8 @@ static bool run_w2ktest(int dummy)
return False;
}
- fnum = cli_open(cli, fname,
- O_RDWR | O_CREAT , DENY_NONE);
+ cli_open(cli, fname,
+ O_RDWR | O_CREAT , DENY_NONE, &fnum);
for (level = 1004; level < 1040; level++) {
new_trans(cli, fnum, level);
@@ -2725,7 +2711,7 @@ static bool run_oplock1(int dummy)
{
struct cli_state *cli1;
const char *fname = "\\lockt1.lck";
- int fnum1;
+ uint16_t fnum1;
bool correct = True;
printf("starting oplock test 1\n");
@@ -2740,8 +2726,7 @@ static bool run_oplock1(int dummy)
cli1->use_oplocks = True;
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
@@ -2774,7 +2759,7 @@ static bool run_oplock2(int dummy)
{
struct cli_state *cli1, *cli2;
const char *fname = "\\lockt2.lck";
- int fnum1, fnum2;
+ uint16_t fnum1, fnum2;
int saved_use_oplocks = use_oplocks;
char buf[4];
bool correct = True;
@@ -2811,8 +2796,7 @@ static bool run_oplock2(int dummy)
cli_sockopt(cli1, sockops);
cli_sockopt(cli2, sockops);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
@@ -2823,8 +2807,7 @@ static bool run_oplock2(int dummy)
if (fork() == 0) {
/* Child code */
- fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
- if (fnum2 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
*shared_correct = False;
exit(0);
@@ -2906,7 +2889,7 @@ static bool run_oplock2(int dummy)
}
/* handler for oplock 3 tests */
-static bool oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
+static NTSTATUS oplock3_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
{
printf("got oplock break fnum=%d level=%d\n",
fnum, level);
@@ -2917,7 +2900,7 @@ static bool run_oplock3(int dummy)
{
struct cli_state *cli;
const char *fname = "\\oplockt3.dat";
- int fnum;
+ uint16_t fnum;
char buf[4] = "abcd";
bool correct = True;
volatile bool *shared_correct;
@@ -2937,7 +2920,7 @@ static bool run_oplock3(int dummy)
}
sleep(2);
/* try to trigger a oplock break in parent */
- fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
+ cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
cli_write(cli, fnum, 0, buf, 0, 4);
exit(0);
}
@@ -2949,10 +2932,10 @@ static bool run_oplock3(int dummy)
return False;
}
cli_oplock_handler(cli, oplock3_handler);
- fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
+ cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
cli_write(cli, fnum, 0, buf, 0, 4);
cli_close(cli, fnum);
- fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
+ cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
cli->timeout = 20000;
cli_receive_smb(cli);
printf("finished oplock test 3\n");
@@ -2972,8 +2955,8 @@ static bool run_deletetest(int dummy)
struct cli_state *cli1 = NULL;
struct cli_state *cli2 = NULL;
const char *fname = "\\delete.file";
- int fnum1 = -1;
- int fnum2 = -1;
+ uint16_t fnum1 = (uint16_t)-1;
+ uint16_t fnum2 = (uint16_t)-1;
bool correct = True;
printf("starting delete test\n");
@@ -2989,11 +2972,9 @@ static bool run_deletetest(int dummy)
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
0, FILE_OVERWRITE_IF,
- FILE_DELETE_ON_CLOSE, 0);
-
- if (fnum1 == -1) {
+ FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3016,8 +2997,7 @@ static bool run_deletetest(int dummy)
goto fail;
}
- fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
- if (fnum1 != -1) {
+ if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
printf("[1] open of %s succeeded (should fail)\n", fname);
correct = False;
goto fail;
@@ -3030,11 +3010,9 @@ static bool run_deletetest(int dummy)
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
- FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3052,8 +3030,7 @@ static bool run_deletetest(int dummy)
goto fail;
}
- fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
- if (fnum1 != -1) {
+ if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
if (!cli_close(cli1, fnum1)) {
printf("[2] close failed (%s)\n", cli_errstr(cli1));
@@ -3068,10 +3045,8 @@ static bool run_deletetest(int dummy)
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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))) {
printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3080,10 +3055,8 @@ static bool run_deletetest(int dummy)
/* This should fail with a sharing violation - open for delete is only compatible
with SHARE_DELETE. */
- fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
-
- if (fnum2 != -1) {
+ if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
correct = False;
goto fail;
@@ -3091,10 +3064,8 @@ static bool run_deletetest(int dummy)
/* This should succeed. */
- fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
-
- if (fnum2 == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3120,8 +3091,7 @@ static bool run_deletetest(int dummy)
/* This should fail - file should no longer be there. */
- fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
- if (fnum1 != -1) {
+ if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
if (!cli_close(cli1, fnum1)) {
printf("[3] close failed (%s)\n", cli_errstr(cli1));
@@ -3136,19 +3106,16 @@ static bool run_deletetest(int dummy)
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(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);
-
- if (fnum1 == -1) {
+ 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))) {
printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
}
/* This should succeed. */
- fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
- FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
- if (fnum2 == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3167,10 +3134,9 @@ static bool run_deletetest(int dummy)
}
/* This should fail - no more opens once delete on close set. */
- fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
+ if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
- FILE_OPEN, 0, 0);
- if (fnum2 != -1) {
+ FILE_OPEN, 0, 0, &fnum2))) {
printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
correct = False;
goto fail;
@@ -3187,8 +3153,7 @@ static bool run_deletetest(int dummy)
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
- if (fnum1 == -1) {
+ 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));
correct = False;
goto fail;
@@ -3214,11 +3179,9 @@ static bool run_deletetest(int dummy)
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
+ 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,
- FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3244,10 +3207,8 @@ static bool run_deletetest(int dummy)
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
- FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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))) {
printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3273,8 +3234,7 @@ static bool run_deletetest(int dummy)
/* This next open should succeed - we reset the flag. */
- fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3300,21 +3260,17 @@ static bool run_deletetest(int dummy)
cli_sockopt(cli1, sockops);
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+ 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_SHARE_DELETE,
- FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
}
- fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
- FILE_OPEN, 0, 0);
-
- if (fnum2 == -1) {
+ FILE_OPEN, 0, 0, &fnum2))) {
printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
correct = False;
goto fail;
@@ -3339,8 +3295,7 @@ static bool run_deletetest(int dummy)
}
/* This should fail.. */
- fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
- if (fnum1 != -1) {
+ if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
goto fail;
correct = False;
@@ -3348,10 +3303,8 @@ static bool run_deletetest(int dummy)
printf("eighth delete on close test succeeded.\n");
/* This should fail - we need to set DELETE_ACCESS. */
- fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
- FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
-
- if (fnum1 != -1) {
+ if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
printf("[9] open of %s succeeded should have failed!\n", fname);
correct = False;
goto fail;
@@ -3359,9 +3312,8 @@ static bool run_deletetest(int dummy)
printf("ninth delete on close test succeeded.\n");
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
- FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3375,8 +3327,7 @@ static bool run_deletetest(int dummy)
}
/* This should fail.. */
- fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
- if (fnum1 != -1) {
+ if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
goto fail;
correct = False;
@@ -3390,9 +3341,8 @@ static bool run_deletetest(int dummy)
delete access ? */
/* Create a readonly file. */
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
- FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
+ FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
@@ -3405,11 +3355,9 @@ static bool run_deletetest(int dummy)
}
/* Now try open for delete access. */
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
+ if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
- FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 != -1) {
+ FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
cli_close(cli1, fnum1);
goto fail;
@@ -3503,7 +3451,7 @@ static bool run_xcopy(int dummy)
static struct cli_state *cli1;
const char *fname = "\\test.txt";
bool correct = True;
- int fnum1, fnum2;
+ uint16_t fnum1, fnum2;
printf("starting xcopy test\n");
@@ -3511,21 +3459,18 @@ static bool run_xcopy(int dummy)
return False;
}
- fnum1 = cli_nt_create_full(cli1, fname, 0,
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
FILE_SHARE_NONE, FILE_OVERWRITE_IF,
- 0x4044, 0);
-
- if (fnum1 == -1) {
+ 0x4044, 0, &fnum1))) {
printf("First open failed - %s\n", cli_errstr(cli1));
return False;
}
- fnum2 = cli_nt_create_full(cli1, fname, 0,
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
SECOND_DESIRED_ACCESS, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
- 0x200000, 0);
- if (fnum2 == -1) {
+ 0x200000, 0, &fnum2))) {
printf("second open failed - %s\n", cli_errstr(cli1));
return False;
}
@@ -3546,7 +3491,7 @@ static bool run_rename(int dummy)
const char *fname = "\\test.txt";
const char *fname1 = "\\test1.txt";
bool correct = True;
- int fnum1;
+ uint16_t fnum1;
printf("starting rename test\n");
@@ -3556,10 +3501,8 @@ static bool run_rename(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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;
}
@@ -3578,14 +3521,12 @@ static bool run_rename(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
#if 0
- FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
+ FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
#else
- FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
+ FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
#endif
-
- if (fnum1 == -1) {
printf("Second open failed - %s\n", cli_errstr(cli1));
return False;
}
@@ -3605,10 +3546,8 @@ static bool run_rename(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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))) {
printf("Third open failed - %s\n", cli_errstr(cli1));
return False;
}
@@ -3616,12 +3555,10 @@ static bool run_rename(int dummy)
#if 0
{
- int fnum2;
-
- fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
+ uint16_t fnum2;
- if (fnum2 == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
printf("Fourth open failed - %s\n", cli_errstr(cli1));
return False;
}
@@ -3654,10 +3591,8 @@ static bool run_rename(int dummy)
/*----*/
- fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("Fourth open failed - %s\n", cli_errstr(cli1));
return False;
}
@@ -3679,10 +3614,8 @@ static bool run_rename(int dummy)
/*--*/
- fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
printf("Fifth open failed - %s\n", cli_errstr(cli1));
return False;
}
@@ -3699,10 +3632,8 @@ static bool run_rename(int dummy)
* Now check if the first name still exists ...
*/
- /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum2 == -1) {
+ /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
printf("Opening original file after rename of open file fails: %s\n",
cli_errstr(cli1));
}
@@ -3733,7 +3664,7 @@ static bool run_pipe_number(int dummy)
{
struct cli_state *cli1;
const char *pipe_name = "\\SPOOLSS";
- int fnum;
+ uint16_t fnum;
int num_pipes = 0;
printf("starting pipenumber test\n");
@@ -3743,10 +3674,8 @@ static bool run_pipe_number(int dummy)
cli_sockopt(cli1, sockops);
while(1) {
- fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0, &fnum))) {
printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
break;
}
@@ -3767,7 +3696,7 @@ static bool run_opentest(int dummy)
static struct cli_state *cli1;
static struct cli_state *cli2;
const char *fname = "\\readonly.file";
- int fnum1, fnum2;
+ uint16_t fnum1, fnum2;
char buf[20];
SMB_OFF_T fsize;
bool correct = True;
@@ -3784,8 +3713,7 @@ static bool run_opentest(int dummy)
cli_sockopt(cli1, sockops);
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ 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;
}
@@ -3800,14 +3728,13 @@ static bool run_opentest(int dummy)
return False;
}
- fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
/* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
- fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
+ cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
NT_STATUS_ACCESS_DENIED)) {
@@ -3822,14 +3749,13 @@ static bool run_opentest(int dummy)
cli_setatr(cli1, fname, 0, 0);
- fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
/* This will fail - but the error should be ERRshare. */
- fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
+ cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
NT_STATUS_SHARING_VIOLATION)) {
@@ -3847,8 +3773,7 @@ static bool run_opentest(int dummy)
/* Test truncate open disposition on file opened for read. */
- fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
@@ -3880,8 +3805,7 @@ static bool run_opentest(int dummy)
/* Now test if we can truncate a file opened for readonly. */
- fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1))) {
printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
return False;
}
@@ -3933,18 +3857,14 @@ static bool run_opentest(int dummy)
printf("TEST #1 testing 2 non-io opens (no delete)\n");
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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));
return False;
}
- fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
-
- if (fnum2 == -1) {
+ 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));
return False;
}
@@ -3964,18 +3884,14 @@ static bool run_opentest(int dummy)
printf("TEST #2 testing 2 non-io opens (first with delete)\n");
- fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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));
return False;
}
- fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
-
- if (fnum2 == -1) {
+ 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));
return False;
}
@@ -3995,18 +3911,14 @@ static bool run_opentest(int dummy)
printf("TEST #3 testing 2 non-io opens (second with delete)\n");
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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));
return False;
}
- fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
-
- if (fnum2 == -1) {
+ 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));
return False;
}
@@ -4026,18 +3938,14 @@ static bool run_opentest(int dummy)
printf("TEST #4 testing 2 non-io opens (both with delete)\n");
- fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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));
return False;
}
- fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
-
- if (fnum2 != -1) {
+ 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));
return False;
}
@@ -4055,18 +3963,14 @@ static bool run_opentest(int dummy)
printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
- fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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));
return False;
}
- fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
-
- if (fnum2 == -1) {
+ 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));
return False;
}
@@ -4087,18 +3991,14 @@ static bool run_opentest(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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));
return False;
}
- fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
-
- if (fnum2 == -1) {
+ 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));
return False;
}
@@ -4119,18 +4019,14 @@ static bool run_opentest(int dummy)
cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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));
return False;
}
- fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
-
- if (fnum2 != -1) {
+ 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));
return False;
}
@@ -4329,7 +4225,7 @@ static bool run_openattrtest(int dummy)
{
static struct cli_state *cli1;
const char *fname = "\\openattr.file";
- int fnum1;
+ uint16_t fnum1;
bool correct = True;
uint16 attr;
unsigned int i, j, k, l;
@@ -4345,10 +4241,8 @@ static bool run_openattrtest(int dummy)
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);
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
+ 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));
return False;
}
@@ -4359,10 +4253,8 @@ static bool run_openattrtest(int dummy)
}
for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
- fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
- FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
-
- if (fnum1 == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
+ FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0, &fnum1))) {
for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
if (attr_results[l].num == k) {
printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
@@ -4442,7 +4334,7 @@ static bool run_dirtest(int dummy)
{
int i;
static struct cli_state *cli;
- int fnum;
+ uint16_t fnum;
double t1;
bool correct = True;
@@ -4458,8 +4350,7 @@ static bool run_dirtest(int dummy)
for (i=0;i<torture_numops;i++) {
fstring fname;
slprintf(fname, sizeof(fname), "\\%x", (int)random());
- fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
fprintf(stderr,"Failed to open %s\n", fname);
return False;
}
@@ -4515,8 +4406,8 @@ static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *st
bool torture_ioctl_test(int dummy)
{
static struct cli_state *cli;
- uint16 device, function;
- int fnum;
+ uint16_t device, function;
+ uint16_t fnum;
const char *fname = "\\ioctl.dat";
DATA_BLOB blob;
NTSTATUS status;
@@ -4529,8 +4420,7 @@ bool torture_ioctl_test(int dummy)
cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
- fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum == -1) {
+ 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;
}
@@ -4570,7 +4460,7 @@ bool torture_ioctl_test(int dummy)
bool torture_chkpath_test(int dummy)
{
static struct cli_state *cli;
- int fnum;
+ uint16_t fnum;
bool ret;
if (!torture_open_connection(&cli, 0)) {
@@ -4594,8 +4484,7 @@ bool torture_chkpath_test(int dummy)
return False;
}
- fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
printf("open1 failed (%s)\n", cli_errstr(cli));
return False;
}
@@ -4651,7 +4540,8 @@ static bool run_eatest(int dummy)
static struct cli_state *cli;
const char *fname = "\\eatest.txt";
bool correct = True;
- int fnum, i;
+ uint16_t fnum;
+ int i;
size_t num_eas;
struct ea_struct *ea_list = NULL;
TALLOC_CTX *mem_ctx = talloc_init("eatest");
@@ -4664,12 +4554,10 @@ static bool run_eatest(int dummy)
}
cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
- fnum = cli_nt_create_full(cli, fname, 0,
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
FILE_SHARE_NONE, FILE_OVERWRITE_IF,
- 0x4044, 0);
-
- if (fnum == -1) {
+ 0x4044, 0, &fnum))) {
printf("open failed - %s\n", cli_errstr(cli));
talloc_destroy(mem_ctx);
return False;
@@ -4770,7 +4658,8 @@ static bool run_dirtest1(int dummy)
{
int i;
static struct cli_state *cli;
- int fnum, num_seen;
+ uint16_t fnum;
+ int num_seen;
bool correct = True;
printf("starting directory test\n");
@@ -4790,9 +4679,8 @@ static bool run_dirtest1(int dummy)
for (i=0;i<1000;i++) {
fstring fname;
slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
- fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
- FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
fprintf(stderr,"Failed to open %s\n", fname);
return False;
}
@@ -4964,7 +4852,7 @@ static bool run_sesssetup_bench(int dummy)
{
static struct cli_state *c;
const char *fname = "\\file.dat";
- int fnum;
+ uint16_t fnum;
NTSTATUS status;
int i;
@@ -4972,11 +4860,10 @@ static bool run_sesssetup_bench(int dummy)
return false;
}
- fnum = cli_nt_create_full(
- c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
- FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
- FILE_DELETE_ON_CLOSE, 0);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(
+ c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
+ FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+ FILE_DELETE_ON_CLOSE, 0, &fnum))) {
d_printf("open %s failed: %s\n", fname, cli_errstr(c));
return false;
}
@@ -5027,7 +4914,7 @@ static bool subst_test(const char *str, const char *user, const char *domain,
static void chain1_open_completion(struct tevent_req *req)
{
- int fnum;
+ uint16_t fnum;
NTSTATUS status;
status = cli_open_recv(req, &fnum);
TALLOC_FREE(req);
@@ -5109,7 +4996,7 @@ static bool run_mangle1(int dummy)
{
struct cli_state *cli;
const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
- int fnum;
+ uint16_t fnum;
fstring alt_name;
NTSTATUS status;
time_t change_time, access_time, write_time;
@@ -5123,10 +5010,9 @@ static bool run_mangle1(int dummy)
cli_sockopt(cli, sockops);
- fnum = cli_nt_create_full(
- cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
- FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
- if (fnum == -1) {
+ if (NT_STATUS_IS_OK(cli_ntcreate(
+ cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
+ FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
d_printf("open %s failed: %s\n", fname, cli_errstr(cli));
return false;
}
@@ -5140,8 +5026,7 @@ static bool run_mangle1(int dummy)
}
d_printf("alt_name: %s\n", alt_name);
- fnum = cli_open(cli, alt_name, O_RDONLY, DENY_NONE);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) {
d_printf("cli_open(%s) failed: %s\n", alt_name,
cli_errstr(cli));
return false;
@@ -5176,7 +5061,7 @@ static size_t null_source(uint8_t *buf, size_t n, void *priv)
static bool run_windows_write(int dummy)
{
struct cli_state *cli1;
- int fnum;
+ uint16_t fnum;
int i;
bool ret = false;
const char *fname = "\\writetest.txt";
@@ -5188,8 +5073,7 @@ static bool run_windows_write(int dummy)
return False;
}
- fnum = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
printf("open failed (%s)\n", cli_errstr(cli1));
return False;
}
diff --git a/source3/torture/utable.c b/source3/torture/utable.c
index 3b7523a85a..1f75164848 100644
--- a/source3/torture/utable.c
+++ b/source3/torture/utable.c
@@ -23,7 +23,7 @@ bool torture_utable(int dummy)
{
struct cli_state *cli;
fstring fname, alt_name;
- int fnum;
+ uint16_t fnum;
smb_ucs2_t c2;
int c, len, fd;
int chars_allowed=0, alt_allowed=0;
@@ -52,9 +52,10 @@ bool torture_utable(int dummy)
p[len] = 0;
fstrcat(fname,"_a_long_extension");
- fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
- DENY_NONE);
- if (fnum == -1) continue;
+ if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
+ DENY_NONE, &fnum))) {
+ continue;
+ }
chars_allowed++;
@@ -118,7 +119,7 @@ bool torture_casetable(int dummy)
{
static struct cli_state *cli;
char *fname;
- int fnum;
+ uint16_t fnum;
int c, i;
#define MAX_EQUIVALENCE 8
smb_ucs2_t equiv[0x10000][MAX_EQUIVALENCE];
@@ -145,13 +146,11 @@ bool torture_casetable(int dummy)
printf("%04x (%c)\n", c, isprint(c)?c:'.');
fname = form_name(c);
- fnum = cli_nt_create_full(cli, fname, 0,
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
GENERIC_ALL_ACCESS,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_NONE,
- FILE_OPEN_IF, 0, 0);
-
- if (fnum == -1) {
+ FILE_OPEN_IF, 0, 0, &fnum))) {
printf("Failed to create file with char %04x\n", c);
continue;
}
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index c48eb3dfb5..8689a09e20 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -4249,7 +4249,7 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd,
int num_tokens,
struct user_token *tokens)
{
- int fnum;
+ uint16_t fnum;
SEC_DESC *share_sd = NULL;
SEC_DESC *root_sd = NULL;
struct cli_state *cli = rpc_pipe_np_smb_conn(pipe_hnd);
@@ -4284,9 +4284,8 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd,
return;
}
- fnum = cli_nt_create(cli, "\\", READ_CONTROL_ACCESS);
-
- if (fnum != -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, "\\", 0, READ_CONTROL_ACCESS, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
root_sd = cli_query_secdesc(cli, fnum, mem_ctx);
}
diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c
index baaf8e9fa3..770d3cac49 100644
--- a/source3/utils/net_rpc_printer.c
+++ b/source3/utils/net_rpc_printer.c
@@ -155,8 +155,8 @@ NTSTATUS net_copy_fileattr(struct net_context *c,
bool copy_timestamps, bool is_file)
{
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
- int fnum_src = 0;
- int fnum_dst = 0;
+ uint16_t fnum_src = 0;
+ uint16_t fnum_dst = 0;
SEC_DESC *sd = NULL;
uint16_t attr;
time_t f_atime, f_ctime, f_mtime;
@@ -170,8 +170,8 @@ NTSTATUS net_copy_fileattr(struct net_context *c,
DEBUGADD(3,("opening %s %s on originating server\n",
is_file?"file":"dir", src_name));
- fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS);
- if (fnum_src == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_src, src_name, 0, READ_CONTROL_ACCESS, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_src))) {
DEBUGADD(0,("cannot open %s %s on originating server %s\n",
is_file?"file":"dir", src_name, cli_errstr(cli_share_src)));
nt_status = cli_nt_error(cli_share_src);
@@ -210,8 +210,8 @@ NTSTATUS net_copy_fileattr(struct net_context *c,
/* open the file/dir on the destination server */
- fnum_dst = cli_nt_create(cli_share_dst, dst_name, WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS);
- if (fnum_dst == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_dst, dst_name, 0, WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_dst))) {
DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
is_file?"file":"dir", dst_name, cli_errstr(cli_share_dst)));
nt_status = cli_nt_error(cli_share_dst);
@@ -309,8 +309,8 @@ NTSTATUS net_copy_file(struct net_context *c,
bool copy_timestamps, bool is_file)
{
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
- int fnum_src = 0;
- int fnum_dst = 0;
+ uint16_t fnum_src = 0;
+ uint16_t fnum_dst = 0;
static int io_bufsize = 64512;
int read_size = io_bufsize;
char *data = NULL;
@@ -327,15 +327,15 @@ NTSTATUS net_copy_file(struct net_context *c,
DEBUGADD(3,("opening %s %s on originating server\n",
is_file ? "file":"dir", src_name));
if (is_file)
- fnum_src = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE);
+ nt_status = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE, &fnum_src);
else
- fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS);
+ nt_status = cli_ntcreate(cli_share_src, src_name, 0, READ_CONTROL_ACCESS, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_src);
- if (fnum_src == -1) {
+ if (!NT_STATUS_IS_OK(nt_status)) {
DEBUGADD(0,("cannot open %s %s on originating server %s\n",
is_file ? "file":"dir",
src_name, cli_errstr(cli_share_src)));
- nt_status = cli_nt_error(cli_share_src);
goto out;
}
@@ -344,13 +344,12 @@ NTSTATUS net_copy_file(struct net_context *c,
/* open file on the destination server */
DEBUGADD(3,("opening file %s on destination server\n", dst_name));
- fnum_dst = cli_open(cli_share_dst, dst_name,
- O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
+ nt_status = cli_open(cli_share_dst, dst_name,
+ O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum_dst);
- if (fnum_dst == -1) {
+ if (!NT_STATUS_IS_OK(nt_status)) {
DEBUGADD(1,("cannot create file %s on destination server: %s\n",
dst_name, cli_errstr(cli_share_dst)));
- nt_status = cli_nt_error(cli_share_dst);
goto out;
}
diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
index 85b7baad00..2e41afc27f 100644
--- a/source3/utils/smbcacls.c
+++ b/source3/utils/smbcacls.c
@@ -660,15 +660,14 @@ dump the acls for a file
static int cacl_dump(struct cli_state *cli, char *filename)
{
int result = EXIT_FAILED;
- int fnum = -1;
+ uint16_t fnum = (uint16_t)-1;
SEC_DESC *sd;
if (test_args)
return EXIT_OK;
- fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
goto done;
}
@@ -685,7 +684,7 @@ static int cacl_dump(struct cli_state *cli, char *filename)
result = EXIT_OK;
done:
- if (fnum != -1)
+ if (fnum != (uint16_t)-1)
cli_close(cli, fnum);
return result;
@@ -699,14 +698,13 @@ because the NT docs say this can't be done :-). JRA.
static int owner_set(struct cli_state *cli, enum chown_mode change_mode,
const char *filename, const char *new_username)
{
- int fnum;
+ uint16_t fnum;
DOM_SID sid;
SEC_DESC *sd, *old;
size_t sd_size;
- fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
return EXIT_FAILED;
}
@@ -728,9 +726,8 @@ static int owner_set(struct cli_state *cli, enum chown_mode change_mode,
(change_mode == REQUEST_CHGRP) ? &sid : NULL,
NULL, NULL, &sd_size);
- fnum = cli_nt_create(cli, filename, WRITE_OWNER_ACCESS);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, WRITE_OWNER_ACCESS, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
return EXIT_FAILED;
}
@@ -815,7 +812,7 @@ set the ACLs on a file given an ascii description
static int cacl_set(struct cli_state *cli, char *filename,
char *the_acl, enum acl_mode mode)
{
- int fnum;
+ uint16_t fnum;
SEC_DESC *sd, *old;
uint32 i, j;
size_t sd_size;
@@ -829,9 +826,8 @@ static int cacl_set(struct cli_state *cli, char *filename,
/* The desired access below is the only one I could find that works
with NT4, W2KP and Samba */
- fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, CREATE_ACCESS_READ, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli));
return EXIT_FAILED;
}
@@ -930,9 +926,8 @@ static int cacl_set(struct cli_state *cli, char *filename,
old->owner_sid, old->group_sid,
NULL, old->dacl, &sd_size);
- fnum = cli_nt_create(cli, filename, WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(cli, filename, 0, WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli));
return EXIT_FAILED;
}
diff --git a/source3/utils/smbcquotas.c b/source3/utils/smbcquotas.c
index 1425d428ec..a0eed65be3 100644
--- a/source3/utils/smbcquotas.c
+++ b/source3/utils/smbcquotas.c
@@ -230,7 +230,7 @@ static int do_quota(struct cli_state *cli,
SMB_NTQUOTA_STRUCT *pqt)
{
uint32 fs_attrs = 0;
- int quota_fnum = 0;
+ uint16_t quota_fnum = 0;
SMB_NTQUOTA_LIST *qtl = NULL;
SMB_NTQUOTA_STRUCT qt;
ZERO_STRUCT(qt);
@@ -246,7 +246,7 @@ static int do_quota(struct cli_state *cli,
return 0;
}
- if (!cli_get_quota_handle(cli, &quota_fnum)) {
+ if (!NT_STATUS_IS_OK(cli_get_quota_handle(cli, &quota_fnum))) {
d_printf("Quotas are not enabled on this share.\n");
d_printf("Failed to open %s %s.\n",
FAKE_FILE_NAME_QUOTA_WIN32,cli_errstr(cli));