private Dictionary <string, string> GetSettings(string username, UserInformation userInfo) { Dictionary <string, string> settings = new Dictionary <string, string>(); Abstractions.WindowsApi.pInvokes.structenums.OSVERSIONINFOW verinfo = Abstractions.WindowsApi.pInvokes.VersionsInfo(); if (verinfo.dwMajorVersion == 0) { m_logger.WarnFormat("GetSettings: VersionsInfo() failed. I'm unable to detect OS beyond Windows 8.0"); verinfo.dwBuildNumber = Environment.OSVersion.Version.Build; verinfo.dwMajorVersion = Environment.OSVersion.Version.Major; verinfo.dwMinorVersion = Environment.OSVersion.Version.Minor; verinfo.dwPlatformId = Environment.OSVersion.Version.Build; } Dictionary <string, string> global_settings = pGina.Shared.Settings.pGinaDynamicSettings.GetSettings(pGina.Shared.Settings.pGinaDynamicSettings.pGinaRoot, new string[] { "" }); string[,] array = new string[, ] { { "TempComp", Settings.Store.TempComp.ToString() }, { "Filename", (!String.IsNullOrEmpty(userInfo.pgSMB_Filename)) ? userInfo.pgSMB_Filename : Settings.Store.Filename.ToString() }, { "SMBshare", (!String.IsNullOrEmpty(userInfo.pgSMB_SMBshare)) ? userInfo.pgSMB_SMBshare : Settings.Store.SMBshare.ToString() }, { "RoamingSource", (!String.IsNullOrEmpty(userInfo.usri4_profile)) ? userInfo.usri4_profile : Settings.Store.RoamingSource.ToString() }, { "ConnectRetry", Settings.Store.ConnectRetry.ToString() }, { "Compressor", Settings.Store.Compressor.ToString() }, { "UncompressCLI", Settings.Store.UncompressCLI.ToString() }, { "CompressCLI", Settings.Store.CompressCLI.ToString() }, { "MaxStore", (userInfo.usri4_max_storage > 0) ? userInfo.usri4_max_storage.ToString() : Settings.Store.MaxStore.ToString() }, { "ntp", (global_settings.ContainsKey("ntpservers")? global_settings["ntpservers"].Replace('\0', ' ') : "") }, /*maybe emty*/ { "MaxStoreExclude", Settings.StoreGlobal.MaxStoreExclude.ToString() }, { "HomeDir", (!String.IsNullOrEmpty(userInfo.usri4_home_dir)) ? userInfo.usri4_home_dir : Settings.Store.HomeDir.ToString() }, { "HomeDirDrive", (!String.IsNullOrEmpty(userInfo.usri4_home_dir_drive)) ? userInfo.usri4_home_dir_drive : Settings.Store.HomeDirDrive.ToString() }, { "ScriptPath", (!String.IsNullOrEmpty(userInfo.LoginScript)) ? userInfo.LoginScript : Settings.Store.ScriptPath.ToString() }, }; for (uint x = 0; x <= array.GetUpperBound(0); x++) { array[x, 1] = Environment.ExpandEnvironmentVariables(array[x, 1]).Replace("%u", username); if (x > 2) { // mask the filename in the string to prevent a replacement array[x, 1] = array[x, 1].Replace(array[2, 1], "??????????"); // replace the roaming folder (NT6 adds .V2) array[x, 1] = array[x, 1].Replace(array[0, 1], array[1, 1]); // unmask the filename array[x, 1] = array[x, 1].Replace("??????????", array[2, 1]); } if (x < 11) // first 11 fields shouldnt be empty { if (String.IsNullOrEmpty(array[x, 1])) { settings.Add("ERROR", array[x, 0]); } } settings.Add(array[x, 0], array[x, 1]); } List <string> keys = new List <string>(settings.Keys); for (uint y = 1; y <= 4; y++) { foreach (string key in keys) { settings[key] = settings[key].Replace("%f", settings["Filename"]); settings[key] = settings[key].Replace("%s", settings["SMBshare"]); settings[key] = settings[key].Replace("%r", settings["RoamingSource"]); settings[key] = settings[key].Replace("%d", settings["TempComp"]); } } foreach (KeyValuePair <string, string> pair in settings) { m_logger.DebugFormat("GetSettings:\"{0}\" \"{1}\"", pair.Key, pair.Value); } return(settings); }
public void SyncToLocalUser() { m_logger.Debug("SyncToLocalUser()"); using (UserPrincipal user = CreateOrGetUserPrincipal(UserInfo)) { // Force password and fullname match (redundant if we just created, but oh well) SyncUserPrincipalInfo(UserInfo); try { List <SecurityIdentifier> ignoredSids = new List <SecurityIdentifier>(new SecurityIdentifier[] { new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), // "Authenticated Users" new SecurityIdentifier("S-1-1-0"), // "Everyone" }); // First remove from any local groups they aren't supposed to be in m_logger.Debug("Checking for groups to remove."); List <GroupPrincipal> localGroups = LocalAccount.GetGroups(user); foreach (GroupPrincipal group in localGroups) { m_logger.DebugFormat("Remove {0}?", group.Name); // Skip ignored sids if (!ignoredSids.Contains(group.Sid)) { GroupInformation gi = new GroupInformation() { Name = group.Name, SID = group.Sid, Description = group.Description }; if (!UserInfo.InGroup(gi)) { m_logger.DebugFormat("Removing user {0} from group {1}", user.Name, group.Name); RemoveUserFromGroup(user, group); } } group.Dispose(); } // Now add to any they aren't already in that they should be m_logger.Debug("Checking for groups to add"); foreach (GroupInformation groupInfo in UserInfo.Groups) { m_logger.DebugFormat("Add {0}?", groupInfo.Name); if (!IsUserInGroup(user, groupInfo)) { using (GroupPrincipal group = CreateOrGetGroupPrincipal(groupInfo)) { m_logger.DebugFormat("Adding user {0} to group {1}", user.Name, group.Name); AddUserToGroup(user, group); } } } } catch (Exception e) { throw new GroupSyncException(e); } } //set ntuser.dat permissions if (!String.IsNullOrEmpty(UserInfo.usri4_profile) && !UserInfo.Description.Contains("pgSMB")) { Abstractions.WindowsApi.pInvokes.structenums.OSVERSIONINFOW verinfo = Abstractions.WindowsApi.pInvokes.VersionsInfo(); if (verinfo.dwMajorVersion == 0) { m_logger.WarnFormat("SyncToLocalUser: VersionsInfo() failed. I'm unable to detect OS beyond Windows 8.0"); verinfo.dwBuildNumber = Environment.OSVersion.Version.Build; verinfo.dwMajorVersion = Environment.OSVersion.Version.Major; verinfo.dwMinorVersion = Environment.OSVersion.Version.Minor; verinfo.dwPlatformId = Environment.OSVersion.Version.Build; } string ProfileExtension = (Environment.OSVersion.Version.Major == 6) ? (verinfo.dwMinorVersion > 3) /*greater than 8.1*/ ? ".V5" : ".V2" : ""; if (Connect2share(UserInfo.usri4_profile + ProfileExtension, UserInfo.Username, UserInfo.Password, 3, false)) { if (File.Exists(UserInfo.usri4_profile + ProfileExtension + "\\NTUSER.DAT")) { SetACL(UserInfo, ProfileExtension); Connect2share(UserInfo.usri4_profile + ProfileExtension, null, null, 0, true); } else { Connect2share(UserInfo.usri4_profile + ProfileExtension, null, null, 0, true); } } } m_logger.Debug("End SyncToLocalUser()"); }