rpmkeys.c
Go to the documentation of this file.
#include "system.h"
#include <popt.h>
#include <rpm/rpmcli.h>
#include "cliutils.h"
#include "debug.h"
#if !defined(__GLIBC__) && !defined(__APPLE__)
char ** environ = NULL;
#endif
enum modes {
MODE_CHECKSIG = (1 << 0),
MODE_IMPORTKEY = (1 << 1),
MODE_DELKEY = (1 << 2),
MODE_LISTKEY = (1 << 3),
};
static int mode = 0;
static int test = 0;
static struct poptOption keyOptsTable[] = {
{ "checksig", 'K', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_CHECKSIG,
N_("verify package signature(s)"), NULL },
{ "import", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_IMPORTKEY,
N_("import an armored public key"), NULL },
{ "test", '\0', POPT_ARG_NONE, &test, 0,
N_("don't import, but tell if it would work or not"), NULL },
#if 0
{ "delete-key", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELKEY,
N_("list keys from RPM keyring"), NULL },
{ "list-keys", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_LISTKEY,
N_("list keys from RPM keyring"), NULL },
#endif
POPT_TABLEEND
};
static struct poptOption optionsTable[] = {
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, keyOptsTable, 0,
N_("Keyring options:"), NULL },
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
N_("Common options for all rpm modes and executables:"), NULL },
POPT_AUTOALIAS
POPT_AUTOHELP
POPT_TABLEEND
};
int main(int argc, char *argv[])
{
int ec = EXIT_FAILURE;
poptContext optCon = rpmcliInit(argc, argv, optionsTable);
rpmts ts = rpmtsCreate();
ARGV_const_t args = NULL;
if (argc < 2) {
printUsage(optCon, stderr, 0);
goto exit;
}
args = (ARGV_const_t) poptGetArgs(optCon);
if (mode != MODE_LISTKEY && args == NULL)
argerror(_("no arguments given"));
rpmtsSetRootDir(ts, rpmcliRootDir);
switch (mode) {
case MODE_CHECKSIG:
ec = rpmcliVerifySignatures(ts, args);
break;
case MODE_IMPORTKEY:
if (test)
rpmtsSetFlags(ts, (rpmtsFlags(ts)|RPMTRANS_FLAG_TEST));
ec = rpmcliImportPubkeys(ts, args);
break;
/* XXX TODO: actually implement these... */
case MODE_DELKEY:
case MODE_LISTKEY:
break;
default:
argerror(_("only one major mode may be specified"));
}
exit:
rpmtsFree(ts);
rpmcliFini(optCon);
return ec;
}
rpmtsSetRootDir
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
keyOptsTable
static struct poptOption keyOptsTable[]
Definition: rpmkeys.c:22
debug.h
MODE_IMPORTKEY
Definition: rpmkeys.c:14
optionsTable
static struct poptOption optionsTable[]
Definition: rpmkeys.c:38
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
cliutils.h
Misc helpers for RPM CLI tools.
_
#define _(Text)
Definition: system.h:112
MODE_LISTKEY
Definition: rpmkeys.c:16
rpmtsFlags
rpmtransFlags rpmtsFlags(rpmts ts)
Get transaction flags, i.e.
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
MODE_DELKEY
Definition: rpmkeys.c:15
modes
modes
Definition: rpmbuild.c:250
main
int main(int argc, char *argv[])
Definition: rpmkeys.c:49
RPMTRANS_FLAG_TEST
Definition: rpmts.h:30
mode
static int mode
Definition: rpmkeys.c:19
rpmcliRootDir
const char * rpmcliRootDir
ARGV_const_t
char *const * ARGV_const_t
Definition: argv.h:18
rpmtsFree
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
rpmts
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
system.h
Some misc low-level API.
test
static int test
Definition: rpmkeys.c:20
MODE_CHECKSIG
Definition: rpmkeys.c:13
N_
#define N_(Text)
Definition: system.h:115
rpmcliVerifySignatures
int rpmcliVerifySignatures(rpmts ts, ARGV_const_t argv)
Verify package signatures.
rpmtsSetFlags
rpmtransFlags rpmtsSetFlags(rpmts ts, rpmtransFlags transFlags)
Set transaction flags, i.e.
rpmtsCreate
rpmts rpmtsCreate(void)
Create an empty transaction set.
rpmcliImportPubkeys
int rpmcliImportPubkeys(rpmts ts, ARGV_const_t argv)
Import public key(s) to rpm keyring.
environ
char ** environ
Definition: rpmkeys.c:9
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.