1 /* $NetBSD: pwgr.c,v 1.1 2007/11/19 14:17:45 jmmv 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>
46 struct passwd PwEntry
;
57 if (getenv("LIBFAKE_EGID_ROOT") != NULL
)
72 if (getenv("LIBFAKE_EUID_ROOT") != NULL
)
81 strcpy(Login
, "test");
88 struct group
*g
= &GrEntry
;
90 memset(g
, 0, sizeof(*g
));
94 } else if (gid
== 100) {
104 getgrouplist(const char *name
, int basegid
, int *groups
, int *ngroups
)
108 if (name
== "root") {
114 ret
= (*ngroups
>= cnt
) ? 0 : -1;
116 } else if (name
== "test") {
127 ret
= (*ngroups
>= cnt
) ? 0 : -1;
136 getgroups(int gidsetlen
, gid_t
*gidset
)
149 getpwnam(const char *login
)
151 struct passwd
*p
= &PwEntry
;
153 memset(p
, 0, sizeof(*p
));
154 if (strcmp(login
, "root") == 0) {
158 } else if (strcmp(login
, "test") == 0) {
171 struct passwd
*p
= &PwEntry
;
173 memset(p
, 0, sizeof(*p
));
178 } else if (uid
== 100) {