Date: 27 Feb 2004 17:53:03 -0000 From: "Christian S.J.Peron" <maneo@bsdpro.com> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/63463: [patch] list IPC mechanisms based on username/UID Message-ID: <20040227175303.56998.qmail@staff.seccuris.com> Resent-Message-ID: <200402271801.i1RI1oWU017372@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 63463 >Category: bin >Synopsis: [patch] list IPC mechanisms based on username/UID >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Feb 27 10:00:40 PST 2004 >Closed-Date: >Last-Modified: >Originator: Christian S.J. Peron >Release: FreeBSD 5.2-CURRENT i386 >Organization: >Environment: FreeBSD movl 5.2-CURRENT FreeBSD 5.2-CURRENT #8: Mon Feb 2 22:04:49 GMT 2004 modulus@movl:/usr/src/sys/i386/compile/ROUTER i386 >Description: Currently there is no way to list IPC mechanisms owned by a specific user. I think it would be usefull to have this option. I have enclosed a patch which implements this functionality. >How-To-Repeat: N/A >Fix: --- usr.bin/ipcs/ipcs.c.bak Fri Feb 27 04:04:15 2004 +++ usr.bin/ipcs/ipcs.c Fri Feb 27 16:57:04 2004 @@ -74,6 +74,7 @@ void sysctlgatherstruct(void *addr, size_t size, struct scgs_vector *vec); void kget(int idx, void *addr, size_t size); void usage(void); +uid_t user2uid(char *username); static struct nlist symbols[] = { {"sema"}, @@ -188,11 +189,12 @@ { int display = SHMINFO | MSGINFO | SEMINFO; int option = 0; - char *core = NULL, *namelist = NULL; + char *core = NULL, *user = NULL, *namelist = NULL; char kvmoferr[_POSIX2_LINE_MAX]; /* Error buf for kvm_openfiles. */ int i; + uid_t uid; - while ((i = getopt(argc, argv, "MmQqSsabC:cN:optTy")) != -1) + while ((i = getopt(argc, argv, "MmQqSsabC:cN:optTu:y")) != -1) switch (i) { case 'M': display = SHMTOTAL; @@ -242,6 +244,10 @@ case 'y': use_sysctl = 0; break; + case 'u': + user = optarg; + uid = user2uid(user); + break; default: usage(); } @@ -320,6 +326,9 @@ ctime_buf[100]; struct msqid_ds *msqptr = &xmsqids[i]; + if (user) + if (uid != msqptr->msg_perm.uid) + continue; cvt_time(msqptr->msg_stime, stime_buf); cvt_time(msqptr->msg_rtime, rtime_buf); cvt_time(msqptr->msg_ctime, ctime_buf); @@ -409,6 +418,9 @@ ctime_buf[100]; struct shmid_ds *shmptr = &xshmids[i]; + if (user) + if (uid != shmptr->shm_perm.uid) + continue; cvt_time(shmptr->shm_atime, atime_buf); cvt_time(shmptr->shm_dtime, dtime_buf); cvt_time(shmptr->shm_ctime, ctime_buf); @@ -502,6 +514,9 @@ char ctime_buf[100], otime_buf[100]; struct semid_ds *semaptr = &xsema[i]; + if (user) + if (uid != semaptr->sem_perm.uid) + continue; cvt_time(semaptr->sem_otime, otime_buf); cvt_time(semaptr->sem_ctime, ctime_buf); @@ -649,11 +664,27 @@ } } +uid_t +user2uid(char *username) +{ + struct passwd *pwd; + uid_t uid; + char *r; + + uid = strtoul(username, &r, 0); + if (!*r && r != username) + return (uid); + if ((pwd = getpwnam(username)) == NULL) + errx(1, "getpwnam failed: No such user"); + endpwent(); + return (pwd->pw_uid); +} + void usage() { fprintf(stderr, - "usage: ipcs [-abcmopqstyMQST] [-C corefile] [-N namelist]\n"); + "usage: ipcs [-abcmopqstyMQST] [-C corefile] [-N namelist] [-u user]\n"); exit(1); } >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040227175303.56998.qmail>