1 | /* |
---|
2 | * ID Command Implementation |
---|
3 | * |
---|
4 | * Author: Fernando RUIZ CASAS |
---|
5 | * Work: fernando.ruiz@ctv.es |
---|
6 | * Home: correo@fernando-ruiz.com |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.org/license/LICENSE. |
---|
11 | */ |
---|
12 | |
---|
13 | #ifdef HAVE_CONFIG_H |
---|
14 | #include "config.h" |
---|
15 | #endif |
---|
16 | |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <unistd.h> |
---|
20 | #include <string.h> |
---|
21 | #include <errno.h> |
---|
22 | #include <pwd.h> |
---|
23 | #include <grp.h> |
---|
24 | |
---|
25 | #include <rtems.h> |
---|
26 | #include <rtems/shell.h> |
---|
27 | #include "internal.h" |
---|
28 | |
---|
29 | static int rtems_shell_main_id( |
---|
30 | int argc __attribute__((unused)), |
---|
31 | char *argv[] __attribute__((unused)) |
---|
32 | ) |
---|
33 | { |
---|
34 | struct passwd *pwd; |
---|
35 | struct group *grp; |
---|
36 | |
---|
37 | pwd = getpwuid(getuid()); |
---|
38 | grp = getgrgid(getgid()); |
---|
39 | printf( |
---|
40 | "uid=%d(%s),gid=%d(%s),", |
---|
41 | getuid(), |
---|
42 | (pwd) ? pwd->pw_name : "", |
---|
43 | getgid(), |
---|
44 | (grp) ? grp->gr_name : "" |
---|
45 | ); |
---|
46 | pwd = getpwuid(geteuid()); |
---|
47 | grp = getgrgid(getegid()); |
---|
48 | printf( |
---|
49 | "euid=%d(%s),egid=%d(%s)\n", |
---|
50 | geteuid(), |
---|
51 | (pwd) ? pwd->pw_name : "", |
---|
52 | getegid(), |
---|
53 | (grp) ? grp->gr_name : "" |
---|
54 | ); |
---|
55 | return 0; |
---|
56 | } |
---|
57 | |
---|
58 | rtems_shell_cmd_t rtems_shell_ID_Command = { |
---|
59 | "id", /* name */ |
---|
60 | "show uid, gid, euid, and egid", /* usage */ |
---|
61 | "misc", /* topic */ |
---|
62 | rtems_shell_main_id, /* command */ |
---|
63 | NULL, /* alias */ |
---|
64 | NULL /* next */ |
---|
65 | }; |
---|