r35645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35644‎ | r35645 | r35646 >
Date:09:27, 31 May 2008
Author:river
Status:old
Tags:
Comment:
- allow root to view the expiry date of another user's account
Modified paths:
  • /trunk/tools/tsutils/acctexp/acctexp.c (modified) (history)

Diff [purge]

Index: trunk/tools/tsutils/acctexp/acctexp.c
@@ -14,20 +14,35 @@
1515 #include <shadow.h>
1616
1717 int
18 -main()
 18+main(argc, argv)
 19+ int argc;
 20+ char **argv;
1921 {
2022 struct spwd *spwent;
2123 struct passwd *pwent;
 24+char const *uname = NULL;
2225 uid_t uid;
2326 time_t when;
2427 char res[256];
2528 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;
3045 }
31 - if ((spwent = getspnam(pwent->pw_name)) == NULL) {
 46+ if ((spwent = getspnam(uname)) == NULL) {
3247 (void) fprintf(stderr, "getspnam: %s\n", strerror(errno));
3348 return 1;
3449 }
@@ -45,9 +60,9 @@
4661 }
4762 (void) strftime(res, sizeof(res) - 1, "%A, %d %B %Y", whentm);
4863 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);
5068 return 0;
5169 }
52 -
53 -
54 -

Status & tagging log