summaryrefslogtreecommitdiffstats
path: root/usr.bin/pkill/pkill.c
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2004-03-25 23:19:16 +0000
committergad <gad@FreeBSD.org>2004-03-25 23:19:16 +0000
commita932a157f4b39354c248578d0423ad0c06a1319a (patch)
tree578bf6c4ef12d501a9f442fe2d8bbd1bdb1835c5 /usr.bin/pkill/pkill.c
parent6db55881ec0f728295a337eaeeefa21d2caa7092 (diff)
downloadFreeBSD-src-a932a157f4b39354c248578d0423ad0c06a1319a.zip
FreeBSD-src-a932a157f4b39354c248578d0423ad0c06a1319a.tar.gz
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 <lioux@FreeBSD.org> Obtained from: the sysutils/pkill port
Diffstat (limited to 'usr.bin/pkill/pkill.c')
-rw-r--r--usr.bin/pkill/pkill.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c
index 45087ad..6a83cce 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);
}
OpenPOWER on IntegriCloud