httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Betz <db...@df.eu>
Subject [users@httpd] problems with apr-iconv and mod_dav with special chars
Date Fri, 12 May 2017 09:03:49 GMT
Hey all,

dont know if im right here, so i will quick ask my question here.

In the german language are this annoying special chars and umlauts: äöü...
Problem is, that when an user saves an file with these umlauts, and connects over webdav to
the apache, then the umlauts are not readable and the files are not usable and so on.
I have tried all Charset options in config, without success :(

Therefore i have thought i will include apr-iconv and patch the mod_dav, that it returns the
filenames in the correct charset.
But the problem is, that im an bad programmer and the apache only segfaults.
I cant find the failure, so my hope is, that someone can have an look and give me an hint
to get this running.

Segfault occurs in lib/iconv.c from apr-iconv-1.2.1:

Program received signal SIGSEGV, Segmentation fault.
apr_iconv_open (to=to@entry=0x80e3fa2 "UTF-8", from=from@entry=0x80e3f98 "ISO8859-1", ctx=ctx@entry=0x81931c0,
res=res@entry=0x0) at iconv.c:82
82              *res = (apr_iconv_t)-1;
(gdb) bt full
#0  apr_iconv_open (to=to@entry=0x80e3fa2 "UTF-8", from=from@entry=0x80e3f98 "ISO8859-1",
ctx=ctx@entry=0x81931c0, res=res@entry=0x0) at iconv.c:82
        idesc = <optimized out>
        icp = <optimized out>
        data = <optimized out>
        error = <optimized out>
#1  0x080b22fe in do_iconv (sIn=sIn@entry=0x818ea20 "/webdav/", p=p@entry=0x81931c0, outCharset=outCharset@entry=0x80e3fa2
"UTF-8", inCharset=inCharset@entry=0x80e3f98 "ISO8859-1") at util.c:2130
        oIconv = <optimized out>
        iInLeft = 8
        iOutLeft = 256
        iTranslated = 135856000
        sSource = 0x818ea20 "/webdav/"
        sTmpDest = 0x8193200 ""
#2  0x080b2467 in iso2utf8 (sIn=0x818ea20 "/webdav/", p=p@entry=0x81931c0) at util.c:2154
No locals.
#3  0x080a7460 in dav_send_one_response (response=response@entry=0xffffdee8, bb=0x818e8f0,
output=0x818ff80, pool=pool@entry=0x81931c0) at mod_dav.c:447
        t = <optimized out>
#4  0x080a7a73 in dav_stream_response (status=status@entry=0, propstats=propstats@entry=0xffffdf48,
pool=0x81931c0, wres=0xffffe0a8, wres=0xffffe0a8) at mod_dav.c:1132
        resp = {href = 0x818ea20 "/webdav/", desc = 0x0, propresult = {propstats = 0x8195290,
xmlns = 0x81952c0}, status = 0, next = 0x0}
        ctx = <optimized out>

The iconv.c relevant part:

API_DECLARE(apr_status_t)
apr_iconv_open(const char *to, const char *from, apr_pool_t *ctx, apr_iconv_t *res) {
        struct iconv_converter_desc **idesc;
        struct iconv_converter *icp;
        void *data;
        apr_status_t error;

        *res = (apr_iconv_t)-1; /* <-------------------------------------------------------------------------------------
Here is line 82 where the segfault occurs. */
        icp = malloc(sizeof(*icp));
        if (icp == NULL)
                return (APR_ENOMEM);
        error = APR_EINVAL;
        for (idesc = converters; *idesc; idesc++) {
                error = (*idesc)->icd_open(to, from, &data, ctx);
                if (error == APR_SUCCESS)
                        break;
        }
        if (error) {
                free(icp);
                return (error);
        }
        icp->ic_desc = *idesc;
        icp->ic_data = data;
        *res = icp;
        return(APR_SUCCESS);
}





The apache config looks like this:

<VirtualHost *>
  ServerName hostname
  ServerAlias www.hostname
  DocumentRoot "/var/ww/html/hostname"
  RuidGid username nobody
  Alias /webdav "/var/www/html/hostname/"
  <Directory />
    Require User "username"
  </Directory>
</VirtualHost>

<Directory /var/www/html>
  Dav ON
  AuthType Digest
  AuthName "webdav"
  AuthUserFile /var/www/html/.passwd
  Options -FollowSymLinks
  RequestHeader edit Transfer-Encoding Chunked chunked early </Directory>


Connection occurs like this: net use P: https://hostname/webdav/  /USER:username /persistent:no


And now my patch for webdav looks like this:

--- httpd/modules/dav/main/util.c        2010-07-21 20:25:49.000000000 +0200
+++ httpd_patched/modules/dav/main/util.c        2017-05-10 11:00:54.723912507 +0200
@@ -19,6 +19,10 @@
 **  - various utilities, repository-independent
 */

+#define ICONV_INTERNAL
+#include "iconv.h"
+#include "apr_iconv.h"
+
 #include "apr_strings.h"
 #include "apr_lib.h"

@@ -2107,3 +2111,50 @@

     return NULL;
 }
+
+char *do_iconv(char *sIn, apr_pool_t *p, const char *outCharset, const char *inCharset) {
+  apr_iconv_t oIconv;
+  apr_size_t iInLeft;
+  apr_size_t iOutLeft;
+  apr_size_t iTranslated;
+  apr_status_t iRet;
+  const char *sSource;
+  char *sTmpDest, *sDest;
+
+  sSource = sIn;
+  iInLeft = strlen(sIn);
+  iOutLeft = (apr_size_t)(NAME_MAX+1);
+  DBG3("Before Source: %s  iInLeft: %d  iOutLeft: %d", sIn, iInLeft, iOutLeft);
+  sTmpDest = sDest = (char *)apr_pcalloc(p, (apr_size_t)(NAME_MAX+1));
+
+  oIconv = apr_iconv_open(outCharset, inCharset, p, oIconv);
+  if ( oIconv == (apr_iconv_t)-1 ) {
+    if ( errno == EINVAL ) {
+      DBG0("Conversion not possible");
+    } else {
+      DBG0("Konnte iconv-Objekt nich erstellen");
+    }
+  }
+
+  apr_size_t iResult;
+  while ( iInLeft > 0 ) {
+          if( apr_iconv(oIconv, &sSource, &iInLeft, &sTmpDest, &iOutLeft,
&iTranslated) == (apr_size_t)(-1) ) {
+            DBG0("Fehler beim iconv");
+          }
+  }
+
+  /*DBG3("After Source: %s  iInLeft: %d  iOutLeft: %d", sIn, iInLeft, iOutLeft);
+  DBG1("%s", sDest);*/
+  apr_iconv_close(oIconv, p);
+
+  return sDest;
+}
+
+char *iso2utf8(char *sIn, apr_pool_t *p) {
+        return do_iconv(sIn, p, "UTF-8", "ISO8859-1");
+}
+
+char *utf82iso(char *sIn, apr_pool_t *p) {
+        return do_iconv(sIn, p, "ISO8859-1", "UTF-8");
+}
+
--- httpd/modules/dav/main/mod_dav.c     2011-02-09 09:43:17.000000000 +0100
+++ httpd_patched/modules/dav/main/mod_dav.c     2017-05-10 08:31:59.444652353 +0200
@@ -443,7 +444,7 @@

     ap_fputstrs(output, bb,
                 DEBUG_CR "<D:href>",
-                dav_xml_escape_uri(pool, response->href),
+                dav_xml_escape_uri(pool, iso2utf8(response->href, pool)),
                 "</D:href>" DEBUG_CR,
                 NULL);


Kind regards,
Daniel



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message