rpm: rpmkeys.c Source File

rpm 4.10.0

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

- File List
- Globals

rpmkeys.c
Go to the documentation of this file.

    00001 #include "system.h"
    00002
    00003 #include <popt.h>
    00004 #include <rpm/rpmcli.h>
    00005 #include "cliutils.h"
    00006 #include "debug.h"
    00007
    00008 #if !defined(__GLIBC__) && !defined(__APPLE__)
    00009 char ** environ = NULL;
    00010 #endif
    00011
    00012 enum modes {
    00013     MODE_CHECKSIG       = (1 << 0),
    00014     MODE_IMPORTKEY      = (1 << 1),
    00015     MODE_DELKEY         = (1 << 2),
    00016     MODE_LISTKEY        = (1 << 3),
    00017 };
    00018
    00019 static int mode = 0;
    00020 static int test = 0;
    00021
    00022 static struct poptOption keyOptsTable[] = {
    00023     { "checksig", 'K', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_CHECKSIG,
    00024         N_("verify package signature(s)"), NULL },
    00025     { "import", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_IMPORTKEY,
    00026         N_("import an armored public key"), NULL },
    00027     { "test", '\0', POPT_ARG_NONE, &test, 0,
    00028         N_("don't import, but tell if it would work or not"), NULL },
    00029 #if 0
    00030     { "delete-key", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELKEY,
    00031         N_("list keys from RPM keyring"), NULL },
    00032     { "list-keys", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_LISTKEY,
    00033         N_("list keys from RPM keyring"), NULL },
    00034 #endif
    00035     POPT_TABLEEND
    00036 };
    00037
    00038 static struct poptOption optionsTable[] = {
    00039     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, keyOptsTable, 0,
    00040         N_("Keyring options:"), NULL },
    00041     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
    00042         N_("Common options for all rpm modes and executables:"), NULL },
    00043
    00044     POPT_AUTOALIAS
    00045     POPT_AUTOHELP
    00046     POPT_TABLEEND
    00047 };
    00048
    00049 int main(int argc, char *argv[])
    00050 {
    00051     int ec = EXIT_FAILURE;
    00052     poptContext optCon = rpmcliInit(argc, argv, optionsTable);
    00053     rpmts ts = rpmtsCreate();
    00054     ARGV_const_t args = NULL;
    00055
    00056     if (argc < 2) {
    00057         printUsage(optCon, stderr, 0);
    00058         goto exit;
    00059     }
    00060
    00061     args = (ARGV_const_t) poptGetArgs(optCon);
    00062
    00063     if (mode != MODE_LISTKEY && args == NULL)
    00064         argerror(_("no arguments given"));
    00065
    00066     rpmtsSetRootDir(ts, rpmcliRootDir);
    00067
    00068     switch (mode) {
    00069     case MODE_CHECKSIG:
    00070         ec = rpmcliVerifySignatures(ts, args);
    00071         break;
    00072     case MODE_IMPORTKEY:
    00073         if (test)
    00074             rpmtsSetFlags(ts, (rpmtsFlags(ts)|RPMTRANS_FLAG_TEST));
    00075         ec = rpmcliImportPubkeys(ts, args);
    00076         break;
    00077     /* XXX TODO: actually implement these... */
    00078     case MODE_DELKEY:
    00079     case MODE_LISTKEY:
    00080         break;
    00081     default:
    00082         argerror(_("only one major mode may be specified"));
    00083     }
    00084
    00085 exit:
    00086     rpmtsFree(ts);
    00087     rpmcliFini(optCon);
    00088     return ec;
    00089 }