From: didg Date: Tue, 7 Dec 2004 02:58:08 +0000 (+0000) Subject: deal with AFP3 connection but type 2 (not UTF8 encoding) name. X-Git-Tag: netatalk-2-0-2~16 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=39b87f80a88ac1798c26033fc04eb0f46a1ce70d deal with AFP3 connection but type 2 (not UTF8 encoding) name. --- diff --git a/etc/afpd/directory.c b/etc/afpd/directory.c index 9f19652a..e22c7c94 100644 --- a/etc/afpd/directory.c +++ b/etc/afpd/directory.c @@ -1,5 +1,5 @@ /* - * $Id: directory.c,v 1.71.2.4.2.15.2.1 2004-10-20 21:43:33 didg Exp $ + * $Id: directory.c,v 1.71.2.4.2.15.2.2 2004-12-07 02:58:10 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -979,6 +979,7 @@ char **cpath; u_int16_t len16; int size = 0; char sep; + int toUTF8 = 0; data = *cpath; afp_errno = AFPERR_NOOBJ; @@ -988,6 +989,10 @@ char **cpath; len = (unsigned char) *data++; size = 2; sep = 0; + if (afp_version >= 30) { + ret.m_type = 3; + toUTF8 = 1; + } break; case 3: if (afp_version >= 30) { @@ -1104,9 +1109,20 @@ char **cpath; if ( p != path ) { /* we got something */ ret.u_name = NULL; if (afp_version >= 30) { - /* check for OS X mangled filename :( */ char *t; cnid_t fileid; + + if (toUTF8) { + static char temp[ MAXPATHLEN + 1]; + + /* not an UTF8 name */ + if (mtoUTF8(vol, path, strlen(path), temp, MAXPATHLEN) == -1) { + afp_errno = AFPERR_PARAM; + return( NULL ); + } + strcpy(path, temp); + } + /* check for OS X mangled filename :( */ t = demangle_osx(vol, path, dir->d_did, &fileid); if (t != path) { diff --git a/etc/afpd/file.c b/etc/afpd/file.c index 52fc185e..09502efa 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -1,5 +1,5 @@ /* - * $Id: file.c,v 1.92.2.2.2.31.2.3 2004-10-30 21:43:46 didg Exp $ + * $Id: file.c,v 1.92.2.2.2.31.2.4 2004-12-07 02:58:09 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1127,7 +1127,21 @@ struct adouble *adp; return( AFP_OK ); } -int copy_path_name(char *newname, char *ibuf) +/* ---------------- + convert a Mac long name to an utf8 name, +*/ +size_t mtoUTF8(const struct vol *vol, const char *src, size_t srclen, char *dest, size_t destlen) +{ +size_t outlen; + + if ((size_t)-1 == (outlen = convert_string ( vol->v_maccharset, CH_UTF8_MAC, src, srclen, dest, destlen)) ) { + return -1; + } + return outlen; +} + +/* ---------------- */ +int copy_path_name(const struct vol *vol, char *newname, char *ibuf) { char type = *ibuf; size_t plen = 0; @@ -1141,8 +1155,16 @@ u_int32_t hint; switch (type) { case 2: if (( plen = (unsigned char)*ibuf++ ) != 0 ) { - strncpy( newname, ibuf, plen ); - newname[ plen ] = '\0'; + if (afp_version >= 30) { + /* convert it to UTF8 + */ + if ((plen = mtoUTF8(vol, ibuf, plen, newname, AFPOBJ_TMPSIZ)) == -1) + return -1; + } + else { + strncpy( newname, ibuf, plen ); + newname[ plen ] = '\0'; + } if (strlen(newname) != plen) { /* there's \0 in newname, e.g. it's a pathname not * only a filename. @@ -1259,7 +1281,7 @@ int ibuflen, *rbuflen; } /* one of the handful of places that knows about the path type */ - if (copy_path_name(newname, ibuf) < 0) { + if (copy_path_name(d_vol, newname, ibuf) < 0) { return( AFPERR_PARAM ); } /* newname is always only a filename so curdir *is* its diff --git a/etc/afpd/file.h b/etc/afpd/file.h index 1e66e70b..dc0ddb83 100644 --- a/etc/afpd/file.h +++ b/etc/afpd/file.h @@ -1,5 +1,5 @@ /* - * $Id: file.h,v 1.16.2.2.2.3 2004-03-11 02:02:01 didg Exp $ + * $Id: file.h,v 1.16.2.2.2.3.2.1 2004-12-07 02:58:09 didg Exp $ * * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. @@ -134,7 +134,9 @@ extern int copyfile __P((const struct vol *, const struct vol *, char *, cha extern int deletefile __P((const struct vol *, char *, int)); extern void *get_finderinfo __P((const char *, struct adouble *, void *)); -extern int copy_path_name __P((char *, char *i)); + +extern size_t mtoUTF8 __P((const struct vol *, const char *, size_t , char *, size_t )); +extern int copy_path_name __P((const struct vol *, char *, char *i)); extern u_int32_t get_id __P((struct vol *, struct adouble *, const struct stat *, const cnid_t , const char *, const int )); diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index 12bede57..8555cada 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -1,5 +1,5 @@ /* - * $Id: filedir.c,v 1.45.2.2.2.14 2004-10-06 20:05:14 bfernhomberg Exp $ + * $Id: filedir.c,v 1.45.2.2.2.14.2.1 2004-12-07 02:58:08 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -503,7 +503,7 @@ int ibuflen, *rbuflen; } /* another place where we know about the path type */ - if ((plen = copy_path_name(newname, ibuf)) < 0) { + if ((plen = copy_path_name(vol, newname, ibuf)) < 0) { return( AFPERR_PARAM ); } @@ -719,7 +719,7 @@ int ibuflen, *rbuflen; } /* one more place where we know about path type */ - if ((plen = copy_path_name(newname, ibuf)) < 0) { + if ((plen = copy_path_name(vol, newname, ibuf)) < 0) { return( AFPERR_PARAM ); }