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) signal(SIGPIPE, SIG_DFL);
00618             (void) close(p[1]);
00619             (void) dup2(p[0], STDIN_FILENO);
00620             (void) close(p[0]);
00621             (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL);
00622             fprintf(stderr, _("exec failed\n"));
00623         }
00624 
00625         (void) close(p[0]);
00626         (void) dup2(p[1], STDOUT_FILENO);
00627         (void) close(p[1]);
00628     }
00629         
00630     ts = rpmtsCreate();
00631     (void) rpmtsSetRootDir(ts, rpmcliRootDir);
00632     switch (bigMode) {
00633 #ifdef  IAM_RPMDB
00634     case MODE_INITDB:
00635         ec = rpmtsInitDB(ts, 0644);
00636         break;
00637 
00638     case MODE_REBUILDDB:
00639     {   rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
00640         rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
00641         ec = rpmtsRebuildDB(ts);
00642         vsflags = rpmtsSetVSFlags(ts, ovsflags);
00643     }   break;
00644     case MODE_VERIFYDB:
00645         ec = rpmtsVerifyDB(ts);
00646         break;
00647 #endif  /* IAM_RPMDB */
00648 
00649 #ifdef  IAM_RPMBT
00650     case MODE_REBUILD:
00651     case MODE_RECOMPILE:
00652     {   const char * pkg;
00653 
00654         while (!rpmIsVerbose())
00655             rpmIncreaseVerbosity();
00656 
00657         if (!poptPeekArg(optCon))
00658             argerror(_("no packages files given for rebuild"));
00659 
00660         ba->buildAmount =
00661             RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL | RPMBUILD_CHECK;
00662         if (bigMode == MODE_REBUILD) {
00663             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00664             ba->buildAmount |= RPMBUILD_RMSOURCE;
00665             ba->buildAmount |= RPMBUILD_RMSPEC;
00666             ba->buildAmount |= RPMBUILD_CLEAN;
00667             ba->buildAmount |= RPMBUILD_RMBUILD;
00668         }
00669 
00670         while ((pkg = poptGetArg(optCon))) {
00671             const char * specFile = NULL;
00672 
00673             ba->cookie = NULL;
00674             ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
00675             if (ec == 0) {
00676                 ba->rootdir = rpmcliRootDir;
00677                 ba->passPhrase = passPhrase;
00678                 ec = build(ts, specFile, ba, rpmcliRcfile);
00679             }
00680             ba->cookie = _free(ba->cookie);
00681             specFile = _free(specFile);
00682 
00683             if (ec)
00684                 /*@loopbreak@*/ break;
00685         }
00686 
00687     }   break;
00688 
00689     case MODE_BUILD:
00690     case MODE_TARBUILD:
00691     {   const char * pkg;
00692         if (!quiet) while (!rpmIsVerbose())
00693             rpmIncreaseVerbosity();
00694        
00695         switch (ba->buildChar) {
00696         case 'a':
00697             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00698             /*@fallthrough@*/
00699         case 'b':
00700             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00701             ba->buildAmount |= RPMBUILD_CLEAN;
00702             /*@fallthrough@*/
00703         case 'i':
00704             ba->buildAmount |= RPMBUILD_INSTALL;
00705             ba->buildAmount |= RPMBUILD_CHECK;
00706             if ((ba->buildChar == 'i') && ba->shortCircuit)
00707                 /*@innerbreak@*/ break;
00708             /*@fallthrough@*/
00709         case 'c':
00710             ba->buildAmount |= RPMBUILD_BUILD;
00711             if ((ba->buildChar == 'c') && ba->shortCircuit)
00712                 /*@innerbreak@*/ break;
00713             /*@fallthrough@*/
00714         case 'p':
00715             ba->buildAmount |= RPMBUILD_PREP;
00716             /*@innerbreak@*/ break;
00717             
00718         case 'l':
00719             ba->buildAmount |= RPMBUILD_FILECHECK;
00720             /*@innerbreak@*/ break;
00721         case 's':
00722             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00723             /*@innerbreak@*/ break;
00724         }
00725 
00726         if (!poptPeekArg(optCon)) {
00727             if (bigMode == MODE_BUILD)
00728                 argerror(_("no spec files given for build"));
00729             else
00730                 argerror(_("no tar files given for build"));
00731         }
00732 
00733         while ((pkg = poptGetArg(optCon))) {
00734             ba->rootdir = rpmcliRootDir;
00735             ba->passPhrase = passPhrase;
00736             ba->cookie = NULL;
00737             ec = build(ts, pkg, ba, rpmcliRcfile);
00738             if (ec)
00739                 /*@loopbreak@*/ break;
00740             rpmFreeMacros(NULL);
00741             (void) rpmReadConfigFiles(rpmcliRcfile, NULL);
00742         }
00743     }   break;
00744 #endif  /* IAM_RPMBT */
00745 
00746 #ifdef  IAM_RPMEIU
00747     case MODE_ERASE:
00748         if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
00749 
00750         if (!poptPeekArg(optCon)) {
00751             if (ia->rbtid == 0)
00752                 argerror(_("no packages given for erase"));
00753 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
00754 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
00755             ec += rpmRollback(ts, ia, NULL);
00756         } else {
00757             ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon));
00758         }
00759         break;
00760 
00761     case MODE_INSTALL:
00762 
00763         /* RPMTRANS_FLAG_KEEPOBSOLETE */
00764 
00765         if (!ia->incldocs) {
00766             if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
00767                 ;
00768             } else if (rpmExpandNumeric("%{_excludedocs}"))
00769                 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
00770         }
00771 
00772         if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
00773 
00774         /* we've already ensured !(!ia->prefix && !ia->relocations) */
00775         /*@-branchstate@*/
00776         if (ia->prefix) {
00777             ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
00778             ia->relocations[0].oldPath = NULL;   /* special case magic */
00779             ia->relocations[0].newPath = ia->prefix;
00780             ia->relocations[1].oldPath = NULL;
00781             ia->relocations[1].newPath = NULL;
00782         } else if (ia->relocations) {
00783             ia->relocations = xrealloc(ia->relocations, 
00784                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
00785             ia->relocations[ia->numRelocations].oldPath = NULL;
00786             ia->relocations[ia->numRelocations].newPath = NULL;
00787         }
00788         /*@=branchstate@*/
00789 
00790         if (!poptPeekArg(optCon)) {
00791             if (ia->rbtid == 0)
00792                 argerror(_("no packages given for install"));
00793 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
00794 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
00795 /*@i@*/     ec += rpmRollback(ts, ia, NULL);
00796         } else {
00797             /*@-compdef -compmempass@*/ /* FIX: ia->relocations[0].newPath undefined */
00798             ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon));
00799             /*@=compdef =compmempass@*/
00800         }
00801         break;
00802 
00803 #endif  /* IAM_RPMEIU */
00804 
00805 #ifdef  IAM_RPMQV
00806     case MODE_QUERY:
00807         if (!poptPeekArg(optCon)
00808          && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST))
00809             argerror(_("no arguments given for query"));
00810 
00811         qva->qva_specQuery = rpmspecQuery;
00812         ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon));
00813         qva->qva_specQuery = NULL;
00814         break;
00815 
00816     case MODE_VERIFY:
00817     {   rpmVerifyFlags verifyFlags = VERIFY_ALL;
00818 
00819         verifyFlags &= ~qva->qva_flags;
00820         qva->qva_flags = (rpmQueryFlags) verifyFlags;
00821 
00822         if (!poptPeekArg(optCon)
00823          && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST))
00824             argerror(_("no arguments given for verify"));
00825         ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon));
00826     }   break;
00827 #endif  /* IAM_RPMQV */
00828 
00829 #ifdef IAM_RPMK
00830     case MODE_CHECKSIG:
00831     {   rpmVerifyFlags verifyFlags =
00832                 (VERIFY_MD5|VERIFY_DIGEST|VERIFY_SIGNATURE);
00833 
00834         verifyFlags &= ~ka->qva_flags;
00835         ka->qva_flags = (rpmQueryFlags) verifyFlags;
00836     }   /*@fallthrough@*/
00837     case MODE_RESIGN:
00838         if (!poptPeekArg(optCon))
00839             argerror(_("no arguments given"));
00840         ka->passPhrase = passPhrase;
00841         ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon));
00842         break;
00843 #endif  /* IAM_RPMK */
00844         
00845 #if !defined(IAM_RPMQV)
00846     case MODE_QUERY:
00847     case MODE_VERIFY:
00848 #endif
00849 #if !defined(IAM_RPMK)
00850     case MODE_CHECKSIG:
00851     case MODE_RESIGN:
00852 #endif
00853 #if !defined(IAM_RPMDB)
00854     case MODE_INITDB:
00855     case MODE_REBUILDDB:
00856     case MODE_VERIFYDB:
00857 #endif
00858 #if !defined(IAM_RPMBT)
00859     case MODE_BUILD:
00860     case MODE_REBUILD:
00861     case MODE_RECOMPILE:
00862     case MODE_TARBUILD:
00863 #endif
00864 #if !defined(IAM_RPMEIU)
00865     case MODE_INSTALL:
00866     case MODE_ERASE:
00867 #endif
00868     case MODE_UNKNOWN:
00869         if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
00870             printUsage(optCon, stderr, 0);
00871             ec = argc;
00872         }
00873         break;
00874     }
00875 
00876 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00877 exit:
00878 #endif  /* IAM_RPMBT || IAM_RPMK */
00879 
00880     ts = rpmtsFree(ts);
00881 
00882     optCon = poptFreeContext(optCon);
00883     rpmFreeMacros(NULL);
00884 /*@i@*/ rpmFreeMacros(rpmCLIMacroContext);
00885     rpmFreeRpmrc();
00886 
00887     if (pipeChild) {
00888         (void) fclose(stdout);
00889         (void) waitpid(pipeChild, &status, 0);
00890     }
00891 
00892     /* keeps memory leak checkers quiet */
00893     freeFilesystems();
00894 /*@i@*/ urlFreeCache();
00895     rpmlogClose();
00896     dbiTags = _free(dbiTags);
00897 
00898 #ifdef  IAM_RPMQV
00899     qva->qva_queryFormat = _free(qva->qva_queryFormat);
00900 #endif
00901 
00902 #ifdef  IAM_RPMBT
00903     freeNames();
00904     ba->buildRootOverride = _free(ba->buildRootOverride);
00905     ba->targets = _free(ba->targets);
00906 #endif
00907 
00908 #ifdef  IAM_RPMEIU
00909     if (ia->relocations != NULL)
00910     for (i = 0; i < ia->numRelocations; i++)
00911         ia->relocations[i].oldPath = _free(ia->relocations[i].oldPath);
00912     ia->relocations = _free(ia->relocations);
00913 #endif
00914 
00915 #if HAVE_MCHECK_H && HAVE_MTRACE
00916     /*@-noeffect@*/
00917     muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
00918     /*@=noeffect@*/
00919 #endif
00920 
00921     /* XXX Avoid exit status overflow. Status 255 is special to xargs(1) */
00922     if (ec > 254) ec = 254;
00923 
00924     /*@-globstate@*/
00925     return ec;
00926     /*@=globstate@*/
00927 }
00928 /*@=mods@*/
00929 /*@=bounds@*/

Generated on Wed Sep 8 11:10:32 2010 for rpm by  doxygen 1.4.7