diff options
author | Werner Koch <wk@gnupg.org> | 2010-04-14 13:24:02 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2010-04-14 13:24:02 +0200 |
commit | 31d7bdfe771853a480203d7d4a661d476d2231a4 (patch) | |
tree | 470c4ed27b06188b1a1a000ce6fb2c41b260b96d /common | |
parent | 2010-04-13 Marcus Brinkmann <marcus@g10code.de> (diff) | |
download | gnupg2-31d7bdfe771853a480203d7d4a661d476d2231a4.tar.xz gnupg2-31d7bdfe771853a480203d7d4a661d476d2231a4.zip |
Whole lot of changes to support CE.
Diffstat (limited to 'common')
-rw-r--r-- | common/ChangeLog | 23 | ||||
-rw-r--r-- | common/asshelp.c | 20 | ||||
-rw-r--r-- | common/estream.c | 3 | ||||
-rw-r--r-- | common/mischelp.c | 6 | ||||
-rw-r--r-- | common/sysutils.c | 111 | ||||
-rw-r--r-- | common/sysutils.h | 3 | ||||
-rw-r--r-- | common/util.h | 2 | ||||
-rw-r--r-- | common/w32help.h | 7 |
8 files changed, 166 insertions, 9 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index 2e61181e9..b4ddfbf37 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,26 @@ +2010-04-14 Werner Koch <wk@g10code.com> + + * asshelp.c (setup_libassuan_logging): Read ASSUAN_DEBUG envvar. + (my_libassuan_log_handler): Use it. + * sysutils.c (_gnupg_getenv): Implement ASSUAN_DEBUG. + +2010-04-08 Werner Koch <wk@g10code.com> + + * w32help.h (_setmode, setmode) [W32CE]: Provide prototype and + macro. + +2010-04-07 Werner Koch <wk@g10code.com> + + * mischelp.c (timegm): Replace unsetenv/putenv by gnupg_unsetenv. + + * sysutils.c: Include setenv.h. + (gnupg_setenv, gnupg_unsetenv): New. + + +2010-04-06 Werner Koch <wk@g10code.com> + + * sysutils.c (gnupg_mkdir): New. + 2010-03-29 Werner Koch <wk@g10code.com> * init.c (sleep_on_exit): Change to 400ms. diff --git a/common/asshelp.c b/common/asshelp.c index 0f744ad00..d07adf7bf 100644 --- a/common/asshelp.c +++ b/common/asshelp.c @@ -36,6 +36,14 @@ #include "asshelp.h" +/* A bitfield that specifies the assuan categories to log. This is + identical to the default log handler of libassuan. We need to do + it ourselves because we use a custom log handler and want to use + the same assuan variables to select the categories to log. */ +static int log_cats; +#define TEST_LOG_CAT(x) (!! (log_cats & (1 << (x - 1)))) + + static int my_libassuan_log_handler (assuan_context_t ctx, void *hook, unsigned int cat, const char *msg) @@ -44,8 +52,9 @@ my_libassuan_log_handler (assuan_context_t ctx, void *hook, (void)ctx; - if (cat != ASSUAN_LOG_CONTROL) - return 0; /* We only want the control channel messages. */ + if (! TEST_LOG_CAT (cat)) + return 0; + dbgval = hook? *(unsigned int*)hook : 0; if (!(dbgval & 1024)) return 0; /* Assuan debugging is not enabled. */ @@ -62,6 +71,13 @@ my_libassuan_log_handler (assuan_context_t ctx, void *hook, void setup_libassuan_logging (unsigned int *debug_var_address) { + char *flagstr; + + flagstr = getenv ("ASSUAN_DEBUG"); + if (flagstr) + log_cats = atoi (flagstr); + else /* Default to log the control channel. */ + log_cats = (1 << (ASSUAN_LOG_CONTROL - 1)); assuan_set_log_cb (my_libassuan_log_handler, debug_var_address); } diff --git a/common/estream.c b/common/estream.c index 41ba4f245..75d5ad694 100644 --- a/common/estream.c +++ b/common/estream.c @@ -118,6 +118,9 @@ void *memrchr (const void *block, int c, size_t size); #ifdef HAVE_W32CE_SYSTEM # define _set_errno(a) gpg_err_set_errno ((a)) +/* Setmode is missing in cegcc but available since CE 5.0. */ +int _setmode (int handle, int mode); +# define setmode(a,b) _setmode ((a),(b)) #else # define _set_errno(a) do { errno = (a); } while (0) #endif diff --git a/common/mischelp.c b/common/mischelp.c index e06be21f2..5c8f1cfab 100644 --- a/common/mischelp.c +++ b/common/mischelp.c @@ -183,11 +183,7 @@ timegm (struct tm *tm) putenv (old_zone); } else -#ifdef HAVE_UNSETENV - unsetenv("TZ"); -#else - putenv("TZ"); -#endif + gnupg_unsetenv("TZ"); tzset(); return answer; diff --git a/common/sysutils.c b/common/sysutils.c index 5eab2b8ba..6ad5e27a9 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -51,6 +51,8 @@ #endif #include <fcntl.h> +#include "setenv.h" /* Gnulib replacement. */ + #include "util.h" #include "i18n.h" @@ -529,6 +531,97 @@ gnupg_remove (const char *fname) } +/* A wrapper around mkdir which takes a string for the mode argument. + This makes it easier to handle the mode argument which is not + defined on all systems. The format of the modestring is + + "-rwxrwxrwx" + + '-' is a don't care or not set. 'r', 'w', 'x' are read allowed, + write allowed, execution allowed with the first group for the user, + the second for the group and the third for all others. If the + string is shorter than above the missing mode characters are meant + to be not set. */ +int +gnupg_mkdir (const char *name, const char *modestr) +{ +#ifdef HAVE_W32CE_SYSTEM + wchar_t *wname; + (void)modestr; + + wname = utf8_to_wchar (name); + if (!wname) + return -1; + if (!CreateDirectoryW (wname, NULL)) + { + xfree (wname); + return -1; /* ERRNO is automagically provided by gpg-error.h. */ + } + xfree (wname); + return 0; +#elif MKDIR_TAKES_ONE_ARG + (void)modestr; + /* Note: In the case of W32 we better use CreateDirectory and try to + set appropriate permissions. However using mkdir is easier + because this sets ERRNO. */ + return mkdir (name); +#else + mode_t mode = 0; + + if (modestr && *modestr) + { + modestr++; + if (*modestr && *modestr++ == 'r') + mode |= S_IRUSR; + if (*modestr && *modestr++ == 'w') + mode |= S_IWUSR; + if (*modestr && *modestr++ == 'x') + mode |= S_IXUSR; + if (*modestr && *modestr++ == 'r') + mode |= S_IRGRP; + if (*modestr && *modestr++ == 'w') + mode |= S_IWGRP; + if (*modestr && *modestr++ == 'x') + mode |= S_IXGRP; + if (*modestr && *modestr++ == 'r') + mode |= S_IROTH; + if (*modestr && *modestr++ == 'w') + mode |= S_IWOTH; + if (*modestr && *modestr++ == 'x') + mode |= S_IXOTH; + } + return mkdir (home, mode) +#endif +} + + +int +gnupg_setenv (const char *name, const char *value, int overwrite) +{ +#ifdef HAVE_W32CE_SYSTEM + (void)name; + (void)value; + (void)overwrite; + return 0; +#else + setenv (name, value, overwrite); +#endif +} + +int +gnupg_unsetenv (const char *name) +{ +#ifdef HAVE_W32CE_SYSTEM + (void)name; + return 0; +#else +# ifdef HAVE_UNSETENV + unsetenv (name); +# else + putenv (name); +# endif +#endif +} #ifdef HAVE_W32CE_SYSTEM @@ -538,8 +631,22 @@ gnupg_remove (const char *fname) char * _gnupg_getenv (const char *name) { - (void)name; - return NULL; + static int initialized; + static char *assuan_debug; + + if (!initialized) + { + assuan_debug = read_w32_registry_string (NULL, + "\\Software\\GNU\\libassuan", + "debug"); + initialized = 1; + } + + if (!strcmp (name, "ASSUAN_DEBUG")) + return assuan_debug; + else + return NULL; } + #endif /*HAVE_W32CE_SYSTEM*/ diff --git a/common/sysutils.h b/common/sysutils.h index ea3b4253e..a2f74f936 100644 --- a/common/sysutils.h +++ b/common/sysutils.h @@ -49,6 +49,9 @@ FILE *gnupg_tmpfile (void); void gnupg_reopen_std (const char *pgmname); void gnupg_allow_set_foregound_window (pid_t pid); int gnupg_remove (const char *fname); +int gnupg_mkdir (const char *name, const char *modestr); +int gnupg_setenv (const char *name, const char *value, int overwrite); +int gnupg_unsetenv (const char *name); #ifdef HAVE_W32_SYSTEM diff --git a/common/util.h b/common/util.h index 615b776c5..159d66ee2 100644 --- a/common/util.h +++ b/common/util.h @@ -298,6 +298,8 @@ ttyname (int fd) #define getpid() GetCurrentProcessId () char *_gnupg_getenv (const char *name); /* See sysutils.c */ #define getenv(a) _gnupg_getenv ((a)) +char *_gnupg_setenv (const char *name); /* See sysutils.c */ +#define setenv(a,b,c) _gnupg_setenv ((a),(b),(c)) #endif diff --git a/common/w32help.h b/common/w32help.h index 518d4251c..6bc9f6605 100644 --- a/common/w32help.h +++ b/common/w32help.h @@ -28,5 +28,12 @@ int write_w32_registry_string (const char *root, const char *dir, const char *name, const char *value); +/* Other stuff. */ +#ifdef HAVE_W32CE_SYSTEM +/* Setmode is missing in cegcc but available since CE 5.0. */ +int _setmode (int handle, int mode); +# define setmode(a,b) _setmode ((a),(b)) +#endif /*HAVE_W32CE_SYSTEM*/ + #endif /*HAVE_W32_SYSTEM*/ #endif /*LIBJNLIB_MISCHELP_H*/ |