2 * Copyright (C) 2002-2004 Net Integration Technologies, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 extern "C" enum nss_status
_nss_uniconf_initgroups_dyn(
27 char *user
, gid_t group
, long int *start
, long int *size
,
28 gid_t
**groupsp
, long int limit
, int *errnop
);
30 void dump_pw(WvLog
&log
, struct passwd
*pw
)
33 log(WvLog::Error
, "%s\n", strerror(errno
));
36 log(WvLog::Info
, "%s - %s - %s - id:%s/%s - %s - %s\n",
37 pw
->pw_name
, pw
->pw_gecos
, pw
->pw_passwd
,
38 pw
->pw_uid
, pw
->pw_gid
,
39 pw
->pw_dir
, pw
->pw_shell
);
43 void dump_gr(WvLog
&log
, struct group
*gr
)
46 log(WvLog::Error
, "%s\n", strerror(errno
));
49 log(WvLog::Info
, "%s - %s - id:%s - members: ",
50 gr
->gr_name
, gr
->gr_passwd
,
52 char **members
= gr
->gr_mem
;
53 while (members
&& *members
)
55 log(WvLog::Info
, "%s ", *members
);
58 log(WvLog::Info
, "\n");
62 void dump_initgr(WvLog
&log
, gid_t
*groups
, long int len
)
65 log(WvLog::Error
, "%s\n", strerror(errno
));
67 for (int i
= 0; i
< len
; i
++)
68 log("User is in group %s.\n", groups
[i
]);
71 int main(int argc
, char **argv
)
73 // wvcrash_setup(argv[0]);
75 WvLog
test("nsstest", WvLog::Info
);
77 WvLogConsole
csl(1, WvLog::Debug5
);
79 // This is a localuser
80 dump_pw(test
, getpwnam("apenwarr"));
81 dump_pw(test
, getpwuid(2002));
83 dump_pw(test
, getpwnam("testuser"));
84 dump_pw(test
, getpwuid(5008));
86 dump_pw(test
, getpwnam("fudge"));
87 dump_pw(test
, getpwuid(12002));
89 dump_gr(test
, getgrnam("wonk"));
90 dump_pw(test
, getpwnam("wonk"));
91 dump_gr(test
, getgrgid(500));
93 // Exists as a user, but not as a team..
94 dump_gr(test
, getgrnam("fred"));
96 // Exists as a team, but not as a user...
97 dump_gr(test
, getgrnam("flunky"));
99 // Exists as a uid/gid, but not as a group...
100 dump_gr(test
, getgrgid(34356));
102 // Exists as a group, but not as a number...
103 dump_gr(test
, getgrnam("flunky"));
105 gid_t
*groups
= (gid_t
*)malloc(16 * sizeof(gid_t
));
112 char *user
= strdup("wonk");
114 ret
= _nss_uniconf_initgroups_dyn(
115 user
, 500, &start
, &size
, &groups
, limit
, &errnop
);
116 if (NSS_STATUS_SUCCESS
== ret
)
117 dump_initgr(test
, groups
, start
);