aboutsummaryrefslogtreecommitdiff
path: root/src/gpg.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-08-22 13:23:03 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-08-22 13:23:03 +0000
commit180ca1d87d2bf69d9dbb0acb76422e9ae15f930c (patch)
treeb14651206aaec8e03fdfdce9e04433068fa62648 /src/gpg.c
parent708a28a2f5bd2384e4c254a47d069ec4d9ef697e (diff)
downloadwydawca-180ca1d87d2bf69d9dbb0acb76422e9ae15f930c.tar.gz
wydawca-180ca1d87d2bf69d9dbb0acb76422e9ae15f930c.tar.bz2
Implement all directives
git-svn-id: file:///svnroot/wydawca/trunk@284 6bb4bd81-ecc2-4fd4-a2d4-9571d19c0d33
Diffstat (limited to 'src/gpg.c')
-rw-r--r--src/gpg.c159
1 files changed, 22 insertions, 137 deletions
diff --git a/src/gpg.c b/src/gpg.c
index 7da4f5b..ea011ff 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -17,9 +17,6 @@
#include "wydawca.h"
#include "save-cwd.h"
#include <gpgme.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <signal.h>
#define fail_if_err(expr) \
do \
@@ -144,7 +141,7 @@ wydawca_gpg_homedir ()
/* FIXME: dpair currently unused */
int
-verify_directive_signature (struct file_register *reg,
+verify_directive_signature (struct file_triplet *trp,
struct directory_pair *dpair, const char *pubkey)
{
gpgme_ctx_t ctx;
@@ -160,25 +157,25 @@ verify_directive_signature (struct file_register *reg,
fail_if_err (gpgme_op_import (ctx, key_data));
fail_if_err (gpgme_data_new_from_file (&directive_data,
- reg->file[file_directive].name, 1));
+ trp->file[file_directive].name, 1));
gpgme_data_new (&plain);
ec = gpgme_op_verify (ctx, directive_data, NULL, plain);
if (ec == GPG_ERR_NO_ERROR)
{
size = gpgme_data_seek (plain, 0, SEEK_END);
gpgme_data_seek (plain, 0, SEEK_SET);
- reg->blurb = xmalloc (size + 1);
- gpgme_data_read (plain, reg->blurb, size);
- reg->blurb[size] = 0;
+ trp->blurb = xmalloc (size + 1);
+ gpgme_data_read (plain, trp->blurb, size);
+ trp->blurb[size] = 0;
gpgme_data_release (plain);
- rc = directive_parse (reg);
+ rc = directive_parse (trp);
}
else
{
rc = 1;
logmsg (LOG_ERR, "%s: directive verification failed: %s",
- reg->name, gpgme_strerror (ec));
+ trp->name, gpgme_strerror (ec));
/* FIXME: Send mail to the project maintainer */
}
@@ -188,74 +185,12 @@ verify_directive_signature (struct file_register *reg,
return rc;
}
-FILE *
-start_prog (int argc, const char **argv, pid_t *ppid)
-{
- int p[2];
- FILE *fp;
- pid_t pid;
- int i;
-
- pipe (p);
- switch (pid = fork ())
- {
- case 0:
- /* Child process */
-
- if (p[1] != 1)
- dup2 (p[1], 1);
- if (p[1] != 1)
- dup2 (p[1], 2);
- close (p[0]);
-
- /* Close unneded descripitors */
- for (i = getmaxfd (); i > 2; i--)
- close (i);
-
- execvp (argv[0], (char**) argv);
- logmsg (LOG_CRIT, "cannot run %s: %s", argv[0], strerror (errno));
- exit (1);
-
- case -1:
- logmsg (LOG_CRIT, "cannot run `%s': fork failed: %s",
- argv[0], strerror (errno));
- return NULL;
-
- default:
- /* Master process */
- close (p[1]);
- fp = fdopen (p[0], "r");
- if (!fp)
- logmsg (LOG_ERR, "cannot fdopen: %s", strerror (errno));
- *ppid = pid;
- }
- return fp;
-}
-
-void
-log_output (int prio, const char *prog, FILE *fp)
-{
- size_t size = 0;
- char *buf = NULL;
-
- logmsg (prio, "%s output follows:", prog);
- while (getline (&buf, &size, fp) > 0)
- logmsg (prio, "%s", buf);
- logmsg (prio, "end of %s output", prog);
- free (buf);
-}
-
int
-verify_detached_signature (struct file_register *reg,
+verify_detached_signature (struct file_triplet *trp,
struct directory_pair *dpair)
{
gpgme_engine_info_t info;
const char *argv[5];
- FILE *fp;
- pid_t pid, npid;
- int status;
- int i;
- int rc;
fail_if_err (gpgme_get_engine_info (&info));
while (info && info->protocol != GPGME_PROTOCOL_OpenPGP)
@@ -264,82 +199,32 @@ verify_detached_signature (struct file_register *reg,
{
logmsg (LOG_CRIT,
"cannot find path to gpg binary (attempting to verify "
- "the detached signature for %s", reg->name);
+ "the detached signature for %s", trp->name);
return 1;
}
wydawca_gpg_homedir ();
argv[0] = info->file_name;
argv[1] = "--verify";
- argv[2] = reg->file[file_signature].name;
- argv[3] = reg->file[file_dist].name;
+ argv[2] = trp->file[file_signature].name;
+ argv[3] = trp->file[file_dist].name;
argv[4] = NULL;
- fp = start_prog (5, argv, &pid);
- if (!fp)
+ switch (wydawca_exec (5, argv, NULL))
{
- logmsg (LOG_CRIT,
- "cannot verify detached signature for %s", reg->name);
- return 1;
- }
-
- for (i = 0; i < 5 && (npid = waitpid (pid, &status, WNOHANG)) == 0; i++)
- sleep (1);
+ case exec_success:
+ if (debug_level)
+ logmsg (LOG_DEBUG, "good detached signature for %s", trp->name);
+ return 0;
- switch (npid)
- {
- case -1:
- logmsg (LOG_CRIT,
- "cannot verify detached signature for %s: "
- "waitpid failed: %s", reg->name, strerror (errno));
- fclose (fp);
- return 1;
-
- case 0:
- logmsg (LOG_CRIT,
- "cannot verify detached signature for %s: "
- "process %s did not respond within 5 seconds: %s",
- reg->name, argv[0], strerror (errno));
- kill (pid, SIGKILL);
- fclose (fp);
- return 1;
-
- default:
+ case exec_fail:
+ logmsg (LOG_ERR, "bad detached signature for %s", trp->name);
break;
- }
- if (WIFEXITED (status))
- {
- rc = WEXITSTATUS (status);
- if (rc)
- {
- logmsg (LOG_ERR, "bad detached signature for %s", reg->name);
- log_output (LOG_ERR, argv[0], fp);
- /* FIXME: email? */
- }
- else if (debug_level > 1)
- log_output (LOG_DEBUG, argv[0], fp);
- }
- else
- {
- rc = 1;
- if (WIFSIGNALED (status))
- logmsg (LOG_ERR,
- "cannot verify detached signature for %s: "
- "%s terminated on signal %d",
- reg->name, argv[0], WTERMSIG (status));
- else if (WIFSTOPPED (status))
- logmsg (LOG_ERR,
- "cannot verify detached signature for %s: "
- "%s stopped on signal %d",
- reg->name, argv[0], WTERMSIG (status));
- else
- logmsg (LOG_ERR,
- "cannot verify detached signature for %s: "
- "%s terminated with unrecognized status",
- reg->name, argv[0]);
+ case exec_error:
+ logmsg (LOG_CRIT, "cannot verify detached signature for %s", trp->name);
+ break;
}
- fclose (fp);
- return rc;
+ return 1;
}

Return to:

Send suggestions and report system problems to the System administrator.