diff options
Diffstat (limited to 'source3/utils/net_rpc_printer.c')
-rw-r--r-- | source3/utils/net_rpc_printer.c | 103 |
1 files changed, 72 insertions, 31 deletions
diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index e4197d72ce..7684878677 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -283,6 +283,8 @@ static void display_reg_value(pstring subkey, REGISTRY_VALUE value) * @param src_file The source file-name * @param dst_file The destination file-name * @param copy_acls Whether to copy acls + * @param copy_attrs Whether to copy DOS attributes + * @param copy_timestamps Whether to preserve timestamps * @param is_file Whether this file is a file or a dir * * @return Normal NTSTATUS return. @@ -291,7 +293,8 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, char *src_name, char *dst_name, - BOOL copy_acls, BOOL is_file) + BOOL copy_acls, BOOL copy_attrs, + BOOL copy_timestamps, BOOL is_file) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; int fnum_src = 0; @@ -302,6 +305,8 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, off_t start = 0; off_t nread = 0; SEC_DESC *sd = NULL; + uint16 attr; + time_t atime, ctime, mtime; /* open on the originating server */ @@ -349,7 +354,20 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* get the security descriptor */ sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx); if (!sd) { - DEBUG(0, ("failed to get security descriptor\n")); + DEBUG(0, ("failed to get security descriptor: %s\n", + cli_errstr(cli_share_src))); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + } + + if (copy_attrs || copy_timestamps) { + + /* get dos attributes */ + if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL, + &ctime, &atime, &mtime)) { + DEBUG(0, ("failed to get file-attrs: %s\n", + cli_errstr(cli_share_src))); nt_status = cli_nt_error(cli_share_src); goto out; } @@ -358,10 +376,13 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* copying file */ if (opt_verbose) { - d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] %s acls.\n", - cli_share_src->desthost, cli_share_src->share, src_name, + d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] " + "%s acls and %s DOS Attributes %s\n", + cli_share_src->desthost, cli_share_src->share, src_name, cli_share_dst->desthost, cli_share_dst->share, dst_name, - copy_acls ? "with" : "without" ); + copy_acls ? "with" : "without", + copy_attrs ? "with" : "without", + copy_timestamps ? "(preserving timestamps)" : "" ); if (DEBUGLEVEL >= 3 && copy_acls) display_sec_desc(sd); @@ -392,7 +413,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* creating dir */ if (!is_file && !cli_chkpath(cli_share_dst, dst_name)) { - DEBUGADD(1,("creating dir %s on the destination server\n", + DEBUGADD(3,("creating dir %s on the destination server\n", dst_name)); if (!cli_mkdir(cli_share_dst, dst_name)) { @@ -408,47 +429,67 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, } } - - /* closing files */ - if (!cli_close(cli_share_src, fnum_src)) { - d_printf("could not close file on originating server: %s\n", - cli_errstr(cli_share_src)); - nt_status = cli_nt_error(cli_share_src); - goto out; - } - - if (is_file && !cli_close(cli_share_dst, fnum_dst)) { - d_printf("could not close file on destinantion server: %s\n", - cli_errstr(cli_share_dst)); + /* open the file/dir a second time */ + fnum_dst = cli_nt_create(cli_share_dst, dst_name, + WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS); + + if (fnum_dst == -1) { + DEBUG(0,("failed to open file/dir again: %s: %s\n", + dst_name, cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); goto out; } + /* set timestamps */ + if (copy_timestamps) { + + if (!cli_setattrE(cli_share_dst, fnum_dst, ctime, atime, mtime)) { + DEBUG(0,("failed to set file-attrs (timestamps): %s\n", + cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + } - /* finally set acls */ + /* set acls */ if (copy_acls) { - /* Open the file/dir a second time */ - fnum_dst = cli_nt_create(cli_share_dst, dst_name, - WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS); - - if (fnum_dst == -1) { - DEBUG(0, ("failed to open file/dir again: %s: %s\n", - dst_name, cli_errstr(cli_share_dst))); + if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) { + DEBUG(0,("could not set secdesc on %s %s: %s\n", + is_file? "file":"dir", dst_name, + cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); goto out; } + } - if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) { - DEBUG(0, ("could not set secdesc on %s %s: %s\n", - is_file? "file":"dir", dst_name, + /* set attrs */ + if (copy_attrs) { + + if (!cli_setatr(cli_share_dst, dst_name, attr, 0)) { + DEBUG(0,("failed to set file-attrs: %s\n", cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); goto out; } } - + /* closing files */ + if (!cli_close(cli_share_src, fnum_src)) { + d_printf("could not close file on originating server: %s\n", + cli_errstr(cli_share_src)); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + + if (is_file && !cli_close(cli_share_dst, fnum_dst)) { + d_printf("could not close file on destination server: %s\n", + cli_errstr(cli_share_dst)); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + + nt_status = NT_STATUS_OK; out: @@ -520,7 +561,7 @@ static NTSTATUS net_copy_driverfile(TALLOC_CTX *mem_ctx, /* finally copy the file */ nt_status = net_copy_file(mem_ctx, cli_share_src, cli_share_dst, - src_name, dst_name, False, True); + src_name, dst_name, False, False, False, True); if (!NT_STATUS_IS_OK(nt_status)) goto out; |