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

Generated on Fri Oct 12 08:44:55 2007 for rpm by  doxygen 1.5.2