Change ',' to '#' in sed 's' command
[platform/upstream/rpm.git] / rpmsign.c
index 61e753e..e29864e 100644 (file)
--- a/rpmsign.c
+++ b/rpmsign.c
@@ -4,6 +4,7 @@
 
 #include <popt.h>
 #include <rpm/rpmcli.h>
+#include <rpm/rpmsign.h>
 #include "cliutils.h"
 #include "debug.h"
 
@@ -19,43 +20,27 @@ enum modes {
 
 static int mode = 0;
 
-static struct poptOption optionsTable[] = {
-    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
-       N_("Common options for all rpm modes and executables:"), NULL },
+static struct poptOption signOptsTable[] = {
     { "addsign", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_ADDSIGN,
        N_("sign package(s)"), NULL },
     { "resign", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_RESIGN,
        N_("sign package(s) (identical to --addsign)"), NULL },
     { "delsign", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELSIGN,
        N_("delete package signatures"), NULL },
+    POPT_TABLEEND
+};
+
+static struct poptOption optionsTable[] = {
+    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, signOptsTable, 0,
+       N_("Signature options:"), NULL },
+    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
+       N_("Common options for all rpm modes and executables:"), NULL },
 
     POPT_AUTOALIAS
     POPT_AUTOHELP
     POPT_TABLEEND
 };
 
-static rpmSigTag lookupSignatureType(void)
-{
-    rpmSigTag rc = 0;
-
-    char *name = rpmExpand("%{?_signature}", NULL);
-    if (!(name && *name != '\0'))
-       rc = 0;
-    else if (!rstrcasecmp(name, "none"))
-       rc = 0;
-    else if (!rstrcasecmp(name, "pgp"))
-       rc = RPMSIGTAG_PGP;
-    else if (!rstrcasecmp(name, "pgp5"))       /* XXX legacy */
-       rc = RPMSIGTAG_PGP;
-    else if (!rstrcasecmp(name, "gpg"))
-       rc = RPMSIGTAG_GPG;
-    else
-       rc = -1;        /* Invalid %_signature spec in macro file */
-
-    name = _free(name);
-    return rc;
-}
-
 static int checkPassPhrase(const char * passPhrase)
 {
     int passPhrasePipe[2];
@@ -113,10 +98,9 @@ static int checkPassPhrase(const char * passPhrase)
 }
 
 /* TODO: permit overriding macro setup on the command line */
-static int doSign(ARGV_const_t args)
+static int doSign(poptContext optCon)
 {
     int rc = EXIT_FAILURE;
-    int sigTag = lookupSignatureType();
     char * passPhrase = NULL;
     char * name = rpmExpand("%{?_gpg_name}", NULL);
 
@@ -125,29 +109,22 @@ static int doSign(ARGV_const_t args)
        goto exit;
     }
 
-    switch (sigTag) {
-    case RPMSIGTAG_PGP:
-    case RPMSIGTAG_GPG:
-    case RPMSIGTAG_DSA:
-    case RPMSIGTAG_RSA:
-       break;
-    default:
-       fprintf(stderr, _("Invalid %%_signature spec in macro file.\n"));
-       goto exit;
-       break;
-    }
-
     /* XXX FIXME: eliminate obsolete getpass() usage */
     passPhrase = getpass(_("Enter pass phrase: "));
     passPhrase = (passPhrase != NULL) ? rstrdup(passPhrase) : NULL;
     if (checkPassPhrase(passPhrase) == 0) {
+       const char *arg;
        fprintf(stderr, _("Pass phrase is good.\n"));
-       rc = rpmcliSign(args, 0, sigTag, passPhrase);
+       rc = 0;
+       while ((arg = poptGetArg(optCon)) != NULL) {
+           rc += rpmPkgSign(arg, NULL, passPhrase);
+       }
     } else {
-       fprintf(stderr, _("Pass phrase check failed\n"));
+       fprintf(stderr, _("Pass phrase check failed or gpg key expired\n"));
     }
 
 exit:
+    free(passPhrase);
     free(name);
     return rc;
 }
@@ -156,25 +133,27 @@ int main(int argc, char *argv[])
 {
     int ec = EXIT_FAILURE;
     poptContext optCon = rpmcliInit(argc, argv, optionsTable);
-    ARGV_const_t args = NULL;
+    const char *arg;
     
     if (argc <= 1) {
        printUsage(optCon, stderr, 0);
        goto exit;
     }
 
-    args = (ARGV_const_t) poptGetArgs(optCon);
-    if (args == NULL) {
+    if (poptPeekArg(optCon) == NULL) {
        argerror(_("no arguments given"));
     }
 
     switch (mode) {
     case MODE_ADDSIGN:
     case MODE_RESIGN:
-       ec = doSign(args);
+       ec = doSign(optCon);
        break;
     case MODE_DELSIGN:
-       ec = rpmcliSign(args, 1, 0, NULL);
+       ec = 0;
+       while ((arg = poptGetArg(optCon)) != NULL) {
+           ec += rpmPkgDelSign(arg);
+       }
        break;
     default:
        argerror(_("only one major mode may be specified"));