]> granicus.if.org Git - p11-kit/commitdiff
remote: Run separate executable binary for 'p11-kit remote'
authorStef Walter <stefw@redhat.com>
Wed, 1 Oct 2014 15:34:02 +0000 (17:34 +0200)
committerStef Walter <stefw@redhat.com>
Thu, 2 Oct 2014 09:44:02 +0000 (11:44 +0200)
This allows security frameworks like SELinux or AppArmor to target
it specifically.

Makefile.am
p11-kit/Makefile.am
p11-kit/p11-kit.c
p11-kit/remote.c
p11-kit/rpc-server.c

index 9032154dfb1d049835ec3b0dfd975c24a45e4fc8..ea87f6ab787fde50abeb1e222ff52d79178c535b 100644 (file)
@@ -15,6 +15,7 @@ AM_CPPFLAGS = \
        -DP11_KIT_FUTURE_UNSTABLE_API
 
 bin_PROGRAMS =
+private_PROGRAMS =
 
 CHECK_PROGS =
 
index b4b488668983c3e6c0d89f2fb3d0ddc042041a81..3ef70f93ae75267c0d3e6568cd85b637b4fb2e39 100644 (file)
@@ -20,7 +20,6 @@ MODULE_SRCS = \
        p11-kit/private.h \
        p11-kit/proxy.c p11-kit/proxy.h \
        p11-kit/messages.c \
-       p11-kit/remote.c \
        p11-kit/rpc-transport.c p11-kit/rpc.h \
        p11-kit/rpc-message.c p11-kit/rpc-message.h \
        p11-kit/rpc-client.c p11-kit/rpc-server.c \
@@ -119,6 +118,18 @@ p11_kit_p11_kit_LDADD = \
        $(LTLIBINTL) \
        $(NULL)
 
+private_PROGRAMS += p11-kit-remote
+
+p11_kit_remote_SOURCES = \
+       p11-kit/remote.c \
+       $(NULL)
+
+p11_kit_remote_LDADD = \
+       libp11-tool.la \
+       libp11-common.la \
+       libp11-kit.la \
+       $(NULL)
+
 # Tests ----------------------------------------------------------------
 
 p11_kit_LIBS = \
index f64359ec5161ba5901d15075b472e602cc302c54..a7b921269183b36ef19c9a299f57cb9add5762f2 100644 (file)
@@ -39,7 +39,6 @@
 #include "message.h"
 #include "path.h"
 #include "p11-kit.h"
-#include "remote.h"
 
 #include <assert.h>
 #include <ctype.h>
@@ -61,12 +60,9 @@ int       p11_kit_trust           (int argc,
 int       p11_kit_external        (int argc,
                                    char *argv[]);
 
-int       p11_kit_remote          (int argc,
-                                   char *argv[]);
-
 static const p11_tool_command commands[] = {
        { "list-modules", p11_kit_list_modules, "List modules and tokens" },
-       { "remote", p11_kit_remote, "Run a specific PKCS#11 module remotely" },
+       { "remote", p11_kit_external, "Run a specific PKCS#11 module remotely" },
        { P11_TOOL_FALLBACK, p11_kit_external, NULL },
        { 0, }
 };
@@ -131,69 +127,6 @@ p11_kit_external (int argc,
        return 2;
 }
 
-int
-p11_kit_remote (int argc,
-                char *argv[])
-{
-       CK_FUNCTION_LIST *module;
-       int opt;
-       int ret;
-
-       enum {
-               opt_verbose = 'v',
-               opt_help = 'h',
-       };
-
-       struct option options[] = {
-               { "verbose", no_argument, NULL, opt_verbose },
-               { "help", no_argument, NULL, opt_help },
-               { 0 },
-       };
-
-       p11_tool_desc usages[] = {
-               { 0, "usage: p11-kit remote <module>" },
-               { 0 },
-       };
-
-       while ((opt = p11_tool_getopt (argc, argv, options)) != -1) {
-               switch (opt) {
-               case opt_verbose:
-                       p11_kit_be_loud ();
-                       break;
-               case opt_help:
-               case '?':
-                       p11_tool_usage (usages, options);
-                       return 0;
-               default:
-                       assert_not_reached ();
-                       break;
-               }
-       }
-
-       argc -= optind;
-       argv += optind;
-
-       if (argc != 1) {
-               p11_message ("specify the module to remote");
-               return 2;
-       }
-
-       if (isatty (0)) {
-               p11_message ("the 'remote' tool is not meant to be run from a terminal");
-               return 2;
-       }
-
-       module = p11_kit_module_load (argv[0], 0);
-       if (module == NULL)
-               return 1;
-
-       ret = p11_kit_remote_serve_module (module, 0, 1);
-       p11_kit_module_release (module);
-
-       return ret;
-}
-
-
 int
 main (int argc,
       char *argv[])
index 944e5010bd99dd1ba038279327a8af4d4bbcb72b..77172770e991ef09deb63222a375b40087121134 100644 (file)
 
 #include "config.h"
 
-#include "buffer.h"
 #include "compat.h"
 #include "debug.h"
 #include "message.h"
-#include "rpc.h"
+#include "p11-kit.h"
 #include "remote.h"
-#include "virtual.h"
+#include "tool.h"
 
 #include <assert.h>
 #include <errno.h>
 #include <unistd.h>
 
 int
-p11_kit_remote_serve_module (CK_FUNCTION_LIST *module,
-                             int in_fd,
-                             int out_fd)
+main (int argc,
+      char *argv[])
 {
-       p11_rpc_status status;
-       unsigned char version;
-       p11_virtual virt;
-       p11_buffer options;
-       p11_buffer buffer;
-       size_t state;
-       int ret = 1;
-       int code;
-
-       return_val_if_fail (module != NULL, 1);
-
-       p11_buffer_init (&options, 0);
-       p11_buffer_init (&buffer, 0);
-
-       p11_virtual_init (&virt, &p11_virtual_base, module, NULL);
-
-       switch (read (in_fd, &version, 1)) {
-       case 0:
-               goto out;
-       case 1:
-               if (version != 0) {
-                       p11_message ("unspported version received: %d", (int)version);
-                       goto out;
-               }
-               break;
-       default:
-               p11_message_err (errno, "couldn't read credential byte");
-               goto out;
-       }
-
-       version = 0;
-       switch (write (out_fd, &version, out_fd)) {
-       case 1:
-               break;
-       default:
-               p11_message_err (errno, "couldn't write credential byte");
-               goto out;
-       }
-
-       status = P11_RPC_OK;
-       while (status == P11_RPC_OK) {
-               state = 0;
-               code = 0;
-
-               do {
-                       status = p11_rpc_transport_read (in_fd, &state, &code,
-                                                        &options, &buffer);
-               } while (status == P11_RPC_AGAIN);
-
-               switch (status) {
-               case P11_RPC_OK:
+       CK_FUNCTION_LIST *module;
+       int opt;
+       int ret;
+
+       enum {
+               opt_verbose = 'v',
+               opt_help = 'h',
+       };
+
+       struct option options[] = {
+               { "verbose", no_argument, NULL, opt_verbose },
+               { "help", no_argument, NULL, opt_help },
+               { 0 },
+       };
+
+       p11_tool_desc usages[] = {
+               { 0, "usage: p11-kit remote <module>" },
+               { 0 },
+       };
+
+       while ((opt = p11_tool_getopt (argc, argv, options)) != -1) {
+               switch (opt) {
+               case opt_verbose:
+                       p11_kit_be_loud ();
                        break;
-               case P11_RPC_EOF:
-                       ret = 0;
-                       continue;
-               case P11_RPC_AGAIN:
+               case opt_help:
+               case '?':
+                       p11_tool_usage (usages, options);
+                       return 0;
+               default:
                        assert_not_reached ();
-               case P11_RPC_ERROR:
-                       p11_message_err (errno, "failed to read rpc message");
-                       goto out;
+                       break;
                }
+       }
 
-               if (!p11_rpc_server_handle (&virt.funcs, &buffer, &buffer)) {
-                       p11_message ("unexpected error handling rpc message");
-                       goto out;
-               }
+       argc -= optind;
+       argv += optind;
 
-               state = 0;
-               options.len = 0;
-               do {
-                       status = p11_rpc_transport_write (out_fd, &state, code,
-                                                         &options, &buffer);
-               } while (status == P11_RPC_AGAIN);
+       if (argc != 1) {
+               p11_message ("specify the module to remote");
+               return 2;
+       }
 
-               switch (status) {
-               case P11_RPC_OK:
-                       break;
-               case P11_RPC_EOF:
-               case P11_RPC_AGAIN:
-                       assert_not_reached ();
-               case P11_RPC_ERROR:
-                       p11_message_err (errno, "failed to write rpc message");
-                       goto out;
-               }
+       if (isatty (0)) {
+               p11_message ("the 'remote' tool is not meant to be run from a terminal");
+               return 2;
        }
 
-out:
-       p11_buffer_uninit (&buffer);
-       p11_buffer_uninit (&options);
+       module = p11_kit_module_load (argv[0], 0);
+       if (module == NULL)
+               return 1;
 
-       p11_virtual_uninit (&virt);
+       ret = p11_kit_remote_serve_module (module, 0, 1);
+       p11_kit_module_release (module);
 
        return ret;
 }
index b8288c9733f56a3354821cc7066d4a04ce8c1eb3..a2562e9f0fe791206c37e20ed2c6c14eda7e22f3 100644 (file)
@@ -41,6 +41,7 @@
 #include "library.h"
 #include "private.h"
 #include "message.h"
+#include "remote.h"
 #include "rpc.h"
 #include "rpc-message.h"
 
@@ -1901,3 +1902,103 @@ p11_rpc_server_handle (CK_X_FUNCTION_LIST *self,
        p11_rpc_message_clear (&msg);
        return true;
 }
+
+int
+p11_kit_remote_serve_module (CK_FUNCTION_LIST *module,
+                             int in_fd,
+                             int out_fd)
+{
+       p11_rpc_status status;
+       unsigned char version;
+       p11_virtual virt;
+       p11_buffer options;
+       p11_buffer buffer;
+       size_t state;
+       int ret = 1;
+       int code;
+
+       return_val_if_fail (module != NULL, 1);
+
+       p11_buffer_init (&options, 0);
+       p11_buffer_init (&buffer, 0);
+
+       p11_virtual_init (&virt, &p11_virtual_base, module, NULL);
+
+       switch (read (in_fd, &version, 1)) {
+       case 0:
+               goto out;
+       case 1:
+               if (version != 0) {
+                       p11_message ("unspported version received: %d", (int)version);
+                       goto out;
+               }
+               break;
+       default:
+               p11_message_err (errno, "couldn't read credential byte");
+               goto out;
+       }
+
+       version = 0;
+       switch (write (out_fd, &version, out_fd)) {
+       case 1:
+               break;
+       default:
+               p11_message_err (errno, "couldn't write credential byte");
+               goto out;
+       }
+
+       status = P11_RPC_OK;
+       while (status == P11_RPC_OK) {
+               state = 0;
+               code = 0;
+
+               do {
+                       status = p11_rpc_transport_read (in_fd, &state, &code,
+                                                        &options, &buffer);
+               } while (status == P11_RPC_AGAIN);
+
+               switch (status) {
+               case P11_RPC_OK:
+                       break;
+               case P11_RPC_EOF:
+                       ret = 0;
+                       continue;
+               case P11_RPC_AGAIN:
+                       assert_not_reached ();
+               case P11_RPC_ERROR:
+                       p11_message_err (errno, "failed to read rpc message");
+                       goto out;
+               }
+
+               if (!p11_rpc_server_handle (&virt.funcs, &buffer, &buffer)) {
+                       p11_message ("unexpected error handling rpc message");
+                       goto out;
+               }
+
+               state = 0;
+               options.len = 0;
+               do {
+                       status = p11_rpc_transport_write (out_fd, &state, code,
+                                                         &options, &buffer);
+               } while (status == P11_RPC_AGAIN);
+
+               switch (status) {
+               case P11_RPC_OK:
+                       break;
+               case P11_RPC_EOF:
+               case P11_RPC_AGAIN:
+                       assert_not_reached ();
+               case P11_RPC_ERROR:
+                       p11_message_err (errno, "failed to write rpc message");
+                       goto out;
+               }
+       }
+
+out:
+       p11_buffer_uninit (&buffer);
+       p11_buffer_uninit (&options);
+
+       p11_virtual_uninit (&virt);
+
+       return ret;
+}