コード例 #1
0
ファイル: MA.Impersonation.cs プロジェクト: sylvainclb/psma
        void RevertImpersonation()
        {
            if (!ShouldImpersonate())
            {
                return;
            }

            Tracer.Enter("revertimpersonation");
            try
            {
                Tracer.TraceInformation("closing-impersonation-context");
                m_ImpersonationContext.Undo();

                Tracer.TraceInformation("closing-impersonation-tokenhandle {0}", impersonationToken);
                NativeMethods.CloseHandle(impersonationToken);
                Tracer.TraceInformation("closing-impersonation-duplicated-tokenhandle {0}", tokenDuplicate);
                NativeMethods.CloseHandle(tokenDuplicate);
            }
            catch (Exception ex)
            {
                Tracer.TraceError("revertimpersonation", ex);
                throw;
            }
            finally
            {
                Tracer.Exit("revertimpersonation");
            }
        }
コード例 #2
0
ファイル: SqlMethods.Schema.cs プロジェクト: ekrotki/sqlma
 public IEnumerable <AttributeDefinition> GetSchema(string TableName)
 {
     Tracer.Enter("getschema");
     try
     {
         string query = string.Format("select top 1 * from {0}", TableName);
         Tracer.TraceInformation("run-query '{0}'", query);
         SqlCommand command = new SqlCommand(query, con);
         using (SqlDataReader reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 for (int n = 0; n < reader.FieldCount; n++)
                 {
                     Tracer.TraceInformation("return-column: name: {0}, type: {1}", reader.GetName(n), reader.GetDataTypeName(n));
                     yield return(new AttributeDefinition(reader.GetName(n), reader.GetDataTypeName(n)));
                 }
             }
         }
     }
     finally
     {
         Tracer.Exit("getschema");
     }
 }
コード例 #3
0
 void WhoAmI()
 {
     Tracer.Enter("show-identity");
     try
     {
         using (WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent())
         {
             Tracer.TraceInformation("identity-name: {0}", currentIdentity.Name);
             Tracer.TraceInformation("identity-token: {0}", currentIdentity.Token);
             Tracer.TraceInformation("identity-user-value: {0}", currentIdentity.User.Value);
             if (currentIdentity.Actor != null)
             {
                 Tracer.TraceInformation("identity-actor: {0}", currentIdentity.Actor.Name);
                 Tracer.TraceInformation("identity-actor-auth-type: {0}", currentIdentity.Actor.AuthenticationType);
             }
             if (currentIdentity.Groups != null)
             {
                 foreach (IdentityReference group in currentIdentity.Groups)
                 {
                     NTAccount account = group.Translate(typeof(NTAccount)) as NTAccount;
                     Tracer.TraceInformation("group-membership {0}", account.Value);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("error-showing-current-identity", ex);
         throw;
     }
     finally
     {
         Tracer.Exit("show-identity");
     }
 }
コード例 #4
0
ファイル: MA.Export.cs プロジェクト: jlonnqvist/psma
        void IMAExtensible2CallExport.OpenExportConnection(System.Collections.ObjectModel.KeyedCollection <string, ConfigParameter> configParameters, Schema types, OpenExportConnectionRunStep exportRunStep)
        {
            Tracer.IndentLevel = 0;
            Tracer.Enter("openexportconnection");
            Tracer.Indent();
            try
            {
                InitializeConfigParameters(configParameters);

                OpenRunspace();
                schema = types;

                exportType = exportRunStep.ExportType;
                Tracer.TraceInformation("export-type '{0}'", exportType);
                exportBatchSize = exportRunStep.BatchSize;
                Tracer.TraceInformation("export-batch-size '{0}'", exportBatchSize);
            }
            catch (Exception ex)
            {
                Tracer.TraceError("openexportconnection", ex);
                throw new TerminateRunException(ex.Message);
            }
            finally
            {
                Tracer.Unindent();
                Tracer.Exit("openexportconnection");
            }
        }
コード例 #5
0
ファイル: SqlMethods.Export.cs プロジェクト: ekrotki/sqlma
 public void RemoveAllMultiValues(object anchor, string attributeName, bool softDelete)
 {
     Tracer.Enter("removeallmultivalues");
     try
     {
         string query = null;
         if (softDelete)
         {
             query = string.Format("update {0} set [{1}] = 1 where ([{2}] = @anchor and [{3}] is not null and [{1}] <> 1)", Configuration.TableNameMulti, Configuration.DeletedColumn, Configuration.BackReferenceColumn, attributeName);
         }
         else
         {
             query = string.Format("delete from {0} where ([{1}] = @anchor and [{2}] is not null)", Configuration.TableNameMulti, Configuration.BackReferenceColumn, attributeName);
         }
         using (SqlCommand cmd = new SqlCommand(query, con))
         {
             cmd.Parameters.AddWithValue("@anchor", anchor);
             Tracer.TraceInformation("run-query {0}", query);
             Tracer.TraceInformation("rows-affected {0:n0}", cmd.ExecuteNonQuery());
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("removeallmultivalues", ex);
     }
     finally
     {
         Tracer.Exit("removeallmultivalues");
     }
 }
コード例 #6
0
 public void RunStoredProcedure(string query, IEnumerable <SqlParameter> parameters)
 {
     Tracer.Enter("runstoredprocedure");
     try
     {
         using (SqlCommand cmd = new SqlCommand(query, con))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             foreach (SqlParameter param in parameters)
             {
                 Tracer.TraceInformation("add-parameter name: {0}, value: '{1}'", param.ParameterName, param.SqlValue);
                 cmd.Parameters.Add(param);
             }
             Tracer.TraceInformation("run-storedprocedure {0}", query);
             Tracer.TraceInformation("rows-affected {0:n0}", cmd.ExecuteNonQuery());
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("runstoredprocedure", ex);
     }
     finally
     {
         Tracer.Exit("runstoredprocedure");
     }
 }
コード例 #7
0
ファイル: SqlMethods.Export.cs プロジェクト: ekrotki/sqlma
 public bool ExistRecord(object anchor)
 {
     Tracer.Enter("existrecord");
     try
     {
         string query = string.Format("select {0} from {1} where [{0}] = @anchor;", Configuration.AnchorColumn, Configuration.TableNameSingle, Configuration.AnchorColumn);
         using (SqlCommand cmd = new SqlCommand(query, con))
         {
             cmd.Parameters.AddWithValue("@anchor", anchor);
             Tracer.TraceInformation("run-query {0}", query);
             object affectedRecords = (object)cmd.ExecuteScalar();
             Tracer.TraceInformation("exists {0}", affectedRecords != null);
             return(affectedRecords != null);
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("existrecord", ex);
     }
     finally
     {
         Tracer.Exit("existrecord");
     }
     return(false);
 }
コード例 #8
0
ファイル: MA.Import.cs プロジェクト: sorengranfeldt/psma
        public CloseImportConnectionResults CloseImportConnection(CloseImportConnectionRunStep importRunStep)
        {
            Tracer.Enter("closeimportconnectionresults");
            try
            {
                CloseRunspace();

                CloseImportConnectionResults cicr = new CloseImportConnectionResults();
                Tracer.TraceInformation("custom-data {0}", importRunStep.CustomData);
                Tracer.TraceInformation("close-reason {0}", importRunStep.Reason);
                if (importRunStep.Reason == CloseReason.Normal)
                {
                    cicr.CustomData = importRunStep.CustomData;
                }
                Dispose();
                return(cicr);
            }
            catch (Exception ex)
            {
                Tracer.TraceError("closeimportconnection", ex);
                throw;
            }
            finally
            {
                Tracer.Exit("closeimportconnectionresults");
            }
        }
コード例 #9
0
        public CloseImportConnectionResults CloseImportConnectionDetached(CloseImportConnectionRunStep importRunStep)
        {
            Tracer.Enter(nameof(CloseImportConnectionDetached));
            CloseImportConnectionResults result = new CloseImportConnectionResults();

            try
            {
                if (Configuration.RunAfterImport)
                {
                    List <SqlParameter> parameters = new List <SqlParameter>();
                    parameters.Add(new SqlParameter("importtype", ImportType.ToString()));
                    parameters.Add(new SqlParameter("customdata", CustomData));
                    methods.RunStoredProcedure(Configuration.ImportCommandAfter, parameters);
                    parameters.Clear();
                    parameters = null;
                }
                methods.CloseConnection();
                if (importAnchors != null)
                {
                    importAnchors.Clear();
                    importAnchors = null;
                }
                GC.Collect();
            }
            catch (Exception ex)
            {
                Tracer.TraceError(nameof(CloseImportConnectionDetached), ex);
                throw;
            }
            finally
            {
                Tracer.Exit(nameof(CloseImportConnectionDetached));
            }
            return(result);
        }
コード例 #10
0
ファイル: SqlMethods.Import.cs プロジェクト: ekrotki/sqlma
        public DataSet ReadObjects(List <object> anchors)
        {
            Tracer.Enter("readobjects");
            DataSet ds = new DataSet();

            try
            {
                string    singleanchor        = Configuration.AnchorColumn;
                string    multivalueanchorref = Configuration.BackReferenceColumn;
                DataTable single = new DataTable(Configuration.TableNameSingle);
                DataTable multi  = Configuration.HasMultivalueTable ? new DataTable(Configuration.TableNameMulti) : null;
                ds.Tables.Add(single);

                StringBuilder anchorList = new StringBuilder();
                for (int i = 0; i < anchors.Count; i++)
                {
                    if (i > 0)
                    {
                        anchorList.Append(",");
                    }
                    anchorList.AppendFormat("'{0}'", anchors[i]);
                }

                StringBuilder query = new StringBuilder();
                query.AppendFormat("select * from {0} where [{1}] in ({2});", Configuration.TableNameSingle, singleanchor, anchorList);
                if (Configuration.HasMultivalueTable)
                {
                    query.AppendFormat("select * from {0} where [{1}] in ({2});", Configuration.TableNameMulti, multivalueanchorref, anchorList);
                    ds.Tables.Add(multi);
                }
                Tracer.TraceInformation("run-query '{0}'", query.ToString());
                using (SqlCommand cmd = new SqlCommand(query.ToString(), con))
                {
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (Configuration.HasMultivalueTable)
                        {
                            ds.Load(dr, LoadOption.OverwriteChanges, single, multi);
                            DataRelation relCustOrder = new DataRelation("mv", single.Columns[singleanchor], multi.Columns[multivalueanchorref]);
                            ds.Relations.Add(relCustOrder);
                        }
                        else
                        {
                            ds.Load(dr, LoadOption.OverwriteChanges, single);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.TraceError("readobjects {0}", ex.Message);
                throw;
            }
            finally
            {
                Tracer.Exit("readobjects");
            }
            return(ds);
        }
コード例 #11
0
        void SetupImpersonationToken()
        {
            Tracer.Enter("setupimpersonationtoken");
            try
            {
                if (!ShouldImpersonate())
                {
                    Tracer.TraceInformation("impersonation-not-configured-running-as-sync-service-account");
                    WhoAmI();
                    return;
                }
                WindowsIdentity m_ImpersonatedUser;

                Tracer.TraceInformation("user-before-impersonation: {0}", WindowsIdentity.GetCurrent(TokenAccessLevels.MaximumAllowed).Name);

                //bool success = NativeMethods.LogonUser(impersonationUsername, impersonationUserDomain, impersonationUserPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out impersonationToken);
                bool success = NativeMethods.LogonUser(impersonationUsername, impersonationUserDomain, impersonationUserPassword, (int)LogonType.LOGON32_LOGON_NETWORK_CLEARTEXT, (int)LogonProvider.LOGON32_PROVIDER_WINNT50, out impersonationToken);
                if (!success)
                {
                    SecurityException ex = new SecurityException(string.Format("failed-to-impersonate: domain: '{0}', username: '******', password: **secret***", impersonationUserDomain, impersonationUsername));
                    Tracer.TraceError(ex.ToString());
                    throw ex;
                }
                else
                {
                    Tracer.TraceInformation("succeeded-in-impersonating: domain: '{0}', username: '******', password: **secret***", impersonationUserDomain, impersonationUsername);
                    if (NativeMethods.DuplicateToken(impersonationToken, (int)ImpersonationLevel.SecurityImpersonation, ref tokenDuplicate) != 0)
                    {
                        m_ImpersonatedUser     = new WindowsIdentity(tokenDuplicate);
                        m_ImpersonationContext = m_ImpersonatedUser.Impersonate();
                        Tracer.TraceInformation("succeeded-in-duplicating-impersonation-token");
                        if (m_ImpersonationContext != null)
                        {
                            Tracer.TraceInformation("user-after-impersonation: {0}", WindowsIdentity.GetCurrent(TokenAccessLevels.MaximumAllowed).Name);
                            WhoAmI();
                        }
                        else
                        {
                            throw new Exception("impersonation-context-is-null");
                        }
                    }
                    else
                    {
                        throw new Exception("could-not-duplicate-impersonation-token");
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.TraceError("setupimpersonationtoken", ex);
                throw;
            }
            finally
            {
                Tracer.Unindent();
                Tracer.Exit("setupimpersonationtoken");
            }
        }
コード例 #12
0
        IList <ConfigParameterDefinition> IMAExtensible2GetParameters.GetConfigParameters(System.Collections.ObjectModel.KeyedCollection <string, ConfigParameter> configParameters, ConfigParameterPage page)
        {
            Tracer.Enter("getconfigparameters");
            Tracer.Indent();
            try
            {
                List <ConfigParameterDefinition> configParametersDefinitions = new List <ConfigParameterDefinition>();
                switch (page)
                {
                case ConfigParameterPage.Connectivity:
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("The Schema script is called to retrieve the object and attribute definitions. This script should be accessible to the FIM Synchronization Service service account during configuration and refreshes of the schema."));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Constants.Parameters.SchemaScript, ""));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateDividerParameter());
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("Authentication (optional): These credentials are passed as parameters to all scripts."));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Constants.Parameters.Username, ""));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateEncryptedStringParameter(Constants.Parameters.Password, ""));

                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateDividerParameter());
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("Impersonation (optional): If username and password below are specified (domain optional), the specified user is used to run all scripts. If not specified,  the scripts are run in the security context of the FIM Synchronization Service service account."));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Constants.Parameters.ImpersonationDomain, ""));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Constants.Parameters.ImpersonationUsername, ""));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateEncryptedStringParameter(Constants.Parameters.ImpersonationPassword, ""));

                    break;

                case ConfigParameterPage.Global:
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("Scripts"));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("These are the PowerShell scripts that are run on the different operations. You should specify the full path of the scripts. Path cannot include spaces or similar whitespaces."));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Constants.Parameters.ImportScript, ""));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Constants.Parameters.ExportScript, ""));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateCheckBoxParameter(Constants.Parameters.UsePagedImport, false));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateDividerParameter());
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("If you enable Password Management, this script is called for both password change and set (requires PCNS)."));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(Constants.Parameters.PasswordManagementScript, ""));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateDividerParameter());
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("The objects piped to the export script will normally be of type PSCustomObject. If you uncheck this, you will get objects of more complex type CSEntryChange instead (legacy behaviour). For more information on the CSEntryChange object type, please see MSDN Library."));
                    configParametersDefinitions.Add(ConfigParameterDefinition.CreateCheckBoxParameter(Constants.Parameters.ExportSimpleObjects, true));
                    break;

                case ConfigParameterPage.Partition:
                    break;

                case ConfigParameterPage.RunStep:
                    break;
                }

                return(configParametersDefinitions);
            }
            catch (Exception ex)
            {
                Tracer.TraceError("getconfigparameters", ex);
                throw;
            }
            finally
            {
                Tracer.Exit("getconfigparameters");
            }
        }
コード例 #13
0
        public PowerShellManagementAgent()
        {
            Tracer.IndentLevel = 0;
            Tracer.Enter("initialize");
            Tracer.Indent();
            try
            {
                Tracer.TraceInformation("memory-usage {0:n} Mb", GC.GetTotalMemory(true) / 102400);
                System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
                string version = fvi.FileVersion;
                Tracer.TraceInformation("psma-version {0}", version);
                Tracer.TraceInformation("reading-registry-settings");
                RegistryKey machineRegistry = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                RegistryKey mreRootKey      = machineRegistry.OpenSubKey(@"SOFTWARE\Granfeldt\FIM\ManagementAgents\PowerShell", false);

                if (mreRootKey != null)
                {
                    Tracer.TraceInformation("adding-eventlog-listener-for name: {0}, source: {1}", EventLogName, EventLogSource);
                    EventLog evl = new EventLog(EventLogName);
                    evl.Log    = EventLogName;
                    evl.Source = EventLogSource;

                    EventLogTraceListener eventLog = new EventLogTraceListener(EventLogSource);
                    eventLog.EventLog = evl;
                    EventTypeFilter filter = new EventTypeFilter(SourceLevels.Warning | SourceLevels.Error | SourceLevels.Critical);
                    eventLog.TraceOutputOptions = TraceOptions.Callstack;
                    eventLog.Filter             = filter;
                    Tracer.Trace.Listeners.Add(eventLog);
                    if (!EventLog.SourceExists(EventLogSource))
                    {
                        Tracer.TraceInformation("creating-eventlog-source '{0}'", EventLogSource);
                        EventLog.CreateEventSource(EventLogSource, EventLogName);
                    }

                    string logFileValue = mreRootKey.GetValue("DebugLogFileName", null) as string;
                    if (logFileValue != null)
                    {
                        Tracer.TraceWarning("Logging to file is no longer supported. Please remove registrykey DebugLogFileName and use DebugView or similar instead to catch traces from this Management Agent");
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.TraceError("could-not-initialize", ex);
                throw;
            }
            finally
            {
                Tracer.Unindent();
                Tracer.Exit("initialize");
            }
        }
コード例 #14
0
ファイル: Sql.MA.Dispose.cs プロジェクト: ekrotki/sqlma
 private bool disposedValue = false;         // To detect redundant calls
 protected virtual void Dispose(bool disposing)
 {
     Tracer.Enter(nameof(Dispose));
     if (!disposedValue)
     {
         if (disposing)
         {
             Tracer.TraceInformation("disposing-managed-objects");
         }
         disposedValue = true;
     }
     Tracer.Exit(nameof(Dispose));
 }
コード例 #15
0
ファイル: SqlMethods.Dispose.cs プロジェクト: ekrotki/sqlma
 private bool disposedValue = false;         // To detect redundant calls
 protected virtual void Dispose(bool disposing)
 {
     Tracer.Enter("dispose-sql");
     if (!disposedValue)
     {
         if (disposing)
         {
             Tracer.TraceInformation("disposing-managed-objects");
             this.CloseConnection();
         }
         disposedValue = true;
     }
     Tracer.Exit("dispose-sql");
 }
コード例 #16
0
ファイル: SqlMethods.Export.cs プロジェクト: ekrotki/sqlma
 public void AddRecord(object anchor, out object newId, string objectClass = null)
 {
     Tracer.Enter("addrecord");
     newId = anchor;
     try
     {
         string query;
         if (anchor == null)
         {
             query = string.Format("insert into {0} ([{1}]) values (@objectclass)", Configuration.TableNameSingle, Configuration.ObjectClass);
             if (Configuration.ObjectClassType == ObjectClassType.Fixed)
             {
                 query = string.Format("insert into {0} default values", Configuration.TableNameSingle);
             }
         }
         else
         {
             query = string.Format("insert into {0} ([{1}], [{2}]) values (@anchor, @objectclass)", Configuration.TableNameSingle, Configuration.AnchorColumn, Configuration.ObjectClass);
             if (Configuration.ObjectClassType == ObjectClassType.Fixed)
             {
                 query = string.Format("insert into [{0}] ([{1}]) values (@anchor)", Configuration.TableNameSingle, Configuration.AnchorColumn);
             }
         }
         query = string.Concat(query, "; select scope_identity();");
         using (SqlCommand cmd = new SqlCommand(query, con))
         {
             cmd.Parameters.AddWithValue("@anchor", anchor);
             cmd.Parameters.AddWithValue("@objectclass", objectClass);
             Tracer.TraceInformation("run-query {0}", query);
             newId = (object)cmd.ExecuteScalar();
             if (newId == null)
             {
                 Tracer.TraceInformation("no-new-anchor-returned (scope_identity)");
                 newId = anchor;
             }
             else
             {
                 Tracer.TraceInformation("scope_identity-returned {0}", newId);
             }
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("addrecord", ex);
     }
     finally
     {
         Tracer.Exit("addrecord");
     }
 }
コード例 #17
0
 public void CloseConnection()
 {
     Tracer.Enter(nameof(CloseConnection));
     Tracer.TraceInformation($"connection-state {con.State}");
     if (con.State != System.Data.ConnectionState.Closed)
     {
         con.Close();
         Tracer.TraceInformation("connection-closed");
     }
     else
     {
         Tracer.TraceInformation("connection-already-closed");
     }
     RevertImpersonation();
     Tracer.Exit(nameof(CloseConnection));
 }
コード例 #18
0
 void WhoAmI()
 {
     Tracer.Enter("show-identity");
     try
     {
         using (WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent())
         {
             Tracer.TraceInformation("identity-name: {0}", currentIdentity.Name);
             Tracer.TraceInformation("identity-token: {0}", currentIdentity.Token);
             Tracer.TraceInformation("identity-user-value: {0}", currentIdentity.User.Value);
             if (currentIdentity.Actor != null)
             {
                 Tracer.TraceInformation("identity-actor: {0}", currentIdentity.Actor.Name);
                 Tracer.TraceInformation("identity-actor-auth-type: {0}", currentIdentity.Actor.AuthenticationType);
             }
             if (currentIdentity.Groups != null)
             {
                 foreach (IdentityReference group in currentIdentity.Groups)
                 {
                     try
                     {
                         NTAccount account = group.Translate(typeof(NTAccount)) as NTAccount;
                         Tracer.TraceInformation("group-membership {0}", account.Value);
                     }
                     catch (Exception ex)
                     {
                         /*
                          * If the SID cannot be resolved, log the SID, but don't throw the exception.
                          * Throwing the exception kills the run profile, where the membership might be totally
                          * irrelevant. We do log the SID for diagnostic purpose.
                          */
                         Tracer.TraceError($"error-resolving-current-group-name: {group.Value}", ex);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("error-showing-current-identity", ex);
         throw;
     }
     finally
     {
         Tracer.Exit("show-identity");
     }
 }
コード例 #19
0
 void IMAExtensible2Password.ChangePassword(CSEntry csentry, SecureString oldPassword, SecureString newPassword)
 {
     Tracer.Enter("changepassword");
     try
     {
         CallPasswordScript(PasswordOperation.Change, csentry, oldPassword, newPassword, PasswordOptions.None);
     }
     catch (Exception ex)
     {
         Tracer.TraceError("changepassword", ex);
         throw;
     }
     finally
     {
         Tracer.Exit("changepassword");
     }
 }
コード例 #20
0
 void IMAExtensible2Password.SetPassword(CSEntry csentry, SecureString newPassword, PasswordOptions options)
 {
     Tracer.Enter("setpassword");
     try
     {
         CallPasswordScript(PasswordOperation.Set, csentry, new SecureString(), newPassword, options);
     }
     catch (Exception ex)
     {
         Tracer.TraceError("setpassword", ex);
         throw;
     }
     finally
     {
         Tracer.Exit("setpassword");
     }
 }
コード例 #21
0
        public OpenImportConnectionResults OpenImportConnectionDetached(KeyedCollection <string, ConfigParameter> configParameters, Schema types, OpenImportConnectionRunStep importRunStep)
        {
            Tracer.Enter(nameof(OpenImportConnectionDetached));
            OpenImportConnectionResults result = new OpenImportConnectionResults();

            try
            {
                if (importRunStep != null) // only use when attached to FIM
                {
                    InitializeConfigParameters(configParameters);
                    ImportType = importRunStep.ImportType;
                    CustomData = ImportType == OperationType.Delta ? importRunStep.CustomData : null;
                    PageSize   = importRunStep.PageSize;
                }
                Tracer.TraceInformation("import-type {0}", ImportType);
                Tracer.TraceInformation("customdata {0}", CustomData);
                Tracer.TraceInformation("pagesize {0}", PageSize);

                Schema = types;

                importCsEntryQueue = new List <CSEntryChange>();

                methods.OpenConnection();

                if (Configuration.RunBeforeImport)
                {
                    List <SqlParameter> parameters = new List <SqlParameter>();
                    parameters.Add(new SqlParameter("importtype", ImportType.ToString()));
                    parameters.Add(new SqlParameter("customdata", CustomData));
                    methods.RunStoredProcedure(Configuration.ImportCommandBefore, parameters);
                    parameters.Clear();
                    parameters = null;
                }
            }
            catch (Exception ex)
            {
                Tracer.TraceError(nameof(OpenImportConnectionDetached), ex);
                throw;
            }
            finally
            {
                Tracer.Exit(nameof(OpenImportConnectionDetached));
            }
            return(result);
        }
コード例 #22
0
 ParameterValidationResult IMAExtensible2GetParameters.ValidateConfigParameters(System.Collections.ObjectModel.KeyedCollection <string, ConfigParameter> configParameters, ConfigParameterPage page)
 {
     try
     {
         Tracer.Enter("validateconfigparameters");
         Tracer.Indent();
         if (page == ConfigParameterPage.Connectivity)
         {
             string schemaScriptFilename = Path.GetFullPath(configParameters[Constants.Parameters.SchemaScript].Value);
             if (!File.Exists(schemaScriptFilename))
             {
                 return(new ParameterValidationResult(ParameterValidationResultCode.Failure, string.Format("Can not find or access Schema script '{0}'. Please make sure that the FIM Synchronization Service service account can read and access this file.", schemaScriptFilename), Constants.Parameters.SchemaScript));
             }
         }
         if (page == ConfigParameterPage.Global)
         {
             string importScriptFilename = Path.GetFullPath(configParameters[Constants.Parameters.ImportScript].Value);
             if (!File.Exists(importScriptFilename))
             {
                 return(new ParameterValidationResult(ParameterValidationResultCode.Failure, string.Format("Can not find or access Import script '{0}'. Please make sure that the FIM Synchronization Service service account can read and access this file.", importScriptFilename), Constants.Parameters.ImportScript));
             }
             string exportScriptFilename = Path.GetFullPath(configParameters[Constants.Parameters.ExportScript].Value);
             if (!File.Exists(exportScriptFilename))
             {
                 return(new ParameterValidationResult(ParameterValidationResultCode.Failure, string.Format("Can not find or access Export script '{0}'. Please make sure that the FIM Synchronization Service service account can read and access this file.", exportScriptFilename), Constants.Parameters.ExportScript));
             }
             string passwordManagementScriptFilename = Path.GetFullPath(configParameters[Constants.Parameters.PasswordManagementScript].Value);
             if (!File.Exists(passwordManagementScriptFilename))
             {
                 return(new ParameterValidationResult(ParameterValidationResultCode.Failure, string.Format("Can not find or access Password Management script '{0}'. Please make sure that the FIM Synchronization Service service account can read and access this file.", passwordManagementScriptFilename), Constants.Parameters.PasswordManagementScript));
             }
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("validateconfigparameters", ex);
         throw;
     }
     finally
     {
         Tracer.Unindent();
         Tracer.Exit("validateconfigparameters");
     }
     return(new ParameterValidationResult(ParameterValidationResultCode.Success, "", ""));
 }
コード例 #23
0
 void IMAExtensible2Password.ClosePasswordConnection()
 {
     Tracer.Enter("closepasswordconnection");
     try
     {
         CloseRunspace();
         Dispose();
     }
     catch (Exception ex)
     {
         Tracer.TraceError("closepasswordconnection", ex);
         throw;
     }
     finally
     {
         Tracer.Exit("closepasswordconnection");
     }
 }
コード例 #24
0
ファイル: MA.Export.cs プロジェクト: sorengranfeldt/psma
 void IMAExtensible2CallExport.CloseExportConnection(CloseExportConnectionRunStep exportRunStep)
 {
     Tracer.Enter("closeexportconnection");
     try
     {
         CloseRunspace();
         Dispose();
     }
     catch (Exception ex)
     {
         Tracer.TraceError("closeexportconnection", ex);
         throw;
     }
     finally
     {
         Tracer.Exit("closeexportconnection");
     }
 }
コード例 #25
0
        void IMAExtensible2Password.OpenPasswordConnection(KeyedCollection <string, ConfigParameter> configParameters, Partition partition)
        {
            Tracer.Enter("openpasswordconnection");
            try
            {
                InitializeConfigParameters(configParameters);

                OpenRunspace();
            }
            catch (Exception ex)
            {
                Tracer.TraceError("openpasswordconnection", ex);
                throw;
            }
            finally
            {
                Tracer.Exit("openpasswordconnection");
            }
        }
コード例 #26
0
 public void RunStoredProcedure(string query)
 {
     Tracer.Enter("runstoredprocedure");
     try
     {
         using (SqlCommand cmd = new SqlCommand(query, con))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             Tracer.TraceInformation("run-storedprocedure {0}", query);
             Tracer.TraceInformation("rows-affected {0:n0}", cmd.ExecuteNonQuery());
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("runstoredprocedure", ex);
     }
     finally
     {
         Tracer.Exit("runstoredprocedure");
     }
 }
コード例 #27
0
 public void Dispose()
 {
     Tracer.Enter("dispose");
     try
     {
         Tracer.TraceInformation("clearing-variables");
         csentryqueue = null;
         objectTypeAnchorAttributeNames = null;
         Tracer.TraceInformation("collection-garbage");
         GC.Collect(0, GCCollectionMode.Default, true);
     }
     catch (Exception ex)
     {
         Tracer.TraceError(ex.ToString());
         throw;
     }
     finally
     {
         Tracer.Exit("dispose");
     }
 }
コード例 #28
0
        void CloseRunspace()
        {
            Tracer.Enter("closerunspace");
            Tracer.Indent();
            try
            {
                if (powershell != null)
                {
                    Tracer.TraceInformation("disposing-powershell");
                    powershell.Runspace.Close();
                    powershell.Dispose();
                    Tracer.TraceInformation("disposed-powershell");
                }

                if (runspace != null)
                {
                    Tracer.TraceInformation("runspace-state '{0}'", runspace.RunspaceStateInfo.State);
                    if (runspace.RunspaceStateInfo.State != RunspaceState.Closed)
                    {
                        Tracer.TraceInformation("removing-runspace-eventhandlers");
                        runspace.StateChanged        -= Runspace_StateChanged;
                        runspace.AvailabilityChanged -= Runspace_AvailabilityChanged;
                        Tracer.TraceInformation("removed-runspace-eventhandlers");
                        Tracer.TraceInformation("dispose-runspace");
                        runspace.Dispose();                         // dispose also closes runspace
                        Tracer.TraceInformation("disposed-runspace");
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.TraceError("closerunspace", ex);
                throw;
            }
            finally
            {
                Tracer.Unindent();
                Tracer.Exit("closerunspace");
            }
        }
コード例 #29
0
ファイル: SqlMethods.Export.cs プロジェクト: ekrotki/sqlma
 public void Undelete(object anchor)
 {
     Tracer.Enter("undelete");
     try
     {
         string query = string.Format("update {0} set [{1}] = null where [{2}] = @anchor", Configuration.TableNameSingle, Configuration.DeletedColumn, Configuration.AnchorColumn);
         using (SqlCommand cmd = new SqlCommand(query, con))
         {
             cmd.Parameters.AddWithValue("@anchor", anchor);
             Tracer.TraceInformation("run-query {0}", query);
             Tracer.TraceInformation("rows-affected {0:n0}", cmd.ExecuteNonQuery());
         }
     }
     catch (Exception ex)
     {
         Tracer.TraceError("undelete", ex);
     }
     finally
     {
         Tracer.Exit("undelete");
     }
 }
コード例 #30
0
ファイル: SqlMethods.Export.cs プロジェクト: ekrotki/sqlma
        public void DeleteRecord(object anchor, bool deleteMultiValues = false, bool softDelete = false)
        {
            Tracer.Enter("deleterecord");
            try
            {
                string query = null;

                if (softDelete)
                {
                    query = string.Format("update {0} set [{1}] = 1 where [{2}] = @anchor;", Configuration.TableNameSingle, Configuration.DeletedColumn, Configuration.AnchorColumn);
                    if (deleteMultiValues)
                    {
                        string.Concat(query, string.Format("update {0} set [{1}] = 1 where [{2}] = @anchor;", Configuration.TableNameMulti, Configuration.DeletedColumn, Configuration.BackReferenceColumn));
                    }
                }
                else
                {
                    query = string.Format("delete from {0} where [{1}] = @anchor;", Configuration.TableNameSingle, Configuration.AnchorColumn);
                    if (deleteMultiValues)
                    {
                        string.Concat(query, string.Format("delete from {0} where [{1}] = @anchor;", Configuration.TableNameMulti, Configuration.BackReferenceColumn));
                    }
                }
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    cmd.Parameters.AddWithValue("@anchor", anchor);
                    Tracer.TraceInformation("run-query {0}", query);
                    Tracer.TraceInformation("rows-affected {0:n0}", cmd.ExecuteNonQuery());
                }
            }
            catch (Exception ex)
            {
                Tracer.TraceError("addsinglevalue", ex);
            }
            finally
            {
                Tracer.Exit("addsinglevalue");
            }
        }