Browse code

Support UTF-8 --client-config-dir

If a common name (or user name, when used in conjunction with
--username-as-common-name) contains UTF-8 encoded characters their
octets get replaced by underscores. This becomes problematic when
user "Müller" and "Möller" need to have a CCD file and both would
receive options from the file "M__ller". The situation is even
worse for non-latin alphabets, where CCD file names consist of
underscores entirely.

This patch removes that limitation and also allows the file names
to contain any punctuation characters besided the resevered ones.

Signed-off-by: Heiko Hund <heiko.hund@sophos.com>
Acked-by: David Sommerseth <davids@redhat.com>
Message-Id: 1351516597-11128-1-git-send-email-heiko.hund@sophos.com
URL: http://article.gmane.org/gmane.network.openvpn.devel/7110
Signed-off-by: David Sommerseth <davids@redhat.com>

Heiko Hund authored on 2012/10/29 22:16:37
Showing 3 changed files
... ...
@@ -782,6 +782,16 @@ char_class (const unsigned char c, const unsigned int flags)
782 782
     return true;
783 783
   if ((flags & CC_EQUAL) && c == '=')
784 784
     return true;
785
+  if ((flags & CC_LESS_THAN) && c == '<')
786
+    return true;
787
+  if ((flags & CC_GREATER_THAN) && c == '>')
788
+    return true;
789
+  if ((flags & CC_PIPE) && c == '|')
790
+    return true;
791
+  if ((flags & CC_QUESTION_MARK) && c == '?')
792
+    return true;
793
+  if ((flags & CC_ASTERISK) && c == '*')
794
+    return true;
785 795
 
786 796
   return false;
787 797
 }
... ...
@@ -736,6 +736,11 @@ const char *np (const char *str);
736 736
 #define CC_REVERSE_QUOTE      (1<<23)
737 737
 #define CC_AT                 (1<<24)
738 738
 #define CC_EQUAL              (1<<25)
739
+#define CC_LESS_THAN          (1<<26)
740
+#define CC_GREATER_THAN       (1<<27)
741
+#define CC_PIPE               (1<<28)
742
+#define CC_QUESTION_MARK      (1<<29)
743
+#define CC_ASTERISK           (1<<30)
739 744
 
740 745
 /* macro classes */
741 746
 #define CC_NAME               (CC_ALNUM|CC_UNDERBAR)
... ...
@@ -1056,7 +1056,13 @@ hostname_randomize(const char *hostname, struct gc_arena *gc)
1056 1056
 const char *
1057 1057
 gen_path (const char *directory, const char *filename, struct gc_arena *gc)
1058 1058
 {
1059
-  const char *safe_filename = string_mod_const (filename, CC_ALNUM|CC_UNDERBAR|CC_DASH|CC_DOT|CC_AT, 0, '_', gc);
1059
+#if WIN32
1060
+  const int CC_PATH_RESERVED = CC_LESS_THAN|CC_GREATER_THAN|CC_COLON|
1061
+    CC_DOUBLE_QUOTE|CC_SLASH|CC_BACKSLASH|CC_PIPE|CC_QUESTION_MARK|CC_ASTERISK;
1062
+#else
1063
+  const int CC_PATH_RESERVED = CC_SLASH;
1064
+#endif
1065
+  const char *safe_filename = string_mod_const (filename, CC_PRINT, CC_PATH_RESERVED, '_', gc);
1060 1066
 
1061 1067
   if (safe_filename
1062 1068
       && strcmp (safe_filename, ".")