Beispiel #1
0
        private ChangePasswordResponseMessage HandleChangePasswordRequest(ChangePasswordRequestMessage msg)
        {
            try
            {
                m_logger.DebugFormat("Processing ChangePasswordRequest for: {0} domain: {1}",
                    msg.Username, msg.Domain);

                ChangePasswordInfo cpInfo = new ChangePasswordInfo()
                {
                    Username = msg.Username,
                    Domain = msg.Domain,
                    OldPassword = msg.OldPassword,
                    NewPassword = msg.NewPassword
                };

                ChangePasswordPluginActivityInfo pluginInfo = new ChangePasswordPluginActivityInfo();
                pluginInfo.LoadedPlugins = PluginLoader.GetOrderedPluginsOfType<IPluginChangePassword>();
                BooleanResult finalResult = new BooleanResult { Success = false, Message = "" };

                // One success means the final result is a success, and we return the message from
                // the last success.  Otherwise, we return the message from the last failure.
                foreach ( IPluginChangePassword plug in PluginLoader.GetOrderedPluginsOfType<IPluginChangePassword>() ) 
                {
                    // Execute the plugin
                    m_logger.DebugFormat("ChangePassword: executing {0}", plug.Uuid);
                    BooleanResult pluginResult = plug.ChangePassword(cpInfo, pluginInfo);

                    // Add result to our list of plugin results
                    pluginInfo.AddResult(plug.Uuid, pluginResult);

                    m_logger.DebugFormat("ChangePassword: result from {0} is {1} message: {2}",
                        plug.Uuid, pluginResult.Success, pluginResult.Message);

                    if (pluginResult.Success)
                    {
                        finalResult.Success = true;
                        finalResult.Message = pluginResult.Message;
                    }
                    else
                    {
                        if (!finalResult.Success)
                        {
                            finalResult.Message = pluginResult.Message;
                        }
                    }
                }

                m_logger.DebugFormat("ChangePassword: returning final result {0}, message {1}",
                    finalResult.Success, finalResult.Message);

                return new ChangePasswordResponseMessage()
                {
                    Result = finalResult.Success,
                    Message = finalResult.Message,
                    Username = msg.Username,
                    Domain = msg.Domain
                };
            }
            catch (Exception e)
            {
                m_logger.ErrorFormat("Internal error, unexpected exception while handling change password request: {0}", e);
                return new ChangePasswordResponseMessage() { Result = false, Message = "Internal error" };
            }
        }
Beispiel #2
0
        public BooleanResult ChangePassword( ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo)
        {
            m_logger.Debug("ChangePassword()");

            try
            {
                LdapServer serv = new LdapServer();

                // Authenticate using old password
                BooleanResult result = serv.Authenticate(cpInfo.Username, cpInfo.OldPassword);
                if (!result.Success)
                {
                    return new BooleanResult { Success = false, Message = "Password change failed: Invalid LDAP username or password." };
                }

                // Set the new password
                serv.SetPassword(cpInfo.Username, cpInfo.NewPassword);

                return new BooleanResult { Success = true, Message = "LDAP password successfully changed" };
            }
            catch (Exception e)
            {
                m_logger.ErrorFormat("Exception in ChangePassword: {0}", e);
                return new BooleanResult() { Success = false, Message = "Error in LDAP plugin." };
            }
        }
Beispiel #3
0
        public BooleanResult ChangePassword( ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo)
        {
            m_logger.Debug("ChangePassword()");

            try
            {
                LdapServer serv = new LdapServer();

                // Authenticate using old password
                BooleanResult result = serv.Authenticate(cpInfo.Username, cpInfo.OldPassword);
                if (!result.Success)
                {
                    return new BooleanResult { Success = false, Message = "Password change failed: Invalid LDAP username or password." };
                }

                // Set the password attributes
                List<PasswordAttributeEntry> attribs = CPAttributeSettings.Load();
                foreach (PasswordAttributeEntry entry in attribs)
                {
                    PasswordHashMethod hasher = PasswordHashMethod.methods[entry.Method];

                    m_logger.DebugFormat("Setting attribute {0} using hash method {1}", entry.Name, hasher.Name);
                    serv.SetUserAttribute(cpInfo.Username, entry.Name, hasher.hash(cpInfo.NewPassword));
                }

                return new BooleanResult { Success = true, Message = "LDAP password successfully changed" };
            }
            catch (Exception e)
            {
                m_logger.ErrorFormat("Exception in ChangePassword: {0}", e);
                return new BooleanResult() { Success = false, Message = "Error in LDAP plugin." };
            }

        }
Beispiel #4
0
 public BooleanResult ChangePassword(ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo)
 {
     return new BooleanResult() { Success = true, Message = "Success from the sample plugin" };
 }
Beispiel #5
0
        public BooleanResult ChangePassword(ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo)
        {
            m_logger.Debug("ChangePassword()");

            // Verify the old password
            if (Abstractions.WindowsApi.pInvokes.ValidateCredentials(cpInfo.Username, cpInfo.OldPassword))
            {
                m_logger.DebugFormat("Authenticated via old password: {0}", cpInfo.Username);
            }
            else
            {
                return new BooleanResult { Success = false, Message = "Current password or username is not valid." };
            }

            using (UserPrincipal user = LocalAccount.GetUserPrincipal(cpInfo.Username))
            {
                if (user != null)
                {
                    m_logger.DebugFormat("Found principal, changing password for {0}", cpInfo.Username);
                    user.SetPassword(cpInfo.NewPassword);
                }
                else
                {
                    return new BooleanResult { Success = false, Message = "Local machine plugin internal error: directory entry not found." };
                }
            }

            return new BooleanResult { Success = true, Message = "Local password successfully changed." };
        }