rpm  4.5
rpmqv.c
Go to the documentation of this file.
1 #include "system.h"
2 extern const char *__progname;
3 
4 #define _AUTOHELP
5 
6 #if defined(IAM_RPM) || defined(__LCLINT__)
7 #define IAM_RPMBT
8 #define IAM_RPMDB
9 #define IAM_RPMEIU
10 #define IAM_RPMQV
11 #define IAM_RPMK
12 #endif
13 
14 #include <rpmcli.h>
15 #include <rpmbuild.h>
16 
17 #include "rpmdb.h"
18 #include "rpmps.h"
19 #include "rpmts.h"
20 
21 #include "rpmlua.h" /* XXX for rpmluaFree() */
22 
23 #include "fs.h" /* XXX for rpmFreeFilesystems() */
24 
25 #ifdef IAM_RPMBT
26 #include "build.h"
27 #define GETOPT_REBUILD 1003
28 #define GETOPT_RECOMPILE 1004
29 #endif
30 
31 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
32 #include "signature.h"
33 #endif
34 
35 #include "debug.h"
36 
37 enum modes {
38 
39  MODE_QUERY = (1 << 0),
40  MODE_VERIFY = (1 << 3),
41 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
42 
43  MODE_INSTALL = (1 << 1),
44  MODE_ERASE = (1 << 2),
45 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
46 
47  MODE_BUILD = (1 << 4),
48  MODE_REBUILD = (1 << 5),
49  MODE_RECOMPILE = (1 << 8),
50  MODE_TARBUILD = (1 << 11),
51 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
52 
53  MODE_CHECKSIG = (1 << 6),
54  MODE_RESIGN = (1 << 7),
55 #define MODES_K (MODE_CHECKSIG | MODE_RESIGN)
56 
57  MODE_INITDB = (1 << 10),
58  MODE_REBUILDDB = (1 << 12),
59  MODE_VERIFYDB = (1 << 13),
61 
62 
64 };
65 
66 #define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
67 #define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY)
68 #define MODES_FOR_TEST (MODES_BT | MODES_IE)
69 #define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB | MODES_K)
70 
71 static int quiet;
72 
73 /* the structure describing the options we take and the defaults */
74 /*@unchecked@*/
75 static struct poptOption optionsTable[] = {
76 
77 #ifdef IAM_RPMQV
78  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
79  N_("Query options (with -q or --query):"),
80  NULL },
81  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
82  N_("Verify options (with -V or --verify):"),
83  NULL },
84 #ifdef NOTYET
85  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliQVSourcePoptTable, 0,
86  N_("Source options (with --query or --verify):"),
87  NULL },
88 #endif
89 #endif /* IAM_RPMQV */
90 
91 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU)
92  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliDepFlagsPoptTable, 0,
93  N_("Dependency check/order options:"),
94  NULL },
95 #endif /* IAM_RPMQV */
96 
97 #ifdef IAM_RPMQV
98  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliFtsPoptTable, 0,
99  N_("File tree walk options (with --ftswalk):"),
100  NULL },
101 #endif /* IAM_RPMQV */
102 
103 #ifdef IAM_RPMK
104  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
105  N_("Signature options:"),
106  NULL },
107 #endif /* IAM_RPMK */
108 
109 #ifdef IAM_RPMDB
110  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
111  N_("Database options:"),
112  NULL },
113 #endif /* IAM_RPMDB */
114 
115 #ifdef IAM_RPMBT
116  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
117  N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
118  NULL },
119 #endif /* IAM_RPMBT */
120 
121 #ifdef IAM_RPMEIU
122  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
123  N_("Install/Upgrade/Erase options:"),
124  NULL },
125 #endif /* IAM_RPMEIU */
126 
127  { "quiet", '\0', 0, &quiet, 0, NULL, NULL},
128 
129  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
130  N_("Common options for all rpm modes and executables:"),
131  NULL },
132 
133  POPT_AUTOALIAS
134  POPT_AUTOHELP
135  POPT_TABLEEND
136 };
137 
138 #ifdef __MINT__
139 /* MiNT cannot dynamically increase the stack. */
140 long _stksize = 64 * 1024L;
141 #endif
142 
143 /*@exits@*/ static void argerror(const char * desc)
144  /*@globals __assert_program_name, fileSystem @*/
145  /*@modifies fileSystem @*/
146 {
147  fprintf(stderr, _("%s: %s\n"), __progname, desc);
148  exit(EXIT_FAILURE);
149 }
150 
151 static void printVersion(FILE * fp)
152  /*@globals rpmEVR, fileSystem @*/
153  /*@modifies *fp, fileSystem @*/
154 {
155  fprintf(fp, _("RPM version %s\n"), rpmEVR);
156 }
157 
158 static void printBanner(FILE * fp)
159  /*@globals fileSystem @*/
160  /*@modifies *fp, fileSystem @*/
161 {
162  fprintf(fp, _("Copyright (C) 1998-2002 - Red Hat, Inc.\n"));
163  fprintf(fp, _("This program may be freely redistributed under the terms of the GNU GPL\n"));
164 }
165 
166 static void printUsage(poptContext con, FILE * fp, int flags)
167  /*@globals rpmEVR, fileSystem, internalState @*/
168  /*@modifies *fp, fileSystem, internalState @*/
169 {
170  printVersion(fp);
171  printBanner(fp);
172  fprintf(fp, "\n");
173 
174  if (rpmIsVerbose())
175  poptPrintHelp(con, fp, flags);
176  else
177  poptPrintUsage(con, fp, flags);
178 }
179 
180 /*@-bounds@*/ /* LCL: segfault */
181 /*@-mods@*/ /* FIX: shrug */
182 #if !defined(__GLIBC__) && !defined(__LCLINT__)
183 int main(int argc, const char ** argv, /*@unused@*/ char ** envp)
184 #else
185 int main(int argc, const char ** argv)
186 #endif
187  /*@globals rpmRcfiles, rpmEVR, RPMVERSION,
188  rpmGlobalMacroContext, rpmCLIMacroContext,
189  h_errno, fileSystem, internalState@*/
190  /*@modifies fileSystem, internalState@*/
191 {
192  poptContext optCon = rpmcliInit(argc, (char *const *)argv, optionsTable);
193 
194  rpmts ts = NULL;
195  enum modes bigMode = MODE_UNKNOWN;
196 
197 #if defined(IAM_RPMQV)
198  QVA_t qva = &rpmQVKArgs;
199 #endif
200 
201 #ifdef IAM_RPMBT
202  BTA_t ba = &rpmBTArgs;
203 #endif
204 
205 #ifdef IAM_RPMEIU
206  QVA_t ia = &rpmIArgs;
207 #endif
208 
209 #if defined(IAM_RPMDB)
210  QVA_t da = &rpmDBArgs;
211 #endif
212 
213 #if defined(IAM_RPMK)
214  QVA_t ka = &rpmQVKArgs;
215 #endif
216 
217 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
218  char * passPhrase = "";
219 #endif
220 
221  pid_t pipeChild = 0;
222  int ec = 0;
223  int status;
224  int p[2];
225 #ifdef IAM_RPMEIU
226  int i;
227 #endif
228 
229 #if !defined(__GLIBC__) && !defined(__LCLINT__)
230  environ = envp;
231 #endif
232 
233  /* Set the major mode based on argv[0] */
234  /*@-nullpass@*/
235 #ifdef IAM_RPMBT
236  if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD;
237  if (!strcmp(__progname, "lt-rpmb")) bigMode = MODE_BUILD;
238  if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD;
239  if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD;
240 #endif
241 #ifdef IAM_RPMQV
242  if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY;
243  if (!strcmp(__progname, "lt-rpmq")) bigMode = MODE_QUERY;
244  if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY;
245  if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY;
246  if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY;
247 #endif
248 #ifdef RPMEIU
249  if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE;
250  if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL;
251  if (!strcmp(__progname, "lt-rpmi")) bigMode = MODE_INSTALL;
252  if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL;
253 #endif
254  /*@=nullpass@*/
255 
256 #if defined(IAM_RPMQV)
257  /* Jumpstart option from argv[0] if necessary. */
258  switch (bigMode) {
259  case MODE_QUERY: qva->qva_mode = 'q'; break;
260  case MODE_VERIFY: qva->qva_mode = 'V'; break;
261  case MODE_CHECKSIG: qva->qva_mode = 'K'; break;
262  case MODE_RESIGN: qva->qva_mode = 'R'; break;
263  case MODE_INSTALL:
264  case MODE_ERASE:
265  case MODE_BUILD:
266  case MODE_REBUILD:
267  case MODE_RECOMPILE:
268  case MODE_TARBUILD:
269  case MODE_INITDB:
270  case MODE_REBUILDDB:
271  case MODE_VERIFYDB:
272  case MODE_UNKNOWN:
273  default:
274  break;
275  }
276 #endif
277 
279 
280 #ifdef IAM_RPMBT
281  switch (ba->buildMode) {
282  case 'b': bigMode = MODE_BUILD; break;
283  case 't': bigMode = MODE_TARBUILD; break;
284  case 'B': bigMode = MODE_REBUILD; break;
285  case 'C': bigMode = MODE_RECOMPILE; break;
286  }
287 
288  if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
289  bigMode = MODE_BUILD;
290 
291  if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
292  bigMode = MODE_BUILD;
293 #endif /* IAM_RPMBT */
294 
295 #ifdef IAM_RPMDB
296  if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
297  if (da->init) {
298  if (bigMode != MODE_UNKNOWN)
299  argerror(_("only one major mode may be specified"));
300  else
301  bigMode = MODE_INITDB;
302  } else
303  if (da->rebuild) {
304  if (bigMode != MODE_UNKNOWN)
305  argerror(_("only one major mode may be specified"));
306  else
307  bigMode = MODE_REBUILDDB;
308  } else
309  if (da->verify) {
310  if (bigMode != MODE_UNKNOWN)
311  argerror(_("only one major mode may be specified"));
312  else
313  bigMode = MODE_VERIFYDB;
314  }
315  }
316 #endif /* IAM_RPMDB */
317 
318 #ifdef IAM_RPMQV
319  if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
320  switch (qva->qva_mode) {
321  case 'q': bigMode = MODE_QUERY; break;
322  case 'V': bigMode = MODE_VERIFY; break;
323  }
324 
325  if (qva->qva_sourceCount) {
326  if (qva->qva_sourceCount > 2)
327  argerror(_("one type of query/verify may be performed at a "
328  "time"));
329  }
330  if (qva->qva_flags && (bigMode & ~MODES_QV))
331  argerror(_("unexpected query flags"));
332 
333  if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
334  argerror(_("unexpected query format"));
335 
336  if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
337  argerror(_("unexpected query source"));
338  }
339 #endif /* IAM_RPMQV */
340 
341 #ifdef IAM_RPMEIU
342  if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
343  { int iflags = (ia->installInterfaceFlags &
345  int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
346 
347  if (iflags & eflags)
348  argerror(_("only one major mode may be specified"));
349  else if (iflags)
350  bigMode = MODE_INSTALL;
351  else if (eflags)
352  bigMode = MODE_ERASE;
353  }
354 #endif /* IAM_RPMEIU */
355 
356 #ifdef IAM_RPMK
357  if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
358  switch (ka->qva_mode) {
359  case RPMSIGN_NONE:
360  ka->sign = 0;
361  break;
364  bigMode = MODE_CHECKSIG;
365  ka->sign = 0;
366  break;
370  bigMode = MODE_RESIGN;
371  ka->sign = (ka->qva_mode != RPMSIGN_DEL_SIGNATURE);
372  break;
373  }
374  }
375 #endif /* IAM_RPMK */
376 
377 #if defined(IAM_RPMEIU)
378  if (!( bigMode == MODE_INSTALL ) &&
380  argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
381  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
382  argerror(_("files may only be relocated during package installation"));
383 
384  if (ia->relocations && ia->qva_prefix)
385  argerror(_("cannot use --prefix with --relocate or --excludepath"));
386 
387  if (bigMode != MODE_INSTALL && ia->relocations)
388  argerror(_("--relocate and --excludepath may only be used when installing new packages"));
389 
390  if (bigMode != MODE_INSTALL && ia->qva_prefix)
391  argerror(_("--prefix may only be used when installing new packages"));
392 
393  if (ia->qva_prefix && ia->qva_prefix[0] != '/')
394  argerror(_("arguments to --prefix must begin with a /"));
395 
396  if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
397  argerror(_("--hash (-h) may only be specified during package "
398  "installation"));
399 
400  if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
401  argerror(_("--percent may only be specified during package "
402  "installation"));
403 
404  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
405  argerror(_("--replacepkgs may only be specified during package "
406  "installation"));
407 
408  if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
409  argerror(_("--excludedocs may only be specified during package "
410  "installation"));
411 
412  if (bigMode != MODE_INSTALL && ia->incldocs)
413  argerror(_("--includedocs may only be specified during package "
414  "installation"));
415 
416  if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
417  argerror(_("only one of --excludedocs and --includedocs may be "
418  "specified"));
419 
420  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
421  argerror(_("--ignorearch may only be specified during package "
422  "installation"));
423 
424  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
425  argerror(_("--ignoreos may only be specified during package "
426  "installation"));
427 
428  if (bigMode != MODE_INSTALL &&
430  argerror(_("--ignoresize may only be specified during package "
431  "installation"));
432 
433  if ((ia->installInterfaceFlags & INSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
434  argerror(_("--allmatches may only be specified during package "
435  "erasure"));
436 
437  if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
438  argerror(_("--allfiles may only be specified during package "
439  "installation"));
440 
441  if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
442  bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
443  argerror(_("--justdb may only be specified during package "
444  "installation and erasure"));
445 
446  if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
448  argerror(_("script disabling options may only be specified during "
449  "package installation and erasure"));
450 
451  if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
453  argerror(_("trigger disabling options may only be specified during "
454  "package installation and erasure"));
455 
456  if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
457  argerror(_("--nodeps may only be specified during package "
458  "building, rebuilding, recompilation, installation,"
459  "erasure, and verification"));
460 
461  if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
462  argerror(_("--test may only be specified during package installation, "
463  "erasure, and building"));
464 #endif /* IAM_RPMEIU */
465 
466  if (rpmcliRootDir && rpmcliRootDir[1] && (bigMode & ~MODES_FOR_ROOT))
467  argerror(_("--root (-r) may only be specified during "
468  "installation, erasure, querying, and "
469  "database rebuilds"));
470 
471  if (rpmcliRootDir) {
472  switch (urlIsURL(rpmcliRootDir)) {
473  default:
474  if (bigMode & MODES_FOR_ROOT)
475  break;
476  /*@fallthrough@*/
477  case URL_IS_UNKNOWN:
478  if (rpmcliRootDir[0] != '/')
479  argerror(_("arguments to --root (-r) must begin with a /"));
480  break;
481  }
482  }
483 
484  if (quiet)
486 
487 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
488  if (0
489 #if defined(IAM_RPMBT)
490  || ba->sign
491 #endif
492 #if defined(IAM_RPMK)
493  || ka->sign
494 #endif
495  )
496  /*@-branchstate@*/
497  {
498  if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
499  bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD)
500  {
501  const char ** av;
502  struct stat sb;
503  int errors = 0;
504 
505  if ((av = poptGetArgs(optCon)) == NULL) {
506  fprintf(stderr, _("no files to sign\n"));
507  errors++;
508  } else
509  while (*av) {
510  if (stat(*av, &sb)) {
511  fprintf(stderr, _("cannot access file %s\n"), *av);
512  errors++;
513  }
514  av++;
515  }
516 
517  if (errors) {
518  ec = errors;
519  goto exit;
520  }
521 
522  if (poptPeekArg(optCon)) {
524  switch (sigTag) {
525  case 0:
526  break;
527  case RPMSIGTAG_PGP:
528 #ifdef DYING /* XXX gpg can now be used for RSA signatures. */
529  if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
530  !rpmDetectPGPVersion(NULL)) {
531  fprintf(stderr, _("pgp not found: "));
532  ec = EXIT_FAILURE;
533  goto exit;
534  } /*@fallthrough@*/
535 #endif
536  case RPMSIGTAG_GPG:
537  case RPMSIGTAG_DSA:
538  case RPMSIGTAG_RSA:
539  passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
540  if (passPhrase == NULL) {
541  fprintf(stderr, _("Pass phrase check failed\n"));
542  ec = EXIT_FAILURE;
543  goto exit;
544  }
545  fprintf(stderr, _("Pass phrase is good.\n"));
546  passPhrase = xstrdup(passPhrase);
547  break;
548  default:
549  fprintf(stderr,
550  _("Invalid %%_signature spec in macro file.\n"));
551  ec = EXIT_FAILURE;
552  goto exit;
553  /*@notreached@*/ break;
554  }
555  }
556  } else {
557  argerror(_("--sign may only be used during package building"));
558  }
559  } else {
560  /* Make rpmLookupSignatureType() return 0 ("none") from now on */
562  }
563  /*@=branchstate@*/
564 #endif /* IAM_RPMBT || IAM_RPMK */
565 
566  if (rpmcliPipeOutput) {
567  (void) pipe(p);
568 
569  if (!(pipeChild = fork())) {
570  (void) close(p[1]);
571  (void) dup2(p[0], STDIN_FILENO);
572  (void) close(p[0]);
573  (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL);
574  fprintf(stderr, _("exec failed\n"));
575  }
576 
577  (void) close(p[0]);
578  (void) dup2(p[1], STDOUT_FILENO);
579  (void) close(p[1]);
580  }
581 
582  ts = rpmtsCreate();
583  (void) rpmtsSetRootDir(ts, rpmcliRootDir);
584  switch (bigMode) {
585 #ifdef IAM_RPMDB
586  case MODE_INITDB:
587  ec = rpmtsInitDB(ts, 0644);
588  break;
589 
590  case MODE_REBUILDDB:
591  { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
592  rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
593  ec = rpmtsRebuildDB(ts);
594  vsflags = rpmtsSetVSFlags(ts, ovsflags);
595  } break;
596  case MODE_VERIFYDB:
597  ec = rpmtsVerifyDB(ts);
598  break;
599 #endif /* IAM_RPMDB */
600 
601 #ifdef IAM_RPMBT
602  case MODE_REBUILD:
603  case MODE_RECOMPILE:
604  { const char * pkg;
605  int nbuilds = 0;
606 
607  while (!rpmIsVerbose())
609 
610  if (!poptPeekArg(optCon))
611  argerror(_("no packages files given for rebuild"));
612 
613  ba->buildAmount =
615  if (bigMode == MODE_REBUILD) {
621  }
622 
623  while ((pkg = poptGetArg(optCon))) {
624  const char * specFile = NULL;
625 
626  if (nbuilds++ > 0) {
627  rpmFreeMacros(NULL);
628  rpmFreeRpmrc();
629  (void) rpmReadConfigFiles(NULL, NULL);
630  }
631  ba->cookie = NULL;
632  ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
633  if (ec == 0) {
634  ba->rootdir = rpmcliRootDir;
635  ba->passPhrase = passPhrase;
636  ec = build(ts, specFile, ba, rpmcliRcfile);
637  }
638  ba->cookie = _free(ba->cookie);
639  specFile = _free(specFile);
640 
641  if (ec)
642  /*@loopbreak@*/ break;
643  }
644 
645  } break;
646 
647  case MODE_BUILD:
648  case MODE_TARBUILD:
649  { const char * pkg;
650  int nbuilds = 0;
651 
652  if (!quiet) while (!rpmIsVerbose())
654 
655  switch (ba->buildChar) {
656  case 'a':
658  /*@fallthrough@*/
659  case 'b':
662  if (
663 #if !defined(RPM_VENDOR_MANDRIVA)
664  (ba->buildChar == 'b') &&
665 #endif
666  ba->shortCircuit)
667  /*@innerbreak@*/ break;
668  /*@fallthrough@*/
669  case 'i':
672  if (
673 #if !defined(RPM_VENDOR_MANDRIVA)
674  (ba->buildChar == 'i') &&
675 #endif
676  ba->shortCircuit)
677  /*@innerbreak@*/ break;
678  /*@fallthrough@*/
679  case 'c':
681  if (
682 #if !defined(RPM_VENDOR_MANDRIVA)
683  (ba->buildChar == 'c') &&
684 #endif
685  ba->shortCircuit)
686  /*@innerbreak@*/ break;
687  /*@fallthrough@*/
688  case 'p':
689  ba->buildAmount |= RPMBUILD_PREP;
690  /*@innerbreak@*/ break;
691 
692  case 'l':
694  /*@innerbreak@*/ break;
695  case 's':
697  /*@innerbreak@*/ break;
698  }
699 
700  if (!poptPeekArg(optCon)) {
701  if (bigMode == MODE_BUILD)
702  argerror(_("no spec files given for build"));
703  else
704  argerror(_("no tar files given for build"));
705  }
706 
707  while ((pkg = poptGetArg(optCon))) {
708  if (nbuilds++ > 0) {
709  rpmFreeMacros(NULL);
710  rpmFreeRpmrc();
711  (void) rpmReadConfigFiles(NULL, NULL);
712  }
713  ba->rootdir = rpmcliRootDir;
714  ba->passPhrase = passPhrase;
715  ba->cookie = NULL;
716  ec = build(ts, pkg, ba, rpmcliRcfile);
717  if (ec)
718  /*@loopbreak@*/ break;
719  }
720  } break;
721 #endif /* IAM_RPMBT */
722 
723 #ifdef IAM_RPMEIU
724  case MODE_ERASE:
727 
728  if (!poptPeekArg(optCon)) {
729  if (ia->rbtid == 0)
730  argerror(_("no packages given for erase"));
733 ia->rbCheck = rpmrbCheck;
734 ia->rbOrder = rpmrbOrder;
735 ia->rbRun = rpmrbRun;
736  ec += rpmRollback(ts, ia, NULL);
737  } else {
738  ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon));
739  }
740  break;
741 
742  case MODE_INSTALL:
743 
744  /* RPMTRANS_FLAG_KEEPOBSOLETE */
745 
747  if (!ia->incldocs) {
748  if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
749  ;
750  } else if (rpmExpandNumeric("%{_excludedocs}"))
752  }
753 
755 
756  /* we've already ensured !(!ia->prefix && !ia->relocations) */
757  /*@-branchstate@*/
758  if (ia->qva_prefix) {
759  ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
760  ia->relocations[0].oldPath = NULL; /* special case magic */
761  ia->relocations[0].newPath = ia->qva_prefix;
762  ia->relocations[1].oldPath = NULL;
763  ia->relocations[1].newPath = NULL;
764  } else if (ia->relocations) {
765  ia->relocations = xrealloc(ia->relocations,
766  sizeof(*ia->relocations) * (ia->numRelocations + 1));
767  ia->relocations[ia->numRelocations].oldPath = NULL;
768  ia->relocations[ia->numRelocations].newPath = NULL;
769  }
770  /*@=branchstate@*/
771 
772  if (!poptPeekArg(optCon)) {
773  if (ia->rbtid == 0)
774  argerror(_("no packages given for install"));
777 ia->rbCheck = rpmrbCheck;
778 ia->rbOrder = rpmrbOrder;
779 ia->rbRun = rpmrbRun;
780 /*@i@*/ ec += rpmRollback(ts, ia, NULL);
781  } else {
782  /*@-compdef -compmempass@*/ /* FIX: ia->relocations[0].newPath undefined */
783  ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon));
784  /*@=compdef =compmempass@*/
785  }
786  break;
787 
788 #endif /* IAM_RPMEIU */
789 
790 #ifdef IAM_RPMQV
791  case MODE_QUERY:
792  if (!poptPeekArg(optCon)
793  && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST))
794  argerror(_("no arguments given for query"));
795 
796  qva->depFlags = global_depFlags;
798  ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon));
799  qva->qva_specQuery = NULL;
800  break;
801 
802  case MODE_VERIFY:
803  { rpmVerifyFlags verifyFlags = VERIFY_ALL;
804 
805  qva->depFlags = global_depFlags;
806  verifyFlags &= ~qva->qva_flags;
807  qva->qva_flags = (rpmQueryFlags) verifyFlags;
808 
809  if (!poptPeekArg(optCon)
810  && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST))
811  argerror(_("no arguments given for verify"));
812  ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon));
813  } break;
814 #endif /* IAM_RPMQV */
815 
816 #ifdef IAM_RPMK
817  case MODE_CHECKSIG:
818  { rpmVerifyFlags verifyFlags =
820 
821  verifyFlags &= ~ka->qva_flags;
822  ka->qva_flags = (rpmQueryFlags) verifyFlags;
823  } /*@fallthrough@*/
824  case MODE_RESIGN:
825  if (!poptPeekArg(optCon))
826  argerror(_("no arguments given"));
827  ka->passPhrase = passPhrase;
828  ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon));
829  break;
830 #endif /* IAM_RPMK */
831 
832 #if !defined(IAM_RPMQV)
833  case MODE_QUERY:
834  case MODE_VERIFY:
835 #endif
836 #if !defined(IAM_RPMK)
837  case MODE_CHECKSIG:
838  case MODE_RESIGN:
839 #endif
840 #if !defined(IAM_RPMDB)
841  case MODE_INITDB:
842  case MODE_REBUILDDB:
843  case MODE_VERIFYDB:
844 #endif
845 #if !defined(IAM_RPMBT)
846  case MODE_BUILD:
847  case MODE_REBUILD:
848  case MODE_RECOMPILE:
849  case MODE_TARBUILD:
850 #endif
851 #if !defined(IAM_RPMEIU)
852  case MODE_INSTALL:
853  case MODE_ERASE:
854 #endif
855  case MODE_UNKNOWN:
856  if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
857  printUsage(optCon, stderr, 0);
858  ec = argc;
859  }
860  break;
861  }
862 
863 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
864 exit:
865 #endif /* IAM_RPMBT || IAM_RPMK */
866 
867  ts = rpmtsFree(ts);
868 
869  if (pipeChild) {
870  (void) fclose(stdout);
871  (void) waitpid(pipeChild, &status, 0);
872  }
873 
874 #ifdef IAM_RPMQV
876 #endif
877 
878 #ifdef IAM_RPMBT
879  freeNames();
880 #endif
881 
882 #ifdef IAM_RPMEIU
883  if (ia->relocations != NULL)
884  for (i = 0; i < ia->numRelocations; i++)
885  ia->relocations[i].oldPath = _free(ia->relocations[i].oldPath);
886  ia->relocations = _free(ia->relocations);
887 #endif
888 
889  optCon = rpmcliFini(optCon);
890 
891  /* XXX don't overflow single byte exit status */
892  if (ec > 255) ec = 255;
893 
894  /*@-globstate@*/
895  return ec;
896  /*@=globstate@*/
897 }
898 /*@=mods@*/
899 /*@=bounds@*/