internal void GenerateIisPasswordIfEmpty(RhspManager manager) { if (IisSite.IdentityPassword == null) { GenerateIisPassword(manager); } }
public TManager CreateManager <TManager>() where TManager : RhspManager { RhspServiceContext context = new RhspServiceContext(); context.ConfigDirectory = configDirectory; return(RhspManager.CreateManager <TManager>(context)); }
public string GetPasswordMd5Hash(RhspManager manager) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] textBuffer = Encoding.ASCII.GetBytes(manager.DecryptPassword(Password)); byte[] hashBuffer = md5.ComputeHash(textBuffer); string hashText = BitConverter.ToString(hashBuffer); return(hashText.Replace("-", String.Empty).ToLower()); }
private MethodInfo getModuleMethod( RhspManager manager, string methodName, RhspParameterCollection rhspParams) { var nameQuery = from m in manager.GetType().GetMethods() where m.Name == methodName select m; if (nameQuery.Count() == 0) { throw new RhspException( "No methods exist with the name '" + methodName + "'."); } var paramCountQuery = from m in nameQuery where m.GetParameters().Length == rhspParams.Count select m; if (paramCountQuery.Count() == 0) { throw new RhspException( "None of the methods named '" + methodName + "' have " + "the same number of prameters as specified in the command."); } var paramNameQuery = from m in paramCountQuery where methodHasParamNames(m, rhspParams) select m; if (paramNameQuery.Count() == 0) { throw new RhspException( "The method with name '" + methodName + "' has the " + "correct number of parameters, but at least one of " + "either the parameter names or types do not match."); } var moduleMethodQuery = from m in paramNameQuery where hasModuleMethodAttribute(m) select m; if (moduleMethodQuery.Count() == 0) { throw new RhspException( "The method with name '" + methodName + "' has the correct number " + "of parameters and the correct parameter types, but does not implement " + "the attribute " + typeof(RhspModuleMethodAttribute).FullName + "."); } return(moduleMethodQuery.Single()); }
public WindowsUser GetIisIdentity(RhspManager manager) { if (IisSite.IdentityUserName == null) { throw new Exception("The IIS identity user name has not been set."); } WindowsUser windowsUser = new WindowsUser( IisSite.IdentityUserName, manager.DecryptPassword(IisSite.IdentityPassword), "IIS Identity (" + PrimaryHost.Name + ")", "User for the IIS site " + PrimaryHost.Name + " and it's application pool.", WindowsUserFlag.PasswordCannotChange | WindowsUserFlag.PasswordNeverExpires, new WindowsUserGroup("IIS_IUSRS")); if (!string.IsNullOrEmpty(IisSite.IdentitySid)) { windowsUser.Sid = new SecurityIdentifier(IisSite.IdentitySid); } return(windowsUser); }
public RhspServiceContext() { this.ConfigDirectory = AppDomain.CurrentDomain.BaseDirectory; this.ServerConfig = RhspManager.CreateManager <ServerConfigManager>(this); this.HostingConfig = RhspManager.CreateManager <HostingConfigManager>(this); }
private RhspCommandResponse getCommandResponse(RhspCommandCarrier carrier) { RhspCommandResponse response = new RhspCommandResponse(); string[] ctParts = carrier.Command.CommandText.Split('.'); if (ctParts.Length != 2) { throw new RhspException( "Unable to process command because it is not in " + "the correct format (ModuleName.MethodName)."); } string moduleName = ctParts[0]; string methodName = ctParts[1]; if (!moduleManagerTable.ContainsKey(moduleName)) { throw new RhspException( "Unable to process command because the module " + "name '" + moduleName + "' was not recognised."); } Type managerType = moduleManagerTable[moduleName]; RhspManager manager; if (managerType == typeof(HostingConfigManager)) { // Ensure that only one hosting config is used. manager = service.Context.HostingConfig; } else if (managerType == typeof(ServerConfigManager)) { // Ensure that only one server config is used. manager = service.Context.ServerConfig; } else { manager = RhspManager.CreateManager( service.Context, managerType); } MethodInfo methodInfo = getModuleMethod( manager, methodName, carrier.Command.Parameters); ParameterInfo[] systemParamArray = methodInfo.GetParameters(); object[] methodValueArray = new object[systemParamArray.Length]; foreach (ParameterInfo systemParam in systemParamArray) { RhspParameter rhspParam = carrier.Command.Parameters[systemParam.Name]; if (!systemParam.ParameterType.IsAssignableFrom(rhspParam.Value.GetType())) { throw new RhspException( "The data type '" + systemParam.ParameterType.Name + "' " + "of system parameter with name '" + systemParam.Name + "' " + "is not compatible with the equivilent command parameter " + "of type '" + rhspParam.Value.GetType().Name + "'."); } // Assign the value to the correct position so it matches the signature. methodValueArray[systemParam.Position] = rhspParam.Value; } // Call method using manager so that apropriate events are fired. response.SetData(manager.InvokeMethod(methodInfo, methodValueArray)); // Save both configs regardless of if changes have been made. // TODO: Only save if changes actually have been made. service.Context.HostingConfig.Save(); service.Context.ServerConfig.Save(); return(response); }
public void GenerateIisPassword(RhspManager manager) { IisSite.IdentityPassword = manager.EncryptPassword(RsRandom.GenerateString(14)); }