]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/unix.c
Add become_root() capability to nfsv4_chmod()
[netatalk.git] / libatalk / util / unix.c
index c16c5da5b50d1514243a29c0afb3edd9bd7593f6..e4cb21e8c12e95e828afb608430a73c8c034ebf8 100644 (file)
@@ -94,6 +94,22 @@ int daemonize(int nochdir, int noclose)
     return 0;
 }
 
+static uid_t saved_uid = -1;
+
+void become_root(void)
+{
+    saved_uid = geteuid();
+    if (seteuid(0) != 0)
+        AFP_PANIC("Can't seteuid(0)");
+}
+
+void unbecome_root(void)
+{
+    if (saved_uid == -1 || seteuid(saved_uid) < 0)
+        AFP_PANIC("Can't seteuid back");
+    saved_uid = -1;
+}
+
 /*!
  * @brief get cwd in static buffer
  *
@@ -110,6 +126,28 @@ const char *getcwdpath(void)
         return strerror(errno);
 }
 
+/*!
+ * @brief Request absolute path
+ *
+ * @returns Absolute filesystem path to object
+ */
+const char *fullpathname(const char *name)
+{
+    static char wd[MAXPATHLEN + 1];
+
+    if (name[0] == '/')
+        return name;
+
+    if (getcwd(wd , MAXPATHLEN)) {
+        strlcat(wd, "/", MAXPATHLEN);
+        strlcat(wd, name, MAXPATHLEN);
+    } else {
+        strlcpy(wd, name, MAXPATHLEN);
+    }
+
+    return wd;
+}
+
 /*!
  * Takes a buffer with a path, strips slashs, returns basename
  *