Index: trunk/tools/tsutils/acctexp/acctexp.c |
— | — | @@ -14,20 +14,35 @@ |
15 | 15 | #include <shadow.h> |
16 | 16 | |
17 | 17 | int |
18 | | -main() |
| 18 | +main(argc, argv) |
| 19 | + int argc; |
| 20 | + char **argv; |
19 | 21 | { |
20 | 22 | struct spwd *spwent; |
21 | 23 | struct passwd *pwent; |
| 24 | +char const *uname = NULL; |
22 | 25 | uid_t uid; |
23 | 26 | time_t when; |
24 | 27 | char res[256]; |
25 | 28 | struct tm *whentm; |
26 | | - uid = getuid(); |
27 | | - if ((pwent = getpwuid(uid)) == NULL) { |
28 | | - (void) fprintf(stderr, "getpwuid: %s\n", strerror(errno)); |
29 | | - return 1; |
| 29 | + if (argc > 1) { |
| 30 | + if (getgid() != getegid()) { |
| 31 | + (void) fprintf(stderr, "only the super-user may view" |
| 32 | + " the account expiry data of another user\n"); |
| 33 | + return 1; |
| 34 | + } |
| 35 | + |
| 36 | + uname = argv[1]; |
| 37 | + } else { |
| 38 | + uid = getuid(); |
| 39 | + if ((pwent = getpwuid(uid)) == NULL) { |
| 40 | + (void) fprintf(stderr, "getpwuid: %s\n", strerror(errno)); |
| 41 | + return 1; |
| 42 | + } |
| 43 | + |
| 44 | + uname = pwent->pw_name; |
30 | 45 | } |
31 | | - if ((spwent = getspnam(pwent->pw_name)) == NULL) { |
| 46 | + if ((spwent = getspnam(uname)) == NULL) { |
32 | 47 | (void) fprintf(stderr, "getspnam: %s\n", strerror(errno)); |
33 | 48 | return 1; |
34 | 49 | } |
— | — | @@ -45,9 +60,9 @@ |
46 | 61 | } |
47 | 62 | (void) strftime(res, sizeof(res) - 1, "%A, %d %B %Y", whentm); |
48 | 63 | res[sizeof(res) - 1] = '\0'; |
49 | | - (void) printf("Your account will expire on %s.\n", res); |
| 64 | + if (argc > 1) |
| 65 | + (void) printf("The account \"%s\" will expire on %s.\n", uname, res); |
| 66 | + else |
| 67 | + (void) printf("Your account will expire on %s.\n", res); |
50 | 68 | return 0; |
51 | 69 | } |
52 | | - |
53 | | - |
54 | | - |