Пример #1
0
 public ShareCopier(SidNameResolver nameResolver, SidTranslator sidTranslator, bool autoResolveShareNameConflicts, IActionObserver observer)
 {
     Resolver      = nameResolver;
     SidTranslator = sidTranslator;
     AutoResolveShareNameConflicts = autoResolveShareNameConflicts;
     ActionObserver = observer;
 }
Пример #2
0
        private Dictionary <string, string> AssembleSidTranslationTable(IEnumerable <AuthorizationRule> authorizationRules)
        {
            var danglingSids = new Dictionary <string, string>();

            foreach (var authorizationRule in authorizationRules)
            {
                // if we encounter a SID and not an account name, it means it could not be resolved
                if (authorizationRule.IdentityReference is SecurityIdentifier)
                {
                    // rule references a dangling id, try to resolve it to remote machine name
                    var    remoteSID = authorizationRule.IdentityReference.Value;
                    string remoteName;
                    string remoteHost;
                    WinAPI.ADVAPI32.SidNameUse remoteNameUse;
                    if (Resolver.TryResolve(remoteSID, out remoteHost, out remoteName, out remoteNameUse))
                    {
                        // 2.1 Translate dangling user to equivalent name on local server
                        if (!danglingSids.ContainsKey(remoteSID))
                        {
                            string translatedName;

                            // translate to a local name
                            if (!SidTranslator.TryTranslate(
                                    remoteHost,
                                    remoteName,
                                    remoteNameUse,
                                    out translatedName))
                            {
                                // couldn't translate it, or import anything, so just default to administrators
                                ActionObserver.NotifyWarning("Unable to translate/import remote {0} '{1}\\{2}'", remoteNameUse, remoteHost, remoteName);
                                translatedName = "Administrators";
                            }

                            var localAccount = new NTAccount(
                                translatedName
                                );

                            var translatedUserSid = localAccount.Translate(
                                typeof(SecurityIdentifier)
                                ).Value;

                            ActionObserver.NotifyAction("Translating", "SID", remoteSID, translatedUserSid);
                            if (!danglingSids.ContainsKey(remoteSID))
                            {
                                danglingSids.Add(remoteSID, translatedUserSid);
                            }
                        }
                    }
                    else
                    {
                        // replace this SID with administrators
                        var localAccount      = new NTAccount("Administrators");
                        var translatedUserSid = localAccount.Translate(
                            typeof(SecurityIdentifier)
                            ).Value;


                        ActionObserver.NotifyWarning("Danging SID '{0}' identified, using Administrators group sid", remoteSID);
                        if (!danglingSids.ContainsKey(remoteSID))
                        {
                            danglingSids.Add(remoteSID, translatedUserSid);
                        }
                    }
                }
            }
            return(danglingSids);
        }