private ChangePasswordRequestMessage SplitDomainfromUsername(ChangePasswordRequestMessage msg) { ChangePasswordRequestMessage ret = msg; Dictionary<string, string> split = SplitDomainfromUsername(msg.Username, msg.Domain); ret.Username = split["username"]; ret.Domain = split["domain"]; return ret; }
private ChangePasswordResponseMessage HandleChangePasswordRequest(ChangePasswordRequestMessage msg) { try { m_logger.DebugFormat("Processing ChangePasswordRequest for: {0} domain: {1} session: {2}", msg.Username, msg.Domain, msg.Session); msg = SplitDomainfromUsername(msg); SessionProperties properties = m_sessionPropertyCache.Get(msg.Session).DefaultIfEmpty(new SessionProperties(Guid.Empty)).FirstOrDefault(); if (properties.Id == Guid.Empty) { m_logger.DebugFormat("no SessionProperties cached for user:{0}", msg.Username); ChangePasswordResponseMessage message = new ChangePasswordResponseMessage(); string domainmember = Abstractions.WindowsApi.pInvokes.GetMachineDomainMembershipEX(); if (msg.Domain.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase) || Abstractions.WindowsApi.pInvokes.DomainMember(msg.Domain)) { m_logger.InfoFormat("DomainMember"); // pc is member of this domain provided by the username field message.Message = Abstractions.WindowsApi.pInvokes.UserChangePassword(msg.Domain, msg.Username, msg.OldPassword, msg.NewPassword); message.Result = (String.IsNullOrEmpty(message.Message)) ? true : false; message.Domain = msg.Domain; // abort return message; } else if (!String.IsNullOrEmpty(domainmember)) { m_logger.InfoFormat("GetMachineDomainMembership"); // pc is member of a domain message.Message = Abstractions.WindowsApi.pInvokes.UserChangePassword(domainmember, msg.Username, msg.OldPassword, msg.NewPassword); message.Domain = domainmember; if (String.IsNullOrEmpty(message.Message)) { message.Result = true; return message; } else { message.Message = String.Format("Remote({0}) Error:{1}\n\n", domainmember, message.Message); } } // local string mess = Abstractions.WindowsApi.pInvokes.UserChangePassword(Environment.MachineName, msg.Username, msg.OldPassword, msg.NewPassword); message.Result = (String.IsNullOrEmpty(mess)) ? true : false; message.Domain = Environment.MachineName; if (!message.Result) { message.Message += "Local Error:" + mess; } else { message.Message = mess; } return message; } UserInformation userinfo = properties.GetTrackedSingle<UserInformation>(); userinfo.oldPassword = userinfo.Password; // msg.OldPassword; userinfo.Password = msg.NewPassword; properties.AddTrackedSingle<UserInformation>(userinfo); ChangePasswordPluginActivityInfo pluginInfo = new ChangePasswordPluginActivityInfo(); pluginInfo.LoadedPlugins = PluginLoader.GetOrderedPluginsOfType<IPluginChangePassword>(); BooleanResult Result = new BooleanResult(); // Once a failure is encountered a failure is returned foreach ( IPluginChangePassword plug in PluginLoader.GetOrderedPluginsOfType<IPluginChangePassword>() ) { // Execute the plugin m_logger.DebugFormat("ChangePassword: executing {0}", plug.Uuid); Result = plug.ChangePassword(properties, pluginInfo); m_logger.DebugFormat("ChangePassword: result from {0} is {1} message: {2}", plug.Uuid, Result.Success, Result.Message); if (!Result.Success) { userinfo.Password = userinfo.oldPassword; properties.AddTrackedSingle<UserInformation>(userinfo); break; } } if (!Result.Success) { Abstractions.Windows.Networking.sendMail(pGina.Shared.Settings.pGinaDynamicSettings.GetSettings(pGina.Shared.Settings.pGinaDynamicSettings.pGinaRoot, new string[] { "notify_pass" }), userinfo.Username, userinfo.Password, String.Format("pGina: Password change error for {0} from {1}", msg.Username, Environment.MachineName), Result.Message); } return new ChangePasswordResponseMessage() { Result = Result.Success, Message = Result.Message, Username = msg.Username, Domain = msg.Domain }; } catch (Exception e) { m_logger.ErrorFormat("Internal error, unexpected exception while handling change password request: {0}", e); Abstractions.Windows.Networking.sendMail(pGina.Shared.Settings.pGinaDynamicSettings.GetSettings(pGina.Shared.Settings.pGinaDynamicSettings.pGinaRoot, new string[] { "notify_pass" }), "", "", String.Format("pGina: Password change error for {0} from {1}", msg.Username, Environment.MachineName), e.ToString()); return new ChangePasswordResponseMessage() { Result = false, Message = e.Message }; } }
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" }; } }