[gnome-keyring] [rpc] Use dynamically allocate socket path.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-keyring] [rpc] Use dynamically allocate socket path.
- Date: Sun, 7 Feb 2010 19:00:30 +0000 (UTC)
commit 64f2a16fc07deadf81da15c50fba428004765ccb
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date: Sun Feb 7 19:00:01 2010 +0000
[rpc] Use dynamically allocate socket path.
GNU Hurd doesn't have a max path length. Fixes bug #604493
pkcs11/rpc-layer/gck-rpc-dispatch.c | 23 +++++++++++++++------
pkcs11/rpc-layer/gck-rpc-module.c | 36 ++++++++++++++++++++++++----------
2 files changed, 41 insertions(+), 18 deletions(-)
---
diff --git a/pkcs11/rpc-layer/gck-rpc-dispatch.c b/pkcs11/rpc-layer/gck-rpc-dispatch.c
index 13e1909..73839ff 100644
--- a/pkcs11/rpc-layer/gck-rpc-dispatch.c
+++ b/pkcs11/rpc-layer/gck-rpc-dispatch.c
@@ -2178,7 +2178,7 @@ typedef struct _DispatchState {
static int pkcs11_socket = -1;
/* The unix socket path, that we listen on */
-static char pkcs11_socket_path[MAXPATHLEN] = { 0, };
+static char *pkcs11_socket_path = NULL;
/* A linked list of dispatcher threads */
static DispatchState *pkcs11_dispatchers = NULL;
@@ -2258,9 +2258,11 @@ gck_rpc_layer_uninitialize (void)
pkcs11_socket = -1;
/* Delete our unix socket */
- if(pkcs11_socket_path[0])
+ if(pkcs11_socket_path) {
unlink (pkcs11_socket_path);
- pkcs11_socket_path[0] = 0;
+ free (pkcs11_socket_path);
+ pkcs11_socket_path = NULL;
+ }
/* Stop all of the dispatch threads */
for (ds = pkcs11_dispatchers; ds; ds = next) {
@@ -2295,8 +2297,13 @@ gck_rpc_layer_startup (const char *prefix)
assert (pkcs11_socket == -1);
assert (pkcs11_dispatchers == NULL);
- snprintf (pkcs11_socket_path, sizeof (pkcs11_socket_path),
- "%s/pkcs11", prefix);
+ free (pkcs11_socket_path);
+ pkcs11_socket_path = malloc (strlen (prefix) + strlen ("/pkcs11") + 1);
+ if (pkcs11_socket_path == NULL) {
+ gck_rpc_warn ("couldn't allocate memory");
+ return -1;
+ }
+ sprintf (pkcs11_socket_path, "%s/pkcs11", prefix);
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
@@ -2337,9 +2344,11 @@ gck_rpc_layer_shutdown (void)
pkcs11_socket = -1;
/* Delete our unix socket */
- if(pkcs11_socket_path[0])
+ if(pkcs11_socket_path) {
unlink (pkcs11_socket_path);
- pkcs11_socket_path[0] = 0;
+ free (pkcs11_socket_path);
+ pkcs11_socket_path = NULL;
+ }
/* Stop all of the dispatch threads */
for (ds = pkcs11_dispatchers; ds; ds = next) {
diff --git a/pkcs11/rpc-layer/gck-rpc-module.c b/pkcs11/rpc-layer/gck-rpc-module.c
index 837abe3..ed74a4c 100644
--- a/pkcs11/rpc-layer/gck-rpc-module.c
+++ b/pkcs11/rpc-layer/gck-rpc-module.c
@@ -59,7 +59,7 @@ static int pkcs11_initialized = 0;
static pid_t pkcs11_initialized_pid = 0;
/* The socket to connect to */
-static char pkcs11_socket_path[MAXPATHLEN] = { 0, };
+static char *pkcs11_socket_path = NULL;
/* The error used by us when parsing of rpc message fails */
#define PARSE_ERROR CKR_DEVICE_ERROR
@@ -100,10 +100,12 @@ parse_argument (char *arg)
*(value++) = 0;
/* Setup the socket path from the arguments */
- if (strcmp (arg, "socket") == 0)
- snprintf (pkcs11_socket_path, sizeof (pkcs11_socket_path), "%s", value);
- else
+ if (strcmp (arg, "socket") == 0) {
+ free (pkcs11_socket_path);
+ pkcs11_socket_path = strdup (value);
+ } else {
warning (("unrecognized argument: %s", arg));
+ }
}
static void
@@ -225,7 +227,12 @@ call_connect (CallState *cs)
assert (cs);
assert (cs->socket == -1);
assert (cs->call_status == CALL_INVALID);
-
+
+ if (!pkcs11_socket_path) {
+ warning (("no socket to connect to"));
+ return CKR_DEVICE_REMOVED;
+ }
+
debug (("connecting to: %s", pkcs11_socket_path));
addr.sun_family = AF_UNIX;
@@ -1177,11 +1184,16 @@ rpc_C_Initialize (CK_VOID_PTR init_args)
}
/* Lookup the socket path, append '/pkcs11' */
- if (pkcs11_socket_path[0] == 0) {
- pkcs11_socket_path[0] = 0;
+ if (pkcs11_socket_path == NULL) {
path = getenv ("GNOME_KEYRING_CONTROL");
if (path && path[0]) {
- snprintf (pkcs11_socket_path, sizeof (pkcs11_socket_path), "%s/pkcs11", path);
+ pkcs11_socket_path = malloc (strlen (path) + strlen ("/pkcs11") + 1);
+ if (pkcs11_socket_path == NULL) {
+ warning (("can't malloc memory"));
+ ret = CKR_HOST_MEMORY;
+ goto done;
+ }
+ sprintf (pkcs11_socket_path, "%s/pkcs11", path);
pkcs11_socket_path[sizeof (pkcs11_socket_path) - 1] = 0;
}
}
@@ -1206,7 +1218,8 @@ done:
} else if (ret != CKR_CRYPTOKI_ALREADY_INITIALIZED) {
pkcs11_initialized = 0;
pkcs11_initialized_pid = 0;
- pkcs11_socket_path[0] = 0;
+ free (pkcs11_socket_path);
+ pkcs11_socket_path = NULL;
}
pthread_mutex_unlock (&init_mutex);
@@ -1242,8 +1255,9 @@ rpc_C_Finalize (CK_VOID_PTR reserved)
/* This should stop all other calls in */
pkcs11_initialized = 0;
pkcs11_initialized_pid = 0;
- pkcs11_socket_path[0] = 0;
-
+ free (pkcs11_socket_path);
+ pkcs11_socket_path = NULL;
+
pthread_mutex_unlock (&init_mutex);
debug (("C_Finalize: %d", CKR_OK));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]