]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/unix.c
Move volume loading to libatalk
[netatalk.git] / libatalk / util / unix.c
index 0ac210ec2c8d4e3e1d99ab16a33f7067cfabd24f..5b0da03c5087e6f710b1d11a5a0717431efeb5b6 100644 (file)
@@ -95,6 +95,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
  *
@@ -256,3 +272,15 @@ void randombytes(void *buf, int n)
 
     return;
 }
+
+int gmem(gid_t gid, int ngroups, gid_t *groups)
+{
+    int                i;
+
+    for ( i = 0; i < ngroups; i++ ) {
+        if ( groups[ i ] == gid ) {
+            return( 1 );
+        }
+    }
+    return( 0 );
+}