summaryrefslogtreecommitdiffstats
path: root/sm
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-06-12 12:33:40 +0200
committerWerner Koch <wk@gnupg.org>2002-06-12 12:33:40 +0200
commit7ca4df0a9ae08031e777a6ca1f6391a72bd277ce (patch)
tree732146541fd3e54e72041aec2d9639001101a907 /sm
parentVarious changes. (diff)
downloadgnupg2-7ca4df0a9ae08031e777a6ca1f6391a72bd277ce.tar.xz
gnupg2-7ca4df0a9ae08031e777a6ca1f6391a72bd277ce.zip
* gpgsm.c (open_fwrite): New.
(main): Allow --output for --verify.
Diffstat (limited to 'sm')
-rw-r--r--sm/ChangeLog5
-rw-r--r--sm/gpgsm.c66
2 files changed, 60 insertions, 11 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog
index 8e217eecd..bd3e6c34a 100644
--- a/sm/ChangeLog
+++ b/sm/ChangeLog
@@ -1,9 +1,12 @@
2002-06-12 Werner Koch <wk@gnupg.org>
+ * gpgsm.c (open_fwrite): New.
+ (main): Allow --output for --verify.
+
* sign.c (hash_and_copy_data): New.
(gpgsm_sign): Implemented normal (non-detached) signatures.
* gpgsm.c (main): Ditto.
-
+
* certpath.c (gpgsm_validate_path): Special error handling for
no policy match.
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index f01ffc709..9ed6623c7 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -397,6 +397,7 @@ static void set_cmd (enum cmd_and_opt_values *ret_cmd,
static int check_special_filename (const char *fname);
static int open_read (const char *filename);
+static FILE *open_fwrite (const char *filename);
static int
@@ -1146,14 +1147,26 @@ main ( int argc, char **argv)
break;
case aVerify:
- if (!argc)
- gpgsm_verify (&ctrl, 0, -1, NULL); /* normal signature from stdin */
- else if (argc == 1)
- gpgsm_verify (&ctrl, open_read (*argv), -1, NULL); /* std signature */
- else if (argc == 2) /* detached signature (sig, detached) */
- gpgsm_verify (&ctrl, open_read (*argv), open_read (argv[1]), NULL);
- else
- wrong_args (_("--verify [signature [detached_data]]"));
+ {
+ FILE *fp = NULL;
+
+ if (argc == 2 && *opt.outfile)
+ log_info ("option --output ignored for a detached signature\n");
+ else if (opt.outfile)
+ fp = open_fwrite (opt.outfile);
+
+ if (!argc)
+ gpgsm_verify (&ctrl, 0, -1, fp); /* normal signature from stdin */
+ else if (argc == 1)
+ gpgsm_verify (&ctrl, open_read (*argv), -1, fp); /* std signature */
+ else if (argc == 2) /* detached signature (sig, detached) */
+ gpgsm_verify (&ctrl, open_read (*argv), open_read (argv[1]), NULL);
+ else
+ wrong_args (_("--verify [signature [detached_data]]"));
+
+ if (fp && fp != stdout)
+ fclose (fp);
+ }
break;
case aVerifyFiles:
@@ -1340,9 +1353,9 @@ check_special_filename (const char *fname)
-/* Open the FILENAME for read and return the fieldescriptor. Stop
+/* Open the FILENAME for read and return the filedescriptor. Stop
with an error message in case of problems. "-" denotes stdin and
- if special filenames are allowed the given fd is opend instead. */
+ if special filenames are allowed the given fd is opened instead. */
static int
open_read (const char *filename)
{
@@ -1361,3 +1374,36 @@ open_read (const char *filename)
}
return fd;
}
+
+/* Open FILENAME for fwrite and return the stream. Stop with an error
+ message in case of problems. "-" denotes stdout and if special
+ filenames are allowed the given fd is opened instead. Caller must
+ close the returned stream unless it is stdout. */
+static FILE *
+open_fwrite (const char *filename)
+{
+ int fd;
+ FILE *fp;
+
+ if (filename[0] == '-' && !filename[1])
+ return stdout;
+
+ fd = check_special_filename (filename);
+ if (fd != -1)
+ {
+ fp = fdopen (dup (fd), "wb");
+ if (!fp)
+ {
+ log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno));
+ gpgsm_exit (2);
+ }
+ return fp;
+ }
+ fp = fopen (filename, "wb");
+ if (!fp)
+ {
+ log_error (_("can't open `%s': %s\n"), filename, strerror (errno));
+ gpgsm_exit (2);
+ }
+ return fp;
+}