From: Ilya Zakharevich Date: Thu, 21 Jun 2001 06:23:56 +0000 (-0400) Subject: [PATCH 5.6.1] OS2 getpw*, getgr* X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f72c975a9a4415edd33b16ea436dde0fc40a3a9d;p=p5sagit%2Fp5-mst-13.2.git [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 Date: Thu, 21 Jun 2001 06:32:21 -0400 Message-ID: <20010621063221.A8823@math.ohio-state.edu> p4raw-id: //depot/perl@10768 --- diff --git a/lib/File/Glob/basic.t b/lib/File/Glob/basic.t index ef9dd96..3c931e7 100755 --- a/lib/File/Glob/basic.t +++ b/lib/File/Glob/basic.t @@ -44,7 +44,7 @@ print "ok 2\n"; # look up the user's home directory # should return a list with one item, and not set ERROR -if ($^O ne 'MSWin32' && $^O ne 'NetWare' && $^O ne 'VMS') { +if ($^O ne 'MSWin32' && $^O ne 'NetWare' && $^O ne 'VMS' && $^O ne 'os2') { eval { ($name, $home) = (getpwuid($>))[0,7]; 1; diff --git a/makedef.pl b/makedef.pl index 5d9b7a1..46ddd14 100644 --- a/makedef.pl +++ b/makedef.pl @@ -304,6 +304,14 @@ elsif ($PLATFORM eq 'os2') { my_flock my_rmdir my_mkdir + my_getpwuid + my_getpwnam + my_getpwent + my_setpwent + my_endpwent + setgrent + endgrent + getgrent malloc_mutex threads_mutex nthreads diff --git a/os2/os2.c b/os2/os2.c index a2b196e..582311a 100644 --- a/os2/os2.c +++ b/os2/os2.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #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 30e67ca..e6e8b5f 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 *);