2 nss sample code for extended winbindd functionality
4 Copyright (C) Andrew Tridgell (tridge@samba.org)
6 you are free to use this code in any way you see fit, including
7 without restriction, using this code in your own products. You do
8 not need to give any attribution.
14 cc -o wbtest wbtest.c nss_winbind.c -ldl
18 ./wbtest /lib/libnss_winbind.so
31 #include <sys/types.h>
33 #include "nss_winbind.h"
35 static int nss_test_users(struct nss_state *nss)
39 if (nss_setpwent(nss) != 0) {
44 /* loop over all users */
45 while ((nss_getpwent(nss, &pwd) == 0)) {
46 char *sid, **group_sids, *name2;
49 printf("User %s\n", pwd.pw_name);
50 if (nss_nametosid(nss, pwd.pw_name, &sid) != 0) {
54 printf("\tSID %s\n", sid);
56 if (nss_sidtoname(nss, sid, &name2) != 0) {
60 printf("\tSID->name %s\n", name2);
62 if (nss_getusersids(nss, sid, &group_sids) != 0) {
63 perror("getusersids");
67 printf("\tGroups:\n");
68 for (i=0; group_sids[i]; i++) {
69 printf("\t\t%s\n", group_sids[i]);
79 if (nss_endpwent(nss) != 0) {
89 main program. It lists all users, listing user SIDs for each user
91 int main(int argc, char *argv[])
94 const char *so_path = "/lib/libnss_winbind.so";
101 if (nss_open(&nss, so_path) != 0) {
106 ret = nss_test_users(&nss);