]> arthur.barton.de Git - netatalk.git/commitdiff
lchdir: use chdir + getcwd
authordidg <didg>
Sun, 28 Feb 2010 17:02:49 +0000 (17:02 +0000)
committerdidg <didg>
Sun, 28 Feb 2010 17:02:49 +0000 (17:02 +0000)
etc/afpd/catsearch.c
etc/afpd/directory.c
include/atalk/util.h
libatalk/util/unix.c

index a1e96dfc50ab74649f67c09569f6ea8c99818e37..97069c87165a0fe832ea176b0e014823182503d8 100644 (file)
@@ -542,7 +542,7 @@ static int catsearch(struct vol *vol, struct dir *dir,
        while ((cidx = reducestack()) != -1) {
                cached = 1;
 
-               error = lchdir(dstack[cidx].path);
+               error = lchdir(vol, dstack[cidx].path);
 
                if (!error && dirpos == NULL) {
                        dirpos = opendir(".");
index dba836608a56215c874154af4de238dd92e85bde..9238cd18ee3c50b61f7f7c36c46d29e8594d393d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $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.
@@ -1581,12 +1581,17 @@ int movecwd(struct vol *vol, struct dir *dir)
         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) {
index 937007b213871f51c32175b21b08b58773831312..0106db2fa48d5e9712af71f77d9135d74c20fe73 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $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 $
  */
 
 /*!
@@ -22,6 +22,7 @@
 #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 */
@@ -121,6 +122,6 @@ extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
  *****************************************************************/
 
 extern const char *getcwdpath(void);
-extern int lchdir(const char *dir);
+extern int lchdir(struct vol *vol, const char *dir);
 
 #endif  /* _ATALK_UTIL_H */
index a8a1e1a5f3e59ee2c86133f46ec4732fdc10f41a..9fd11e615d5e9e798d9302a4e93eca492ff47dd3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  $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
@@ -64,40 +64,13 @@ const char *getcwdpath(void)
  *
  * @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
@@ -107,22 +80,14 @@ int lchdir(const char *dir)
      * /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;
 }