From 51dc986c1a36aba9703d91bca5eccfaabc9e0695 Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Tue, 3 Mar 1998 11:51:38 +0100
Subject: [PATCH] Added getgrent and friends.

Rev: src/modules/system/configure.in:1.19
Rev: src/modules/system/passwords.c:1.6
Rev: src/modules/system/system.c:1.43
Rev: src/modules/system/system.h:1.4
---
 src/modules/system/configure.in |  3 +-
 src/modules/system/passwords.c  | 79 ++++++++++++++++++++++++++-------
 src/modules/system/system.c     | 23 ++++++++--
 src/modules/system/system.h     |  5 ++-
 4 files changed, 90 insertions(+), 20 deletions(-)

diff --git a/src/modules/system/configure.in b/src/modules/system/configure.in
index 75ab3b9b5e..2430ac69c9 100644
--- a/src/modules/system/configure.in
+++ b/src/modules/system/configure.in
@@ -15,7 +15,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 chown \
 	initgroups setgroups getgroups seteuid setresuid setegid setresgid \
         geteuid getpgrp getpgid getppid getuid getgid setuid setgid \
-	getpwnam getspnam getpwent setpwent endpwent \
+	getpwnam getspnam getgrnam getpwuid getgrgid \
+	getgrent setgrent endgrent getpwent setpwent endpwent \
 	chroot fchroot uname gethostname gethostbyname)
 
 
diff --git a/src/modules/system/passwords.c b/src/modules/system/passwords.c
index 321a635dfd..6f962d781c 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 10:51:37 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 10:51:37 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 918f9bfce8..62df9dc8bf 100644
--- a/src/modules/system/system.c
+++ b/src/modules/system/system.c
@@ -1,5 +1,5 @@
 /*
- * $Id: system.c,v 1.42 1998/02/27 08:41:45 hubbe Exp $
+ * $Id: system.c,v 1.43 1998/03/03 10:51:38 mast Exp $
  *
  * System-call module for Pike
  *
@@ -14,7 +14,7 @@
 #include "system.h"
 
 #include "global.h"
-RCSID("$Id: system.c,v 1.42 1998/02/27 08:41:45 hubbe Exp $");
+RCSID("$Id: system.c,v 1.43 1998/03/03 10:51:38 mast Exp $");
 #ifdef HAVE_WINSOCK_H
 #include <winsock.h>
 #endif
@@ -1046,20 +1046,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 776c769244..acb7337033 100644
--- a/src/modules/system/system.h
+++ b/src/modules/system/system.h
@@ -1,5 +1,5 @@
 /*
- * $Id: system.h,v 1.3 1998/02/24 23:10:25 hubbe Exp $
+ * $Id: system.h,v 1.4 1998/03/03 10:51:38 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
-- 
GitLab