rpm  5.4.15
poptIO.c
Go to the documentation of this file.
1 
6 #include "system.h"
7 
8 #include <poptIO.h>
9 
10 #if defined(WITH_BEECRYPT)
11 #include <rpmbc.h>
12 #endif
13 #if defined(WITH_CDSA)
14 #include <rpmcdsa.h>
15 #endif
16 #if defined(WITH_GCRYPT)
17 #include <rpmgc.h>
18 #endif
19 #if defined(WITH_NSS)
20 #include <rpmnss.h>
21 #endif
22 #if defined(WITH_SSL)
23 #include <rpmssl.h>
24 #endif
25 #if defined(WITH_TOMCRYPT)
26 #include <rpmltc.h>
27 #endif
28 
29 #include <rpmasn.h>
30 #include <rpmtpm.h>
31 #include <mongo.h>
32 
33 #include <rpmaug.h>
34 #include <rpmbag.h>
35 #include <rpmbf.h>
36 #include <rpmcudf.h>
37 #include <rpmcvs.h>
38 #include <rpmficl.h>
39 #include <rpmgit.h>
40 #include <rpmhkp.h>
41 #include <rpmjs.h>
42 #include <rpmmrb.h>
43 #include <rpmnix.h>
44 #include <rpmodbc.h>
45 #include <rpmperl.h>
46 #include <rpmpython.h>
47 #include <rpmruby.h>
48 #include <rpmsql.h>
49 #include <rpmsquirrel.h>
50 #include <rpmsvn.h>
51 extern int _rpmsvn_debug;
52 #include <rpmtcl.h>
53 
54 #include <rpmsm.h>
55 #include <rpmsp.h>
56 #include <rpmsx.h>
57 
58 #include <set.h>
59 
60 #include "debug.h"
61 
62 #ifdef __cplusplus
63 GENfree(rpmioP)
64 #endif /* __cplusplus */
65 
66 const char *__progname;
67 
68 #if !defined(POPT_ARGFLAG_TOGGLE) /* XXX compat with popt < 1.15 */
69 #define POPT_ARGFLAG_TOGGLE 0
70 #endif
71 #define POPT_SHOWVERSION -999
72 #define POPT_UNDEFINE -994
73 #define POPT_CRYPTO -993
74 
75 /*@unchecked@*/
76 int __debug = 0;
77 
78 /*@-exportheadervar@*/
79 /*@-redecl@*/
80 /*@unchecked@*/
81 extern int _ar_debug;
82 /*@unchecked@*/
83 extern int _av_debug;
84 /*@unchecked@*/
85 extern int _cpio_debug;
86 /*@unchecked@*/
87 extern int _ctx_debug;
88 /*@unchecked@*/
89 extern int _dav_debug;
90 /*@unchecked@*/
91 extern int _ftp_debug;
92 /*@unchecked@*/
93 extern int _fts_debug;
94 /*@unchecked@*/
95 extern int _ht_debug;
96 /*@unchecked@*/
97 extern int _html_debug;
98 /*@unchecked@*/
99 extern int _iosm_debug;
100 /*@unchecked@*/
101 extern int noLibio;
102 /*@unchecked@*/
103 extern int _pgp_debug;
104 /*@unchecked@*/
105 extern int _pgp_print;
106 /*@unchecked@*/
107 extern int _rpmio_debug;
108 /*@unchecked@*/
109 extern int _rpmiob_debug;
110 /*@unchecked@*/
111 extern int _rpmlua_debug;
112 /*@unchecked@*/
113 extern int _rpmsq_debug;
114 /*@unchecked@*/
115 extern int _rpmzq_debug;
116 /*@unchecked@*/
117 extern int _tar_debug;
118 /*@unchecked@*/
119 extern int _xar_debug;
120 /*@=redecl@*/
121 /*@=exportheadervar@*/
122 
123 /*@unchecked@*/ /*@null@*/
124 const char * rpmioPipeOutput = NULL;
125 
126 /*@unchecked@*/
127 const char * rpmioRootDir = "/";
128 
129 /*@observer@*/ /*@unchecked@*/
130 const char *rpmioEVR = VERSION;
131 
132 /*@unchecked@*/
133 static int rpmioInitialized = -1;
134 
135 #ifdef NOTYET
136 #ifdef WITH_LUA
137 /*@unchecked@*/
138 extern const char *rpmluaFiles;
139 #endif
140 
141 /*@unchecked@*/
142 static char *rpmpoptfiles = RPMPOPTFILES;
143 #endif
144 
146 
148 
152 struct poptOption rpmioDigestPoptTable[] = {
153  { "md2", '\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_MD2,
154  N_("MD2 digest (RFC-1319)"), NULL },
155  { "md4", '\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_MD4,
156  N_("MD4 digest"), NULL },
157  { "md5", '\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_MD5,
158  N_("MD5 digest (RFC-1321)"), NULL },
159  { "sha1",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHA1,
160  N_("SHA-1 digest (FIPS-180-1)"), NULL },
161  { "sha224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHA224,
162  N_("SHA-224 digest (FIPS-180-2)"), NULL },
163  { "sha256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHA256,
164  N_("SHA-256 digest (FIPS-180-2)"), NULL },
165  { "sha384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHA384,
166  N_("SHA-384 digest (FIPS-180-2)"), NULL },
167  { "sha512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHA512,
168  N_("SHA-512 digest (FIPS-180-2)"), NULL },
169  { "skein-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SKEIN_224,
170  N_("SKEIN-224 digest"), NULL },
171  { "skein-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SKEIN_256,
172  N_("SKEIN-256 digest"), NULL },
173  { "skein-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SKEIN_384,
174  N_("SKEIN-384 digest"), NULL },
175  { "skein-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SKEIN_512,
176  N_("SKEIN-512 digest"), NULL },
177  { "skein-1024",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SKEIN_1024,
178  N_("SKEIN-1024 digest"), NULL },
179  { "arirang-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_ARIRANG_224,
180  N_("Arirang-224 digest"), NULL },
181  { "arirang-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_ARIRANG_256,
182  N_("Arirang-256 digest"), NULL },
183  { "arirang-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_ARIRANG_384,
184  N_("Arirang-384 digest"), NULL },
185  { "arirang-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_ARIRANG_512,
186  N_("Arirang-512 digest"), NULL },
187  { "blake-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BLAKE_224,
188  N_("Blake-224 digest"), NULL },
189  { "blake-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BLAKE_256,
190  N_("Blake-256 digest"), NULL },
191  { "blake-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BLAKE_384,
192  N_("Blake-384 digest"), NULL },
193  { "blake-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BLAKE_512,
194  N_("Blake-512 digest"), NULL },
195  { "blake2b",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BLAKE2B,
196  N_("Blake2b digest"), NULL },
197  { "blake2bp",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BLAKE2BP,
198  N_("Blake2bp digest"), NULL },
199  { "blake2s",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BLAKE2S,
200  N_("Blake2s digest"), NULL },
201  { "blake2sp",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BLAKE2SP,
202  N_("Blake2sp digest"), NULL },
203  { "bmw-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BMW_224,
204  N_("BlueMidnightWish-224 digest"), NULL },
205  { "bmw-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BMW_256,
206  N_("BlueMidnightWish-256 digest"), NULL },
207  { "bmw-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BMW_384,
208  N_("BlueMidnightWish-384 digest"), NULL },
209  { "bmw-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_BMW_512,
210  N_("BlueMidnightWish-512 digest"), NULL },
211  { "chi-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CHI_224,
212  N_("Chi-224 digest"), NULL },
213  { "chi-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CHI_256,
214  N_("Chi-256 digest"), NULL },
215  { "chi-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CHI_384,
216  N_("Chi-384 digest"), NULL },
217  { "chi-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CHI_512,
218  N_("Chi-512 digest"), NULL },
219  { "cubehash-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CUBEHASH_224,
220  N_("CubeHash-224 digest"), NULL },
221  { "cubehash-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CUBEHASH_256,
222  N_("CubeHash-256 digest"), NULL },
223  { "cubehash-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CUBEHASH_384,
224  N_("CubeHash-384 digest"), NULL },
225  { "cubehash-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CUBEHASH_512,
226  N_("CubeHash-512 digest"), NULL },
227  { "echo-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_ECHO_224,
228  N_("Echo-224 digest"), NULL },
229  { "echo-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_ECHO_256,
230  N_("Echo-256 digest"), NULL },
231  { "echo-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_ECHO_384,
232  N_("Echo-384 digest"), NULL },
233  { "echo-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_ECHO_512,
234  N_("Echo-512 digest"), NULL },
235  { "edonr-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_EDONR_224,
236  N_("EdonR-224 digest"), NULL },
237  { "edonr-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_EDONR_256,
238  N_("EdonR-256 digest"), NULL },
239  { "edonr-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_EDONR_384,
240  N_("EdonR-384 digest"), NULL },
241  { "edonr-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_EDONR_512,
242  N_("EdonR-512 digest"), NULL },
243  { "fugue-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_FUGUE_224,
244  N_("Fugue-224 digest"), NULL },
245  { "fugue-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_FUGUE_256,
246  N_("Fugue-256 digest"), NULL },
247  { "fugue-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_FUGUE_384,
248  N_("Fugue-384 digest"), NULL },
249  { "fugue-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_FUGUE_512,
250  N_("Fugue-512 digest"), NULL },
251  { "groestl-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_GROESTL_224,
252  N_("Groestl-224 digest"), NULL },
253  { "groestl-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_GROESTL_256,
254  N_("Groestl-256 digest"), NULL },
255  { "groestl-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_GROESTL_384,
256  N_("Groestl-384 digest"), NULL },
257  { "groestl-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_GROESTL_512,
258  N_("Groestl-512 digest"), NULL },
259  { "hamsi-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_HAMSI_224,
260  N_("Hamsi-224 digest"), NULL },
261  { "hamsi-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_HAMSI_256,
262  N_("Hamsi-256 digest"), NULL },
263  { "hamsi-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_HAMSI_384,
264  N_("Hamsi-384 digest"), NULL },
265  { "hamsi-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_HAMSI_512,
266  N_("Hamsi-512 digest"), NULL },
267  { "jh-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_JH_224,
268  N_("JH-224 digest"), NULL },
269  { "jh-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_JH_256,
270  N_("JH-256 digest"), NULL },
271  { "jh-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_JH_384,
272  N_("JH-384 digest"), NULL },
273  { "jh-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_JH_512,
274  N_("JH-512 digest"), NULL },
275  { "keccak-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_KECCAK_224,
276  N_("Keccak-224 digest"), NULL },
277  { "keccak-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_KECCAK_256,
278  N_("Keccak-256 digest"), NULL },
279  { "keccak-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_KECCAK_384,
280  N_("Keccak-384 digest"), NULL },
281  { "keccak-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_KECCAK_512,
282  N_("Keccak-512 digest"), NULL },
283  { "lane-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_LANE_224,
284  N_("Lane-224 digest"), NULL },
285  { "lane-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_LANE_256,
286  N_("Lane-256 digest"), NULL },
287  { "lane-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_LANE_384,
288  N_("Lane-384 digest"), NULL },
289  { "lane-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_LANE_512,
290  N_("Lane-512 digest"), NULL },
291  { "luffa-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_LUFFA_224,
292  N_("Luffa-224 digest"), NULL },
293  { "luffa-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_LUFFA_256,
294  N_("Luffa-256 digest"), NULL },
295  { "luffa-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_LUFFA_384,
296  N_("Luffa-384 digest"), NULL },
297  { "luffa-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_LUFFA_512,
298  N_("Luffa-512 digest"), NULL },
299  { "md6-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_MD6_224,
300  N_("MD6-224 digest"), NULL },
301  { "md6-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_MD6_256,
302  N_("MD6-256 digest"), NULL },
303  { "md6-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_MD6_384,
304  N_("MD6-384 digest"), NULL },
305  { "md6-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_MD6_512,
306  N_("MD6-512digest"), NULL },
307  { "rg32-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_RG32_256,
308  N_("RadioGatun32-256 digest"), NULL },
309  { "rg64-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_RG64_256,
310  N_("RadioGatun64-256 digest"), NULL },
311  { "shabal-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHABAL_224,
312  N_("Shabal-224 digest"), NULL },
313  { "shabal-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHABAL_256,
314  N_("Shabal-256 digest"), NULL },
315  { "shabal-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHABAL_384,
316  N_("Shabal-384 digest"), NULL },
317  { "shabal-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHABAL_512,
318  N_("Shabal-512 digest"), NULL },
319  { "shavite3-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHAVITE3_224,
320  N_("SHAvite3-224 digest"), NULL },
321  { "shavite3-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHAVITE3_256,
322  N_("SHAvite3-256 digest"), NULL },
323  { "shavite3-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHAVITE3_384,
324  N_("SHAvite3-384 digest"), NULL },
325  { "shavite3-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SHAVITE3_512,
326  N_("SHAvite3-512 digest"), NULL },
327  { "simd-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SIMD_224,
328  N_("SIMD-224 digest"), NULL },
329  { "simd-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SIMD_256,
330  N_("SIMD-256 digest"), NULL },
331  { "simd-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SIMD_384,
332  N_("SIMD-384 digest"), NULL },
333  { "simd-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_SIMD_512,
334  N_("SIMD-512 digest"), NULL },
335  { "tib3-224",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_TIB3_224,
336  N_("TIB3-224 digest"), NULL },
337  { "tib3-256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_TIB3_256,
338  N_("TIB3-256 digest"), NULL },
339  { "tib3-384",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_TIB3_384,
340  N_("TIB3-384 digest"), NULL },
341  { "tib3-512",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_TIB3_512,
342  N_("TIB3-512 digest"), NULL },
343  { "salsa10",'\0', POPT_ARG_VAL,&rpmioDigestHashAlgo, PGPHASHALGO_SALSA10,
344  N_("SALSA-10 hash"), NULL },
345  { "salsa20",'\0', POPT_ARG_VAL,&rpmioDigestHashAlgo, PGPHASHALGO_SALSA20,
346  N_("SALSA-20 hash"), NULL },
347  { "rmd128",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_RIPEMD128,
348  N_("RIPEMD-128 digest"), NULL },
349  { "rmd160",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_RIPEMD160,
350  N_("RIPEMD-160 digest"), NULL },
351  { "rmd256",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_RIPEMD256,
352  N_("RIPEMD-256 digest"), NULL },
353  { "rmd320",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_RIPEMD320,
354  N_("RIPEMD-320 digest"), NULL },
355  { "tiger",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_TIGER192,
356  N_("TIGER digest"), NULL },
357  { "crc32",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CRC32,
358  N_("CRC-32 checksum"), NULL },
359  { "crc64",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_CRC64,
360  N_("CRC-64 checksum"), NULL },
361  { "adler32",'\0', POPT_ARG_VAL,&rpmioDigestHashAlgo, PGPHASHALGO_ADLER32,
362  N_("ADLER-32 checksum"), NULL },
363  { "jlu32",'\0', POPT_ARG_VAL, &rpmioDigestHashAlgo, PGPHASHALGO_JLU32,
364  N_("Lookup3 hash"), NULL },
365  { "nodigest",'\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmioDigestHashAlgo, PGPHASHALGO_NONE,
366  N_("No hash algorithm"), NULL },
367  { "alldigests",'\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmioDigestHashAlgo, 256,
368  N_("All hash algorithm(s)"), NULL },
369  POPT_TABLEEND
370 };
371 
375 static void printVersion(FILE * fp)
376  /*@globals rpmioEVR, fileSystem @*/
377  /*@modifies *fp, fileSystem @*/
378 {
379  fprintf(fp, _("%s (" RPM_NAME ") %s\n"), __progname, rpmioEVR);
380 }
381 
382 void rpmioConfigured(void)
383  /*@globals rpmioInitialized @*/
384  /*@modifies rpmioInitialized @*/
385 {
386 
387  if (rpmioInitialized < 0) {
388  /* XXX TODO: add initialization side-effects. */
389  rpmioInitialized = 0;
390  }
391  if (rpmioInitialized)
392  exit(EXIT_FAILURE);
393 }
394 
397 static void rpmioAllArgCallback(poptContext con,
398  /*@unused@*/ enum poptCallbackReason reason,
399  const struct poptOption * opt, const char * arg,
400  /*@unused@*/ const void * data)
401  /*@globals pgpImplVecs,
402  rpmGlobalMacroContext,
403  fileSystem, internalState @*/
404  /*@modifies con, pgpImplVecs,
405  rpmGlobalMacroContext,
406  fileSystem, internalState @*/
407 {
408 
409  /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
410  if (opt->arg == NULL)
411  switch (opt->val) {
412  case 'q':
414  break;
415  case 'v':
417  break;
418 #ifdef NOTYET
419  case 'D':
420  { char *s, *t;
421  /* XXX Convert '-' in macro name to underscore, skip leading %. */
422  s = t = xstrdup(arg);
423  while (*t && !xisspace((int)*t)) {
424  if (*t == '-') *t = '_';
425  t++;
426  }
427  t = s;
428  if (*t == '%') t++;
429  rpmioConfigured();
430 /*@-type@*/
431  /* XXX adding macro to global context isn't Right Thing Todo. */
432  (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
434 /*@=type@*/
435  s = _free(s);
436  } break;
437  case POPT_UNDEFINE:
438  { char *s, *t;
439  /* XXX Convert '-' in macro name to underscore, skip leading %. */
440  s = t = xstrdup(arg);
441  while (*t && !xisspace((int)*t)) {
442  if (*t == '-') *t = '_';
443  t++;
444  }
445  t = s;
446  if (*t == '%') t++;
447 /*@-type@*/
448  rpmioConfigured();
449  (void) rpmUndefineMacro(NULL, t);
451 /*@=type@*/
452  s = _free(s);
453  } break;
454  case 'E':
455  rpmioConfigured();
456  { const char *val = rpmExpand(arg, NULL);
457  size_t val_len;
458  val_len = strlen(val);
459  if (val[val_len - 1] == '\n')
460  fwrite(val, val_len, 1, stdout);
461  else
462  fprintf(stdout, "%s\n", val);
463  val = _free(val);
464  }
465  break;
466 #endif /* NOTYET */
467  case POPT_CRYPTO:
468  { const char *val;
469 #ifdef NOTYET
470  rpmioConfigured();
471  val = rpmExpand(arg, NULL);
472 #else
473  val = xstrdup(arg);
474 #endif /* NOTYET */
475  if (!xstrcasecmp(val, "beecrypt") || !xstrcasecmp(val, "bc")) {
476 #if defined(WITH_BEECRYPT)
478 #else
479  rpmlog(RPMLOG_ERR, "BeeCrypt (\"beecrypt\") based cryptography implementation not available\n");
480  exit(EXIT_FAILURE);
481 #endif
482  }
483  else if (!xstrcasecmp(val, "gcrypt") || !xstrcasecmp(val, "gc")) {
484 #if defined(WITH_GCRYPT)
486 #else
487  rpmlog(RPMLOG_ERR, "GCrypt (\"gcrypt\") based cryptography implementation not available\n");
488  exit(EXIT_FAILURE);
489 #endif
490  }
491  else if (!xstrcasecmp(val, "tomcrypt") || !xstrcasecmp(val, "ltc")) {
492 #if defined(WITH_TOMCRYPT)
494 #else
495  rpmlog(RPMLOG_ERR, "TomCrypt (\"tomcrypt\") based cryptography implementation not available\n");
496  exit(EXIT_FAILURE);
497 #endif
498  }
499  else if (!xstrcasecmp(val, "NSS")) {
500 #if defined(WITH_NSS)
502 #else
503  rpmlog(RPMLOG_ERR, "Mozilla NSS (\"nss\") based cryptography implementation not available\n");
504  exit(EXIT_FAILURE);
505 #endif
506  }
507  else if (!xstrcasecmp(val, "OpenSSL") || !xstrcasecmp(val, "ssl")) {
508 #if defined(WITH_SSL)
510 #else
511  rpmlog(RPMLOG_ERR, "OpenSSL (\"openssl\") based cryptography implementation not available\n");
512  exit(EXIT_FAILURE);
513 #endif
514  }
515  else if (!xstrcasecmp(val, "CDSA")) {
516 #if defined(WITH_CDSA)
517  pgpImplVecs = &rpmcdsaImplVecs;
518 #else
519  rpmlog(RPMLOG_ERR, "CDSA (\"cdsa\") based cryptography implementation not available\n");
520  exit(EXIT_FAILURE);
521 #endif
522  }
523  else {
524  rpmlog(RPMLOG_ERR, "cryptography implementation \"%s\" not known\n", val);
525  exit(EXIT_FAILURE);
526  }
527  val = _free(val);
528  }
529  break;
530  case POPT_SHOWVERSION:
531  printVersion(stdout);
532 /*@i@*/ con = rpmioFini(con);
533  exit(EXIT_SUCCESS);
534  /*@notreached@*/ break;
535  }
536 }
537 
538 /*@unchecked@*/
539 int rpmioFtsOpts = 0;
540 
541 /*@unchecked@*/
542 struct poptOption rpmioFtsPoptTable[] = {
543  { "comfollow", '\0', POPT_BIT_SET, &rpmioFtsOpts, FTS_COMFOLLOW,
544  N_("FTS_COMFOLLOW: follow command line symlinks"), NULL },
545  { "logical", '\0', POPT_BIT_SET, &rpmioFtsOpts, FTS_LOGICAL,
546  N_("FTS_LOGICAL: logical walk"), NULL },
547  { "nochdir", '\0', POPT_BIT_SET, &rpmioFtsOpts, FTS_NOCHDIR,
548  N_("FTS_NOCHDIR: don't change directories"), NULL },
549  { "nostat", '\0', POPT_BIT_SET, &rpmioFtsOpts, FTS_NOSTAT,
550  N_("FTS_NOSTAT: don't get stat info"), NULL },
551  { "physical", '\0', POPT_BIT_SET, &rpmioFtsOpts, FTS_PHYSICAL,
552  N_("FTS_PHYSICAL: physical walk"), NULL },
553  { "seedot", '\0', POPT_BIT_SET, &rpmioFtsOpts, FTS_SEEDOT,
554  N_("FTS_SEEDOT: return dot and dot-dot"), NULL },
555  { "xdev", '\0', POPT_BIT_SET, &rpmioFtsOpts, FTS_XDEV,
556  N_("FTS_XDEV: don't cross devices"), NULL },
557  { "whiteout", '\0', POPT_BIT_SET, &rpmioFtsOpts, FTS_WHITEOUT,
558  N_("FTS_WHITEOUT: return whiteout information"), NULL },
559  POPT_TABLEEND
560 };
561 
562 /*@-bitwisesigned -compmempass @*/
563 /*@unchecked@*/
564 struct poptOption rpmioAllPoptTable[] = {
565 /*@-type@*/ /* FIX: cast? */
566  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
567  (void *)rpmioAllArgCallback, 0, NULL, NULL },
568 /*@=type@*/
569 
570  { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &__debug, -1,
571  N_("Debug generic operations"), NULL },
572 
573 #ifdef NOTYET
574  { "define", 'D', POPT_ARG_STRING, NULL, (int)'D',
575  N_("Define MACRO with value EXPR"),
576  N_("'MACRO EXPR'") },
577  { "undefine", '\0', POPT_ARG_STRING, NULL, POPT_UNDEFINE,
578  N_("Undefine MACRO"),
579  N_("'MACRO'") },
580  { "eval", 'E', POPT_ARG_STRING, NULL, (int)'E',
581  N_("Print macro expansion of EXPR"),
582  N_("'EXPR'") },
583 
584  { "macros", '\0', POPT_ARG_STRING, &rpmMacrofiles, 0,
585  N_("Read <FILE:...> instead of default file(s)"),
586  N_("<FILE:...>") },
587 #ifdef WITH_LUA
588  { "rpmlua", '\0', POPT_ARG_STRING, &rpmluaFiles, 0,
589  N_("Read <FILE:...> instead of default RPM Lua file(s)"),
590  N_("<FILE:...>") },
591 #endif
592  { "rpmpopt", '\0', POPT_ARG_STRING, NULL, 0,
593  N_("Read <FILE:...> instead of default POPT file(s)"),
594  N_("<FILE:...>") },
595 #endif /* NOTYET */
596 
597  { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmioPipeOutput, 0,
598  N_("Send stdout to CMD"),
599  N_("CMD") },
600  { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmioRootDir, 0,
601  N_("Use ROOT as top level directory"),
602  N_("ROOT") },
603 
604  { "quiet", '\0', 0, NULL, (int)'q',
605  N_("Provide less detailed output"), NULL},
606  { "verbose", 'v', 0, NULL, (int)'v',
607  N_("Provide more detailed output"), NULL},
608  { "version", '\0', 0, NULL, POPT_SHOWVERSION,
609  N_("Print the version"), NULL },
610 
611 #if defined(HAVE_LIBIO_H) && defined(_G_IO_IO_FILE_VERSION)
612  { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, -1,
613  N_("Disable use of libio(3) API"), NULL},
614 #endif
615 
616  { "usecrypto",'\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_CRYPTO,
617  N_("Select cryptography implementation"),
618  N_("CRYPTO") },
619 
620  { "ardebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ar_debug, -1,
621  N_("Debug ar archives"), NULL},
622  { "avdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_av_debug, -1,
623  N_("Debug argv collections"), NULL},
624  { "cpiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_cpio_debug, -1,
625  N_("Debug cpio archives"), NULL},
626  { "ctxdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ctx_debug, -1,
627  N_("Debug digest contexts"), NULL},
628  { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1,
629  N_("Debug WebDAV data stream"), NULL},
630  { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
631  N_("Debug FTP/HTTP data stream"), NULL},
632  { "ftsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fts_debug, -1,
633  N_("Debug Fts(3) traverse"), NULL},
634  { "htdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ht_debug, -1,
635  N_("Debug hash tables"), NULL},
636  { "htmldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_html_debug, -1,
637  N_("Debug HTML parsing"), NULL},
638  { "iosmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_iosm_debug, -1,
639  N_("Debug I/O state machine"), NULL},
640  { "miredebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_mire_debug, -1,
641  N_("Debug miRE patterns"), NULL},
642  { "pgpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_pgp_debug, -1,
643  N_("Debug PGP usage"), NULL},
644  { "pgpprint", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_pgp_print, -1,
645  N_("Print PGP keys"), NULL},
646  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
647  N_("Debug rpmio I/O"), NULL},
648  { "rpmiobdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmiob_debug, -1,
649  N_("Debug rpmio I/O buffers"), NULL},
650 
651  { "rpmasndebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmasn_debug, -1,
652  N_("Debug embedded ASN.1 interpreter"), NULL},
653  { "rpmbagdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmbag_debug, -1,
654  N_("Debug depsolver wrappers "), NULL},
655  { "rpmcvsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmcvs_debug, -1,
656  N_("Debug CVS wrappers "), NULL},
657  { "rpmgitdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgit_debug, -1,
658  N_("Debug GIT wrappers "), NULL},
659  { "rpmsetdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmset_debug, -1,
660  N_("Debug SET-VERSION wrappers "), NULL},
661  { "rpmsvndebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsvn_debug, -1,
662  N_("Debug Subversion wrappers "), NULL},
663  { "rpmtpmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmtpm_debug, -1,
664  N_("Debug TPM emulator"), NULL},
665 
666  { "rpmaugdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmaug_debug, -1,
667  N_("Debug embedded Augeas interpreter"), NULL},
668  { "rpmbfdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmbf_debug, -1,
669  N_("Debug Bloom filters"), NULL},
670  { "rpmcudfdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmcudf_debug, -1,
671  N_("Debug embedded CUDF parser"), NULL},
672  { "rpmficldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmficl_debug, -1,
673  N_("Debug embedded FICL interpreter"), NULL},
674  { "rpmhkpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmhkp_debug, -1,
675  N_("Debug hkp:// keyring"), NULL},
676  { "rpmjsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmjs_debug, -1,
677  N_("Debug embedded JavaScript interpreter"), NULL},
678 #ifdef WITH_LUA
679  { "rpmluadebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmlua_debug, -1,
680  N_("Debug embedded Lua interpreter"), NULL},
681 #endif
682  { "rpmmgdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmmg_debug, -1,
683  N_("Debug rpmmg magic"), NULL},
684  { "rpmmrbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmmrb_debug, -1,
685  N_("Debug embedded MRuby interpreter"), NULL},
686  { "mongodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmmgo_debug, -1,
687  N_("Debug Mongo DB connection"), NULL},
688  { "nixdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmnix_debug, -1,
689  N_("Debug embedded Nix interpreter"), NULL},
690  { "odbcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_odbc_debug, -1,
691  N_("Debug embedded ODBC interface"), NULL},
692  { "rpmperldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmperl_debug, -1,
693  N_("Debug embedded Perl interpreter"), NULL},
694  { "rpmpythondebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmpython_debug, -1,
695  N_("Debug embedded Python interpreter"), NULL},
696  { "rpmrubydebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmruby_debug, -1,
697  N_("Debug embedded Ruby interpreter"), NULL},
698  { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
699  N_("Debug rpmsq Signal Queue"), NULL},
700  { "rpmsqldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsql_debug, -1,
701  N_("Debug embedded SQL interpreter"), NULL},
702  { "rpmsquirreldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsquirrel_debug, -1,
703  N_("Debug embedded SQUIRREL interpreter"), NULL},
704  { "rpmsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsm_debug, 1,
705  N_("Debug semanage"), NULL},
706  { "rpmspdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsp_debug, 1,
707  N_("Debug sepol"), NULL},
708  { "rpmsxdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsx_debug, 1,
709  N_("Debug selinux"), NULL},
710  { "rpmtcldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmtcl_debug, -1,
711  N_("Debug embedded TCL interpreter"), NULL},
712  { "rpmvcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmvc_debug, -1,
713  N_("Debug embedded SQL virtual cursor"), NULL},
714  { "rpmvtdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmvt_debug, -1,
715  N_("Debug embedded SQL virtual table"), NULL},
716 #ifdef WITH_BZIP2
717  { "rpmzqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmzq_debug, -1,
718  N_("Debug rpmzq Job Queuing"), NULL},
719 #endif
720  { "xardebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_xar_debug, -1,
721  N_("Debug xar archives"), NULL},
722  { "tardebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_tar_debug, -1,
723  N_("Debug tar archives"), NULL},
724  { "stats", '\0', POPT_ARG_VAL, &_rpmsw_stats, -1,
725  N_("Display operation statistics"), NULL},
726  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
727  N_("Debug URL cache handling"), NULL},
728 
729  POPT_TABLEEND
730 };
731 /*@=bitwisesigned =compmempass @*/
732 
733 poptContext
734 rpmioFini(poptContext optCon)
735 {
736  /* XXX this should be done in the rpmioClean() wrapper. */
737  /* keeps memory leak checkers quiet */
738  rpmFreeMacros(NULL);
740 
741  rpmioClean();
742 
743  optCon = poptFreeContext(optCon);
744 
745 #if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
746  /*@-noeffect@*/
747  muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
748  /*@=noeffect@*/
749 #endif
750 
751  return NULL;
752 }
753 
754 static inline int checkfd(const char * devnull, int fdno, int flags)
755  /*@*/
756 {
757  struct stat sb;
758  int ret = 0;
759 
760  if (fstat(fdno, &sb) == -1 && errno == EBADF)
761  ret = (open(devnull, flags) == fdno) ? 1 : 2;
762  return ret;
763 }
764 
765 /*@-globstate@*/
766 poptContext
767 rpmioInit(int argc, char *const argv[], struct poptOption * optionsTable)
768 {
769  poptContext optCon;
770  int rc;
771 #ifdef NOTYET
772  int i;
773 #endif
774 
775 #if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
776  /*@-noeffect@*/
777  mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
778  /*@=noeffect@*/
779 #endif
780 /*@-globs -mods@*/
781  setprogname(argv[0]); /* Retrofit glibc __progname */
782 
783  /* XXX glibc churn sanity */
784  if (__progname == NULL) {
785  if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
786  else __progname = argv[0];
787  }
788 /*@=globs =mods@*/
789 
790  /* Insure that stdin/stdout/stderr are open, lest stderr end up in rpmdb. */
791  { static const char _devnull[] = "/dev/null";
792 #if defined(STDIN_FILENO)
793  (void) checkfd(_devnull, STDIN_FILENO, O_RDONLY);
794 #endif
795 #if defined(STDOUT_FILENO)
796  (void) checkfd(_devnull, STDOUT_FILENO, O_WRONLY);
797 #endif
798 #if defined(STDERR_FILENO)
799  (void) checkfd(_devnull, STDERR_FILENO, O_WRONLY);
800 #endif
801  }
802 
803 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
804  (void) setlocale(LC_ALL, "" );
806  (void) textdomain(PACKAGE);
807 #endif
808 
810 
811  if (optionsTable == NULL) {
812  /* Read rpm configuration (if not already read). */
813  rpmioConfigured();
814  return NULL;
815  }
816 
817 #ifdef NOTYET
818  /* read all RPM POPT configuration files */
819  for (i = 1; i < argc; i++) {
820  if (strcmp(argv[i], "--rpmpopt") == 0 && i+1 < argc) {
821  rpmpoptfiles = argv[i+1];
822  break;
823  }
824  else if (strncmp(argv[i], "--rpmpopt=", 10) == 0) {
825  rpmpoptfiles = argv[i]+10;
826  break;
827  }
828  }
829 #endif /* NOTYET */
830 
831 /*@-nullpass -temptrans@*/
832  optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, _rpmio_popt_context_flags);
833 /*@=nullpass =temptrans@*/
834 
835 #ifdef NOTYET
836 #if defined(RPM_VENDOR_OPENPKG) /* stick-with-rpm-file-sanity-checking */ || \
837  !defined(POPT_ERROR_BADCONFIG) /* XXX POPT 1.15 retrofit */
838  { char * path_buf = xstrdup(rpmpoptfiles);
839  char *path;
840  char *path_next;
841 
842  for (path = path_buf; path != NULL && *path != '\0'; path = path_next) {
843  const char **av;
844  int ac, i;
845 
846  /* locate start of next path element */
847  path_next = strchr(path, ':');
848  if (path_next != NULL && *path_next == ':')
849  *path_next++ = '\0';
850  else
851  path_next = path + strlen(path);
852 
853  /* glob-expand the path element */
854  ac = 0;
855  av = NULL;
856  if ((i = rpmGlob(path, &ac, &av)) != 0)
857  continue;
858 
859  /* work-off each resulting file from the path element */
860  for (i = 0; i < ac; i++) {
861  const char *fn = av[i];
862  if (fn[0] == '@' /* attention */) {
863  fn++;
864  if (!rpmSecuritySaneFile(fn)) {
865  rpmlog(RPMLOG_WARNING, "existing POPT configuration file \"%s\" considered INSECURE -- not loaded\n", fn);
866  continue;
867  }
868  }
869  (void)poptReadConfigFile(optCon, fn);
870  av[i] = _free(av[i]);
871  }
872  av = _free(av);
873  }
874  path_buf = _free(path_buf);
875  }
876 #else
877  /* XXX FIXME: better error message is needed. */
878  if ((xx = poptReadConfigFiles(optCon, rpmpoptfiles)) != 0)
879  rpmlog(RPMLOG_WARNING, "existing POPT configuration file \"%s\" considered INSECURE -- not loaded\n", rpmpoptfiles);
880 #endif
881 
882  /* read standard POPT configuration files */
883  /* XXX FIXME: the 2nd arg useEnv flag is UNUSED. */
884  (void) poptReadDefaultConfig(optCon, 1);
885 
886  poptSetExecPath(optCon, USRLIBRPM, 1);
887 #endif /* NOTYET */
888 
889  /* Process all options, whine if unknown. */
890  while ((rc = poptGetNextOpt(optCon)) > 0) {
891  const char * optArg = poptGetOptArg(optCon);
892 /*@-dependenttrans -modobserver -observertrans @*/
893  optArg = _free(optArg);
894 /*@=dependenttrans =modobserver =observertrans @*/
895  switch (rc) {
896  default:
897 /*@-nullpass@*/
898  fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
899  __progname, rc);
900 /*@=nullpass@*/
901  exit(EXIT_FAILURE);
902 
903  /*@notreached@*/ /*@switchbreak@*/ break;
904  }
905  }
906 
907  if (rc < -1) {
908 /*@-nullpass@*/
909  fprintf(stderr, "%s: %s: %s\n", __progname,
910  poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
911  poptStrerror(rc));
912 /*@=nullpass@*/
913  exit(EXIT_FAILURE);
914  }
915 
916  /* Read rpm configuration (if not already read). */
917  rpmioConfigured();
918 
919  if (__debug) {
922  }
923 
924  return optCon;
925 }
926 /*@=globstate@*/
927 
935 /*@null@*/
936 static char *
937 matchchar(char * p, char pl, char pr)
938  /*@*/
939 {
940  int lvl = 0;
941  char c;
942 
943  while ((c = *p++) != '\0') {
944  if (c == '\\') { /* Ignore escaped chars */
945  p++;
946  continue;
947  }
948  if (c == pr) {
949  if (--lvl <= 0) return --p;
950  } else if (c == pl)
951  lvl++;
952  }
953  return (char *)NULL;
954 }
955 
957 {
958  if (P != NULL) {
959  P->str = _free(P->str);
960  P->av = argvFree(P->av);
961  P = _free(P);
962  }
963  return NULL;
964 }
965 
966 rpmRC rpmioParse(rpmioP *Pptr, const char * str)
967 {
968  static char whitespace[] = " \t\n\r";
969  rpmioP P;
970  rpmRC rc = RPMRC_FAIL; /* assume failure */
971  char *b;
972  char *be;
973  int xx;
974  int c;
975 
976  if ((P = *Pptr) == NULL)
977  *Pptr = P = (rpmioP) xcalloc(1, sizeof(*P));
978 
979  if (str != NULL) {
980  P->str = _free(P->str);
981  P->next = P->str = xstrdup(str);
982  }
983 
984  /* Ltrim whitespace. Anything left to parse? */
985  if ((b = P->next) != NULL)
986  while (*b && strchr(whitespace, *b))
987  *b++ = '\0';
988  if (b == NULL || *b == '\0')
989  return RPMRC_NOTFOUND;
990 
991  /* Parse next command into an argv. */
992  P->ac = 0;
993  P->av = argvFree(P->av);
994  if ((be = b) != NULL)
995  while (1) {
996  c = *be++;
997  switch (c) {
998  default:
999  break;
1000  case '\\': /* escaped character. */
1001  if (*be != '\0')
1002  be++;
1003  break;
1004  case '\0': /* end-of-command termination. */
1005  case '\n':
1006  case '\r':
1007  case ';':
1008  if (be[-1] != '\0')
1009  be[-1] = '\0';
1010  else
1011  be--; /* XXX one too far */
1012  if ((be - b) > 1) {
1013  xx = argvAdd(&P->av, b);
1014  P->ac++;
1015  }
1016  goto exit;
1017  break;
1018  case '[': /* XPath construct with '[' balancing. */
1019  if ((be = matchchar(be, '[', ']')) == NULL) {
1020  be += strlen(b); /* XXX unmatched ']' */
1021  goto exit;
1022  }
1023  be++;
1024  break;
1025  case '"': /* quoted string */
1026  while (1) {
1027  if ((be = strchr(be, '"')) == NULL) {
1028  be += strlen(b); /* XXX unmatched '"' */
1029  goto exit;
1030  }
1031  be++;
1032  if (be[-2] == '\\') /* escaped quote */
1033  continue;
1034  break;
1035  }
1036  break;
1037  case ' ': /* argument separator */
1038  case '\t':
1039  be[-1] = '\0';
1040  if ((be - b) > 1) {
1041  xx = argvAdd(&P->av, b);
1042  P->ac++;
1043  }
1044  b = be;
1045  while (*b && (*b == ' ' || *b == '\t'))
1046  *b++ = '\0';
1047  be = b;
1048  break;
1049  }
1050  }
1051  rc = RPMRC_OK;
1052 
1053 exit:
1054  P->next = be;
1055  return rc;
1056 }
const bson * b
Definition: bson.h:280
#define RPMPOPTFILES
Definition: config.h:1156
void rpmFreeMacros(MacroContext mc)
Destroy macro context.
Definition: macro.c:3076
const char ** av
Definition: rpmiotypes.h:72
int noLibio
Definition: rpmio.c:167
int _rpmsx_debug
Definition: rpmsx.c:61
#define FTS_XDEV
Definition: fts.h:93
int _rpmbf_debug
Definition: rpmbf.c:22
pgpImplVecs_t * pgpImplVecs
Definition: rpmpgp.c:51
poptContext rpmioInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpmio executable context.
Definition: poptIO.c:767
struct pgpImplVecs_s rpmbcImplVecs
Definition: rpmbc.c:695
int _rpmgit_debug
Definition: rpmgit.c:21
#define setprogname(pn)
Definition: system.h:364
int _mire_debug
Definition: mire.c:18
struct poptOption rpmioDigestPoptTable[]
Digest options using popt.
Definition: poptIO.c:152
int _rpmasn_debug
Definition: rpmasn.c:21
void rpmioClean(void)
Free all memory allocated by rpmio usage.
Definition: rpmio.c:3228
int _ftp_debug
Definition: rpmio.c:190
int _rpmvt_debug
Definition: rpmsql.c:46
struct rpmioP_s * rpmioP
static int checkfd(const char *devnull, int fdno, int flags)
Definition: poptIO.c:754
int _rpmmgo_debug
Definition: mongo.c:42
int _ar_debug
Definition: ar.c:23
#define EXIT_FAILURE
char * xstrdup(const char *str)
Definition: rpmmalloc.c:321
int _rpmiob_debug
Definition: rpmiob.c:14
int _rpmsm_debug
Definition: rpmsm.c:21
MacroContext rpmCLIMacroContext
Definition: macro.c:129
enum pgpHashAlgo_e pgpHashAlgo
9.4.
int _rpmcudf_debug
Definition: rpmcudf.c:14
static struct poptOption optionsTable[]
Definition: rpmqv.c:168
int _html_debug
Definition: rpmdav.c:1117
pgpImplVecs_t rpmltcImplVecs
Implementation specific parameter storage.
struct poptOption rpmioFtsPoptTable[]
Popt option table for options to set Fts(3) options.
Definition: poptIO.c:542
#define VERSION
Definition: config.h:1306
int _rpmsq_debug
Definition: rpmsq.c:278
int errno
int _rpmzq_debug
static void rpmlog(int code, const char *fmt,...)
Definition: rpmlog.h:299
pgpImplVecs_t rpmnssImplVecs
pgpHashAlgo rpmioDigestHashAlgo
Definition: poptIO.c:147
int _ctx_debug
Definition: digest.c:113
#define bindtextdomain(Domain, Directory)
Definition: system.h:522
const char * rpmioPipeOutput
Definition: poptIO.c:124
int _rpmsquirrel_debug
Definition: rpmsquirrel.c:24
int _rpmmg_debug
Definition: rpmmg.c:21
#define POPT_UNDEFINE
Definition: poptIO.c:72
const char * str
Definition: bson.h:593
#define POPT_CRYPTO
Definition: poptIO.c:73
int rpmGlob(const char *patterns, int *argcPtr, const char ***argvPtr)
Return URL path(s) from a (URL prefixed) pattern glob.
Definition: macro.c:2607
void * xcalloc(size_t nmemb, size_t size)
Definition: rpmmalloc.c:300
int _av_debug
Definition: rpmio.c:185
int _rpmperl_debug
Definition: rpmperl.c:19
int _rpmjs_debug
Definition: rpmjs.c:74
int _rpmruby_debug
Triggers printing of debugging information.
Definition: rpmruby.c:29
#define N_(Text)
Definition: system.h:531
int _url_debug
Definition: url.c:71
int _rpmbag_debug
Definition: rpmbag.c:22
#define FTS_COMFOLLOW
Definition: fts.h:87
const char const bson * data
Definition: mongo.h:463
#define POPT_ARGFLAG_TOGGLE
Definition: poptIO.c:69
static int xisspace(int c)
Definition: rpmiotypes.h:555
const char * rpmioRootDir
Definition: poptIO.c:127
int _rpmvc_debug
Definition: rpmsql.c:49
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
Definition: argv.c:44
#define setlocale(Category, Locale)
Definition: system.h:513
static void printVersion(FILE *fp)
Display rpm version.
Definition: poptIO.c:375
int _rpmsvn_debug
Definition: rpmsvn.c:25
int rpmDefineMacro(MacroContext mc, const char *macro, int level)
Define macro in context.
Definition: macro.c:2849
rpmioP rpmioPFree(rpmioP P)
Destroy a rpmioP object.
Definition: poptIO.c:956
int _rpmtcl_debug
Definition: rpmtcl.c:14
static void rpmioAllArgCallback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
Definition: poptIO.c:397
int _dav_debug
Definition: rpmio.c:195
char * str
Definition: rpmiotypes.h:70
const char * rpmluaFiles
int _rpmpython_debug
Definition: rpmpython.c:20
const char * rpmMacrofiles
List of macro files to read when configuring rpm.
Definition: macro.c:62
#define FTS_SEEDOT
Definition: fts.h:92
pgpImplVecs_t rpmsslImplVecs
Implementation specific parameter storage.
int argvAdd(ARGV_t *argvp, ARGstr_t val)
Add a string to an argv array.
Definition: argv.c:199
#define RPM_NAME
Definition: config.h:1165
char * next
Definition: rpmiotypes.h:71
int xstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
Definition: strcasecmp.c:9
int rpmioFtsOpts
Definition: poptIO.c:539
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
Definition: macro.c:3238
Embedded Ruby interpreter.
int __debug
Definition: poptIO.c:76
#define POPT_SHOWVERSION
Definition: poptIO.c:71
#define rpmSetVerbosity(_lvl)
Definition: rpmcb.h:13
const char const char int arg
Definition: mongo.h:777
int _ht_debug
Definition: rpmhash.c:13
int _xar_debug
Definition: rpmxar.c:70
const char const bson int mongo_write_concern int flags
Definition: mongo.h:485
void rpmioConfigured(void)
Make sure that rpm configuration has been read.
Definition: poptIO.c:382
#define USRLIBRPM
Definition: config.h:1297
int _rpmcvs_debug
Definition: rpmcvs.c:17
int _rpmio_popt_context_flags
Definition: poptIO.c:145
int _rpmhkp_debug
Definition: rpmhkp.c:19
enum rpmRC_e rpmRC
RPM return codes.
int _rpmtpm_debug
Definition: rpmtpm.c:30
int _odbc_debug
Definition: rpmodbc.c:24
const char const int i
Definition: bson.h:778
#define FTS_NOCHDIR
Definition: fts.h:89
int _rpmio_debug
Definition: rpmio.c:180
#define FTS_WHITEOUT
Definition: fts.h:94
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:756
#define LOCALEDIR
Definition: config.h:1100
pgpImplVecs_t rpmgcImplVecs
Implementation specific parameter storage.
int rpmSecuritySaneFile(const char *filename)
Check whether configuration file is moderately secure to load.
Definition: macro.c:2584
static const char * rpmpoptfiles
Definition: poptALL.c:188
#define FTS_PHYSICAL
Definition: fts.h:91
#define FTS_LOGICAL
Definition: fts.h:88
#define textdomain(Domain)
Definition: system.h:524
int _tar_debug
Definition: tar.c:21
int _rpmsw_stats
Definition: rpmsw.c:20
#define _(Text)
Definition: system.h:29
#define RMIL_CMDLINE
Definition: rpmmacro.h:66
int _rpmsql_debug
Definition: rpmsql.c:43
const char * rpmioEVR
Definition: poptIO.c:130
#define PACKAGE
Definition: config.h:1123
int _rpmlua_debug
Definition: rpmlua.c:58
struct poptOption rpmioAllPoptTable[]
Popt option table for options shared by all modes and executables.
Definition: poptIO.c:564
static int rpmioInitialized
Definition: poptIO.c:133
int _cpio_debug
Definition: cpio.c:20
poptContext rpmioFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
Definition: poptIO.c:734
int _pgp_print
Definition: rpmpgp.c:45
#define FTS_NOSTAT
Definition: fts.h:90
int _rpmficl_debug
Definition: rpmficl.c:14
int _rpmset_debug
Definition: set.c:24
int _pgp_debug
Definition: rpmpgp.c:42
int rpmUndefineMacro(MacroContext mc, const char *macro)
Undefine macro in context.
Definition: macro.c:2863
int _rpmaug_debug
Definition: rpmaug.c:33
int _rpmsp_debug
Definition: rpmsp.c:25
int ac
Definition: rpmiotypes.h:73
int _fts_debug
Definition: fts.c:165
#define rpmIncreaseVerbosity()
Definition: rpmcb.h:15
static char * matchchar(char *p, char pl, char pr)
Return text between pl and matching pr characters.
Definition: poptIO.c:937
rpmRC rpmioParse(rpmioP *Pptr, const char *str)
Parse next command out of a string incrementally.
Definition: poptIO.c:966
int _iosm_debug
Definition: iosm.c:75
const char * __progname
Definition: poptIO.c:66