summaryrefslogtreecommitdiff
path: root/os2
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
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')
-rw-r--r--os2/os2.c107
-rw-r--r--os2/os2ish.h32
2 files changed, 139 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));
+}
diff --git a/os2/os2ish.h b/os2/os2ish.h
index 30e67ca071..e6e8b5faef 100644
--- a/os2/os2ish.h
+++ b/os2/os2ish.h
@@ -17,6 +17,23 @@
#define HAS_DLERROR
#define HAS_WAITPID_RUNTIME (_emx_env & 0x200)
+/* HAS_PASSWD
+ * This symbol, if defined, indicates that the getpwnam() and
+ * getpwuid() routines are available to get password entries.
+ * The getpwent() has a separate definition, HAS_GETPWENT.
+ */
+#define HAS_PASSWD
+
+/* HAS_GROUP
+ * This symbol, if defined, indicates that the getgrnam() and
+ * getgrgid() routines are available to get group entries.
+ * The getgrent() has a separate definition, HAS_GETGRENT.
+ */
+#define HAS_GROUP
+#define HAS_GETGRENT /* fake */
+#define HAS_SETGRENT /* fake */
+#define HAS_ENDGRENT /* fake */
+
/* USEMYBINMODE
* This symbol, if defined, indicates that the program should
* use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
@@ -263,6 +280,16 @@ FILE *my_tmpfile (void);
char *my_tmpnam (char *);
int my_mkdir (__const__ char *, long);
int my_rmdir (__const__ char *);
+struct passwd *my_getpwent (void);
+void my_setpwent (void);
+void my_endpwent (void);
+
+struct group *getgrent (void);
+void setgrent (void);
+void endgrent (void);
+
+struct passwd *my_getpwuid (uid_t);
+struct passwd *my_getpwnam (__const__ char *);
#undef L_tmpnam
#define L_tmpnam MAXPATHLEN
@@ -287,6 +314,11 @@ int my_rmdir (__const__ char *);
#define flock my_flock
#define rmdir my_rmdir
#define mkdir my_mkdir
+#define setpwent my_setpwent
+#define getpwent my_getpwent
+#define endpwent my_endpwent
+#define getpwuid my_getpwuid
+#define getpwnam my_getpwnam
void *emx_calloc (size_t, size_t);
void emx_free (void *);