1 /* $NetBSD: pwgr.c,v 1.1 2012/03/17 16:33:14 jruoho Exp $ */
3 * Copyright (c) 2007 The NetBSD Foundation, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
29 * This file implements replacements for all user/group-related functions
30 * called by id(1). It provides fake but deterministic user and group
31 * information. The details are as such:
32 * User root, uid 0, primary group 0 (wheel).
33 * User test, uid 100, primary group 100 (users), secondary group 0 (wheel).
36 #include <sys/types.h>
47 struct passwd PwEntry;
58 if (getenv("LIBFAKE_EGID_ROOT") != NULL)
73 if (getenv("LIBFAKE_EUID_ROOT") != NULL)
82 strcpy(Login, "test");
89 struct group *g = &GrEntry;
91 memset(g, 0, sizeof(*g));
93 g->gr_name = __UNCONST("wheel");
95 } else if (gid == 100) {
96 g->gr_name = __UNCONST("users");
105 getgrouplist(const char *name, gid_t basegid, gid_t *groups, int *ngroups)
109 if (strcmp(name, "root") == 0) {
115 ret = (*ngroups >= cnt) ? 0 : -1;
117 } else if (strcmp(name, "test") == 0) {
128 ret = (*ngroups >= cnt) ? 0 : -1;
137 getgroups(int gidsetlen, gid_t *gidset)
150 getpwnam(const char *login)
152 struct passwd *p = &PwEntry;
154 memset(p, 0, sizeof(*p));
155 if (strcmp(login, "root") == 0) {
156 p->pw_name = __UNCONST("root");
159 } else if (strcmp(login, "test") == 0) {
160 p->pw_name = __UNCONST("test");
172 struct passwd *p = &PwEntry;
174 memset(p, 0, sizeof(*p));
176 p->pw_name = __UNCONST("root");
179 } else if (uid == 100) {
180 p->pw_name = __UNCONST("test");