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 IndexIBM MQ API SupportC/C++ Set USERID_DATA

Post new topicReply to topic
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

Newbie

Joined: 29 Jan 2018
Posts: 2

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
View user's profile Send private message
gbaddeley
PostPosted: Mon Jan 29, 2018 2:46 pm Post subject: Reply with quote

Padawan

Joined: 25 Mar 2003
Posts: 1838
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

Newbie

Joined: 29 Jan 2018
Posts: 2

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
View user's profile Send private message
markt
PostPosted: Tue Jan 30, 2018 11:52 am Post subject: Reply with quote

Chevalier

Joined: 14 May 2002
Posts: 401

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

Padawan

Joined: 25 Mar 2003
Posts: 1838
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
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ API SupportC/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.