Ejemplo n.º 1
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."
                });
            }
        }
Ejemplo n.º 2
0
 public BooleanResult ChangePassword(ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo)
 {
     return(new BooleanResult()
     {
         Success = true, Message = "Success from the sample plugin"
     });
 }
Ejemplo n.º 3
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."
            });
        }
Ejemplo n.º 4
0
 public BooleanResult ChangePassword(SessionProperties properties, ChangePasswordPluginActivityInfo pluginInfo)
 {
     return(new BooleanResult()
     {
         Success = true, Message = "Success from the sample plugin"
     });
 }
Ejemplo n.º 5
0
        public BooleanResult ChangePassword(SessionProperties properties, ChangePasswordPluginActivityInfo pluginInfo)
        {
            UserInformation userInfo = properties.GetTrackedSingle <UserInformation>();
            Dictionary <string, Dictionary <bool, string> > settings = GetSettings(userInfo);
            Dictionary <bool, string> changepwd_sys = new Dictionary <bool, string>();

            try { changepwd_sys = settings["changepwd_sys"]; }
            catch { }
            Dictionary <bool, string> changepwd_usr = new Dictionary <bool, string>();

            try { changepwd_usr = settings["changepwd_usr"]; }
            catch { }

            foreach (KeyValuePair <bool, string> line in changepwd_sys)
            {
                if (!Run(userInfo.SessionID, line.Value, userInfo, line.Key, true))
                {
                    return new BooleanResult {
                               Success = false, Message = String.Format("failed to run:{0}", line.Value)
                    }
                }
                ;
            }
            foreach (KeyValuePair <bool, string> line in changepwd_usr)
            {
                if (!Run(userInfo.SessionID, line.Value, userInfo, line.Key, false))
                {
                    return new BooleanResult {
                               Success = false, Message = String.Format("failed to run:{0}", line.Value)
                    }
                }
                ;
            }

            // the change password plugin chain will end as soon as one plugin failed
            // no special treatment needed
            return(new BooleanResult {
                Success = true
            });
        }
    }
}
Ejemplo n.º 6
0
        public BooleanResult ChangePassword(SessionProperties properties, ChangePasswordPluginActivityInfo pluginInfo)
        {
            UserInformation userInfo = properties.GetTrackedSingle <UserInformation>();

            m_logger.DebugFormat("ChangePassword(): {0}", userInfo.ToString());

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

            return(CognitoAccessor.getPwChangeResponse(userInfo.Username, userInfo.Password, userInfo.oldPassword));
        }
Ejemplo n.º 7
0
        public BooleanResult ChangePassword(SessionProperties properties, ChangePasswordPluginActivityInfo pluginInfo)
        {
            UserInformation userInfo = properties.GetTrackedSingle <UserInformation>();
            Dictionary <string, List <notify> > settings = GetSettings(userInfo);
            List <notify> changepwd_sys = new List <notify>();

            try { changepwd_sys = settings["changepwd_sys"]; }
            catch { }
            List <notify> changepwd_usr = new List <notify>();

            try { changepwd_usr = settings["changepwd_usr"]; }
            catch { }

            foreach (notify line in changepwd_sys)
            {
                if (!Run(userInfo.SessionID, line.script, userInfo, line.pwd, true, GetAuthenticationPluginResults(properties), GetAuthorizationResults(properties), GetGatewayResults(properties)))
                {
                    return new BooleanResult {
                               Success = false, Message = String.Format("failed to run:{0}", line.script)
                    }
                }
                ;
            }
            foreach (notify line in changepwd_usr)
            {
                if (!Run(userInfo.SessionID, line.script, userInfo, line.pwd, false, GetAuthenticationPluginResults(properties), GetAuthorizationResults(properties), GetGatewayResults(properties)))
                {
                    return new BooleanResult {
                               Success = false, Message = String.Format("failed to run:{0}", line.script)
                    }
                }
                ;
            }

            // the change password plugin chain will end as soon as one plugin failed
            // no special treatment needed
            return(new BooleanResult {
                Success = true
            });
        }
Ejemplo n.º 8
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."
                });
            }
        }
Ejemplo n.º 9
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"
                });
            }
        }
Ejemplo n.º 10
0
        public BooleanResult ChangePassword(SessionProperties properties, ChangePasswordPluginActivityInfo pluginInfo)
        {
            ////m_logger.Debug("ChangePassword()");

            UserInformation userInfo = properties.GetTrackedSingle <UserInformation>();

            using (LdapServer serv = new LdapServer())
            {
                try
                {
                    string[] hosts = Settings.Store.LdapHost;

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

                    // Set the password attributes
                    List <AttributeEntry> attribs = CPAttributeSettings.Load();
                    foreach (AttributeEntry entry in attribs)
                    {
                        if (entry.Method.HasFlag(Methods.ADPWD))
                        {
                            foreach (string server in hosts)
                            {
                                if (Abstractions.WindowsApi.pInvokes.UserChangePassword(server, userInfo.Username, userInfo.oldPassword, userInfo.Password) == "")
                                {
                                    break;
                                }
                            }
                            continue;
                        }

                        if (entry.Method.HasFlag(Methods.Timestamps) || entry.Method.HasFlag(Methods.Timestampd) || entry.Method.HasFlag(Methods.Timestampt))
                        {
                            TimeMethod time = TimeMethod.methods[entry.Method];

                            ////m_logger.DebugFormat("Setting attribute {0} using method {1}", entry.Name, time.Name);
                            if (!serv.SetUserAttribute(userInfo.Username, entry.Name, time.time()))
                            {
                                return new BooleanResult {
                                           Success = false, Message = "LDAPplugin failed by setting an attribute\nFor more details please consult the log!"
                                }
                            }
                            ;
                        }
                        else
                        {
                            AttribMethod hasher = AttribMethod.methods[entry.Method];

                            ////m_logger.DebugFormat("Setting attribute {0} using method {1}", entry.Name, hasher.Name);
                            if (!serv.SetUserAttribute(userInfo.Username, entry.Name, hasher.hash(userInfo.Password)))
                            {
                                return new BooleanResult {
                                           Success = false, Message = "LDAPplugin failed by setting an attribute\nFor more details please consult the log!"
                                }
                            }
                            ;
                        }
                    }
                    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."
                    });
                }
            }
        }