Last change
on this file was 2036, checked in by bird, 20 years ago |
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.1 KB
|
Line | |
---|
1 | #include <grp.h>
|
---|
2 | #include <pwd.h>
|
---|
3 | #include <sys/types.h>
|
---|
4 | #include <unistd.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <stdio.h>
|
---|
7 |
|
---|
8 | int
|
---|
9 | main (int argc, char *argv[])
|
---|
10 | {
|
---|
11 | uid_t me;
|
---|
12 | struct passwd *my_passwd;
|
---|
13 | struct group *my_group = NULL;
|
---|
14 | char **members;
|
---|
15 |
|
---|
16 | me = getuid ();
|
---|
17 | my_passwd = getpwuid (me);
|
---|
18 | if (my_passwd == NULL)
|
---|
19 | printf ("Cannot find user entry for UID %d\n", me);
|
---|
20 | else
|
---|
21 | {
|
---|
22 | printf ("My login name is %s.\n", my_passwd->pw_name);
|
---|
23 | printf ("My uid is %d.\n", (int)(my_passwd->pw_uid));
|
---|
24 | printf ("My home directory is %s.\n", my_passwd->pw_dir);
|
---|
25 | printf ("My default shell is %s.\n", my_passwd->pw_shell);
|
---|
26 |
|
---|
27 | my_group = getgrgid (my_passwd->pw_gid);
|
---|
28 | if (my_group == NULL)
|
---|
29 | printf ("No data for group %d found\n", my_passwd->pw_gid);
|
---|
30 | else
|
---|
31 | {
|
---|
32 | printf ("My default group is %s (%d).\n",
|
---|
33 | my_group->gr_name, (int)(my_passwd->pw_gid));
|
---|
34 | printf ("The members of this group are:\n");
|
---|
35 | for (members = my_group->gr_mem; *members != NULL; ++members)
|
---|
36 | printf (" %s\n", *members);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | return my_passwd && my_group ? EXIT_SUCCESS : EXIT_FAILURE;
|
---|
41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.