rpm: rpmkeys.c Source File

rpm 4.12.0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

rpmkeys.c
Go to the documentation of this file.
1 #include "system.h"
2
3 #include <popt.h>
4 #include <rpm/rpmcli.h>
5 #include "cliutils.h"
6 #include "debug.h"
7
8 #if !defined(__GLIBC__) && !defined(__APPLE__)
9 char ** environ = NULL;
10 #endif
11
12 enum modes {
13 MODE_CHECKSIG = (1 << 0),
14 MODE_IMPORTKEY = (1 << 1),
15 MODE_DELKEY = (1 << 2),
16 MODE_LISTKEY = (1 << 3),
17 };
18
19 static int mode = 0;
20 static int test = 0;
21
22 static struct poptOption keyOptsTable[] = {
23 { "checksig", 'K', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_CHECKSIG,
24 N_("verify package signature(s)"), NULL },
25 { "import", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_IMPORTKEY,
26 N_("import an armored public key"), NULL },
27 { "test", '\0', POPT_ARG_NONE, &test, 0,
28 N_("don't import, but tell if it would work or not"), NULL },
29 #if 0
30 { "delete-key", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELKEY,
31 N_("list keys from RPM keyring"), NULL },
32 { "list-keys", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_LISTKEY,
33 N_("list keys from RPM keyring"), NULL },
34 #endif
35 POPT_TABLEEND
36 };
37
38 static struct poptOption optionsTable[] = {
39 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, keyOptsTable, 0,
40 N_("Keyring options:"), NULL },
41 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
42 N_("Common options for all rpm modes and executables:"), NULL },
43
44 POPT_AUTOALIAS
45 POPT_AUTOHELP
46 POPT_TABLEEND
47 };
48
49 int main(int argc, char *argv[])
50 {
51 int ec = EXIT_FAILURE;
52 poptContext optCon = rpmcliInit(argc, argv, optionsTable);
53 rpmts ts = rpmtsCreate();
54 ARGV_const_t args = NULL;
55
56 if (argc < 2) {
57 printUsage(optCon, stderr, 0);
58 goto exit;
59 }
60
61 args = (ARGV_const_t) poptGetArgs(optCon);
62
63 if (mode != MODE_LISTKEY && args == NULL)
64 argerror(_("no arguments given"));
65
66 rpmtsSetRootDir(ts, rpmcliRootDir);
67
68 switch (mode) {
69 case MODE_CHECKSIG:
70 ec = rpmcliVerifySignatures(ts, args);
71 break;
72 case MODE_IMPORTKEY:
73 if (test)
74 rpmtsSetFlags(ts, (rpmtsFlags(ts)|RPMTRANS_FLAG_TEST));
75 ec = rpmcliImportPubkeys(ts, args);
76 break;
77 /* XXX TODO: actually implement these... */
78 case MODE_DELKEY:
79 case MODE_LISTKEY:
80 break;
81 default:
82 argerror(_("only one major mode may be specified"));
83 }
84
85 exit:
86 rpmtsFree(ts);
87 rpmcliFini(optCon);
88 return ec;
89 }
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
keyOptsTable
static struct poptOption keyOptsTable[]
Definition: rpmkeys.c:22
debug.h
rpmtsSetFlags
rpmtransFlags rpmtsSetFlags(rpmts ts, rpmtransFlags transFlags)
Set transaction flags, i.e.
rpmtsFree
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
MODE_IMPORTKEY
Definition: rpmkeys.c:14
optionsTable
static struct poptOption optionsTable[]
Definition: rpmkeys.c:38
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
rpmcliVerifySignatures
int rpmcliVerifySignatures(rpmts ts, ARGV_const_t argv)
Verify package signatures.
cliutils.h
rpmts
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
_
#define _(Text)
Definition: system.h:110
rpmtsCreate
rpmts rpmtsCreate(void)
Create an empty transaction set.
MODE_LISTKEY
Definition: rpmkeys.c:16
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
MODE_DELKEY
Definition: rpmkeys.c:15
modes
modes
Definition: rpmbuild.c:204
main
int main(int argc, char *argv[])
Definition: rpmkeys.c:49
mode
static int mode
Definition: rpmkeys.c:19
rpmcliRootDir
const char * rpmcliRootDir
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
ARGV_const_t
char *const * ARGV_const_t
Definition: argv.h:16
rpmtsFlags
rpmtransFlags rpmtsFlags(rpmts ts)
Get transaction flags, i.e.
system.h
test
static int test
Definition: rpmkeys.c:20
RPMTRANS_FLAG_TEST
Definition: rpmts.h:30
MODE_CHECKSIG
Definition: rpmkeys.c:13
N_
#define N_(Text)
Definition: system.h:113
rpmtsSetRootDir
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
rpmcliImportPubkeys
int rpmcliImportPubkeys(rpmts ts, ARGV_const_t argv)
Import public key(s) to rpm keyring.
environ
char ** environ
Definition: rpmkeys.c:9