]> arthur.barton.de Git - netatalk.git/commitdiff
Move lchdir() to libatalk/util/unix.c and use that in catsearch.c.
authorfranklahm <franklahm>
Fri, 19 Feb 2010 11:29:51 +0000 (11:29 +0000)
committerfranklahm <franklahm>
Fri, 19 Feb 2010 11:29:51 +0000 (11:29 +0000)
etc/afpd/catsearch.c
etc/afpd/directory.c
include/atalk/util.h
libatalk/util/unix.c

index 58aab8e18360bf74e40f0bb7969b2c44cc9d0b51..a1e96dfc50ab74649f67c09569f6ea8c99818e37 100644 (file)
@@ -49,6 +49,8 @@
 #ifdef CNID_DB
 #include <atalk/cnid.h>
 #endif /* CNID_DB */
+#include <atalk/util.h>
+
 #include "desktop.h"
 #include "directory.h"
 #include "file.h"
@@ -540,8 +542,7 @@ static int catsearch(struct vol *vol, struct dir *dir,
        while ((cidx = reducestack()) != -1) {
                cached = 1;
 
-               /* XXX use lchdir */
-               error = chdir(dstack[cidx].path);
+               error = lchdir(dstack[cidx].path);
 
                if (!error && dirpos == NULL) {
                        dirpos = opendir(".");
index 438cc43f63ed707866a0dbb92a5228db42508765..dba836608a56215c874154af4de238dd92e85bde 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: directory.c,v 1.134 2010-02-19 10:51:59 franklahm Exp $
+ * $Id: directory.c,v 1.135 2010-02-19 11:29:51 franklahm Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -133,76 +133,6 @@ static struct dir rootpar  = { SENTINEL, SENTINEL, NULL,
  * frPutAway:   4    home directory ID
  */
 
-/*!
- * @brief symlink safe chdir replacement
- *
- * Only chdirs to dir if it doesn't contain symlinks.
- *
- * @returns 1 if a path element is a symlink, 0 otherwise, -1 on syserror
- */
-static int lchdir(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)
-        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
-     * (after getwcwd) |                 |
-     * =======================================
-     * /a/b/.          | /a/b            | 0
-     * /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 (chdir(dir) != 0) {
-        ret = -1;
-        goto exit;
-    }
-
-exit:
-#ifdef REALPATH_TAKES_NULL
-    free(rpath);
-#endif
-    return ret;
-}
-
 static struct dir *
 vol_tree_root(const struct vol *vol, u_int32_t did)
 {
index c03fe311e44f826326b75c5ed9a130fdcd7a8e5d..937007b213871f51c32175b21b08b58773831312 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: util.h,v 1.18 2010-01-05 19:05:52 franklahm Exp $
+ * $Id: util.h,v 1.19 2010-02-19 11:29:52 franklahm Exp $
  */
 
 /*!
@@ -121,5 +121,6 @@ extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
  *****************************************************************/
 
 extern const char *getcwdpath(void);
+extern int lchdir(const char *dir);
 
 #endif  /* _ATALK_UTIL_H */
index 5ebd3e5c0c6204dabb8d3fabe4b2a1c606db19f1..a8a1e1a5f3e59ee2c86133f46ec4732fdc10f41a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  $Id: unix.c,v 1.3 2010-01-26 08:05:17 didg Exp $
+  $Id: unix.c,v 1.4 2010-02-19 11:29:52 franklahm Exp $
   Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
 
   This program is free software; you can redistribute it and/or modify
@@ -46,7 +46,7 @@
  *
  * @returns pointer to path or pointer to error messages on error
  */
-extern const char *getcwdpath(void)
+const char *getcwdpath(void)
 {
     static char cwd[MAXPATHLEN + 1];
     char *p;
@@ -56,3 +56,73 @@ extern const char *getcwdpath(void)
     else
         return strerror(errno);
 }
+
+/*!
+ * @brief symlink safe chdir replacement
+ *
+ * Only chdirs to dir if it doesn't contain symlinks.
+ *
+ * @returns 1 if a path element is a symlink, 0 otherwise, -1 on syserror
+ */
+int lchdir(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)
+        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
+     * (after getwcwd) |                 |
+     * =======================================
+     * /a/b/.          | /a/b            | 0
+     * /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 (chdir(dir) != 0) {
+        ret = -1;
+        goto exit;
+    }
+
+exit:
+#ifdef REALPATH_TAKES_NULL
+    free(rpath);
+#endif
+    return ret;
+}