summaryrefslogtreecommitdiff
path: root/os2/os2.c
diff options
context:
space:
mode:
authorIlya Zakharevich <ilya@math.berkeley.edu>2001-06-21 02:23:56 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2001-06-21 12:03:56 +0000
commitf72c975a9a4415edd33b16ea436dde0fc40a3a9d (patch)
tree5c14e6b338bbeb4df504534a77c6f268da10b152 /os2/os2.c
parentb8a35e92cdd8c3e28d74655a02307c4b94315f31 (diff)
downloadperl-f72c975a9a4415edd33b16ea436dde0fc40a3a9d.tar.gz
[PATCH 5.6.1] OS2 getpw*, getgr*
Date: Thu, 21 Jun 2001 06:23:56 -0400 Message-ID: <20010621062356.A8619@math.ohio-state.edu> Subject: Re: [PATCH 5.6.1] OS2 getpw*, getgr* From: Ilya Zakharevich <ilya@math.ohio-state.edu> Date: Thu, 21 Jun 2001 06:32:21 -0400 Message-ID: <20010621063221.A8823@math.ohio-state.edu> p4raw-id: //depot/perl@10768
Diffstat (limited to 'os2/os2.c')
-rw-r--r--os2/os2.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/os2/os2.c b/os2/os2.c
index a2b196e3eb..582311a3a8 100644
--- a/os2/os2.c
+++ b/os2/os2.c
@@ -21,6 +21,8 @@
#include <limits.h>
#include <process.h>
#include <fcntl.h>
+#include <pwd.h>
+#include <grp.h>
#define PERLIO_NOT_STDIO 0
@@ -2414,3 +2416,108 @@ my_flock(int handle, int o)
errno = 0;
return 0;
}
+
+static int pwent_cnt;
+static int _my_pwent = -1;
+
+static int
+use_my_pwent(void)
+{
+ if (_my_pwent == -1) {
+ char *s = getenv("USE_PERL_PWENT");
+ if (s)
+ _my_pwent = atoi(s);
+ else
+ _my_pwent = 1;
+ }
+ return _my_pwent;
+}
+
+#undef setpwent
+#undef getpwent
+#undef endpwent
+
+void
+my_setpwent(void)
+{
+ if (!use_my_pwent()) {
+ setpwent(); /* Delegate to EMX. */
+ return;
+ }
+ pwent_cnt = 0;
+}
+
+void
+my_endpwent(void)
+{
+ if (!use_my_pwent()) {
+ endpwent(); /* Delegate to EMX. */
+ return;
+ }
+}
+
+struct passwd *
+my_getpwent (void)
+{
+ if (!use_my_pwent())
+ return getpwent(); /* Delegate to EMX. */
+ if (pwent_cnt++)
+ return 0; // Return one entry only
+ return getpwuid(0);
+}
+
+static int grent_cnt;
+
+void
+setgrent(void)
+{
+ grent_cnt = 0;
+}
+
+void
+endgrent(void)
+{
+}
+
+struct group *
+getgrent (void)
+{
+ if (grent_cnt++)
+ return 0; // Return one entry only
+ return getgrgid(0);
+}
+
+#undef getpwuid
+#undef getpwnam
+
+/* Too long to be a crypt() of anything, so it is not-a-valid pw_passwd. */
+static const char pw_p[] = "Jf0Wb/BzMFvk7K7lrzK";
+
+static struct passwd *
+passw_wrap(struct passwd *p)
+{
+ static struct passwd pw;
+ char *s;
+
+ if (!p || (p->pw_passwd && *p->pw_passwd)) /* Not a dangerous password */
+ return p;
+ pw = *p;
+ s = getenv("PW_PASSWD");
+ if (!s)
+ s = (char*)pw_p; /* Make match impossible */
+
+ pw.pw_passwd = s;
+ return &pw;
+}
+
+struct passwd *
+my_getpwuid (uid_t id)
+{
+ return passw_wrap(getpwuid(id));
+}
+
+struct passwd *
+my_getpwnam (__const__ char *n)
+{
+ return passw_wrap(getpwnam(n));
+}