[Test] public void TestGroups() { List <LocalUsersAndGroups.Group> groups = LocalUsersAndGroups.Groups(); // Find administrators bool found = false; foreach (LocalUsersAndGroups.Group g in groups) { if (g.SID == "S-1-5-32-544") { found = true; break; } } Assert.IsTrue(found, "Administrators group not found"); }
[Test] public void TestUsers() { List <LocalUsersAndGroups.User> users = LocalUsersAndGroups.Users(); // Find administrator bool found = false; foreach (LocalUsersAndGroups.User u in users) { if (Regex.IsMatch(u.SID, "^S-1-5-.*-500$")) { found = true; break; } } Assert.IsTrue(found, "Administrator user not found"); }
public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver); try { if (SkipDatabaseInstallation) { EventLog.WriteEntry(_syslogWebName, "Installation of database skipped - manual configuration will be required", EventLogEntryType.Warning); return; } DatabaseInstaller dbInsSys = GetSystemInstaller(); DatabaseInstaller dbInsUser = GetUserInstaller(); // Check that the system login can access the database try { dbInsSys.TestMasterConnection(); } catch (Exception ex) { throw new Exception(String.Format( "Unable to connect to the database server as user {0}: {1}", dbInsUser.UserName, ex.Message)); } // If user login given, check that too if (!dbInsUser.TrustedConnection) { try { dbInsUser.TestMasterConnection(); } catch (Exception ex) { throw new Exception(String.Format( "Unable to connect to the database server as user {0}: {1}", dbInsUser.UserName, ex.Message)); } } // Check that the database already exists if (!dbInsSys.DatabaseExists) { throw new InstallException( String.Format("The database {0} does not exists on the server {1}", dbInsSys.Database, dbInsSys.Server)); } // If we are installing this application // - on the same computer as SQL Server / MSDE // - using IWA // Then add the ASP.NET service account to the database if (dbInsUser.TrustedConnection && dbInsUser.LocalServer) { try { // Determine which account to use string accountDBName = String.Empty; string accountNTName = String.Empty; // Search for IIS user List <LocalUsersAndGroups.User> au = LocalUsersAndGroups.Users(); foreach (LocalUsersAndGroups.User u in au) { if (u.Name.ToUpper() == _aspNet) { accountDBName = u.Name; accountNTName = u.Caption; break; } } if (accountDBName.Length == 0) { // Assume network service accountDBName = "NETWORK SERVICE"; accountNTName = @"NT AUTHORITY\NETWORK SERVICE"; } // Add account to database if needed Dictionary <string, string> rep = new Dictionary <string, string>(); rep["%NTUSER%"] = accountNTName; rep["%NEWDBUSER%"] = accountDBName; dbInsSys.ExecuteGenericSQL(Assembly.GetExecutingAssembly(), "Aonaware.SyslogWeb.database.createuser.sql", rep); // Add some info to the event log EventLog.WriteEntry(_syslogWebName, String.Format( "Automatically added account {0} to database", accountNTName), EventLogEntryType.Information); } catch (Exception ex) { EventLog.WriteEntry(_syslogWebName, String.Format("Unable to create ASP.NET account on database server: {0}", ex.Message), EventLogEntryType.Warning); } } // If we are using SQL Server authentication, give access to database if (!dbInsUser.TrustedConnection) { Dictionary <string, string> rep = new Dictionary <string, string>(); rep["%SVCUSER%"] = dbInsUser.UserName; dbInsSys.ExecuteGenericSQL(Assembly.GetExecutingAssembly(), "Aonaware.SyslogWeb.database.users.sql", rep); } // Finally modify the config file string targetDir = TargetDirectory; string configFile = Path.Combine(targetDir, "Web.config"); dbInsUser.ModifyConfigFile(configFile, "Aonaware.SyslogWeb.Properties.Settings.DbConnection"); } catch (InstallException inst) { throw inst; } catch (Exception ex) { EventLog.WriteEntry(_syslogWebName, ex.Message, EventLogEntryType.Error); throw new InstallException(ex.Message); } }