6 #include <rpm/rpmcli.h> 
    7 #include <rpm/rpmsign.h> 
   11 #if !defined(__GLIBC__) && !defined(__APPLE__) 
   24     { 
"addsign", 
'\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, 
MODE_ADDSIGN,
 
   25         N_(
"sign package(s)"), NULL },
 
   26     { 
"resign", 
'\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, 
MODE_RESIGN,
 
   27         N_(
"sign package(s) (identical to --addsign)"), NULL },
 
   28     { 
"delsign", 
'\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, 
MODE_DELSIGN,
 
   29         N_(
"delete package signatures"), NULL },
 
   35         N_(
"Signature options:"), NULL },
 
   37         N_(
"Common options for all rpm modes and executables:"), NULL },
 
   46     int passPhrasePipe[2];
 
   51     if (passPhrase == NULL)
 
   54     passPhrasePipe[0] = passPhrasePipe[1] = 0;
 
   55     if (pipe(passPhrasePipe))
 
   60         close(passPhrasePipe[0]);
 
   61         close(passPhrasePipe[1]);
 
   66         char * cmd, * gpg_path;
 
   72         close(passPhrasePipe[1]);
 
   73         if ((fdno = open(
"/dev/null", O_RDONLY)) != STDIN_FILENO) {
 
   74             xx = dup2(fdno, STDIN_FILENO);
 
   77         if ((fdno = open(
"/dev/null", O_WRONLY)) != STDOUT_FILENO) {
 
   78             xx = dup2(fdno, STDOUT_FILENO);
 
   81         xx = dup2(passPhrasePipe[0], 3);
 
   83         unsetenv(
"MALLOC_CHECK_");
 
   84         gpg_path = 
rpmExpand(
"%{?_gpg_path}", NULL);
 
   87             setenv(
"GNUPGHOME", gpg_path, 1);
 
   89         cmd = 
rpmExpand(
"%{?__gpg_check_password_cmd}", NULL);
 
   90         rc = poptParseArgvString(cmd, NULL, (
const char ***)&av);
 
   91         if (xx >= 0 && rc == 0) {
 
   92             rc = execve(av[0], av+1, 
environ);
 
   93             fprintf(stderr, 
_(
"Could not exec %s: %s\n"), 
"gpg",
 
   99     close(passPhrasePipe[0]);
 
  100     xx = write(passPhrasePipe[1], passPhrase, strlen(passPhrase));
 
  101     xx = write(passPhrasePipe[1], 
"\n", 1);
 
  102     close(passPhrasePipe[1]);
 
  104     if (xx >= 0 && waitpid(pid, &status, 0) >= 0)
 
  105         rc = (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? 0 : 1;
 
  113     int rc = EXIT_FAILURE;
 
  114     char * passPhrase = NULL;
 
  115     char * name = 
rpmExpand(
"%{?_gpg_name}", NULL);
 
  118         fprintf(stderr, 
_(
"You must set \"%%_gpg_name\" in your macro file\n"));
 
  123     passPhrase = getpass(
_(
"Enter pass phrase: "));
 
  124     passPhrase = (passPhrase != NULL) ? 
rstrdup(passPhrase) : NULL;
 
  127         fprintf(stderr, 
_(
"Pass phrase is good.\n"));
 
  129         while ((arg = poptGetArg(optCon)) != NULL) {
 
  133         fprintf(stderr, 
_(
"Pass phrase check failed or gpg key expired\n"));
 
  142 int main(
int argc, 
char *argv[])
 
  144     int ec = EXIT_FAILURE;
 
  145     poptContext optCon = 
rpmcliInit(argc, argv, optionsTable);
 
  153     if (poptPeekArg(optCon) == NULL) {
 
  164         while ((arg = poptGetArg(optCon)) != NULL) {
 
  169         argerror(
_(
"only one major mode may be specified"));
 
int rpmPkgSign(const char *path, const struct rpmSignArgs *args, const char *passPhrase)
Sign a package. 
void printUsage(poptContext con, FILE *fp, int flags)
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context. 
char * rstrdup(const char *str)
char * rpmExpand(const char *arg,...) RPM_GNUC_NULL_TERMINATED
Return (malloc'ed) concatenated macro expansion(s). 
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context. 
void argerror(const char *desc)
static struct poptOption optionsTable[]
static struct poptOption signOptsTable[]
static int rstreq(const char *s1, const char *s2)
Test for string equality. 
static int checkPassPhrase(const char *passPhrase)
int main(int argc, char *argv[])
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables. 
int rpmPkgDelSign(const char *path)
Delete signature(s) from a package. 
static int doSign(poptContext optCon)