From 998c10ebd965b271fc01c3e2d8d0c59424a53915 Mon Sep 17 00:00:00 2001 From: Garance A Drosehn Date: Thu, 25 Mar 2004 23:19:16 +0000 Subject: Add `-M' and `-N' options to `pkill' and `pgrep', similar to what are supported in `ps': -M Extract values associated with the name list from the specified core instead of the default /dev/kmem. -N Extract the name list from the specified system instead of the default /kernel. Written by: Mario Sergio Fujikawa Ferreira Obtained from: the sysutils/pkill port --- usr.bin/pkill/pkill.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'usr.bin/pkill/pkill.c') diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c index 45087ade6699..6a83cceeb5d2 100644 --- a/usr.bin/pkill/pkill.c +++ b/usr.bin/pkill/pkill.c @@ -125,7 +125,7 @@ main(int argc, char **argv) extern int optind; char buf[_POSIX2_LINE_MAX], *mstr, **pargv, *p, *q; char *execf, *coref, *swapf; - int i, j, ch, bestidx, rv, criteria; + int i, j, ch, bestidx, rv, criteria, drop_privs; void (*action)(struct kinfo_proc *); struct kinfo_proc *kp; struct list *li; @@ -169,13 +169,22 @@ main(int argc, char **argv) #endif criteria = 0; + drop_privs = 0; - while ((ch = getopt(argc, argv, "G:P:U:d:fg:lns:t:u:vx")) != -1) + while ((ch = getopt(argc, argv, "G:M:N:P:U:d:fg:lns:t:u:vx")) != -1) switch (ch) { case 'G': makelist(&rgidlist, LT_GROUP, optarg); criteria = 1; break; + case 'M': + coref = optarg; + drop_privs = 1; + break; + case 'N': + execf = optarg; + drop_privs = 1; + break; case 'P': makelist(&ppidlist, LT_GENERIC, optarg); criteria = 1; @@ -235,6 +244,15 @@ main(int argc, char **argv) if (!criteria) usage(); + /* + * Discard privileges if not the running kernel so that bad + * guys can't print interesting stuff from kernel memory. + */ + if (drop_privs) { + setgid(getgid()); + setuid(getuid()); + } + mypid = getpid(); /* @@ -426,9 +444,9 @@ usage(void) ustr = "[-signal] [-fnvx]"; fprintf(stderr, - "usage: %s %s [-G gid] [-P ppid] [-U uid] [-g pgrp] [-s sid]\n" - " [-t tty] [-u euid] pattern ...\n", getprogname(), - ustr); + "usage: %s %s [-G gid] [-M core] [-N system]\n" + " [-P ppid] [-U uid] [-g pgrp] [-s sid] [-t tty]\n" + " [-u euid] pattern ...\n", getprogname(), ustr); exit(STATUS_ERROR); } -- cgit v1.3