summaryrefslogtreecommitdiffstats
path: root/main.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'main.cxx')
-rw-r--r--main.cxx55
1 files changed, 55 insertions, 0 deletions
diff --git a/main.cxx b/main.cxx
index cdcae41a..d6c03c2f 100644
--- a/main.cxx
+++ b/main.cxx
@@ -368,6 +368,7 @@ main (int argc, char * const argv [])
s.output_file = ""; // -o FILE
s.keep_tmpdir = false;
s.cmd = "";
+ s.cert_db_path = "";
s.target_pid = 0;
s.merge=true;
s.perfmon=0;
@@ -438,6 +439,7 @@ main (int argc, char * const argv [])
#define LONG_OPT_IGNORE_DWARF 4
#define LONG_OPT_VERBOSE_PASS 5
#define LONG_OPT_SKIP_BADVARS 6
+#define LONG_OPT_SIGN_MODULE 7
// NB: also see find_hash(), usage(), switch stmt below, stap.1 man page
static struct option long_options[] = {
{ "kelf", 0, &long_opt, LONG_OPT_KELF },
@@ -446,6 +448,7 @@ main (int argc, char * const argv [])
{ "ignore-dwarf", 0, &long_opt, LONG_OPT_IGNORE_DWARF },
{ "skip-badvars", 0, &long_opt, LONG_OPT_SKIP_BADVARS },
{ "vp", 1, &long_opt, LONG_OPT_VERBOSE_PASS },
+ { "sign-module", 2, &long_opt, LONG_OPT_SIGN_MODULE },
{ NULL, 0, NULL, 0 }
};
int grc = getopt_long (argc, argv, "hVMvtp:I:e:o:R:r:m:kgPc:x:D:bs:uqwl:d:L:FS:",
@@ -713,6 +716,42 @@ main (int argc, char * const argv [])
case LONG_OPT_SKIP_BADVARS:
s.skip_badvars = true;
break;
+ case LONG_OPT_SIGN_MODULE:
+ if (!s.cert_db_path.empty())
+ {
+ cerr << "You can't specify multiple --sign-module options." << endl;
+ usage(s, 1);
+ }
+#if HAVE_NSS
+ if (optarg)
+ {
+ s.cert_db_path = optarg;
+ string::size_type len = s.cert_db_path.length();
+
+ // Make sure the name is not empty (i.e. --sign-module= )
+ if (len == 0)
+ {
+ cerr << "Certificate database directory name can not be empty." << endl;
+ usage (s, 1);
+ }
+
+ // Chop off any trailing '/'.
+ if (len > 1 && s.cert_db_path.substr(len - 1, 1) == "/")
+ s.cert_db_path.erase(len - 1);
+ }
+ else
+ {
+ /* If we're root, use the database in SYSCONFDIR, otherwise
+ use the one in our $HOME directory. */
+ if (getuid() == 0)
+ s.cert_db_path = SYSCONFDIR "/systemtap/ssl/server";
+ else
+ s.cert_db_path = getenv("HOME") + string ("/.systemtap/ssl/server");
+ }
+#else
+ cerr << "WARNING: Module signing is disabled. The required nss libraries are not available." << endl;
+#endif
+ break;
default:
cerr << "Internal error parsing command arguments." << endl;
usage(s, 1);
@@ -1129,6 +1168,22 @@ main (int argc, char * const argv [])
if (copy_file(module_src_path.c_str(), module_dest_path.c_str()) != 0)
cerr << "Copy failed (\"" << module_src_path << "\" to \""
<< module_dest_path << "\"): " << strerror(errno) << endl;
+
+#if HAVE_NSS
+ // Save the signature as well, if the module was signed.
+ if (!s.cert_db_path.empty())
+ {
+ module_src_path += ".sgn";
+ module_dest_path += ".sgn";
+
+ if (s.verbose > 1)
+ clog << "Copying " << module_src_path << " to "
+ << module_dest_path << endl;
+ if (copy_file(module_src_path.c_str(), module_dest_path.c_str()) != 0)
+ cerr << "Copy failed (\"" << module_src_path << "\" to \""
+ << module_dest_path << "\"): " << strerror(errno) << endl;
+ }
+#endif
}
}