#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "pwd.h"
#include "xalloc.h"
static char *lookup_env (char **);
static char *login_strings[] =
{
"LOGIN", "USER", "MAILNAME", "USERNAME", NULL
};
static char *group_strings[] =
{
"GROUP", NULL
};
static char *anonymous = "anonymous";
static char *login = NULL;
static char *group = NULL;
static struct passwd pw;
static struct group gr;
#define my_fake_uid ((const uid_t) 4545)
#define my_fake_gid my_fake_uid
struct passwd *
getpwuid (int uid)
{
pw.pw_name = getlogin ();
pw.pw_dir = woe32_home_dir ();
pw.pw_shell = woe32_shell ();
pw.pw_uid = 0;
return &pw;
}
struct passwd *
getpwnam (const char *name)
{
return NULL;
}
struct group *
getgrgid (int uid)
{
gr.gr_name = getgr_name ();
gr.gr_gid = 0;
return &gr;
}
struct group *
getgrnam (const char *name)
{
return NULL;
}
char *
getlogin (void)
{
if (!login)
login = lookup_env (login_strings);
if (!login)
login = woe32_getlogin ();
if (!login)
login = anonymous;
return login;
}
char *
getgr_name (void)
{
if (!group)
group = lookup_env (group_strings);
if (!group)
group = anonymous;
return group;
}
uid_t
getuid (void)
{
return my_fake_uid;
}
gid_t
getgid (void)
{
return my_fake_gid;
}
uid_t
geteuid (void)
{
return my_fake_uid;
}
gid_t
getegid (void)
{
return my_fake_gid;
}
struct passwd *
getpwent (void)
{
return NULL;
}
void
setpwent (void)
{
}
void
endpwent (void)
{
}
void
endgrent (void)
{
}
int
getgroups (int ngroups, gid_t *groups)
{
if (ngroups > 0)
*groups = my_fake_gid;
return 1;
}
static char *
lookup_env (char *table[])
{
char *ptr;
char *entry;
size_t len;
while (*table && !(ptr = getenv (*table++))) ;
if (!ptr) return NULL;
len = strcspn (ptr, " \n\t\n\r");
if (!(entry = xmalloc (len + 1)))
{
fprintf (stderr, "Out of memory.\nStop.");
exit (-1);
}
strncpy (entry, ptr, len);
entry[len] = '\0';
return entry;
}