diff options
author | David Yuste <dyuste@gcc.gnu.org> | 2011-02-25 10:55:56 +0000 |
---|---|---|
committer | David Yuste <dyuste@gcc.gnu.org> | 2011-02-25 10:55:56 +0000 |
commit | ccdc60d209a9dbcef627d8e287c50f27d013ecf1 (patch) | |
tree | 994a7a7d70c357bad6d2e9a7c0277c2a5c89c814 | |
parent | e6db3a189c8f65d1352782c38bef3a5803f1b5b8 (diff) |
provided POSIX users abstraction in libstd (new functions: getuid, geteuid, getpwuid, getpwnam)
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/st/cli-be@170491 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libstd/include/Makefile.am | 1 | ||||
-rw-r--r-- | libstd/include/Makefile.in | 1 | ||||
-rw-r--r-- | libstd/include/__host.h | 10 | ||||
-rw-r--r-- | libstd/include/pwd.h | 53 | ||||
-rw-r--r-- | libstd/include/unistd.h | 4 | ||||
-rw-r--r-- | libstd/src/MSCorelibWrapper.cs | 132 | ||||
-rw-r--r-- | libstd/src/Makefile.am | 1 | ||||
-rw-r--r-- | libstd/src/Makefile.in | 28 | ||||
-rw-r--r-- | libstd/src/__host.c | 50 | ||||
-rw-r--r-- | libstd/src/_users.c | 81 | ||||
-rw-r--r-- | libstd/src_opt/MSCorelibWrapper.cs | 14 |
11 files changed, 371 insertions, 4 deletions
diff --git a/libstd/include/Makefile.am b/libstd/include/Makefile.am index e7bfe2f050d..3e18da94c1e 100644 --- a/libstd/include/Makefile.am +++ b/libstd/include/Makefile.am @@ -19,6 +19,7 @@ include_HEADERS = \ locale.h \ malloc.h \ math.h \ + pwd.h \ setjmp.h \ signal.h \ stdbool.h \ diff --git a/libstd/include/Makefile.in b/libstd/include/Makefile.in index 21d36427266..3a5d8e8f1b3 100644 --- a/libstd/include/Makefile.in +++ b/libstd/include/Makefile.in @@ -200,6 +200,7 @@ include_HEADERS = \ locale.h \ malloc.h \ math.h \ + pwd.h \ setjmp.h \ signal.h \ stdbool.h \ diff --git a/libstd/include/__host.h b/libstd/include/__host.h index 45967ca0e26..d618df8c145 100644 --- a/libstd/include/__host.h +++ b/libstd/include/__host.h @@ -108,6 +108,16 @@ LIBSTD_HPROTO(void, gettimeofday, void *tv_sec, void *tv_usec); /* Getting process time informations */ LIBSTD_HPROTO(int, gettimes, unsigned long *clks, unsigned long * tms_utime, unsigned long *tms_stime, unsigned long *tms_cutime, unsigned long *tms_cstime); + +/* User information*/ +LIBSTD_HPROTO(unsigned int, getuid, void); +LIBSTD_HPROTO(unsigned int, geteuid, void); + +LIBSTD_HPROTO(int, getpwuid, unsigned int uid, char **name, char **passwd, + unsigned int *gid, char **gecos, char **dir, char **shell); +LIBSTD_HPROTO(int, getpwnam, char *name, char **passwd, unsigned int *uid, + unsigned int *gid, char **gecos, char **dir, char **shell); + /* Floating point classification */ LIBSTD_HPROTO(int, fpclassify, double p0); diff --git a/libstd/include/pwd.h b/libstd/include/pwd.h new file mode 100644 index 00000000000..d253f5ca0f5 --- /dev/null +++ b/libstd/include/pwd.h @@ -0,0 +1,53 @@ +/* + + Copyright (C) 2007-2008 Free Software Foundation, Inc. + Contributed by STMicroelectronics + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING. If not, write to the Free +Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. */ + +#ifndef __PWD_H +#define __PWD_H + +#include <__cdefs.h> + + +#include <sys/types.h> +#include <stddef.h> + +__BEGIN_EXTERN_C + +/* The passwd structure. */ +struct passwd +{ + char *pw_name; /* Username. */ + char *pw_passwd; /* Password. */ + uid_t pw_uid; /* User ID. */ + gid_t pw_gid; /* Group ID. */ + char *pw_gecos; /* Real name. */ + char *pw_dir; /* Home directory. */ + char *pw_shell; /* Shell program. */ +}; + +/* Implemented in src/_users.c */ +LIBSTD_LPROTO(struct passwd *, getpwuid, uid_t); +LIBSTD_LPROTO(struct passwd *, getpwnam, char *); + +__END_EXTERN_C + +#endif /*__PWD_H*/ + diff --git a/libstd/include/unistd.h b/libstd/include/unistd.h index 64aa72916ba..04161268333 100644 --- a/libstd/include/unistd.h +++ b/libstd/include/unistd.h @@ -49,6 +49,10 @@ LIBSTD_LPROTO(long, sysconf, int); LIBSTD_LPROTO(int, isatty, int); +/* Implemented in src/_users.c */ +LIBSTD_LPROTO(uid_t, getuid, void); +LIBSTD_LPROTO(uid_t, geteuid, void); + __END_EXTERN_C #endif /*__UNISTD_H__*/ diff --git a/libstd/src/MSCorelibWrapper.cs b/libstd/src/MSCorelibWrapper.cs index 7b5677c0d8b..7227fd44e67 100644 --- a/libstd/src/MSCorelibWrapper.cs +++ b/libstd/src/MSCorelibWrapper.cs @@ -28,6 +28,7 @@ using System.Security.Principal; using System.Security.AccessControl; using System.Runtime.InteropServices; using System.Diagnostics; +using System.Collections; public class MSCorelibWrapper { @@ -120,6 +121,9 @@ public class MSCorelibWrapper initial_ticks = DateTime.UtcNow.Ticks; // Init the internal buffer array buffer = new byte[buffer_size]; + + /* Matching (pseudo)POSIX <--> .NET users */ + InitUsers (); } private static int allocateHandle(Stream stream) @@ -774,6 +778,134 @@ public class MSCorelibWrapper } } + /***************** User information *******************/ + /* This provides an abstraction of POSIX users. Values for uid are + coherent ONLY inside this library, and don't match the underlying + system ones -in case the that there is a POSIX system-. + + UID are generated (in a random way) from user strings. Thus, + a call recieving an UID as argument will only accept the + user if it has been generated inside the library; via: + - getuid(), geteuid() + - getpwnam() + - stat() -users not yet implemented here- + */ + + class UserPair { + public UserPair (String name, uint uid) { + this.name = name; + this.uid = uid; + } + + public String name; + public uint uid; + }; + + private static ArrayList users_set; + private static uint users_count; + + private static void InitUsers () + { + users_set = new ArrayList(8); + users_count = 0; + } + + private static uint GetUidFromName (String name) + { + uint uid = 0; + + foreach (UserPair user in users_set) + { + if (user.name == name) + uid = user.uid; + } + + if (uid != 0) + return uid; + + /* here is where users join users_set */ + uid = ++users_count; + users_set.Add (new UserPair (name, uid)); + return uid; + } + + private static String GetNameFromUid (uint uid) + { + foreach (UserPair user in users_set) + { + if (user.uid == uid) + return user.name; + } + + /* may be an UID external to this implementation, not supported */ + throw new Exception("the specified UID does not exist"); + } + + /* POSIX user-related functions */ + public static uint getuid () + { + String name = WindowsIdentity.GetCurrent().Name; + + return GetUidFromName (name); + } + + public static uint geteuid () + { + /* Are there "effective users" in .NET? Is that impersonation? */ + return getuid (); + } + + unsafe public static int getpwuid (uint uid, sbyte** name, sbyte** passwd, + uint* gid, sbyte** gecos, sbyte** dir, sbyte** shell) + { + String str_name; + + try { + str_name = GetNameFromUid (uid); + } catch (Exception) { + my_errno = __LIBSTD_ENOENT; + return -1; + } + + *name = (sbyte*) Marshal.StringToHGlobalAnsi(str_name).ToPointer(); + + return getpw_base (str_name, passwd, gid, gecos, dir, shell); + } + + unsafe public static int getpwnam (sbyte* name, sbyte** passwd, uint* uid, + uint* gid, sbyte** gecos, sbyte** dir, sbyte** shell) + { + String str_name = Marshal.PtrToStringAnsi(new IntPtr(name)); + + *uid = GetUidFromName (str_name); + + return getpw_base (str_name, passwd, gid, gecos, dir, shell); + } + + unsafe private static int getpw_base (String name, sbyte** passwd, uint* gid, + sbyte** gecos, sbyte** dir, sbyte** shell) + { + /*home_path = (Environment.OSVersion.Platform == PlatformID.Unix || + Environment.OSVersion.Platform == PlatformID.MacOSX) + ? Environment.GetEnvironmentVariable("HOME") + : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");*/ + + *passwd = (sbyte*) new IntPtr(0); + *gid = 0; + /* TODO: may be we can find the actual name */ + *gecos = (sbyte*) Marshal.StringToHGlobalAnsi(name).ToPointer(); + if (name == WindowsIdentity.GetCurrent().Name) + { + String home_path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); + *dir = (sbyte*) Marshal.StringToHGlobalAnsi(home_path).ToPointer(); + } + else + *dir = (sbyte*) new IntPtr(0); + *shell = (sbyte*) new IntPtr(0); + + return 0; + } + public static double dbl_epsilon() { return System.Double.Epsilon; diff --git a/libstd/src/Makefile.am b/libstd/src/Makefile.am index 5b69b567968..756afc81ed1 100644 --- a/libstd/src/Makefile.am +++ b/libstd/src/Makefile.am @@ -10,6 +10,7 @@ SRC = _Exit.c \ __io_perm.c \ __libinfo.c \ __libstd_initfini.c \ + _users.c \ abort.c \ abs.c \ asctime.c \ diff --git a/libstd/src/Makefile.in b/libstd/src/Makefile.in index 49dbf41b804..3b22605c0a0 100644 --- a/libstd/src/Makefile.in +++ b/libstd/src/Makefile.in @@ -64,7 +64,7 @@ am__objects_1 = libstd_la-_Exit.lo libstd_la-__io_device.lo \ libstd_la-__io_fopen.lo libstd_la-__io_fout.lo \ libstd_la-__io_fread.lo libstd_la-__io_ftable.lo \ libstd_la-__io_perm.lo libstd_la-__libinfo.lo \ - libstd_la-__libstd_initfini.lo libstd_la-abort.lo \ + libstd_la-__libstd_initfini.lo libstd_la-_users.lo libstd_la-abort.lo \ libstd_la-abs.lo libstd_la-asctime.lo libstd_la-assert.lo \ libstd_la-basename.lo libstd_la-bsearch.lo libstd_la-calloc.lo \ libstd_la-clearerr.lo libstd_la-close.lo libstd_la-creat.lo \ @@ -120,7 +120,7 @@ am__objects_2 = libstd_dll-_Exit.$(OBJEXT) \ libstd_dll-__io_fread.$(OBJEXT) \ libstd_dll-__io_ftable.$(OBJEXT) \ libstd_dll-__io_perm.$(OBJEXT) libstd_dll-__libinfo.$(OBJEXT) \ - libstd_dll-__libstd_initfini.$(OBJEXT) \ + libstd_dll-__libstd_initfini.$(OBJEXT) libstd_dll-_users.$(OBJEXT) \ libstd_dll-abort.$(OBJEXT) libstd_dll-abs.$(OBJEXT) \ libstd_dll-asctime.$(OBJEXT) libstd_dll-assert.$(OBJEXT) \ libstd_dll-basename.$(OBJEXT) libstd_dll-bsearch.$(OBJEXT) \ @@ -327,6 +327,7 @@ SRC = _Exit.c \ __io_perm.c \ __libinfo.c \ __libstd_initfini.c \ + _users.c \ abort.c \ abs.c \ asctime.c \ @@ -549,6 +550,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_dll-__io_perm.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_dll-__libinfo.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_dll-__libstd_initfini.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_dll-_users.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_dll-abort.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_dll-abs.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_dll-asctime.Po@am__quote@ @@ -678,6 +680,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_la-__io_perm.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_la-__libinfo.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_la-__libstd_initfini.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_la-_users.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_la-abort.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_la-abs.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstd_la-asctime.Plo@am__quote@ @@ -895,6 +898,13 @@ libstd_la-__libstd_initfini.lo: __libstd_initfini.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_la_CFLAGS) $(CFLAGS) -c -o libstd_la-__libstd_initfini.lo `test -f '__libstd_initfini.c' || echo '$(srcdir)/'`__libstd_initfini.c +libstd_la-_users.lo: _users.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_la_CFLAGS) $(CFLAGS) -MT libstd_la-_users.lo -MD -MP -MF "$(DEPDIR)/libstd_la-_users.Tpo" -c -o libstd_la-_users.lo `test -f '_users.c' || echo '$(srcdir)/'`_users.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libstd_la-_users.Tpo" "$(DEPDIR)/libstd_la-_users.Plo"; else rm -f "$(DEPDIR)/libstd_la-_users.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='_users.c' object='libstd_la-_users.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_la_CFLAGS) $(CFLAGS) -c -o libstd_la-_users.lo `test -f '_users.c' || echo '$(srcdir)/'`_users.c + libstd_la-abort.lo: abort.c @am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_la_CFLAGS) $(CFLAGS) -MT libstd_la-abort.lo -MD -MP -MF "$(DEPDIR)/libstd_la-abort.Tpo" -c -o libstd_la-abort.lo `test -f 'abort.c' || echo '$(srcdir)/'`abort.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libstd_la-abort.Tpo" "$(DEPDIR)/libstd_la-abort.Plo"; else rm -f "$(DEPDIR)/libstd_la-abort.Tpo"; exit 1; fi @@ -1875,6 +1885,20 @@ libstd_dll-__libstd_initfini.obj: __libstd_initfini.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_dll_CFLAGS) $(CFLAGS) -c -o libstd_dll-__libstd_initfini.obj `if test -f '__libstd_initfini.c'; then $(CYGPATH_W) '__libstd_initfini.c'; else $(CYGPATH_W) '$(srcdir)/__libstd_initfini.c'; fi` +libstd_dll-_users.o: _users.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_dll_CFLAGS) $(CFLAGS) -MT libstd_dll-_users.o -MD -MP -MF "$(DEPDIR)/libstd_dll-_users.Tpo" -c -o libstd_dll-_users.o `test -f '_users.c' || echo '$(srcdir)/'`_users.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libstd_dll-_users.Tpo" "$(DEPDIR)/libstd_dll-_users.Po"; else rm -f "$(DEPDIR)/libstd_dll-_users.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='_users.c' object='libstd_dll-_users.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_dll_CFLAGS) $(CFLAGS) -c -o libstd_dll-_users.o `test -f '_users.c' || echo '$(srcdir)/'`_users.c + +libstd_dll-_users.obj: _users.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_dll_CFLAGS) $(CFLAGS) -MT libstd_dll-_users.obj -MD -MP -MF "$(DEPDIR)/libstd_dll-_users.Tpo" -c -o libstd_dll-_users.obj `if test -f '_users.c'; then $(CYGPATH_W) '_users.c'; else $(CYGPATH_W) '$(srcdir)/_users.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libstd_dll-_users.Tpo" "$(DEPDIR)/libstd_dll-_users.Po"; else rm -f "$(DEPDIR)/libstd_dll-_users.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='_users.c' object='libstd_dll-_users.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_dll_CFLAGS) $(CFLAGS) -c -o libstd_dll-_users.obj `if test -f '_users.c'; then $(CYGPATH_W) '_users.c'; else $(CYGPATH_W) '$(srcdir)/_users.c'; fi` + libstd_dll-abort.o: abort.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libstd_dll_CFLAGS) $(CFLAGS) -MT libstd_dll-abort.o -MD -MP -MF "$(DEPDIR)/libstd_dll-abort.Tpo" -c -o libstd_dll-abort.o `test -f 'abort.c' || echo '$(srcdir)/'`abort.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libstd_dll-abort.Tpo" "$(DEPDIR)/libstd_dll-abort.Po"; else rm -f "$(DEPDIR)/libstd_dll-abort.Tpo"; exit 1; fi diff --git a/libstd/src/__host.c b/libstd/src/__host.c index d0428b0fbca..a5adde2cdcc 100644 --- a/libstd/src/__host.c +++ b/libstd/src/__host.c @@ -50,8 +50,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA #include <sys/stat.h> #include <sys/time.h> #include <sys/times.h> - - +#include <pwd.h> static int my_errno = 0; @@ -444,6 +443,53 @@ LIBSTD_HPROTO_IMPL(long, getsysconf, int name) return sysconf(name); } +/* user information */ +LIBSTD_HPROTO_IMPL(unsigned int, getuid, void) +{ + return getuid (); +} + +LIBSTD_HPROTO_IMPL(unsigned int, geteuid, void) +{ + return geteuid (); +} + +LIBSTD_HPROTO_IMPL(int, getpwuid, unsigned int uid, char **name, char **passwd, + unsigned int *gid, char **gecos, char **dir, char **shell) +{ + struct passwd * pwd = getpwuid(uid); + + if (!pwd) + return -1; + + *name = pwd->pw_name; + *passwd = pwd->pw_passwd; + *gid = pwd->pw_gid; + *gecos = pwd->pw_gecos; + *dir = pwd->pw_dir; + *shell = pwd->pw_shell; + + return 0; +} + +LIBSTD_HPROTO_IMPL(int, getpwnam, char *name, char **passwd, + unsigned int *uid, unsigned int *gid, char **gecos, char **dir, char **shell) +{ + struct passwd * pwd = getpwnam(name); + + if (!pwd) + return -1; + + *passwd = pwd->pw_passwd; + *uid = pwd->pw_uid; + *gid = pwd->pw_gid; + *gecos = pwd->pw_gecos; + *dir = pwd->pw_dir; + *shell = pwd->pw_shell; + + return 0; +} + LIBSTD_HPROTO_IMPL(int, fpclassify, double p0) { return fpclassify(p0); diff --git a/libstd/src/_users.c b/libstd/src/_users.c new file mode 100644 index 00000000000..19eba8aaa74 --- /dev/null +++ b/libstd/src/_users.c @@ -0,0 +1,81 @@ +/* + + Copyright (C) 2007-2008 Free Software Foundation, Inc. + Contributed by STMicroelectronics + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING. If not, write to the Free +Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. */ + +/* If we are compiling this, we are sure this is to build C-runtime*/ +#define __LIBSTD_CRT_BUILD + +#include <__cdefs.h> + +#include "__host.h" + +#include <unistd.h> +#include <pwd.h> + +/* according to man getpwd, it is safe to reuse this structure */ +static struct passwd pwdbf; + + +LIBSTD_LPROTO_IMPL(uid_t, getuid, void) +{ + return LIBSTD_HNAME(getuid)(); +} + +LIBSTD_LPROTO_IMPL(uid_t, geteuid, void) +{ + return LIBSTD_HNAME(geteuid)(); +} + +LIBSTD_LPROTO_IMPL(struct passwd *, getpwuid, uid_t uid) +{ + if (LIBSTD_HNAME(getpwuid)(uid, + &(pwdbf.pw_name), + &(pwdbf.pw_passwd), + &(pwdbf.pw_gid), + &(pwdbf.pw_gecos), + &(pwdbf.pw_dir), + &(pwdbf.pw_shell)) == -1) + return NULL; + + pwdbf.pw_uid = uid; + + return &pwdbf; +} + +LIBSTD_LPROTO_IMPL(struct passwd *, getpwnam, char * uname) +{ + if (LIBSTD_HNAME(getpwnam)(uname, + &(pwdbf.pw_passwd), + &(pwdbf.pw_uid), + &(pwdbf.pw_gid), + &(pwdbf.pw_gecos), + &(pwdbf.pw_dir), + &(pwdbf.pw_shell)) == -1) + return NULL; + + pwdbf.pw_name = uname; + + return &pwdbf; +} + + + + diff --git a/libstd/src_opt/MSCorelibWrapper.cs b/libstd/src_opt/MSCorelibWrapper.cs index 17119d956fd..956967d4dda 100644 --- a/libstd/src_opt/MSCorelibWrapper.cs +++ b/libstd/src_opt/MSCorelibWrapper.cs @@ -99,6 +99,20 @@ public class MSCorelibWrapper [DllImport("MSCorelibWrapper_support.so", EntryPoint="__host__errno")] unsafe public static extern int* errno(); + + [DllImport("MSCorelibWrapper_support.so", EntryPoint="__host__getuid")] + public static uint getuid (); + + [DllImport("MSCorelibWrapper_support.so", EntryPoint="__host__geteuid")] + public static uint geteuid (); + + [DllImport("MSCorelibWrapper_support.so", EntryPoint="__host__getpwuid")] + unsafe public static int getpwuid (uint uid, sbyte** name, sbyte** passwd, + uint* gid, sbyte** gecos, sbyte** dir, sbyte** shell); + + [DllImport("MSCorelibWrapper_support.so", EntryPoint="__host__getpwnam")] + unsafe public static int getpwnam (sbyte* name, sbyte** passwd, uint* uid, + uint* gid, sbyte** gecos, sbyte** dir, sbyte** shell); [DllImport("MSCorelibWrapper_support.so", EntryPoint="__host__dbl_epsilon")] unsafe public static extern double dbl_epsilon(); |