Пример #1
0
 public string ResolveShareNameConflict(NTHost host, string existingName)
 {
     while (host.ContainsShare(existingName))
     {
         existingName += " Copy";
     }
     return(existingName);
 }
Пример #2
0
 public static bool CanConnectTo(string hostname)
 {
     try {
         var host = new NTHost(hostname);
     } catch {
         return(false);
     }
     return(true);
 }
Пример #3
0
        public bool TryTranslate(
            string remoteHost,
            string remoteName,
            WinAPI.ADVAPI32.SidNameUse remoteNameUse,
            out string translatedAccountName
            )
        {
            ActionObserver.NotifyAction("Translating", remoteNameUse.ToString(), remoteName, string.Empty);

            bool retval = false;

            translatedAccountName = string.Empty;
            string key = string.Format("{0}\\{1}", remoteHost, remoteName);

            if (_translations.ContainsKey(key))
            {
                translatedAccountName = _translations[key];
                retval = true;
            }
            else
            {
                // attempt to resolve with local user/group of same name
                if (AccountExistsLocally(remoteName))
                {
                    _translations[key]    = remoteName;
                    translatedAccountName = _translations[key];
                    retval = true;
                    ActionObserver.NotifyInformation("Translated remote account '{0}\\{1}' to already existing local account '{2}'", remoteHost, remoteName, translatedAccountName);
                }
                else if (_importObject)
                {
                    #region Import remote object
                    NTHost        host = new NTHost(remoteHost);
                    NTLocalObject obj;
                    if (host.TryGetLocalObject(remoteName, out obj))
                    {
                        if (obj is NTLocalUser)
                        {
                            NTLocalUser remoteUser = (NTLocalUser)obj;
                            UserCopier  userCopier = new UserCopier(
                                true,
                                false,
                                _defaultPassword,
                                false,
                                ActionObserver
                                );
                            NTLocalUser localUser =
                                userCopier.CopyRemoteUserToLocalMachine(remoteUser);
                            translatedAccountName = localUser.Name;

                            ActionObserver.NotifyInformation("Copied and translated remote user '{0}\\{1}' to local group '{2}'", remoteHost, remoteName, translatedAccountName);
                        }
                        else if (obj is NTLocalGroup)
                        {
                            NTLocalGroup remoteGroup = (NTLocalGroup)obj;
                            GroupCopier  groupCopier = new GroupCopier(
                                true,
                                false,
                                true,
                                _defaultPassword,
                                false,
                                ActionObserver
                                );

                            NTLocalGroup localGroup =
                                groupCopier.CopyRemoteGroupToLocalMachine(remoteGroup);
                            translatedAccountName = remoteGroup.Name;

                            ActionObserver.NotifyInformation("Copied and translated remote group '{0}\\{1}' to local group '{2}'", remoteHost, remoteName, translatedAccountName);
                        }
                    }

                    #endregion

                    _translations[key] = translatedAccountName;
                    retval             = true;
                }
            }

            if (!retval)
            {
                ActionObserver.NotifyWarning("Failed to translate '{0}\\{1}' into a local object.", remoteHost, remoteName);
            }
            return(retval);
        }