version 1.11.30.3, 2007/01/02 06:14:47
|
version 1.13, 2007/05/25 18:35:18
|
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Nag Boranna, Hewlett-Packard Company(nagaraja_boranna@hp.com) |
|
// |
|
// Modified By: |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
| |
#include <Pegasus/Common/FileSystem.h> | #include <Pegasus/Common/FileSystem.h> |
#include <Pegasus/Common/Tracer.h> | #include <Pegasus/Common/Tracer.h> |
#include <Pegasus/Common/Executor.h> | #include <Pegasus/Common/Executor.h> |
|
#include <Executor/Strlcpy.h> |
| |
#include "LocalAuthFile.h" | #include "LocalAuthFile.h" |
#include "SecureLocalAuthenticator.h" | #include "SecureLocalAuthenticator.h" |
|
|
// | // |
// Does local authentication | // Does local authentication |
// | // |
Boolean SecureLocalAuthenticator::authenticate |
Boolean SecureLocalAuthenticator::authenticate( |
( |
|
const String& filePath, | const String& filePath, |
const String& secretReceived, | const String& secretReceived, |
const String& secretKept |
const String& secretKept) |
) |
|
{ | { |
PEG_METHOD_ENTER(TRC_AUTHENTICATION, | PEG_METHOD_ENTER(TRC_AUTHENTICATION, |
"SecureLocalAuthenticator::authenticate()"); | "SecureLocalAuthenticator::authenticate()"); |
| |
Boolean authenticated = false; | Boolean authenticated = false; |
| |
|
// Use executor, if present. |
| |
if ((!String::equal(secretReceived, String::EMPTY)) && |
if (Executor::detectExecutor() == 0) |
(!String::equal(secretKept, String::EMPTY))) |
|
{ | { |
if (String::equal(secretKept, secretReceived)) |
if (!String::equal(secretKept, String::EMPTY) && |
|
String::equal(secretKept, secretReceived)) |
|
{ |
|
authenticated = true; |
|
} |
|
else if (Executor::authenticateLocal( |
|
(const char*)filePath.getCString(), |
|
(const char*)secretReceived.getCString()) == 0) |
{ | { |
authenticated = true; | authenticated = true; |
} | } |
} | } |
|
else |
|
{ |
|
// Check secret. |
|
|
|
if (!String::equal(secretKept, String::EMPTY) && |
|
String::equal(secretKept, secretReceived)) |
|
{ |
|
authenticated = true; |
|
} |
|
|
|
// Remove the auth file created for this user request |
| |
// |
|
// remove the auth file created for this user request |
|
// |
|
if (filePath.size()) | if (filePath.size()) |
{ | { |
if (FileSystem::exists(filePath)) | if (FileSystem::exists(filePath)) |
{ | { |
Executor::removeFile(filePath.getCString()); |
FileSystem::removeFile(filePath); |
|
} |
} | } |
} | } |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
| |
return (authenticated); |
return authenticated; |
} | } |
| |
|
|
Boolean SecureLocalAuthenticator::validateUser (const String& userName) | Boolean SecureLocalAuthenticator::validateUser (const String& userName) |
{ | { |
PEG_METHOD_ENTER(TRC_AUTHENTICATION, | PEG_METHOD_ENTER(TRC_AUTHENTICATION, |
|
|
String SecureLocalAuthenticator::getAuthResponseHeader( | String SecureLocalAuthenticator::getAuthResponseHeader( |
const String& authType, | const String& authType, |
const String& userName, | const String& userName, |
String& challenge) |
String& filePath, |
|
String& secret) |
{ | { |
PEG_METHOD_ENTER(TRC_AUTHENTICATION, | PEG_METHOD_ENTER(TRC_AUTHENTICATION, |
"SecureLocalAuthenticator::getAuthResponseHeader()"); | "SecureLocalAuthenticator::getAuthResponseHeader()"); |
|
|
responseHeader.append(authType); | responseHeader.append(authType); |
responseHeader.append(" \""); | responseHeader.append(" \""); |
| |
// |
// Use executor, if present. |
|
|
|
if (Executor::detectExecutor() == 0) |
|
{ |
|
char filePathBuffer[EXECUTOR_BUFFER_SIZE]; |
|
|
|
if (Executor::challengeLocal( |
|
userName.getCString(), filePathBuffer) != 0) |
|
{ |
|
throw CannotOpenFile(filePathBuffer); |
|
} |
|
filePath = filePathBuffer; |
|
secret.clear(); |
|
|
|
responseHeader.append(filePath); |
|
responseHeader.append("\""); |
|
} |
|
else |
|
{ |
// create a file using user name and write a random number in it. | // create a file using user name and write a random number in it. |
// |
|
LocalAuthFile localAuthFile(userName); | LocalAuthFile localAuthFile(userName); |
String filePath = localAuthFile.create(); |
filePath = localAuthFile.create(); |
| |
// | // |
// get the challenge string |
// get the secret string |
// | // |
String temp = localAuthFile.getChallengeString(); |
secret = localAuthFile.getSecretString(); |
challenge = temp; |
|
| |
// |
|
// build response header with file path and challenge string. | // build response header with file path and challenge string. |
// |
|
responseHeader.append(filePath); | responseHeader.append(filePath); |
responseHeader.append("\""); | responseHeader.append("\""); |
|
} |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
| |
return (responseHeader); |
return responseHeader; |
} | } |
| |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |