diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpg-error.def.in | 12 | ||||
-rw-r--r-- | src/gpg-error.h.in | 9 | ||||
-rw-r--r-- | src/gpg-error.vers | 3 | ||||
-rw-r--r-- | src/gpgrt-int.h | 7 | ||||
-rw-r--r-- | src/sysutils.c | 116 | ||||
-rw-r--r-- | src/visibility.c | 141 | ||||
-rw-r--r-- | src/visibility.h | 41 |
7 files changed, 248 insertions, 81 deletions
diff --git a/src/gpg-error.def.in b/src/gpg-error.def.in index 6c40571..64c75dc 100644 --- a/src/gpg-error.def.in +++ b/src/gpg-error.def.in @@ -189,11 +189,13 @@ EXPORTS gpgrt_strdup @144 gpgrt_strconcat @145 - gpgrt_getenv @146 - gpgrt_setenv @147 + gpgrt_w32_reg_query_string @146 + + gpgrt_getenv @147 + gpgrt_setenv @148 + gpgrt_mkdir @149 + gpgrt_chdir @150 + gpgrt_getcwd @151 -#ifdef HAVE_W32_SYSTEM - gpgrt_w32_reg_query_string @148 -#endif ;; end of file with public symbols for Windows. diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in index 3d9c914..dffde2e 100644 --- a/src/gpg-error.h.in +++ b/src/gpg-error.h.in @@ -456,6 +456,15 @@ char *gpgrt_getenv (const char *name); int gpgrt_setenv (const char *name, const char *value, int overwrite); #define gpgrt_unsetenv(n) gpgrt_setenv ((n), NULL, 1) +/* A wrapper around mkdir using a string for the mode. */ +int gpgrt_mkdir (const char *name, const char *modestr); + +/* A simple wrapper around chdir. */ +int gpgrt_chdir (const char *name); + +/* Return the current WD as a malloced string. */ +char *gpgrt_getcwd (void); + diff --git a/src/gpg-error.vers b/src/gpg-error.vers index 661222c..92184f3 100644 --- a/src/gpg-error.vers +++ b/src/gpg-error.vers @@ -165,6 +165,9 @@ GPG_ERROR_1.0 { gpgrt_getenv; gpgrt_setenv; + gpgrt_mkdir; + gpgrt_chdir; + gpgrt_getcwd; local: *; diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h index c65f630..b2f87b9 100644 --- a/src/gpgrt-int.h +++ b/src/gpgrt-int.h @@ -566,7 +566,14 @@ char *_gpgrt_getenv (const char *name); * NULL and OVERRIDE to true. */ int _gpgrt_setenv (const char *name, const char *value, int overwrite); +/* A wrapper around mkdir using a string for the mode (permissions). */ +int _gpgrt_mkdir (const char *name, const char *modestr); +/* A simple wrapper around chdir. */ +int _gpgrt_chdir (const char *name); + +/* Return the current WD as a malloced string. */ +char *_gpgrt_getcwd (void); /* diff --git a/src/sysutils.c b/src/sysutils.c index 2dda4cd..70c2dc3 100644 --- a/src/sysutils.c +++ b/src/sysutils.c @@ -27,6 +27,11 @@ #ifdef HAVE_W32_SYSTEM # include <windows.h> #endif +#ifdef HAVE_STAT +# include <sys/stat.h> +#endif +#include <sys/types.h> +#include <fcntl.h> #include "gpgrt-int.h" @@ -212,3 +217,114 @@ _gpgrt_setenv (const char *name, const char *value, int overwrite) # endif /*!HAVE_SETENV*/ #endif /*!HAVE_W32_SYSTEM*/ } + + +#ifndef HAVE_W32_SYSTEM +static mode_t +modestr_to_mode (const char *modestr) +{ + 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 mode; +} +#endif + + +/* 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 +_gpgrt_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 + return mkdir (name, modestr_to_mode (modestr)); +#endif +} + + +/* A simple wrapper around chdir. NAME is expected to be utf8 + * encoded. */ +int +_gpgrt_chdir (const char *name) +{ + return chdir (name); +} + + +/* Return the current working directory as a malloced string. Return + * NULL and sets ERRNO on error. */ +char * +_gpgrt_getcwd (void) +{ + char *buffer; + size_t size = 100; + + for (;;) + { + buffer = xtrymalloc (size+1); + if (!buffer) + return NULL; +#ifdef HAVE_W32CE_SYSTEM + strcpy (buffer, "/"); /* Always "/". */ + return buffer; +#else + if (getcwd (buffer, size) == buffer) + return buffer; + xfree (buffer); + if (errno != ERANGE) + return NULL; + size *= 2; +#endif + } +} diff --git a/src/visibility.c b/src/visibility.c index 45ac644..c0cab3d 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -504,66 +504,6 @@ gpgrt_read_line (estream_t stream, max_length); } -void * -gpgrt_realloc (void *a, size_t n) -{ - return _gpgrt_realloc (a, n); -} - -void * -gpgrt_malloc (size_t n) -{ - return _gpgrt_malloc (n); -} - -void * -gpgrt_calloc (size_t n, size_t m) -{ - return _gpgrt_calloc (n, m); -} - -char * -gpgrt_strdup (const char *string) -{ - return _gpgrt_strdup (string); -} - -char * -gpgrt_strconcat (const char *s1, ...) -{ - va_list arg_ptr; - char *result; - - if (!s1) - result = _gpgrt_strdup (""); - else - { - va_start (arg_ptr, s1); - result = _gpgrt_strconcat_core (s1, arg_ptr); - va_end (arg_ptr); - } - return result; -} - -void -gpgrt_free (void *a) -{ - if (a) - _gpgrt_free (a); -} - -char * -gpgrt_getenv (const char *name) -{ - return _gpgrt_getenv (name); -} - -int -gpgrt_setenv (const char *name, const char *value, int overwrite) -{ - return _gpgrt_setenv (name, value, overwrite); -} - int gpgrt_vfprintf (estream_t _GPGRT__RESTRICT stream, const char *_GPGRT__RESTRICT format, @@ -769,6 +709,85 @@ gpgrt_vsnprintf (char *buf, size_t bufsize, +void * +gpgrt_realloc (void *a, size_t n) +{ + return _gpgrt_realloc (a, n); +} + +void * +gpgrt_malloc (size_t n) +{ + return _gpgrt_malloc (n); +} + +void * +gpgrt_calloc (size_t n, size_t m) +{ + return _gpgrt_calloc (n, m); +} + +char * +gpgrt_strdup (const char *string) +{ + return _gpgrt_strdup (string); +} + +char * +gpgrt_strconcat (const char *s1, ...) +{ + va_list arg_ptr; + char *result; + + if (!s1) + result = _gpgrt_strdup (""); + else + { + va_start (arg_ptr, s1); + result = _gpgrt_strconcat_core (s1, arg_ptr); + va_end (arg_ptr); + } + return result; +} + +void +gpgrt_free (void *a) +{ + if (a) + _gpgrt_free (a); +} + +char * +gpgrt_getenv (const char *name) +{ + return _gpgrt_getenv (name); +} + +int +gpgrt_setenv (const char *name, const char *value, int overwrite) +{ + return _gpgrt_setenv (name, value, overwrite); +} + +int +gpgrt_mkdir (const char *name, const char *modestr) +{ + return _gpgrt_mkdir (name, modestr); +} + +int +gpgrt_chdir (const char *name) +{ + return _gpgrt_chdir (name); +} + +char *gpgrt_getcwd (void) +{ + return _gpgrt_getcwd (); +} + + + gpgrt_b64state_t gpgrt_b64dec_start (const char *title) { @@ -990,6 +1009,8 @@ _gpgrt_log_assert (const char *expr, const char *file, + + /* For consistency reasons we use function wrappers also for Windows * specific function despite that they are technically not needed. */ diff --git a/src/visibility.h b/src/visibility.h index 3c2d6be..3209c23 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -118,14 +118,6 @@ MARK_VISIBLE (gpgrt_fputs) MARK_VISIBLE (gpgrt_fputs_unlocked) MARK_VISIBLE (gpgrt_getline) MARK_VISIBLE (gpgrt_read_line) -MARK_VISIBLE (gpgrt_realloc) -MARK_VISIBLE (gpgrt_malloc) -MARK_VISIBLE (gpgrt_calloc) -MARK_VISIBLE (gpgrt_strdup) -MARK_VISIBLE (gpgrt_strconcat) -MARK_VISIBLE (gpgrt_free) -MARK_VISIBLE (gpgrt_getenv) -MARK_VISIBLE (gpgrt_setenv) MARK_VISIBLE (gpgrt_fprintf) MARK_VISIBLE (gpgrt_fprintf_unlocked) MARK_VISIBLE (gpgrt_printf) @@ -149,10 +141,23 @@ MARK_VISIBLE (gpgrt_bsprintf) MARK_VISIBLE (gpgrt_vbsprintf) MARK_VISIBLE (gpgrt_snprintf) MARK_VISIBLE (gpgrt_vsnprintf) + MARK_VISIBLE (gpgrt_set_syscall_clamp) MARK_VISIBLE (gpgrt_get_syscall_clamp) MARK_VISIBLE (gpgrt_set_alloc_func) +MARK_VISIBLE (gpgrt_realloc) +MARK_VISIBLE (gpgrt_malloc) +MARK_VISIBLE (gpgrt_calloc) +MARK_VISIBLE (gpgrt_strdup) +MARK_VISIBLE (gpgrt_strconcat) +MARK_VISIBLE (gpgrt_free) +MARK_VISIBLE (gpgrt_getenv) +MARK_VISIBLE (gpgrt_setenv) +MARK_VISIBLE (gpgrt_mkdir) +MARK_VISIBLE (gpgrt_chdir) +MARK_VISIBLE (gpgrt_getcwd) + MARK_VISIBLE (gpgrt_b64dec_start) MARK_VISIBLE (gpgrt_b64dec_proc) MARK_VISIBLE (gpgrt_b64dec_finish) @@ -264,14 +269,6 @@ MARK_VISIBLE (_gpgrt_log_assert) #define gpgrt_fputs_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_getline _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_read_line _gpgrt_USE_UNDERSCORED_FUNCTION -#define gpgrt_realloc _gpgrt_USE_UNDERSCORED_FUNCTION -#define gpgrt_malloc _gpgrt_USE_UNDERSCORED_FUNCTION -#define gpgrt_calloc _gpgrt_USE_UNDERSCORED_FUNCTION -#define gpgrt_strdup _gpgrt_USE_UNDERSCORED_FUNCTION -#define gpgrt_strconcat _gpgrt_USE_UNDERSCORED_FUNCTION -#define gpgrt_free _gpgrt_USE_UNDERSCORED_FUNCTION -#define gpgrt_getenv _gpgrt_USE_UNDERSCORED_FUNCTION -#define gpgrt_setenv _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_fprintf _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_fprintf_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_printf _gpgrt_USE_UNDERSCORED_FUNCTION @@ -296,6 +293,18 @@ MARK_VISIBLE (_gpgrt_log_assert) #define gpgrt_snprintf _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_vsnprintf _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_realloc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_malloc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_calloc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_strdup _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_strconcat _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_free _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_getenv _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_setenv _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_mkdir _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_chdir _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_getcwd _gpgrt_USE_UNDERSCORED_FUNCTION + #define gpgrt_set_syscall_clamp _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_get_syscall_clamp _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_set_alloc_func _gpgrt_USE_UNDERSCORED_FUNCTION |