2 * Copyright (c) 1999-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 seteuid 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 USESETEUID in conf.h.
17 ** NOTE: It is not sufficient to have seteuid in your library.
18 ** You must also have saved uids that function properly.
20 ** Compilation is trivial -- just "cc t_seteuid.c". Make it set-user-ID
21 ** root and then execute it as a non-root user.
24 #include <sys/types.h>
29 static char id
[] = "@(#)$Id: t_seteuid.c,v 8.8 2001/09/23 03:35:41 ca Exp $";
33 # define seteuid(e) setresuid(-1, e, -1)
41 printf("%s (should be %d/%d): r/euid=%d/%d\n", str
, (int) r
, (int) e
,
42 (int) getuid(), (int) geteuid());
51 uid_t realuid
= getuid();
53 printuids("initial uids", realuid
, 0);
57 printf("SETUP ERROR: re-run set-user-ID root\n");
63 printf("SETUP ERROR: must be run by a non-root user\n");
68 printf("seteuid(1) failure\n");
69 printuids("after seteuid(1)", realuid
, 1);
74 printf("MAYDAY! Wrong effective uid\n");
77 /* do activity here */
82 printf("seteuid(0) failure\n");
84 printuids("after seteuid(0)", realuid
, 0);
89 printf("MAYDAY! Wrong effective uid\n");
91 if (getuid() != realuid
)
94 printf("MAYDAY! Wrong real uid\n");
101 printf("seteuid(2) failure\n");
103 printuids("after seteuid(2)", realuid
, 2);
108 printf("MAYDAY! Wrong effective uid\n");
111 /* do activity here */
116 printf("seteuid(0) failure\n");
118 printuids("after seteuid(0)", realuid
, 0);
123 printf("MAYDAY! Wrong effective uid\n");
125 if (getuid() != realuid
)
128 printf("MAYDAY! Wrong real uid\n");
133 printf("\nThis system cannot use seteuid\n");
137 printf("\nIt is safe to define USESETEUID on this system\n");