lib/poptQV.c

Go to the documentation of this file.
00001 
00006 #include "system.h"
00007 
00008 #include <rpmcli.h>
00009 #include <rpmbuild.h>
00010 #include <rpmgi.h>      /* XXX for giFlags */
00011 
00012 #include "debug.h"
00013 
00014 /*@unchecked@*/
00015 struct rpmQVKArguments_s rpmQVKArgs;
00016 
00017 /*@unchecked@*/
00018 int specedit = 0;
00019 
00020 #define POPT_QUERYFORMAT        -1000
00021 #define POPT_WHATREQUIRES       -1001
00022 #define POPT_WHATPROVIDES       -1002
00023 #define POPT_QUERYBYNUMBER      -1003
00024 #define POPT_TRIGGEREDBY        -1004
00025 #define POPT_DUMP               -1005
00026 #define POPT_SPECFILE           -1006
00027 #define POPT_QUERYBYPKGID       -1007
00028 #define POPT_QUERYBYHDRID       -1008
00029 #define POPT_QUERYBYFILEID      -1009
00030 #define POPT_QUERYBYTID         -1010
00031 #define POPT_HDLIST             -1011
00032 #define POPT_FTSWALK            -1012
00033 
00034 /* -1025 thrugh -1032 are common in rpmcli.h. */
00035 #define POPT_TARGETPLATFORM     -1036
00036 #define POPT_TRUST              -1037
00037 
00038 /* ========== Query/Verify/Signature source args */
00039 static void rpmQVSourceArgCallback( /*@unused@*/ poptContext con,
00040                 /*@unused@*/ enum poptCallbackReason reason,
00041                 const struct poptOption * opt, /*@unused@*/ const char * arg, 
00042                 /*@unused@*/ const void * data)
00043         /*@globals rpmQVKArgs @*/
00044         /*@modifies rpmQVKArgs @*/
00045 {
00046     QVA_t qva = &rpmQVKArgs;
00047 
00048     switch (opt->val) {
00049     case 'q':   /* from --query, -q */
00050     case 'Q':   /* from --querytags (handled by poptALL) */
00051     case 'V':   /* from --verify, -V */
00052     case 'A':   /* from --addsign */
00053     case 'D':   /* from --delsign */
00054     case 'I':   /* from --import */
00055     case 'K':   /* from --checksig, -K */
00056     case 'R':   /* from --resign */
00057         if (qva->qva_mode == '\0' || strchr("qQ ", qva->qva_mode)) {
00058             qva->qva_mode = opt->val;
00059             qva->qva_char = ' ';
00060         }
00061         break;
00062     case 'a': qva->qva_source |= RPMQV_ALL; qva->qva_sourceCount++; break;
00063     case 'f': qva->qva_source |= RPMQV_PATH; qva->qva_sourceCount++; break;
00064     case 'g': qva->qva_source |= RPMQV_GROUP; qva->qva_sourceCount++; break;
00065     case 'p': qva->qva_source |= RPMQV_RPM; qva->qva_sourceCount++; break;
00066     case POPT_WHATPROVIDES: qva->qva_source |= RPMQV_WHATPROVIDES; 
00067                                 qva->qva_sourceCount++; break;
00068     case POPT_WHATREQUIRES: qva->qva_source |= RPMQV_WHATREQUIRES; 
00069                                 qva->qva_sourceCount++; break;
00070     case POPT_TRIGGEREDBY: qva->qva_source |= RPMQV_TRIGGEREDBY;
00071                                 qva->qva_sourceCount++; break;
00072     case POPT_QUERYBYPKGID: qva->qva_source |= RPMQV_PKGID;
00073                                 qva->qva_sourceCount++; break;
00074     case POPT_QUERYBYHDRID: qva->qva_source |= RPMQV_HDRID;
00075                                 qva->qva_sourceCount++; break;
00076     case POPT_QUERYBYFILEID: qva->qva_source |= RPMQV_FILEID;
00077                                 qva->qva_sourceCount++; break;
00078     case POPT_QUERYBYTID: qva->qva_source |= RPMQV_TID;
00079                                 qva->qva_sourceCount++; break;
00080     case POPT_HDLIST: qva->qva_source |= RPMQV_HDLIST;
00081                                 qva->qva_sourceCount++; break;
00082     case POPT_FTSWALK:qva->qva_source |= RPMQV_FTSWALK;
00083                                 qva->qva_sourceCount++; break;
00084 
00085 /* XXX SPECFILE is not verify sources */
00086     case POPT_SPECFILE:
00087         qva->qva_source |= RPMQV_SPECFILE;
00088         qva->qva_sourceCount++;
00089         break;
00090     case POPT_QUERYBYNUMBER:
00091         qva->qva_source |= RPMQV_DBOFFSET; 
00092         qva->qva_sourceCount++;
00093         break;
00094     }
00095 }
00096 
00100 /*@unchecked@*/
00101 struct poptOption rpmQVSourcePoptTable[] = {
00102 /*@-type@*/ /* FIX: cast? */
00103  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA, 
00104         rpmQVSourceArgCallback, 0, NULL, NULL },
00105 /*@=type@*/
00106  { "all", 'a', 0, 0, 'a',
00107         N_("query/verify all packages"), NULL },
00108  { "checksig", 'K', POPT_ARGFLAG_DOC_HIDDEN, NULL, 'K',
00109         N_("rpm checksig mode"), NULL },
00110  { "file", 'f', 0, 0, 'f',
00111         N_("query/verify package(s) owning file"), "FILE" },
00112  { "group", 'g', 0, 0, 'g',
00113         N_("query/verify package(s) in group"), "GROUP" },
00114  { "package", 'p', 0, 0, 'p',
00115         N_("query/verify a package file"), NULL },
00116 
00117  { "ftswalk", 'W', 0, 0, POPT_FTSWALK,
00118         N_("query/verify package(s) from TOP file tree walk"), "TOP" },
00119  { "hdlist", 'H', POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_HDLIST,
00120         N_("query/verify package(s) from system HDLIST"), "HDLIST" },
00121 
00122  { "pkgid", '\0', 0, 0, POPT_QUERYBYPKGID,
00123         N_("query/verify package(s) with package identifier"), "MD5" },
00124  { "hdrid", '\0', 0, 0, POPT_QUERYBYHDRID,
00125         N_("query/verify package(s) with header identifier"), "SHA1" },
00126  { "fileid", '\0', 0, 0, POPT_QUERYBYFILEID,
00127         N_("query/verify package(s) with file identifier"), "MD5" },
00128 
00129  { "query", 'q', POPT_ARGFLAG_DOC_HIDDEN, NULL, 'q',
00130         N_("rpm query mode"), NULL },
00131  { "querybynumber", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_QUERYBYNUMBER,
00132         N_("query/verify a header instance"), "HDRNUM" },
00133  { "specfile", '\0', 0, 0, POPT_SPECFILE,
00134         N_("query a spec file"), N_("<spec>") },
00135  { "tid", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_QUERYBYTID,
00136         N_("query/verify package(s) from install transaction"), "TID" },
00137  { "triggeredby", '\0', 0, 0, POPT_TRIGGEREDBY, 
00138         N_("query the package(s) triggered by the package"), "PACKAGE" },
00139  { "verify", 'V', POPT_ARGFLAG_DOC_HIDDEN, NULL, 'V',
00140         N_("rpm verify mode"), NULL },
00141  { "whatrequires", '\0', 0, 0, POPT_WHATREQUIRES, 
00142         N_("query/verify the package(s) which require a dependency"), "CAPABILITY" },
00143  { "whatprovides", '\0', 0, 0, POPT_WHATPROVIDES, 
00144         N_("query/verify the package(s) which provide a dependency"), "CAPABILITY" },
00145 
00146  { "transaction", 'T', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &giFlags, (RPMGI_TSADD|RPMGI_TSORDER),
00147         N_("create transaction set"), NULL},
00148  { "noorder", '\0', POPT_BIT_CLR|POPT_ARGFLAG_DOC_HIDDEN, &giFlags, RPMGI_TSORDER,
00149         N_("do not order transaction set"), NULL},
00150  { "noglob", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &giFlags, RPMGI_NOGLOB,
00151         N_("do not glob arguments"), NULL},
00152  { "nomanifest", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOMANIFEST,
00153         N_("do not process non-package files as manifests"), NULL},
00154  { "noheader", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &giFlags, RPMGI_NOHEADER,
00155         N_("do not read headers"), NULL},
00156 
00157 
00158    POPT_TABLEEND
00159 };
00160 
00161 /* ========== Query specific popt args */
00162 
00163 static void queryArgCallback(poptContext con,
00164                 /*@unused@*/enum poptCallbackReason reason,
00165                 const struct poptOption * opt, const char * arg, 
00166                 /*@unused@*/ const void * data)
00167         /*@globals rpmQVKArgs @*/
00168         /*@modifies con, rpmQVKArgs @*/
00169 {
00170     QVA_t qva = &rpmQVKArgs;
00171 
00172     switch (opt->val) {
00173     case 'c': qva->qva_flags |= QUERY_FOR_CONFIG | QUERY_FOR_LIST; break;
00174     case 'd': qva->qva_flags |= QUERY_FOR_DOCS | QUERY_FOR_LIST; break;
00175     case 'l': qva->qva_flags |= QUERY_FOR_LIST; break;
00176     case 's': qva->qva_flags |= QUERY_FOR_STATE | QUERY_FOR_LIST;
00177         break;
00178     case POPT_DUMP: qva->qva_flags |= QUERY_FOR_DUMPFILES | QUERY_FOR_LIST;
00179         break;
00180 
00181     case POPT_QUERYFORMAT:
00182         if (arg) {
00183             char * qf = (char *)qva->qva_queryFormat;
00184             /*@-branchstate@*/
00185             if (qf) {
00186                 int len = strlen(qf) + strlen(arg) + 1;
00187                 qf = xrealloc(qf, len);
00188 /*@-boundswrite@*/
00189                 strcat(qf, arg);
00190 /*@=boundswrite@*/
00191             } else {
00192                 qf = xmalloc(strlen(arg) + 1);
00193                 strcpy(qf, arg);
00194             }
00195             /*@=branchstate@*/
00196             qva->qva_queryFormat = qf;
00197         }
00198         break;
00199 
00200     case 'i':
00201         if (qva->qva_mode == 'q') {
00202             /*@-nullassign -readonlytrans@*/
00203             const char * infoCommand[] = { "--info", NULL };
00204             /*@=nullassign =readonlytrans@*/
00205             (void) poptStuffArgs(con, infoCommand);
00206         }
00207         break;
00208 
00209     case RPMCLI_POPT_NODIGEST:
00210         qva->qva_flags |= VERIFY_DIGEST;
00211         break;
00212 
00213     case RPMCLI_POPT_NOSIGNATURE:
00214         qva->qva_flags |= VERIFY_SIGNATURE;
00215         break;
00216 
00217     case RPMCLI_POPT_NOHDRCHK:
00218         qva->qva_flags |= VERIFY_HDRCHK;
00219         break;
00220 
00221     case RPMCLI_POPT_NODEPS:
00222         qva->qva_flags |= VERIFY_DEPS;
00223         break;
00224 
00225     case RPMCLI_POPT_NOMD5:
00226         qva->qva_flags |= VERIFY_MD5;
00227         break;
00228 
00229     case RPMCLI_POPT_NOCONTEXTS:
00230         qva->qva_flags |= VERIFY_CONTEXTS;
00231         break;
00232 
00233 #ifdef  NOTYET
00234     case RPMCLI_POPT_FORCE:
00235         ia->probFilter |=
00236                 ( RPMPROB_FILTER_REPLACEPKG
00237                 | RPMPROB_FILTER_REPLACEOLDFILES
00238                 | RPMPROB_FILTER_REPLACENEWFILES
00239                 | RPMPROB_FILTER_OLDPACKAGE );
00240         break;
00241 #endif
00242 
00243     case RPMCLI_POPT_NOSCRIPTS:
00244         qva->qva_flags |= VERIFY_SCRIPT;
00245         break;
00246 
00247     /* XXX perhaps POPT_ARG_INT instead of callback. */
00248     case POPT_TRUST:
00249     {   char * end = NULL;
00250         long trust = (int) strtol(arg, &end, 0);
00251         /* XXX range checks on trust. */
00252         /* XXX if (end && *end) argerror(_("non-numeric trust metric.")); */
00253         qva->trust = trust;
00254     }   break;
00255     }
00256 }
00257 
00261 /*@unchecked@*/
00262 struct poptOption rpmQueryPoptTable[] = {
00263 /*@-type@*/ /* FIX: cast? */
00264  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE, 
00265         queryArgCallback, 0, NULL, NULL },
00266 /*@=type@*/
00267  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0,
00268         NULL, NULL },
00269  { "configfiles", 'c', 0, 0, 'c',
00270         N_("list all configuration files"), NULL },
00271  { "docfiles", 'd', 0, 0, 'd',
00272         N_("list all documentation files"), NULL },
00273  { "dump", '\0', 0, 0, POPT_DUMP,
00274         N_("dump basic file information"), NULL },
00275  { NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i',
00276         NULL, NULL },
00277  { "list", 'l', 0, 0, 'l',
00278         N_("list files in package"), NULL },
00279 
00280  /* Duplicate file attr flags from packages into command line options. */
00281  { "noghost", '\0', POPT_BIT_CLR|POPT_ARGFLAG_DOC_HIDDEN,
00282         &rpmQVKArgs.qva_fflags, RPMFILE_GHOST,
00283         N_("skip %%ghost files"), NULL },
00284 #ifdef  NOTEVER         /* XXX there's hardly a need for these */
00285  { "nolicense", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00286         &rpmQVKArgs.qva_fflags, RPMFILE_LICENSE,
00287         N_("skip %%license files"), NULL },
00288  { "noreadme", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00289         &rpmQVKArgs.qva_fflags, RPMFILE_README,
00290         N_("skip %%readme files"), NULL },
00291 #endif
00292 
00293  { "qf", '\0', POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN, 0, 
00294         POPT_QUERYFORMAT, NULL, NULL },
00295  { "queryformat", '\0', POPT_ARG_STRING, 0, POPT_QUERYFORMAT,
00296         N_("use the following query format"), "QUERYFORMAT" },
00297  { "specedit", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &specedit, -1,
00298         N_("substitute i18n sections into spec file"), NULL },
00299  { "state", 's', 0, 0, 's',
00300         N_("display the states of the listed files"), NULL },
00301    POPT_TABLEEND
00302 };
00303 
00307 struct poptOption rpmVerifyPoptTable[] = {
00308 /*@-type@*/ /* FIX: cast? */
00309  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE, 
00310         queryArgCallback, 0, NULL, NULL },
00311 /*@=type@*/
00312  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0,
00313         NULL, NULL },
00314 
00315  /* Duplicate file verify flags from packages into command line options. */
00317 #ifdef  DYING
00318  { "nomd5", '\0', POPT_BIT_SET, &rpmQVKArgs.qva_flags, VERIFY_MD5,
00319         N_("don't verify MD5 digest of files"), NULL },
00320 #else
00321  { "nomd5", '\0', 0, NULL, RPMCLI_POPT_NOMD5,
00322         N_("don't verify MD5 digest of files"), NULL },
00323 #endif
00324  { "nosize", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00325         &rpmQVKArgs.qva_flags, VERIFY_SIZE,
00326         N_("don't verify size of files"), NULL },
00327  { "nolinkto", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00328         &rpmQVKArgs.qva_flags, VERIFY_LINKTO,
00329         N_("don't verify symlink path of files"), NULL },
00330  { "nouser", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00331         &rpmQVKArgs.qva_flags, VERIFY_USER,
00332         N_("don't verify owner of files"), NULL },
00333  { "nogroup", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00334         &rpmQVKArgs.qva_flags, VERIFY_GROUP,
00335         N_("don't verify group of files"), NULL },
00336  { "nomtime", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00337         &rpmQVKArgs.qva_flags, VERIFY_MTIME,
00338         N_("don't verify modification time of files"), NULL },
00339  { "nomode", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00340         &rpmQVKArgs.qva_flags, VERIFY_MODE,
00341         N_("don't verify mode of files"), NULL },
00342  { "nordev", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00343         &rpmQVKArgs.qva_flags, VERIFY_RDEV,
00344         N_("don't verify mode of files"), NULL },
00345 
00346  { "nocontexts", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOCONTEXTS,
00347         N_("don't verify file security contexts"), NULL },
00348  { "nofiles", '\0', POPT_BIT_SET, &rpmQVKArgs.qva_flags, VERIFY_FILES,
00349         N_("don't verify files in package"), NULL},
00350 #ifdef  DYING
00351  { "nodeps", '\0', POPT_BIT_SET, &rpmQVKArgs.qva_flags, VERIFY_DEPS,
00352         N_("don't verify package dependencies"), NULL },
00353 #else
00354  { "nodeps", '\0', 0, NULL, RPMCLI_POPT_NODEPS,
00355         N_("don't verify package dependencies"), NULL },
00356 #endif
00357 
00358 #ifdef  DYING
00359  { "noscript", '\0', POPT_BIT_SET,&rpmQVKArgs.qva_flags, VERIFY_SCRIPT,
00360         N_("don't execute verify script(s)"), NULL },
00361  /* XXX legacy had a trailing s on --noscript */
00362  { "noscripts", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00363         &rpmQVKArgs.qva_flags, VERIFY_SCRIPT,
00364         N_("don't execute verify script(s)"), NULL },
00365 #else
00366  { "noscript", '\0', 0, NULL, RPMCLI_POPT_NOSCRIPTS,
00367         N_("don't execute verify script(s)"), NULL },
00368  /* XXX legacy had a trailing s on --noscript */
00369  { "noscripts", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOSCRIPTS,
00370         N_("don't execute verify script(s)"), NULL },
00371 #endif
00372 
00373 #ifdef  DYING
00374  { "nodigest", '\0', POPT_BIT_SET, &rpmQVKArgs.qva_flags, VERIFY_DIGEST,
00375         N_("don't verify package digest(s)"), NULL },
00376  { "nohdrchk", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00377         &rpmQVKArgs.qva_flags, VERIFY_HDRCHK,
00378         N_("don't verify database header(s) when retrieved"), NULL },
00379  { "nosignature", '\0', POPT_BIT_SET,
00380         &rpmQVKArgs.qva_flags, VERIFY_SIGNATURE,
00381         N_("don't verify package signature(s)"), NULL },
00382 #else
00383  { "nodigest", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NODIGEST,
00384         N_("don't verify package digest(s)"), NULL },
00385  { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
00386         N_("don't verify database header(s) when retrieved"), NULL },
00387  { "nosignature", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOSIGNATURE,
00388         N_("don't verify package signature(s)"), NULL },
00389 #endif
00390 
00391     POPT_TABLEEND
00392 };
00393 
00397 /*@unchecked@*/
00398 struct poptOption rpmSignPoptTable[] = {
00399 /*@-type@*/ /* FIX: cast? */
00400  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00401         rpmQVSourceArgCallback, 0, NULL, NULL },
00402 /*@=type@*/
00403  { "addsign", '\0', 0, NULL, 'A',
00404         N_("sign package(s) (identical to --resign)"), NULL },
00405  { "checksig", 'K', 0, NULL, 'K',
00406         N_("verify package signature(s)"), NULL },
00407  { "delsign", '\0', 0, NULL, 'D',
00408         N_("delete package signatures"), NULL },
00409  { "import", '\0', 0, NULL, 'I',
00410         N_("import an armored public key"), NULL },
00411  { "resign", '\0', 0, NULL, 'R',
00412         N_("sign package(s) (identical to --addsign)"), NULL },
00413  { "sign", '\0', POPT_ARGFLAG_DOC_HIDDEN, &rpmQVKArgs.sign, 0,
00414         N_("generate signature"), NULL },
00415  /* XXX perhaps POPT_ARG_INT instead of callback. */
00416  { "trust", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0,  POPT_TRUST,
00417         N_("specify trust metric"), "TRUST" },
00418  { "trusted", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN,
00419         &rpmQVKArgs.trust, 1,
00420         N_("set ultimate trust when importing pubkey(s)"), NULL },
00421  { "untrusted", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN,
00422         &rpmQVKArgs.trust, -1,
00423         N_("unset ultimate trust when importing pubkey(s)"), NULL },
00424 
00425  { "nodigest", '\0', POPT_BIT_SET, &rpmQVKArgs.qva_flags, VERIFY_DIGEST,
00426         N_("don't verify package digest(s)"), NULL },
00427  { "nohdrchk", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00428         &rpmQVKArgs.qva_flags, VERIFY_HDRCHK,
00429         N_("don't verify database header(s) when retrieved"), NULL },
00430  { "nosignature", '\0', POPT_BIT_SET, &rpmQVKArgs.qva_flags, VERIFY_SIGNATURE,
00431         N_("don't verify package signature(s)"), NULL },
00432 
00433    POPT_TABLEEND
00434 };

Generated on Fri Oct 12 08:44:53 2007 for rpm by  doxygen 1.5.2