| 1 | /*
|
|---|
| 2 | nss sample code for extended winbindd functionality
|
|---|
| 3 |
|
|---|
| 4 | Copyright (C) Andrew Tridgell ([email protected])
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /*
|
|---|
| 12 | compile like this:
|
|---|
| 13 |
|
|---|
| 14 | cc -o wbtest wbtest.c nss_winbind.c -ldl
|
|---|
| 15 |
|
|---|
| 16 | and run like this:
|
|---|
| 17 |
|
|---|
| 18 | ./wbtest /lib/libnss_winbind.so
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #define _GNU_SOURCE
|
|---|
| 22 |
|
|---|
| 23 | #include <stdio.h>
|
|---|
| 24 | #include <stdlib.h>
|
|---|
| 25 | #include <nss.h>
|
|---|
| 26 | #include <dlfcn.h>
|
|---|
| 27 | #include <pwd.h>
|
|---|
| 28 | #include <grp.h>
|
|---|
| 29 | #include <errno.h>
|
|---|
| 30 | #include <string.h>
|
|---|
| 31 | #include <sys/types.h>
|
|---|
| 32 |
|
|---|
| 33 | #include "nss_winbind.h"
|
|---|
| 34 |
|
|---|
| 35 | static int nss_test_users(struct nss_state *nss)
|
|---|
| 36 | {
|
|---|
| 37 | struct passwd pwd;
|
|---|
| 38 |
|
|---|
| 39 | if (nss_setpwent(nss) != 0) {
|
|---|
| 40 | perror("setpwent");
|
|---|
| 41 | return -1;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | /* loop over all users */
|
|---|
| 45 | while ((nss_getpwent(nss, &pwd) == 0)) {
|
|---|
| 46 | char *sid, **group_sids, *name2;
|
|---|
| 47 | int i;
|
|---|
| 48 |
|
|---|
| 49 | printf("User %s\n", pwd.pw_name);
|
|---|
| 50 | if (nss_nametosid(nss, pwd.pw_name, &sid) != 0) {
|
|---|
| 51 | perror("nametosid");
|
|---|
| 52 | return -1;
|
|---|
| 53 | }
|
|---|
| 54 | printf("\tSID %s\n", sid);
|
|---|
| 55 |
|
|---|
| 56 | if (nss_sidtoname(nss, sid, &name2) != 0) {
|
|---|
| 57 | perror("sidtoname");
|
|---|
| 58 | return -1;
|
|---|
| 59 | }
|
|---|
| 60 | printf("\tSID->name %s\n", name2);
|
|---|
| 61 |
|
|---|
|
|---|