-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibnss_ufp_test.c
58 lines (43 loc) · 1.03 KB
/
libnss_ufp_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include <errno.h>
#include <pwd.h>
#include <shadow.h>
struct spwd *getspnam(const char *name);
int main (int argc, char *argv[]){
struct passwd *p;
struct spwd *s;
char *usern="pippo.pluto";
if(argc ==2)
{
usern=argv[1];
}
if (!(p=getpwnam(usern))) {
return -1;
}
size_t buflen = 1024;
char buffer[buflen];
struct passwd *otherp;
int index = 0;
while (getpwnam_r(usern, p, buffer, buflen, &otherp) != 0) {
printf("loop %d\n", index++);
if (errno != ERANGE) {
break;
}
}
printf("FROM PASSWORD:\n");
printf("\tname: %s\n", p->pw_name);
printf("\tdir: %s\n", p->pw_dir);
printf("\tuid: %d\n", p->pw_uid);
printf("\tgid: %d\n", p->pw_gid);
printf("\tshell: %s\n", p->pw_shell);
printf("\tgecos: %s\n", p->pw_gecos);
printf("FROM SHADOW:\n");
if (!(s = getspnam(usern))) {
return -1;
}
printf ("\tname: %s\n", s->sp_namp);
printf ("\tpass: %s\n", s->sp_pwdp);
return 0;
}