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
00021 static struct poptOption keyOptsTable[] = {
00022 { "checksig", 'K', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_CHECKSIG,
00023 N_("verify package signature(s)"), NULL },
00024 { "import", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_IMPORTKEY,
00025 N_("import an armored public key"), NULL },
00026 #if 0
00027 { "delete-key", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELKEY,
00028 N_("list keys from RPM keyring"), NULL },
00029 { "list-keys", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_LISTKEY,
00030 N_("list keys from RPM keyring"), NULL },
00031 #endif
00032 POPT_TABLEEND
00033 };
00034
00035 static struct poptOption optionsTable[] = {
00036 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, keyOptsTable, 0,
00037 N_("Keyring options:"), NULL },
00038 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
00039 N_("Common options for all rpm modes and executables:"), NULL },
00040
00041 POPT_AUTOALIAS
00042 POPT_AUTOHELP
00043 POPT_TABLEEND
00044 };
00045
00046 int main(int argc, char *argv[])
00047 {
00048 int ec = EXIT_FAILURE;
00049 poptContext optCon = rpmcliInit(argc, argv, optionsTable);
00050 rpmts ts = rpmtsCreate();
00051 ARGV_const_t args = NULL;
00052
00053 if (argc < 2) {
00054 printUsage(optCon, stderr, 0);
00055 goto exit;
00056 }
00057
00058 args = (ARGV_const_t) poptGetArgs(optCon);
00059
00060 if (mode != MODE_LISTKEY && args == NULL)
00061 argerror(_("no arguments given"));
00062
00063 rpmtsSetRootDir(ts, rpmcliRootDir);
00064
00065 switch (mode) {
00066 case MODE_CHECKSIG:
00067 ec = rpmcliVerifySignatures(ts, args);
00068 break;
00069 case MODE_IMPORTKEY:
00070 ec = rpmcliImportPubkeys(ts, args);
00071 break;
00072
00073 case MODE_DELKEY:
00074 case MODE_LISTKEY:
00075 break;
00076 default:
00077 argerror(_("only one major mode may be specified"));
00078 }
00079
00080 exit:
00081 rpmtsFree(ts);
00082 rpmcliFini(optCon);
00083 return ec;
00084 }