version 1.12, 2007/03/02 19:00:44
|
version 1.12.2.2, 2007/03/30 00:35:04
|
|
|
| |
#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 <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 (Executor::detectExecutor() == 0) |
|
{ |
|
if (Executor::authenticateLocal( |
|
(const char*)secretKept.getCString(), |
|
(const char*)secretReceived.getCString()) == 0) |
|
{ |
|
authenticated = true; |
|
} |
|
} |
|
else |
|
{ |
|
// Check secret. |
| |
if ((!String::equal(secretReceived, String::EMPTY)) && | if ((!String::equal(secretReceived, String::EMPTY)) && |
(!String::equal(secretKept, String::EMPTY))) | (!String::equal(secretKept, String::EMPTY))) |
|
|
} | } |
} | } |
| |
// |
// 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)) |
|
|
FileSystem::removeFile(filePath); | 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, |
|
|
responseHeader.append(authType); | responseHeader.append(authType); |
responseHeader.append(" \""); | responseHeader.append(" \""); |
| |
// |
// Use executor, if present. |
|
|
|
if (Executor::detectExecutor() == 0) |
|
{ |
|
char challenge[EXECUTOR_BUFFER_SIZE]; |
|
|
|
if (Executor::challengeLocal(userName.getCString(), challenge) != 0) |
|
{ |
|
throw CannotOpenFile(challenge); |
|
} |
|
secret = challenge; |
|
|
|
responseHeader.append(challenge); |
|
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(); | String filePath = localAuthFile.create(); |
| |
|
|
// | // |
secret = localAuthFile.getSecretString(); | secret = localAuthFile.getSecretString(); |
| |
// |
|
// 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 |