File pegasus-2.9.0-local-or-remote-auth.patch of Package tog-pegasus
Index: src/Executor/Messages.h
===================================================================
--- src/Executor/Messages.h.orig
+++ src/Executor/Messages.h
@@ -198,6 +198,7 @@ struct ExecutorAuthenticatePasswordReque
{
char username[EXECUTOR_BUFFER_SIZE];
char password[EXECUTOR_BUFFER_SIZE];
+ int isRemoteUser;
};
struct ExecutorAuthenticatePasswordResponse
Index: src/Executor/PAMAuth.h
===================================================================
--- src/Executor/PAMAuth.h.orig
+++ src/Executor/PAMAuth.h
@@ -43,6 +43,7 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <syslog.h>
#include <Executor/Strlcpy.h>
#include <Executor/Strlcat.h>
#include <security/pam_appl.h>
@@ -393,35 +394,66 @@ static int PAMValidateUserCallback(
*/
static int PAMAuthenticateInProcess(
- const char* username, const char* password)
+ const char* username, const char* password, int isRemoteUser)
{
PAMData data;
struct pam_conv pconv;
- pam_handle_t* handle;
+ pam_handle_t* phandle;
+ int retcode;
+ const char *pam_tty_val = isRemoteUser ? "wbemNetwork" : "wbemLocal";
data.password = password;
pconv.conv = PAMAuthenticateCallback;
pconv.appdata_ptr = &data;
- if (pam_start("wbem", username, &pconv, &handle) != PAM_SUCCESS)
- return -1;
+ // NOTE: if any pam call should log anything, our syslog socket will
+ // be redirected to the AUTH facility, so we need to redirect it
+ // back after each pam call.
- if (pam_authenticate(handle, 0) != PAM_SUCCESS)
+ if ((retcode = pam_start("wbem", username, &pconv, &phandle)) != PAM_SUCCESS)
{
- pam_end(handle, 0);
+ closelog();
+ openlog("cimserver", LOG_PID, LOG_DAEMON);
+ syslog(LOG_ERR, "pam_start failed: %s", pam_strerror(phandle, retcode));
return -1;
}
-
- if (pam_acct_mgmt(handle, 0) != PAM_SUCCESS)
+ if ((retcode = pam_set_item(phandle, PAM_TTY, pam_tty_val)) != PAM_SUCCESS )
{
- pam_end(handle, 0);
+ pam_end(phandle, 0);
+ closelog();
+ openlog("cimserver", LOG_PID, LOG_DAEMON);
+ syslog(LOG_ERR, "pam_set_item(PAM_TTY=%s) failed: %s", pam_tty_val,
+ pam_strerror(phandle, retcode));
return -1;
}
- pam_end(handle, 0);
+ if ((retcode = pam_authenticate(phandle, 0)) != PAM_SUCCESS)
+ {
+ closelog();
+ openlog("cimserver", LOG_PID, LOG_DAEMON);
+ syslog(LOG_ERR, "pam_authenticate failed: %s",
+ pam_strerror(phandle, retcode));
+ goto auth_failed;
+ }
+
+ if (pam_acct_mgmt(phandle, 0) != PAM_SUCCESS)
+ {
+ closelog();
+ openlog("cimserver", LOG_PID, LOG_DAEMON);
+ syslog(LOG_ERR, "pam_acct_mgmt failed: %s",
+ pam_strerror(phandle, retcode));
+ goto auth_failed;
+ }
+ pam_end(phandle, 0);
return 0;
+
+auth_failed:
+ pam_end(phandle, 0);
+ syslog(LOG_ERR, "PAM authentication failed for %s user: %s",
+ isRemoteUser ? "remote" : "local", username);
+ return -1;
}
/*
@@ -439,15 +471,23 @@ static int PAMValidateUserInProcess(cons
PAMData data;
struct pam_conv pconv;
pam_handle_t* phandle;
+ int retcode;
pconv.conv = PAMValidateUserCallback;
pconv.appdata_ptr = &data;
- if (pam_start("wbem", username, &pconv, &phandle) != PAM_SUCCESS)
+ if ((retcode = pam_start("wbem", username, &pconv, &phandle)) != PAM_SUCCESS)
+ closelog();
+ openlog("cimserver", LOG_PID, LOG_DAEMON);
+ syslog(LOG_ERR, "pam_start failed: %s", pam_strerror(phandle, retcode));
return -1;
- if (pam_acct_mgmt(phandle, 0) != PAM_SUCCESS)
+ if ((retcode = pam_acct_mgmt(phandle, 0)) != PAM_SUCCESS)
{
+ closelog();
+ openlog("cimserver", LOG_PID, LOG_DAEMON);
+ syslog(LOG_ERR, "pam_acct_mgmt failed: %s",
+ pam_strerror(phandle, retcode));
pam_end(phandle, 0);
return -1;
}
@@ -467,12 +507,13 @@ static int PAMValidateUserInProcess(cons
**==============================================================================
*/
-static int PAMAuthenticate(const char* username, const char* password)
+static int PAMAuthenticate(const char* username, const char* password,
+ int isRemoteUser)
{
#ifdef PEGASUS_USE_PAM_STANDALONE_PROC
return CimserveraProcessOperation("authenticate", username, password);
#else
- return PAMAuthenticateInProcess(username, password);
+ return PAMAuthenticateInProcess(username, password, isRemoteUser);
#endif
}
Index: src/Executor/Parent.c
===================================================================
--- src/Executor/Parent.c.orig
+++ src/Executor/Parent.c
@@ -623,7 +623,8 @@ static void HandleAuthenticatePasswordRe
#if defined(PEGASUS_PAM_AUTHENTICATION)
- if (PAMAuthenticate(request.username, request.password) != 0)
+ if (PAMAuthenticate(request.username, request.password,
+ request.isRemoteUser) != 0)
{
status = -1;
break;
Index: src/Executor/tests/PAMAuth/TestExecutorPAMAuth.c
===================================================================
--- src/Executor/tests/PAMAuth/TestExecutorPAMAuth.c.orig
+++ src/Executor/tests/PAMAuth/TestExecutorPAMAuth.c
@@ -49,7 +49,7 @@ int main()
sprintf(prompt, "Enter password for %s: ", PEGASUS_CIMSERVERMAIN_USER);
pw = getpass(prompt);
- if (PAMAuthenticate(PEGASUS_CIMSERVERMAIN_USER, pw) == 0)
+ if (PAMAuthenticate(PEGASUS_CIMSERVERMAIN_USER, pw, 0) == 0)
printf("Correct password\n");
else
printf("Wrong password\n");
Index: src/Pegasus/Common/AuthenticationInfo.h
===================================================================
--- src/Pegasus/Common/AuthenticationInfo.h.orig
+++ src/Pegasus/Common/AuthenticationInfo.h
@@ -354,6 +354,22 @@ public:
return _rep->getRemotePrivilegedUserAccessChecked();
}
+ /** Indicate whether the user is Remote
+ */
+ Boolean isRemoteUser() const
+ {
+ CheckRep(_rep);
+ return _rep->isRemoteUser();
+ }
+
+ /** Set the Remote User flag
+ */
+ void setRemoteUser(Boolean remoteUser)
+ {
+ CheckRep(_rep);
+ _rep->setRemoteUser(remoteUser);
+ }
+
private:
AuthenticationInfo(AuthenticationInfoRep* rep) : _rep(rep)
Index: src/Pegasus/Common/AuthenticationInfoRep.cpp
===================================================================
--- src/Pegasus/Common/AuthenticationInfoRep.cpp.orig
+++ src/Pegasus/Common/AuthenticationInfoRep.cpp
@@ -44,7 +44,8 @@ const String AuthenticationInfoRep::AUTH
AuthenticationInfoRep::AuthenticationInfoRep(Boolean flag)
: _connectionAuthenticated(false),
- _wasRemotePrivilegedUserAccessChecked(false)
+ _wasRemotePrivilegedUserAccessChecked(false),
+ _remoteUser(true)
{
PEG_METHOD_ENTER(
TRC_AUTHENTICATION, "AuthenticationInfoRep::AuthenticationInfoRep");
@@ -166,5 +167,15 @@ void AuthenticationInfoRep::setClientCer
PEG_METHOD_EXIT();
}
+
+void AuthenticationInfoRep::setRemoteUser(Boolean remoteUser)
+{
+ PEG_METHOD_ENTER(TRC_AUTHENTICATION,
+ "AuthenticationInfoRep::setRemoteUser");
+
+ _remoteUser = remoteUser;
+
+ PEG_METHOD_EXIT();
+}
PEGASUS_NAMESPACE_END
Index: src/Pegasus/Common/AuthenticationInfoRep.h
===================================================================
--- src/Pegasus/Common/AuthenticationInfoRep.h.orig
+++ src/Pegasus/Common/AuthenticationInfoRep.h
@@ -165,6 +165,13 @@ public:
return _wasRemotePrivilegedUserAccessChecked;
}
+ Boolean isRemoteUser() const
+ {
+ return _remoteUser;
+ }
+
+ void setRemoteUser(Boolean remoteUser);
+
private:
/** Constructors */
@@ -190,6 +197,7 @@ private:
Boolean _wasRemotePrivilegedUserAccessChecked;
Array<SSLCertificateInfo*> _clientCertificate;
+ Boolean _remoteUser;
};
PEGASUS_NAMESPACE_END
Index: src/Pegasus/Common/Executor.cpp
===================================================================
--- src/Pegasus/Common/Executor.cpp.orig
+++ src/Pegasus/Common/Executor.cpp
@@ -125,7 +125,8 @@ public:
virtual int authenticatePassword(
const char* username,
- const char* password) = 0;
+ const char* password,
+ Boolean isRemoteUser) = 0;
virtual int validateUser(
const char* username) = 0;
@@ -555,10 +556,11 @@ public:
virtual int authenticatePassword(
const char* username,
- const char* password)
+ const char* password,
+ Boolean isRemoteUser)
{
#if defined(PEGASUS_PAM_AUTHENTICATION)
- return PAMAuthenticate(username, password);
+ return PAMAuthenticate(username, password, isRemoteUser);
#else
// ATTN: not handled so don't call in this case.
return -1;
@@ -897,7 +899,8 @@ public:
virtual int authenticatePassword(
const char* username,
- const char* password)
+ const char* password,
+ Boolean isRemoteUser)
{
AutoMutex autoMutex(_mutex);
@@ -915,6 +918,7 @@ public:
memset(&request, 0, sizeof(request));
Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE);
Strlcpy(request.password, password, EXECUTOR_BUFFER_SIZE);
+ request.isRemoteUser = isRemoteUser;
if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request))
return -1;
@@ -1165,10 +1169,11 @@ int Executor::reapProviderAgent(
int Executor::authenticatePassword(
const char* username,
- const char* password)
+ const char* password,
+ Boolean isRemoteUser)
{
once(&_executorImplOnce, _initExecutorImpl);
- return _executorImpl->authenticatePassword(username, password);
+ return _executorImpl->authenticatePassword(username, password, isRemoteUser);
}
int Executor::validateUser(
Index: src/Pegasus/Common/Executor.h
===================================================================
--- src/Pegasus/Common/Executor.h.orig
+++ src/Pegasus/Common/Executor.h
@@ -183,7 +183,8 @@ public:
*/
static int authenticatePassword(
const char* username,
- const char* password);
+ const char* password,
+ Boolean isRemoteUser);
/** Check whether the given user is valid for the underlying authentcation
mechanism.
Index: src/Pegasus/Common/HTTPConnection.cpp
===================================================================
--- src/Pegasus/Common/HTTPConnection.cpp.orig
+++ src/Pegasus/Common/HTTPConnection.cpp
@@ -2151,6 +2151,50 @@ void HTTPConnection::_handleReadEvent()
_incomingBuffer).get()));
}
+ // Allow authenticators to differentiate Remote and Local users:
+ struct sockaddr_in6 sin_peer, sin_svr;
+ socklen_t slen1=sizeof(sin_peer), slen2=sizeof(sin_svr);
+ uint32_t sock = _socket.get()->getSocket() ;
+ memset(&sin_peer,'\0',slen1);
+ memset(&sin_svr, '\0',slen2);
+ if (::getpeername( sock, (struct sockaddr*)&sin_peer, &slen1) == 0 ||
+ ::getsockname( sock, (struct sockaddr*)&sin_svr, &slen2) == 0)
+ {
+ if (sin_peer.sin6_family == AF_INET)
+ {
+ struct sockaddr_in sin;
+ memcpy(&sin, &sin_peer, sizeof(sin));
+ if ((ntohl(sin.sin_addr.s_addr) >> 24) & 0xff == 127)
+ // message was sent FROM localhost interface
+ message->fromRemoteHost = false;
+ }
+ if (sin_svr.sin6_family == AF_INET)
+ {
+ struct sockaddr_in sin;
+ memcpy(&sin, &sin_svr, sizeof(sin));
+ if ((ntohl( sin.sin_addr.s_addr) >> 24) & 0xff == 127)
+ // message was sent TO localhost interface
+ message->fromRemoteHost = false;
+ }
+ if (sin_peer.sin6_family == AF_INET6)
+ {
+ // ::ffff:127.x.x.x
+ static char ipv4_localhost[] =
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127};
+ if (memcmp(&sin_peer.sin6_addr, ipv4_localhost,
+ sizeof(ipv4_localhost)) == 0)
+ {
+ message->fromRemoteHost = false;
+ }
+ // ::1
+ if (memcmp(&sin_peer.sin6_addr, &in6addr_loopback,
+ sizeof(struct in6_addr)) == 0)
+ {
+ message->fromRemoteHost = false;
+ }
+ }
+ }
+
//
// increment request count
//
Index: src/Pegasus/Common/HTTPMessage.cpp
===================================================================
--- src/Pegasus/Common/HTTPMessage.cpp.orig
+++ src/Pegasus/Common/HTTPMessage.cpp
@@ -133,7 +133,8 @@ HTTPMessage::HTTPMessage(
queueId(queueId_),
authInfo(0),
acceptLanguagesDecoded(false),
- contentLanguagesDecoded(false)
+ contentLanguagesDecoded(false),
+ fromRemoteHost(true)
{
if (cimException_)
cimException = *cimException_;
Index: src/Pegasus/Common/HTTPMessage.h
===================================================================
--- src/Pegasus/Common/HTTPMessage.h.orig
+++ src/Pegasus/Common/HTTPMessage.h
@@ -73,6 +73,7 @@ public:
ContentLanguageList contentLanguages;
Boolean acceptLanguagesDecoded;
Boolean contentLanguagesDecoded;
+ Boolean fromRemoteHost;
CIMException cimException;
void parse(
Index: src/Pegasus/Common/tests/Executor/TestExecutor.cpp
===================================================================
--- src/Pegasus/Common/tests/Executor/TestExecutor.cpp.orig
+++ src/Pegasus/Common/tests/Executor/TestExecutor.cpp
@@ -76,7 +76,7 @@ void testExecutorLoopbackImpl()
#endif
PEGASUS_TEST_ASSERT(Executor::authenticatePassword(
- "xnonexistentuserx", "wrongpassword") == -1);
+ "xnonexistentuserx", "wrongpassword", 0) == -1);
PEGASUS_TEST_ASSERT(Executor::validateUser("xnonexistentuserx") == -1);
char challengeFilePath[EXECUTOR_BUFFER_SIZE];
@@ -115,7 +115,7 @@ void testExecutorSocketImpl()
PEGASUS_TEST_ASSERT(Executor::reapProviderAgent(123) == 0);
PEGASUS_TEST_ASSERT(Executor::authenticatePassword(
- "xnonexistentuserx", "wrongpassword") == -1);
+ "xnonexistentuserx", "wrongpassword", 0) == -1);
PEGASUS_TEST_ASSERT(Executor::validateUser("xnonexistentuserx") == -1);
char challengeFilePath[EXECUTOR_BUFFER_SIZE];
Index: src/Pegasus/Security/Authentication/BasicAuthenticationHandler.cpp
===================================================================
--- src/Pegasus/Security/Authentication/BasicAuthenticationHandler.cpp.orig
+++ src/Pegasus/Security/Authentication/BasicAuthenticationHandler.cpp
@@ -152,7 +152,8 @@ Boolean BasicAuthenticationHandler::auth
}
authInfo->setRemotePrivilegedUserAccessChecked();
- authenticated = _basicAuthenticator->authenticate(userName, password);
+ authenticated = _basicAuthenticator->authenticate(userName, password,
+ authInfo->isRemoteUser());
// Log audit message.
PEG_AUDIT_LOG(logBasicAuthentication(
Index: src/Pegasus/Security/Authentication/BasicAuthenticator.h
===================================================================
--- src/Pegasus/Security/Authentication/BasicAuthenticator.h.orig
+++ src/Pegasus/Security/Authentication/BasicAuthenticator.h
@@ -65,7 +65,8 @@ public:
*/
virtual Boolean authenticate(
const String& userName,
- const String& password) = 0;
+ const String& password,
+ Boolean isRemoteUser) = 0;
/** Construct and return the HTTP Basic authentication challenge header
@return A string containing the authentication challenge header.
Index: src/Pegasus/Security/Authentication/PAMBasicAuthenticator.h
===================================================================
--- src/Pegasus/Security/Authentication/PAMBasicAuthenticator.h.orig
+++ src/Pegasus/Security/Authentication/PAMBasicAuthenticator.h
@@ -53,7 +53,8 @@ public:
Boolean authenticate(
const String& userName,
- const String& password);
+ const String& password,
+ Boolean isRemoteUser);
Boolean validateUser(const String& userName);
Index: src/Pegasus/Security/Authentication/PAMBasicAuthenticatorStub.cpp
===================================================================
--- src/Pegasus/Security/Authentication/PAMBasicAuthenticatorStub.cpp.orig
+++ src/Pegasus/Security/Authentication/PAMBasicAuthenticatorStub.cpp
@@ -73,7 +73,8 @@ PAMBasicAuthenticator::~PAMBasicAuthenti
Boolean PAMBasicAuthenticator::authenticate(
const String& userName,
- const String& password)
+ const String& password,
+ Boolean isRemoteUser)
{
PEG_METHOD_ENTER(TRC_AUTHENTICATION,
"PAMBasicAuthenticator::authenticate()");
Index: src/Pegasus/Security/Authentication/PAMBasicAuthenticatorUnix.cpp
===================================================================
--- src/Pegasus/Security/Authentication/PAMBasicAuthenticatorUnix.cpp.orig
+++ src/Pegasus/Security/Authentication/PAMBasicAuthenticatorUnix.cpp
@@ -64,13 +64,14 @@ PAMBasicAuthenticator::~PAMBasicAuthenti
Boolean PAMBasicAuthenticator::authenticate(
const String& userName,
- const String& password)
+ const String& password,
+ Boolean isRemoteUser)
{
PEG_METHOD_ENTER(TRC_AUTHENTICATION,
"PAMBasicAuthenticator::authenticate()");
if (Executor::authenticatePassword(
- userName.getCString(), password.getCString()) != 0)
+ userName.getCString(), password.getCString(), isRemoteUser) != 0)
{
return false;
}
Index: src/Pegasus/Security/Authentication/SecureBasicAuthenticator.cpp
===================================================================
--- src/Pegasus/Security/Authentication/SecureBasicAuthenticator.cpp.orig
+++ src/Pegasus/Security/Authentication/SecureBasicAuthenticator.cpp
@@ -236,7 +236,7 @@ Boolean SecureBasicAuthenticator::authen
if (Executor::detectExecutor() == 0)
{
if (Executor::authenticatePassword(
- userName.getCString(), password.getCString()) == 0)
+ userName.getCString(), password.getCString(), 0) == 0)
{
authenticated = true;
}
Index: src/Pegasus/Server/HTTPAuthenticatorDelegator.cpp
===================================================================
--- src/Pegasus/Server/HTTPAuthenticatorDelegator.cpp.orig
+++ src/Pegasus/Server/HTTPAuthenticatorDelegator.cpp
@@ -421,6 +421,9 @@ void HTTPAuthenticatorDelegator::handleH
Tracer::LEVEL3,
"HTTPAuthenticatorDelegator - Authentication processing start");
+ // Let Authenticators know whether this user is Local or Remote:
+ httpMessage->authInfo->setRemoteUser( httpMessage->fromRemoteHost );
+
//
// Handle authentication:
//