Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# rpmqv.c

Go to the documentation of this file.

    00001 #include "system.h"
    00002
    00003 #define _AUTOHELP
    00004
    00005 #if defined(IAM_RPM) || defined(__LCLINT__)
    00006 #define IAM_RPMBT
    00007 #define IAM_RPMDB
    00008 #define IAM_RPMEIU
    00009 #define IAM_RPMQV
    00010 #define IAM_RPMK
    00011 #endif
    00012
    00013 #include <rpmcli.h>
    00014 #include <rpmbuild.h>
    00015
    00016 #define POPT_NODEPS             1025
    00017 #define POPT_FORCE              1026
    00018 #define POPT_NOMD5              1027
    00019 #define POPT_NOSCRIPTS          1028
    00020
    00021 #ifdef  IAM_RPMBT
    00022 #include "build.h"
    00023 #define GETOPT_REBUILD          1003
    00024 #define GETOPT_RECOMPILE        1004
    00025 #endif
    00026
    00027 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
    00028 #include "signature.h"
    00029 #endif
    00030
    00031 #include "debug.h"
    00032
    00033 #define GETOPT_DBPATH           1010
    00034 #define GETOPT_SHOWRC           1018
    00035 #define GETOPT_DEFINEMACRO      1020
    00036 #define GETOPT_EVALMACRO        1021
    00037 #ifdef  NOTYET
    00038 #define GETOPT_RCFILE           1022
    00039 #endif
    00040
    00041 enum modes {
    00042
    00043     MODE_QUERY          = (1 <<  0),
    00044     MODE_VERIFY         = (1 <<  3),
    00045     MODE_QUERYTAGS      = (1 <<  9),
    00046 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
    00047
    00048     MODE_INSTALL        = (1 <<  1),
    00049     MODE_ERASE          = (1 <<  2),
    00050 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
    00051
    00052     MODE_BUILD          = (1 <<  4),
    00053     MODE_REBUILD        = (1 <<  5),
    00054     MODE_RECOMPILE      = (1 <<  8),
    00055     MODE_TARBUILD       = (1 << 11),
    00056 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
    00057
    00058     MODE_CHECKSIG       = (1 <<  6),
    00059     MODE_RESIGN         = (1 <<  7),
    00060 #define MODES_K  (MODE_CHECKSIG | MODE_RESIGN)
    00061
    00062     MODE_INITDB         = (1 << 10),
    00063     MODE_REBUILDDB      = (1 << 12),
    00064     MODE_VERIFYDB       = (1 << 13),
    00065 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB)
    00066
    00067
    00068     MODE_UNKNOWN        = 0
    00069 };
    00070
    00071 #define MODES_FOR_DBPATH        (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
    00072 #define MODES_FOR_NODEPS        (MODES_BT | MODES_IE | MODE_VERIFY)
    00073 #define MODES_FOR_TEST          (MODES_BT | MODES_IE)
    00074 #define MODES_FOR_ROOT          (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
    00075
    00076 /*@-exportheadervar@*/
    00077 /*@unchecked@*/
    00078 extern int _ftp_debug;
    00079 /*@unchecked@*/
    00080 extern int noLibio;
    00081 /*@unchecked@*/
    00082 extern int _rpmio_debug;
    00083 /*@-redecl@*/
    00084 /*@unchecked@*/
    00085 extern int _url_debug;
    00086 /*@=redecl@*/
    00087
    00088 /*@=exportheadervar@*/
    00089
    00090 /* options for all executables */
    00091
    00092 /*@unchecked@*/
    00093 static int help = 0;
    00094 /*@unchecked@*/
    00095 static int noUsageMsg = 0;
    00096 /*@unchecked@*/ /*@observer@*/ /*@null@*/
    00097 static const char * pipeOutput = NULL;
    00098 /*@unchecked@*/
    00099 static int quiet = 0;
    00100 /*@unchecked@*/ /*@observer@*/ /*@null@*/
    00101 static const char * rcfile = NULL;
    00102 /*@unchecked@*/ /*@observer@*/ /*@null@*/
    00103 static char * rootdir = "/";
    00104 /*@unchecked@*/
    00105 static int showrc = 0;
    00106 /*@unchecked@*/
    00107 static int showVersion = 0;
    00108
    00109 /*@unchecked@*/
    00110 static struct poptOption rpmAllPoptTable[] = {
    00111  { "version", '\0', 0, &showVersion, 0,
    00112         N_("print the version of rpm being used"),
    00113         NULL },
    00114  { "quiet", '\0', 0, &quiet, 0,
    00115         N_("provide less detailed output"), NULL},
    00116  { "verbose", 'v', 0, 0, 'v',
    00117         N_("provide more detailed output"), NULL},
    00118  { "define", '\0', POPT_ARG_STRING, 0, GETOPT_DEFINEMACRO,
    00119         N_("define macro <name> with value <body>"),
    00120         N_("'<name> <body>'") },
    00121  { "eval", '\0', POPT_ARG_STRING, 0, GETOPT_EVALMACRO,
    00122         N_("print macro expansion of <expr>+"),
    00123         N_("<expr>+") },
    00124  { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &pipeOutput, 0,
    00125         N_("send stdout to <cmd>"),
    00126         N_("<cmd>") },
    00127  { "root", 'r', POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &rootdir, 0,
    00128         N_("use <dir> as the top level directory"),
    00129         N_("<dir>") },
    00130  { "macros", '\0', POPT_ARG_STRING, &macrofiles, 0,
    00131         N_("read <file:...> instead of default macro file(s)"),
    00132         N_("<file:...>") },
    00133 #if !defined(GETOPT_RCFILE)
    00134  { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0,
    00135         N_("read <file:...> instead of default rpmrc file(s)"),
    00136         N_("<file:...>") },
    00137 #else
    00138  { "rcfile", '\0', 0, 0, GETOPT_RCFILE,
    00139         N_("read <file:...> instead of default rpmrc file(s)"),
    00140         N_("<file:...>") },
    00141 #endif
    00142  { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC,
    00143         N_("display final rpmrc and macro configuration"),
    00144         NULL },
    00145
    00146 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
    00147  { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
    00148         N_("disable use of libio(3) API"), NULL},
    00149 #endif
    00150  { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
    00151         N_("debug protocol data stream"), NULL},
    00152  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
    00153         N_("debug rpmio I/O"), NULL},
    00154  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
    00155         N_("debug URL cache handling"), NULL},
    00156
    00157    POPT_TABLEEND
    00158 };
    00159
    00160 /* the structure describing the options we take and the defaults */
    00161 /*@unchecked@*/
    00162 static struct poptOption optionsTable[] = {
    00163
    00164  /* XXX colliding options */
    00165 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
    00166  {  NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i',                 NULL, NULL},
    00167  {  "nodeps", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NODEPS,       NULL, NULL},
    00168  {  "noscripts", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOSCRIPTS, NULL, NULL},
    00169  {  "nomd5", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOMD5,         NULL, NULL},
    00170  {  "force", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_FORCE,         NULL, NULL},
    00171 #endif
    00172
    00173 #ifdef  IAM_RPMQV
    00174  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
    00175         N_("Query options (with -q or --query):"),
    00176         NULL },
    00177  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
    00178         N_("Verify options (with -V or --verify):"),
    00179         NULL },
    00180 #endif  /* IAM_RPMQV */
    00181
    00182 #ifdef  IAM_RPMK
    00183  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
    00184         N_("Signature options:"),
    00185         NULL },
    00186 #endif  /* IAM_RPMK */
    00187
    00188 #ifdef  IAM_RPMDB
    00189  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
    00190         N_("Database options:"),
    00191         NULL },
    00192 #endif  /* IAM_RPMDB */
    00193
    00194 #ifdef  IAM_RPMBT
    00195  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
    00196         N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
    00197         NULL },
    00198 #endif  /* IAM_RPMBT */
    00199
    00200 #ifdef  IAM_RPMEIU
    00201  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
    00202         N_("Install/Upgrade/Erase options:"),
    00203         NULL },
    00204 #endif  /* IAM_RPMEIU */
    00205
    00206  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmAllPoptTable, 0,
    00207         N_("Common options for all rpm modes:"),
    00208         NULL },
    00209
    00210    POPT_AUTOALIAS
    00211    POPT_AUTOHELP
    00212    POPT_TABLEEND
    00213 };
    00214
    00215 #ifdef __MINT__
    00216 /* MiNT cannot dynamically increase the stack.  */
    00217 long _stksize = 64 * 1024L;
    00218 #endif
    00219
    00220 /*@exits@*/ static void argerror(const char * desc)
    00221         /*@globals fileSystem @*/
    00222         /*@modifies fileSystem @*/
    00223 {
    00224     fprintf(stderr, _("%s: %s\n"), __progname, desc);
    00225     exit(EXIT_FAILURE);
    00226 }
    00227
    00228 static void printVersion(void)
    00229         /*@globals rpmEVR, fileSystem @*/
    00230         /*@modifies fileSystem @*/
    00231 {
    00232     fprintf(stdout, _("RPM version %s\n"), rpmEVR);
    00233 }
    00234
    00235 static void printBanner(void)
    00236         /*@globals fileSystem @*/
    00237         /*@modifies fileSystem @*/
    00238 {
    00239     (void) puts(_("Copyright (C) 1998-2000 - Red Hat, Inc."));
    00240     (void) puts(_("This program may be freely redistributed under the terms of the GNU GPL"));
    00241 }
    00242
    00243 static void printUsage(void)
    00244         /*@globals fileSystem @*/
    00245         /*@modifies fileSystem @*/
    00246 {
    00247     FILE * fp = stdout;
    00248     printVersion();
    00249     printBanner();
    00250     (void) puts("");
    00251
    00252     fprintf(fp, _("Usage: %s {--help}\n"), __progname);
    00253     fprintf(fp,   "       %s {--version}\n" , __progname);
    00254
    00255 #ifdef  IAM_RPMEIU
    00256 #ifdef  DYING
    00257 --dbpath        all
    00258 --ftpproxy etc  all
    00259 --force         alias for --replacepkgs --replacefiles
    00260 --includedocs   handle as option in table
    00261                 --erase forbids many options
    00262 #endif  /* DYING */
    00263 #endif  /* IAM_RPMEIU */
    00264
    00265 #ifdef  IAM_RPMQV
    00266 #ifdef  DYING   /* XXX popt glue needing --help doco. */
    00267 --dbpath        all
    00268 --ftpproxy etc  all
    00269 -i,--info       Q
    00270 -R,--requires   Q
    00271 -P,--provides   Q
    00272 --scripts       Q
    00273 --triggeredby   Q
    00274 --changelog     Q
    00275 --triggers      Q
    00276 --querytags     !V
    00277 --setperms      V
    00278 --setugids      V
    00279 #endif  /* DYING */
    00280 #endif  /* IAM_RPMQV */
    00281
    00282 }
    00283
    00284 int main(int argc, const char ** argv)
    00285 {
    00286     enum modes bigMode = MODE_UNKNOWN;
    00287
    00288 #ifdef  IAM_RPMQV
    00289     QVA_t qva = &rpmQVArgs;
    00290 #endif
    00291
    00292 #ifdef  IAM_RPMBT
    00293     BTA_t ba = &rpmBTArgs;
    00294 #endif
    00295
    00296 #ifdef  IAM_RPMEIU
    00297    struct rpmInstallArguments_s * ia = &rpmIArgs;
    00298 #endif
    00299
    00300 #if defined(IAM_RPMDB)
    00301    struct rpmDatabaseArguments_s * da = &rpmDBArgs;
    00302 #endif
    00303
    00304 #if defined(IAM_RPMK)
    00305    struct rpmSignArguments_s * ka = &rpmKArgs;
    00306 #endif
    00307
    00308 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
    00309     char * passPhrase = "";
    00310 #endif
    00311
    00312     int arg;
    00313     int gotDbpath = 0;
    00314
    00315     const char * optArg;
    00316     pid_t pipeChild = 0;
    00317     poptContext optCon;
    00318     int ec = 0;
    00319     int status;
    00320     int p[2];
    00321
    00322 #if HAVE_MCHECK_H && HAVE_MTRACE
    00323     mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
    00324 #endif
    00325     setprogname(argv[0]);       /* Retrofit glibc __progname */
    00326
    00327     /* XXX glibc churn sanity */
    00328     if (__progname == NULL) {
    00329         if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
    00330         else __progname = argv[0];
    00331     }
    00332
    00333     /* Set the major mode based on argv[0] */
    00334     /*@-nullpass@*/
    00335 #ifdef  IAM_RPMBT
    00336     if (!strcmp(__progname, "rpmb"))    bigMode = MODE_BUILD;
    00337     if (!strcmp(__progname, "rpmt"))    bigMode = MODE_TARBUILD;
    00338     if (!strcmp(__progname, "rpmbuild"))        bigMode = MODE_BUILD;
    00339 #endif
    00340 #ifdef  IAM_RPMQV
    00341     if (!strcmp(__progname, "rpmq"))    bigMode = MODE_QUERY;
    00342     if (!strcmp(__progname, "rpmv"))    bigMode = MODE_VERIFY;
    00343     if (!strcmp(__progname, "rpmquery"))        bigMode = MODE_QUERY;
    00344     if (!strcmp(__progname, "rpmverify"))       bigMode = MODE_VERIFY;
    00345 #endif
    00346 #ifdef  RPMEIU
    00347     if (!strcmp(__progname, "rpme"))    bigMode = MODE_ERASE;
    00348     if (!strcmp(__progname, "rpmi"))    bigMode = MODE_INSTALL;
    00349     if (!strcmp(__progname, "rpmu"))    bigMode = MODE_INSTALL;
    00350 #endif
    00351     /*@=nullpass@*/
    00352
    00353     /* set the defaults for the various command line options */
    00354     _ftp_debug = 0;
    00355
    00356 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
    00357     noLibio = 0;
    00358 #else
    00359     noLibio = 1;
    00360 #endif
    00361     _rpmio_debug = 0;
    00362     _url_debug = 0;
    00363
    00364     /* XXX Eliminate query linkage loop */
    00365     specedit = 0;
    00366     parseSpecVec = parseSpec;
    00367     freeSpecVec = freeSpec;
    00368
    00369     /* set up the correct locale */
    00370     (void) setlocale(LC_ALL, "" );
    00371
    00372 #ifdef  __LCLINT__
    00373 #define LOCALEDIR       "/usr/share/locale"
    00374 #endif
    00375     bindtextdomain(PACKAGE, LOCALEDIR);
    00376     textdomain(PACKAGE);
    00377
    00378     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
    00379
    00380     /* Make a first pass through the arguments, looking for --rcfile */
    00381     /* We need to handle that before dealing with the rest of the arguments. */
    00382     /*@-nullpass -temptrans@*/
    00383     optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
    00384     /*@=nullpass =temptrans@*/
    00385     (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
    00386     (void) poptReadDefaultConfig(optCon, 1);
    00387     poptSetExecPath(optCon, RPMCONFIGDIR, 1);
    00388
    00389     /* reading rcfile early makes it easy to override */
    00390     /* XXX only --rcfile (and --showrc) need this pre-parse */
    00391
    00392     while ((arg = poptGetNextOpt(optCon)) > 0) {
    00393         switch(arg) {
    00394         case 'v':
    00395             rpmIncreaseVerbosity();     /* XXX silly use by showrc */
    00396             break;
    00397         default:
    00398             break;
    00399       }
    00400     }
    00401
    00402     if (rpmReadConfigFiles(rcfile, NULL))
    00403         exit(EXIT_FAILURE);
    00404
    00405     if (showrc) {
    00406         (void) rpmShowRC(stdout);
    00407         exit(EXIT_SUCCESS);
    00408     }
    00409
    00410     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
    00411
    00412     poptResetContext(optCon);
    00413
    00414 #ifdef  IAM_RPMQV
    00415     qva->qva_queryFormat = _free(qva->qva_queryFormat);
    00416     memset(qva, 0, sizeof(*qva));
    00417     qva->qva_source = RPMQV_PACKAGE;
    00418     qva->qva_fflags = RPMFILE_ALL;
    00419     qva->qva_mode = ' ';
    00420     qva->qva_char = ' ';
    00421 #endif
    00422
    00423 #ifdef  IAM_RPMBT
    00424     ba->buildRootOverride = _free(ba->buildRootOverride);
    00425     ba->targets = _free(ba->targets);
    00426     memset(ba, 0, sizeof(*ba));
    00427     ba->buildMode = ' ';
    00428     ba->buildChar = ' ';
    00429 #endif
    00430
    00431 #ifdef  IAM_RPMDB
    00432     memset(da, 0, sizeof(*da));
    00433 #endif
    00434
    00435 #ifdef  IAM_RPMK
    00436     memset(ka, 0, sizeof(*ka));
    00437     ka->addSign = RESIGN_NONE;
    00438     ka->checksigFlags = CHECKSIG_ALL;
    00439 #endif
    00440
    00441 #ifdef  IAM_RPMEIU
    00442     ia->relocations = _free(ia->relocations);
    00443     memset(ia, 0, sizeof(*ia));
    00444     ia->transFlags = RPMTRANS_FLAG_NONE;
    00445     ia->probFilter = RPMPROB_FILTER_NONE;
    00446     ia->installInterfaceFlags = INSTALL_NONE;
    00447     ia->eraseInterfaceFlags = UNINSTALL_NONE;
    00448 #endif
    00449
    00450     while ((arg = poptGetNextOpt(optCon)) > 0) {
    00451         optArg = poptGetOptArg(optCon);
    00452
    00453         switch (arg) {
    00454
    00455         case 'v':
    00456             rpmIncreaseVerbosity();
    00457             break;
    00458
    00459 /* XXX options used in multiple rpm modes */
    00460 #if defined(IAM_RPMQV) || defined(IAM_RPMK)
    00461         case POPT_NOMD5:
    00462 #ifdef  IAM_RPMQV
    00463             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
    00464                 qva->qva_flags |= VERIFY_MD5;
    00465             else
    00466 #endif
    00467 #ifdef  IAM_RPMK
    00468             if (bigMode & MODES_K)
    00469                 ka->checksigFlags &= ~CHECKSIG_MD5;
    00470             else
    00471 #endif
    00472 #ifdef  IAM_RPMEIU
    00473             if (bigMode & MODES_IE)
    00474                 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
    00475             else
    00476 #endif
    00477                 {};
    00478             break;
    00479 #endif  /* IAM_RPMQV || IAM_RPMK */
    00480
    00481 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
    00482         case POPT_NODEPS:
    00483 #ifdef  IAM_RPMQV
    00484             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
    00485                 qva->qva_flags |= VERIFY_DEPS;
    00486             else
    00487 #endif
    00488 #ifdef  IAM_RPMEIU
    00489             if ((bigMode & MODES_IE) ||
    00490                 (ia->installInterfaceFlags &
    00491             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
    00492                 ia->noDeps = 1;
    00493             else
    00494 #endif
    00495 #ifdef  IAM_RPMBT
    00496             if ((bigMode & MODES_BT) || ba->buildMode != ' ')
    00497                 ba->noDeps = 1;
    00498             else
    00499 #endif
    00500                 /*@-ifempty@*/ ;
    00501             break;
    00502
    00503         case POPT_FORCE:
    00504 #ifdef  IAM_RPMEIU
    00505             if ((bigMode & MODES_IE) ||
    00506                 (ia->installInterfaceFlags &
    00507             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
    00508                 ia->probFilter |=
    00509                         ( RPMPROB_FILTER_REPLACEPKG
    00510                         | RPMPROB_FILTER_REPLACEOLDFILES
    00511                         | RPMPROB_FILTER_REPLACENEWFILES
    00512                         | RPMPROB_FILTER_OLDPACKAGE);
    00513             else
    00514 #endif
    00515 #ifdef  IAM_RPMBT
    00516             if ((bigMode & MODES_BT) || ba->buildMode != ' ')
    00517                 ba->force = 1;
    00518             else
    00519 #endif
    00520                 /*@-ifempty@*/ ;
    00521             break;
    00522
    00523         case 'i':
    00524 #ifdef  IAM_RPMQV
    00525             if (bigMode == MODE_QUERY || qva->qva_mode == 'q') {
    00526                 /*@-nullassign -readonlytrans@*/
    00527                 const char * infoCommand[] = { "--info", NULL };
    00528                 /*@=nullassign =readonlytrans@*/
    00529                 (void) poptStuffArgs(optCon, infoCommand);
    00530             } else
    00531 #endif
    00532 #ifdef  IAM_RPMEIU
    00533             if (bigMode == MODE_INSTALL ||
    00534                 (ia->installInterfaceFlags &
    00535                     (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)))
    00536                 /*@-ifempty@*/ ;
    00537             else if (bigMode == MODE_UNKNOWN) {
    00538                 /*@-nullassign -readonlytrans@*/
    00539                 const char * installCommand[] = { "--install", NULL };
    00540                 /*@=nullassign =readonlytrans@*/
    00541                 (void) poptStuffArgs(optCon, installCommand);
    00542             } else
    00543 #endif
    00544                 /*@-ifempty@*/ ;
    00545             break;
    00546
    00547         case POPT_NOSCRIPTS:
    00548 #ifdef  IAM_RPMQV
    00549             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
    00550                 qva->qva_flags |= VERIFY_SCRIPT;
    00551             else
    00552 #endif
    00553 #ifdef  IAM_RPMEIU
    00554             if ((bigMode & MODES_IE) ||
    00555                 (ia->installInterfaceFlags &
    00556             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
    00557                 ia->transFlags |= (_noTransScripts | _noTransTriggers);
    00558             else
    00559 #endif
    00560                 /*@-ifempty@*/ ;
    00561             break;
    00562
    00563 #endif  /* IAM_RPMQV || IAM_RPMEIU || IAM_RPMBT */
    00564
    00565         case GETOPT_DEFINEMACRO:
    00566             if (optArg) {
    00567                 (void) rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
    00568                 (void) rpmDefineMacro(rpmCLIMacroContext, optArg,RMIL_CMDLINE);
    00569             }
    00570             noUsageMsg = 1;
    00571             break;
    00572
    00573         case GETOPT_EVALMACRO:
    00574             if (optArg) {
    00575                 const char *val = rpmExpand(optArg, NULL);
    00576                 fprintf(stdout, "%s\n", val);
    00577                 val = _free(val);
    00578             }
    00579             noUsageMsg = 1;
    00580             break;
    00581
    00582 #if defined(GETOPT_RCFILE)
    00583         case GETOPT_RCFILE:
    00584             fprintf(stderr, _("The --rcfile option has been eliminated.\n"));
    00585             fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n"));
    00586             exit(EXIT_FAILURE);
    00587             /*@notreached@*/ break;
    00588 #endif
    00589
    00590         default:
    00591             fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
    00592             exit(EXIT_FAILURE);
    00593         }
    00594     }
    00595
    00596     if (quiet)
    00597         rpmSetVerbosity(RPMMESS_QUIET);
    00598
    00599     if (showVersion) printVersion();
    00600
    00601     if (arg < -1) {
    00602         fprintf(stderr, "%s: %s\n",
    00603                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
    00604                 poptStrerror(arg));
    00605         exit(EXIT_FAILURE);
    00606     }
    00607
    00608 #ifdef  IAM_RPMBT
    00609     switch (ba->buildMode) {
    00610     case 'b':   bigMode = MODE_BUILD;           break;
    00611     case 't':   bigMode = MODE_TARBUILD;        break;
    00612     case 'B':   bigMode = MODE_REBUILD;         break;
    00613     case 'C':   bigMode = MODE_RECOMPILE;       break;
    00614     }
    00615
    00616     if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
    00617         bigMode = MODE_BUILD;
    00618
    00619     if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
    00620         bigMode = MODE_BUILD;
    00621
    00622     if (ba->buildRootOverride && bigMode != MODE_BUILD &&
    00623         bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
    00624         argerror("--buildroot may only be used during package builds");
    00625     }
    00626 #endif  /* IAM_RPMBT */
    00627
    00628 #ifdef  IAM_RPMDB
    00629   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
    00630     if (da->init) {
    00631         if (bigMode != MODE_UNKNOWN)
    00632             argerror(_("only one major mode may be specified"));
    00633         else
    00634             bigMode = MODE_INITDB;
    00635     } else
    00636     if (da->rebuild) {
    00637         if (bigMode != MODE_UNKNOWN)
    00638             argerror(_("only one major mode may be specified"));
    00639         else
    00640             bigMode = MODE_REBUILDDB;
    00641     } else
    00642     if (da->verify) {
    00643         if (bigMode != MODE_UNKNOWN)
    00644             argerror(_("only one major mode may be specified"));
    00645         else
    00646             bigMode = MODE_VERIFYDB;
    00647     }
    00648   }
    00649 #endif  /* IAM_RPMDB */
    00650
    00651 #ifdef  IAM_RPMQV
    00652   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
    00653     switch (qva->qva_mode) {
    00654     case 'q':   bigMode = MODE_QUERY;           break;
    00655     case 'V':   bigMode = MODE_VERIFY;          break;
    00656     case 'Q':   bigMode = MODE_QUERYTAGS;       break;
    00657     }
    00658
    00659     if (qva->qva_sourceCount) {
    00660         if (qva->qva_sourceCount > 2)
    00661             argerror(_("one type of query/verify may be performed at a "
    00662                         "time"));
    00663     }
    00664     if (qva->qva_flags && (bigMode & ~MODES_QV))
    00665         argerror(_("unexpected query flags"));
    00666
    00667     if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
    00668         argerror(_("unexpected query format"));
    00669
    00670     if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
    00671         argerror(_("unexpected query source"));
    00672   }
    00673 #endif  /* IAM_RPMQV */
    00674
    00675 #ifdef  IAM_RPMEIU
    00676   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
    00677     {   int iflags = (ia->installInterfaceFlags &
    00678                 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
    00679         int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
    00680
    00681         if (iflags & eflags)
    00682             argerror(_("only one major mode may be specified"));
    00683         else if (iflags)
    00684             bigMode = MODE_INSTALL;
    00685         else if (eflags)
    00686             bigMode = MODE_ERASE;
    00687     }
    00688 #endif  /* IAM_RPMQV */
    00689
    00690 #ifdef  IAM_RPMK
    00691   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
    00692         switch (ka->addSign) {
    00693         case RESIGN_NONE:
    00694             break;
    00695         case RESIGN_CHK_SIGNATURE:
    00696             bigMode = MODE_CHECKSIG;
    00697             break;
    00698         case RESIGN_ADD_SIGNATURE:
    00699         case RESIGN_NEW_SIGNATURE:
    00700             bigMode = MODE_RESIGN;
    00701             break;
    00702
    00703         }
    00704   }
    00705 #endif  /* IAM_RPMK */
    00706
    00707     /* XXX TODO: never happens. */
    00708     if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
    00709         argerror(_("--dbpath given for operation that does not use a "
    00710                         "database"));
    00711
    00712 #if defined(IAM_RPMEIU)
    00713     if (!( bigMode == MODE_INSTALL ) &&
    00714 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
    00715         argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
    00716     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
    00717         argerror(_("files may only be relocated during package installation"));
    00718
    00719     if (ia->relocations && ia->prefix)
    00720         argerror(_("only one of --prefix or --relocate may be used"));
    00721
    00722     if (bigMode != MODE_INSTALL && ia->relocations)
    00723         argerror(_("--relocate and --excludepath may only be used when installing new packages"));
    00724
    00725     if (bigMode != MODE_INSTALL && ia->prefix)
    00726         argerror(_("--prefix may only be used when installing new packages"));
    00727
    00728     if (ia->prefix && ia->prefix[0] != '/')
    00729         argerror(_("arguments to --prefix must begin with a /"));
    00730
    00731     if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
    00732         argerror(_("--hash (-h) may only be specified during package "
    00733                         "installation"));
    00734
    00735     if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
    00736         argerror(_("--percent may only be specified during package "
    00737                         "installation"));
    00738
    00739     if (bigMode != MODE_INSTALL &&
    00740  (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
    00741         argerror(_("--replacefiles may only be specified during package "
    00742                         "installation"));
    00743
    00744     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
    00745         argerror(_("--replacepkgs may only be specified during package "
    00746                         "installation"));
    00747
    00748     if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
    00749         argerror(_("--excludedocs may only be specified during package "
    00750                    "installation"));
    00751
    00752     if (bigMode != MODE_INSTALL && ia->incldocs)
    00753         argerror(_("--includedocs may only be specified during package "
    00754                    "installation"));
    00755
    00756     if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
    00757         argerror(_("only one of --excludedocs and --includedocs may be "
    00758                  "specified"));
    00759
    00760     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
    00761         argerror(_("--ignorearch may only be specified during package "
    00762                    "installation"));
    00763
    00764     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
    00765         argerror(_("--ignoreos may only be specified during package "
    00766                    "installation"));
    00767
    00768     if (bigMode != MODE_INSTALL &&
    00769         (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
    00770         argerror(_("--ignoresize may only be specified during package "
    00771                    "installation"));
    00772
    00773     if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
    00774         argerror(_("--allmatches may only be specified during package "
    00775                    "erasure"));
    00776
    00777     if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
    00778         argerror(_("--allfiles may only be specified during package "
    00779                    "installation"));
    00780
    00781     if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
    00782         bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
    00783         argerror(_("--justdb may only be specified during package "
    00784                    "installation and erasure"));
    00785
    00786     if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
    00787         (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
    00788         argerror(_("script disabling options may only be specified during "
    00789                    "package installation and erasure"));
    00790
    00791     if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
    00792         (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
    00793         argerror(_("trigger disabling options may only be specified during "
    00794                    "package installation and erasure"));
    00795
    00796     if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
    00797         argerror(_("--nodeps may only be specified during package "
    00798                    "building, rebuilding, recompilation, installation,"
    00799                    "erasure, and verification"));
    00800
    00801     if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
    00802         argerror(_("--test may only be specified during package installation, "
    00803                  "erasure, and building"));
    00804 #endif  /* IAM_RPMEIU */
    00805
    00806     if (rootdir && rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
    00807         argerror(_("--root (-r) may only be specified during "
    00808                  "installation, erasure, querying, and "
    00809                  "database rebuilds"));
    00810
    00811     if (rootdir) {
    00812         switch (urlIsURL(rootdir)) {
    00813         default:
    00814             if (bigMode & MODES_FOR_ROOT)
    00815                 break;
    00816             /*@fallthrough@*/
    00817         case URL_IS_UNKNOWN:
    00818             if (rootdir[0] != '/')
    00819                 argerror(_("arguments to --root (-r) must begin with a /"));
    00820             break;
    00821         }
    00822     }
    00823
    00824 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
    00825     if (0
    00826 #if defined(IAM_RPMBT)
    00827     || ba->sign
    00828 #endif
    00829 #if defined(IAM_RPMK)
    00830     || ka->sign
    00831 #endif
    00832     ) {
    00833         if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
    00834             bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) {
    00835             const char ** av;
    00836             struct stat sb;
    00837             int errors = 0;
    00838
    00839             if ((av = poptGetArgs(optCon)) == NULL) {
    00840                 fprintf(stderr, _("no files to sign\n"));
    00841                 errors++;
    00842             } else
    00843             while (*av) {
    00844                 if (stat(*av, &sb)) {
    00845                     fprintf(stderr, _("cannot access file %s\n"), *av);
    00846                     errors++;
    00847                 }
    00848                 av++;
    00849             }
    00850
    00851             if (errors) {
    00852                 ec = errors;
    00853                 goto exit;
    00854             }
    00855
    00856             if (poptPeekArg(optCon)) {
    00857                 int sigTag;
    00858                 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
    00859                   case 0:
    00860                     break;
    00861                   case RPMSIGTAG_PGP:
    00862                     if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
    00863                         !rpmDetectPGPVersion(NULL)) {
    00864                         fprintf(stderr, _("pgp not found: "));
    00865                         ec = EXIT_FAILURE;
    00866                         goto exit;
    00867                     }   /*@fallthrough@*/
    00868                   case RPMSIGTAG_GPG:
    00869                     passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
    00870                     if (passPhrase == NULL) {
    00871                         fprintf(stderr, _("Pass phrase check failed\n"));
    00872                         ec = EXIT_FAILURE;
    00873                         goto exit;
    00874                     }
    00875                     fprintf(stderr, _("Pass phrase is good.\n"));
    00876                     passPhrase = xstrdup(passPhrase);
    00877                     break;
    00878                   default:
    00879                     fprintf(stderr,
    00880                             _("Invalid %%_signature spec in macro file.\n"));
    00881                     ec = EXIT_FAILURE;
    00882                     goto exit;
    00883                     /*@notreached@*/ break;
    00884                 }
    00885             }
    00886         } else {
    00887             argerror(_("--sign may only be used during package building"));
    00888         }
    00889     } else {
    00890         /* Make rpmLookupSignatureType() return 0 ("none") from now on */
    00891         (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
    00892     }
    00893 #endif  /* IAM_RPMBT || IAM_RPMK */
    00894
    00895     if (pipeOutput) {
    00896         (void) pipe(p);
    00897
    00898         if (!(pipeChild = fork())) {
    00899             (void) close(p[1]);
    00900             (void) dup2(p[0], STDIN_FILENO);
    00901             (void) close(p[0]);
    00902             (void) execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
    00903             fprintf(stderr, _("exec failed\n"));
    00904         }
    00905
    00906         (void) close(p[0]);
    00907         (void) dup2(p[1], STDOUT_FILENO);
    00908         (void) close(p[1]);
    00909     }
    00910
    00911     switch (bigMode) {
    00912 #ifdef  IAM_RPMDB
    00913     case MODE_INITDB:
    00914         (void) rpmdbInit(rootdir, 0644);
    00915         break;
    00916
    00917     case MODE_REBUILDDB:
    00918         ec = rpmdbRebuild(rootdir);
    00919         break;
    00920     case MODE_VERIFYDB:
    00921         ec = rpmdbVerify(rootdir);
    00922         break;
    00923 #endif  /* IAM_RPMDB */
    00924
    00925 #ifdef  IAM_RPMBT
    00926     case MODE_REBUILD:
    00927     case MODE_RECOMPILE:
    00928       { const char * pkg;
    00929         while (!rpmIsVerbose())
    00930             rpmIncreaseVerbosity();
    00931
    00932         if (!poptPeekArg(optCon))
    00933             argerror(_("no packages files given for rebuild"));
    00934
    00935         ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
    00936         if (bigMode == MODE_REBUILD) {
    00937             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
    00938             ba->buildAmount |= RPMBUILD_RMSOURCE;
    00939             ba->buildAmount |= RPMBUILD_RMSPEC;
    00940             ba->buildAmount |= RPMBUILD_CLEAN;
    00941             ba->buildAmount |= RPMBUILD_RMBUILD;
    00942         }
    00943
    00944         while ((pkg = poptGetArg(optCon))) {
    00945             const char * specFile = NULL;
    00946             char * cookie = NULL;
    00947
    00948             ec = rpmInstallSource("", pkg, &specFile, &cookie);
    00949             if (ec)
    00950                 /*@loopbreak@*/ break;
    00951
    00952             ba->rootdir = rootdir;
    00953             ec = build(specFile, ba, passPhrase, cookie, rcfile);
    00954             free(cookie);
    00955             cookie = NULL;
    00956             free((void *)specFile);
    00957             specFile = NULL;
    00958
    00959             if (ec)
    00960                 /*@loopbreak@*/ break;
    00961         }
    00962       } break;
    00963
    00964       case MODE_BUILD:
    00965       case MODE_TARBUILD:
    00966       { const char * pkg;
    00967         while (!rpmIsVerbose())
    00968             rpmIncreaseVerbosity();
    00969
    00970         switch (ba->buildChar) {
    00971         case 'a':
    00972             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
    00973             /*@fallthrough@*/
    00974         case 'b':
    00975             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
    00976             ba->buildAmount |= RPMBUILD_CLEAN;
    00977             /*@fallthrough@*/
    00978         case 'i':
    00979             ba->buildAmount |= RPMBUILD_INSTALL;
    00980             if ((ba->buildChar == 'i') && ba->shortCircuit)
    00981                 break;
    00982             /*@fallthrough@*/
    00983         case 'c':
    00984             ba->buildAmount |= RPMBUILD_BUILD;
    00985             if ((ba->buildChar == 'c') && ba->shortCircuit)
    00986                 break;
    00987             /*@fallthrough@*/
    00988         case 'p':
    00989             ba->buildAmount |= RPMBUILD_PREP;
    00990             break;
    00991
    00992         case 'l':
    00993             ba->buildAmount |= RPMBUILD_FILECHECK;
    00994             break;
    00995         case 's':
    00996             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
    00997             break;
    00998         }
    00999
    01000         if (!poptPeekArg(optCon)) {
    01001             if (bigMode == MODE_BUILD)
    01002                 argerror(_("no spec files given for build"));
    01003             else
    01004                 argerror(_("no tar files given for build"));
    01005         }
    01006
    01007         while ((pkg = poptGetArg(optCon))) {
    01008             ba->rootdir = rootdir;
    01009             ec = build(pkg, ba, passPhrase, NULL, rcfile);
    01010             if (ec)
    01011                 /*@loopbreak@*/ break;
    01012             rpmFreeMacros(NULL);
    01013             (void) rpmReadConfigFiles(rcfile, NULL);
    01014         }
    01015       } break;
    01016 #endif  /* IAM_RPMBT */
    01017
    01018 #ifdef  IAM_RPMEIU
    01019     case MODE_ERASE:
    01020         ia->rootdir = rootdir;
    01021         if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
    01022
    01023         if (!poptPeekArg(optCon)) {
    01024             if (ia->rbtid == 0)
    01025                 argerror(_("no packages given for erase"));
    01026 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
    01027 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
    01028             ec += rpmRollback(ia, NULL);
    01029         } else {
    01030             ec += rpmErase(rootdir, (const char **)poptGetArgs(optCon),
    01031                          ia->transFlags, ia->eraseInterfaceFlags);
    01032         }
    01033         break;
    01034
    01035     case MODE_INSTALL:
    01036         /* RPMTRANS_FLAG_BUILD_PROBS */
    01037         /* RPMTRANS_FLAG_KEEPOBSOLETE */
    01038         ia->rootdir = rootdir;
    01039         if (!ia->incldocs) {
    01040             if (ia->transFlags & RPMTRANS_FLAG_NODOCS)
    01041                 ;
    01042             else if (rpmExpandNumeric("%{_excludedocs}"))
    01043                 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
    01044         }
    01045
    01046         if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
    01047
    01048         /* we've already ensured !(!ia->prefix && !ia->relocations) */
    01049         if (ia->prefix) {
    01050             ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
    01051             ia->relocations[0].oldPath = NULL;   /* special case magic */
    01052             ia->relocations[0].newPath = ia->prefix;
    01053             ia->relocations[1].oldPath = ia->relocations[1].newPath = NULL;
    01054         } else if (ia->relocations) {
    01055             ia->relocations = xrealloc(ia->relocations,
    01056                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
    01057             ia->relocations[ia->numRelocations].oldPath = NULL;
    01058             ia->relocations[ia->numRelocations].newPath = NULL;
    01059         }
    01060
    01061         if (!poptPeekArg(optCon)) {
    01062             if (ia->rbtid == 0)
    01063                 argerror(_("no packages given for install"));
    01064 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
    01065 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
    01066             ec += rpmRollback(ia, NULL);
    01067         } else {
    01068
    01069             /*@-compdef@*/ /* FIX: ia->relocations[0].newPath undefined */
    01070             ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon),
    01071                         ia->transFlags, ia->installInterfaceFlags,
    01072                         ia->probFilter, ia->relocations);
    01073         }
    01074         /*@=compdef@*/
    01075         break;
    01076 #endif  /* IAM_RPMEIU */
    01077
    01078 #ifdef  IAM_RPMQV
    01079     case MODE_QUERY:
    01080       { const char * pkg;
    01081
    01082         qva->qva_prefix = rootdir;
    01083         if (qva->qva_source == RPMQV_ALL) {
    01084 #ifdef  DYING
    01085             if (poptPeekArg(optCon))
    01086                 argerror(_("extra arguments given for query of all packages"));
    01087 #else
    01088             const char ** av = poptGetArgs(optCon);
    01089 #endif
    01090             /*@-nullpass@*/     /* FIX: av can be NULL */
    01091             ec = rpmQuery(qva, RPMQV_ALL, (const char *) av);
    01092             /*@=nullpass@*/
    01093         } else {
    01094             if (!poptPeekArg(optCon))
    01095                 argerror(_("no arguments given for query"));
    01096             while ((pkg = poptGetArg(optCon)))
    01097                 ec += rpmQuery(qva, qva->qva_source, pkg);
    01098         }
    01099       } break;
    01100
    01101     case MODE_VERIFY:
    01102       { const char * pkg;
    01103         rpmVerifyFlags verifyFlags = VERIFY_ALL;
    01104
    01105         verifyFlags &= ~qva->qva_flags;
    01106         qva->qva_flags = (rpmQueryFlags) verifyFlags;
    01107         qva->qva_prefix = rootdir;
    01108
    01109         if (qva->qva_source == RPMQV_ALL) {
    01110             if (poptPeekArg(optCon))
    01111                 argerror(_("extra arguments given for verify of all packages"));
    01112             ec = rpmVerify(qva, RPMQV_ALL, NULL);
    01113         } else {
    01114             if (!poptPeekArg(optCon))
    01115                 argerror(_("no arguments given for verify"));
    01116             while ((pkg = poptGetArg(optCon)))
    01117                 ec += rpmVerify(qva, qva->qva_source, pkg);
    01118         }
    01119       } break;
    01120
    01121     case MODE_QUERYTAGS:
    01122         if (argc != 2)
    01123             argerror(_("unexpected arguments to --querytags "));
    01124
    01125         rpmDisplayQueryTags(stdout);
    01126         break;
    01127 #endif  /* IAM_RPMQV */
    01128
    01129 #ifdef IAM_RPMK
    01130     case MODE_CHECKSIG:
    01131         if (!poptPeekArg(optCon))
    01132             argerror(_("no packages given for signature check"));
    01133         ec = rpmCheckSig(ka->checksigFlags,
    01134                         (const char **)poptGetArgs(optCon));
    01135         /* XXX don't overflow single byte exit status */
    01136         if (ec > 255) ec = 255;
    01137         break;
    01138
    01139     case MODE_RESIGN:
    01140         if (!poptPeekArg(optCon))
    01141             argerror(_("no packages given for signing"));
    01142         ec = rpmReSign(ka->addSign, passPhrase,
    01143                         (const char **)poptGetArgs(optCon));
    01144         /* XXX don't overflow single byte exit status */
    01145         if (ec > 255) ec = 255;
    01146         break;
    01147 #endif  /* IAM_RPMK */
    01148
    01149 #if !defined(IAM_RPMQV)
    01150     case MODE_QUERY:
    01151     case MODE_VERIFY:
    01152     case MODE_QUERYTAGS:
    01153 #endif
    01154 #if !defined(IAM_RPMK)
    01155     case MODE_CHECKSIG:
    01156     case MODE_RESIGN:
    01157 #endif
    01158 #if !defined(IAM_RPMDB)
    01159     case MODE_INITDB:
    01160     case MODE_REBUILDDB:
    01161     case MODE_VERIFYDB:
    01162 #endif
    01163 #if !defined(IAM_RPMBT)
    01164     case MODE_BUILD:
    01165     case MODE_REBUILD:
    01166     case MODE_RECOMPILE:
    01167     case MODE_TARBUILD:
    01168 #endif
    01169 #if !defined(IAM_RPMEIU)
    01170     case MODE_INSTALL:
    01171     case MODE_ERASE:
    01172 #endif
    01173     case MODE_UNKNOWN:
    01174         if (!showVersion && !help && !noUsageMsg) printUsage();
    01175         break;
    01176     }
    01177
    01178 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
    01179 exit:
    01180 #endif  /* IAM_RPMBT || IAM_RPMK */
    01181     optCon = poptFreeContext(optCon);
    01182     rpmFreeMacros(NULL);
    01183     rpmFreeMacros(rpmCLIMacroContext);
    01184     rpmFreeRpmrc();
    01185
    01186     if (pipeChild) {
    01187         (void) fclose(stdout);
    01188         (void) waitpid(pipeChild, &status, 0);
    01189     }
    01190
    01191     /* keeps memory leak checkers quiet */
    01192     freeNames();
    01193     freeFilesystems();
    01194     urlFreeCache();
    01195     rpmlogClose();
    01196     dbiTags = _free(dbiTags);
    01197
    01198 #ifdef  IAM_RPMQV
    01199     qva->qva_queryFormat = _free(qva->qva_queryFormat);
    01200 #endif
    01201
    01202 #ifdef  IAM_RPMBT
    01203     ba->buildRootOverride = _free(ba->buildRootOverride);
    01204     ba->targets = _free(ba->targets);
    01205 #endif
    01206
    01207 #ifdef  IAM_RPMEIU
    01208     ia->relocations = _free(ia->relocations);
    01209 #endif
    01210
    01211 #if HAVE_MCHECK_H && HAVE_MTRACE
    01212     muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
    01213 #endif
    01214     /*@-globstate@*/
    01215     return ec;
    01216     /*@=globstate@*/
    01217 }