*/
#define _XOPEN_SOURCE 500 /* For pread() pwrite() */
-#define _BSD_SOURCE /* For seteuid() */
#define _LARGEFILE64_SOURCE /* For O_LARGEFILE */
#include <alloca.h>
#include <errno.h>
char *program; /* Name of program */
char *device; /* Device to install to */
-uid_t ruid; /* Real uid */
-uid_t euid; /* Initial euid */
pid_t mypid;
void usage(void)
int force = 0; /* -f (force) option */
off_t offset = 0; /* -o (offset) option */
- ruid = getuid();
- euid = geteuid();
- mypid = getpid();
-
- if ( !euid )
- setreuid(-1, ruid); /* Run as regular user until we need it */
-
program = argv[0];
device = NULL;
/*
* Now mount the device.
*/
- if ( euid ) {
+ if ( geteuid() ) {
fprintf(stderr, "%s: This program needs root privilege\n", program);
exit(1);
} else {
if ( lstat(mntname, &dst) != -1 || errno != ENOENT )
continue;
- seteuid(0); /* *** BECOME ROOT *** */
- rv = mkdir(mntname, 0000); /* AS ROOT */
- seteuid(ruid);
+ rv = mkdir(mntname, 0000);
if ( rv == -1 ) {
if ( errno == EEXIST || errno == EINTR )
exit(1);
} else if ( f == 0 ) {
char mnt_opts[128];
- seteuid(0); /* ***BECOME ROOT*** */
- setuid(0);
if ( S_ISREG(st.st_mode) ) {
- snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,loop,offset=%llu,umask=077,uid=%lu",
- (unsigned long long)offset, (unsigned long)ruid);
+ snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,loop,offset=%llu,umask=077",
+ (unsigned long long)offset);
} else {
- snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,umask=077,uid=%lu",
- (unsigned long)ruid);
+ snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,umask=077");
}
execl(_PATH_MOUNT, _PATH_MOUNT, "-t", "msdos", "-o", mnt_opts,\
devfdname, mntpath, NULL);
w = waitpid(f, &status, 0);
if ( w != f || status ) {
- if ( !euid )
- rmdir(mntpath);
+ rmdir(mntpath);
exit(1); /* Mount failed */
}
perror("fork");
exit(1);
} else if ( f == 0 ) {
- seteuid(0); /* ***BECOME ROOT*** */
- setuid(0);
execl(_PATH_UMOUNT, _PATH_UMOUNT, mntpath, NULL);
}
}
sync();
-
- if ( !euid ) {
- seteuid(0); /* *** BECOME ROOT *** */
- rmdir(mntpath); /* AS ROOT */
- seteuid(ruid);
- }
+ rmdir(mntpath);
if ( err )
exit(err);