Beispiel #1
0
        public void UpdateCurrentPassword(IComputer computer, string password, DateTime rotationInstant, DateTime expiryDate, int maximumPasswordHistory, MsMcsAdmPwdBehaviour msLapsBehaviour)
        {
            DirectoryEntry de = computer.DirectoryEntry;

            ProtectedPasswordHistoryItem oldPassword = GetCurrentPassword(de);

            if (oldPassword != null)
            {
                oldPassword.Retired = rotationInstant;
            }

            List <ProtectedPasswordHistoryItem> items = this.GetPasswordHistory(de);

            if (oldPassword != null)
            {
                items.Insert(0, oldPassword);
            }

            items = this.PruneHistoryItems(items, maximumPasswordHistory);

            ProtectedPasswordHistoryItem newPassword = new ProtectedPasswordHistoryItem()
            {
                Created       = rotationInstant,
                EncryptedData = this.encryptionProvider.Encrypt(this.certificateProvider.FindEncryptionCertificate(), password)
            };

            de.Properties[AttrLithnetAdminPasswordHistory].Clear();
            if (items.Count > 0)
            {
                de.Properties[AttrLithnetAdminPasswordHistory]
                .AddRange(items.Select(JsonConvert.SerializeObject).ToArray <object>());
            }

            de.Properties[AttrLithnetAdminPasswordExpiry].Value = expiryDate.ToFileTimeUtc().ToString();
            de.Properties[AttrLithnetAdminPassword].Value       = JsonConvert.SerializeObject(newPassword);

            if (msLapsBehaviour == MsMcsAdmPwdBehaviour.Populate)
            {
                de.Properties[AttrMsMcsAdmPwd].Value = password;
                de.Properties[AttrMsMcsAdmPwdExpirationTime].Value = expiryDate.ToFileTimeUtc().ToString();
            }
            else if (msLapsBehaviour == MsMcsAdmPwdBehaviour.Clear)
            {
                de.Properties[AttrMsMcsAdmPwd].Clear();
                de.Properties[AttrMsMcsAdmPwdExpirationTime].Clear();
            }

            de.CommitChanges();
        }
        public void UpdateCurrentPassword(IComputer computer, string encryptedPassword, DateTime rotationInstant, DateTime expiryDate, int maximumPasswordHistory)
        {
            DirectoryEntry de = computer.DirectoryEntry;

            ProtectedPasswordHistoryItem oldPassword = GetCurrentPassword(de);

            if (oldPassword != null)
            {
                oldPassword.Retired = rotationInstant;
            }

            List <ProtectedPasswordHistoryItem> items = this.GetPasswordHistory(de);

            if (oldPassword != null)
            {
                items.Insert(0, oldPassword);
            }

            items = this.PruneHistoryItems(items, maximumPasswordHistory);

            ProtectedPasswordHistoryItem newPassword = new ProtectedPasswordHistoryItem()
            {
                Created       = rotationInstant,
                EncryptedData = encryptedPassword,
            };

            de.Properties["lithnetAdminPasswordHistory"].Clear();
            if (items.Count > 0)
            {
                de.Properties["lithnetAdminPasswordHistory"]
                .AddRange(items.Select(JsonConvert.SerializeObject).ToArray <object>());
            }

            de.Properties["lithnetAdminPasswordExpiry"].Value = expiryDate.ToFileTimeUtc().ToString();
            de.Properties["lithnetAdminPassword"].Value       = JsonConvert.SerializeObject(newPassword);
            de.CommitChanges();
        }