while ((cidx = reducestack()) != -1) {
cached = 1;
- error = lchdir(vol, dstack[cidx].path);
+ error = lchdir(dstack[cidx].path);
if (!error && dirpos == NULL) {
dirpos = opendir(".");
/*
- * $Id: directory.c,v 1.136 2010-02-28 17:02:49 didg Exp $
+ * $Id: directory.c,v 1.137 2010-02-28 22:29:15 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
}
p = path + sizeof(path) - 1;
- *p-- = '\0';
- *p = '.';
+ *p = '\0';
for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) {
u = d->d_u_name;
if (!u) {
p -= n;
memcpy( p, vol->v_path, n );
}
- if ( (ret = lchdir(vol, p )) != 0 ) {
+ if ( (ret = lchdir(p )) != 0 ) {
LOG(log_debug, logtype_afpd, "movecwd('%s'): ret:%d, %u/%s", p, ret, errno, strerror(errno));
if (ret == 1) {
/*
- * $Id: util.h,v 1.20 2010-02-28 17:02:49 didg Exp $
+ * $Id: util.h,v 1.21 2010-02-28 22:29:16 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(struct vol *vol, const char *dir);
+extern int lchdir(const char *dir);
#endif /* _ATALK_UTIL_H */
/*
- $Id: unix.c,v 1.5 2010-02-28 17:02:49 didg Exp $
+ $Id: unix.c,v 1.6 2010-02-28 22:29:16 didg Exp $
Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
This program is free software; you can redistribute it and/or modify
#include <atalk/ea.h>
#include <atalk/afp.h>
#include <atalk/logger.h>
-#include <atalk/volume.h>
#include <atalk/vfs.h>
#include <atalk/util.h>
#include <atalk/unix.h>
*
* @returns 1 if a path element is a symlink, 0 otherwise, -1 on syserror
*/
-int lchdir(struct vol *vol, const char *dir)
+int lchdir(const char *dir)
{
char buf[MAXPATHLEN+1];
+ char cwd[MAXPATHLEN+1];
+ char *test;
+ int i;
+ /*
+ dir is a canonical path (without "../" "./" "//" )
+ but may end with a /
+ */
+ *cwd = 0;
+ if (*dir != '/') {
+ if (getcwd(cwd, MAXPATHLEN) == NULL)
+ return -1;
+ }
if (chdir(dir) != 0)
return -1;
if (getcwd(buf, MAXPATHLEN) == NULL)
return 1;
- for (int i = 0; vol->v_path[i]; i++) {
- if (buf[i] != vol->v_path[i]) {
+ i = 0;
+ if (*cwd) {
+ /* relative path requested,
+ * Same directory?
+ */
+ for (; cwd[i]; i++) {
+ if (buf[i] != cwd[i])
+ return 1;
+ }
+ if (buf[i]) {
+ if (buf[i] != '/')
+ return 1;
+ i++;
+ }
+ }
+
+ test = &buf[i];
+ for (i = 0; test[i]; i++) {
+ if (test[i] != dir[i]) {
return 1;
}
}
-
+ /* trailing '/' ? */
+ if (!dir[i])
+ return 0;
+
+ if (dir[i] != '/')
+ return 1;
+
+ i++;
+ if (dir[i])
+ return 1;
+
return 0;
}