【问题标题】:Failed to load mqe.dll using impersonation使用模拟加载 mqe.dll 失败
【发布时间】:2017-09-01 06:58:19
【问题描述】:

我正在尝试使用系统上创建的本地用户连接到 IBM MQ 队列管理器。

我使用的是 Win server 2008 R2,IBM MQ 客户端和服务器版本是 8.0.0.6

为了以本地用户身份运行代码,我实现了模拟。现在,当我冒充用户并尝试连接时,出现以下连接错误。当我以其他用户(本地用户)身份运行 Visual Studio 时,它可以工作,但在我使用模拟时却不行。

下面是轨迹:

 System.TypeInitializationException was unhandled
  HResult=-2146233036
  Message=The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception.
  Source=amqmdnet
  TypeName=IBM.WMQ.MQQueueManager
  StackTrace:
       at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, String Channel, String ConnName)
       at MQExample.MQTest.ConnectMQ(String strQueueManagerName, String strQueueName, String strChannelInfo) in D:\Adidas\MQExample\MQExample\MQExample\MQTest.cs:line 83
       at MQExample.Form1.button1_Click(Object sender, EventArgs e) in D:\Adidas\MQExample\MQExample\MQExample\Form1.cs:line 33
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at MQExample.Program.Main() in D:\Adidas\MQExample\MQExample\MQExample\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146232828
       Message=Exception has been thrown by the target of an invocation.
       Source=mscorlib
       StackTrace:
            at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
            at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
            at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
            at System.Activator.CreateInstance(Type type, Boolean nonPublic)
            at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
            at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
            at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
            at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
            at IBM.WMQ.CommonServices.CreateCommonServices()
            at IBM.WMQ.CommonServices.TraceConstructor(String objectId, String sccsid)
            at IBM.WMQ.Nmqi.NmqiEnvironment..ctor(NmqiPropertyHandler nmqiPropertyHandler)
            at IBM.WMQ.Nmqi.NmqiFactory.GetInstance(NmqiPropertyHandler properties)
            at IBM.WMQ.MQQueueManager..cctor()
       InnerException: 
            HResult=-2146232828
            Message=Exception has been thrown by the target of an invocation.
            Source=amqmdnet
            StackTrace:
                 at IBM.WMQ.MQCommonServices..ctor()
            InnerException: 
                 HResult=-2146233088
                 Message=Failed to load mqe.dll from folder C:\Program Files\IBM\WebSphere MQ\bin\
                 Source=amqmdnet
                 StackTrace:
                      at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode)
                 InnerException: 

实现它的代码:

 using (new Tools.Impersonator("iibadmin", ".", "Test@1234"))
                    {
                        string userafter = WindowsIdentity.GetCurrent().Name;
                        MQQueueManager queueManager = null;
                        queueManager = new MQQueueManager(QueueManagerName, channelName, connectionName);

                        int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;
                        queue = queueManager.AccessQueue(QueueName, openOptions);
                        int depth = queue.CurrentDepth;
                        queueMessage = new MQMessage();
                        queueMessage.Format = MQC.MQFMT_STRING;
                        queueGetMessageOptions = new MQGetMessageOptions();
                        queue.Get(queueMessage, queueGetMessageOptions);
                        strReturn =
                        queueMessage.ReadString(queueMessage.MessageLength);
                        queue.Close();

                        queueManager.Disconnect();
                    }

【问题讨论】:

  • 文件C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll是否存在?被模拟的用户是否有权访问该文件?您想模拟运行它的原因是什么?以这种方式使用模拟将表明队列管理器上的 SVRCONN 通道不安全,并且只是接受您在服务器上模拟的用户标识为有效。使用 MQv8,您可以将用户名和密码发送到队列管理器,如果设置,它将验证并使用该 ID 来确定服务器上的 MQ 访问,不需要模拟并且安全性更好,因为您正在验证。
  • 文件C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll是否存在?被模拟的用户是否有权访问该文件?
  • 是的,它确实存在,并且模拟用户可以访问它。当 Visual Studio 作为不同的用户(我正在模拟的本地用户)运行时,它就像黄油一样工作。当我冒充它运行它时,同样不起作用。我正在使用 MQ 版本 8.0.0.6 。 MQ 服务器中的用户没有设置密码,它只有用户名。我不能只设置用户名并连接到 MQueueManager。我希望你的意思是在哈希表属性中设置用户 ID 属性和密码。请告诉我是否可以仅使用用户名来完成?
  • 正如我所说,它作为您模拟的用户工作这一事实对安全性来说是一个不好的迹象,因为它表明队列管理器只是接受断言的用户 ID。使用 IBM MQ Classes for Java 或 JMS,断言您想要的任何 id 都是微不足道的。使用 .NET 等其他 API,您需要在该名称的用户下运行以声明 id,但如果您有权创建本地用户,这也是微不足道的。实际上通过CONNAUTH 验证ID 和密码并使用ADOPTCTX(YES) 意味着您现在还需要密码才能连接。
  • 如果您想继续排除模拟不存在的原因,我建议您在服务器上启用 MQ 跟踪。另一种选择是,基于它正在寻找mqe.dll 的事实,它表明它已成功调用amqmdnet.dll,但在非托管模式下运行,这意味着它需要其他非.NET dll 作为客户端安装的一部分。如果您在托管模式下运行它,则不需要任何 dll,除了 amqmdnet.dll

标签: c# dll ibm-mq


【解决方案1】:

您的模拟用户可能没有设置 MQ 环境。

即环境变量:

PATH
LIB
MQ_JAVA_DATA_PATH
MQ_JAVA_INSTALL_PATH
MQ_JAVA_LIB_PATH
MQ_JRE_PATH

如果您运行的是 32 位 .NET,那么您需要像 64 位一样指向 32 位 MQ 环境。

即mqe.dll 位于:

C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll
C:\Program Files\IBM\WebSphere MQ\bin64\mqe.dll

因此,最好了解您正在运行什么以及需要设置什么 MQ 环境。

【讨论】:

  • 如果不同的位 (32 -64) 位是问题,当我以不同的用户身份运行 VS 时,它不应该连接。我的系统中确实设置了 MQ 客户端。如何检查用户的环境变量?
猜你喜欢
  • 1970-01-01
  • 2015-10-11
  • 2017-04-23
  • 2015-11-28
  • 1970-01-01
  • 2016-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多