gam_server: Drop privileges after fork if euid != ruid for
Samba support (effective uid is user's uid, but real uid is 0).

-- fumiyas at osstech, 2008-05-12

diff -upr gamin-0.1.9/libgamin/gam_fork.c gamin-0.1.9.drop-privileges/libgamin/gam_fork.c
--- gamin-0.1.9/libgamin/gam_fork.c	2007-07-04 22:36:48.000000000 +0900
+++ gamin-0.1.9.drop-privileges/libgamin/gam_fork.c	2009-01-16 01:28:03.000000000 +0900
@@ -70,6 +70,23 @@ gamin_fork_server(const char *fam_client
 	int fd;
         long open_max;
 	long i;
+	uid_t uid = getuid(), euid = geteuid();
+	gid_t gid = getgid(), egid = getegid();
+
+	if (euid != uid || egid != gid) {
+	  seteuid(uid); /* Back to the super user */
+
+	  if (egid != gid) {
+	      gam_error(DEBUG_INFO, "gid=%d egid=%d\n", gid, egid);
+	      setgid(egid);
+	      gam_error(DEBUG_INFO, "gid=%d egid=%d\n", getgid(), getegid());
+	  }
+	  if (euid != uid) {
+	      gam_error(DEBUG_INFO, "uid=%d euid=%d\n", uid, euid);
+	      setuid(euid);
+	      gam_error(DEBUG_INFO, "uid=%d euid=%d\n", getuid(), geteuid());
+	  }
+	}
 
         /* don't hold open fd opened from the client of the library */
 	open_max = sysconf (_SC_OPEN_MAX);
