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

rpmqv.c

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

Generated on Sun Oct 26 13:02:04 2003 for rpm by doxygen1.2.18