/// <summary> /// Method to change a user's password /// </summary> /// <param name="Username" mandatory="true">Username to set the password on.</param> /// <param name="OldPassword" mandatory="true">Old password.</param> /// <param name="NewPassword" mandatory="true">New password.</param> /// <returns>int status for different status results</returns> static public int ChangePassword(string UserID, string OldPassword, string NewPassword) { int status = 2; //2 is for Failed to reset password. Store store = null; Simias.Storage.Domain domain = null; Member member = null; Property DNprop = null; string MemberDN = null; if (User.provider != null && OldPassword != null && NewPassword != null) { store = Store.GetStore(); domain = store.GetDomain(store.DefaultDomain); member = domain.GetMemberByID(UserID); if (member != null) { DNprop = member.Properties.GetSingleProperty("DN"); if (DNprop != null && DNprop.Value != null) { MemberDN = (string)DNprop.Value as string; if (Simias.Service.Manager.LdapServiceEnabled == false) { status = User.provider.ResetPassword(MemberDN, OldPassword, NewPassword); } else { Simias.Server.IUserProvider userProvider = null; Simias.Configuration config = Store.Config; string assemblyName = String.Empty; assemblyName = config.Get("Identity", "Assembly"); string userClass = config.Get("Identity", "Class"); if (assemblyName != null && userClass != null) { Assembly idAssembly = Assembly.LoadWithPartialName(assemblyName); if (idAssembly != null) { Type type = idAssembly.GetType(userClass); if (type != null) { userProvider = Activator.CreateInstance(type) as IUserProvider; if (userProvider != null) { status = userProvider.ResetPassword(MemberDN, OldPassword, NewPassword); } } } } } } } } return(status); }
/// <summary> /// commit the encrypted password as part of member object /// </summary> /// <returns>true if setting is successful</returns> private bool SetAdminPassword() { bool status = false; // Bootstrap the domain from the Simias.config file Simias.Configuration config = Store.Config; string adminName = config.Get("EnterpriseDomain", "AdminName"); string adminPassword = config.Get("EnterpriseDomain", "AdminPassword"); if (adminName != null && adminName != "" && adminPassword != null) { try { Member member = domain.GetMemberByName(adminName); if (member != null) { Property pwd = member.Properties.GetSingleProperty(InternalUser.pwdProperty); if (pwd == null || pwd.Value == null) { pwd = new Property(InternalUser.pwdProperty, HashPassword(adminPassword)); member.Properties.ModifyProperty(pwd); // Marker so we know this member was created internally // and not through an external identity sync. domain.SetType(member as Node, InternalUser.memberMarker); domain.Commit(member); status = true; } } } catch (Exception ap) { log.Error(ap.Message); log.Error(ap.StackTrace); } } return(status); }
public void CheckStoreAndLoadRA() { SimiasAccessLogger accessLog = new SimiasAccessLogger("Service", "Loading RA's"); Store store = Store.GetStore(); //Load the RSA for the domain - need to see how this can be migrated --FIXME if (store.DefaultDomain != null) { //Store the DEFAULT certificate(RSA information) for users using the "Server Default" option in client // need to find a better way of representing DEFAULT Simias.Security.RSAStore.CheckAndStoreRSA(store.DefaultRSARA.ToXmlString(true), "DEFAULT", true); } X509Certificate raCert = null; try { Simias.Configuration config = Store.Config; string raPath = config.Get("Server", "RAPath"); if (raPath != null && raPath != String.Empty && raPath != "") { string[] racertFiles = Directory.GetFiles(raPath, "*.?er"); Simias.Security.CertificateStore.CleanCertsFromStore(); foreach (string file in racertFiles) { try { raCert = X509Certificate.CreateFromCertFile(file); } catch (CryptographicException ce) { log.Debug("Exception {0}, File: {1}", ce.ToString(), file); continue; } //Simias.Security.CertificateStore.StoreRACertificate (raCert.GetRawCertData(), raCert.GetName().ToLower(), true); Simias.Security.CertificateStore.StoreRACertificate(raCert.GetRawCertData(), Path.GetFileNameWithoutExtension(file).ToLower(), true); accessLog.LogAccess("CheckStoreAndLoadRA", "Loading RecoveryAgent", "-", raCert.GetName()); } } } catch (Exception e) { log.Error(e.ToString()); accessLog.LogAccess("CheckStoreAndLoadRA", "Failed Loading RecoveryAgent", "-", "-"); } Simias.Security.CertificateStore.LoadRACertsFromStore(); //this loads all Certs including RA - but client will not have RA if (store.DefaultDomain != null) //load the RSA data from store - only on server { Simias.Security.RSAStore.LoadRSAFromStore(); } }
/// <summary> /// Get the specified configuration setting. /// </summary> /// <param name="key">The setting to retrieve.</param> /// <param name="defaultValue">The default setting.</param> /// <returns>The stored setting.</returns> public string Get(string key, string defaultValue) { string setting; lock (this) { if (!settingTable.Contains(key)) { setting = conf.Get(CFG_Section, key); if (setting == null) { setting = defaultValue; } settingTable[key] = setting; } } return((string)settingTable[key]); }
/// <summary> /// Reads Simnias.config file to get which directory server is being used and loads that /// </summary> /// <returns>true if Loading of IdentitySuncProvider succeeds</returns> private bool LoadIdentityProvider() { bool status = false; // Bootstrap the identity provider from the Simias.config file Simias.Configuration config = Store.Config; string assemblyName = config.Get("Identity", "ServiceAssembly"); string userClass = config.Get("Identity", "Class"); if (assemblyName != null && userClass != null) { log.Debug("Identity assembly: {0} class: {1}", assemblyName, userClass); Assembly idAssembly = Assembly.LoadWithPartialName(assemblyName); if (idAssembly != null) { Type type = idAssembly.GetType(userClass); if (type != null) { userProvider = Activator.CreateInstance(type) as IUserProvider; if (userProvider != null) { log.Debug("created user provider instance"); User.RegisterProvider(userProvider); status = true; // does this provider support external syncing? foreach (Type ctype in idAssembly.GetTypes()) { foreach (Type itype in ctype.GetInterfaces()) { if (Simias.IdentitySynchronization.Service.master && itype == typeof(Simias.IIdentitySyncProvider)) { syncProvider = Activator.CreateInstance(ctype) as IIdentitySyncProvider; if (syncProvider != null) { Simias.IdentitySynchronization.Service.Register(syncProvider); log.Debug("created sync provider instance"); } else { log.Debug("failed to create an instance of IIdentitySyncProvider"); } break; } } if (syncProvider != null) { break; } } } else { log.Debug("userProvider is null"); } } else { log.Debug("Assembly type is null"); } } else { log.Debug("Unable to load Assembly"); } } // If we couldn't load the configured provider // load the internal user/identity provider if (status == false) { if (userProvider == null) { log.Info("Could not load the configured user provider - loading InternalUser"); userProvider = new Simias.Identity.InternalUser(); User.RegisterProvider(userProvider); status = true; } } return(status); }
/// <summary> /// Method to get the Simias Enterprise server domain /// If the the domain does not exist and the create flag is true /// the domain will be created. If create == false, ownerName is ignored /// </summary> internal Simias.Storage.Domain GetServerDomain(bool Create) { // Check if the Server domain exists in the store Simias.Storage.Domain enterpriseDomain = null; bool master = true; try { Collection collection = store.GetSingleCollectionByType("Enterprise"); if (collection != null) { enterpriseDomain = store.GetDomain(collection.ID); if (enterpriseDomain != null) { this.domainName = enterpriseDomain.Name; this.id = enterpriseDomain.ID; // For backwards compatibility, if the report collection does not // exist because the store was created with a previous version of // simias, check and create it here. // Don't create this directory on a slave server. //TODO : Check with migration !! Report.CreateReportCollection(store, enterpriseDomain); } } if (enterpriseDomain == null && Create == true) { // Bootstrap the domain from the Simias.config file Simias.Configuration config = Store.Config; string cfgValue = config.Get("EnterpriseDomain", "SystemName"); if (cfgValue != null && cfgValue != String.Empty) { this.domainName = cfgValue; } cfgValue = config.Get("EnterpriseDomain", "Description"); if (cfgValue != null && cfgValue != String.Empty) { this.description = cfgValue; } cfgValue = config.Get("EnterpriseDomain", "AdminName"); if (cfgValue != null && cfgValue != String.Empty) { this.admin = cfgValue; } cfgValue = config.Get("Server", "MasterAddress"); if (cfgValue != null && cfgValue != String.Empty) { master = false; } /* * cfgValue = config.Get( "EnterpriseDomain", "AdminPassword" ); * if ( cfgValue != null && cfgValue != "" ) * { * this.adminPassword = cfgValue; * } */ if (master == true) { cfgValue = config.Get("EnterpriseDomain", "DomainID"); if (cfgValue != null && cfgValue != String.Empty) { this.id = cfgValue; } else { this.id = Guid.NewGuid().ToString(); } // Create the enterprise server domain. enterpriseDomain = new Simias.Storage.Domain( store, this.domainName, this.id, this.description, Simias.Sync.SyncRoles.Master, Simias.Storage.Domain.ConfigurationType.ClientServer); // This needs to be added to allow the enterprise location provider // to be able to resolve this domain. enterpriseDomain.SetType(enterpriseDomain, "Enterprise"); // Create the owner member for the domain. string provider = null; cfgValue = config.Get("Identity", "Assembly"); if (cfgValue != null && cfgValue != String.Empty) { provider = cfgValue; } this.admin = ParseUserName(this.admin, provider); Member member = new Member(this.admin, Guid.NewGuid().ToString(), Access.Rights.Admin); member.IsOwner = true; enterpriseDomain.SetType(member as Node, "User"); // Marker so we know this member was created internally // and not through an external identity sync. enterpriseDomain.SetType(member as Node, "Internal"); enterpriseDomain.Commit(new Node[] { enterpriseDomain, member }); // Set the domain default store.DefaultDomain = enterpriseDomain.ID; // Create the name mapping. store.AddDomainIdentity(enterpriseDomain.ID, member.UserID); } else { // Slave host so create the proxy domain and owner. enterpriseDomain = Simias.Host.SlaveSetup.GetDomain(Store.StorePath); store.DefaultDomain = enterpriseDomain.ID; enterpriseDomain.Role = Simias.Sync.SyncRoles.Slave; Member owner = Simias.Host.SlaveSetup.GetOwner(Store.StorePath); enterpriseDomain.SetType(enterpriseDomain, "Enterprise"); enterpriseDomain.Proxy = true; owner.Proxy = true; enterpriseDomain.Commit(new Node[] { enterpriseDomain, owner }); } Report.CreateReportCollection(store, enterpriseDomain); } } catch (Exception gssd) { log.Error(gssd.Message); log.Error(gssd.StackTrace); } return(enterpriseDomain); }
/// <summary> /// Static constructor for the object. /// </summary> static Report() { // Initialize the resources. resourceManager = new ResourceManager("Simias.Server.Report", Assembly.GetExecutingAssembly()); // Initalize the name of the report collection. Store store = Store.GetStore(); //get the language try { string locale = getLocaleString(); if (locale != null) { // we will atleast have POSIX log.Debug("Current Culture in environment {0}", locale); if (locale.Equals("POSIX") == false) { string lang = locale.Substring(0, 5); lang = lang.Replace('_', '-'); cli = new CultureInfo(lang, true); log.Debug("Current Culture in environment {0}, {1}", locale, lang); } } } catch (Exception ex) { log.Error("Error while trying to create language culture. {0}", ex.Message); } //search to see if its already exists; as domain name is modifiable Collection report = store.GetSingleCollectionByType("Reports"); if (report != null) { reportCollectionName = report.Name; } else { Domain domain = store.GetDomain(store.DefaultDomain); //Note : During First instance, Domain has just been created. So take serverName from the configuration files. Simias.Configuration config = Store.Config; string serverName = config.Get("Server", "Name"); reportCollectionName = domain.Name + "-" + serverName + "-" + GetString("REPORTS"); //construct path } // columns columns[( int )ColumnID.ReportTime] = new ReportColumn(GetString("REPORT_TIME"), "{0:G}"); columns[( int )ColumnID.iFolderSystem] = new ReportColumn(GetString("IFOLDER_SYSTEM")); columns[( int )ColumnID.iFolderServer] = new ReportColumn(GetString("IFOLDER_SERVER")); columns[( int )ColumnID.iFolderID] = new ReportColumn(GetString("IFOLDER_ID")); columns[( int )ColumnID.iFolderName] = new ReportColumn(GetString("IFOLDER_NAME")); columns[( int )ColumnID.iFolderSize] = new ReportColumn(GetString("IFOLDER_SIZE"), "{0:N02}"); columns[( int )ColumnID.iFolderPath] = new ReportColumn(GetString("IFOLDER_PATH")); columns[( int )ColumnID.iFolderQuota] = new ReportColumn(GetString("IFOLDER_QUOTA"), "{0:N02}"); columns[( int )ColumnID.MemberCount] = new ReportColumn(GetString("MEMBER_COUNT")); columns[( int )ColumnID.FileCount] = new ReportColumn(GetString("FILE_COUNT")); columns[( int )ColumnID.DirectoryCount] = new ReportColumn(GetString("DIRECTORY_COUNT")); columns[( int )ColumnID.OwnerID] = new ReportColumn(GetString("OWNER_ID")); columns[( int )ColumnID.OwnerName] = new ReportColumn(GetString("OWNER_NAME")); columns[( int )ColumnID.OwnerCN] = new ReportColumn(GetString("OWNER_CN")); columns[( int )ColumnID.OwnerDN] = new ReportColumn(GetString("OWNER_DN")); columns[( int )ColumnID.OwnerQuota] = new ReportColumn(GetString("OWNER_QUOTA"), "{0:N02}"); columns[( int )ColumnID.OwnerLastLogin] = new ReportColumn(GetString("OWNER_LAST_LOGIN"), "{0:G}"); columns[( int )ColumnID.OwnerDisabled] = new ReportColumn(GetString("OWNER_DISABLED")); columns[( int )ColumnID.PreviousOwner] = new ReportColumn(GetString("PREVIOUS_OWNER")); columns[( int )ColumnID.OrphanedOwner] = new ReportColumn(GetString("ORPHANED_OWNER")); columns[( int )ColumnID.LastSyncTime] = new ReportColumn(GetString("LAST_SYNC_TIME"), "{0:G}"); }
/// <summary> /// It removes All User's POBox . Before that it extracts all the policy related information from User's POBox and store them /// as part of member object. This is used in cases where server is upgraded from a lower version to 3.7 . Even if server is /// not upgraded, whenever server is restarted, this code will remove POBox for all users. /// It does not search those policies which were not present in earlier version. e.g sharing /// </summary> public void ExtractMemberPoliciesOnMaster() { log.Debug("ExtractMemberPoliciesOnMaster: entered"); Store store = Store.GetStore(); Domain domain = store.GetDomain(store.DefaultDomain); Simias.Configuration config = Store.Config; string UpgradedServer = String.Empty; UpgradedServer = config.Get("Server", "UpgradedServer"); if (UpgradedServer == null || UpgradedServer != "yes") { return; } HostNode hNode = null; HostNode mNode = null; HostNode masterNode = null; bool OnMaster = false; try { if (domain == null) { throw new Exception("store not initialized yet"); } hNode = HostNode.GetLocalHost(); Collection c = domain; ICSList members = c.GetMemberList(); foreach (ShallowNode sn in members) { Member member = new Member(c, sn); if (member == null) { //throw new Exception("cannot form member object !!!!"); log.Debug("bug : Member is null !!!"); continue; } if (member.IsType("Host")) { continue; } if (hNode == null) { log.Debug("local host is null"); return; } mNode = member.HomeServer; if (mNode == null) { continue; } masterNode = HostNode.GetMaster(domain.ID); OnMaster = false; if (hNode.UserID == masterNode.UserID) { // local host is master so no need to do web-service call during commit OnMaster = true; } ExtractMemberPolicies(domain.ID, member, sn, OnMaster); } } catch (Exception ex) { log.Debug("Extracting of member policies from local server and setting on master failed..." + ex.ToString()); } }