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 setreuid works.
13 ** Compile it, make it set-user-ID root, and run it as yourself (NOT as
14 ** root). If it won't compile or outputs any MAYDAY messages, don't
15 ** define HASSETREUID in conf.h.
17 ** Compilation is trivial -- just "cc t_setreuid.c". Make it set-user-ID,
18 ** root and then execute it as a non-root user.
21 #include <sys/types.h>
26 static char id
[] = "@(#)$Id: t_setreuid.c,v 8.9 2001/10/12 03:04:46 gshapiro Exp $";
30 # define setreuid(r, e) setresuid(r, e, -1)
38 printf("%s (should be %d/%d): r/euid=%d/%d\n", str
, (int) r
, (int) e
,
39 (int) getuid(), (int) geteuid());
48 uid_t realuid
= getuid();
50 printuids("initial uids", realuid
, 0);
54 printf("SETUP ERROR: re-run set-user-ID root\n");
60 printf("SETUP ERROR: must be run by a non-root user\n");
64 if (setreuid(0, 1) < 0)
67 printf("setreuid(0, 1) failure\n");
69 printuids("after setreuid(0, 1)", 0, 1);
74 printf("MAYDAY! Wrong real uid\n");
80 printf("MAYDAY! Wrong effective uid\n");
83 /* do activity here */
85 if (setreuid(-1, 0) < 0)
88 printf("setreuid(-1, 0) failure\n");
90 printuids("after setreuid(-1, 0)", 0, 0);
91 if (setreuid(realuid
, 0) < 0)
94 printf("setreuid(%d, 0) failure\n", (int) realuid
);
96 printuids("after setreuid(realuid, 0)", realuid
, 0);
101 printf("MAYDAY! Wrong effective uid\n");
103 if (getuid() != realuid
)
106 printf("MAYDAY! Wrong real uid\n");
110 if (setreuid(0, 2) < 0)
113 printf("setreuid(0, 2) failure\n");
115 printuids("after setreuid(0, 2)", 0, 2);
120 printf("MAYDAY! Wrong effective uid\n");
126 printf("MAYDAY! Wrong real uid\n");
129 /* do activity here */
131 if (setreuid(-1, 0) < 0)
134 printf("setreuid(-1, 0) failure\n");
136 printuids("after setreuid(-1, 0)", 0, 0);
137 if (setreuid(realuid
, 0) < 0)
140 printf("setreuid(%d, 0) failure\n", (int) realuid
);
142 printuids("after setreuid(realuid, 0)", realuid
, 0);
147 printf("MAYDAY! Wrong effective uid\n");
149 if (getuid() != realuid
)
152 printf("MAYDAY! Wrong real uid\n");
157 printf("\nThis system cannot use setreuid\n");
161 printf("\nIt is safe to define HASSETREUID on this system\n");