Add macro %isu_package to generate ISU Package
[platform/upstream/rpm.git] / rpmkeys.c
1 #include "system.h"
2
3 #include <popt.h>
4 #include <rpm/rpmcli.h>
5 #include "cliutils.h"
6 #include "debug.h"
7
8 enum modes {
9     MODE_CHECKSIG       = (1 << 0),
10     MODE_IMPORTKEY      = (1 << 1),
11     MODE_DELKEY         = (1 << 2),
12     MODE_LISTKEY        = (1 << 3),
13 };
14
15 static int mode = 0;
16 static int test = 0;
17
18 static struct poptOption keyOptsTable[] = {
19     { "checksig", 'K', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_CHECKSIG,
20         N_("verify package signature(s)"), NULL },
21     { "import", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_IMPORTKEY,
22         N_("import an armored public key"), NULL },
23     { "test", '\0', POPT_ARG_NONE, &test, 0,
24         N_("don't import, but tell if it would work or not"), NULL },
25 #if 0
26     { "delete-key", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELKEY,
27         N_("list keys from RPM keyring"), NULL },
28     { "list-keys", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_LISTKEY,
29         N_("list keys from RPM keyring"), NULL },
30 #endif
31     POPT_TABLEEND
32 };
33
34 static struct poptOption optionsTable[] = {
35     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, keyOptsTable, 0,
36         N_("Keyring options:"), NULL },
37     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
38         N_("Common options for all rpm modes and executables:"), NULL },
39
40     POPT_AUTOALIAS
41     POPT_AUTOHELP
42     POPT_TABLEEND
43 };
44
45 int main(int argc, char *argv[])
46 {
47     int ec = EXIT_FAILURE;
48     poptContext optCon = NULL;
49     rpmts ts = rpmtsCreate();
50     ARGV_const_t args = NULL;
51
52     xsetprogname(argv[0]); /* Portability call -- see system.h */
53     
54     optCon = rpmcliInit(argc, argv, optionsTable);
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 }