summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2002-06-30 22:47:32 +0000
committerjbj <devnull@localhost>2002-06-30 22:47:32 +0000
commit8c4991e9d533de552b957ea445d65f6834205f29 (patch)
tree159a3aaa6575611308382acbadba3a55d9856bd5 /lib
parent10e3aaa69f3d7f74958e3dd0d0b471b296a1bb23 (diff)
downloadrpm-8c4991e9d533de552b957ea445d65f6834205f29.tar.gz
rpm-8c4991e9d533de552b957ea445d65f6834205f29.tar.bz2
rpm-8c4991e9d533de552b957ea445d65f6834205f29.zip
- warn only once for each NOKEY/UNTRUSTED key id.
- factor common options into table, add rpmcliInit() and rpmcliFini(). - add preliminary rpmgraph(8) and rpmcache(8) executables to rpm-devel. CVS patchset: 5535 CVS date: 2002/06/30 22:47:32
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/package.c44
-rw-r--r--lib/poptALL.c262
-rw-r--r--lib/poptI.c4
-rw-r--r--lib/rpmcli.h27
-rw-r--r--lib/rpminstall.c14
-rw-r--r--lib/rpmps.h3
7 files changed, 339 insertions, 17 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index ec388599a..7296db906 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -32,7 +32,7 @@ lib_LTLIBRARIES = librpm.la
librpm_la_SOURCES = \
cpio.c depends.c formats.c fs.c fsm.c getdate.c \
manifest.c misc.c package.c \
- poptI.c poptQV.c psm.c query.c \
+ poptALL.c poptI.c poptQV.c psm.c query.c \
rpmal.c rpmchecksig.c rpmds.c rpmfi.c rpminstall.c \
rpmlead.c rpmlibprov.c rpmps.c rpmrc.c rpmte.c rpmts.c rpmvercmp.c \
signature.c stringbuf.c transaction.c \
diff --git a/lib/package.c b/lib/package.c
index 25bcaec05..ee9306867 100644
--- a/lib/package.c
+++ b/lib/package.c
@@ -142,6 +142,43 @@ Header headerRegenSigHeader(const Header h)
}
/*@unchecked@*/
+static int nkeyids = 0;
+/*@unchecked@*/
+static int * keyids = NULL;
+
+/**
+ * Remember current key id.
+ * @param ts transaction set
+ * @return 0 if new keyid, otherwise 1
+ */
+static int rpmtsStashKeyid(rpmts ts)
+ /*@globals keyids, nkeyids @*/
+ /*@modifies keyids, nkeyids @*/
+{
+ struct pgpDigParams_s * sigp = NULL;
+ unsigned int keyid;
+ int i;
+
+ if (ts->sig == NULL || ts->dig == NULL)
+ return 0;
+
+ sigp = &ts->dig->signature;
+ keyid = pgpGrab(sigp->signid+4, 4);
+
+ if (keyids != NULL && keyid > 0)
+ for (i = 0; i < nkeyids; i++) {
+ if (keyid == keyids[i])
+ return 1;
+ }
+
+ keyids = xrealloc(keyids, (nkeyids + 1) * sizeof(*keyids));
+ keyids[nkeyids] = keyid;
+ nkeyids++;
+
+ return 0;
+}
+
+/*@unchecked@*/
static unsigned char header_magic[8] = {
0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
};
@@ -389,9 +426,14 @@ int rpmReadPackageFile(rpmts ts, FD_t fd,
rpmMessage(RPMMESS_DEBUG, "%s: %s", fn, buf);
rc = RPMRC_OK;
break;
- case RPMSIG_UNKNOWN: /* Signature is unknown. */
case RPMSIG_NOKEY: /* Key is unavailable. */
case RPMSIG_NOTTRUSTED: /* Signature is OK, but key is not trusted. */
+ /* XXX Print NOKEY/NOTTRUSTED warning only once. */
+ if (!rpmtsStashKeyid(ts))
+ rpmMessage(RPMMESS_WARNING, "%s: %s", fn, buf);
+ rc = RPMRC_OK;
+ break;
+ case RPMSIG_UNKNOWN: /* Signature is unknown. */
rpmMessage(RPMMESS_WARNING, "%s: %s", fn, buf);
rc = RPMRC_OK;
break;
diff --git a/lib/poptALL.c b/lib/poptALL.c
new file mode 100644
index 000000000..5beecdd5e
--- /dev/null
+++ b/lib/poptALL.c
@@ -0,0 +1,262 @@
+/*@-boundsread@*/
+/** \ingroup rpmcli
+ * \file lib/poptALL.c
+ * Popt tables for all rpm modes.
+ */
+
+#include "system.h"
+
+#include <rpmcli.h>
+
+#include "debug.h"
+
+#ifdef NOTYET
+#define POPT_RCFILE -1022
+#endif
+#define POPT_SHOWVERSION -999
+#define POPT_SHOWRC -998
+
+/*@unchecked@*/
+static int _debug = 0;
+
+/*@unchecked@*/
+/*@observer@*/ /*@null@*/
+static const char * pipeOutput = NULL;
+/*@unchecked@*/
+/*@observer@*/ /*@null@*/
+static const char * rcfile = NULL;
+/*@unchecked@*/
+static const char * rootdir = "/";
+
+/*@-exportheadervar@*/
+/*@unchecked@*/
+extern int _ftp_debug;
+/*@unchecked@*/
+extern int noLibio;
+/*@unchecked@*/
+extern int _rpmio_debug;
+/*@=exportheadervar@*/
+
+/**
+ * Display rpm version.
+ */
+static void printVersion(void)
+ /*@globals rpmEVR, fileSystem @*/
+ /*@modifies fileSystem @*/
+{
+ fprintf(stdout, _("RPM version %s\n"), rpmEVR);
+}
+
+/**
+ * Make sure that config files have been read.
+ * @warning Options like --rcfile and --verbose must precede callers option.
+ */
+/*@mayexit@*/
+static void rpmcliConfigured(void)
+ /*@globals internalState @*/
+ /*@modifies internalState @*/
+{
+ static int initted = -1;
+
+ if (initted < 0)
+ initted = rpmReadConfigFiles(rcfile, NULL);
+ if (initted)
+ exit(EXIT_FAILURE);
+}
+
+/**
+ */
+/*@-bounds@*/
+static void rpmcliAllArgCallback( /*@unused@*/ poptContext con,
+ /*@unused@*/ enum poptCallbackReason reason,
+ const struct poptOption * opt, const char * arg,
+ /*@unused@*/ const void * data)
+ /*@*/
+{
+#if 0
+/*@observer@*/
+static const char *cbreasonstr[] = { "PRE", "POST", "OPTION", "?WTFO?" };
+fprintf(stderr, "*** rpmcliALL: -%c,--%s %s %s opt %p arg %p val %d\n", opt->shortName, opt->longName, arg, cbreasonstr[reason&0x3], opt, opt->arg, opt->val);
+#endif
+
+ /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
+ /*@-branchstate@*/
+ if (opt->arg == NULL)
+ switch (opt->val) {
+ case 'q':
+ rpmSetVerbosity(RPMMESS_QUIET);
+ break;
+ case 'v':
+ rpmIncreaseVerbosity();
+ break;
+ case 'D':
+ (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
+ rpmcliConfigured();
+ (void) rpmDefineMacro(rpmCLIMacroContext, arg, RMIL_CMDLINE);
+ break;
+ case 'E':
+ rpmcliConfigured();
+ { const char *val = rpmExpand(arg, NULL);
+ fprintf(stdout, "%s\n", val);
+ val = _free(val);
+ }
+ break;
+ case POPT_SHOWVERSION:
+ printVersion();
+ exit(EXIT_SUCCESS);
+ /*@notreached@*/ break;
+ case POPT_SHOWRC:
+ rpmcliConfigured();
+ (void) rpmShowRC(stdout);
+ exit(EXIT_SUCCESS);
+ /*@notreached@*/ break;
+#if defined(POPT_RCFILE)
+ case POPT_RCFILE: /* XXX FIXME: noop for now */
+ break;
+#endif
+ }
+ /*@=branchstate@*/
+}
+
+/*@unchecked@*/
+struct poptOption rpmcliAllPoptTable[] = {
+/*@-type@*/ /* FIX: cast? */
+ { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
+ rpmcliAllArgCallback, 0, NULL, NULL },
+/*@=type@*/
+
+ { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
+ NULL, NULL },
+ { "quiet", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, 'q',
+ N_("provide less detailed output"), NULL},
+ { "verbose", 'v', 0, 0, 'v',
+ N_("provide more detailed output"), NULL},
+ { "version", '\0', 0, 0, POPT_SHOWVERSION,
+ N_("print the version of rpm being used"), NULL },
+
+ { "define", 'D', POPT_ARG_STRING, 0, 'D',
+ N_("define MACRO with value EXPR"),
+ N_("'MACRO EXPR'") },
+ { "eval", 'E', POPT_ARG_STRING, 0, 'E',
+ N_("print macro expansion of EXPR"),
+ N_("'EXPR'") },
+ { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &pipeOutput, 0,
+ N_("send stdout to <cmd>"),
+ N_("<cmd>") },
+ { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARGFLAG_DOC_HIDDEN, &rootdir, 0,
+ N_("use <dir> as the top level directory"),
+ N_("<dir>") },
+ { "macros", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &macrofiles, 0,
+ N_("read <FILE:...> instead of default file(s)"),
+ N_("<FILE:...>") },
+#if !defined(POPT_RCFILE)
+ { "rcfile", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rcfile, 0,
+ N_("read <FILE:...> instead of default file(s)"),
+ N_("<FILE:...>") },
+#else
+ { "rcfile", '\0', 0, 0, POPT_RCFILE|POPT_ARGFLAG_DOC_HIDDEN,
+ N_("read <FILE:...> instead of default file(s)"),
+ N_("<FILE:...>") },
+#endif
+ { "showrc", '\0', 0, POPT_SHOWRC|POPT_ARGFLAG_DOC_HIDDEN, 0,
+ N_("display final rpmrc and macro configuration"),
+ NULL },
+
+#if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
+ { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
+ N_("disable use of libio(3) API"), NULL},
+#endif
+
+ { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
+ N_("debug protocol data stream"), NULL},
+ { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
+ N_("debug rpmio I/O"), NULL},
+ { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
+ N_("debug URL cache handling"), NULL},
+
+ POPT_TABLEEND
+};
+
+poptContext
+rpmcliFini(poptContext optCon)
+{
+ optCon = poptFreeContext(optCon);
+
+#if HAVE_MCHECK_H && HAVE_MTRACE
+ muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
+#endif
+
+ return NULL;
+}
+
+poptContext
+rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
+{
+ const char * optArg;
+ poptContext optCon;
+ int rc;
+
+#if HAVE_MCHECK_H && HAVE_MTRACE
+ mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
+#endif
+ setprogname(argv[0]); /* Retrofit glibc __progname */
+
+ /* XXX glibc churn sanity */
+ if (__progname == NULL) {
+ if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
+ else __progname = argv[0];
+ }
+
+ (void)setlocale(LC_ALL, "" );
+
+#ifdef __LCLINT__
+#define LOCALEDIR "/usr/share/locale"
+#endif
+ (void)bindtextdomain(PACKAGE, LOCALEDIR);
+ (void)textdomain(PACKAGE);
+
+ rpmSetVerbosity(RPMMESS_NORMAL);
+
+ if (optionsTable == NULL) {
+ /* Read rpm configuration (if not already read). */
+ rpmcliConfigured();
+ return NULL;
+ }
+
+ optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
+ (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
+ poptReadDefaultConfig(optCon, 1);
+ poptSetExecPath(optCon, RPMCONFIGDIR, 1);
+
+ /* Process all options, whine if unknown. */
+ while ((rc = poptGetNextOpt(optCon)) > 0) {
+ optArg = poptGetOptArg(optCon);
+ switch (rc) {
+ default:
+ fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
+ __progname, rc);
+ exit(EXIT_FAILURE);
+
+ /*@notreached@*/ break;
+ }
+ }
+
+ if (rc < -1) {
+ fprintf(stderr, "%s: %s: %s\n", __progname,
+ poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror(rc));
+ exit(EXIT_FAILURE);
+ }
+
+ /* Read rpm configuration (if not already read). */
+ rpmcliConfigured();
+
+ if (_debug) {
+ rpmIncreaseVerbosity();
+ rpmIncreaseVerbosity();
+ }
+
+ return optCon;
+}
+
+/*@=boundsread@*/
diff --git a/lib/poptI.c b/lib/poptI.c
index fb138ca48..d85570ceb 100644
--- a/lib/poptI.c
+++ b/lib/poptI.c
@@ -37,8 +37,8 @@ static void installArgCallback( /*@unused@*/ poptContext con,
/*@unused@*/ enum poptCallbackReason reason,
const struct poptOption * opt, const char * arg,
/*@unused@*/ const void * data)
- /*@globals rpmIArgs */
- /*@modifies rpmIArgs */
+ /*@globals rpmIArgs @*/
+ /*@modifies rpmIArgs @*/
{
struct rpmInstallArguments_s * ia = &rpmIArgs;
diff --git a/lib/rpmcli.h b/lib/rpmcli.h
index ec57113ec..b48c0cc9e 100644
--- a/lib/rpmcli.h
+++ b/lib/rpmcli.h
@@ -21,6 +21,33 @@ extern int _noDirTokens;
extern "C" {
#endif
+/** \ingroup rpmcli
+ * Popt option table for options shared by all modes and executables.
+ */
+/*@unchecked@*/
+extern struct poptOption rpmcliAllPoptTable[];
+
+/**
+ * Initialize most everything needed by an rpm CLI executable context.
+ * @param argc no. of args
+ * @param argv arg array
+ * @param optionsTable popt option table
+ * @return popt context (or NULL)
+ */
+/*@null@*/
+poptContext
+rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
+ /*@*/;
+
+/**
+ * Destroy most everything needed by an rpm CLI executable context.
+ * @param optCon popt context
+ * @return NULL always
+ */
+poptContext
+rpmcliFini(/*@only@*/ /*@null@*/ poptContext optCon)
+ /*@modifies optCon @*/;
+
/* ==================================================================== */
/** \name RPMBT */
/*@{*/
diff --git a/lib/rpminstall.c b/lib/rpminstall.c
index 0348d7423..691711b9e 100644
--- a/lib/rpminstall.c
+++ b/lib/rpminstall.c
@@ -230,7 +230,7 @@ int rpmInstall(rpmts ts,
/*@only@*/ /*@null@*/ const char * fileURL = NULL;
int stopInstall = 0;
const char ** av = NULL;
- int vsflags;
+ int vsflags = _RPMTS_VSF_VERIFY_LEGACY;
int ac = 0;
int rc;
int xx;
@@ -244,15 +244,11 @@ int rpmInstall(rpmts ts,
ts->goal = TSM_INSTALL;
- vsflags = 0;
if (ia->qva_flags & VERIFY_DIGEST)
vsflags |= _RPMTS_VSF_NODIGESTS;
if (ia->qva_flags & VERIFY_SIGNATURE)
vsflags |= _RPMTS_VSF_NOSIGNATURES;
- vsflags |= _RPMTS_VSF_VERIFY_LEGACY;
-
- /* Open database RDONLY initiallly, reopen RDWR in rpmtsRun(). */
- ts->dbmode = O_RDONLY;
+ xx = rpmtsSetVerifySigFlags(ts, (vsflags & ~_RPMTS_VSF_VERIFY_LEGACY));
{ int notifyFlags;
notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
@@ -654,12 +650,6 @@ int rpmErase(rpmts ts,
ts->goal = TSM_ERASE;
- /* XXX W2DO? O_EXCL??? */
- ts->dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
- ? O_RDONLY : (O_RDWR|O_EXCL);
-
- (void) rpmtsOpenDB(ts, ts->dbmode);
-
for (arg = argv; *arg; arg++) {
rpmdbMatchIterator mi;
diff --git a/lib/rpmps.h b/lib/rpmps.h
index 39bef8349..4f110a50a 100644
--- a/lib/rpmps.h
+++ b/lib/rpmps.h
@@ -146,13 +146,14 @@ void rpmpsPrint(/*@null@*/ FILE *fp, /*@null@*/ rpmps ps)
/*@modifies *fp, ps, fileSystem @*/;
/**
- * Append a problem to set.
+ * Append a problem to current set of problems.
* @param ps problem set
* @param type type of problem
* @param pkgNEVR package name
* @param key filename or python object address
* @param dn directory name
* @param bn file base name
+ * @param altNEVR related (e.g. through a dependency) package name
* @param ulong1 generic pointer/long attribute
*/
void rpmpsAppend(/*@null@*/ rpmps ps, rpmProblemType type,