Пример #1
0
 public void CopyShareSecurity(NTShare sourceShare, NTShare destShare)
 {
     ActionObserver.NotifyAction("Copying", "Share Security", sourceShare.FullName, destShare.FullName);
     try {
         ShareSecurity sourceSecurity = sourceShare.GetAccessControl();
         NTShare.SetAccessControl(
             destShare.FullName,
             TranslateShareACL(
                 sourceShare.GetAccessControl()
                 )
             );
     } catch (Exception error) {
         ActionObserver.NotifyActionFailed("Copying", "Share Security", sourceShare.FullName, destShare.FullName, error.Message);
     }
 }
Пример #2
0
        public void CopyShare(CopyableShare copyableShare)
        {
            #region Validation
            if (!Directory.Exists(copyableShare.DestPath))
            {
                ActionObserver.NotifyError("Cannot copy share '{0}' to '{1}' as the destination path does not exist", copyableShare.SourceShare.FullName, copyableShare.DestPath);
                return;
            }
            #endregion

            NTShare sourceShare = copyableShare.SourceShare;
            string  destPath    = copyableShare.DestPath;

            ActionObserver.NotifyAction("Copying", "Share", sourceShare.FullName, destPath);
            try {
                NTShare destShare;

                // try to load share at destination server (assumed to be localhost), by name
                if (!NTHost.CurrentMachine.TryGetShare(sourceShare.Name, out destShare))
                {
                    // one doesn't exist so create one
                    destShare = NTHost.CurrentMachine.CreateShare(
                        sourceShare.Name,
                        sourceShare.Description,
                        sourceShare.Type,
                        destPath
                        );
                }
                else
                {
                    // make sure we loaded one pointing to same directory as we expect
                    if (!Path.Equals(destShare.ServerPath, copyableShare.DestPath))
                    {
                        // in this branch, a different share of the same name already exists
                        if (AutoResolveShareNameConflicts)
                        {
                            string newName = ResolveShareNameConflict(NTHost.CurrentMachine, sourceShare.Name);
                            ActionObserver.NotifyWarning(
                                "Copying share '{0}\\{1}' as '{2}\\{3}' to avoid name conflict",
                                copyableShare.SourceShare.Host,
                                copyableShare.SourceShare.Name,
                                NTHost.CurrentMachine.Host,
                                newName
                                );

                            // we want to auto-create a share name
                            destShare = NTHost.CurrentMachine.CreateShare(
                                newName,
                                sourceShare.Description,
                                sourceShare.Type,
                                destPath
                                );
                        }
                        else
                        {
                            // in this branch, bail out of share copying as share name already taken
                            ActionObserver.NotifyError(
                                "Cannot copy the share '{0}\\{1}' to folder '{2}' as it will conflict with '{3}\\{4}' defined for folder '{5}'",
                                copyableShare.SourceShare.Host,
                                copyableShare.SourceShare.Name,
                                copyableShare.DestPath,
                                destShare.Host,
                                destShare.Name,
                                destShare.ServerPath
                                );
                        }
                        return;
                    }
                }

                // copy details
                destShare.Name        = sourceShare.Name;
                destShare.Description = sourceShare.Description;
                destShare.MaxUses     = sourceShare.MaxUses;
                destShare.Password    = sourceShare.Password;
                destShare.Permissions = sourceShare.Permissions;
                destShare.Reserved    = sourceShare.Reserved;
                destShare.ServerPath  = destPath;
                destShare.Update();

                CopyShareSecurity(sourceShare, destShare);

                // create new share
            } catch (Exception error) {
                ActionObserver.NotifyActionFailed("Copying", "Share", copyableShare.SourceShare.FullName, copyableShare.DestPath, error.Message);
            }
        }