rpmqv.c

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

Generated on Sun Jun 1 21:56:23 2008 for rpm by  doxygen 1.5.4