rpm  4.12.0.1
rpmqv.c
Go to the documentation of this file.
1 #include "system.h"
2 const char *__progname;
3 
4 #include <rpm/rpmcli.h>
5 #include <rpm/rpmlib.h> /* RPMSIGTAG, rpmReadPackageFile .. */
6 #include <rpm/rpmlog.h>
7 #include <rpm/rpmps.h>
8 #include <rpm/rpmts.h>
9 
10 #include "cliutils.h"
11 
12 #include "debug.h"
13 
14 #if defined(IAM_RPMQ) || defined(IAM_RPMV)
15 #define IAM_RPMQV
16 #endif
17 
18 enum modes {
19 
20  MODE_QUERY = (1 << 0),
21  MODE_VERIFY = (1 << 3),
22 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
23 
24  MODE_INSTALL = (1 << 1),
25  MODE_ERASE = (1 << 2),
26 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
27 
29 };
30 
31 #define MODES_FOR_NODEPS (MODES_IE | MODE_VERIFY)
32 #define MODES_FOR_TEST (MODES_IE)
33 
34 static int quiet;
35 
36 /* the structure describing the options we take and the defaults */
37 static struct poptOption optionsTable[] = {
38 
39 #ifdef IAM_RPMQV
40  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0,
41  N_("Query/Verify package selection options:"),
42  NULL },
43 #endif
44 #ifdef IAM_RPMQ
45  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
46  N_("Query options (with -q or --query):"),
47  NULL },
48 #endif
49 #ifdef IAM_RPMV
50  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
51  N_("Verify options (with -V or --verify):"),
52  NULL },
53 #endif
54 
55 #ifdef IAM_RPMEIU
56  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
57  N_("Install/Upgrade/Erase options:"),
58  NULL },
59 #endif /* IAM_RPMEIU */
60 
61  { "quiet", '\0', POPT_ARGFLAG_DOC_HIDDEN, &quiet, 0, NULL, NULL},
62 
63  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
64  N_("Common options for all rpm modes and executables:"),
65  NULL },
66 
67  POPT_AUTOALIAS
68  POPT_AUTOHELP
69  POPT_TABLEEND
70 };
71 
72 int main(int argc, char *argv[])
73 {
74  rpmts ts = NULL;
75  enum modes bigMode = MODE_UNKNOWN;
76 
77 #if defined(IAM_RPMQV)
78  QVA_t qva = &rpmQVKArgs;
79 #endif
80 
81 #ifdef IAM_RPMEIU
82  struct rpmInstallArguments_s * ia = &rpmIArgs;
83 #endif
84 
85  poptContext optCon;
86  int ec = 0;
87 #ifdef IAM_RPMEIU
88  int i;
89 #endif
90 
91  optCon = rpmcliInit(argc, argv, optionsTable);
92 
93  /* Set the major mode based on argv[0] */
94 #ifdef IAM_RPMQV
95  if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY;
96  if (rstreq(__progname, "rpmverify")) bigMode = MODE_VERIFY;
97 #endif
98 
99 #if defined(IAM_RPMQV)
100  /* Jumpstart option from argv[0] if necessary. */
101  switch (bigMode) {
102  case MODE_QUERY: qva->qva_mode = 'q'; break;
103  case MODE_VERIFY: qva->qva_mode = 'V'; break;
104  case MODE_INSTALL:
105  case MODE_ERASE:
106  case MODE_UNKNOWN:
107  default:
108  break;
109  }
110 #endif
111 
112 #ifdef IAM_RPMQV
113  if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
114  switch (qva->qva_mode) {
115  case 'q': bigMode = MODE_QUERY; break;
116  case 'V': bigMode = MODE_VERIFY; break;
117  }
118 
119  if (qva->qva_sourceCount) {
120  if (qva->qva_sourceCount > 1)
121  argerror(_("one type of query/verify may be performed at a "
122  "time"));
123  }
124  if (qva->qva_flags && (bigMode & ~MODES_QV))
125  argerror(_("unexpected query flags"));
126 
127  if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
128  argerror(_("unexpected query format"));
129 
130  if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
131  argerror(_("unexpected query source"));
132  }
133 #endif /* IAM_RPMQV */
134 
135 #ifdef IAM_RPMEIU
136  if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
137  { int iflags = (ia->installInterfaceFlags &
140  int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
141 
142  if (iflags & eflags)
143  argerror(_("only one major mode may be specified"));
144  else if (iflags)
145  bigMode = MODE_INSTALL;
146  else if (eflags)
147  bigMode = MODE_ERASE;
148  }
149 #endif /* IAM_RPMEIU */
150 
151 #if defined(IAM_RPMEIU)
152  if (!( bigMode == MODE_INSTALL ) &&
154  argerror(_("only installation and upgrading may be forced"));
155  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
156  argerror(_("files may only be relocated during package installation"));
157 
158  if (ia->relocations && ia->prefix)
159  argerror(_("cannot use --prefix with --relocate or --excludepath"));
160 
161  if (bigMode != MODE_INSTALL && ia->relocations)
162  argerror(_("--relocate and --excludepath may only be used when installing new packages"));
163 
164  if (bigMode != MODE_INSTALL && ia->prefix)
165  argerror(_("--prefix may only be used when installing new packages"));
166 
167  if (ia->prefix && ia->prefix[0] != '/')
168  argerror(_("arguments to --prefix must begin with a /"));
169 
170  if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_HASH))
171  argerror(_("--hash (-h) may only be specified during package "
172  "installation and erasure"));
173 
174  if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_PERCENT))
175  argerror(_("--percent may only be specified during package "
176  "installation and erasure"));
177 
178  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
179  argerror(_("--replacepkgs may only be specified during package "
180  "installation"));
181 
182  if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
183  argerror(_("--excludedocs may only be specified during package "
184  "installation"));
185 
186  if (bigMode != MODE_INSTALL && ia->incldocs)
187  argerror(_("--includedocs may only be specified during package "
188  "installation"));
189 
190  if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
191  argerror(_("only one of --excludedocs and --includedocs may be "
192  "specified"));
193 
194  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
195  argerror(_("--ignorearch may only be specified during package "
196  "installation"));
197 
198  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
199  argerror(_("--ignoreos may only be specified during package "
200  "installation"));
201 
202  if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
204  argerror(_("--ignoresize may only be specified during package "
205  "installation"));
206 
207  if ((ia->installInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
208  argerror(_("--allmatches may only be specified during package "
209  "erasure"));
210 
211  if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
212  argerror(_("--allfiles may only be specified during package "
213  "installation"));
214 
215  if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
216  bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
217  argerror(_("--justdb may only be specified during package "
218  "installation and erasure"));
219 
220  if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
222  argerror(_("script disabling options may only be specified during "
223  "package installation and erasure"));
224 
225  if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
227  argerror(_("trigger disabling options may only be specified during "
228  "package installation and erasure"));
229 
230  if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
231  argerror(_("--nodeps may only be specified during package "
232  "installation, erasure, and verification"));
233 
234  if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
235  argerror(_("--test may only be specified during package installation "
236  "and erasure"));
237 #endif /* IAM_RPMEIU */
238 
239  if (rpmcliRootDir && rpmcliRootDir[0] != '/') {
240  argerror(_("arguments to --root (-r) must begin with a /"));
241  }
242 
243  if (quiet)
245 
246  if (rpmcliPipeOutput && initPipe())
247  exit(EXIT_FAILURE);
248 
249  ts = rpmtsCreate();
250  (void) rpmtsSetRootDir(ts, rpmcliRootDir);
251  switch (bigMode) {
252 #ifdef IAM_RPMEIU
253  case MODE_ERASE:
255 
256  if (!poptPeekArg(optCon)) {
257  argerror(_("no packages given for erase"));
258  } else {
259  ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon));
260  }
261  break;
262 
263  case MODE_INSTALL:
264 
265  /* RPMTRANS_FLAG_KEEPOBSOLETE */
266 
267  if (!ia->incldocs) {
268  if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
269  ;
270  } else if (rpmExpandNumeric("%{_excludedocs}"))
272  }
273 
275 
276  /* we've already ensured !(!ia->prefix && !ia->relocations) */
277  if (ia->prefix) {
278  ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
279  ia->relocations[0].oldPath = NULL; /* special case magic */
280  ia->relocations[0].newPath = ia->prefix;
281  ia->relocations[1].oldPath = NULL;
282  ia->relocations[1].newPath = NULL;
283  } else if (ia->relocations) {
284  ia->relocations = xrealloc(ia->relocations,
285  sizeof(*ia->relocations) * (ia->numRelocations + 1));
286  ia->relocations[ia->numRelocations].oldPath = NULL;
287  ia->relocations[ia->numRelocations].newPath = NULL;
288  }
289 
290  if (!poptPeekArg(optCon)) {
291  argerror(_("no packages given for install"));
292  } else {
293  /* FIX: ia->relocations[0].newPath undefined */
294  ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon));
295  }
296  break;
297 
298 #endif /* IAM_RPMEIU */
299 
300 #ifdef IAM_RPMQV
301  case MODE_QUERY:
302  if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
303  argerror(_("no arguments given for query"));
304 
305  ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
306  break;
307 
308  case MODE_VERIFY:
309  { rpmVerifyFlags verifyFlags = VERIFY_ALL;
310 
311  verifyFlags &= ~qva->qva_flags;
312  qva->qva_flags = (rpmQueryFlags) verifyFlags;
313 
314  if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
315  argerror(_("no arguments given for verify"));
316  ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
317  } break;
318 #endif /* IAM_RPMQV */
319 
320 #if !defined(IAM_RPMQV)
321  case MODE_QUERY:
322  case MODE_VERIFY:
323 #endif
324 #if !defined(IAM_RPMEIU)
325  case MODE_INSTALL:
326  case MODE_ERASE:
327 #endif
328  case MODE_UNKNOWN:
329  if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
330  printUsage(optCon, stderr, 0);
331  ec = argc;
332  }
333  break;
334  }
335 
336  rpmtsFree(ts);
337  if (finishPipe())
338  ec = EXIT_FAILURE;
339 
340 #ifdef IAM_RPMQV
341  free(qva->qva_queryFormat);
342 #endif
343 
344 #ifdef IAM_RPMEIU
345  if (ia->relocations != NULL) {
346  for (i = 0; i < ia->numRelocations; i++)
347  free(ia->relocations[i].oldPath);
348  free(ia->relocations);
349  }
350 #endif
351 
352  rpmcliFini(optCon);
353 
354  return RETVAL(ec);
355 }
#define RETVAL(rc)
Definition: cliutils.h:9
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
rpmFlags rpmVerifyFlags
Definition: rpmvf.h:77
int qva_sourceCount
Definition: rpmcli.h:170
#define xmalloc(_size)
Definition: system.h:83
char ** ARGV_t
Definition: argv.h:15
char * oldPath
Definition: rpmfiles.h:95
int main(int argc, char *argv[])
Definition: rpmqv.c:72
rpmprobFilterFlags probFilter
Definition: rpmcli.h:337
static struct poptOption optionsTable[]
Definition: rpmqv.c:37
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
int rpmErase(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_const_t argv)
Erase binary rpm package.
rpmQueryFlags qva_flags
Definition: rpmcli.h:171
char * newPath
Definition: rpmfiles.h:96
#define MODES_FOR_NODEPS
Definition: rpmqv.c:31
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
int rpmcliQuery(rpmts ts, QVA_t qva, ARGV_const_t argv)
Display package information.
rpmRelocation * relocations
Definition: rpmcli.h:342
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
#define _noTransScripts
Definition: rpmts.h:60
int finishPipe(void)
Definition: cliutils.c:73
#define _(Text)
Definition: system.h:110
Describe query/verify/signature command line operation.
Definition: rpmcli.h:168
#define rpmIsVerbose()
Definition: rpmlog.h:272
#define MODES_QV
Definition: rpmqv.c:22
#define MODES_FOR_TEST
Definition: rpmqv.c:32
#define _noTransTriggers
Definition: rpmts.h:69
struct rpmQVKArguments_s rpmQVKArgs
rpmts rpmtsCreate(void)
Create an empty transaction set.
struct poptOption rpmInstallPoptTable[]
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
const char * rpmcliPipeOutput
void argerror(const char *desc)
Definition: cliutils.c:19
struct poptOption rpmQueryPoptTable[]
rpmFlags rpmQueryFlags
Definition: rpmcli.h:130
static int rstreq(const char *s1, const char *s2)
Test for string equality.
Definition: rpmstring.h:113
rpmtransFlags transFlags
Definition: rpmcli.h:336
modes
Definition: rpmbuild.c:204
#define VERIFY_ALL
Definition: rpmvf.h:82
struct poptOption rpmQVSourcePoptTable[]
rpmQVSources qva_source
Definition: rpmcli.h:169
int rpmcliVerify(rpmts ts, QVA_t qva, ARGV_const_t argv)
Verify package install.
int initPipe(void)
Definition: cliutils.c:48
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
rpmInstallFlags installInterfaceFlags
Definition: rpmcli.h:338
struct rpmInstallArguments_s rpmIArgs
static int quiet
Definition: rpmqv.c:34
const char * rpmcliRootDir
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
char * qva_queryFormat
Definition: rpmcli.h:176
char *const * ARGV_const_t
Definition: argv.h:16
#define UNINSTALL_ALLMATCHES
Definition: rpmcli.h:296
Describe database command line requests.
Definition: rpmcli.h:335
struct poptOption rpmVerifyPoptTable[]
#define __progname
Definition: system.h:96
int rpmInstall(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_t fileArgv)
Install/upgrade/freshen/reinstall binary rpm package.
#define N_(Text)
Definition: system.h:113
#define rpmSetVerbosity(_lvl)
Definition: rpmlog.h:264
#define UNINSTALL_NODEPS
Definition: rpmcli.h:295
#define MODES_IE
Definition: rpmqv.c:26
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
#define xrealloc(_ptr, _size)
Definition: system.h:85