diff -X CVS -ruN top.orig/top.c top/top.c --- top.orig/top.c Wed Jun 22 15:03:21 2005 +++ top/top.c Mon Jul 18 17:12:24 2005 @@ -55,6 +55,14 @@ /* Size of the stdio buffer given to stdout */ #define BUFFERSIZE 2048 +#define PRIVACY + +#ifdef PRIVACY +#include +#define GRP_NAME "wheel" +int verify_grp(void); +#endif + /* The buffer that stdio will use */ char stdoutbuf[BUFFERSIZE]; @@ -270,6 +278,26 @@ ps.pid = (pid_t)-1; ps.command = NULL; +#ifdef PRIVACY + if (verify_grp() ) { + ps.idle = Yes; + ps.system = No; + ps.uid = (uid_t)-1; + ps.command = NULL; + } else { + ps.idle = Yes; + ps.system = No; + ps.uid = getuid(); + ps.command = NULL; + } +#else + ps.idle = Yes; + ps.system = No; + ps.uid = (uid_t)-1; + ps.command = NULL; +#endif + + /* get preset options from the environment */ if ((env_top = getenv("TOP")) != NULL) { av = preset_argv = argparse(env_top, &preset_argc); @@ -771,23 +799,51 @@ break; case CMD_user: +#ifdef PRIVACY + if(verify_grp() ) { + new_message(MT_standout, + "Username to show: "); + if (readline(tempbuf2, sizeof(tempbuf2), No) > 0) { + if (tempbuf2[0] == '+' && + tempbuf2[1] == '\0') { + ps.uid = (uid_t)-1; + } else if ((uid = userid(tempbuf2)) == (uid_t)-1) { + new_message(MT_standout, + " %s: unknown user", tempbuf2); + no_command = Yes; + } else + ps.uid = uid; + if (putchar('\r') == EOF) + exit(1); + } else + clear_message(); + break; + } else { + new_message(MT_standout, + "You have to be root"); + clear_message(); + ps.system = No; + no_command = Yes; + } +#else new_message(MT_standout, - "Username to show: "); + "Username to show: "); if (readline(tempbuf2, sizeof(tempbuf2), No) > 0) { if (tempbuf2[0] == '+' && - tempbuf2[1] == '\0') { + tempbuf2[1] == '\0') { ps.uid = (uid_t)-1; } else if ((uid = userid(tempbuf2)) == (uid_t)-1) { new_message(MT_standout, - " %s: unknown user", tempbuf2); + " %s: unknown user", tempbuf2); no_command = Yes; } else ps.uid = uid; - if (putchar('\r') == EOF) - exit(1); + if (putchar('\r') == EOF) + exit(1); } else clear_message(); - break; + break; +#endif case CMD_system: ps.system = !ps.system; @@ -909,3 +965,27 @@ end_screen(); exit(ret); } + +int +verify_grp(void) +{ + int i = 0; + + struct group *grp; + char **g, *username; + + grp = getgrnam(GRP_NAME); + username = getlogin(); + + for (g = grp->gr_mem; *g; ++g) { + if (strcmp(username, *g) == 0) { + i = 1; + break; + } + } + if(!*g) + i = 0; + + return(i); +} +