rpm  4.13.0
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 #ifdef __OS2__
92  setprogname(argv[0]); /* Retrofit glibc __progname */
93  /* XXX glibc churn sanity */
94  if (__progname == NULL) {
95  if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
96  else __progname = argv[0];
97  }
98 #endif
99  optCon = rpmcliInit(argc, argv, optionsTable);
100 
101  /* Set the major mode based on argv[0] */
102 #ifdef IAM_RPMQV
103  if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY;
104  if (rstreq(__progname, "rpmverify")) bigMode = MODE_VERIFY;
105 #endif
106 
107 #if defined(IAM_RPMQV)
108  /* Jumpstart option from argv[0] if necessary. */
109  switch (bigMode) {
110  case MODE_QUERY: qva->qva_mode = 'q'; break;
111  case MODE_VERIFY: qva->qva_mode = 'V'; break;
112  case MODE_INSTALL:
113  case MODE_ERASE:
114  case MODE_UNKNOWN:
115  default:
116  break;
117  }
118 #endif
119 
120 #ifdef IAM_RPMQV
121  if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
122  switch (qva->qva_mode) {
123  case 'q': bigMode = MODE_QUERY; break;
124  case 'V': bigMode = MODE_VERIFY; break;
125  }
126 
127  if (qva->qva_sourceCount) {
128  if (qva->qva_sourceCount > 1)
129  argerror(_("one type of query/verify may be performed at a "
130  "time"));
131  }
132  if (qva->qva_flags && (bigMode & ~MODES_QV))
133  argerror(_("unexpected query flags"));
134 
135  if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
136  argerror(_("unexpected query format"));
137 
138  if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
139  argerror(_("unexpected query source"));
140  }
141 #endif /* IAM_RPMQV */
142 
143 #ifdef IAM_RPMEIU
144  if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
145  { int iflags = (ia->installInterfaceFlags &
148  int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
149 
150  if (iflags & eflags)
151  argerror(_("only one major mode may be specified"));
152  else if (iflags)
153  bigMode = MODE_INSTALL;
154  else if (eflags)
155  bigMode = MODE_ERASE;
156  }
157 #endif /* IAM_RPMEIU */
158 
159 #if defined(IAM_RPMEIU)
160  if (!( bigMode == MODE_INSTALL ) &&
162  argerror(_("only installation and upgrading may be forced"));
163  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
164  argerror(_("files may only be relocated during package installation"));
165 
166  if (ia->relocations && ia->prefix)
167  argerror(_("cannot use --prefix with --relocate or --excludepath"));
168 
169  if (bigMode != MODE_INSTALL && ia->relocations)
170  argerror(_("--relocate and --excludepath may only be used when installing new packages"));
171 
172  if (bigMode != MODE_INSTALL && ia->prefix)
173  argerror(_("--prefix may only be used when installing new packages"));
174 
175  if (ia->prefix && ia->prefix[0] != '/')
176  argerror(_("arguments to --prefix must begin with a /"));
177 
178  if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_HASH))
179  argerror(_("--hash (-h) may only be specified during package "
180  "installation and erasure"));
181 
182  if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_PERCENT))
183  argerror(_("--percent may only be specified during package "
184  "installation and erasure"));
185 
186  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
187  argerror(_("--replacepkgs may only be specified during package "
188  "installation"));
189 
190  if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
191  argerror(_("--excludedocs may only be specified during package "
192  "installation"));
193 
194  if (bigMode != MODE_INSTALL && ia->incldocs)
195  argerror(_("--includedocs may only be specified during package "
196  "installation"));
197 
198  if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
199  argerror(_("only one of --excludedocs and --includedocs may be "
200  "specified"));
201 
202  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
203  argerror(_("--ignorearch may only be specified during package "
204  "installation"));
205 
206  if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
207  argerror(_("--ignoreos may only be specified during package "
208  "installation"));
209 
210  if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
212  argerror(_("--ignoresize may only be specified during package "
213  "installation"));
214 
215  if ((ia->installInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
216  argerror(_("--allmatches may only be specified during package "
217  "erasure"));
218 
219  if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
220  argerror(_("--allfiles may only be specified during package "
221  "installation"));
222 
223  if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
224  bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
225  argerror(_("--justdb may only be specified during package "
226  "installation and erasure"));
227 
228  if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
230  argerror(_("script disabling options may only be specified during "
231  "package installation and erasure"));
232 
233  if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
235  argerror(_("trigger disabling options may only be specified during "
236  "package installation and erasure"));
237 
238  if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
239  argerror(_("--nodeps may only be specified during package "
240  "installation, erasure, and verification"));
241 
242  if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
243  argerror(_("--test may only be specified during package installation "
244  "and erasure"));
245 #endif /* IAM_RPMEIU */
246 
247 #ifdef __OS2__
248  if (rpmcliRootDir && rpmcliRootDir[0] != '/' && rpmcliRootDir[1] != ':') {
249 #else
250  if (rpmcliRootDir && rpmcliRootDir[0] != '/') {
251 #endif
252  argerror(_("arguments to --root (-r) must begin with a /"));
253  }
254 
255  if (quiet)
257 
258  if (rpmcliPipeOutput && initPipe())
259  exit(EXIT_FAILURE);
260 
261  ts = rpmtsCreate();
262  (void) rpmtsSetRootDir(ts, rpmcliRootDir);
263  switch (bigMode) {
264 #ifdef IAM_RPMEIU
265  case MODE_ERASE:
267 
268  if (!poptPeekArg(optCon)) {
269  argerror(_("no packages given for erase"));
270  } else {
271  ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon));
272  }
273  break;
274 
275  case MODE_INSTALL:
276 
277  /* RPMTRANS_FLAG_KEEPOBSOLETE */
278 
279  if (!ia->incldocs) {
280  if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
281  ;
282  } else if (rpmExpandNumeric("%{_excludedocs}"))
284  }
285 
287 
288  /* we've already ensured !(!ia->prefix && !ia->relocations) */
289  if (ia->prefix) {
290  ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
291  ia->relocations[0].oldPath = NULL; /* special case magic */
292  ia->relocations[0].newPath = ia->prefix;
293  ia->relocations[1].oldPath = NULL;
294  ia->relocations[1].newPath = NULL;
295  } else if (ia->relocations) {
296  ia->relocations = xrealloc(ia->relocations,
297  sizeof(*ia->relocations) * (ia->numRelocations + 1));
298  ia->relocations[ia->numRelocations].oldPath = NULL;
299  ia->relocations[ia->numRelocations].newPath = NULL;
300  }
301 
302  if (!poptPeekArg(optCon)) {
303  argerror(_("no packages given for install"));
304  } else {
305  /* FIX: ia->relocations[0].newPath undefined */
306  ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon));
307  }
308  break;
309 
310 #endif /* IAM_RPMEIU */
311 
312 #ifdef IAM_RPMQV
313  case MODE_QUERY:
314  if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
315  argerror(_("no arguments given for query"));
316 
317  ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
318  break;
319 
320  case MODE_VERIFY:
321  { rpmVerifyFlags verifyFlags = VERIFY_ALL;
322 
323  verifyFlags &= ~qva->qva_flags;
324  qva->qva_flags = (rpmQueryFlags) verifyFlags;
325 
326  if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
327  argerror(_("no arguments given for verify"));
328  ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
329  } break;
330 #endif /* IAM_RPMQV */
331 
332 #if !defined(IAM_RPMQV)
333  case MODE_QUERY:
334  case MODE_VERIFY:
335 #endif
336 #if !defined(IAM_RPMEIU)
337  case MODE_INSTALL:
338  case MODE_ERASE:
339 #endif
340  case MODE_UNKNOWN:
341  if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
342  printUsage(optCon, stderr, 0);
343  ec = argc;
344  }
345  break;
346  }
347 
348  rpmtsFree(ts);
349  if (finishPipe())
350  ec = EXIT_FAILURE;
351 
352 #ifdef IAM_RPMQV
353  free(qva->qva_queryFormat);
354 #endif
355 
356 #ifdef IAM_RPMEIU
357  if (ia->relocations != NULL) {
358  for (i = 0; i < ia->numRelocations; i++)
359  free(ia->relocations[i].oldPath);
360  free(ia->relocations);
361  }
362 #endif
363 
364  rpmcliFini(optCon);
365 
366  return RETVAL(ec);
367 }
_
#define _(Text)
Definition: system.h:112
INSTALL_FRESHEN
@ INSTALL_FRESHEN
Definition: rpmcli.h:286
MODES_FOR_TEST
#define MODES_FOR_TEST
Definition: rpmqv.c:32
RPMPROB_FILTER_OLDPACKAGE
@ RPMPROB_FILTER_OLDPACKAGE
Definition: rpmprob.h:29
MODES_QV
#define MODES_QV
Definition: rpmqv.c:22
RPMTRANS_FLAG_TEST
@ RPMTRANS_FLAG_TEST
Definition: rpmts.h:30
rpmInstallArguments_s::probFilter
rpmprobFilterFlags probFilter
Definition: rpmcli.h:341
rpmInstallArguments_s::numRelocations
int numRelocations
Definition: rpmcli.h:343
setprogname
#define setprogname(pn)
Definition: system.h:98
INSTALL_NODEPS
@ INSTALL_NODEPS
Definition: rpmcli.h:282
RPMTRANS_FLAG_NOTRIGGERS
@ RPMTRANS_FLAG_NOTRIGGERS
Definition: rpmts.h:34
quiet
static int quiet
Definition: rpmqv.c:34
RPMPROB_FILTER_DISKNODES
@ RPMPROB_FILTER_DISKNODES
Definition: rpmprob.h:31
RETVAL
#define RETVAL(rc)
Definition: cliutils.h:9
MODES_FOR_NODEPS
#define MODES_FOR_NODEPS
Definition: rpmqv.c:31
rpmtsCreate
rpmts rpmtsCreate(void)
rpmQVKArguments_s::qva_queryFormat
char * qva_queryFormat
Definition: rpmcli.h:180
ARGV_const_t
char *const * ARGV_const_t
Definition: argv.h:16
RPMTRANS_FLAG_JUSTDB
@ RPMTRANS_FLAG_JUSTDB
Definition: rpmts.h:33
rpmInstallPoptTable
struct poptOption rpmInstallPoptTable[]
rpmErase
int rpmErase(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_const_t argv)
MODE_QUERY
@ MODE_QUERY
Definition: rpmqv.c:20
rpmRelocation_s::newPath
char * newPath
Definition: rpmfiles.h:96
INSTALL_UPGRADE
@ INSTALL_UPGRADE
Definition: rpmcli.h:285
optionsTable
static struct poptOption optionsTable[]
Definition: rpmqv.c:37
rpmInstallArguments_s::relocations
rpmRelocation * relocations
Definition: rpmcli.h:346
RPMTRANS_FLAG_NOSCRIPTS
@ RPMTRANS_FLAG_NOSCRIPTS
Definition: rpmts.h:32
rpmcliPipeOutput
const char * rpmcliPipeOutput
rpmts
struct rpmts_s * rpmts
Definition: rpmtypes.h:63
VERIFY_ALL
#define VERIFY_ALL
Definition: rpmvf.h:82
rpmIArgs
struct rpmInstallArguments_s rpmIArgs
rpmSetVerbosity
#define rpmSetVerbosity(_lvl)
Definition: rpmlog.h:264
UNINSTALL_ALLMATCHES
#define UNINSTALL_ALLMATCHES
Definition: rpmcli.h:300
rpmcliVerify
int rpmcliVerify(rpmts ts, QVA_t qva, ARGV_const_t argv)
rpmVerifyFlags
rpmFlags rpmVerifyFlags
Definition: rpmvf.h:77
rpmQVKArguments_s::qva_sourceCount
int qva_sourceCount
Definition: rpmcli.h:174
_noTransScripts
#define _noTransScripts
Definition: rpmts.h:60
INSTALL_INSTALL
@ INSTALL_INSTALL
Definition: rpmcli.h:287
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
RPMPROB_FILTER_IGNOREOS
@ RPMPROB_FILTER_IGNOREOS
Definition: rpmprob.h:23
rpmQVKArgs
struct rpmQVKArguments_s rpmQVKArgs
rpmInstallArguments_s
Definition: rpmcli.h:339
rpmQVKArguments_s
Definition: rpmcli.h:172
INSTALL_REINSTALL
@ INSTALL_REINSTALL
Definition: rpmcli.h:290
ARGV_t
char ** ARGV_t
Definition: argv.h:15
rpmInstallArguments_s::transFlags
rpmtransFlags transFlags
Definition: rpmcli.h:340
RPMPROB_FILTER_DISKSPACE
@ RPMPROB_FILTER_DISKSPACE
Definition: rpmprob.h:30
initPipe
int initPipe(void)
Definition: cliutils.c:48
rpmQVKArguments_s::qva_source
rpmQVSources qva_source
Definition: rpmcli.h:173
RPMTRANS_FLAG_ALLFILES
@ RPMTRANS_FLAG_ALLFILES
Definition: rpmts.h:36
rpmcliRootDir
const char * rpmcliRootDir
__progname
#define __progname
Definition: system.h:97
RPMPROB_FILTER_FORCERELOCATE
@ RPMPROB_FILTER_FORCERELOCATE
Definition: rpmprob.h:26
rpmQueryPoptTable
struct poptOption rpmQueryPoptTable[]
rpmInstallArguments_s::installInterfaceFlags
rpmInstallFlags installInterfaceFlags
Definition: rpmcli.h:342
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
MODE_INSTALL
@ MODE_INSTALL
Definition: rpmqv.c:24
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
RPMQV_ALL
@ RPMQV_ALL
Definition: rpmcli.h:81
INSTALL_HASH
@ INSTALL_HASH
Definition: rpmcli.h:281
rpmInstallArguments_s::noDeps
int noDeps
Definition: rpmcli.h:344
main
int main(int argc, char *argv[])
Definition: rpmqv.c:72
rpmExpandNumeric
int rpmExpandNumeric(const char *arg)
RPMPROB_FILTER_REPLACEPKG
@ RPMPROB_FILTER_REPLACEPKG
Definition: rpmprob.h:25
modes
modes
Definition: rpmbuild.c:250
MODE_UNKNOWN
@ MODE_UNKNOWN
Definition: rpmqv.c:28
finishPipe
int finishPipe(void)
Definition: cliutils.c:77
system.h
rpmIsVerbose
#define rpmIsVerbose()
Definition: rpmlog.h:272
rpmQVKArguments_s::qva_flags
rpmQueryFlags qva_flags
Definition: rpmcli.h:175
rpmQVSourcePoptTable
struct poptOption rpmQVSourcePoptTable[]
rpmQVKArguments_s::qva_mode
char qva_mode
Definition: rpmcli.h:181
rpmInstallArguments_s::prefix
char * prefix
Definition: rpmcli.h:347
UNINSTALL_NODEPS
#define UNINSTALL_NODEPS
Definition: rpmcli.h:299
MODE_VERIFY
@ MODE_VERIFY
Definition: rpmqv.c:21
RPMQV_PACKAGE
@ RPMQV_PACKAGE
Definition: rpmcli.h:79
RPMLOG_WARNING
@ RPMLOG_WARNING
Definition: rpmlog.h:34
xrealloc
#define xrealloc(_ptr, _size)
Definition: system.h:85
rpmcliQuery
int rpmcliQuery(rpmts ts, QVA_t qva, ARGV_const_t argv)
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
rstreq
static int rstreq(const char *s1, const char *s2)
Test for string equality.
Definition: rpmstring.h:113
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
MODES_IE
#define MODES_IE
Definition: rpmqv.c:26
RPMPROB_FILTER_IGNOREARCH
@ RPMPROB_FILTER_IGNOREARCH
Definition: rpmprob.h:24
cliutils.h
rpmVerifyPoptTable
struct poptOption rpmVerifyPoptTable[]
_noTransTriggers
#define _noTransTriggers
Definition: rpmts.h:69
rpmtsSetRootDir
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
INSTALL_ERASE
@ INSTALL_ERASE
Definition: rpmcli.h:288
rpmInstallArguments_s::incldocs
int incldocs
Definition: rpmcli.h:345
N_
#define N_(Text)
Definition: system.h:115
INSTALL_PERCENT
@ INSTALL_PERCENT
Definition: rpmcli.h:280
MODE_ERASE
@ MODE_ERASE
Definition: rpmqv.c:25
xmalloc
#define xmalloc(_size)
Definition: system.h:83
rpmRelocation_s::oldPath
char * oldPath
Definition: rpmfiles.h:95
rpmInstall
int rpmInstall(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_t fileArgv)
debug.h
rpmtsFree
rpmts rpmtsFree(rpmts ts)
RPMTRANS_FLAG_NODOCS
@ RPMTRANS_FLAG_NODOCS
Definition: rpmts.h:35
rpmQueryFlags
rpmFlags rpmQueryFlags
Definition: rpmcli.h:134