]> sourceware.org Git - systemtap.git/blame - stap-sign-module.cxx
Fixed PR18577 by making 'stap -l **' faster.
[systemtap.git] / stap-sign-module.cxx
CommitLineData
aeb9cc10
DB
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
e8daaf60 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
aeb9cc10
DB
20*/
21
22#include "config.h"
23
24extern "C" {
25#include <nspr.h>
26#include <nss.h>
27}
28#include <string>
29
30#include "util.h"
31#include "nsscommon.h"
32
33using namespace std;
34
35// Called by methods within nsscommon.cxx.
36extern "C"
37void
38nsscommon_error (const char *msg, int logit __attribute ((unused)))
39{
40 clog << msg << endl << flush;
41}
42
43int
44main (int argc, char **argv)
45{
43ee156a 46#if ENABLE_NLS
aeb9cc10
DB
47 setlocale (LC_ALL, "");
48 bindtextdomain (PACKAGE, LOCALEDIR);
49 textdomain (PACKAGE);
43ee156a 50#endif
aeb9cc10
DB
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.078161 seconds and 5 git commands to generate.