Last change
on this file since 165 was 1, checked in by Paul Smedley, 18 years ago |
Initial code import
|
File size:
972 bytes
|
Line | |
---|
1 | /*
|
---|
2 | * Lookup a group by name
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include <stdio.h>
|
---|
6 | #include <grp.h>
|
---|
7 | #include <sys/types.h>
|
---|
8 |
|
---|
9 | int main(int argc, char **argv)
|
---|
10 | {
|
---|
11 | struct group *gr;
|
---|
12 |
|
---|
13 | /* Check args */
|
---|
14 |
|
---|
15 | if (argc != 2) {
|
---|
16 | printf("ERROR: no arg specified\n");
|
---|
17 | exit(1);
|
---|
18 | }
|
---|
19 |
|
---|
20 | /* Do getgrnam() */
|
---|
21 |
|
---|
22 | if ((gr = getgrnam(argv[1])) == NULL) {
|
---|
23 | printf("FAIL: group %s does not exist\n", argv[1]);
|
---|
24 | exit(1);
|
---|
25 | }
|
---|
26 |
|
---|
27 | /* Print group info */
|
---|
28 |
|
---|
29 | printf("PASS: group %s exists\n", argv[1]);
|
---|
30 | printf("gr_name = %s\n", gr->gr_name);
|
---|
31 | printf("gr_passwd = %s\n", gr->gr_passwd);
|
---|
32 | printf("gr_gid = %d\n", gr->gr_gid);
|
---|
33 |
|
---|
34 | /* Group membership */
|
---|
35 |
|
---|
36 | if (gr->gr_mem != NULL) {
|
---|
37 | int i = 0;
|
---|
38 |
|
---|
39 | printf("gr_mem = ");
|
---|
40 | while(gr->gr_mem[i] != NULL) {
|
---|
41 | printf("%s", gr->gr_mem[i]);
|
---|
42 | i++;
|
---|
43 | if (gr->gr_mem != NULL) {
|
---|
44 | printf(",");
|
---|
45 | }
|
---|
46 | }
|
---|
47 | printf("\n");
|
---|
48 | }
|
---|
49 |
|
---|
50 | exit(0);
|
---|
51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.