2 * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
12 ** This program checks to see if your version of setuid works.
13 ** Compile it, make it set-user-ID root, and run it as yourself (NOT as
16 ** NOTE: This should work everywhere, but Linux has the ability
17 ** to use the undocumented setcap() call to make this break.
19 ** Compilation is trivial -- just "cc t_setuid.c". Make it set-user-ID,
20 ** root and then execute it as a non-root user.
23 #include <sys/types.h>
28 static char id
[] = "@(#)$Id: t_setuid.c,v 8.7 2001/09/23 03:35:41 ca Exp $";
36 printf("%s (should be %d/%d): r/euid=%d/%d\n", str
, (int) r
, (int) e
,
37 (int) getuid(), (int) geteuid());
46 uid_t realuid
= getuid();
48 printuids("initial uids", realuid
, 0);
52 printf("SETUP ERROR: re-run set-user-ID root\n");
58 printf("SETUP ERROR: must be run by a non-root user\n");
63 printf("setuid(1) failure\n");
64 printuids("after setuid(1)", 1, 1);
69 printf("MAYDAY! Wrong effective uid\n");
75 printf("MAYDAY! Wrong real uid\n");
79 /* do activity here */
83 printf("MAYDAY! setuid(0) succeeded (should have failed)\n");
87 printf("setuid(0) failed (this is correct)\n");
89 printuids("after setuid(0)", 1, 1);
94 printf("MAYDAY! Wrong effective uid\n");
99 printf("MAYDAY! Wrong real uid\n");
105 printf("\nThis system cannot use setuid (maybe use setreuid)\n");
109 printf("\nIt is safe to use setuid on this system\n");