Beispiel #1
0
        public void CopyUserMembership(NTLocalUser sourceRemoteUser, NTLocalUser destLocalUser)
        {
            ActionObserver.NotifyAction("Copying", "User Membership", sourceRemoteUser.FullName, destLocalUser.FullName);
            TextBank    existingMembers = new TextBank(destLocalUser.GetMembership());
            GroupCopier groupCopier     = new GroupCopier(false, false, true, DefaultUserPassword, false, ActionObserver);

            foreach (NTLocalGroup remoteGroup in sourceRemoteUser.GetMembership())
            {
                if (!existingMembers.ContainsText(remoteGroup.Name))
                {
                    NTLocalGroup localGroup = null;

                    // find a user by the same name of local machine
                    if (!NTHost.CurrentMachine.TryGetLocalGroup(remoteGroup.Name, out localGroup))
                    {
                        if (_importLocalGroups)
                        {
                            groupCopier.CopyRemoteGroupToLocalMachine(remoteGroup);
                        }
                    }

                    if (localGroup != null)
                    {
                        if (!existingMembers.ContainsText(localGroup.Name))
                        {
                            destLocalUser.AddMembership(localGroup);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void CopyRemoteGroupMembership(NTLocalGroup sourceRemoteGroup, NTLocalGroup destinationLocalGroup, NTObject[] destinationLocalGroupMembers)
        {
            ActionObserver.NotifyAction("Copy", "Remote Group Membership", sourceRemoteGroup.FullName, destinationLocalGroup.FullName);
            TextBank existingMembers = new TextBank(
                from obj in destinationLocalGroupMembers
                where obj is NTObject
                select(object) obj
                );


            #region debug region
            NTRemoteObject[] tmpObjects = sourceRemoteGroup.GetRemoteMembers();
            if (tmpObjects == null)
            {
                tmpObjects = new NTRemoteObject[0];
            }
            ActionObserver.NotifyInformation("Detected a total of {0} members for remote local group {1}", tmpObjects.Length, sourceRemoteGroup.FullName);
            foreach (NTRemoteObject remoteObject in tmpObjects)
            {
                ActionObserver.NotifyInformation("Member '{0}' its type is {1}", remoteObject.FullName, remoteObject.GetType().FullName);
            }

            #endregion


            NTRemoteObject[] remoteObjects = sourceRemoteGroup.GetRemoteMembers();
            if (remoteObjects == null)
            {
                remoteObjects = new NTRemoteObject[0];
            }
            ActionObserver.NotifyInformation("Detected a total of {0} AD members for remote local group {1}", remoteObjects.Length, sourceRemoteGroup.FullName);
            foreach (NTRemoteObject remoteObject in remoteObjects)
            {
                ActionObserver.NotifyInformation("AD Member '{0}' its is {1}", remoteObject.FullName, remoteObject.GetType().FullName);
            }



            foreach (NTRemoteObject remoteObject in remoteObjects)
            {
                string remoteObjectName = remoteObject.Domain + "\\" + remoteObject.Name;
                if (!existingMembers.ContainsText(remoteObjectName))
                {
                    destinationLocalGroup.AddMember(remoteObjectName);
                }
            }
        }
Beispiel #3
0
        public void CopyLocalGroupMembership(NTLocalGroup sourceRemoteGroup, NTLocalGroup destinationLocalGroup, NTObject[] destinationLocalGroupMembers)
        {
            ActionObserver.NotifyAction("Copy", "Local Group Membership", sourceRemoteGroup.FullName, destinationLocalGroup.FullName);
            TextBank existingMembers = new TextBank(
                from obj in destinationLocalGroupMembers
                where obj is NTLocalObject
                select(object) obj
                );

            UserCopier userCopier = new UserCopier(
                false,
                false,
                DefaultUserPassword,
                false,
                ActionObserver
                );

            foreach (NTLocalUser remoteUser in sourceRemoteGroup.GetLocalMembers())
            {
                NTLocalUser localUser = null;

                // find a user by the same name of local machine
                if (!NTHost.CurrentMachine.TryGetLocalUser(remoteUser.Name, out localUser))
                {
                    // import the user if required
                    if (_importLocalUsers)
                    {
                        localUser = userCopier.CopyRemoteUserToLocalMachine(remoteUser);
                    }
                }

                if (localUser != null)
                {
                    if (!existingMembers.ContainsText(localUser.Name))
                    {
                        destinationLocalGroup.AddLocalMember(localUser);
                    }
                }
            }
        }