summaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-12-09 21:56:50 +0000
committerStef Walter <stef@memberwebs.com>2008-12-09 21:56:50 +0000
commitfb9374be05108422a9662217e727b940ef896bf6 (patch)
tree94d427a86793569de3f589d6770bd8821b820b57 /module
parenta414a5af4b26f039ad7b0a592aca12d2b14b1654 (diff)
Fix copious amounts of debugging messages. Add concept of warning messages.
Diffstat (limited to 'module')
-rw-r--r--module/p11-capi-builtin.c10
-rw-r--r--module/p11-capi-cert.c4
-rw-r--r--module/p11-capi-object.c4
-rw-r--r--module/p11-capi-object.h15
-rw-r--r--module/p11-capi-session.c12
-rw-r--r--module/p11-capi-session.h9
-rw-r--r--module/p11-capi-trust.c2
-rw-r--r--module/p11-capi.c40
-rw-r--r--module/p11-capi.h10
-rw-r--r--module/p11-capi.vcproj36
10 files changed, 90 insertions, 52 deletions
diff --git a/module/p11-capi-builtin.c b/module/p11-capi-builtin.c
index 95fd476..4341f0c 100644
--- a/module/p11-capi-builtin.c
+++ b/module/p11-capi-builtin.c
@@ -58,12 +58,12 @@ typedef struct _BuiltinMatch
BuiltinMatch;
static const BuiltinMatch all_builtins[] = {
- { (CK_ATTRIBUTE_PTR)&builtin_root, P11C_SLOT_TRUSTED | P11C_SLOT_CA | P11C_SLOT_CERTS },
+// { (CK_ATTRIBUTE_PTR)&builtin_root, P11C_SLOT_TRUSTED | P11C_SLOT_CA | P11C_SLOT_CERTS },
{ NULL, 0 }
};
/* This is filled in later */
-static CK_ULONG num_builtins = 0;
+static CK_ULONG num_builtins = CK_END_LIST;
/* --------------------------------------------------------------------------
* IMPLEMENTATION
@@ -131,7 +131,7 @@ builtin_load_data(P11cSession* sess, P11cObject* obj, P11cObjectData** objdata)
ASSERT(bobj);
ASSERT(objdata);
- ASSERT(num_builtins > 0);
+ ASSERT(num_builtins != CK_END_LIST);
bdata = (BuiltinObjectData*)calloc(1, sizeof(BuiltinObjectData));
if(!bdata)
@@ -211,11 +211,11 @@ p11c_builtin_find(P11cSession* sess, CK_OBJECT_CLASS cls, CK_ATTRIBUTE_PTR match
CK_ULONG i, fl;
/* First time around count total number */
- if(!num_builtins)
+ if(num_builtins == CK_END_LIST)
{
+ num_builtins = 0;
while(all_builtins[num_builtins].attr)
++num_builtins;
- ASSERT(num_builtins > 0);
}
/* Match each certificate */
diff --git a/module/p11-capi-cert.c b/module/p11-capi-cert.c
index 53e198f..49cc508 100644
--- a/module/p11-capi-cert.c
+++ b/module/p11-capi-cert.c
@@ -89,7 +89,7 @@ parse_basic_constraints(CertObjectData* cdata, CK_ULONG* category)
{
if(basic->SubjectType.cbData != 1)
{
- DBG(("basic constraints bits are of invalid size"));
+ WARN(("basic constraints bits are of invalid size"));
ret = CKR_GENERAL_ERROR;
}
else
@@ -372,7 +372,7 @@ calculate_check_value(PCCERT_CONTEXT cert, CK_ATTRIBUTE_PTR attr)
if(length < 3)
{
- DBG(("SHA1 hash length too short: %d", length));
+ WARN(("SHA1 hash length too short: %d", length));
return CKR_DEVICE_ERROR;
}
diff --git a/module/p11-capi-object.c b/module/p11-capi-object.c
index 6c2330e..2c37987 100644
--- a/module/p11-capi-object.c
+++ b/module/p11-capi-object.c
@@ -142,7 +142,7 @@ attribute_data_type(CK_ATTRIBUTE_TYPE type)
case CKA_WRAP_TEMPLATE:
case CKA_UNWRAP_TEMPLATE:
default:
- DBG(("unknown attribute type: %x", type));
+ WARN(("unknown attribute type: %x", type));
return DATA_UNKNOWN;
};
}
@@ -269,7 +269,7 @@ p11c_object_data_get_attrs(P11cObjectData* objdata, CK_ATTRIBUTE_PTR attrs,
/* Attribute doesn't exist */
else if(rv == CKR_ATTRIBUTE_TYPE_INVALID)
{
- DBG(("O%d: attribute not found: 0x%08x", objdata->object, attrs[i].type));
+ WARN(("O%d: attribute not found: 0x%08x", objdata->object, attrs[i].type));
attrs[i].ulValueLen = (CK_ULONG)-1;
}
diff --git a/module/p11-capi-object.h b/module/p11-capi-object.h
index e884ee1..c204f17 100644
--- a/module/p11-capi-object.h
+++ b/module/p11-capi-object.h
@@ -22,10 +22,6 @@
#include "p11-capi.h"
-/* Debug print something about an object */
-#define DBGO(obj, msg) \
- p11c_debug("O%d: %s", (obj) ? (obj)->id : 0, (msg))
-
/* A function to load data for an object */
typedef CK_RV (*P11cLoadData)(P11cSession* sess, struct _P11cObject* obj,
P11cObjectData** objdata);
@@ -93,8 +89,13 @@ CK_BBOOL p11c_object_data_match_attr (P11cObjectData* objdata,
CK_RV p11c_object_data_get_attrs (P11cObjectData* objdata, CK_ATTRIBUTE_PTR attrs,
CK_ULONG count);
-/* Debug print something about an object data */
-#define DBGOD(objdata, msg) \
- p11c_debug("O%d: %s", (objdata) ? (objdata)->obj : 0, (msg))
+/* Debug print something about an object or object data */
+#if DBG_OUTPUT
+#define DBGO(obj, msg) p11c_log("O%d: %s", (obj) ? (obj)->id : 0, (msg))
+#define DBGOD(objdata, msg) p11c_log("O%d: %s", (objdata) ? (objdata)->obj : 0, (msg))
+#else
+#define DBGO(obj, msg)
+#define DBGOD(objdata, msg)
+#endif
#endif /* P11C_OBJECT_H */
diff --git a/module/p11-capi-session.c b/module/p11-capi-session.c
index e921875..5b2fc14 100644
--- a/module/p11-capi-session.c
+++ b/module/p11-capi-session.c
@@ -244,7 +244,7 @@ lock_ref_internal(P11cArray* sessions, CK_SESSION_HANDLE id,
if(id >= sessions->len)
{
- DBG(("invalid session id: %d", id));
+ WARN(("invalid session id: %d", id));
return CKR_SESSION_HANDLE_INVALID;
}
@@ -254,7 +254,7 @@ lock_ref_internal(P11cArray* sessions, CK_SESSION_HANDLE id,
if(!sess)
{
- DBG(("session does not exist: %d", id));
+ WARN(("session does not exist: %d", id));
return CKR_SESSION_HANDLE_INVALID;
}
@@ -276,7 +276,7 @@ lock_ref_internal(P11cArray* sessions, CK_SESSION_HANDLE id,
if(sess->in_call)
{
- DBGS(sess, ("an operation is already active in this session"));
+ WARNS(sess, ("an operation is already active in this session"));
return CKR_OPERATION_ACTIVE;
}
}
@@ -289,7 +289,7 @@ lock_ref_internal(P11cArray* sessions, CK_SESSION_HANDLE id,
if(!remove && sess->in_call)
{
ReleaseMutex(sess->mutex);
- DBGS(sess, ("an operation is already active in this session"));
+ WARNS(sess, ("an operation is already active in this session"));
return CKR_OPERATION_ACTIVE;
}
@@ -331,7 +331,7 @@ p11c_session_get_lock_ref(CK_ULONG id, BOOL writable, P11cSession **sess)
if(id <= 0)
{
- DBG(("invalid session id passed: %d", id));
+ WARN(("invalid session id passed: %d", id));
return CKR_ARGUMENTS_BAD;
}
@@ -355,7 +355,7 @@ p11c_session_remove_lock_ref(CK_ULONG id, P11cSession **sess)
if(id <= 0)
{
- DBG(("invalid session id passed: %d", id));
+ WARN(("invalid session id passed: %d", id));
return CKR_ARGUMENTS_BAD;
}
diff --git a/module/p11-capi-session.h b/module/p11-capi-session.h
index 8f84026..cb02ee5 100644
--- a/module/p11-capi-session.h
+++ b/module/p11-capi-session.h
@@ -69,8 +69,13 @@ typedef struct _P11cSession
P11cSession;
/* Debug print something related to a session */
-#define DBGS(sess, msg) \
- p11c_debug("S%d: %s", (sess) ? (sess)->id : 0, (msg))
+#if DBG_OUTPUT
+#define DBGS(sess, msg) p11c_log("S%d: %s", (sess) ? (sess)->id : 0, (msg))
+#else
+#define DBGS(sess, msg)
+#endif
+
+#define WARNS(sess, msg) p11c_log("S%d: %s", (sess) ? (sess)->id : 0, (msg))
/* Create a session */
CK_RV p11c_session_create (CK_SLOT_ID slot, P11cSession** ret);
diff --git a/module/p11-capi-trust.c b/module/p11-capi-trust.c
index e45106a..08e5ac6 100644
--- a/module/p11-capi-trust.c
+++ b/module/p11-capi-trust.c
@@ -365,7 +365,7 @@ parse_restrictions(TrustObjectData* tdata)
if(rst->cbData != 1 &&
rst->cUnusedBits != 0)
{
- DBG(("key usage are of invalid size"));
+ WARN(("key usage are of invalid size"));
}
else
{
diff --git a/module/p11-capi.c b/module/p11-capi.c
index b5f7f62..8f15cf5 100644
--- a/module/p11-capi.c
+++ b/module/p11-capi.c
@@ -37,8 +37,8 @@
static int cryptoki_initialized = 0;
static HANDLE global_mutex = NULL;
-#define MANUFACTURER_ID "Cryptoki CAPI "
-#define LIBRARY_DESCRIPTION "Cryptoki CAPI Provider "
+#define MANUFACTURER_ID "p11-capi "
+#define LIBRARY_DESCRIPTION "PKCS#11 CAPI Provider "
#define LIBRARY_VERSION_MAJOR 1
#define LIBRARY_VERSION_MINOR 1
#define HARDWARE_VERSION_MAJOR 0
@@ -61,7 +61,7 @@ static CK_MECHANISM_TYPE all_mechanisms[] = {
#define LINE 1024
void
-p11c_debug(const char* msg, ...)
+p11c_log(const char* msg, ...)
{
char buf[LINE];
va_list va;
@@ -76,10 +76,12 @@ p11c_debug(const char* msg, ...)
strncpy(buf + len, "\n", 1024 - len);
buf[LINE - 1] = 0;
- // OutputDebugStringA(buf);
+ OutputDebugStringA(buf);
}
/* Bah humbug, MSVC doesn't have __func__ */
+#if DBG_OUTPUT
+
#define ENTER(func) \
char* _func = #func; \
p11c_debug("%s: enter", _func)
@@ -87,8 +89,26 @@ p11c_debug(const char* msg, ...)
#define RETURN(ret) \
return (p11c_debug("%s: %d", _func, ret), ret)
+#else /* !DBG_OUTPUT */
+
+#define ENTER(func) \
+ char* _func = #func;
+
+#define RETURN(ret) \
+ return log_return(_func, ret)
+
+static CK_RV
+log_return(char *func, CK_RV ret)
+{
+ if(ret != CKR_OK)
+ p11c_log("%s: %d", func, ret);
+ return ret;
+}
+
+#endif /* !DBG_OUTPUT */
+
#define PREREQ(cond, ret) \
- if (!(cond)) { p11c_debug("%s: %s failed: %d", _func, #cond, ret); return ret; }
+ if (!(cond)) { p11c_log("%s: %s failed: %d", _func, #cond, ret); return ret; }
void
p11c_lock_global(void)
@@ -325,7 +345,7 @@ p11c_return_filetime(CK_ATTRIBUTE_PTR attr, FILETIME *ftime)
if(!FileTimeToSystemTime(ftime, &stime))
{
- DBG(("An invalid FILETIME was encountered"));
+ WARN(("An invalid FILETIME was encountered"));
return CKR_GENERAL_ERROR;
}
@@ -377,7 +397,7 @@ PC_C_Initialize(CK_VOID_PTR init_args)
}
cryptoki_initialized = 1;
-
+ p11c_log("initialized p11-capi module");
RETURN(CKR_OK);
}
@@ -393,6 +413,7 @@ PC_C_Finalize(CK_VOID_PTR pReserved)
p11c_session_cleanup_all();
p11c_token_cleanup_all();
+ p11c_log("finalized p11-capi module");
RETURN(CKR_OK);
}
@@ -893,6 +914,11 @@ PC_C_GetAttributeValue(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object,
p11c_session_unref_unlock(sess);
}
+ if(ret == CKR_OBJECT_HANDLE_INVALID)
+ {
+ WARN(("object handle invalid"));
+ }
+
RETURN(ret);
}
diff --git a/module/p11-capi.h b/module/p11-capi.h
index e522bfa..d672b69 100644
--- a/module/p11-capi.h
+++ b/module/p11-capi.h
@@ -66,9 +66,15 @@ typedef struct _P11cSession P11cSession;
* Module helper and logging functions.
*/
-#define DBG(args) p11c_debug args
+#if DBG_OUTPUT
+#define DBG(args) p11c_log args
+#else
+#define DBG(args)
+#endif
+
+#define WARN(args) p11c_log args
-void p11c_debug (const char* msg, ...);
+void p11c_log (const char* msg, ...);
/*
* Protect global data with these.
diff --git a/module/p11-capi.vcproj b/module/p11-capi.vcproj
index 7c554d1..288a8ed 100644
--- a/module/p11-capi.vcproj
+++ b/module/p11-capi.vcproj
@@ -16,8 +16,8 @@
<Configurations>
<Configuration
Name="Debug|Win32"
- OutputDirectory=".\Debug"
- IntermediateDirectory=".\Debug"
+ OutputDirectory="..\Debug"
+ IntermediateDirectory="..\Debug"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@@ -52,10 +52,10 @@
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
- PrecompiledHeaderFile=".\Debug/p11-capi.pch"
- AssemblerListingLocation=".\Debug/"
- ObjectFile=".\Debug/"
- ProgramDataBaseFileName=".\Debug/"
+ PrecompiledHeaderFile="..\Debug/p11-capi.pch"
+ AssemblerListingLocation="..\Debug/"
+ ObjectFile="..\Debug/"
+ ProgramDataBaseFileName="..\Debug/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
@@ -74,12 +74,12 @@
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib crypt32.lib advapi32.lib"
- OutputFile=".\Debug/p11-capi.dll"
+ OutputFile="..\Debug/p11-capi.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
GenerateDebugInformation="true"
- ProgramDatabaseFile=".\Debug/p11-capi.pdb"
- ImportLibrary=".\Debug/p11-capi.lib"
+ ProgramDatabaseFile="..\Debug/p11-capi.pdb"
+ ImportLibrary="..\Debug/p11-capi.lib"
TargetMachine="1"
/>
<Tool
@@ -111,8 +111,8 @@
</Configuration>
<Configuration
Name="Release|Win32"
- OutputDirectory=".\Release"
- IntermediateDirectory=".\Release"
+ OutputDirectory="..\Release"
+ IntermediateDirectory="..\Release"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@@ -148,10 +148,10 @@
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile=".\Release/p11-capi.pch"
- AssemblerListingLocation=".\Release/"
- ObjectFile=".\Release/"
- ProgramDataBaseFileName=".\Release/"
+ PrecompiledHeaderFile="..\Release/p11-capi.pch"
+ AssemblerListingLocation="..\Release/"
+ ObjectFile="..\Release/"
+ ProgramDataBaseFileName="..\Release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
@@ -169,11 +169,11 @@
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib crypt32.lib"
- OutputFile=".\Release/p11-capi.dll"
+ OutputFile="..\Release/p11-capi.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
- ProgramDatabaseFile=".\Release/p11-capi.pdb"
- ImportLibrary=".\Release/p11-capi.lib"
+ ProgramDatabaseFile="..\Release/p11-capi.pdb"
+ ImportLibrary="..\Release/p11-capi.lib"
TargetMachine="1"
/>
<Tool