Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: GnuPG: devel

GnuPG 1.4.11 v. VMS batch mode

 

 

GnuPG devel RSS feed   Index | Next | Previous | View Threaded


sms at antinode

Sep 7, 2011, 9:33 PM

Post #1 of 4 (211 views)
Permalink
GnuPG 1.4.11 v. VMS batch mode

Greetings:

A victim of my GnuPG 1.4.11 for VMS kit recently ran into an
interesting problem. A DCL procedure (think: "shell script") works when
run interactively, but loops when run as a batch job (think: "at/cron
job"?). I think that I've figured out what's happening, and I thought
that I'd get a consultation on a proposed fix.

The (apparently harmless) problem command looks like this:

pipe gpg -d -o bat.out --passphrase-fd 0 login.com-gpg < pp.txt

The problem seems (to me, at the moment) to be bad general code, but the
problem case may never occur on a UNIX(-like) system, so perhaps no one
else would have noticed it. During the program initialization,
util/ttyio.c:init_ttyfp() gets called. It uses ctermid() to get the
name of the controlling terminal. For a batch job on VMS, this comes
back as the disk name (which is what I'd guess never happens elsewhere).
The program tries to fopen() this, which fails, because it's a disk, not
a terminal. The program then tries to write a "cannot open" error
message to the terminal, but it won't do that until it gets the terminal
I/O set up properly, and for that it calls init_ttyfp(). Lather, rinse,
...

The following change seems to solve the looping in a
plausible/harmless way (slightly enhancing the message, because a
typical VMS user might not otherwise guess why anyone is trying to open
a disk device):

--- util/ttyio.c_orig 2010-09-28 04:39:05 -0500
+++ util/ttyio.c 2011-09-07 22:19:34 -0500
@@ -185,7 +185,8 @@
#else
ttyfp = batchmode? stderr : fopen( tty_get_ttyname (), "r+");
if( !ttyfp ) {
- log_error("cannot open `%s': %s\n",
+ initialized = 1; /* Don't come back again, ever. */
+ log_error("cannot open tty, `%s': %s\n",
tty_get_ttyname (), strerror(errno) );
exit(2);
}

The victim still needs to specify option(s) like "--batch" to avoid the
fatal "cannot open [tty]" error, but this way it dies promptly, emitting
a message like:

gpg: cannot open tty, `_ALP$DKC0:': no such file or directory

which, while not wonderfully informative, certainly beats an endless
loop (and no message).

On VMS, it should be relatively easy to check the process mode during
initialization, and set the "--batch" flag ("batchmode"?) automatically
for a batch job. I haven't yet thought of a good reason not to do this,
but I'm always open to a good counter-argument.

Any wisdom would be gratefully received.

------------------------------------------------------------------------

Steven M. Schweda sms [at] antinode-inf
382 South Warwick Street (+1) 651-699-9818
Saint Paul MN 55105-2547

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel


sms at antinode

Sep 8, 2011, 8:52 PM

Post #2 of 4 (200 views)
Permalink
Re: GnuPG 1.4.11 v. VMS batch mode [In reply to]

> On VMS, it should be relatively easy to check the process mode during
> initialization, and set the "--batch" flag ("batchmode"?) automatically
> for a batch job. I haven't yet thought of a good reason not to do this,
> but I'm always open to a good counter-argument.

This seems to work (with the associated changes to various
VMS-specific files in the "vms" and "vmslib" subdirectories:

--- g10/gpg.c_orig 2010-07-05 04:17:37 -0500
+++ g10/gpg.c 2011-09-08 13:37:06 -0500
@@ -40,6 +40,10 @@
#include <windows.h>
#endif

+#ifdef __VMS
+# include "vms.h"
+#endif
+
#define INCLUDED_BY_MAIN_MODULE 1
#include "packet.h"
#include "iobuf.h"
@@ -1872,6 +1876,14 @@
opt.lock_once = 1;
#endif /* __riscos__ */

+#ifdef __VMS
+ /* On VMS, set the default value of the "--[no-]batch" flag
+ * according to the actual process mode. The user can override this
+ * with an explicit command-line "--[no-]batch" option.
+ */
+ opt.batch = batch_mode_vms();
+#endif
+
reopen_std();
trap_unaligned();
secmem_set_flags( secmem_get_flags() | 2 ); /* suspend warnings */


I thought about trying to hide this stuff in some VMS-specific place,
to avoid adding VMS-specific clutter in the main thing, but it made more
sense to me to set opt.batch this way, in the same neighborhood as the
normal opt.xxxx-setting code.

Comments welcome, as usual.

------------------------------------------------------------------------

Steven M. Schweda sms [at] antinode-inf
382 South Warwick Street (+1) 651-699-9818
Saint Paul MN 55105-2547

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel


wk at gnupg

Sep 12, 2011, 6:15 AM

Post #3 of 4 (205 views)
Permalink
Re: GnuPG 1.4.11 v. VMS batch mode [In reply to]

On Thu, 8 Sep 2011 06:33, sms [at] antinode said:

> - log_error("cannot open `%s': %s\n",
> + initialized = 1; /* Don't come back again, ever. */
> + log_error("cannot open tty, `%s': %s\n",
> tty_get_ttyname (), strerror(errno) );
> exit(2);

I added
ttyfp = stderr
so that it has a defined value.

> On VMS, it should be relatively easy to check the process mode during
> initialization, and set the "--batch" flag ("batchmode"?) automatically
> for a batch job. I haven't yet thought of a good reason not to do this,

I'll also apply your other patch.


Shalom-Salam,

Werner


--
Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz.


_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel


sms at antinode

Sep 12, 2011, 6:29 AM

Post #4 of 4 (202 views)
Permalink
Re: GnuPG 1.4.11 v. VMS batch mode [In reply to]

From: Werner Koch <wk [at] gnupg>

> I added
> ttyfp = stderr
> so that it has a defined value.

> I'll also apply your other patch.

Sounds good to me. Thanks.

------------------------------------------------------------------------

Steven M. Schweda sms [at] antinode-inf
382 South Warwick Street (+1) 651-699-9818
Saint Paul MN 55105-2547

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel [at] gnupg
http://lists.gnupg.org/mailman/listinfo/gnupg-devel

GnuPG devel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.