ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » C/C++ Set USERID_DATA

Post new topic  Reply to topic Goto page 1, 2  Next
 C/C++ Set USERID_DATA « View previous topic :: View next topic » 
Author Message
ratzrattillo
PostPosted: Mon Jan 29, 2018 1:17 pm    Post subject: C/C++ Set USERID_DATA Reply with quote

Guest




Hello,

i am trying to set Username and Password via the C and C++ API in the same way, like the MQ-Explorer does, when selecting the user identification compatibility mode when connecting to a Remote Queue Manager. However, so far i have not found a way to do this. When capturing the traffic between my program and the Queue Manager, my program always uses the current Windows User. I cannot find any way how to send custom username and password in the USERID_DATA field (as it is displayed in wireshark)

How can i solve this. I am going through documentation since 2 days!

Thank you for your help!
Back to top
gbaddeley
PostPosted: Mon Jan 29, 2018 2:46 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2492
Location: Melbourne, Australia

Search for MQCSP, a structure that can be passed on MQ connection. I can provide example code in C.
_________________
Glenn
Back to top
View user's profile Send private message
ratzrattillo
PostPosted: Tue Jan 30, 2018 11:46 am    Post subject: C and C++ Connect Codes Reply with quote

Guest




Hello Glenn and other readers,

I try to use the CSP Option, but i have not been successful so far.

I use the following Code Snippets in C and C++:
C:
Code:

//#pragma comment(lib, "mqic.lib")


#include <cmqc.h>
#include <cmqxc.h>
#include <string.h>
#include <stdio.h>


int main(int argc, char **argv) {

   MQHCONN      HConn;
   MQLONG      CompCode;
   MQLONG      Reason;
   MQCNO      ConnectOptions = { MQCNO_DEFAULT };
   MQCD      ClientConn = { MQCD_CLIENT_CONN_DEFAULT };
   MQCSP      ClientSecurityParameters = { MQCSP_DEFAULT };
   MQCHAR      QMName[MQ_Q_MGR_NAME_LENGTH] = "QM_TEST";
   MQCHAR      channelName[MQ_CHANNEL_NAME_LENGTH + 1] = "SYSTEM.ADMIN.SVRCONN";
   MQCHAR      hostname[MQ_CONN_NAME_LENGTH + 1] = "192.168.1.20(1414)";
   MQCHAR      password[MQ_PASSWORD_LENGTH + 1] = "";
   MQCHAR      username[MQ_USER_ID_LENGTH + 1] = "Y";

   strncpy_s(QMName, MQ_Q_MGR_DESC_LENGTH, QMName, strlen(QMName));
   strncpy_s(ClientConn.ConnectionName, MQ_CONN_NAME_LENGTH, hostname, strlen(hostname));
   strncpy_s(ClientConn.ChannelName, MQ_CHANNEL_NAME_LENGTH, channelName, strlen(channelName) - 1);
   strncpy_s(ClientConn.QMgrName, MQ_Q_MGR_NAME_LENGTH, QMName, strlen(QMName));

   ClientSecurityParameters.AuthenticationType = MQCSP_AUTH_USER_ID_AND_PWD;
   ClientSecurityParameters.CSPUserIdPtr = (MQPTR)username;
   ClientSecurityParameters.CSPUserIdLength = (MQLONG)strlen(username) - 1;
   ClientSecurityParameters.CSPPasswordPtr = (MQPTR)password;
   ClientSecurityParameters.CSPPasswordLength = (MQLONG)strlen(password) - 1;

   ConnectOptions.ClientConnPtr = &ClientConn;
   ConnectOptions.SecurityParmsPtr = &ClientSecurityParameters;

   MQCONNX(QMName, &ConnectOptions, &HConn, &CompCode, &Reason);

   printf("QMName: %s\n", QMName);
   printf("Hostname: %s\n", hostname);
   printf("ChannelName: %s\n", channelName);
   printf("Reason: %ld\n", Reason);
   printf("CompCode: %ld\n", CompCode);

   return CompCode;
}



C++:
Code:

//#pragma comment(lib, "imqc23vn.lib")
//#pragma comment(lib, "imqb23vn.lib")


#include <imqi.hpp>
#include <cmqc.h>
#include <string.h>
#include <stdio.h>


int main(int argc, char **argv) {

   ImqQueueManager *pmanager = new ImqQueueManager;
   ImqChannel *pchannel = new ImqChannel;
   ImqBoolean ret = 0;
   //ImqAuthenticationRecord *pauthrec = new ImqAuthenticationRecord;

   //pauthrec->setPassword("");
   //pauthrec->setUserName("Y");
   //pauthrec->setConnectionName("192.168.1.20(1414)");
   //pauthrec->setType(MQAIT_ALL);
   //pauthrec->setConnectionReference(pmanager);


   if (ret = pchannel->setHeartBeatInterval(1))
      printf("setHeartBeatInterval %d\n", ret);

   if (ret = pchannel->setTransportType(MQXPT_TCP))
      printf("setTransportType returned %d\n", ret);

   if (ret = pchannel->setChannelName("SYSTEM.ADMIN.SVRCONN"))
      printf("setChannelName returned %d\n", ret);

   if (ret = pchannel->setConnectionName("192.168.1.20(1414)"))
      printf("setConnectionName returned %d\n", ret);

   if (ret = pchannel->setUserId("Y"))
      printf("setUserId returned %d\n", ret);

   if (ret = pchannel->setPassword(""))
      printf("setPassword returned %d\n", ret);



   if (ret = pmanager->setChannelReference(pchannel))
      printf("setChannelReference returned %d\n", ret);

   if (ret = pmanager->setName("QM_TEST"))
      printf("setName returned %d\n", ret);

   pmanager->setAuthenticationType(MQCSP_AUTH_USER_ID_AND_PWD);

   if (ret = pmanager->setUserId("Y"))
      printf("setUserId returned %d\n", ret);

   if (ret = pmanager->setAlternateUserId("Y"))
      printf("setAlternateUserId returned %d\n", ret);

   if (ret = pmanager->setPassword(""))
      printf("setPassword returned %d\n", ret);


   if (pmanager->connect()) {
      printf("The queue manager name is %s.\n", (char *)pmanager->name());
   }
   else {
      printf("ImqQueueManager::connect failed with reason code %ld\n", pmanager->reasonCode());
      delete pchannel;
   }
}


When i connect using Websphere MQ Explorer with the following settings, the authentication works just fine:
[img]
https://image.ibb.co/fGhJER/Websphere_MQ_UID_Compatibility_Mode_Connect_Settings.jpg
[/img]

[img]
https://image.ibb.co/jMKtg6/Websphere_MQ_UID_Compatibility_Mode_Connect.jpg
[/img]


However, when trying to do so with the C++ or C API for example, the Wireshark Log looks like this and i get an Error 2035:
[img]
https://image.ibb.co/gqiTg6/Websphere_MQ_UID_C_Connect.jpg
[/img]

[img]
https://image.ibb.co/n0PjM6/Websphere_MQ_UID_C_Connect_CONNINFO.jpg
[/img]

Could you please show me, how you would connect to a QM which is only accepting connections using the compatiblity mode (in C or C++)?

Best regards!
Back to top
markt
PostPosted: Tue Jan 30, 2018 11:52 am    Post subject: Reply with quote

Knight

Joined: 14 May 2002
Posts: 502

ConnectOptions.Version = MQCNO_VERSION_5;

see amqsput0.c et al.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Tue Jan 30, 2018 2:45 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2492
Location: Melbourne, Australia

markt wrote:
ConnectOptions.Version = MQCNO_VERSION_5;
see amqsput0.c et al.

Correct.
Code:
ClientSecurityParameters.CSPUserIdLength = (MQLONG)strlen(username) - 1;
   ClientSecurityParameters.CSPPasswordLength = (MQLONG)strlen(password) - 1;

Why are you subtracting 1?
Code:
MQCHAR      channelName[MQ_CHANNEL_NAME_LENGTH + 1] = "SYSTEM.ADMIN.SVRCONN";

Don't use this channel for your own apps. Define a new SVRCONN channel with appropriate attribute settings.
_________________
Glenn
Back to top
View user's profile Send private message
ratzrattillo
PostPosted: Mon Nov 12, 2018 2:21 pm    Post subject: Reply with quote

Guest




Thank you for your help so far!

I retried it again today and connecting to a local queue manager still does not work with my program (even after adjusting it according to gbaddeley's sugestions).

However, it seems to work with the precompiled amqsputc0.c example. I did not notice any difference between the amqsputc code and my code. So i compiled amqsputc0.c with Visual Studio 2017, but eventhough the program compiles successfully, it does not work. I always get the following error message:

Code:

Sample AMQSPUT0 start
MQCONNX ended with reason code 2058


However, the precompiled sample works just fine. Do you have any idea, why this behaviour might appear? Can it bee a compiler issue? Can you reproduce this behaviour?

Greetings!
Back to top
hughson
PostPosted: Mon Nov 12, 2018 2:42 pm    Post subject: Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

ratzrattillo wrote:
Thank you for your help so far!

I retried it again today and connecting to a local queue manager still does not work with my program (even after adjusting it according to gbaddeley's sugestions).

However, it seems to work with the precompiled amqsputc0.c example. I did not notice any difference between the amqsputc code and my code. So i compiled amqsputc0.c with Visual Studio 2017, but eventhough the program compiles successfully, it does not work. I always get the following error message:

Code:

Sample AMQSPUT0 start
MQCONNX ended with reason code 2058


However, the precompiled sample works just fine. Do you have any idea, why this behaviour might appear? Can it bee a compiler issue? Can you reproduce this behaviour?

Greetings!
Which library are you linking with? mqm or mqic?
Are you intending to connect as a client or as local connection?
MQRC_Q_MGR_NAME_ERROR (2058) when you are making a local connection just means you typed in your queue manager name wrong.

However, with a client connection, it means that it is trying to use the CCDT and could not find the queue manager name in any record in the CCDT.

Perhaps you could tell us the name of your queue manager, and the answers to the above question, and show us how you are invoking your application?

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
gbaddeley
PostPosted: Mon Nov 12, 2018 3:07 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2492
Location: Melbourne, Australia

Try running MQ trace. It will show what is happening in the connection. Compare trace of the 2 programs.
_________________
Glenn
Back to top
View user's profile Send private message
ratzrattillo
PostPosted: Tue Nov 13, 2018 5:48 am    Post subject: Reply with quote

Guest




Thank you very much for your help. It seems to have been a linker issue!

The samples now work perfectly. However, i do not yet understand how to connect to a remote queue manager. How do i have to configure the QueueManager and its channel to not get the following error:



Code:
PS C:\Program Files\IBM\MQ\Tools\cplus\Samples\Bin64\vn> .\imqsputc.exe DE.RATZ.QUEUE QMTEST DE.RATZ.CHANNEL/tcp/localhost(1414)
Sample IMQSPUT start
ImqQueueManager::connect ended with reason code 2035


It seems like credentials are needed for my newly created Channel, but how do i add them?

Greetings!
Back to top
bruce2359
PostPosted: Tue Nov 13, 2018 7:16 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9394
Location: US: west coast, almost. Otherwise, enroute.

ratzrattillo wrote:
Thank you very much for your help. It seems to have been a linker issue!


For the benefit of others, Please explain what you did to correct this. What did you change?
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
ratzrattillo
PostPosted: Tue Nov 13, 2018 7:57 am    Post subject: Reply with quote

Guest




I was having a misconfiguration in my Visual Studio project settings where i was linking to old/maybe wrong version of both the mqm.lib and mqci.lib. I removed these linking directives and set new ones in my sourcecode using a #pragma directive. This allowed me to connect to a local queue manager.

However i am still working on a solution to connect to a freshly created QueueManager over the network without receiving 2035 error.
Currently i am reading https://www.mqtechconference.com/sessions_v2014/IBM_MQ_Connection_Authentication.pdf in the hope of solving this issue too!
Back to top
hughson
PostPosted: Tue Nov 13, 2018 2:04 pm    Post subject: Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

ratzrattillo wrote:
However i am still working on a solution to connect to a freshly created QueueManager over the network without receiving 2035 error.

Remember to look in the queue manager error log which will tell you exactly what the error is. 2035 can cover quite a number of things.

You may also find this article useful:-

Getting going without turning off IBM MQ Security

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
ratzrattillo
PostPosted: Wed May 08, 2019 9:47 am    Post subject: UserID Compatibility mode. Reply with quote

Guest




MQ Explorer offers the ability to connect to a QM via UserId-Compatibility mode.
How can this mode be used instead of MQCSP authentication in C and C++?
Are there examples available that do exactly that?

Thanks for your help
Back to top
hughson
PostPosted: Wed May 08, 2019 1:27 pm    Post subject: Re: UserID Compatibility mode. Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

ratzrattillo wrote:
MQ Explorer offers the ability to connect to a QM via UserId-Compatibility mode.
How can this mode be used instead of MQCSP authentication in C and C++?

It can't - it's a "feature" specifically in the Java client. Why would you want it? MQCSP offers a super-set of function.

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
ratzrattillo
PostPosted: Wed May 08, 2019 11:17 pm    Post subject: Reply with quote

Guest




I am just experimenting with it, and i was curious, if it was possible to use it or not, do offer similar functionality for authentication, like MQ Explorer does.
Thanks for your reply!
Back to top
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ API Support » C/C++ Set USERID_DATA
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.