r7609: Move top level dir handling in from of the loop. This makes the code
authorLars Müller <lmuelle@samba.org>
Wed, 15 Jun 2005 14:24:11 +0000 (14:24 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:57:16 +0000 (10:57 -0500)
much straither.

copy_top_level_perms() is jra's work.

I modified the copy_top_level_perms() function to use the copy_clistate.

And I don't forget trunk.

Lars
(This used to be commit 2c68568e5232c057d4f76f4bb044c54d18272602)

source3/utils/net.h
source3/utils/net_rpc.c
source3/utils/net_rpc_printer.c

index ebabf605dd3a72e7ef25216d9d3b606ead8845f0..c67786cf9e3e052f7f95a16eb4610117eafd3063 100644 (file)
@@ -31,7 +31,6 @@ typedef struct copy_clistate {
        struct cli_state *cli_share_src;
        struct cli_state *cli_share_dst;
        char *cwd;
-       BOOL top_level_dir;
        uint16 attribute;
        int mode;
 }copy_clistate; 
index 9d1eece9f7faf460b12a8ea5793081f500b7da60..614f19c803db522ddbae64ff915e0281b801a74f 100644 (file)
@@ -2798,13 +2798,7 @@ static void copy_fn(const char *mnt, file_info *f, const char *mask, void *state
        local_state = (struct copy_clistate *)state;
        nt_status = NT_STATUS_UNSUCCESSFUL;
 
-       if (strequal(f->name, ".")) {
-               if (local_state->top_level_dir)
-                       f->name[0] = '\0';
-               else
-                       return;
-       }
-       if (strequal(f->name, ".."))
+       if (strequal(f->name, ".") || strequal(f->name, ".."))
                return;
 
        DEBUG(3,("got mask: %s, name: %s\n", mask, f->name));
@@ -2832,7 +2826,7 @@ static void copy_fn(const char *mnt, file_info *f, const char *mask, void *state
                                                  False);
                        break;
                default:
-                       DEBUG(0,( "Unsupported mode %d", local_state->mode));
+                       d_printf("Unsupported mode %d\n", local_state->mode);
                        return;
                }
 
@@ -2840,19 +2834,16 @@ static void copy_fn(const char *mnt, file_info *f, const char *mask, void *state
                        printf("could not handle dir %s: %s\n", 
                                dir, nt_errstr(nt_status));
 
-               if (!local_state->top_level_dir) {
-                       /* search below that directory */
-                       fstrcpy(new_mask, dir);
-                       fstrcat(new_mask, "\\*");
-
-                       old_dir = local_state->cwd;
-                        local_state->cwd = dir;
-                       if (!sync_files(local_state, new_mask))
-                               printf("could not handle files\n");
-                       local_state->cwd = old_dir;
-               } else
-                       local_state->top_level_dir = False;
-                       
+               /* search below that directory */
+               fstrcpy(new_mask, dir);
+               fstrcat(new_mask, "\\*");
+
+               old_dir = local_state->cwd;
+               local_state->cwd = dir;
+               if (!sync_files(local_state, new_mask))
+                       printf("could not handle files\n");
+               local_state->cwd = old_dir;
+
                return;
        }
 
@@ -2877,7 +2868,7 @@ static void copy_fn(const char *mnt, file_info *f, const char *mask, void *state
                                          True);
                break;
        default:
-               DEBUG(0,( "Unsupported file mode %d", local_state->mode));
+               d_printf("Unsupported file mode %d\n", local_state->mode);
                return;
        }
 
@@ -2911,6 +2902,43 @@ BOOL sync_files(struct copy_clistate *cp_clistate, pstring mask)
 }
 
 
+/**
+ * Set the top level directory permissions before we do any further copies.
+ * Should set up ACL inheritance.
+ **/
+
+BOOL copy_top_level_perms(struct copy_clistate *cp_clistate, 
+                               const char *sharename)
+{
+       NTSTATUS nt_status;
+
+       switch (cp_clistate->mode) {
+       case NET_MODE_SHARE_MIGRATE:
+               DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename));
+               nt_status = net_copy_fileattr(cp_clistate->mem_ctx,
+                                               cp_clistate->cli_share_src, 
+                                               cp_clistate->cli_share_dst,
+                                               "\\", "\\",
+                                               opt_acls? True : False, 
+                                               opt_attrs? True : False,
+                                               opt_timestamps? True: False,
+                                               False);
+               break;
+       default:
+               d_printf("Unsupported mode %d\n", cp_clistate->mode);
+               break;
+       }
+
+       if (!NT_STATUS_IS_OK(nt_status))  {
+               printf("Could handle directory attributes for top level directory of share %s. Error %s\n", 
+                       sharename, nt_errstr(nt_status));
+               return False;
+       }
+
+       return True;
+}
+
+
 /** 
  * Sync all files inside a remote share to another share (over smb)
  *
@@ -3005,7 +3033,7 @@ rpc_share_migrate_files_internals(const DOM_SID *domain_sid, const char *domain_
                        printf("syncing");
                        break;
                default:
-                       DEBUG(0,("Unsupported mode %d", cp_clistate.mode));
+                       d_printf("Unsupported mode %d\n", cp_clistate.mode);
                        break;
                }
                printf("    [%s] files and directories %s ACLs, %s DOS Attributes %s\n", 
@@ -3018,7 +3046,6 @@ rpc_share_migrate_files_internals(const DOM_SID *domain_sid, const char *domain_
                cp_clistate.cli_share_src = NULL;
                cp_clistate.cli_share_dst = NULL;
                cp_clistate.cwd = NULL;
-               cp_clistate.top_level_dir = True;
                cp_clistate.attribute = aSYSTEM | aHIDDEN | aDIR;
 
                /* open share source */
@@ -3040,6 +3067,11 @@ rpc_share_migrate_files_internals(const DOM_SID *domain_sid, const char *domain_
                        got_dst_share = True;
                }
 
+               if (!copy_top_level_perms(&cp_clistate, netname)) {
+                       d_printf("Could not handle the top level directory permissions for the share: %s\n", netname);
+                       nt_status = NT_STATUS_UNSUCCESSFUL;
+                       goto done;
+               }
 
                /* now call the filesync */
                pstrcpy(mask, "\\*");
index 840688be9a2c78d5914819598e99477538f1ed1a..f1f82a5ceadddf34d06926b60f5333e118dd5f34 100644 (file)
@@ -292,8 +292,7 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value)
  *
  * @return Normal NTSTATUS return.
  **/ 
-static NTSTATUS 
-net_copy_fileattr(TALLOC_CTX *mem_ctx,
+NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx,
                  struct cli_state *cli_share_src,
                  struct cli_state *cli_share_dst, 
                  const char *src_name, const char *dst_name,