dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetC/libc/pwd .cvsignore,NONE,1.1 Makefile.


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetC/libc/pwd .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 endpwent.c,NONE,1.1 getpwent.c,NONE,1.1 getpwnam.c,NONE,1.1 getpwnam_r.c,NONE,1.1 getpwuid.c,NONE,1.1 getpwuid_r.c,NONE,1.1 pwent.c,NONE,1.1 pwent.h,NONE,1.1 pwpersist.c,NONE,1.1setpwent.c,NONE,1.1
Date: Mon, 23 Dec 2002 20:21:54 -0500

Update of /cvsroot/dotgnu-pnet/pnetC/libc/pwd
In directory subversions:/tmp/cvs-serv21238/libc/pwd

Added Files:
        .cvsignore Makefile.am endpwent.c getpwent.c getpwnam.c 
        getpwnam_r.c getpwuid.c getpwuid_r.c pwent.c pwent.h 
        pwpersist.c setpwent.c 
Log Message:


Add fake password file access routines (getpwnam, etc); stub out
pthread-style mutexes to assist with building thread-safety into
the rest of the library.


--- NEW FILE ---
Makefile
Makefile.in
.deps

--- NEW FILE ---

AUTOMAKE_OPTIONS = no-dependencies

noinst_LIBRARIES = libCPwd.a

libCPwd_a_SOURCES = endpwent.c \
                                        getpwent.c \
                                        getpwnam.c \
                                        getpwnam_r.c \
                                        getpwuid.c \
                                        getpwuid_r.c \
                                        pwent.c \
                                        pwent.h \
                                        pwpersist.c \
                                        setpwent.c

AM_CFLAGS = -I$(top_srcdir)/include \
                        -I$(top_srcdir)/libc/unistd \
                        -imacros $(top_srcdir)/include/libc-symbols.h

--- NEW FILE ---
/*
 * endpwent.c - End the password file walking routines.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pwd.h>
#include "pwent.h"

void
endpwent (void)
{
  /* Nothing to do here, because we aren't using external password files */
}

--- NEW FILE ---
/*
 * getpwent.c - Get the next entry during password file walking.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pwd.h>
#include "pwent.h"

struct passwd *
getpwent (void)
{
  if (__nextpwent (__pwinfo.pi_posn, &(__pwinfo.pi_pwd)))
    {
      ++(__pwinfo.pi_posn);
      return &(__pwinfo.pi_pwd);
    }
  else
    {
      return 0;
    }
}

--- NEW FILE ---
/*
 * getpwnam.c - Get a password file entry by name.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pwd.h>
#include <string.h>

struct passwd *
getpwnam (const char *name)
{
  struct passwd *pwd;
  if (!name)
    {
      return 0;
    }
  setpwent();
  while ((pwd = getpwent()) != 0)
    {
      if (!strcmp(pwd->pw_name, name))
        {
          break;
        }
    }
  endpwent();
  return pwd;
}

--- NEW FILE ---
/*
 * getpwnam_r.c - Get a password file entry by name, using re-entrant scanning.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pwd.h>
#include <string.h>
#include <errno.h>
#include "pwent.h"

int
getpwnam_r (const char *name,
            struct passwd * __restrict resultbuf,
            char * __restrict buffer, size_t buflen,
            struct passwd ** __restrict result)
{
  int posn;

  /* Validate the parameters */
  if (!resultbuf || !buffer || !result)
    {
      return ERANGE;
    }
  if (!name)
    {
      *result = 0;
      return 0;
    }

  /* Scan the password file until we find a match */
  posn = 0;
  while (__nextpwent (posn, resultbuf))
    {
      if (!strcmp (resultbuf->pw_name, name))
        {
          if (__persistpw (resultbuf, (char *)buffer, buflen))
            {
              *result = resultbuf;
              return 0;
            }
          else
            {
              return ERANGE;
            }
        }
      ++posn;
    }

  /* We were unable to find a match */
  *result = 0;
  return 0;
}

--- NEW FILE ---
/*
 * getpwuid.c - Get a password file entry by UID.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pwd.h>

struct passwd *
getpwuid (uid_t uid)
{
  struct passwd *pwd;
  setpwent();
  while ((pwd = getpwent()) != 0)
    {
      if (pwd->pw_uid == uid)
        {
          break;
        }
    }
  endpwent();
  return pwd;
}

--- NEW FILE ---
/*
 * getpwuid_r.c - Get a password file entry by UID, using re-entrant scanning.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pwd.h>
#include <errno.h>
#include "pwent.h"

int
getpwuid_r (uid_t uid,
            struct passwd * __restrict resultbuf,
            char * __restrict buffer, size_t buflen,
            struct passwd ** __restrict result)
{
  int posn;

  /* Validate the parameters */
  if (!resultbuf || !buffer || !result)
    {
      return ERANGE;
    }

  /* Scan the password file until we find a match */
  posn = 0;
  while (__nextpwent (posn, resultbuf))
    {
      if (resultbuf->pw_uid == uid)
        {
          if (__persistpw (resultbuf, (char *)buffer, buflen))
            {
              *result = resultbuf;
              return 0;
            }
          else
            {
              return ERANGE;
            }
        }
      ++posn;
    }

  /* We were unable to find a match */
  *result = 0;
  return 0;
}

--- NEW FILE ---
/*
 * pwent.c - Walk through the fake password entry list.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * This source file implements a fake password file consisting of
 * three entries: "root", "user", and "nobody".  The information
 * is sufficient to fool applications into believing that they have
 * a POSIX-like password file, without allowing the application
 * to circumvent system security and walk the real password file.
 */

#include <pwd.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include "pwent.h"
#include "fake-ids.h"

typedef __csharp__(System.String) String;
typedef __csharp__(System.Runtime.InteropServices.Marshal) Marshal;
typedef __csharp__(System.Environment) Environment;

static pthread_mutex_t currentUserMutex = PTHREAD_MUTEX_INITIALIZER;
static char *currentUser, *currentReal, *currentHome, *currentShell;

int
__nextpwent (int posn, struct passwd *pwd)
{
  switch (posn)
    {
      case 0:
        {
          /* Return information about "root" */
          pwd->pw_name   = FAKE_ROOT_USER;
          pwd->pw_passwd = "*";
          pwd->pw_uid    = FAKE_ROOT_UID;
          pwd->pw_gid    = FAKE_ROOT_GID;
          pwd->pw_gecos  = FAKE_ROOT_REAL;
          pwd->pw_dir    = FAKE_ROOT_HOME;
          pwd->pw_shell  = FAKE_SHELL;
        }
        return 1;

      case 1:
        {
          /* Return information about "user" */
          pthread_mutex_lock(&currentUserMutex);
          if(!currentUser)
            {
              currentUser = getlogin();
              if(!strcmp(currentUser, "nobody"))
                {
                  /* The runtime engine will not return user information */
                  currentUser = FAKE_CURRENT_USER;
                  currentReal = FAKE_CURRENT_REAL;
                  currentHome = FAKE_CURRENT_HOME;
                  currentShell = FAKE_SHELL;
                }
              else
                {
                  /* Fetch the rest of the user information */
                  String str;
                  currentReal = currentUser;
                  str = __invoke__ Environment.GetEnvironmentVariable("HOME");
                  currentHome = (char *)__invoke__
                        Marshal.StringToHGlobalAnsi(str);
                  if(!currentHome)
                    currentHome = FAKE_CURRENT_HOME;
                  str = __invoke__ Environment.GetEnvironmentVariable("SHELL");
                  currentShell = (char *)__invoke__
                        Marshal.StringToHGlobalAnsi(str);
                  if(!currentShell)
                    currentShell = FAKE_SHELL;
                }
            }
          pwd->pw_name   = currentUser;
          pwd->pw_passwd = "*";
          pwd->pw_uid    = FAKE_UID;
          pwd->pw_gid    = FAKE_GID;
          pwd->pw_gecos  = currentReal;
          pwd->pw_dir    = currentHome;
          pwd->pw_shell  = currentShell;
          pthread_mutex_unlock(&currentUserMutex);
        }
        return 1;

      case 2:
        {
          /* Return information about "nobody" */
          pwd->pw_name   = FAKE_NOBODY_USER;
          pwd->pw_passwd = "*";
          pwd->pw_uid    = FAKE_NOBODY_UID;
          pwd->pw_gid    = FAKE_NOBODY_GID;
          pwd->pw_gecos  = FAKE_NOBODY_REAL;
          pwd->pw_dir    = FAKE_NOBODY_HOME;
          pwd->pw_shell  = FAKE_SHELL;
        }
        return 1;
    }
  return 0;
}

--- NEW FILE ---
/*
 * pwent.h - Walk through the fake password entry list.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _PWENT_H
#define _PWENT_H

/* Information that is stored on the current thread for
   the "setpwent", "getpwent", and "endpwent" functions */
struct passwd_info
  {
    int           pi_posn;
    struct passwd pi_pwd;
  };

extern struct passwd_info __pwinfo;
extern int __nextpwent(int posn, struct passwd *pwd);
extern int __persistpw(struct passwd *pwd, char *buffer, size_t buflen);

#endif /* _PWENT_H */

--- NEW FILE ---
/*
 * pwpersist.c - Persist a password entry within a re-entrant return buffer.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pwd.h>
#include <string.h>
#include "pwent.h"

static char *
persistpw (char *value, char **buffer, size_t *buflen)
{
  size_t len = strlen (value);
  char *result;
  if (len >= *buflen)
    {
      return 0;
    }
  strcpy (*buffer, value);
  result = *buffer;
  *buffer += len + 1;
  *buflen -= len + 1;
  return result;
}

int
__persistpw (struct passwd *pwd, char *buffer, size_t buflen)
{
  if ((pwd->pw_name = persistpw (pwd->pw_name, &buffer, &buflen)) == 0)
    {
      return 0;
    }
  if ((pwd->pw_passwd = persistpw (pwd->pw_passwd, &buffer, &buflen)) == 0)
    {
      return 0;
    }
  if ((pwd->pw_gecos = persistpw (pwd->pw_gecos, &buffer, &buflen)) == 0)
    {
      return 0;
    }
  if ((pwd->pw_dir = persistpw (pwd->pw_dir, &buffer, &buflen)) == 0)
    {
      return 0;
    }
  if ((pwd->pw_shell = persistpw (pwd->pw_shell, &buffer, &buflen)) == 0)
    {
      return 0;
    }
  return 1;
}

--- NEW FILE ---
/*
 * setpwent.c - Reset the password file walking routines.
 *
 * This file is part of the Portable.NET C library.
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pwd.h>
#include "pwent.h"

struct passwd_info __pwinfo;

void
setpwent (void)
{
  __pwinfo.pi_posn = 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]