=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/fstat/fstat.c,v retrieving revision 1.61 retrieving revision 1.62 diff -u -r1.61 -r1.62 --- src/usr.bin/fstat/fstat.c 2008/04/08 14:46:45 1.61 +++ src/usr.bin/fstat/fstat.c 2008/10/07 02:20:12 1.62 @@ -1,4 +1,4 @@ -/* $OpenBSD: fstat.c,v 1.61 2008/04/08 14:46:45 thib Exp $ */ +/* $OpenBSD: fstat.c,v 1.62 2008/10/07 02:20:12 deraadt Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -37,7 +37,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)fstat.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$OpenBSD: fstat.c,v 1.61 2008/04/08 14:46:45 thib Exp $"; +static char *rcsid = "$OpenBSD: fstat.c,v 1.62 2008/10/07 02:20:12 deraadt Exp $"; #endif /* not lint */ #include @@ -146,6 +146,7 @@ (kvm_read(kd, (u_long)(kaddr), (void *)(paddr), (len)) == (len)) kvm_t *kd; +uid_t uid; int ufs_filestat(struct vnode *, struct filestat *); int ext2fs_filestat(struct vnode *, struct filestat *); @@ -232,6 +233,12 @@ } /* + * get the uid, for oflg and sflg + */ + + uid = getuid(); + + /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ @@ -290,6 +297,7 @@ } char *Uname, *Comm; +uid_t *procuid; pid_t Pid; #define PREFIX(i) do { \ @@ -325,6 +333,7 @@ #define filed filed0.fd_fd Uname = user_from_uid(kp->p_uid, 0); + procuid = &kp->p_uid; Pid = kp->p_pid; Comm = kp->p_comm; @@ -522,13 +531,22 @@ } default: printf(" %8lld", (long long)fst.size); - if (oflg) - printf(":%-8lld", (long long)(fp? fp->f_offset : 0)); + if (oflg) { + if (uid == 0 || uid == *procuid) + printf(":%-8lld", (long long)(fp? fp->f_offset : 0)); + else + printf(":%-8s", "*"); + } } - if (sflg) - printf(" %8lld %8lld", - (long long)(fp? fp->f_rxfer + fp->f_wxfer : 0), - (long long)(fp? fp->f_rbytes + fp->f_wbytes : 0) / 1024); + if (sflg) { + if (uid == 0 || uid == *procuid) { + printf(" %8lld %8lld", + (long long)(fp? fp->f_rxfer + fp->f_wxfer : 0), + (long long)(fp? fp->f_rbytes + fp->f_wbytes : 0) / 1024); + } else { + printf(" %8s %8s", "*", "*"); + } + } if (filename && !fsflg) printf(" %s", filename); putchar('\n');