1 /* $OpenBSD: setgid_none.c,v 1.3 2021/12/15 18:42:38 anton Exp $ */
2 /*
3 * Written by Bret Stephen Lambert <blambert@openbsd.org> 2014
4 * Public Domain.
5 */
6
7 #include <sys/types.h>
8 #include <sys/signal.h>
9 #include <sys/proc.h>
10 #include <sys/sysctl.h>
11 #include <sys/wait.h>
12
13 #include <err.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <pwd.h>
17 #include <unistd.h>
18
19 #include "setuid_regress.h"
20
21 int
main(int argc,const char * argv[])22 main(int argc, const char *argv[])
23 {
24 struct kinfo_proc kproc;
25 gid_t gid;
26
27 gid = getgid();
28
29 checkgids(gid, gid, gid, "checkgid");
30
31 /* should only respond to setgid upon exec */
32 if (issetugid())
33 errx(1, "process incorrectly marked as issetugid()");
34
35 if (read_kproc_pid(&kproc, getpid()) == -1)
36 err(1, "kproc read failed");
37
38 if (kproc.p_psflags & PS_SUGID)
39 errx(1, "PS_SUGID incorrectly set");
40 if (kproc.p_psflags & PS_SUGIDEXEC)
41 errx(1, "PS_SUGIDEXEC incorrectly set");
42
43 exit(0);
44 }
45