From 5a4a20436042ff567ebda2518f0944dacf4d01fc Mon Sep 17 00:00:00 2001 From: franklahm Date: Fri, 19 Feb 2010 10:51:59 +0000 Subject: [PATCH] Remove v_realpath from struct dir, normalize v_path instead --- etc/afpd/catsearch.c | 2 +- etc/afpd/directory.c | 6 +++--- etc/afpd/filedir.c | 6 +++--- etc/afpd/volume.c | 25 ++++++++++++++++++++++--- include/atalk/volume.h | 3 +-- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/etc/afpd/catsearch.c b/etc/afpd/catsearch.c index 662a8766..58aab8e1 100644 --- a/etc/afpd/catsearch.c +++ b/etc/afpd/catsearch.c @@ -497,7 +497,7 @@ static int catsearch(struct vol *vol, struct dir *dir, int result = AFP_OK; int ccr; struct path path; - char *vpath = vol->v_realpath; + char *vpath = vol->v_path; char *rrbuf = rbuf; time_t start_time; int num_rounds = NUM_ROUNDS; diff --git a/etc/afpd/directory.c b/etc/afpd/directory.c index 7c7eae72..438cc43f 100644 --- a/etc/afpd/directory.c +++ b/etc/afpd/directory.c @@ -1,5 +1,5 @@ /* - * $Id: directory.c,v 1.133 2010-02-19 01:26:03 didg Exp $ + * $Id: directory.c,v 1.134 2010-02-19 10:51:59 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1642,14 +1642,14 @@ int movecwd(struct vol *vol, struct dir *dir) memcpy( p, u, n ); } if ( d != curdir ) { - n = strlen( vol->v_realpath ); + n = strlen( vol->v_path ); if (p -n -1 < path) { afp_errno = AFPERR_PARAM; return -1; } *--p = '/'; p -= n; - memcpy( p, vol->v_realpath, n ); + memcpy( p, vol->v_path, n ); } if ( (ret = lchdir( p )) != 0 ) { LOG(log_debug, logtype_afpd, "movecwd('%s'): ret:%d, %u/%s", p, ret, errno, strerror(errno)); diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index 407e48a1..203622f4 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -1,5 +1,5 @@ /* - * $Id: filedir.c,v 1.71 2010-02-19 01:26:03 didg Exp $ + * $Id: filedir.c,v 1.72 2010-02-19 10:51:59 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -588,13 +588,13 @@ char *absupath(const struct vol *vol, struct dir *dir, char *u) p -= len; memcpy( p, u, len ); } - len = strlen( vol->v_realpath ); + len = strlen( vol->v_path ); if (p -len -1 < path) { return NULL; } *--p = '/'; p -= len; - memcpy( p, vol->v_realpath, len ); + memcpy( p, vol->v_path, len ); return( p ); } diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index 5dfb3b66..9d2e64f3 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -1,5 +1,5 @@ /* - * $Id: volume.c,v 1.118 2010-02-19 01:26:03 didg Exp $ + * $Id: volume.c,v 1.119 2010-02-19 10:51:59 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1252,7 +1252,6 @@ static void volume_free(struct vol *vol) free(vol->v_macname); vol->v_macname = NULL; free(vol->v_path); - free(vol->v_realpath); free(vol->v_password); free(vol->v_veto); free(vol->v_volcodepage); @@ -1993,7 +1992,27 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t LOG(log_error, logtype_afpd, "afp_openvol(%s): volume pathlen too long", volume->v_path); return AFPERR_MISC; } - volume->v_realpath = strdup(path); + + /* Normalize volume path */ +#ifdef REALPATH_TAKES_NULL + if ((volume->v_path = realpath(path, NULL)) == NULL) + return AFPERR_MISC; +#else + if ((volume->v_path = malloc(MAXPATHLEN+1)) == NULL) + return AFPERR_MISC; + if (realpath(path, volume->v_path) == NULL) { + free(volume->v_path); + return AFPERR_MISC; + } + /* Safe some memory */ + char *tmp; + if ((tmp = strdup(volume->v_path)) == NULL) { + free(volume->v_path); + return AFPERR_MISC; + } + free(volume->v_path); + volume->v_path = tmp; +#endif if (volume_codepage(obj, volume) < 0) { ret = AFPERR_MISC; diff --git a/include/atalk/volume.h b/include/atalk/volume.h index 3c47bf06..e2458ec4 100644 --- a/include/atalk/volume.h +++ b/include/atalk/volume.h @@ -1,5 +1,5 @@ /* - * $Id: volume.h,v 1.14 2010-02-19 01:26:03 didg Exp $ + * $Id: volume.h,v 1.15 2010-02-19 10:51:59 franklahm Exp $ * * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -25,7 +25,6 @@ struct vol { u_int16_t v_vid; int v_flags; char *v_path; - char *v_realpath; /* canonical path */ struct dir *v_dir, *v_root; struct dir *v_curdir; /* cache */ hash_t *v_hash; -- 2.39.2