summaryrefslogtreecommitdiff
path: root/source3/utils/net_rpc_printer.c
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2004-08-20 20:13:05 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:52:25 -0500
commit19e949a91ba342ec1de2c01e5bfddf8392cb68b5 (patch)
treeb404cbcc6af35cb4ef16b594d8c1d141144fd6a1 /source3/utils/net_rpc_printer.c
parent3eb42d3b6e64c817396ee4391e0dcaacc5db0029 (diff)
downloadsamba-19e949a91ba342ec1de2c01e5bfddf8392cb68b5.tar.gz
samba-19e949a91ba342ec1de2c01e5bfddf8392cb68b5.tar.bz2
samba-19e949a91ba342ec1de2c01e5bfddf8392cb68b5.zip
r1966: further work on and cleanup of the net-migration-tool.
It's now possible to migrate files preserving dos-attributes and correct timestamps. Also added some small docu- and syntax-fixes. Guenther (This used to be commit 0e990582a0416933a8671ca660d22e980f828402)
Diffstat (limited to 'source3/utils/net_rpc_printer.c')
-rw-r--r--source3/utils/net_rpc_printer.c103
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;