]> sourceware.org Git - systemtap.git/blob - stap-sign-module.cxx
Fix rawhide compile problems in aux_syscalls.stp.
[systemtap.git] / stap-sign-module.cxx
1 /*
2 This program signs the given file using the named certificate and private
3 key in the given certificate database and places the signature in the named
4 output file.
5
6 Copyright (C) 2009-2011 Red Hat Inc.
7
8 This file is part of systemtap, and is free software. You can
9 redistribute it and/or modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "config.h"
23
24 extern "C" {
25 #include <nspr.h>
26 #include <nss.h>
27 }
28 #include <string>
29
30 #include "util.h"
31 #include "nsscommon.h"
32
33 using namespace std;
34
35 // Called by methods within nsscommon.cxx.
36 extern "C"
37 void
38 nsscommon_error (const char *msg, int logit __attribute ((unused)))
39 {
40 clog << msg << endl << flush;
41 }
42
43 int
44 main (int argc, char **argv)
45 {
46 #if ENABLE_NLS
47 setlocale (LC_ALL, "");
48 bindtextdomain (PACKAGE, LOCALEDIR);
49 textdomain (PACKAGE);
50 #endif
51
52 if (argc < 2) {
53 nsscommon_error (_("Module name was not specified."));
54 return 1;
55 }
56 string module_name = argv[1];
57
58 string cert_db_path;
59 if (argc >= 3)
60 cert_db_path = argv[2];
61 else
62 cert_db_path = server_cert_db_path ();
63
64 const char *nickName = server_cert_nickname ();
65 if (check_cert (cert_db_path, nickName) != 0)
66 return 1;
67
68 /* Call the NSPR initialization routines. */
69 PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
70
71 /* Set the cert database password callback. */
72 PK11_SetPasswordFunc (nssPasswordCallback);
73
74 /* Initialize NSS. */
75 SECStatus secStatus = nssInit (cert_db_path.c_str());
76 if (secStatus != SECSuccess)
77 {
78 // Message already issued.
79 return 1;
80 }
81
82 sign_file (cert_db_path, nickName, module_name, module_name + ".sgn");
83
84 /* Shutdown NSS and exit NSPR gracefully. */
85 nssCleanup (cert_db_path.c_str ());
86 PR_Cleanup ();
87
88 return 0;
89 }
90
91 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.042912 seconds and 5 git commands to generate.