Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
t_setreuid.c
Package: sendmail.8.10.0.Beta10.tar.Z [view]
Upload User: xu_441
Upload Date: 2007-01-04
Package Size: 1640k
Code Size: 3k
Category:
Email Client
Development Platform:
Unix_Linux
- /*
- ** This program checks to see if your version of setreuid works.
- ** Compile it, make it setuid root, and run it as yourself (NOT as
- ** root). If it won't compile or outputs any MAYDAY messages, don't
- ** define HASSETREUID in conf.h.
- **
- ** Compilation is trivial -- just "cc t_setreuid.c". Make it setuid,
- ** root and then execute it as a non-root user.
- */
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #ifndef lint
- static char id[] = "@(#)$Id: t_setreuid.c,v 8.4 1999/08/28 00:25:28 gshapiro Exp $";
- #endif /* ! lint */
- #ifdef __hpux
- # define setreuid(r, e) setresuid(r, e, -1)
- #endif /* __hpux */
- static void
- printuids(str, r, e)
- char *str;
- int r, e;
- {
- printf("%s (should be %d/%d): r/euid=%d/%dn", str, r, e,
- getuid(), geteuid());
- }
- int
- main(argc, argv)
- int argc;
- char **argv;
- {
- int fail = 0;
- uid_t realuid = getuid();
- printuids("initial uids", realuid, 0);
- if (geteuid() != 0)
- {
- printf("SETUP ERROR: re-run setuid rootn");
- exit(1);
- }
- if (getuid() == 0)
- {
- printf("SETUP ERROR: must be run by a non-root usern");
- exit(1);
- }
- if (setreuid(0, 1) < 0)
- {
- fail++;
- printf("setreuid(0, 1) failuren");
- }
- printuids("after setreuid(0, 1)", 0, 1);
- if (geteuid() != 1)
- {
- fail++;
- printf("MAYDAY! Wrong effective uidn");
- }
- /* do activity here */
- if (setreuid(-1, 0) < 0)
- {
- fail++;
- printf("setreuid(-1, 0) failuren");
- }
- printuids("after setreuid(-1, 0)", 0, 0);
- if (setreuid(realuid, 0) < 0)
- {
- fail++;
- printf("setreuid(%d, 0) failuren", realuid);
- }
- printuids("after setreuid(realuid, 0)", realuid, 0);
- if (geteuid() != 0)
- {
- fail++;
- printf("MAYDAY! Wrong effective uidn");
- }
- if (getuid() != realuid)
- {
- fail++;
- printf("MAYDAY! Wrong real uidn");
- }
- printf("n");
- if (setreuid(0, 2) < 0)
- {
- fail++;
- printf("setreuid(0, 2) failuren");
- }
- printuids("after setreuid(0, 2)", 0, 2);
- if (geteuid() != 2)
- {
- fail++;
- printf("MAYDAY! Wrong effective uidn");
- }
- /* do activity here */
- if (setreuid(-1, 0) < 0)
- {
- fail++;
- printf("setreuid(-1, 0) failuren");
- }
- printuids("after setreuid(-1, 0)", 0, 0);
- if (setreuid(realuid, 0) < 0)
- {
- fail++;
- printf("setreuid(%d, 0) failuren", realuid);
- }
- printuids("after setreuid(realuid, 0)", realuid, 0);
- if (geteuid() != 0)
- {
- fail++;
- printf("MAYDAY! Wrong effective uidn");
- }
- if (getuid() != realuid)
- {
- fail++;
- printf("MAYDAY! Wrong real uidn");
- }
- if (fail)
- {
- printf("nThis system cannot use setreuidn");
- exit(1);
- }
- printf("nIt is safe to define HASSETREUID on this systemn");
- exit(0);
- }