Main Page Modules Data Structures File List Data Fields Globals Related Pages

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