int rc = CheckLocalAuthToken(challengeFilePath, response);
- if (challengeFilePath)
- unlink((char*)challengeFilePath);
+ /* Clean up the file now that the authentication is complete. */
+
+ unlink(challengeFilePath);
return rc;
}
#define ARG(X) #X, X
-/*
-**==============================================================================
-**
-** Policy
-**
-** This structure defines a policy rule.
-**
-**==============================================================================
-*/
-
-struct Policy
-{
- enum ExecutorMessageCode messageCode;
- const char* arg1;
- const char* arg2;
-};
-
/*
**==============================================================================
**
**==============================================================================
*/
-static int CheckPolicy(
+int CheckPolicy(
const struct Policy* policyTable,
size_t policyTableSize,
enum ExecutorMessageCode messageCode,
#ifndef _Executor_Policy_h
#define _Executor_Policy_h
+#include <stdlib.h>
+#include "Defines.h"
+#include "Messages.h"
+
+/*
+**==============================================================================
+**
+** Policy
+**
+** This structure defines a policy rule.
+**
+**==============================================================================
+*/
+
+struct Policy
+{
+ enum ExecutorMessageCode messageCode;
+ const char* arg1;
+ const char* arg2;
+};
+
+EXECUTOR_LINKAGE
+int CheckPolicy(
+ const struct Policy* policyTable,
+ size_t policyTableSize,
+ enum ExecutorMessageCode messageCode,
+ const char* arg1,
+ const char* arg2);
+
+EXECUTOR_LINKAGE
int CheckOpenFilePolicy(const char* path, int mode);
+EXECUTOR_LINKAGE
int CheckRemoveFilePolicy(const char* path);
+EXECUTOR_LINKAGE
int CheckRenameFilePolicy(const char* oldPath, const char* newPath);
+EXECUTOR_LINKAGE
void DumpPolicy(int expandMacros);
#endif /* _Executor_Policy_h */
/* If no-null terminator found, return size. */
if (i == size)
- return size;
+ {
+ int j = 0;
+ while (src[j])
+ {
+ j++;
+ }
+ return size + j;
+ }
/* Copy src characters to dest. */
for (j = 0; src[j] && i + 1 < size; i++, j++)
dest[i] = src[j];
- /* Null terminate size non-zero. */
+ /* Null terminate the destination. We are guaranteed that size is
+ * non-zero, because the (i == size) condition above is always true
+ * when size is zero.
+ */
- if (size > 0)
- dest[i] = '\0';
+ dest[i] = '\0';
while (src[j])
{
Options \
PasswordFile \
Path \
+ Policy \
Process \
Random \
Socket \
--- /dev/null
+#//%2006////////////////////////////////////////////////////////////////////////
+#//
+#// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
+#// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
+#// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
+#// IBM Corp.; EMC Corporation, The Open Group.
+#// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
+#// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
+#// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+#// EMC Corporation; VERITAS Software Corporation; The Open Group.
+#// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+#// EMC Corporation; Symantec Corporation; The Open Group.
+#//
+#// Permission is hereby granted, free of charge, to any person obtaining a copy
+#// of this software and associated documentation files (the "Software"), to
+#// deal in the Software without restriction, including without limitation the
+#// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+#// sell copies of the Software, and to permit persons to whom the Software is
+#// furnished to do so, subject to the following conditions:
+#//
+#// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
+#// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
+#// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+#// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+#// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+#// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+#// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+#// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#//
+#//=============================================================================
+
+ROOT = $(PEGASUS_ROOT)
+DIR = Executor/tests/Policy
+
+include $(ROOT)/mak/config.mak
+
+PROGRAM = TestExecutorPolicy
+SOURCES = TestExecutorPolicy.c
+EXTRA_INCLUDES += -I../../..
+
+LIBRARIES += pegexecutor
+
+include ../common.mak
+include $(ROOT)/mak/program.mak
+
+tests:
+ $(PROGRAM)
+
+poststarttests:
--- /dev/null
+/*
+//%2006////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
+// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
+// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation, The Open Group.
+// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; Symantec Corporation; The Open Group.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
+// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
+// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//==============================================================================
+//
+//%/////////////////////////////////////////////////////////////////////////////
+*/
+
+#include <Executor/Policy.h>
+#include <Executor/Macro.h>
+#include <stdio.h>
+#include <assert.h>
+
+static struct Policy _testPolicyTable[] =
+{
+ {
+ EXECUTOR_PING_MESSAGE,
+ NULL,
+ NULL
+ },
+ {
+ EXECUTOR_RENAME_FILE_MESSAGE,
+ "${file1}",
+ "${file2}"
+ },
+ {
+ EXECUTOR_RENAME_FILE_MESSAGE,
+ "file1",
+ "${file2}"
+ },
+ {
+ EXECUTOR_RENAME_FILE_MESSAGE,
+ "file1",
+ "file2"
+ }
+};
+
+static const size_t _testPolicyTableSize =
+ sizeof(_testPolicyTable) / sizeof(_testPolicyTable[0]);
+
+void testCheckPolicy()
+{
+ /* Test non-existent policy */
+ assert(CheckPolicy(
+ _testPolicyTable,
+ _testPolicyTableSize,
+ EXECUTOR_REAP_PROVIDER_AGENT,
+ NULL,
+ NULL) != 0);
+
+ /* Test policy with no arguments */
+ assert(CheckPolicy(
+ _testPolicyTable,
+ _testPolicyTableSize,
+ EXECUTOR_PING_MESSAGE,
+ NULL,
+ NULL) == 0);
+
+ /* Test policies with invalid macro expansion in first argument and
+ * non-match in first argument
+ */
+ assert(CheckPolicy(
+ _testPolicyTable,
+ _testPolicyTableSize,
+ EXECUTOR_RENAME_FILE_MESSAGE,
+ "MyFile",
+ "file2") != 0);
+
+ /* Test policies with invalid macro expansion in second argument and
+ * non-match in second argument
+ */
+ assert(CheckPolicy(
+ _testPolicyTable,
+ _testPolicyTableSize,
+ EXECUTOR_RENAME_FILE_MESSAGE,
+ "file1",
+ "MyFile") != 0);
+
+ /* Test policy with successful match in both arguments */
+ assert(CheckPolicy(
+ _testPolicyTable,
+ _testPolicyTableSize,
+ EXECUTOR_RENAME_FILE_MESSAGE,
+ "file1",
+ "file2") == 0);
+}
+
+void testFilePolicies()
+{
+ const char* currentConfigFile = "MyConfigFile";
+ const char* currentConfigFileBak = "MyConfigFile.bak";
+ const char* noAccessFile = "NoAccessFile";
+
+ /* Define a macro used in the static policy table */
+ DefineMacro("currentConfigFilePath", currentConfigFile);
+
+ assert(CheckOpenFilePolicy(currentConfigFile, 'w') == 0);
+ assert(CheckOpenFilePolicy(noAccessFile, 'w') != 0);
+
+ assert(CheckRemoveFilePolicy(currentConfigFile) == 0);
+ assert(CheckRemoveFilePolicy(noAccessFile) != 0);
+
+ assert(CheckRenameFilePolicy(currentConfigFile, currentConfigFileBak) == 0);
+ assert(CheckRenameFilePolicy(currentConfigFile, noAccessFile) != 0);
+}
+
+int main()
+{
+ testCheckPolicy();
+ testFilePolicies();
+
+ printf("+++++ passed all tests\n");
+
+ return 0;
+}
memset(buf, 'X', sizeof(buf));
n = Strlcat(buf, "abc", sizeof(buf));
- assert(n == sizeof(buf));
+ assert(n == sizeof(buf) + 3);
assert(memcmp(buf, "XXXXXXXX", 8) == 0);
}
assert(strcmp(buf, "1234567") == 0);
}
+ {
+ char buf[8];
+ size_t n;
+ memset(buf, 'X', sizeof(buf));
+
+ *buf = '\0';
+ n = Strlcat(buf, "1234", 0);
+ assert(n == 4);
+ assert(strlen(buf) == 0);
+ }
+
printf("+++++ passed all tests\n");
return 0;
assert(strcmp(buffer, "1") == 0);
}
+ {
+ char buffer[1024];
+ size_t n;
+ strcpy(buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+
+ n = Strlcpy(buffer, "1234567890", 0);
+ assert(n == 10);
+ assert(strcmp(
+ buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") == 0);
+ }
+
printf("+++++ passed all tests\n");
return 0;
assert(GetUserName(uid, username) == 0);
assert(strcmp(username, "root") == 0);
+ assert(GetUserInfo("xinvaliduserx", &uid, &gid) != 0);
+
+ assert(GetUserName(-1492, username) != 0);
+ assert(strlen(username) == 0);
+
printf("+++++ passed all tests\n");
return 0;
}
_moduleName));
}
- // Set the session key to be used for requests emanating from this read
- // pipe (i.e., the provider agent). Examples include requests made by the
- // provider with the CIMOMHandle or indications delivered by the provider.
-
# if defined(PEGASUS_HAS_SIGNALS)
_pid = pid;
# endif