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 setgid works.
13 ** Compile it, make it set-group-ID guest, and run it as yourself (NOT as
14 ** root and not as member of the group guest).
16 ** Compilation is trivial -- just "cc t_setgid.c". Make it set-group-ID,
17 ** guest and then execute it as a non-root user.
20 #include <sys/types.h>
25 static char id
[] = "@(#)$Id: t_setgid.c,v 1.6 2001/09/23 03:35:41 ca Exp $";
33 printf("%s (should be %d/%d): r/egid=%d/%d\n", str
, (int) r
, (int) e
,
34 (int) getgid(), (int) getegid());
44 gid_t realgid
= getgid();
45 gid_t effgid
= getegid();
47 printgids("initial gids", realgid
, effgid
);
49 if (effgid
== realgid
)
51 printf("SETUP ERROR: re-run set-group-ID guest\n");
56 res
= setregid(effgid
, effgid
);
57 #else /* SM_CONF_SETREGID */
59 #endif /* SM_CONF_SETREGID */
61 printf("setgid(%d)=%d %s\n", (int) effgid
, res
,
62 res
< 0 ? "failure" : "ok");
64 printgids("after setregid()", effgid
, effgid
);
65 #else /* SM_CONF_SETREGID */
66 printgids("after setgid()", effgid
, effgid
);
67 #endif /* SM_CONF_SETREGID */
69 if (getegid() != effgid
)
72 printf("MAYDAY! Wrong effective gid\n");
75 if (getgid() != effgid
)
78 printf("MAYDAY! Wrong real gid\n");
81 /* do activity here */
85 printf("MAYDAY! setgid(0) succeeded (should have failed)\n");
89 printf("setgid(0) failed (this is correct)\n");
91 printgids("after setgid(0)", effgid
, effgid
);
93 if (getegid() != effgid
)
96 printf("MAYDAY! Wrong effective gid\n");
98 if (getgid() != effgid
)
101 printf("MAYDAY! Wrong real gid\n");
107 printf("\nThis system cannot use %s to set the real gid to the effective gid\nand clear the saved gid.\n",
110 #else /* SM_CONF_SETREGID */
112 #endif /* SM_CONF_SETREGID */
117 printf("\nIt is possible to use setgid on this system\n");