Improvements to htpasswd code following review
Improved multi-threading, including new test
This commit is contained in:
committed by
Arthur J Barr
parent
5fd9fc5e26
commit
4257f6a199
@@ -64,12 +64,16 @@ void MQENTRY MQStart(
|
||||
{
|
||||
MQLONG CC = MQCC_OK;
|
||||
MQLONG Reason = MQRC_NONE;
|
||||
|
||||
CC = log_init(LOG_FILE);
|
||||
if (CC == MQCC_OK)
|
||||
int log_rc = 0;
|
||||
|
||||
log_rc = log_init(LOG_FILE);
|
||||
if (log_rc != 0)
|
||||
{
|
||||
log_infof("MQStart options=%s qmgr=%s", ((Options == MQZIO_SECONDARY) ? "Secondary" : "Primary"), trim(QMgrName));
|
||||
CC = MQCC_FAILED;
|
||||
Reason = MQRC_INITIALIZATION_FAILED;
|
||||
}
|
||||
|
||||
log_infof("MQStart options=%s qmgr=%s", ((Options == MQZIO_SECONDARY) ? "Secondary" : "Primary"), trim(QMgrName));
|
||||
/************************************************************************/
|
||||
/* Initialize the entry point vectors. This is performed for both */
|
||||
/* global and process initialisation, i.e whatever the value of the */
|
||||
@@ -126,6 +130,13 @@ static void MQENTRY mqhtpass_authenticate_user(
|
||||
{
|
||||
char *spuser = NULL;
|
||||
char *sppass = NULL;
|
||||
// By default, return a warning, which indicates to MQ that this
|
||||
// authorization service hasn't authenticated the user.
|
||||
*pCompCode = MQCC_WARNING;
|
||||
*pReason = MQRC_NONE;
|
||||
// By default, tell the queue manager to continue trying other
|
||||
// authorization services.
|
||||
*pContinuation = MQZCI_CONTINUE;
|
||||
|
||||
if ((pSecurityParms->AuthenticationType) == MQCSP_AUTH_USER_ID_AND_PWD)
|
||||
{
|
||||
@@ -133,9 +144,21 @@ static void MQENTRY mqhtpass_authenticate_user(
|
||||
|
||||
// Firstly, create null-terminated strings from the user credentials in the MQ CSP object
|
||||
spuser = malloc(pSecurityParms->CSPUserIdLength + 1);
|
||||
if (!spuser)
|
||||
{
|
||||
log_errorf("Unable to allocate memory");
|
||||
return;
|
||||
}
|
||||
strncpy(spuser, pSecurityParms->CSPUserIdPtr, pSecurityParms->CSPUserIdLength);
|
||||
spuser[pSecurityParms->CSPUserIdLength] = 0;
|
||||
sppass = malloc(pSecurityParms->CSPPasswordLength + 1);
|
||||
if (!sppass)
|
||||
{
|
||||
log_errorf("Unable to allocate memory");
|
||||
if (spuser)
|
||||
free(spuser);
|
||||
return;
|
||||
}
|
||||
strncpy(sppass, pSecurityParms->CSPPasswordPtr, pSecurityParms->CSPPasswordLength);
|
||||
sppass[pSecurityParms->CSPPasswordLength] = 0;
|
||||
log_debugf("%s with CSP user set. user=%s", __func__, spuser);
|
||||
@@ -151,11 +174,6 @@ static void MQENTRY mqhtpass_authenticate_user(
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return a warning, which indicates to MQ that this authorization service hasn't
|
||||
// authenticated the user, but other authorization services should be tried as well.
|
||||
*pCompCode = MQCC_WARNING;
|
||||
*pReason = MQRC_NONE;
|
||||
*pContinuation = MQZCI_CONTINUE;
|
||||
log_debugf(
|
||||
"Failed to authenticate user=%s effuser=%s applname=%s cspuser=%s cc=%d reason=%d",
|
||||
pIdentityContext->UserIdentifier,
|
||||
@@ -165,13 +183,20 @@ static void MQENTRY mqhtpass_authenticate_user(
|
||||
*pCompCode,
|
||||
*pReason);
|
||||
}
|
||||
free(spuser);
|
||||
free(sppass);
|
||||
if (spuser)
|
||||
free(spuser);
|
||||
if (sppass)
|
||||
free(sppass);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Password not supplied, so just check that the user ID is valid
|
||||
spuser = malloc(sizeof(PMQCHAR12));
|
||||
spuser = malloc(sizeof(PMQCHAR12) + 1);
|
||||
if (!sppass)
|
||||
{
|
||||
log_errorf("Unable to allocate memory");
|
||||
return;
|
||||
}
|
||||
strncpy(spuser, pApplicationContext->EffectiveUserID, strlen(pApplicationContext->EffectiveUserID));
|
||||
spuser[sizeof(PMQCHAR12)] = 0;
|
||||
log_debugf("%s without CSP user set. effectiveuid=%s", __func__, spuser);
|
||||
@@ -185,9 +210,6 @@ static void MQENTRY mqhtpass_authenticate_user(
|
||||
}
|
||||
else
|
||||
{
|
||||
*pCompCode = MQCC_WARNING;
|
||||
*pReason = MQRC_NONE;
|
||||
*pContinuation = MQZCI_CONTINUE;
|
||||
log_debugf(
|
||||
"Invalid user=%s effuser=%s applname=%s cspuser=%s cc=%d reason=%d",
|
||||
pIdentityContext->UserIdentifier,
|
||||
@@ -197,6 +219,8 @@ static void MQENTRY mqhtpass_authenticate_user(
|
||||
*pCompCode,
|
||||
*pReason);
|
||||
}
|
||||
if (spuser)
|
||||
free(spuser);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -216,7 +240,7 @@ static void MQENTRY mqhtpass_free_user(
|
||||
PMQLONG pCompCode,
|
||||
PMQLONG pReason)
|
||||
{
|
||||
log_infof("mqhtpass_freeuser()");
|
||||
log_debugf("mqhtpass_freeuser()");
|
||||
*pCompCode = MQCC_WARNING;
|
||||
*pReason = MQRC_NONE;
|
||||
*pContinuation = MQZCI_CONTINUE;
|
||||
@@ -236,8 +260,8 @@ static void MQENTRY mqhtpass_term_auth(
|
||||
PMQLONG pCompCode,
|
||||
PMQLONG pReason)
|
||||
{
|
||||
log_infof("mqhtpass_term_auth()");
|
||||
if ((Options & MQZTO_PRIMARY) == MQZTO_PRIMARY)
|
||||
log_debugf("mqhtpass_term_auth()");
|
||||
if (Options == MQZTO_PRIMARY)
|
||||
{
|
||||
log_close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user