[svn] GnuPG - r4634 - in trunk: common g10 sm
svn author wk
cvs at cvs.gnupg.org
Mon Dec 3 14:05:19 CET 2007
Author: wk
Date: 2007-12-03 14:05:15 +0100 (Mon, 03 Dec 2007)
New Revision: 4634
Modified:
trunk/common/ChangeLog
trunk/common/sysutils.c
trunk/common/sysutils.h
trunk/g10/ChangeLog
trunk/g10/gpg.c
trunk/sm/ChangeLog
trunk/sm/gpgsm.c
Log:
Try to make sure that the standard descriptors are connected when calling
gpgsm.
Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog 2007-11-29 14:51:08 UTC (rev 4633)
+++ trunk/common/ChangeLog 2007-12-03 13:05:15 UTC (rev 4634)
@@ -1,3 +1,7 @@
+2007-12-03 Werner Koch <wk at g10code.com>
+
+ * sysutils.c (gnupg_reopen_std): New. Taken from ../g10/gpg.c.
+
2007-11-27 Werner Koch <wk at g10code.com>
* Makefile.am (CLEANFILES): New.
Modified: trunk/common/sysutils.c
===================================================================
--- trunk/common/sysutils.c 2007-11-29 14:51:08 UTC (rev 4633)
+++ trunk/common/sysutils.c 2007-12-03 13:05:15 UTC (rev 4634)
@@ -48,6 +48,7 @@
#ifdef HAVE_PTH
# include <pth.h>
#endif
+#include <fcntl.h>
#include "util.h"
#include "i18n.h"
@@ -119,7 +120,7 @@
return 1;
limit.rlim_cur = limit.rlim_max;
setrlimit (RLIMIT_CORE, &limit);
- return 1; /* We always return true because trhis function is
+ return 1; /* We always return true because this function is
merely a debugging aid. */
# endif
return 1;
@@ -397,3 +398,76 @@
return tmpfile ();
#endif /*!HAVE_W32_SYSTEM*/
}
+
+
+/* Make sure that the standard file descriptors are opened. Obviously
+ some folks close them before an exec and the next file we open will
+ get one of them assigned and thus any output (i.e. diagnostics) end
+ up in that file (e.g. the trustdb). Not actually a gpg problem as
+ this will hapen with almost all utilities when called in a wrong
+ way. However we try to minimize the damage here and raise
+ awareness of the problem.
+
+ Must be called before we open any files! */
+void
+gnupg_reopen_std (const char *pgmname)
+{
+#if defined(HAVE_STAT) && !defined(HAVE_W32_SYSTEM)
+ struct stat statbuf;
+ int did_stdin = 0;
+ int did_stdout = 0;
+ int did_stderr = 0;
+ FILE *complain;
+
+ if (fstat (STDIN_FILENO, &statbuf) == -1 && errno ==EBADF)
+ {
+ if (open ("/dev/null",O_RDONLY) == STDIN_FILENO)
+ did_stdin = 1;
+ else
+ did_stdin = 2;
+ }
+
+ if (fstat (STDOUT_FILENO, &statbuf) == -1 && errno == EBADF)
+ {
+ if (open ("/dev/null",O_WRONLY) == STDOUT_FILENO)
+ did_stdout = 1;
+ else
+ did_stdout = 2;
+ }
+
+ if (fstat (STDERR_FILENO, &statbuf)==-1 && errno==EBADF)
+ {
+ if (open ("/dev/null", O_WRONLY) == STDERR_FILENO)
+ did_stderr = 1;
+ else
+ did_stderr = 2;
+ }
+
+ /* It's hard to log this sort of thing since the filehandle we would
+ complain to may be closed... */
+ if (!did_stderr)
+ complain = stderr;
+ else if (!did_stdout)
+ complain = stdout;
+ else
+ complain = NULL;
+
+ if (complain)
+ {
+ if (did_stdin == 1)
+ fprintf (complain, "%s: WARNING: standard input reopened\n", pgmname);
+ if (did_stdout == 1)
+ fprintf (complain, "%s: WARNING: standard output reopened\n", pgmname);
+ if (did_stderr == 1)
+ fprintf (complain, "%s: WARNING: standard error reopened\n", pgmname);
+
+ if (did_stdin == 2 || did_stdout == 2 || did_stderr == 2)
+ fprintf(complain,"%s: fatal: unable to reopen standard input,"
+ " output, or error\n", pgmname);
+ }
+
+ if (did_stdin == 2 || did_stdout == 2 || did_stderr == 2)
+ exit (3);
+#endif /* HAVE_STAT && !HAVE_W32_SYSTEM */
+}
+
Modified: trunk/common/sysutils.h
===================================================================
--- trunk/common/sysutils.h 2007-11-29 14:51:08 UTC (rev 4633)
+++ trunk/common/sysutils.h 2007-12-03 13:05:15 UTC (rev 4634)
@@ -46,6 +46,7 @@
int translate_sys2libc_fd (gnupg_fd_t fd, int for_write);
int translate_sys2libc_fd_int (int fd, int for_write);
FILE *gnupg_tmpfile (void);
+void gnupg_reopen_std (const char *pgmname);
#ifdef HAVE_W32_SYSTEM
Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog 2007-11-29 14:51:08 UTC (rev 4633)
+++ trunk/g10/ChangeLog 2007-12-03 13:05:15 UTC (rev 4634)
@@ -1,3 +1,10 @@
+2007-12-03 Werner Koch <wk at g10code.com>
+
+ * gpg.c (reopen_std): Moved to ../common and renamed to
+ gnupg_reopen_std.
+
+ * gpg.c: Remove second inclusion of fcntl.h.
+
2007-11-19 Werner Koch <wk at g10code.com>
* keyedit.c (keyedit_menu): String grammar fix.
Modified: trunk/g10/gpg.c
===================================================================
--- trunk/g10/gpg.c 2007-11-29 14:51:08 UTC (rev 4633)
+++ trunk/g10/gpg.c 2007-12-03 13:05:15 UTC (rev 4634)
@@ -26,9 +26,6 @@
#include <ctype.h>
#include <unistd.h>
#include <assert.h>
-#ifdef HAVE_DOSISH_SYSTEM
-#include <fcntl.h> /* for setmode() */
-#endif
#ifdef HAVE_STAT
#include <sys/stat.h> /* for stat() */
#endif
@@ -1687,76 +1684,6 @@
}
-
-/* Make sure that the standard file descriptors are opened. Obviously
- some folks close them before an exec and the next file we open will
- get one of them assigned and thus any output (i.e. diagnostics) end
- up in that file (e.g. the trustdb). Not actually a gpg problem as
- this will hapenn with almost all utilities when called in a wrong
- way. However we try to minimize the damage here and raise
- awareness of the problem.
-
- Must be called before we open any files! */
-static void
-reopen_std(void)
-{
-#if defined(HAVE_STAT) && !defined(HAVE_W32_SYSTEM)
- struct stat statbuf;
- int did_stdin=0,did_stdout=0,did_stderr=0;
- FILE *complain;
-
- if(fstat(STDIN_FILENO,&statbuf)==-1 && errno==EBADF)
- {
- if(open("/dev/null",O_RDONLY)==STDIN_FILENO)
- did_stdin=1;
- else
- did_stdin=2;
- }
-
- if(fstat(STDOUT_FILENO,&statbuf)==-1 && errno==EBADF)
- {
- if(open("/dev/null",O_WRONLY)==STDOUT_FILENO)
- did_stdout=1;
- else
- did_stdout=2;
- }
-
- if(fstat(STDERR_FILENO,&statbuf)==-1 && errno==EBADF)
- {
- if(open("/dev/null",O_WRONLY)==STDERR_FILENO)
- did_stderr=1;
- else
- did_stderr=2;
- }
-
- /* It's hard to log this sort of thing since the filehandle we would
- complain to may be closed... */
- if(did_stderr==0)
- complain=stderr;
- else if(did_stdout==0)
- complain=stdout;
- else
- complain=NULL;
-
- if(complain)
- {
- if(did_stdin==1)
- fprintf(complain,"gpg: WARNING: standard input reopened\n");
- if(did_stdout==1)
- fprintf(complain,"gpg: WARNING: standard output reopened\n");
- if(did_stderr==1)
- fprintf(complain,"gpg: WARNING: standard error reopened\n");
-
- if(did_stdin==2 || did_stdout==2 || did_stderr==2)
- fprintf(complain,"gpg: fatal: unable to reopen standard input,"
- " output, or error\n");
- }
-
- if(did_stdin==2 || did_stdout==2 || did_stderr==2)
- exit(3);
-#endif /* HAVE_STAT && !HAVE_W32_SYSTEM */
-}
-
/* Pack an s2k iteration count into the form specified in 2440. If
we're in between valid values, round up. */
static unsigned char
@@ -1855,7 +1782,7 @@
/* Please note that we may running SUID(ROOT), so be very CAREFUL
when adding any stuff between here and the call to
secmem_init() somewhere after the option parsing. */
- reopen_std ();
+ gnupg_reopen_std ("gpg");
trap_unaligned ();
gnupg_rl_initialize ();
set_strusage (my_strusage);
Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog 2007-11-29 14:51:08 UTC (rev 4633)
+++ trunk/sm/ChangeLog 2007-12-03 13:05:15 UTC (rev 4634)
@@ -1,3 +1,7 @@
+2007-12-03 Werner Koch <wk at g10code.com>
+
+ * gpgsm.c (main): All gnupg_reopen_std.
+
h2007-11-22 Werner Koch <wk at g10code.com>
* server.c (cmd_getauditlog): New.
Modified: trunk/sm/gpgsm.c
===================================================================
--- trunk/sm/gpgsm.c 2007-11-29 14:51:08 UTC (rev 4633)
+++ trunk/sm/gpgsm.c 2007-12-03 13:05:15 UTC (rev 4634)
@@ -851,6 +851,7 @@
/*mtrace();*/
+ gnupg_reopen_std ("gpgsm");
/* trap_unaligned ();*/
gnupg_rl_initialize ();
set_strusage (my_strusage);
More information about the Gnupg-commits
mailing list