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

rpmqv.c

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

Generated on Mon Nov 1 21:57:36 2004 for rpm by  doxygen 1.3.9.1