1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/* pwd.c - Try to approximate UN*X's getuser...() functions under MS-DOS.
Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program 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 General Public License for more details. */
/* This 'implementation' is conjectured from the use of this functions in
the RCS and BASH distributions. Of course these functions don't do too
much useful things under MS-DOS, but using them avoids many "#ifdef
MSDOS" in ported UN*X code ... */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
static char *lookup_env (char **);
/* where people might scribble their name into the environment ... */
static char *login_strings[] =
{
"LOGIN", "USER", "MAILNAME", (char *) 0
};
static char *group_strings[] =
{
"GROUP", (char *) 0
};
static char *anonymous = "anonymous"; /* if all else fails ... */
static char *home_dir = "."; /* we feel (no|every)where at home */
static char *login_shell = "not cmd.exe!";
static char *login = (char *) 0;/* cache the names here */
static char *group = (char *) 0;
static struct passwd pw; /* should we return a malloc()'d structure */
static struct group gr; /* instead of pointers to static structures? */
/* return something like a username in a (butchered!) passwd structure. */
struct passwd *
getpwuid (int uid)
{
pw.pw_name = getlogin ();
pw.pw_dir = home_dir;
pw.pw_shell = login_shell;
pw.pw_uid = 0;
return &pw;
}
struct passwd *
getpwnam (char *name)
{
return (struct passwd *) 0;
}
/* return something like a groupname in a (butchered!) group structure. */
struct group *
getgrgid (int uid)
{
gr.gr_name = getgr_name ();
gr.gr_gid = 0;
return &gr;
}
struct group *
getgrnam (char *name)
{
return (struct group *) 0;
}
/* return something like a username. */
char *
getlogin ()
{
if (!login) /* have we been called before? */
login = lookup_env (login_strings);
if (!login) /* have we been successful? */
login = anonymous;
return login;
}
/* return something like a group. */
char *
getgr_name ()
{
if (!group) /* have we been called before? */
group = lookup_env (group_strings);
if (!group) /* have we been successful? */
group = anonymous;
return group;
}
/* return something like a uid. */
int
getuid ()
{
return 0; /* every user is a super user ... */
}
int
getgid ()
{
return 0;
}
int
geteuid ()
{
return 0;
}
int
getegid ()
{
return 0;
}
struct passwd *
getpwent ()
{
return (struct passwd *) 0;
}
void
setpwent ()
{
}
void
endpwent ()
{
}
void
endgrent ()
{
}
/* return groups. */
int
getgroups (int ngroups, int *groups)
{
*groups = 0;
return 1;
}
/* lookup environment. */
static char *
lookup_env (char *table[])
{
char *ptr;
char *entry;
size_t len;
while (*table && !(ptr = getenv (*table++))) ; /* scan table */
if (!ptr)
return (char *) 0;
len = strcspn (ptr, " \n\t\n\r"); /* any WS? */
if (!(entry = malloc (len + 1)))
{
fprintf (stderr, "Out of memory.\nStop.");
exit (-1);
}
strncpy (entry, ptr, len);
entry[len] = '\0';
return entry;
}
/*
* Local Variables:
* mode:C
* ChangeLog:ChangeLog
* compile-command:make
* End:
*/
|