Main Page Modules Data Structures 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 #include "rpmdb.h"
    00017 #include "rpmps.h"
    00018 #include "rpmts.h"
    00019
    00020 #ifdef  IAM_RPMBT
    00021 #include "build.h"
    00022 #define GETOPT_REBUILD          1003
    00023 #define GETOPT_RECOMPILE        1004
    00024 #endif
    00025
    00026 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
    00027 #include "signature.h"
    00028 #endif
    00029
    00030 #include "debug.h"
    00031
    00032 enum modes {
    00033
    00034     MODE_QUERY          = (1 <<  0),
    00035     MODE_VERIFY         = (1 <<  3),
    00036 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
    00037
    00038     MODE_INSTALL        = (1 <<  1),
    00039     MODE_ERASE          = (1 <<  2),
    00040 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
    00041
    00042     MODE_BUILD          = (1 <<  4),
    00043     MODE_REBUILD        = (1 <<  5),
    00044     MODE_RECOMPILE      = (1 <<  8),
    00045     MODE_TARBUILD       = (1 << 11),
    00046 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
    00047
    00048     MODE_CHECKSIG       = (1 <<  6),
    00049     MODE_RESIGN         = (1 <<  7),
    00050 #define MODES_K  (MODE_CHECKSIG | MODE_RESIGN)
    00051
    00052     MODE_INITDB         = (1 << 10),
    00053     MODE_REBUILDDB      = (1 << 12),
    00054     MODE_VERIFYDB       = (1 << 13),
    00055 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB)
    00056
    00057
    00058     MODE_UNKNOWN        = 0
    00059 };
    00060
    00061 #define MODES_FOR_DBPATH        (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
    00062 #define MODES_FOR_NODEPS        (MODES_BT | MODES_IE | MODE_VERIFY)
    00063 #define MODES_FOR_TEST          (MODES_BT | MODES_IE)
    00064 #define MODES_FOR_ROOT          (MODES_BT | MODES_IE | MODES_QV | MODES_DB | MODES_K)
    00065
    00066 /* the structure describing the options we take and the defaults */
    00067 /*@unchecked@*/
    00068 static struct poptOption optionsTable[] = {
    00069
    00070 #ifdef  IAM_RPMQV
    00071  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
    00072         N_("Query options (with -q or --query):"),
    00073         NULL },
    00074  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
    00075         N_("Verify options (with -V or --verify):"),
    00076         NULL },
    00077 #endif  /* IAM_RPMQV */
    00078
    00079 #ifdef  IAM_RPMK
    00080  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
    00081         N_("Signature options:"),
    00082         NULL },
    00083 #endif  /* IAM_RPMK */
    00084
    00085 #ifdef  IAM_RPMDB
    00086  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
    00087         N_("Database options:"),
    00088         NULL },
    00089 #endif  /* IAM_RPMDB */
    00090
    00091 #ifdef  IAM_RPMBT
    00092  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
    00093         N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
    00094         NULL },
    00095 #endif  /* IAM_RPMBT */
    00096
    00097 #ifdef  IAM_RPMEIU
    00098  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
    00099         N_("Install/Upgrade/Erase options:"),
    00100         NULL },
    00101 #endif  /* IAM_RPMEIU */
    00102
    00103  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
    00104         N_("Common options for all rpm modes:"),
    00105         NULL },
    00106
    00107    POPT_AUTOALIAS
    00108    POPT_AUTOHELP
    00109    POPT_TABLEEND
    00110 };
    00111
    00112 #ifdef __MINT__
    00113 /* MiNT cannot dynamically increase the stack.  */
    00114 long _stksize = 64 * 1024L;
    00115 #endif
    00116
    00117 /*@exits@*/ static void argerror(const char * desc)
    00118         /*@globals __assert_program_name, fileSystem @*/
    00119         /*@modifies fileSystem @*/
    00120 {
    00121     fprintf(stderr, _("%s: %s\n"), __progname, desc);
    00122     exit(EXIT_FAILURE);
    00123 }
    00124
    00125 static void printVersion(FILE * fp)
    00126         /*@globals rpmEVR, fileSystem @*/
    00127         /*@modifies *fp, fileSystem @*/
    00128 {
    00129     fprintf(fp, _("RPM version %s\n"), rpmEVR);
    00130 }
    00131
    00132 static void printBanner(FILE * fp)
    00133         /*@globals fileSystem @*/
    00134         /*@modifies *fp, fileSystem @*/
    00135 {
    00136     fprintf(fp, _("Copyright (C) 1998-2002 - Red Hat, Inc.\n"));
    00137     fprintf(fp, _("This program may be freely redistributed under the terms of the GNU GPL\n"));
    00138 }
    00139
    00140 static void printUsage(poptContext con, FILE * fp, int flags)
    00141         /*@globals rpmEVR, fileSystem, internalState @*/
    00142         /*@modifies *fp, fileSystem, internalState @*/
    00143 {
    00144     printVersion(fp);
    00145     printBanner(fp);
    00146     fprintf(fp, "\n");
    00147
    00148     if (rpmIsVerbose())
    00149         poptPrintHelp(con, fp, flags);
    00150     else
    00151         poptPrintUsage(con, fp, flags);
    00152 }
    00153
    00154 /*@-bounds@*/ /* LCL: segfault */
    00155 /*@-mods@*/ /* FIX: shrug */
    00156 #if !defined(__GLIBC__) && !defined(__LCLINT__)
    00157 int main(int argc, const char ** argv, /*@unused@*/ char ** envp)
    00158 #else
    00159 int main(int argc, const char ** argv)
    00160 #endif
    00161         /*@globals __assert_program_name, rpmEVR, RPMVERSION,
    00162                 rpmGlobalMacroContext, rpmCLIMacroContext,
    00163                 fileSystem, internalState@*/
    00164         /*@modifies __assert_program_name,
    00165                 fileSystem, internalState@*/
    00166 {
    00167     rpmts ts = NULL;
    00168     enum modes bigMode = MODE_UNKNOWN;
    00169
    00170 #if defined(IAM_RPMQV)
    00171     QVA_t qva = &rpmQVKArgs;
    00172 #endif
    00173
    00174 #ifdef  IAM_RPMBT
    00175     BTA_t ba = &rpmBTArgs;
    00176 #endif
    00177
    00178 #ifdef  IAM_RPMEIU
    00179    struct rpmInstallArguments_s * ia = &rpmIArgs;
    00180 #endif
    00181
    00182 #if defined(IAM_RPMDB)
    00183    struct rpmDatabaseArguments_s * da = &rpmDBArgs;
    00184 #endif
    00185
    00186 #if defined(IAM_RPMK)
    00187    QVA_t ka = &rpmQVKArgs;
    00188 #endif
    00189
    00190 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
    00191     char * passPhrase = "";
    00192 #endif
    00193
    00194     int arg;
    00195
    00196     const char * optArg;
    00197     pid_t pipeChild = 0;
    00198     poptContext optCon;
    00199     int ec = 0;
    00200     int status;
    00201     int p[2];
    00202 #ifdef  IAM_RPMEIU
    00203     int i;
    00204 #endif
    00205
    00206 #if HAVE_MCHECK_H && HAVE_MTRACE
    00207     /*@-noeffect@*/
    00208     mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
    00209     /*@=noeffect@*/
    00210 #endif
    00211     setprogname(argv[0]);       /* Retrofit glibc __progname */
    00212
    00213 #if !defined(__GLIBC__) && !defined(__LCLINT__)
    00214     environ = envp;
    00215 #endif
    00216
    00217     /* XXX glibc churn sanity */
    00218     if (__progname == NULL) {
    00219         if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
    00220         else __progname = argv[0];
    00221     }
    00222
    00223     /* Set the major mode based on argv[0] */
    00224     /*@-nullpass@*/
    00225 #ifdef  IAM_RPMBT
    00226     if (!strcmp(__progname, "rpmb"))    bigMode = MODE_BUILD;
    00227     if (!strcmp(__progname, "lt-rpmb")) bigMode = MODE_BUILD;
    00228     if (!strcmp(__progname, "rpmt"))    bigMode = MODE_TARBUILD;
    00229     if (!strcmp(__progname, "rpmbuild"))        bigMode = MODE_BUILD;
    00230 #endif
    00231 #ifdef  IAM_RPMQV
    00232     if (!strcmp(__progname, "rpmq"))    bigMode = MODE_QUERY;
    00233     if (!strcmp(__progname, "lt-rpmq")) bigMode = MODE_QUERY;
    00234     if (!strcmp(__progname, "rpmv"))    bigMode = MODE_VERIFY;
    00235     if (!strcmp(__progname, "rpmquery"))        bigMode = MODE_QUERY;
    00236     if (!strcmp(__progname, "rpmverify"))       bigMode = MODE_VERIFY;
    00237 #endif
    00238 #ifdef  RPMEIU
    00239     if (!strcmp(__progname, "rpme"))    bigMode = MODE_ERASE;
    00240     if (!strcmp(__progname, "rpmi"))    bigMode = MODE_INSTALL;
    00241     if (!strcmp(__progname, "lt-rpmi")) bigMode = MODE_INSTALL;
    00242     if (!strcmp(__progname, "rpmu"))    bigMode = MODE_INSTALL;
    00243 #endif
    00244     /*@=nullpass@*/
    00245
    00246 #if defined(IAM_RPMQV)
    00247     /* Jumpstart option from argv[0] if necessary. */
    00248     switch (bigMode) {
    00249     case MODE_QUERY:    qva->qva_mode = 'q';    break;
    00250     case MODE_VERIFY:   qva->qva_mode = 'V';    break;
    00251     case MODE_CHECKSIG: qva->qva_mode = 'K';    break;
    00252     case MODE_RESIGN:   qva->qva_mode = 'R';    break;
    00253     case MODE_INSTALL:
    00254     case MODE_ERASE:
    00255     case MODE_BUILD:
    00256     case MODE_REBUILD:
    00257     case MODE_RECOMPILE:
    00258     case MODE_TARBUILD:
    00259     case MODE_INITDB:
    00260     case MODE_REBUILDDB:
    00261     case MODE_VERIFYDB:
    00262     case MODE_UNKNOWN:
    00263     default:
    00264         break;
    00265     }
    00266 #endif
    00267
    00268     /* XXX Eliminate query linkage loop */
    00269     /*@-type@*/ /* FIX: casts? */
    00270     parseSpecVec = parseSpec;
    00271     freeSpecVec = freeSpec;
    00272     /*@=type@*/
    00273
    00274     /* set up the correct locale */
    00275     (void) setlocale(LC_ALL, "" );
    00276
    00277 #ifdef  __LCLINT__
    00278 #define LOCALEDIR       "/usr/share/locale"
    00279 #endif
    00280     bindtextdomain(PACKAGE, LOCALEDIR);
    00281     textdomain(PACKAGE);
    00282
    00283     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
    00284
    00285     /* Make a first pass through the arguments, looking for --rcfile */
    00286     /* We need to handle that before dealing with the rest of the arguments. */
    00287     /*@-nullpass -temptrans@*/
    00288     optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
    00289     /*@=nullpass =temptrans@*/
    00290     (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
    00291     (void) poptReadDefaultConfig(optCon, 1);
    00292     poptSetExecPath(optCon, RPMCONFIGDIR, 1);
    00293
    00294     while ((arg = poptGetNextOpt(optCon)) > 0) {
    00295         optArg = poptGetOptArg(optCon);
    00296
    00297         switch (arg) {
    00298         default:
    00299             fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
    00300             exit(EXIT_FAILURE);
    00301         }
    00302     }
    00303
    00304     if (arg < -1) {
    00305         fprintf(stderr, "%s: %s\n",
    00306                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
    00307                 poptStrerror(arg));
    00308         exit(EXIT_FAILURE);
    00309     }
    00310
    00311     rpmcliConfigured();
    00312
    00313 #ifdef  IAM_RPMBT
    00314     switch (ba->buildMode) {
    00315     case 'b':   bigMode = MODE_BUILD;           break;
    00316     case 't':   bigMode = MODE_TARBUILD;        break;
    00317     case 'B':   bigMode = MODE_REBUILD;         break;
    00318     case 'C':   bigMode = MODE_RECOMPILE;       break;
    00319     }
    00320
    00321     if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
    00322         bigMode = MODE_BUILD;
    00323
    00324     if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
    00325         bigMode = MODE_BUILD;
    00326
    00327     if (ba->buildRootOverride && bigMode != MODE_BUILD &&
    00328         bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
    00329         argerror("--buildroot may only be used during package builds");
    00330     }
    00331 #endif  /* IAM_RPMBT */
    00332
    00333 #ifdef  IAM_RPMDB
    00334   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
    00335     if (da->init) {
    00336         if (bigMode != MODE_UNKNOWN)
    00337             argerror(_("only one major mode may be specified"));
    00338         else
    00339             bigMode = MODE_INITDB;
    00340     } else
    00341     if (da->rebuild) {
    00342         if (bigMode != MODE_UNKNOWN)
    00343             argerror(_("only one major mode may be specified"));
    00344         else
    00345             bigMode = MODE_REBUILDDB;
    00346     } else
    00347     if (da->verify) {
    00348         if (bigMode != MODE_UNKNOWN)
    00349             argerror(_("only one major mode may be specified"));
    00350         else
    00351             bigMode = MODE_VERIFYDB;
    00352     }
    00353   }
    00354 #endif  /* IAM_RPMDB */
    00355
    00356 #ifdef  IAM_RPMQV
    00357   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
    00358     switch (qva->qva_mode) {
    00359     case 'q':   bigMode = MODE_QUERY;           break;
    00360     case 'V':   bigMode = MODE_VERIFY;          break;
    00361     }
    00362
    00363     if (qva->qva_sourceCount) {
    00364         if (qva->qva_sourceCount > 2)
    00365             argerror(_("one type of query/verify may be performed at a "
    00366                         "time"));
    00367     }
    00368     if (qva->qva_flags && (bigMode & ~MODES_QV))
    00369         argerror(_("unexpected query flags"));
    00370
    00371     if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
    00372         argerror(_("unexpected query format"));
    00373
    00374     if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
    00375         argerror(_("unexpected query source"));
    00376   }
    00377 #endif  /* IAM_RPMQV */
    00378
    00379 #ifdef  IAM_RPMEIU
    00380   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
    00381     {   int iflags = (ia->installInterfaceFlags &
    00382                 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
    00383         int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
    00384
    00385         if (iflags & eflags)
    00386             argerror(_("only one major mode may be specified"));
    00387         else if (iflags)
    00388             bigMode = MODE_INSTALL;
    00389         else if (eflags)
    00390             bigMode = MODE_ERASE;
    00391     }
    00392 #endif  /* IAM_RPMQV */
    00393
    00394 #ifdef  IAM_RPMK
    00395   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
    00396         switch (ka->qva_mode) {
    00397         case RPMSIGN_NONE:
    00398             ka->sign = 0;
    00399             break;
    00400         case RPMSIGN_IMPORT_PUBKEY:
    00401         case RPMSIGN_CHK_SIGNATURE:
    00402             bigMode = MODE_CHECKSIG;
    00403             ka->sign = 0;
    00404             break;
    00405         case RPMSIGN_ADD_SIGNATURE:
    00406         case RPMSIGN_NEW_SIGNATURE:
    00407             bigMode = MODE_RESIGN;
    00408             ka->sign = 1;
    00409             break;
    00410         }
    00411   }
    00412 #endif  /* IAM_RPMK */
    00413
    00414 #if defined(IAM_RPMEIU)
    00415     if (!( bigMode == MODE_INSTALL ) &&
    00416 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
    00417         argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
    00418     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
    00419         argerror(_("files may only be relocated during package installation"));
    00420
    00421     if (ia->relocations && ia->prefix)
    00422         argerror(_("only one of --prefix or --relocate may be used"));
    00423
    00424     if (bigMode != MODE_INSTALL && ia->relocations)
    00425         argerror(_("--relocate and --excludepath may only be used when installing new packages"));
    00426
    00427     if (bigMode != MODE_INSTALL && ia->prefix)
    00428         argerror(_("--prefix may only be used when installing new packages"));
    00429
    00430     if (ia->prefix && ia->prefix[0] != '/')
    00431         argerror(_("arguments to --prefix must begin with a /"));
    00432
    00433     if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
    00434         argerror(_("--hash (-h) may only be specified during package "
    00435                         "installation"));
    00436
    00437     if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
    00438         argerror(_("--percent may only be specified during package "
    00439                         "installation"));
    00440
    00441     if (bigMode != MODE_INSTALL &&
    00442  (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
    00443         argerror(_("--replacefiles may only be specified during package "
    00444                         "installation"));
    00445
    00446     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
    00447         argerror(_("--replacepkgs may only be specified during package "
    00448                         "installation"));
    00449
    00450     if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
    00451         argerror(_("--excludedocs may only be specified during package "
    00452                    "installation"));
    00453
    00454     if (bigMode != MODE_INSTALL && ia->incldocs)
    00455         argerror(_("--includedocs may only be specified during package "
    00456                    "installation"));
    00457
    00458     if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
    00459         argerror(_("only one of --excludedocs and --includedocs may be "
    00460                  "specified"));
    00461
    00462     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
    00463         argerror(_("--ignorearch may only be specified during package "
    00464                    "installation"));
    00465
    00466     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
    00467         argerror(_("--ignoreos may only be specified during package "
    00468                    "installation"));
    00469
    00470     if (bigMode != MODE_INSTALL &&
    00471         (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
    00472         argerror(_("--ignoresize may only be specified during package "
    00473                    "installation"));
    00474
    00475     if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
    00476         argerror(_("--allmatches may only be specified during package "
    00477                    "erasure"));
    00478
    00479     if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
    00480         argerror(_("--allfiles may only be specified during package "
    00481                    "installation"));
    00482
    00483     if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
    00484         bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
    00485         argerror(_("--justdb may only be specified during package "
    00486                    "installation and erasure"));
    00487
    00488     if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
    00489         (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
    00490         argerror(_("script disabling options may only be specified during "
    00491                    "package installation and erasure"));
    00492
    00493     if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
    00494         (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
    00495         argerror(_("trigger disabling options may only be specified during "
    00496                    "package installation and erasure"));
    00497
    00498     if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
    00499         argerror(_("--nodeps may only be specified during package "
    00500                    "building, rebuilding, recompilation, installation,"
    00501                    "erasure, and verification"));
    00502
    00503     if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
    00504         argerror(_("--test may only be specified during package installation, "
    00505                  "erasure, and building"));
    00506 #endif  /* IAM_RPMEIU */
    00507
    00508     if (rpmcliRootDir && rpmcliRootDir[1] && (bigMode & ~MODES_FOR_ROOT))
    00509         argerror(_("--root (-r) may only be specified during "
    00510                  "installation, erasure, querying, and "
    00511                  "database rebuilds"));
    00512
    00513     if (rpmcliRootDir) {
    00514         switch (urlIsURL(rpmcliRootDir)) {
    00515         default:
    00516             if (bigMode & MODES_FOR_ROOT)
    00517                 break;
    00518             /*@fallthrough@*/
    00519         case URL_IS_UNKNOWN:
    00520             if (rpmcliRootDir[0] != '/')
    00521                 argerror(_("arguments to --root (-r) must begin with a /"));
    00522             break;
    00523         }
    00524     }
    00525
    00526 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
    00527     if (0
    00528 #if defined(IAM_RPMBT)
    00529     || ba->sign
    00530 #endif
    00531 #if defined(IAM_RPMK)
    00532     || ka->sign
    00533 #endif
    00534     )
    00535     /*@-branchstate@*/
    00536     {
    00537         if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
    00538             bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD)
    00539         {
    00540             const char ** av;
    00541             struct stat sb;
    00542             int errors = 0;
    00543
    00544             if ((av = poptGetArgs(optCon)) == NULL) {
    00545                 fprintf(stderr, _("no files to sign\n"));
    00546                 errors++;
    00547             } else
    00548             while (*av) {
    00549                 if (stat(*av, &sb)) {
    00550                     fprintf(stderr, _("cannot access file %s\n"), *av);
    00551                     errors++;
    00552                 }
    00553                 av++;
    00554             }
    00555
    00556             if (errors) {
    00557                 ec = errors;
    00558                 goto exit;
    00559             }
    00560
    00561             if (poptPeekArg(optCon)) {
    00562                 int sigTag;
    00563                 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
    00564                   case 0:
    00565                     break;
    00566                   case RPMSIGTAG_PGP:
    00567                     if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
    00568                         !rpmDetectPGPVersion(NULL)) {
    00569                         fprintf(stderr, _("pgp not found: "));
    00570                         ec = EXIT_FAILURE;
    00571                         goto exit;
    00572                     }   /*@fallthrough@*/
    00573                   case RPMSIGTAG_GPG:
    00574                     passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
    00575                     if (passPhrase == NULL) {
    00576                         fprintf(stderr, _("Pass phrase check failed\n"));
    00577                         ec = EXIT_FAILURE;
    00578                         goto exit;
    00579                     }
    00580                     fprintf(stderr, _("Pass phrase is good.\n"));
    00581                     passPhrase = xstrdup(passPhrase);
    00582                     break;
    00583                   default:
    00584                     fprintf(stderr,
    00585                             _("Invalid %%_signature spec in macro file.\n"));
    00586                     ec = EXIT_FAILURE;
    00587                     goto exit;
    00588                     /*@notreached@*/ break;
    00589                 }
    00590             }
    00591         } else {
    00592             argerror(_("--sign may only be used during package building"));
    00593         }
    00594     } else {
    00595         /* Make rpmLookupSignatureType() return 0 ("none") from now on */
    00596         (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
    00597     }
    00598     /*@=branchstate@*/
    00599 #endif  /* IAM_RPMBT || IAM_RPMK */
    00600
    00601     if (rpmcliPipeOutput) {
    00602         (void) pipe(p);
    00603
    00604         if (!(pipeChild = fork())) {
    00605             (void) close(p[1]);
    00606             (void) dup2(p[0], STDIN_FILENO);
    00607             (void) close(p[0]);
    00608             (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL);
    00609             fprintf(stderr, _("exec failed\n"));
    00610         }
    00611
    00612         (void) close(p[0]);
    00613         (void) dup2(p[1], STDOUT_FILENO);
    00614         (void) close(p[1]);
    00615     }
    00616
    00617     ts = rpmtsCreate();
    00618     (void) rpmtsSetRootDir(ts, rpmcliRootDir);
    00619     switch (bigMode) {
    00620 #ifdef  IAM_RPMDB
    00621     case MODE_INITDB:
    00622         (void) rpmtsInitDB(ts, 0644);
    00623         break;
    00624
    00625     case MODE_REBUILDDB:
    00626     {   rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
    00627         rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
    00628         ec = rpmtsRebuildDB(ts);
    00629         vsflags = rpmtsSetVSFlags(ts, ovsflags);
    00630     }   break;
    00631     case MODE_VERIFYDB:
    00632         ec = rpmtsVerifyDB(ts);
    00633         break;
    00634 #endif  /* IAM_RPMDB */
    00635
    00636 #ifdef  IAM_RPMBT
    00637     case MODE_REBUILD:
    00638     case MODE_RECOMPILE:
    00639     {   const char * pkg;
    00640
    00641         while (!rpmIsVerbose())
    00642             rpmIncreaseVerbosity();
    00643
    00644         if (!poptPeekArg(optCon))
    00645             argerror(_("no packages files given for rebuild"));
    00646
    00647         ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
    00648         if (bigMode == MODE_REBUILD) {
    00649             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
    00650             ba->buildAmount |= RPMBUILD_RMSOURCE;
    00651             ba->buildAmount |= RPMBUILD_RMSPEC;
    00652             ba->buildAmount |= RPMBUILD_CLEAN;
    00653             ba->buildAmount |= RPMBUILD_RMBUILD;
    00654         }
    00655
    00656         while ((pkg = poptGetArg(optCon))) {
    00657             const char * specFile = NULL;
    00658
    00659             ba->cookie = NULL;
    00660             ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
    00661             if (ec == 0) {
    00662                 ba->rootdir = rpmcliRootDir;
    00663                 ba->passPhrase = passPhrase;
    00664                 ec = build(ts, specFile, ba, rpmcliRcfile);
    00665             }
    00666             ba->cookie = _free(ba->cookie);
    00667             specFile = _free(specFile);
    00668
    00669             if (ec)
    00670                 /*@loopbreak@*/ break;
    00671         }
    00672
    00673     }   break;
    00674
    00675     case MODE_BUILD:
    00676     case MODE_TARBUILD:
    00677     {   const char * pkg;
    00678         while (!rpmIsVerbose())
    00679             rpmIncreaseVerbosity();
    00680
    00681         switch (ba->buildChar) {
    00682         case 'a':
    00683             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
    00684             /*@fallthrough@*/
    00685         case 'b':
    00686             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
    00687             ba->buildAmount |= RPMBUILD_CLEAN;
    00688             /*@fallthrough@*/
    00689         case 'i':
    00690             ba->buildAmount |= RPMBUILD_INSTALL;
    00691             if ((ba->buildChar == 'i') && ba->shortCircuit)
    00692                 /*@innerbreak@*/ break;
    00693             /*@fallthrough@*/
    00694         case 'c':
    00695             ba->buildAmount |= RPMBUILD_BUILD;
    00696             if ((ba->buildChar == 'c') && ba->shortCircuit)
    00697                 /*@innerbreak@*/ break;
    00698             /*@fallthrough@*/
    00699         case 'p':
    00700             ba->buildAmount |= RPMBUILD_PREP;
    00701             /*@innerbreak@*/ break;
    00702
    00703         case 'l':
    00704             ba->buildAmount |= RPMBUILD_FILECHECK;
    00705             /*@innerbreak@*/ break;
    00706         case 's':
    00707             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
    00708             /*@innerbreak@*/ break;
    00709         }
    00710
    00711         if (!poptPeekArg(optCon)) {
    00712             if (bigMode == MODE_BUILD)
    00713                 argerror(_("no spec files given for build"));
    00714             else
    00715                 argerror(_("no tar files given for build"));
    00716         }
    00717
    00718         while ((pkg = poptGetArg(optCon))) {
    00719             ba->rootdir = rpmcliRootDir;
    00720             ba->passPhrase = passPhrase;
    00721             ba->cookie = NULL;
    00722             ec = build(ts, pkg, ba, rpmcliRcfile);
    00723             if (ec)
    00724                 /*@loopbreak@*/ break;
    00725             rpmFreeMacros(NULL);
    00726             (void) rpmReadConfigFiles(rpmcliRcfile, NULL);
    00727         }
    00728     }   break;
    00729 #endif  /* IAM_RPMBT */
    00730
    00731 #ifdef  IAM_RPMEIU
    00732     case MODE_ERASE:
    00733         if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
    00734
    00735         if (!poptPeekArg(optCon)) {
    00736             if (ia->rbtid == 0)
    00737                 argerror(_("no packages given for erase"));
    00738 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
    00739 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
    00740             ec += rpmRollback(ts, ia, NULL);
    00741         } else {
    00742             ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon));
    00743         }
    00744         break;
    00745
    00746     case MODE_INSTALL:
    00747
    00748         /* RPMTRANS_FLAG_KEEPOBSOLETE */
    00749
    00750         if (!ia->incldocs) {
    00751             if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
    00752                 ;
    00753             } else if (rpmExpandNumeric("%{_excludedocs}"))
    00754                 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
    00755         }
    00756
    00757         if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
    00758
    00759         /* we've already ensured !(!ia->prefix && !ia->relocations) */
    00760         /*@-branchstate@*/
    00761         if (ia->prefix) {
    00762             ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
    00763             ia->relocations[0].oldPath = NULL;   /* special case magic */
    00764             ia->relocations[0].newPath = ia->prefix;
    00765             ia->relocations[1].oldPath = NULL;
    00766             ia->relocations[1].newPath = NULL;
    00767         } else if (ia->relocations) {
    00768             ia->relocations = xrealloc(ia->relocations,
    00769                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
    00770             ia->relocations[ia->numRelocations].oldPath = NULL;
    00771             ia->relocations[ia->numRelocations].newPath = NULL;
    00772         }
    00773         /*@=branchstate@*/
    00774
    00775         if (!poptPeekArg(optCon)) {
    00776             if (ia->rbtid == 0)
    00777                 argerror(_("no packages given for install"));
    00778 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
    00779 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
    00780 /*@i@*/     ec += rpmRollback(ts, ia, NULL);
    00781         } else {
    00782             /*@-compdef -compmempass@*/ /* FIX: ia->relocations[0].newPath undefined */
    00783             ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon));
    00784             /*@=compdef =compmempass@*/
    00785         }
    00786         break;
    00787
    00788 #endif  /* IAM_RPMEIU */
    00789
    00790 #ifdef  IAM_RPMQV
    00791     case MODE_QUERY:
    00792         if (qva->qva_source != RPMQV_ALL && !poptPeekArg(optCon))
    00793             argerror(_("no arguments given for query"));
    00794         ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon));
    00795         /* XXX don't overflow single byte exit status */
    00796         if (ec > 255) ec = 255;
    00797         break;
    00798
    00799     case MODE_VERIFY:
    00800     {   rpmVerifyFlags verifyFlags = VERIFY_ALL;
    00801
    00802         verifyFlags &= ~qva->qva_flags;
    00803         qva->qva_flags = (rpmQueryFlags) verifyFlags;
    00804
    00805         if (qva->qva_source != RPMQV_ALL && !poptPeekArg(optCon))
    00806             argerror(_("no arguments given for verify"));
    00807         ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon));
    00808         /* XXX don't overflow single byte exit status */
    00809         if (ec > 255) ec = 255;
    00810     }   break;
    00811 #endif  /* IAM_RPMQV */
    00812
    00813 #ifdef IAM_RPMK
    00814     case MODE_CHECKSIG:
    00815     {   rpmVerifyFlags verifyFlags =
    00816                 (VERIFY_MD5|VERIFY_DIGEST|VERIFY_SIGNATURE);
    00817
    00818         verifyFlags &= ~ka->qva_flags;
    00819         ka->qva_flags = (rpmQueryFlags) verifyFlags;
    00820     }   /*@fallthrough@*/
    00821     case MODE_RESIGN:
    00822         if (!poptPeekArg(optCon))
    00823             argerror(_("no arguments given"));
    00824         ka->passPhrase = passPhrase;
    00825         ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon));
    00826         /* XXX don't overflow single byte exit status */
    00827         if (ec > 255) ec = 255;
    00828         break;
    00829 #endif  /* IAM_RPMK */
    00830
    00831 #if !defined(IAM_RPMQV)
    00832     case MODE_QUERY:
    00833     case MODE_VERIFY:
    00834 #endif
    00835 #if !defined(IAM_RPMK)
    00836     case MODE_CHECKSIG:
    00837     case MODE_RESIGN:
    00838 #endif
    00839 #if !defined(IAM_RPMDB)
    00840     case MODE_INITDB:
    00841     case MODE_REBUILDDB:
    00842     case MODE_VERIFYDB:
    00843 #endif
    00844 #if !defined(IAM_RPMBT)
    00845     case MODE_BUILD:
    00846     case MODE_REBUILD:
    00847     case MODE_RECOMPILE:
    00848     case MODE_TARBUILD:
    00849 #endif
    00850 #if !defined(IAM_RPMEIU)
    00851     case MODE_INSTALL:
    00852     case MODE_ERASE:
    00853 #endif
    00854     case MODE_UNKNOWN:
    00855         if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose())
    00856             printUsage(optCon, stdout, 0);
    00857         break;
    00858     }
    00859
    00860 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
    00861 exit:
    00862 #endif  /* IAM_RPMBT || IAM_RPMK */
    00863
    00864     ts = rpmtsFree(ts);
    00865
    00866     optCon = poptFreeContext(optCon);
    00867     rpmFreeMacros(NULL);
    00868 /*@i@*/ rpmFreeMacros(rpmCLIMacroContext);
    00869     rpmFreeRpmrc();
    00870
    00871     if (pipeChild) {
    00872         (void) fclose(stdout);
    00873         (void) waitpid(pipeChild, &status, 0);
    00874     }
    00875
    00876     /* keeps memory leak checkers quiet */
    00877     freeNames();
    00878     freeFilesystems();
    00879 /*@i@*/ urlFreeCache();
    00880     rpmlogClose();
    00881     dbiTags = _free(dbiTags);
    00882
    00883 #ifdef  IAM_RPMQV
    00884     qva->qva_queryFormat = _free(qva->qva_queryFormat);
    00885 #endif
    00886
    00887 #ifdef  IAM_RPMBT
    00888     ba->buildRootOverride = _free(ba->buildRootOverride);
    00889     ba->targets = _free(ba->targets);
    00890 #endif
    00891
    00892 #ifdef  IAM_RPMEIU
    00893     if (ia->relocations != NULL)
    00894     for (i = 0; i < ia->numRelocations; i++)
    00895         ia->relocations[i].oldPath = _free(ia->relocations[i].oldPath);
    00896     ia->relocations = _free(ia->relocations);
    00897 #endif
    00898
    00899 #if HAVE_MCHECK_H && HAVE_MTRACE
    00900     /*@-noeffect@*/
    00901     muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
    00902     /*@=noeffect@*/
    00903 #endif
    00904     /*@-globstate@*/
    00905     return ec;
    00906     /*@=globstate@*/
    00907 }
    00908 /*@=mods@*/
    00909 /*@=bounds@*/