rpm  4.12.0.1
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 }
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
static struct poptOption keyOptsTable[]
Definition: rpmkeys.c:22
rpmtransFlags rpmtsSetFlags(rpmts ts, rpmtransFlags transFlags)
Set transaction flags, i.e.
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
static struct poptOption optionsTable[]
Definition: rpmkeys.c:38
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
int rpmcliVerifySignatures(rpmts ts, ARGV_const_t argv)
Verify package signatures.
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
#define _(Text)
Definition: system.h:110
rpmts rpmtsCreate(void)
Create an empty transaction set.
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
void argerror(const char *desc)
Definition: cliutils.c:19
modes
Definition: rpmbuild.c:204
int main(int argc, char *argv[])
Definition: rpmkeys.c:49
static int mode
Definition: rpmkeys.c:19
const char * rpmcliRootDir
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
char *const * ARGV_const_t
Definition: argv.h:16
rpmtransFlags rpmtsFlags(rpmts ts)
Get transaction flags, i.e.
static int test
Definition: rpmkeys.c:20
#define N_(Text)
Definition: system.h:113
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
int rpmcliImportPubkeys(rpmts ts, ARGV_const_t argv)
Import public key(s) to rpm keyring.
char ** environ
Definition: rpmkeys.c:9