Kludge to test the --supervised feature
Werner Koch
wk at gnupg.org
Wed Oct 5 09:26:13 CEST 2016
Hi,
find below the kludge I use to briefly test the --supervised mode of
gpg-agent w/o resorting to installingsystemd or writing dedicated test
tool.
LISTEN_PID=$$ LISTEN_FDNAMES=ssh:browser:extra:foo \
GNUPGHOME=$(pwd) gpg-agent --supervised -v
Then use
gpg-connect-agent -S /tmp/foo-bar
to connect to the agent.
Salam-Shalom,
Werner
========
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index dcc9bb6..58329c3 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -958,6 +958,66 @@ initialize_modules (void)
}
+
+static int
+set_sockaddr_un (const char *fname, struct sockaddr *addr)
+{
+ struct sockaddr_un *unaddr = (struct sockaddr_un *)addr;
+ struct stat statbuf;
+
+ if (strlen (fname)+1 >= sizeof unaddr->sun_path)
+ {
+ gpg_err_set_errno (ENAMETOOLONG);
+ return -1;
+ }
+
+ memset (unaddr, 0, sizeof *unaddr);
+ unaddr->sun_family = AF_LOCAL;
+ strncpy (unaddr->sun_path, fname, sizeof unaddr->sun_path - 1);
+ unaddr->sun_path[sizeof unaddr->sun_path - 1] = 0;
+
+ return 0;
+}
+
+
+static void
+create_dummy_socket (const char *name)
+{
+ int x;
+ struct sockaddr *addr;
+ struct sockaddr_un *unaddr;
+ socklen_t len;
+
+ unaddr = malloc (sizeof *unaddr);
+ if (!unaddr)
+ abort ();
+ addr = (struct sockaddr*)unaddr;
+
+ x = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (x == -1)
+ {
+ fprintf (stderr, "can't create socket: %s\n", strerror (errno));
+ abort ();
+ }
+ set_sockaddr_un (name, addr);
+ fprintf (stderr,"created socket with fd %d\n", x);
+ len = SUN_LEN (unaddr);
+ if (bind (x, addr, len) == -1)
+ {
+ fprintf (stderr, "error binding socket: %s\n", strerror (errno));
+ abort ();
+ }
+
+ if (listen (x, 5) == -1)
+ {
+ fprintf (stderr, "listen() failed: %s\n", strerror (errno));
+ abort ();
+ }
+
+ free (unaddr);
+}
+
+
/* The main entry point. */
int
main (int argc, char **argv )
@@ -981,6 +1041,12 @@ main (int argc, char **argv )
gpg_error_t err;
struct assuan_malloc_hooks malloc_hooks;
+ create_dummy_socket ("/tmp/wk1-dummy-1");
+ create_dummy_socket ("/tmp/wk1-dummy-2");
+ create_dummy_socket ("/tmp/wk1-dummy-3");
+ create_dummy_socket ("/tmp/wk1-dummy-4");
+
+
early_system_init ();
/* Before we do anything else we save the list of currently open
--
Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 162 bytes
Desc: not available
URL: </pipermail/attachments/20161005/752df636/attachment.sig>
More information about the Gnupg-devel
mailing list