1 /* list users for a particular nss module
10 typedef enum nss_status NSS_STATUS;
12 static char *nss_name;
14 static NSS_STATUS last_error;
15 static int total_errors;
17 static void *find_fn(const char *name)
23 asprintf(&s, "_nss_%s_%s", nss_name, name);
24 asprintf(&so_path, "/lib/libnss_%s.so.2", nss_name);
27 h = dlopen(so_path, RTLD_LAZY);
30 printf("Can't open shared library %s\n", so_path);
35 printf("Can't find function %s\n", s);
43 static void report_nss_error(const char *who, NSS_STATUS status)
47 printf("ERROR %s: NSS_STATUS=%d %d (nss_errno=%d)\n",
48 who, status, NSS_STATUS_SUCCESS, nss_errno);
51 static struct passwd *nss_getpwent(void)
53 NSS_STATUS (*_nss_getpwent_r)(struct passwd *, char *,
54 size_t , int *) = find_fn("getpwent_r");
55 static struct passwd pwd;
56 static char buf[1000];
59 status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno);
60 if (status == NSS_STATUS_NOTFOUND) {
63 if (status != NSS_STATUS_SUCCESS) {
64 report_nss_error("getpwent", status);
70 static void nss_setpwent(void)
72 NSS_STATUS (*_nss_setpwent)(void) = find_fn("setpwent");
74 status = _nss_setpwent();
75 if (status != NSS_STATUS_SUCCESS) {
76 report_nss_error("setpwent", status);
80 static void nss_endpwent(void)
82 NSS_STATUS (*_nss_endpwent)(void) = find_fn("endpwent");
84 status = _nss_endpwent();
85 if (status != NSS_STATUS_SUCCESS) {
86 report_nss_error("endpwent", status);
90 static void list_users(void)
95 /* loop over all users */
96 while ((pwd = nss_getpwent())) {
97 printf("%s\n", pwd->pw_name);
102 static void usage(void)
104 printf("nsslist <nsstype>\n");
107 int main(int argc, char *argv[])