rpm  4.11.1-rc1
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 
67 
68  switch (mode) {
69  case MODE_CHECKSIG:
70  ec = rpmcliVerifySignatures(ts, args);
71  break;
72  case MODE_IMPORTKEY:
73  if (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 }