version 1.1.2.1, 2007/01/02 06:17:19
|
version 1.1.2.2, 2007/01/02 07:47:24
|
|
|
static int _sock = -1; | static int _sock = -1; |
static Mutex _mutex; | static Mutex _mutex; |
| |
|
static int _getSock() |
|
{ |
|
int sock; |
|
_mutex.lock(); |
|
sock = _sock; |
|
_mutex.unlock(); |
|
return sock; |
|
} |
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//// | //// |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_PING_REQUEST; | header.code = EXECUTOR_PING_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
ExecutorPingResponse response; | ExecutorPingResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
if (response.magic == EXECUTOR_PING_MAGIC) | if (response.magic == EXECUTOR_PING_MAGIC) |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_OPEN_FILE_REQUEST; | header.code = EXECUTOR_OPEN_FILE_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return NULL; | return NULL; |
| |
// Send request body. | // Send request body. |
|
|
Strlcpy(request.path, path, EXECUTOR_BUFFER_SIZE); | Strlcpy(request.path, path, EXECUTOR_BUFFER_SIZE); |
request.mode = mode; | request.mode = mode; |
| |
if (Send(_sock, &request, sizeof(request)) != sizeof(request)) |
if (Send(_getSock(), &request, sizeof(request)) != sizeof(request)) |
return NULL; | return NULL; |
| |
// Receive the response | // Receive the response |
| |
ExecutorOpenFileResponse response; | ExecutorOpenFileResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return NULL; | return NULL; |
| |
// Receive descriptor (if response successful). | // Receive descriptor (if response successful). |
|
|
{ | { |
int fds[1]; | int fds[1]; |
| |
if (_receiveDescriptorArray(_sock, fds, 1) != 0) |
if (_receiveDescriptorArray(_getSock(), fds, 1) != 0) |
return NULL; | return NULL; |
| |
if (fds[0] == -1) | if (fds[0] == -1) |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_RENAME_FILE_REQUEST; | header.code = EXECUTOR_RENAME_FILE_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
// Send request body. | // Send request body. |
|
|
Strlcpy(request.oldPath, oldPath, EXECUTOR_BUFFER_SIZE); | Strlcpy(request.oldPath, oldPath, EXECUTOR_BUFFER_SIZE); |
Strlcpy(request.newPath, newPath, EXECUTOR_BUFFER_SIZE); | Strlcpy(request.newPath, newPath, EXECUTOR_BUFFER_SIZE); |
| |
if (Send(_sock, &request, sizeof(request)) != sizeof(request)) |
if (Send(_getSock(), &request, sizeof(request)) != sizeof(request)) |
return -1; | return -1; |
| |
// Receive the response | // Receive the response |
| |
ExecutorRenameFileResponse response; | ExecutorRenameFileResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
return response.status; | return response.status; |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_REMOVE_FILE_REQUEST; | header.code = EXECUTOR_REMOVE_FILE_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
// Send request body. | // Send request body. |
|
|
memset(&request, 0, sizeof(request)); | memset(&request, 0, sizeof(request)); |
Strlcpy(request.path, path, EXECUTOR_BUFFER_SIZE); | Strlcpy(request.path, path, EXECUTOR_BUFFER_SIZE); |
| |
if (Send(_sock, &request, sizeof(request)) != sizeof(request)) |
if (Send(_getSock(), &request, sizeof(request)) != sizeof(request)) |
return -1; | return -1; |
| |
// Receive the response | // Receive the response |
| |
ExecutorRemoveFileResponse response; | ExecutorRemoveFileResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
return response.status; | return response.status; |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_START_PROVIDER_AGENT_REQUEST; | header.code = EXECUTOR_START_PROVIDER_AGENT_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
// Send request body. | // Send request body. |
|
|
request.uid = uid; | request.uid = uid; |
request.gid = gid; | request.gid = gid; |
| |
if (Send(_sock, &request, sizeof(request)) != sizeof(request)) |
if (Send(_getSock(), &request, sizeof(request)) != sizeof(request)) |
return -1; | return -1; |
| |
// Receive the response | // Receive the response |
| |
ExecutorStartProviderAgentResponse response; | ExecutorStartProviderAgentResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
// Check response status and pid. | // Check response status and pid. |
|
|
// Receive descriptors. | // Receive descriptors. |
| |
int descriptors[2]; | int descriptors[2]; |
int result = _receiveDescriptorArray(_sock, descriptors, 2); |
int result = _receiveDescriptorArray(_getSock(), descriptors, 2); |
| |
if (result == 0) | if (result == 0) |
{ | { |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_DAEMONIZE_EXECUTOR_REQUEST; | header.code = EXECUTOR_DAEMONIZE_EXECUTOR_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
// Receive the response | // Receive the response |
| |
ExecutorDaemonizeExecutorResponse response; | ExecutorDaemonizeExecutorResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
return response.status; | return response.status; |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_CHANGE_OWNER_REQUEST; | header.code = EXECUTOR_CHANGE_OWNER_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
// Send request body: | // Send request body: |
|
|
Strlcpy(request.path, path, sizeof(request.path)); | Strlcpy(request.path, path, sizeof(request.path)); |
Strlcpy(request.owner, owner, sizeof(request.owner)); | Strlcpy(request.owner, owner, sizeof(request.owner)); |
| |
if (Send(_sock, &request, sizeof(request)) != sizeof(request)) |
if (Send(_getSock(), &request, sizeof(request)) != sizeof(request)) |
return -1; | return -1; |
| |
// Receive the response | // Receive the response |
| |
ExecutorChangeOwnerResponse response; | ExecutorChangeOwnerResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
return response.status; | return response.status; |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_WAIT_PID_REQUEST; | header.code = EXECUTOR_WAIT_PID_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
// Send request body: | // Send request body: |
|
|
ExecutorWaitPidRequest request; | ExecutorWaitPidRequest request; |
request.pid = pid; | request.pid = pid; |
| |
if (Send(_sock, &request, sizeof(request)) != sizeof(request)) |
if (Send(_getSock(), &request, sizeof(request)) != sizeof(request)) |
return -1; | return -1; |
| |
// Receive the response | // Receive the response |
| |
ExecutorWaitPidResponse response; | ExecutorWaitPidResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
return response.status; | return response.status; |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_PAM_AUTHENTICATE_REQUEST; | header.code = EXECUTOR_PAM_AUTHENTICATE_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
// Send request body. | // Send request body. |
|
|
Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE); | Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE); |
Strlcpy(request.password, password, EXECUTOR_BUFFER_SIZE); | Strlcpy(request.password, password, EXECUTOR_BUFFER_SIZE); |
| |
if (Send(_sock, &request, sizeof(request)) != sizeof(request)) |
if (Send(_getSock(), &request, sizeof(request)) != sizeof(request)) |
return -1; | return -1; |
| |
// Receive the response | // Receive the response |
| |
ExecutorPAMAuthenticateResponse response; | ExecutorPAMAuthenticateResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
return response.status; | return response.status; |
|
|
ExecutorRequestHeader header; | ExecutorRequestHeader header; |
header.code = EXECUTOR_PAM_VALIDATE_USER_REQUEST; | header.code = EXECUTOR_PAM_VALIDATE_USER_REQUEST; |
| |
if (Send(_sock, &header, sizeof(header)) != sizeof(header)) |
if (Send(_getSock(), &header, sizeof(header)) != sizeof(header)) |
return -1; | return -1; |
| |
// Send request body. | // Send request body. |
|
|
memset(&request, 0, sizeof(request)); | memset(&request, 0, sizeof(request)); |
Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE); | Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE); |
| |
if (Send(_sock, &request, sizeof(request)) != sizeof(request)) |
if (Send(_getSock(), &request, sizeof(request)) != sizeof(request)) |
return -1; | return -1; |
| |
// Receive the response | // Receive the response |
| |
ExecutorPAMValidateUserResponse response; | ExecutorPAMValidateUserResponse response; |
| |
if (Recv(_sock, &response, sizeof(response)) != sizeof(response)) |
if (Recv(_getSock(), &response, sizeof(response)) != sizeof(response)) |
return -1; | return -1; |
| |
return response.status; | return response.status; |
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
| |
void Executor::setExecutorSocket(int sock) |
void Executor::setSock(int sock) |
{ | { |
|
_mutex.lock(); |
_sock = sock; | _sock = sock; |
|
_mutex.unlock(); |
} | } |
| |
int Executor::ping() | int Executor::ping() |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_ping(); | return InProcess_ping(); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
|
const char* path, | const char* path, |
int mode) | int mode) |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_openFile(path, mode); | return InProcess_openFile(path, mode); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
|
const char* oldPath, | const char* oldPath, |
const char* newPath) | const char* newPath) |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_renameFile(oldPath, newPath); | return InProcess_renameFile(oldPath, newPath); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
|
int Executor::removeFile( | int Executor::removeFile( |
const char* path) | const char* path) |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_removeFile(path); | return InProcess_removeFile(path); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
|
AnonymousPipe*& readPipe, | AnonymousPipe*& readPipe, |
AnonymousPipe*& writePipe) | AnonymousPipe*& writePipe) |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_startProviderAgent( | return InProcess_startProviderAgent( |
module, uid, gid, pid, readPipe, writePipe); | module, uid, gid, pid, readPipe, writePipe); |
| |
|
|
| |
int Executor::daemonizeExecutor() | int Executor::daemonizeExecutor() |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_daemonizeExecutor(); | return InProcess_daemonizeExecutor(); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
|
const char* path, | const char* path, |
const char* owner) | const char* owner) |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_changeOwner(path, owner); | return InProcess_changeOwner(path, owner); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
|
int Executor::waitPid( | int Executor::waitPid( |
int pid) | int pid) |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_waitPid(pid); | return InProcess_waitPid(pid); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
|
const char* username, | const char* username, |
const char* password) | const char* password) |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_pamAuthenticate(username, password); | return InProcess_pamAuthenticate(username, password); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
|
int Executor::pamValidateUser( | int Executor::pamValidateUser( |
const char* username) | const char* username) |
{ | { |
if (_sock == -1) |
if (_getSock() == -1) |
return InProcess_pamValidateUser(username); | return InProcess_pamValidateUser(username); |
| |
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |