Simple R5 style pwd function implementation, courtesy of Eli Green.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7332 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
caa910df64
commit
86f34490f8
@ -1,62 +1,134 @@
|
||||
/*
|
||||
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
** Copyright 2004, Eli Green, eli@earthshattering.org. All rights reserved.
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
/*
|
||||
** All the functions in this file return the "baron" user.
|
||||
** baron is uid 0, gid 0. the pw_name field is set to either
|
||||
** "baron" or the value of the USER environment variable.
|
||||
**
|
||||
** This is done to be fully compatible with BeOS R5. /etc/passwd
|
||||
** is not consulted.
|
||||
**
|
||||
** One difference:
|
||||
** R5's getpwnam always returns NULL, but the implementation in this
|
||||
** file returns passwd struct for baron if the name argument is set to
|
||||
** the USER environment variable, or "baron" if USER is unset.
|
||||
**
|
||||
** The reentrant versions do not exist under BeOS R5.
|
||||
*/
|
||||
|
||||
|
||||
#include <pwd.h>
|
||||
#include <syscalls.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
// ToDo: implement pwd stuff for real!
|
||||
static char _pw_first = 1;
|
||||
static struct passwd _pw_struct;
|
||||
|
||||
|
||||
static char *
|
||||
get_user_name()
|
||||
{
|
||||
char *user = getenv("USER");
|
||||
if (user != NULL)
|
||||
return user;
|
||||
|
||||
return "baron";
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
getbaron(struct passwd *pw)
|
||||
{
|
||||
pw->pw_name = get_user_name();
|
||||
pw->pw_passwd = "";
|
||||
pw->pw_uid = 0;
|
||||
pw->pw_gid = 0;
|
||||
pw->pw_dir = "/boot/home";
|
||||
pw->pw_shell = "/bin/sh";
|
||||
pw->pw_gecos = "system";
|
||||
}
|
||||
|
||||
|
||||
struct passwd *
|
||||
getpwent(void)
|
||||
{
|
||||
return NULL;
|
||||
if (!_pw_first)
|
||||
return NULL;
|
||||
|
||||
_pw_first = 0;
|
||||
|
||||
getbaron(&_pw_struct);
|
||||
return &_pw_struct;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
setpwent(void)
|
||||
{
|
||||
_pw_first = 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
endpwent(void)
|
||||
{
|
||||
_pw_first = 1;
|
||||
}
|
||||
|
||||
|
||||
struct passwd *
|
||||
getpwnam(const char *name)
|
||||
{
|
||||
if (!strcmp(name, get_user_name())) {
|
||||
getbaron(&_pw_struct);
|
||||
return &_pw_struct;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
getpwnam_r(const char *name, struct passwd *passwd, char *buffer,
|
||||
size_t bufferSize, struct passwd **result)
|
||||
size_t bufferSize, struct passwd **_result)
|
||||
{
|
||||
return -1;
|
||||
if (strcmp(name, get_user_name())) {
|
||||
*_result = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
getbaron(passwd);
|
||||
*_result = passwd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct passwd *
|
||||
getpwuid(uid_t uid)
|
||||
{
|
||||
return NULL;
|
||||
if (uid != 0)
|
||||
return NULL;
|
||||
|
||||
getbaron(&_pw_struct);
|
||||
return &_pw_struct;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
getpwuid_r(uid_t uid, struct passwd *passwd, char *buffer,
|
||||
size_t bufferSize, struct passwd **result)
|
||||
size_t bufferSize, struct passwd **_result)
|
||||
{
|
||||
return -1;
|
||||
if (uid != 0) {
|
||||
*_result = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
getbaron(passwd);
|
||||
*_result = passwd;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user