From 8cf78ff55312768d0b454b1d7e0560e04e6296da Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 30 Apr 2009 15:26:43 -0700 Subject: 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. --- source3/utils/net_rpc.c | 7 +++---- source3/utils/net_rpc_printer.c | 31 +++++++++++++++---------------- source3/utils/smbcacls.c | 33 ++++++++++++++------------------- source3/utils/smbcquotas.c | 4 ++-- 4 files changed, 34 insertions(+), 41 deletions(-) (limited to 'source3/utils') 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, "a_fnum)) { + if (!NT_STATUS_IS_OK(cli_get_quota_handle(cli, "a_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)); -- cgit