2004-09-14 Loren Bandiera <lorenb@mmgsecurity.com>
authorJoshua Tauberer <joshua@mono-cvs.ximian.com>
Thu, 16 Sep 2004 11:09:02 +0000 (11:09 -0000)
committerJoshua Tauberer <joshua@mono-cvs.ximian.com>
Thu, 16 Sep 2004 11:09:02 +0000 (11:09 -0000)
* Syscall.cs: Added method for getpwnam which uses Passwd
struct.
* macros.c: Helper function for getpwnam
(In committing, Josh Tauberer also added getpwuid.)

svn path=/trunk/mono/; revision=33955

support/macros.c

index c763a7ca2f8719d442cda74e017ee846fedf4fa8..c64c7dae52832cde199f77566d25f3ac8696abeb 100644 (file)
@@ -95,3 +95,50 @@ char *helper_Mono_Posix_readdir(DIR *dir) {
        if (e == NULL) return NULL;
        return strdup (e->d_name);
 }
+
+int helper_Mono_Posix_getpwnamuid (int mode, char *in_name, int in_uid,
+       char **account,
+       char **password,
+       int *uid,
+       int *gid,
+       char **name,
+       char **home,
+       char **shell
+       ) {
+
+       struct passwd pw, *pwp;
+       char buf[4096];
+       int ret;
+
+       if (mode == 0)
+               ret = getpwnam_r (in_name, &pw, buf, 4096, &pwp);
+       else
+               ret = getpwuid_r (in_uid, &pw, buf, 4096, &pwp);
+
+       if (ret == 0 && pwp == NULL) {
+               // Don't know why this happens, but it does.
+               // ret == 0, errno == 0, but no record was found.
+               ret = ENOENT;
+       }
+
+       if (ret) {
+               *account = NULL; // prevent marshalling unset pointers
+               *password = NULL;
+               *uid = 0;
+               *gid = 0;
+               *name = NULL;
+               *home = NULL;
+               *shell = NULL;
+               return ret;
+       }
+
+       *account = pwp->pw_name;
+       *password = pwp->pw_passwd;
+       *uid = pwp->pw_uid;
+       *gid = pwp->pw_gid;
+       *name = pwp->pw_gecos;
+       *home = pwp->pw_dir;
+       *shell = pwp->pw_shell;
+
+       return 0;
+}