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"));