1 /* $OpenBSD: setuid_none.c,v 1.1 2014/08/27 07:36:14 blambert 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/param.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 22 main(int argc, char *argv[]) 23 { 24 struct kinfo_proc kproc; 25 uid_t uid; 26 27 uid = getuid(); 28 29 checkuids(uid, uid, uid, "getuid"); 30 31 /* should only respond to setuid 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