--- gdomap.c.org	Fri Aug  8 19:35:10 2003
+++ gdomap.c	Mon Aug 18 11:15:59 2003
@@ -823,7 +823,11 @@
 static unsigned long	prb_size = 0;
 typedef struct	{
   struct in_addr	sin;
+#ifdef __FreeBSD__
+  time_t		when; // ctime() expects a 'const time_t *'
+#else
   long			when;
+#endif
 } prb_type;
 static prb_type	**prb = 0;
 
@@ -4637,6 +4641,101 @@
     }
   else
     {
+      //
+      // Note: the following code is pretty much useless.
+      // We chroot(3)'d to '/tmp' above, effectively 'cutting off' access to /etc/passwd
+      // which means that we WON'T be able to get the uid and gid for 'nobody'.
+      //
+      // Nevertheless, I added this snipped for FreeBSD in case this part of gdomap is
+      // going to be fixed. Assuming -2 for uid and gid is not an option, see below...
+      //
+#ifdef CBV /* __FreeBSD__ */
+      struct passwd	*pw;
+      const char	*name = "nobody";
+      uid_t		uid;
+      gid_t		gid;
+      
+      pw = NULL;
+      
+      //
+      // Rewind to the beginning of the PW database and make sure it stays open
+      //
+      
+      setpassent(1);
+      {
+        errno = 0;
+        
+        /* No need to check whether HAVE_GETPWNAM is defined as it has been around
+        ** since AT&T Version 7 -- same holds true for getpwuid()
+        */
+        
+        //
+        // Translate name into a PW pointer
+        //
+        
+        pw = (struct passwd *) getpwnam(name);
+        
+        //
+        // Got the entry
+        //
+        
+        if( pw )
+        {
+          uid = pw->pw_uid;
+          gid = pw->pw_gid;
+        }
+        //
+        // Failed, so let's try it as a number
+        //
+        else
+        {
+          long	id;
+          char	*p;
+          
+          id = strtol(name, &p, 10);
+          
+          if( *name && !*p && (pw = getpwuid(id)) )
+          {
+            uid = pw->pw_uid;
+            gid = pw->pw_gid;
+          }
+          //
+          // Failed again, so dump a warning and assume default values
+          //
+          else
+          {
+            sprintf(ebuf, "Cannot get UID, assuming default values.");
+            gdomap_log(LOG_WARNING);
+            
+            // uid_t and gid_t expect an 'unsigned int'
+            // so -2 would be way out of range (ie. 4294967294)
+            
+            uid = gid = 65534;
+          }
+        }
+        // Nothing more to do, close the PW database
+      }
+      endpwent();
+      
+      errno = 0;
+      
+      //
+      // setgroups() works correctly only for 'root', therefor we clear the
+      // group access list before switching and dump a warning if it failed
+      //
+      
+      if( setgroups(0, NULL) < 0 )
+      {
+        sprintf(ebuf, "Cannot clear the group access list: %s",
+                      strerror(errno));
+        gdomap_log(LOG_WARNING);
+      }
+      
+      setuid(uid);
+      setgid(gid);
+      
+#else /* __FreeBSD__ */
+      
       int	uid = -2;
       int	gid = -2;
 #ifdef	HAVE_PWD_H
@@ -4653,6 +4752,7 @@
       setuid (uid);
       setgid (gid);
       setgroups (0, 0);	/* Empty additional groups list */
+#endif /* __FreeBSD__ */
     }
 #endif /* __MINGW__ */
 
