diff --git a/src/kernel/libroot/posix/pwd.c b/src/kernel/libroot/posix/pwd.c index d5e6ab43f4..019fa91c46 100644 --- a/src/kernel/libroot/posix/pwd.c +++ b/src/kernel/libroot/posix/pwd.c @@ -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 -#include +#include #include -#include -// 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; }