while ((cidx = reducestack()) != -1) {
cached = 1;
- error = lchdir(dstack[cidx].path);
+ error = lchdir(vol, dstack[cidx].path);
if (!error && dirpos == NULL) {
dirpos = opendir(".");
/*
- * $Id: directory.c,v 1.135 2010-02-19 11:29:51 franklahm Exp $
+ * $Id: directory.c,v 1.136 2010-02-28 17:02:49 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
p -= n;
memcpy( p, vol->v_path, n );
}
- if ( (ret = lchdir( p )) != 0 ) {
+ if ( (ret = lchdir(vol, p )) != 0 ) {
LOG(log_debug, logtype_afpd, "movecwd('%s'): ret:%d, %u/%s", p, ret, errno, strerror(errno));
if (ret == 1) {
- /* p is a symlink */
+ /* p is a symlink or getcwd failed */
afp_errno = AFPERR_BADTYPE;
+ vol->v_curdir = curdir = vol->v_dir;
+ if (chdir(vol->v_path ) < 0) {
+ LOG(log_debug, logtype_afpd, "can't chdir back'%s': %s", vol->v_path, strerror(errno));
+ /* XXX what do we do here? */
+ }
return -1;
}
switch (errno) {
/*
- * $Id: util.h,v 1.19 2010-02-19 11:29:52 franklahm Exp $
+ * $Id: util.h,v 1.20 2010-02-28 17:02:49 didg Exp $
*/
/*!
#endif /* HAVE_UNISTD_H */
#include <netatalk/at.h>
#include <atalk/unicode.h>
+#include <atalk/volume.h>
/* exit error codes */
#define EXITERR_CLNT 1 /* client related error */
*****************************************************************/
extern const char *getcwdpath(void);
-extern int lchdir(const char *dir);
+extern int lchdir(struct vol *vol, const char *dir);
#endif /* _ATALK_UTIL_H */
/*
- $Id: unix.c,v 1.4 2010-02-19 11:29:52 franklahm Exp $
+ $Id: unix.c,v 1.5 2010-02-28 17:02:49 didg Exp $
Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
This program is free software; you can redistribute it and/or modify
*
* @returns 1 if a path element is a symlink, 0 otherwise, -1 on syserror
*/
-int lchdir(const char *dir)
+int lchdir(struct vol *vol, const char *dir)
{
- int ret = 0;
char buf[MAXPATHLEN+1];
-#ifdef REALPATH_TAKES_NULL
- char *rpath = NULL;
-#else
- char rpath[MAXPATHLEN+1];
-#endif
- /* dir might be an relative or an absolute path */
- if (dir[0] == '/') {
- /* absolute path, just make sure buf is prepared for strlcat */
- buf[0] = 0;
- } else {
- /* relative path, push cwd int buf */
- if (getcwd(buf, MAXPATHLEN) == NULL)
- return -1;
- if (strlcat(buf, "/", MAXPATHLEN) >= MAXPATHLEN)
- return -1;
- }
-
- if (strlcat(buf, dir, MAXPATHLEN) >= MAXPATHLEN)
+ if (chdir(dir) != 0)
return -1;
-#ifdef REALPATH_TAKES_NULL
- if ((rpath = realpath(dir, NULL)) == NULL) {
-#else
- if (realpath(dir, rpath) == NULL) {
-#endif
- ret = -1;
- goto exit;
- }
-
/*
* Cases:
* chdir request | realpath result | ret
* /a/b/. | /c | 1
* /a/b/. | /c/d/e/f | 1
*/
- ret = 0;
- for (int i = 0; rpath[i]; i++) {
- if (buf[i] != rpath[i]) {
- ret = 1;
- goto exit;
- }
- }
+ if (getcwd(buf, MAXPATHLEN) == NULL)
+ return 1;
- if (chdir(dir) != 0) {
- ret = -1;
- goto exit;
+ for (int i = 0; vol->v_path[i]; i++) {
+ if (buf[i] != vol->v_path[i]) {
+ return 1;
+ }
}
-
-exit:
-#ifdef REALPATH_TAKES_NULL
- free(rpath);
-#endif
- return ret;
+
+ return 0;
}