1 #ifndef H_RPMCLI
2 #define	H_RPMCLI
3 
4 /** \ingroup rpmcli rpmbuild
5  * \file lib/rpmcli.h
6  *
7  * Parsing RPM command line arguments
8  */
9 
10 #include <popt.h>
11 
12 #include <rpm/rpmlib.h>
13 #include <rpm/rpmurl.h>
14 #include <rpm/rpmmacro.h>
15 #include <rpm/rpmcallback.h>
16 #include <rpm/rpmts.h>
17 #include <rpm/rpmfi.h>
18 #include <rpm/argv.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /** \ingroup rpmcli
25  * Popt option table for options shared by all modes and executables.
26  */
27 extern struct poptOption		rpmcliAllPoptTable[];
28 
29 extern const char * rpmcliPipeOutput;
30 
31 extern const char * rpmcliRcfile;
32 
33 extern const char * rpmcliRootDir;
34 
35 /** \ingroup rpmcli
36  * Initialize most everything needed by an rpm CLI executable context.
37  * @param argc			no. of args
38  * @param argv			arg array
39  * @param optionsTable		popt option table
40  * @return			popt context (or NULL)
41  */
42 poptContext
43 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable);
44 
45 /** \ingroup rpmcli
46  * Make sure that rpm configuration has been read.
47  * @warning Options like --rcfile and --verbose must precede callers option.
48  */
49 void rpmcliConfigured(void);
50 
51 /** \ingroup rpmcli
52  * Destroy most everything needed by an rpm CLI executable context.
53  * @param optCon		popt context
54  * @return			NULL always
55  */
56 poptContext
57 rpmcliFini(poptContext optCon);
58 
59 /**
60  * Common/global popt tokens used for command line option tables.
61  */
62 #define	RPMCLI_POPT_NODEPS		-1025
63 #define	RPMCLI_POPT_FORCE		-1026
64 #define	RPMCLI_POPT_NOMD5		-1027
65 #define	RPMCLI_POPT_NOFILEDIGEST	-1027	/* same as obsolete RPMCLI_POPT_NOMD5 */
66 #define	RPMCLI_POPT_NOSCRIPTS		-1028
67 #define	RPMCLI_POPT_NOSIGNATURE		-1029
68 #define	RPMCLI_POPT_NODIGEST		-1030
69 #define	RPMCLI_POPT_NOHDRCHK		-1031
70 #define	RPMCLI_POPT_NOCONTEXTS		-1032
71 #define	RPMCLI_POPT_NOCAPS		-1033
72 #define	RPMCLI_POPT_TARGETPLATFORM	-1034
73 
74 /* ==================================================================== */
75 /** \name RPMQV */
76 
77 /** \ingroup rpmcli
78  * Query/Verify argument qualifiers.
79  * @todo Reassign to tag values.
80  */
81 enum rpmQVSources_e {
82     RPMQV_PACKAGE = 0,	/*!< ... from package name db search. */
83     RPMQV_PATH,		/*!< ... from file path db search. */
84     RPMQV_ALL,		/*!< ... from each installed package. */
85     RPMQV_RPM, 		/*!< ... from reading binary rpm package. */
86     RPMQV_GROUP,	/*!< ... from group db search. */
87     RPMQV_WHATPROVIDES,	/*!< ... from provides db search. */
88     RPMQV_WHATREQUIRES,	/*!< ... from requires db search. */
89     RPMQV_TRIGGEREDBY,	/*!< ... from trigger db search. */
90     RPMQV_DBOFFSET,	/*!< ... from database header instance. */
91     RPMQV_SPECRPMS,	/*!< ... from spec file binaries (query only). */
92     RPMQV_SPECFILE = RPMQV_SPECRPMS, /*!< ... backwards compatibility */
93     RPMQV_PKGID,	/*!< ... from package id (header+payload MD5). */
94     RPMQV_HDRID,	/*!< ... from header id (immutable header SHA1). */
95     RPMQV_TID,		/*!< ... from install transaction id (time stamp). */
96     RPMQV_SPECSRPM,	/*!< ... from spec file source (query only). */
97     RPMQV_WHATRECOMMENDS,	/*!< ... from recommends db search. */
98     RPMQV_WHATSUGGESTS,		/*!< ... from suggests db search. */
99     RPMQV_WHATSUPPLEMENTS,	/*!< ... from supplements db search. */
100     RPMQV_WHATENHANCES,		/*!< ... from enhances db search. */
101     RPMQV_SPECBUILTRPMS,	/*!< ... from pkgs which would be built from spec */
102     RPMQV_WHATOBSOLETES,	/*!< ... from obsoletes db search. */
103     RPMQV_WHATCONFLICTS,	/*!< ... from conflicts db search. */
104 };
105 
106 typedef rpmFlags rpmQVSources;
107 
108 /** \ingroup rpmcli
109  * Bit(s) to control rpmQuery() operation, stored in qva_flags.
110  * @todo Merge rpmQueryFlags, rpmVerifyFlags, and rpmVerifyAttrs?.
111  */
112 enum rpmQueryFlags_e {
113     QUERY_FOR_DEFAULT	= 0,		/*!< */
114 	/* bits 0-14 unused */
115 	/* bits 15-18 reserved for rpmVerifyFlags */
116 	/* bits 19-21 unused */
117     QUERY_FOR_LIST	= (1 << 23),	/*!< query:  from --list */
118     QUERY_FOR_STATE	= (1 << 24),	/*!< query:  from --state */
119 	/* bits 25-26 unused */
120     QUERY_FOR_DUMPFILES	= (1 << 27),	/*!< query:  from --dump */
121 };
122 
123 typedef rpmFlags rpmQueryFlags;
124 
125 #define	_QUERY_FOR_BITS	\
126    (QUERY_FOR_LIST|QUERY_FOR_STATE|QUERY_FOR_DUMPFILES)
127 
128 /** \ingroup rpmcli
129  * Bit(s) from common command line options.
130  */
131 extern rpmQueryFlags rpmcliQueryFlags;
132 
133 extern rpmVSFlags rpmcliVSFlags;
134 
135 extern int rpmcliVfyLevelMask;
136 
137 /** \ingroup rpmcli
138  */
139 typedef struct rpmQVKArguments_s * QVA_t;
140 
141 /** \ingroup rpmcli
142  * Function to display iterator matches.
143  *
144  * @param qva		parsed query/verify options
145  * @param ts		transaction set
146  * @param h		header to use for query/verify
147  * @return		0 on success
148  */
149 typedef	int (*QVF_t) (QVA_t qva, rpmts ts, Header h);
150 
151 /** \ingroup rpmcli
152  * Function to query spec file.
153  *
154  * @param ts		transaction set
155  * @param qva		parsed query/verify options
156  * @param arg		query argument
157  * @return		0 on success
158  */
159 typedef	int (*QSpecF_t) (rpmts ts, QVA_t qva, const char * arg);
160 
161 /** \ingroup rpmcli
162  * Describe query/verify/signature command line operation.
163  */
164 struct rpmQVKArguments_s {
165     rpmQVSources qva_source;	/*!< Identify CLI arg type. */
166     int 	qva_sourceCount;/*!< Exclusive option check (>1 is error). */
167     rpmQueryFlags qva_flags;	/*!< Bit(s) to control operation. */
168     rpmfileAttrs qva_incattr;	/*!< Bit(s) to include on attribute. */
169     rpmfileAttrs qva_excattr;	/*!< Bit(s) to exclude on attribute. */
170 
171     rpmVerifyAttrs qva_ofvattr; /*!< Bit(s) to omit on file verification. */
172 
173     QVF_t qva_showPackage;	/*!< Function to display iterator matches. */
174     QSpecF_t qva_specQuery;	/*!< Function to query spec file. */
175     char * qva_queryFormat;	/*!< Format for headerFormat(). */
176     char	qva_mode;
177 		/*!<
178 		- 'q'	from --query, -q
179 		- 'Q'	from --querytags
180 		- 'V'	from --verify, -V
181 		- 'I'	from --import
182 		- 'K'	from --checksig, -K
183 		*/
184 };
185 
186 /** \ingroup rpmcli
187  */
188 extern struct rpmQVKArguments_s rpmQVKArgs;
189 
190 /** \ingroup rpmcli
191  */
192 extern struct poptOption rpmQVSourcePoptTable[];
193 
194 /** \ingroup rpmcli
195  */
196 extern struct poptOption rpmQVFilePoptTable[];
197 
198 /** \ingroup rpmcli
199  */
200 extern struct poptOption rpmQueryPoptTable[];
201 
202 /** \ingroup rpmcli
203  */
204 extern struct poptOption rpmVerifyPoptTable[];
205 
206 /** \ingroup rpmcli
207  * Display list of tags that can be used in --queryformat.
208  * @param fp	file handle to use for display
209  */
210 void rpmDisplayQueryTags(FILE * fp);
211 
212 /** \ingroup rpmcli
213  * Display results of package query.
214  * @todo Devise a meaningful return code.
215  * @param qva		parsed query/verify options
216  * @param ts		transaction set
217  * @param h		header to use for query
218  * @return		0 always
219  */
220 int showQueryPackage(QVA_t qva, rpmts ts, Header h);
221 
222 /** \ingroup rpmcli
223  * Iterate over query/verify arg list.
224  * @param ts		transaction set
225  * @param qva		parsed query/verify options
226  * @param argv		query argument(s) (or NULL)
227  * @return		0 on success, else no. of failures
228  */
229 int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv);
230 
231 /** \ingroup rpmcli
232  * Display package information.
233  * @todo hack: RPMQV_ALL can pass char ** arglist = NULL, not char * arg. Union?
234  * @param ts		transaction set
235  * @param qva		parsed query/verify options
236  * @param argv		query argument(s) (or NULL)
237  * @return		0 on success, else no. of failures
238  */
239 int rpmcliQuery(rpmts ts, QVA_t qva, ARGV_const_t argv);
240 
241 /** \ingroup rpmcli
242  * Display results of package verify.
243  * @param qva		parsed query/verify options
244  * @param ts		transaction set
245  * @param h		header to use for verify
246  * @return		result of last non-zero verify return
247  */
248 int showVerifyPackage(QVA_t qva, rpmts ts, Header h);
249 
250 /**
251  * Check package and header signatures.
252  * @param qva		unused
253  * @param ts		transaction set
254  * @param fd		package file handle
255  * @param fn		package file name
256  * @return		0 on success, 1 on failure
257  */
258 int rpmVerifySignatures(QVA_t qva, rpmts ts, FD_t fd, const char * fn);
259 
260 /** \ingroup rpmvf
261  * Bit(s) to control rpmcliVerify() operation
262  */
263 enum rpmVerifyFlags_e {
264     VERIFY_DEFAULT	= 0,		/*!< */
265 	/* bits 1-14 unused */
266     VERIFY_CONTEXTS	= (1 << 15),	/*!< verify: from --nocontexts */
267     VERIFY_FILES	= (1 << 16),	/*!< verify: from --nofiles */
268     VERIFY_DEPS		= (1 << 17),	/*!< verify: from --nodeps */
269     VERIFY_SCRIPT	= (1 << 18),	/*!< verify: from --noscripts */
270 };
271 
272 typedef rpmFlags rpmVerifyFlags;
273 
274 #define	VERIFY_ALL	\
275   ( VERIFY_FILES | VERIFY_DEPS | VERIFY_SCRIPT )
276 
277 /** \ingroup rpmcli
278  * Verify package install.
279  * @todo hack: RPMQV_ALL can pass char ** arglist = NULL, not char * arg. Union?
280  * @param ts		transaction set
281  * @param qva		parsed query/verify options
282  * @param argv		verify argument(s) (or NULL)
283  * @return		0 on success, else no. of failures
284  */
285 int rpmcliVerify(rpmts ts, QVA_t qva, ARGV_const_t argv);
286 
287 /* ==================================================================== */
288 /** \name RPMEIU */
289 /* --- install/upgrade/erase modes */
290 
291 /** \ingroup rpmcli
292  * Bit(s) to control rpmInstall() operation.
293  */
294 enum rpmInstallFlags_e {
295     INSTALL_NONE	= 0,
296     INSTALL_PERCENT	= (1 << 0),	/*!< from --percent */
297     INSTALL_HASH	= (1 << 1),	/*!< from --hash */
298     INSTALL_NODEPS	= (1 << 2),	/*!< from --nodeps */
299     INSTALL_NOORDER	= (1 << 3),	/*!< from --noorder */
300     INSTALL_LABEL	= (1 << 4),	/*!< from --verbose (notify) */
301     INSTALL_UPGRADE	= (1 << 5),	/*!< from --upgrade */
302     INSTALL_FRESHEN	= (1 << 6),	/*!< from --freshen */
303     INSTALL_INSTALL	= (1 << 7),	/*!< from --install */
304     INSTALL_ERASE	= (1 << 8),	/*!< from --erase */
305     INSTALL_ALLMATCHES	= (1 << 9),	/*!< from --allmatches */
306     INSTALL_REINSTALL	= (1 << 10),	/*!< from --reinstall */
307 };
308 
309 typedef rpmFlags rpmInstallFlags;
310 
311 /** \ingroup rpmcli
312  * Bit(s) to control rpmErase() operation.
313  */
314 #define UNINSTALL_NONE INSTALL_NONE
315 #define UNINSTALL_NODEPS INSTALL_NODEPS
316 #define UNINSTALL_ALLMATCHES INSTALL_ALLMATCHES
317 
318 /** \ingroup rpmcli
319  * The rpm CLI generic transaction callback handler.
320  * @todo Remove headerFormat() from the progress callback.
321  * @deprecated Transaction callback arguments need to change, so don't rely on
322  * this routine in the rpmcli API.
323  *
324  * @param arg		per-callback private data (e.g. an rpm header)
325  * @param what		callback identifier
326  * @param amount	per-callback progress info
327  * @param total		per-callback progress info
328  * @param key		opaque header key (e.g. file name or PyObject)
329  * @param data		private data (e.g. rpmInstallInterfaceFlags)
330  * @return		per-callback data (e.g. an opened FD_t)
331  */
332 void * rpmShowProgress(const void * arg,
333 		const rpmCallbackType what,
334 		const rpm_loff_t amount,
335 		const rpm_loff_t total,
336 		fnpyKey key,
337 		void * data);
338 
339 /** \ingroup rpmcli
340  * Install source rpm package.
341  * @param ts		transaction set
342  * @param arg		source rpm file name
343  * @retval *specFilePtr	(installed) spec file name
344  * @retval *cookie
345  * @return		0 on success
346  */
347 int rpmInstallSource(rpmts ts, const char * arg,
348 		char ** specFilePtr,
349 		char ** cookie);
350 
351 
352 /** \ingroup rpmcli
353  * Describe database command line requests.
354  */
355 struct rpmInstallArguments_s {
356     rpmtransFlags transFlags;
357     rpmprobFilterFlags probFilter;
358     rpmInstallFlags installInterfaceFlags;
359     int numRelocations;
360     int noDeps;
361     int incldocs;
362     rpmRelocation * relocations;
363     char * prefix;
364 };
365 
366 /** \ingroup rpmcli
367  * Install/upgrade/freshen/reinstall binary rpm package.
368  * @param ts		transaction set
369  * @param ia		mode flags and parameters
370  * @param fileArgv	array of package file names (NULL terminated)
371  * @return		0 on success
372  *
373  * @todo		fileArgv is modified on errors, should be ARGV_const_t
374  */
375 int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv);
376 
377 /** \ingroup rpmcli
378  * Erase binary rpm package.
379  * @param ts		transaction set
380  * @param ia		control args/bits
381  * @param argv		array of package file names (NULL terminated)
382  * @return		0 on success
383  */
384 
385 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv);
386 
387 /** \ingroup rpmcli
388  */
389 extern struct rpmInstallArguments_s rpmIArgs;
390 
391 /** \ingroup rpmcli
392  */
393 extern struct poptOption rpmInstallPoptTable[];
394 
395 /* ==================================================================== */
396 /** \name RPMK */
397 
398 /** Import public key(s) to rpm keyring
399  * @param ts		transaction set
400  * @param argv		array of pubkey path arguments (NULL terminated)
401  * @return		0 on success
402  */
403 int rpmcliImportPubkeys(rpmts ts, ARGV_const_t argv);
404 
405 /** \ingroup rpmcli
406  * Verify package signatures
407  * @param ts		transaction set
408  * @param argv		array of package path arguments (NULL terminated)
409  * @return		0 on success
410  */
411 int rpmcliVerifySignatures(rpmts ts, ARGV_const_t argv);
412 
413 #ifdef __cplusplus
414 }
415 #endif
416 
417 #endif	/* H_RPMCLI */
418