Attached is a patch that makes the persistent storage code correct
for both big-endian and little-endian builds.
-Signed off by Wyllys Ingersoll
--- configure.in.orig Thu Jan 28 13:56:20 2010
+++ configure.in Wed Mar 3 16:40:12 2010
@@ -14,10 +14,9 @@
AM_INIT_AUTOMAKE([foreign 1.6])
# Debugging support
-AC_ARG_ENABLE(debug,
- AC_HELP_STRING([--enable-debug], [turn on all trousers
debugging flags [default is off]]),
- [enable_debug="yes"
- AC_MSG_RESULT([*** Enabling debugging at user request ***])],)
+AC_ARG_ENABLE([debug],
+ [AC_HELP_STRING([--enable-debug], [turn on all trousers debugging flags
[default=off]])],
+ AC_MSG_RESULT([*** Enabling debugging at user request ***]),)
# If the user has not set CFLAGS, do something appropriate
test_CFLAGS=${CFLAGS+set}
@@ -39,6 +38,9 @@
*ppc64* | *powerpc64* | *x86_64*)
CFLAGS="$CFLAGS -m64"
;;
+ *solaris*)
+ CFLAGS="$CFLAGS -DSOLARIS"
+ ;;
*)
;;
esac
@@ -347,7 +349,16 @@
AC_PROG_CC
AC_PROG_LIBTOOL
-CFLAGS="$CFLAGS -W -Wall -Werror -Wno-unused-parameter -Wsign-compare \
+AC_C_BIGENDIAN([AC_DEFINE(_BIG_ENDIAN, 1, [big-endian host])])
+AC_CHECK_HEADER(endian.h, [AC_DEFINE(HAVE_ENDIAN_H, 1, [endian.h header])])
+AC_CHECK_HEADER(sys/byteorder.h, [AC_DEFINE(HAVE_BYTEORDER_H, 1,
[sys/byteorder.h header])])
+AC_CHECK_FUNC(daemon, [ AC_DEFINE(HAVE_DAEMON, 1, [daemon function is
available]) ])
+
+if test "x${GCC}" = "xyes"; then
+ CFLAGS="$CFLAGS -W -Wall -Werror -Wno-unused-parameter -Wsign-compare"
+fi
+
+CFLAGS="$CFLAGS -I../include \
-DTCSD_DEFAULT_PORT=${TCSD_DEFAULT_PORT}
-DTSS_VER_MAJOR=${TSS_VER_MAJOR} \
-DTSS_VER_MINOR=${TSS_VER_MINOR} -DTSS_SPEC_MAJOR=${TSS_SPEC_MAJOR} \
-DTSS_SPEC_MINOR=${TSS_SPEC_MINOR}"
--- src/tcs/ps/ps_utils.c.orig Tue Sep 8 07:39:30 2009
+++ src/tcs/ps/ps_utils.c Mon Feb 1 06:18:11 2010
@@ -1,4 +1,3 @@
-
/*
* Licensed Materials - Property of IBM
*
@@ -14,6 +13,18 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#if defined(HAVE_BYTEORDER_H)
+#include <sys/byteorder.h>
+#elif defined(HAVE_ENDIAN_H)
+#include <endian.h>
+#define LE_16 htole16
+#define LE_32 htole32
+#define LE_64 htole64
+#else
+#define LE_16(x) (x)
+#define LE_32(x) (x)
+#define LE_64(x) (x)
+#endif
#include <fcntl.h>
#include <string.h>
#include <limits.h>
@@ -133,6 +144,7 @@
/* read the number of keys */
rc = read(fd, &num_keys, sizeof(UINT32));
+ num_keys = LE_32(num_keys);
if (rc == -1) {
LogError("read of %zd bytes: %s", sizeof(UINT32),
strerror(errno));
return -1;
@@ -160,6 +172,7 @@
return -1;
}
+ num_keys = LE_32(num_keys);
if ((rc = write_data(fd, &num_keys, sizeof(UINT32)))) {
LogError("%s", __FUNCTION__);
return rc;
@@ -187,7 +200,7 @@
LogError("lseek: %s", strerror(errno));
return -1;
}
-
+ num_keys = LE_32(num_keys);
if ((rc = write_data(fd, &num_keys, sizeof(UINT32)))) {
LogError("%s", __FUNCTION__);
return rc;
@@ -274,6 +287,7 @@
} else if ((unsigned)rc < sizeof(UINT32)) {
num_keys = 0;
}
+ num_keys = LE_32(num_keys);
return num_keys;
}
@@ -403,6 +417,7 @@
LogError("%s", __FUNCTION__);
goto err_exit;
}
+ tmp->pub_data_size = LE_16(tmp->pub_data_size);
DBG_ASSERT(tmp->pub_data_size <= 2048 && tmp->pub_data_size >
0);
@@ -411,7 +426,7 @@
LogError("%s", __FUNCTION__);
goto err_exit;
}
-
+ tmp->blob_size = LE_16(tmp->blob_size);
DBG_ASSERT(tmp->blob_size <= 4096 && tmp->blob_size > 0);
/* vendor data size */
@@ -419,6 +434,7 @@
LogError("%s", __FUNCTION__);
goto err_exit;
}
+ tmp->vendor_data_size = LE_32(tmp->vendor_data_size);
/* cache flags */
if ((rc = read_data(fd, &tmp->flags, sizeof(UINT16)))) {
@@ -425,6 +441,7 @@
LogError("%s", __FUNCTION__);
goto err_exit;
}
+ tmp->flags = LE_16(tmp->flags);
#ifdef TSS_DEBUG
if (tmp->flags & CACHE_FLAG_VALID)
--- src/tcs/ps/tcsps.c.orig Thu Oct 29 06:44:36 2009
+++ src/tcs/ps/tcsps.c Mon Feb 1 06:18:15 2010
@@ -17,6 +17,18 @@
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
+#if defined (HAVE_BYTEORDER_H)
+#include <sys/byteorder.h>
+#elif defined (HAVE_ENDIAN_H)
+#include <endian.h>
+#define LE_16 htole16
+#define LE_32 htole32
+#define LE_64 htole64
+#else
+#define LE_16(x) (x)
+#define LE_32(x) (x)
+#define LE_64(x) (x)
+#endif
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
@@ -603,28 +615,40 @@
}
/* [UINT16 pub_data_size0 ] yes */
+ pub_key_size = LE_16(pub_key_size);
if ((rc = write_data(fd, &pub_key_size, sizeof(UINT16)))) {
LogError("%s", __FUNCTION__);
goto done;
}
+ /* Swap it back for later */
+ pub_key_size = LE_16(pub_key_size);
/* [UINT16 blob_size0 ] yes */
+ key_blob_size = LE_16(key_blob_size);
if ((rc = write_data(fd, &key_blob_size, sizeof(UINT16)))) {
LogError("%s", __FUNCTION__);
goto done;
}
+ /* Swap it back for later */
+ key_blob_size = LE_16(key_blob_size);
/* [UINT32 vendor_data_size0 ] yes */
+ vendor_size = LE_32(vendor_size);
if ((rc = write_data(fd, &vendor_size, sizeof(UINT32)))) {
LogError("%s", __FUNCTION__);
goto done;
}
+ /* Swap it back for later */
+ vendor_size = LE_32(vendor_size);
/* [UINT16 cache_flags0 ] yes */
+ cache_flags = LE_16(cache_flags);
if ((rc = write_data(fd, &cache_flags, sizeof(UINT16)))) {
LogError("%s", __FUNCTION__);
goto done;
}
+ /* Swap it back for later */
+ cache_flags = LE_16(cache_flags);
/* [BYTE[] pub_data0 ] no */
if ((rc = write_data(fd, (void *)key.pubKey.key, pub_key_size))) {
@@ -746,6 +770,7 @@
}
rc = read(fd, &num_keys, sizeof(UINT32));
+ num_keys = LE_32(num_keys);
if (rc != sizeof(UINT32)) {
LogError("read of %zd bytes: %s", sizeof(UINT32),
strerror(errno));
return TCSERR(TSS_E_INTERNAL_ERROR);
@@ -760,6 +785,7 @@
/* decrement, then write back out to disk */
num_keys--;
+ num_keys = LE_32(num_keys);
if ((result = write_data(fd, (void *)&num_keys, sizeof(UINT32)))) {
LogError("%s", __FUNCTION__);
return result;
--- src/tspi/tsp_policy.c.orig Mon Feb 1 05:47:31 2010
+++ src/tspi/tsp_policy.c Mon Feb 1 05:48:14 2010
@@ -26,6 +26,10 @@
#include "tsplog.h"
#include "obj.h"
+#define PGSIZE sysconf(_SC_PAGESIZE)
+#define PGOFFSET (PGSIZE - 1)
+#define PGMASK (~PGOFFSET)
+
/*
* popup_GetSecret()
*
@@ -43,7 +47,7 @@
{
BYTE secret[UI_MAX_SECRET_STRING_LENGTH] = { 0 };
BYTE *dflt = (BYTE *)"TSS Authentication Dialog";
- UINT32 secret_len;
+ UINT32 secret_len = 0;
TSS_RESULT result;
if (popup_str == NULL)
@@ -88,6 +92,8 @@
return 0;
}
+ len += (uintptr_t)addr & PGOFFSET;
+ addr = (void *)((uintptr_t)addr & PGMASK);
if (mlock(addr, len) == -1) {
LogError("mlock: %s", strerror(errno));
return 1;
@@ -105,6 +111,8 @@
return 0;
}
+ len += (uintptr_t)addr & PGOFFSET;
+ addr = (void *)((uintptr_t)addr & PGMASK);
if (munlock(addr, len) == -1) {
LogError("mlock: %s", strerror(errno));
return 1;
--- src/tspi/ps/tspps.c.orig Fri Jan 29 11:54:49 2010
+++ src/tspi/ps/tspps.c Fri Jan 29 11:54:15 2010
@@ -19,6 +19,21 @@
#include <sys/file.h>
#include <sys/stat.h>
#include <assert.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <netdb.h>
+#if defined (HAVE_BYTEORDER_H)
+#include <sys/byteorder.h>
+#elif defined(HAVE_ENDIAN_H)
+#include <endian.h>
+#define LE_16 htole16
+#define LE_32 htole32
+#define LE_64 htole64
+#else
+#define LE_16(x) (x)
+#define LE_32(x) (x)
+#define LE_64(x) (x)
+#endif
#include "trousers/tss.h"
#include "trousers/trousers.h"
@@ -33,6 +48,17 @@
#if (defined (__FreeBSD__) || defined (__OpenBSD__))
static MUTEX_DECLARE_INIT(user_ps_path);
#endif
+#if defined (SOLARIS)
+static struct flock fl = {
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ {0, 0, 0, 0}
+};
+#endif
/*
@@ -62,6 +88,16 @@
euid = geteuid();
+#if defined (SOLARIS)
+ /*
+ * Solaris keeps user PS in a local directory instead of
+ * in the user's home directory, which may be shared
+ * by multiple systems.
+ *
+ * The directory path on Solaris is /var/tpm/userps/[EUID]/
+ */
+ rc = snprintf(buf, sizeof (buf), "%s/%d", TSS_USER_PS_DIR, euid);
+#else
setpwent();
while (1) {
#if (defined (__linux) || defined (linux))
@@ -93,8 +129,9 @@
return TSPERR(TSS_E_OUTOFMEMORY);
/* Tack on TSS_USER_PS_DIR and see if it exists */
- rc = snprintf(buf, PASSWD_BUFSIZE, "%s/%s", home_dir, TSS_USER_PS_DIR);
- if (rc == PASSWD_BUFSIZE) {
+ rc = snprintf(buf, sizeof (buf), "%s/%s", home_dir, TSS_USER_PS_DIR);
+#endif /* SOLARIS */
+ if (rc == sizeof (buf)) {
LogDebugFn("USER PS: Path to file too long! (> %d bytes)",
PASSWD_BUFSIZE);
result = TSPERR(TSS_E_INTERNAL_ERROR);
goto done;
@@ -104,7 +141,7 @@
if ((rc = stat(buf, &stat_buf)) == -1) {
if (errno == ENOENT) {
errno = 0;
- /* Create the base directory, $HOME/.trousers */
+ /* Create the user's ps directory if it is not there. */
if ((rc = mkdir(buf, 0700)) == -1) {
LogDebugFn("USER PS: Error creating dir: %s:
%s", buf,
strerror(errno));
@@ -119,10 +156,15 @@
}
/* Directory exists or has been created, return the path to the file */
- rc = snprintf(buf, PASSWD_BUFSIZE, "%s/%s/%s", home_dir,
TSS_USER_PS_DIR,
+#if defined (SOLARIS)
+ rc = snprintf(buf, sizeof (buf), "%s/%d/%s", TSS_USER_PS_DIR, euid,
TSS_USER_PS_FILE);
- if (rc == PASSWD_BUFSIZE) {
- LogDebugFn("USER PS: Path to file too long! (> %d bytes)",
PASSWD_BUFSIZE);
+#else
+ rc = snprintf(buf, sizeof (buf), "%s/%s/%s", home_dir, TSS_USER_PS_DIR,
+ TSS_USER_PS_FILE);
+#endif
+ if (rc == sizeof (buf)) {
+ LogDebugFn("USER PS: Path to file too long! (> %d bytes)",
sizeof (buf));
} else
*file = strdup(buf);
@@ -143,12 +185,16 @@
/* check the global file handle first. If it exists, lock it and
return */
if (user_ps_fd != -1) {
+#if defined (SOLARIS)
+ fl.l_type = F_WRLCK;
+ if ((rc = fcntl(user_ps_fd, F_SETLKW, &fl))) {
+#else
if ((rc = flock(user_ps_fd, LOCK_EX))) {
+#endif /* SOLARIS */
LogDebug("USER PS: failed to lock file: %s",
strerror(errno));
MUTEX_UNLOCK(user_ps_lock);
return TSPERR(TSS_E_INTERNAL_ERROR);
}
-
*fd = user_ps_fd;
return TSS_SUCCESS;
}
@@ -167,8 +213,12 @@
MUTEX_UNLOCK(user_ps_lock);
return TSPERR(TSS_E_INTERNAL_ERROR);
}
-
+#if defined (SOLARIS)
+ fl.l_type = F_WRLCK;
+ if ((rc = fcntl(user_ps_fd, F_SETLKW, &fl))) {
+#else
if ((rc = flock(user_ps_fd, LOCK_EX))) {
+#endif /* SOLARIS */
LogDebug("USER PS: failed to get lock of %s: %s", file_name,
strerror(errno));
free(file_name);
close(user_ps_fd);
@@ -190,7 +240,12 @@
fsync(fd);
/* release the file lock */
+#if defined (SOLARIS)
+ fl.l_type = F_UNLCK;
+ if ((rc = fcntl(fd, F_SETLKW, &fl))) {
+#else
if ((rc = flock(fd, LOCK_UN))) {
+#endif /* SOLARIS */
LogDebug("USER PS: failed to unlock file: %s", strerror(errno));
rc = -1;
}
@@ -365,6 +420,7 @@
LogDebug("read of %zd bytes: %s", sizeof(UINT32),
strerror(errno));
return TSPERR(TSS_E_INTERNAL_ERROR);
}
+ num_keys = LE_32(num_keys);
if (increment)
num_keys++;
@@ -377,6 +433,7 @@
return TSPERR(TSS_E_INTERNAL_ERROR);
}
+ num_keys = LE_32(num_keys);
if ((result = write_data(fd, (void *)&num_keys, sizeof(UINT32)))) {
LogDebug("%s", __FUNCTION__);
return result;
@@ -498,16 +555,20 @@
}
/* [UINT16 pub_data_size0 ] yes */
+ pub_key_size = LE_16(pub_key_size);
if ((result = write_data(fd, &pub_key_size, sizeof(UINT16)))) {
LogDebug("%s", __FUNCTION__);
goto done;
}
+ pub_key_size = LE_16(pub_key_size);
/* [UINT16 blob_size0 ] yes */
+ key_blob_size = LE_16(key_blob_size);
if ((result = write_data(fd, &key_blob_size, sizeof(UINT16)))) {
LogDebug("%s", __FUNCTION__);
goto done;
}
+ key_blob_size = LE_16(key_blob_size);
/* [UINT32 vendor_data_size0 ] yes */
if ((result = write_data(fd, &zero, sizeof(UINT32)))) {
@@ -516,10 +577,12 @@
}
/* [UINT16 cache_flags0 ] yes */
+ cache_flags = LE_16(cache_flags);
if ((result = write_data(fd, &cache_flags, sizeof(UINT16)))) {
LogDebug("%s", __FUNCTION__);
goto done;
}
+ cache_flags = LE_16(cache_flags);
/* [BYTE[] pub_data0 ] no */
if ((result = write_data(fd, (void *)key.pubKey.key, pub_key_size))) {
@@ -685,6 +748,7 @@
LogDebug("%s", __FUNCTION__);
goto err_exit;
}
+ tmp[i].pub_data_size = LE_16(tmp[i].pub_data_size);
DBG_ASSERT(tmp[i].pub_data_size <= 2048);
@@ -693,6 +757,7 @@
LogDebug("%s", __FUNCTION__);
goto err_exit;
}
+ tmp[i].blob_size = LE_16(tmp[i].blob_size);
DBG_ASSERT(tmp[i].blob_size <= 4096);
@@ -701,6 +766,7 @@
LogDebug("%s", __FUNCTION__);
goto err_exit;
}
+ tmp[i].vendor_data_size = LE_32(tmp[i].vendor_data_size);
/* cache flags */
if ((result = read_data(fd, &tmp[i].flags, sizeof(UINT16)))) {
@@ -707,6 +773,7 @@
LogDebug("%s", __FUNCTION__);
goto err_exit;
}
+ tmp[i].flags = LE_16(tmp[i].flags);
/* fast forward over the pub key */
offset = lseek(fd, tmp[i].pub_data_size, SEEK_CUR);
@@ -1031,6 +1098,8 @@
num_keys = 0;
}
+ /* The system PS file is written in little-endian */
+ num_keys = LE_32(num_keys);
return num_keys;
}
@@ -1109,7 +1178,7 @@
LogDebug("%s", __FUNCTION__);
return result;
}
-
+ c->pub_data_size = LE_16(c->pub_data_size);
DBG_ASSERT(c->pub_data_size <= 2048 && c->pub_data_size > 0);
/* blob size */
@@ -1117,7 +1186,7 @@
LogDebug("%s", __FUNCTION__);
return result;
}
-
+ c->blob_size = LE_16(c->blob_size);
DBG_ASSERT(c->blob_size <= 4096 && c->blob_size > 0);
/* vendor data size */
@@ -1125,6 +1194,7 @@
LogDebug("%s", __FUNCTION__);
return result;
}
+ c->vendor_data_size = LE_32(c->vendor_data_size);
/* cache flags */
if ((result = read_data(fd, &c->flags, sizeof(UINT16)))) {
@@ -1131,6 +1201,7 @@
LogDebug("%s", __FUNCTION__);
return result;
}
+ c->flags = LE_16(c->flags);
/* fast forward over the pub key */
offset = lseek(fd, c->pub_data_size, SEEK_CUR);
@@ -1198,6 +1269,7 @@
return result;
}
+ c->pub_data_size = LE_16(c->pub_data_size);
DBG_ASSERT(c->pub_data_size <= 2048 && c->pub_data_size > 0);
/* blob size */
@@ -1206,6 +1278,7 @@
return result;
}
+ c->blob_size = LE_16(c->blob_size);
DBG_ASSERT(c->blob_size <= 4096 && c->blob_size > 0);
/* vendor data size */
@@ -1213,6 +1286,7 @@
LogDebug("%s", __FUNCTION__);
return result;
}
+ c->vendor_data_size = LE_32(c->vendor_data_size);
/* cache flags */
if ((result = read_data(fd, &c->flags, sizeof(UINT16)))) {
@@ -1219,6 +1293,7 @@
LogDebug("%s", __FUNCTION__);
return result;
}
+ c->flags = LE_16(c->flags);
if (c->pub_data_size == pub_size) {
/* read in the pub key */
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
TrouSerS-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/trousers-tech