Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Jun 2005 14:17:33 +0300
From:      Giorgos Keramidas <keramida@freebsd.org>
To:        Matteo Riondato <matteo@freebsd.org>
Cc:        freebsd-bugs@freebsd.org
Subject:   Re: bin/82465: top(1) in 6-CURRENT shows incorrect user
Message-ID:  <20050622111732.GA36398@orion.daedalusnetworks.priv>
In-Reply-To: <200506211700.j5LH0eRb074284@freefall.freebsd.org>
References:  <200506211700.j5LH0eRb074284@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-06-21 17:00, Matteo Riondato <matteo@freebsd.org> wrote:
>On Tue, Jun 21, 2005 at 06:15:12AM +0000, Peter wrote:
>> >Description:
>> $ ps auxww|grep Xorg
>> root    783  0.0 46.7 57884 57136  v1  S    10:38PM   0:20.85 X :0 -nolisten tcp (Xorg)
>> peter   970  0.0  0.8  1568  1004  p1  R+   11:36PM   0:00.02 grep Xorg
>> $ top -b|grep Xorg
>>   783 peter       1  96    0 57884K 57136K select   0:21  0.00% Xorg
>>
>> ps(1) shows `root' top(1) shows `peter'
>
> Then I would say that the one showing an incorrect user is ps(1), not
> top(1). Or is the euid more important then the ruid ?

The access checks that the kernel does use the effective uid, so it may
be more important that the real uid.  Modifying top to toggle between
effective/real uid by hitting 'U' or some other command character
shouldn't be that hard, if that is deemed a useful feature.

( http://people.freebsd.org/~keramida/diff/top-ruid.patch )

%%%
Index: contrib/top/machine.h
===================================================================
RCS file: /home/ncvs/src/contrib/top/machine.h,v
retrieving revision 1.7
diff -u -r1.7 machine.h
--- contrib/top/machine.h	18 May 2005 13:30:08 -0000	1.7
+++ contrib/top/machine.h	22 Jun 2005 11:05:36 -0000
@@ -62,6 +62,7 @@
     int thread;		/* show threads */
     int uid;		/* only this uid (unless uid == -1) */
     int wcpu;		/* show weighted cpu */
+    int euid;		/* display euid instead of ruid */
     char *command;	/* only this command (unless == NULL) */
 };
 
Index: contrib/top/top.c
===================================================================
RCS file: /home/ncvs/src/contrib/top/top.c,v
retrieving revision 1.17
diff -u -r1.17 top.c
--- contrib/top/top.c	18 May 2005 13:30:08 -0000	1.17
+++ contrib/top/top.c	22 Jun 2005 11:04:46 -0000
@@ -193,9 +193,9 @@
     fd_set readfds;
 
 #ifdef ORDER
-    static char command_chars[] = "\f qh?en#sdkriIutHmSCo";
+    static char command_chars[] = "\f qh?en#sdkriIutHmSCUo";
 #else
-    static char command_chars[] = "\f qh?en#sdkriIutHmSC";
+    static char command_chars[] = "\f qh?en#sdkriIutHmSCU";
 #endif
 /* these defines enumerate the "strchr"s of the commands in command_chars */
 #define CMD_redraw	0
@@ -219,8 +219,9 @@
 #define CMD_viewtog	17
 #define CMD_viewsys	18
 #define	CMD_wcputog	19
+#define	CMD_euidtog	20
 #ifdef ORDER
-#define CMD_order       20
+#define CMD_order       21
 #endif
 
     /* set the buffer for stdout */
@@ -252,6 +253,7 @@
     ps.uid     = -1;
     ps.thread  = No;
     ps.wcpu    = 1;
+    ps.euid    = 0;
     ps.command = NULL;
 
     /* get preset options from the environment */
@@ -1008,6 +1010,15 @@
 				reset_display();
 				putchar('\r');
 				break;
+			    case CMD_euidtog:
+			        ps.euid = !ps.euid;
+				new_message(MT_standout | MT_delayed,
+				    "Displaying %sUID",
+				    ps.euid ? "E" : "R");
+				header_text = format_header(uname_field);
+				reset_display();
+				putchar('\r');
+				break;
 			    case CMD_viewtog:
 				if (++displaymode == DISP_MAX)
 					displaymode = 0;
Index: usr.bin/top/machine.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/top/machine.c,v
retrieving revision 1.74
diff -u -r1.74 machine.c
--- usr.bin/top/machine.c	18 May 2005 13:42:51 -0000	1.74
+++ usr.bin/top/machine.c	22 Jun 2005 11:14:19 -0000
@@ -609,7 +609,9 @@
 			/* skip processes that aren't doing I/O */
 			continue;
 
-		if (show_uid && pp->ki_ruid != (uid_t)sel->uid)
+		if (show_uid &&
+		    ((ps.euid != 0 && pp->ki_uid != (uid_t)sel->uid) ||
+		    pp->ki_ruid != (uid_t)sel->uid))
 			/* skip processes which don't belong to the selected UID */
 			continue;
 
@@ -736,7 +738,7 @@
 		sprintf(fmt, io_Proc_format,
 		    pp->ki_pid,
 		    namelength, namelength,
-		    (*get_userid)(pp->ki_ruid),
+		    (*get_userid)((ps.euid != 0) ? pp->ki_uid : pp->ki_ruid),
 		    rup->ru_nvcsw,
 		    rup->ru_nivcsw,
 		    rup->ru_inblock,
@@ -761,7 +763,7 @@
 	sprintf(fmt, proc_fmt,
 	    pp->ki_pid,
 	    namelength, namelength,
-	    (*get_userid)(pp->ki_ruid),
+	    (*get_userid)((ps.euid != 0) ? pp->ki_uid : pp->ki_ruid),
 	    thr_buf,
 	    pp->ki_pri.pri_level - PZERO,
 
@@ -1131,8 +1133,12 @@
 	cnt = pref_len;
 	while (--cnt >= 0) {
 		pp = *prefp++;
-		if (pp->ki_pid == (pid_t)pid)
-			return ((int)pp->ki_ruid);
+		if (pp->ki_pid == (pid_t)pid) {
+			if (ps.euid != 0)
+				return ((int)pp->ki_uid);
+			else
+				return ((int)pp->ki_ruid);
+		}
 	}
 	return (-1);
 }
%%%



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050622111732.GA36398>