Skip to content
Snippets Groups Projects
Commit c6399e55 authored by Nadav Har'El's avatar Nadav Har'El
Browse files

Stub getpwnam(), setuid() and setgid()

Implement getpwname(), setuid() and setgid() in the simplest way possible
considering that we don't support any userid except 0:

getpwname() returns user 0 for any username given to it.
setuid() and setgid() does nothing for uid or gid 0, otherwise fails.
Where would the caller get this !=0 id anyway?

Memcached needs these calls, because it wants to be clever and
warn the user against running it as root....
parent 1ca1bd43
No related branches found
No related tags found
No related merge requests found
......@@ -634,3 +634,4 @@ libc += sem.o
libc += pipe_buffer.o
libc += pipe.o
libc += af_local.o
libc += user.o
// OSV does not support different users, and getuid(), getgid() and friends
// always return 0.
// In this file we implement various user-handling functions in traditional
// libc, in the most sensible way we can given our limitations. In particular:
// 1. Every user name resolves to user id 0.
// 2. setuid() to any other user id but 0 fails on assertion
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
#include <debug.hh>
static char username[] = "osv";
static char password[] = "";
static char gecos[] = "OSV User";
static char homedir[] = "/";
static char shell[] = "?";
static struct passwd single_user = {
username, password, 0, 0, gecos, homedir, shell
};
struct passwd *getpwnam(const char *name)
{
return &single_user;
}
int setuid(uid_t uid)
{
assert(uid == 0);
return 0;
}
int setgid(gid_t gid)
{
assert(gid == 0);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment