]> arthur.barton.de Git - netatalk.git/commitdiff
previous commit 'lchdir: use chdir + getcwd' was only testing for symlink outside...
authordidg <didg>
Sun, 28 Feb 2010 22:29:15 +0000 (22:29 +0000)
committerdidg <didg>
Sun, 28 Feb 2010 22:29:15 +0000 (22:29 +0000)
etc/afpd/catsearch.c
etc/afpd/directory.c
include/atalk/util.h
libatalk/util/unix.c

index 97069c87165a0fe832ea176b0e014823182503d8..a1e96dfc50ab74649f67c09569f6ea8c99818e37 100644 (file)
@@ -542,7 +542,7 @@ static int catsearch(struct vol *vol, struct dir *dir,
        while ((cidx = reducestack()) != -1) {
                cached = 1;
 
        while ((cidx = reducestack()) != -1) {
                cached = 1;
 
-               error = lchdir(vol, dstack[cidx].path);
+               error = lchdir(dstack[cidx].path);
 
                if (!error && dirpos == NULL) {
                        dirpos = opendir(".");
 
                if (!error && dirpos == NULL) {
                        dirpos = opendir(".");
index 9238cd18ee3c50b61f7f7c36c46d29e8594d393d..8e41298f48c9df474cc48009b3812df2501e30a2 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * $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.
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -1553,8 +1553,7 @@ int movecwd(struct vol *vol, struct dir *dir)
     }
 
     p = path + sizeof(path) - 1;
     }
 
     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) {
     for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) {
         u = d->d_u_name;
         if (!u) {
@@ -1581,7 +1580,7 @@ int movecwd(struct vol *vol, struct dir *dir)
         p -= n;
         memcpy( p, vol->v_path, n );
     }
         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) {
         LOG(log_debug, logtype_afpd, "movecwd('%s'): ret:%d, %u/%s", p, ret, errno, strerror(errno));
 
         if (ret == 1) {
index 0106db2fa48d5e9712af71f77d9135d74c20fe73..0d1f59ae8f1c502811bc4db2edd02ab4a9d2af18 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * $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 $
  */
 
 /*!
  */
 
 /*!
@@ -22,7 +22,6 @@
 #endif /* HAVE_UNISTD_H */
 #include <netatalk/at.h>
 #include <atalk/unicode.h>
 #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 */
 
 /* exit error codes */
 #define EXITERR_CLNT 1  /* client related error */
@@ -122,6 +121,6 @@ extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
  *****************************************************************/
 
 extern const char *getcwdpath(void);
  *****************************************************************/
 
 extern const char *getcwdpath(void);
-extern int lchdir(struct vol *vol, const char *dir);
+extern int lchdir(const char *dir);
 
 #endif  /* _ATALK_UTIL_H */
 
 #endif  /* _ATALK_UTIL_H */
index 9fd11e615d5e9e798d9302a4e93eca492ff47dd3..6231a03782c538809dd632593c0796bd9e57fc9a 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
-  $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
   Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
 
   This program is free software; you can redistribute it and/or modify
@@ -36,7 +36,6 @@
 #include <atalk/ea.h>
 #include <atalk/afp.h>
 #include <atalk/logger.h>
 #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>
 #include <atalk/vfs.h>
 #include <atalk/util.h>
 #include <atalk/unix.h>
@@ -64,10 +63,22 @@ const char *getcwdpath(void)
  *
  * @returns 1 if a path element is a symlink, 0 otherwise, -1 on syserror
  */
  *
  * @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 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 (chdir(dir) != 0)
         return -1;
 
@@ -83,11 +94,38 @@ int lchdir(struct vol *vol, const char *dir)
     if (getcwd(buf, MAXPATHLEN) == NULL)
         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;
         }
     }
             return 1;
         }
     }
-        
+    /* trailing '/' ? */
+    if (!dir[i])
+        return 0;
+
+    if (dir[i] != '/')
+        return 1;
+
+    i++;
+    if (dir[i])
+        return 1;
+
     return 0;
 }
     return 0;
 }