]> arthur.barton.de Git - netatalk.git/commitdiff
Move realpath_safe() to libatalk/util/unix.c and make it a global function
authorFrank Lahm <franklahm@googlemail.com>
Wed, 10 Oct 2012 12:13:31 +0000 (14:13 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 10 Oct 2012 12:13:31 +0000 (14:13 +0200)
include/atalk/util.h
libatalk/util/netatalk_conf.c
libatalk/util/unix.c

index c5b23ee6f9eaeca3687c0a884d6b5a0c5c614c63..9ff6813f9f36ca36c643e48bcc2ace9e34a99d9b 100644 (file)
@@ -182,6 +182,7 @@ extern int lchdir(const char *dir);
 extern void randombytes(void *buf, int n);
 extern int daemonize(int nochdir, int noclose);
 extern int run_cmd(const char *cmd, char **cmd_argv);
+extern char *realpath_safe(const char *path);
 
 /******************************************************************
  * cnid.c
index e577ac564cd1d74ff309ffd19383651f78e9d7c3..48f60783ac010c9ab9e83b6d226f9214895e8db9 100644 (file)
@@ -67,42 +67,6 @@ static int have_uservol = 0; /* whether there's generic user home share in confi
 static struct vol *Volumes = NULL;
 static uint16_t    lastvid = 0;
 
-
-/*
- * Normalize volume path
- */
-static char *realpath_safe(const char *path)
-{
-    char *resolved_path;
-
-#ifdef REALPATH_TAKES_NULL
-    if ((resolved_path = realpath(path, NULL)) == NULL) {
-        LOG(log_error, logtype_afpd, "realpath() cannot resolve path \"%s\"", path);
-        return NULL;
-    }
-    return resolved_path;
-
-#else
-if ((resolved_path = malloc(MAXPATHLEN+1)) == NULL)
-        return NULL;
-    if (realpath(path, resolved_path) == NULL) {
-        free(resolved_path);
-        LOG(log_error, logtype_afpd, "realpath() cannot resolve path \"%s\"", path);
-        return NULL;
-    }
-    /* Safe some memory */
-    char *tmp;
-    if ((tmp = strdup(resolved_path)) == NULL) {
-        free(resolved_path);
-        return NULL;
-    }
-    free(resolved_path);
-    resolved_path = tmp;
-    return resolved_path;
-#endif
-}
-
-
 /* 
  * Get a volumes UUID from the config file.
  * If there is none, it is generated and stored there.
index 56c3e168eaea05c05705464a0f21830aedf60c03..0e8fcab6aaf323867fad7a44052e7df9abbecca3 100644 (file)
@@ -342,3 +342,36 @@ int gmem(gid_t gid, int ngroups, gid_t *groups)
     }
     return( 0 );
 }
+
+/*
+ * realpath() replacement that always allocates storage for returned path
+ */
+char *realpath_safe(const char *path)
+{
+    char *resolved_path;
+
+#ifdef REALPATH_TAKES_NULL
+    if ((resolved_path = realpath(path, NULL)) == NULL) {
+        LOG(log_error, logtype_afpd, "realpath() cannot resolve path \"%s\"", path);
+        return NULL;
+    }
+    return resolved_path;
+#else
+    if ((resolved_path = malloc(MAXPATHLEN+1)) == NULL)
+        return NULL;
+    if (realpath(path, resolved_path) == NULL) {
+        free(resolved_path);
+        LOG(log_error, logtype_afpd, "realpath() cannot resolve path \"%s\"", path);
+        return NULL;
+    }
+    /* Safe some memory */
+    char *tmp;
+    if ((tmp = strdup(resolved_path)) == NULL) {
+        free(resolved_path);
+        return NULL;
+    }
+    free(resolved_path);
+    resolved_path = tmp;
+    return resolved_path;
+#endif
+}