diff --git a/src/modules/system/configure.in b/src/modules/system/configure.in
index 05e750460aa1d65e80e59b327c3dd1466872c119..da8278035d8db967ae9dd64bdb418cff41ecfb03 100644
--- a/src/modules/system/configure.in
+++ b/src/modules/system/configure.in
@@ -14,7 +14,8 @@ AC_HAVE_HEADERS(syslog.h sys/syslog.h sys/types.h errno.h unistd.h pwd.h \
 AC_HAVE_FUNCS(syslog link symlink readlink \
 	initgroups setgroups seteuid setresuid setegid setresgid \
         geteuid getpgrp getpgid getppid \
-	getpwnam getspnam getpwent setpwent endpwent \
+	getpwnam getspnam getgrnam getpwuid getgrgid \
+	getgrent setgrent endgrent getpwent setpwent endpwent \
 	chroot fchroot uname gethostname gethostbyname)
 
 AC_CHECK_LIB(nsl, gethostbyname)
diff --git a/src/modules/system/passwords.c b/src/modules/system/passwords.c
index 321a635dfd345db282f3e23fbe22cdf6f62c00ac..d66ce4897695e1c3a9b08f6a5331990892cb1f1d 100644
--- a/src/modules/system/passwords.c
+++ b/src/modules/system/passwords.c
@@ -1,5 +1,5 @@
 /*
- * $Id: passwords.c,v 1.5 1997/12/07 22:00:27 grubba Exp $
+ * $Id: passwords.c,v 1.6 1998/03/03 07:56:47 mast Exp $
  *
  * Password handling for Pike.
  *
@@ -15,7 +15,7 @@
 
 #include "global.h"
 
-RCSID("$Id: passwords.c,v 1.5 1997/12/07 22:00:27 grubba Exp $");
+RCSID("$Id: passwords.c,v 1.6 1998/03/03 07:56:47 mast Exp $");
 
 #include "module_support.h"
 #include "interpret.h"
@@ -28,12 +28,15 @@ RCSID("$Id: passwords.c,v 1.5 1997/12/07 22:00:27 grubba Exp $");
 # include <passwd.h>
 # include <group.h>
 #endif /* HAVE_PASSWD_H */
- 
+
 #ifdef HAVE_PWD_H
 # include <pwd.h>
-# include <grp.h>
 #endif /* HAVE_PWD_H */
- 
+
+#ifdef HAVE_GRP_H
+# include <grp.h>
+#endif /* HAVE_GRP_H */
+
 #ifdef HAVE_SHADOW_H
 # include <shadow.h>
 #endif /* HAVE_SHADOW_H */
@@ -42,7 +45,7 @@ RCSID("$Id: passwords.c,v 1.5 1997/12/07 22:00:27 grubba Exp $");
  * Functions
  */
 
-#if defined(HAVE_GETPWNAM) || defined(HAVE_GETPWUID) || defined(HAVE_SETPWENT) || defined(HAVE_ENDPWENT) || defined(HAVE_GETPWENT)
+#if defined(HAVE_GETPWNAM) || defined(HAVE_GETPWUID) || defined(HAVE_GETPWENT)
 static void push_pwent(struct passwd *ent)
 {
   if(!ent)
@@ -70,7 +73,9 @@ static void push_pwent(struct passwd *ent)
   push_text(ent->pw_shell);
   f_aggregate(7);
 }
+#endif
 
+#if defined(HAVE_GETGRNAM) || defined(HAVE_GETGRUID) || defined(HAVE_GETGRENT)
 static void push_grent(struct group *ent)
 {
   if(!ent)
@@ -90,9 +95,9 @@ static void push_grent(struct group *ent)
   f_aggregate(4);
 }
 #endif
- 
-#ifdef HAVE_GETPWNAM
-/* array getpwnam(string str) */
+
+#ifdef HAVE_GETGRGID
+/* array getgrgid(int gid) */
 void f_getgrgid(INT32 args)
 {
   int gid;
@@ -102,17 +107,23 @@ void f_getgrgid(INT32 args)
   pop_n_elems( args );
   push_grent( foo );
 }
+#endif /* HAVE_GETGRGID */
 
+#ifdef HAVE_GETGRNAM
+/* array getgrnam(string str) */
 void f_getgrnam(INT32 args)
 {
   char *str;
   struct group *foo;
-  get_all_args("getpwnam", args, "%s", &str);
+  get_all_args("getgrnam", args, "%s", &str);
   foo = getgrnam( str );
   pop_n_elems( args );
   push_grent( foo );
 }
+#endif /* HAVE_GETGRNAM */
 
+#ifdef HAVE_GETPWNAM
+/* array getpwnam(string str) */
 void f_getpwnam(INT32 args)
 {
   char *str;
@@ -125,7 +136,9 @@ void f_getpwnam(INT32 args)
   pop_n_elems(args);
   push_pwent(foo);
 }
+#endif /* HAVE_GETPWNAM */
 
+#ifdef HAVE_GETPWUID
 /* array getpwuid(int uid) */
 void f_getpwuid(INT32 args)
 {
@@ -139,8 +152,8 @@ void f_getpwuid(INT32 args)
   pop_n_elems(args);
   push_pwent(foo);
 }
-#endif
- 
+#endif /* HAVE_GETPWUID */
+
 #ifdef HAVE_SETPWENT
 /* int setpwent() */
 void f_setpwent(INT32 args)
@@ -151,7 +164,7 @@ void f_setpwent(INT32 args)
 }
 #endif /* HAVE_SETPWENT */
  
-#ifdef HAVE_GETPWENT
+#ifdef HAVE_ENDPWENT
 /* int endpwent() */
 void f_endpwent(INT32 args)
 {
@@ -159,7 +172,9 @@ void f_endpwent(INT32 args)
   pop_n_elems(args);
   push_int(0);
 }
+#endif /* HAVE_ENDPWENT */
 
+#ifdef HAVE_GETPWENT
 /* int|array getpwent() */ 
 void f_getpwent(INT32 args)
 {
@@ -173,6 +188,40 @@ void f_getpwent(INT32 args)
   }
   push_pwent(foo);
 }
-
 #endif /* HAVE_GETPWENT */
- 
+
+#ifdef HAVE_SETGRENT
+/* int setgrent() */
+void f_setgrent(INT32 args)
+{
+  setgrent();
+  pop_n_elems(args);
+  push_int(0);
+}
+#endif /* HAVE_SETGRENT */
+
+#ifdef HAVE_ENDGRENT
+/* int endgrent() */
+void f_endgrent(INT32 args)
+{
+  endgrent();
+  pop_n_elems(args);
+  push_int(0);
+}
+#endif /* HAVE_ENDGRENT */
+
+#ifdef HAVE_GETGRENT
+/* int|array getgrent() */
+void f_getgrent(INT32 args)
+{
+  struct group *foo;
+  pop_n_elems(args);
+  foo = getgrent();
+  if(!foo)
+  {
+    push_int(0);
+    return;
+  }
+  push_grent(foo);
+}
+#endif /* HAVE_GETGRENT */
diff --git a/src/modules/system/system.c b/src/modules/system/system.c
index f9f4b17c6787fbaa52e97a55df293215f69523b0..56892ee95badf71353076ff69ead09c7b334e129 100644
--- a/src/modules/system/system.c
+++ b/src/modules/system/system.c
@@ -1,5 +1,5 @@
 /*
- * $Id: system.c,v 1.32 1998/03/02 15:21:58 grubba Exp $
+ * $Id: system.c,v 1.33 1998/03/03 07:56:47 mast Exp $
  *
  * System-call module for Pike
  *
@@ -14,7 +14,7 @@
 #include "system.h"
 
 #include "global.h"
-RCSID("$Id: system.c,v 1.32 1998/03/02 15:21:58 grubba Exp $");
+RCSID("$Id: system.c,v 1.33 1998/03/03 07:56:47 mast Exp $");
 #include "module_support.h"
 #include "las.h"
 #include "interpret.h"
@@ -859,20 +859,37 @@ void pike_module_init(void)
 #ifdef HAVE_GETPWNAM
   add_efun("getpwnam", f_getpwnam, "function(string:array)", 
 	   OPT_EXTERNAL_DEPEND);
+#endif
+#ifdef HAVE_GETPWUID
   add_efun("getpwuid", f_getpwuid, "function(int:array)", OPT_EXTERNAL_DEPEND);
-
+#endif
+#ifdef HAVE_GETGRNAM
   add_efun("getgrnam", f_getgrnam, "function(string:array)",
 	   OPT_EXTERNAL_DEPEND);
+#endif
+#ifdef HAVE_GETGRGID
   add_efun("getgrgid", f_getgrgid, "function(int:array)", OPT_EXTERNAL_DEPEND);
 #endif
 #ifdef HAVE_GETPWENT
   add_efun("getpwent", f_getpwent, "function(void:int|array)",
            OPT_EXTERNAL_DEPEND);
+#endif
+#ifdef HAVE_ENDPWENT
   add_efun("endpwent", f_endpwent, "function(void:int)", OPT_EXTERNAL_DEPEND);
 #endif
 #ifdef HAVE_SETPWENT
   add_efun("setpwent", f_setpwent, "function(void:int)", OPT_EXTERNAL_DEPEND);
 #endif
+#ifdef HAVE_GETGRENT
+  add_efun("getgrent", f_getgrent, "function(void:int|array)",
+           OPT_EXTERNAL_DEPEND);
+#endif
+#ifdef HAVE_ENDGRENT
+  add_efun("endgrent", f_endgrent, "function(void:int)", OPT_EXTERNAL_DEPEND);
+#endif
+#ifdef HAVE_SETGRENT
+  add_efun("setgrent", f_setgrent, "function(void:int)", OPT_EXTERNAL_DEPEND);
+#endif
 
 #ifdef GETHOSTBYNAME_MUTEX_EXISTS
   add_to_callback(& fork_child_callback, cleanup_after_fork, 0, 0);
diff --git a/src/modules/system/system.h b/src/modules/system/system.h
index ab243e5bbb347f14a5a1604d3be4144876cff1db..3a708506866b69886b57d18ed5532dc0f38bd264 100644
--- a/src/modules/system/system.h
+++ b/src/modules/system/system.h
@@ -1,5 +1,5 @@
 /*
- * $Id: system.h,v 1.2 1997/09/07 11:37:01 per Exp $
+ * $Id: system.h,v 1.3 1998/03/03 07:56:47 mast Exp $
  *
  * Prototypes for the Pike system-module
  *
@@ -30,6 +30,9 @@ void f_getpwuid(INT32 args);
 void f_setpwent(INT32 args);
 void f_endpwent(INT32 args);
 void f_getpwent(INT32 args);
+void f_setgrent(INT32 args);
+void f_endgrent(INT32 args);
+void f_getgrent(INT32 args);
 
 /*
  * syslog.c