blob: 00e5f073ff359bd62c7887da83a5b798b8a9861f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* $OpenBSD: cansig.c,v 1.1 2008/06/10 18:04:31 hshoexer Exp $ */
/* Written by Michael Shalayeff, 2008. Public Domain */
#include <sys/param.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <err.h>
int
main()
{
pid_t pid;
int serrno;
if ((pid = fork()) < 0)
err(1, "fork");
/* nun sex */
if (!pid) {
if (seteuid(1))
err(1, "seteuid");
sleep(3);
return 0;
}
/* monk rock */
sleep(1);
/* first see if we can still do it */
if (kill(pid, 0)) {
serrno = errno;
kill(pid, SIGKILL);
errno = serrno;
err(1, "kill0");
}
if (setreuid(1, 1)) {
serrno = errno;
kill(pid, SIGKILL);
errno = serrno;
err(1, "seteuid1");
}
/* not allowed */
if (!kill(pid, 0))
errx(1, "kill1");
/* we can't collect the remains from the kiddo */
return 0;
}
|