From 71bbbd76c62630c88441237d72fe5b61f0b45b2a Mon Sep 17 00:00:00 2001 From: Heiko Hund Date: Fri, 10 Feb 2012 15:13:42 +0100 Subject: handle Windows unicode paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Openvpn for Windows is not compiled as a Unicode binary and thus cannot handle paths which contain non-ASCII characters using the argv vector. Characters that are not present in the system codepage are simply replaced with a question mark, e.g. if started as 'openvpn --config домой.ovpn' the file '?????.ovpn' is tried to be opened as configuration. The same applies to paths in config files which need to be UTF-8 encoded if they contain non ASCII characters. The option line 'key лев.pem' will lead to openvpn trying to open 'лев.pem' on a system with codepage 1252. This patch makes openvpn read the command line in UCS-2 and convert it to UTF-8 internally. Windows stores names in the filesystem in UCS-2. When using a paths openvpn converts it from UTF-8 to UCS-2 and uses the wide character Windows API function. Signed-off-by: Heiko Hund Acked-by: David Sommerseth Signed-off-by: David Sommerseth --- misc.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'misc.h') diff --git a/misc.h b/misc.h index b1badd9..2413f53 100644 --- a/misc.h +++ b/misc.h @@ -136,6 +136,7 @@ int openvpn_execve (const struct argv *a, const struct env_set *es, const unsign bool openvpn_execve_check (const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message); bool openvpn_execve_allowed (const unsigned int flags); int openvpn_system (const char *command, const struct env_set *es, unsigned int flags); +int openvpn_access (const char *path, int mode); static inline bool openvpn_run_script (const struct argv *a, const struct env_set *es, const unsigned int flags, const char *hook) @@ -146,6 +147,36 @@ openvpn_run_script (const struct argv *a, const struct env_set *es, const unsign return openvpn_execve_check(a, es, flags | S_SCRIPT, msg); }; +#ifdef TARGET_WIN32 +FILE * openvpn_fopen (const char *path, const char *mode); +#else +static inline FILE * +openvpn_fopen (const char *path, const char *mode) +{ + return fopen (path, mode); +} +#endif + +#ifdef TARGET_WIN32 +int openvpn_open (const char *path, int flags, mode_t mode); +#else +static inline int +openvpn_open (const char *path, int flags, mode_t mode) +{ + return open (path, flags, mode); +} +#endif + +#ifdef TARGET_WIN32 +int openvpn_stat (const char *path, struct stat *buf); +#else +static inline int +openvpn_stat (const char *path, struct stat *buf) +{ + return stat (path, buf); +} +#endif + #ifdef HAVE_STRERROR /* a thread-safe version of strerror */ const char* strerror_ts (int errnum, struct gc_arena *gc); -- cgit