support systems without setresugid

This commit is contained in:
tg 2006-11-16 13:35:07 +00:00
parent d3dea44bb5
commit 8adc4a2c56
2 changed files with 21 additions and 3 deletions

12
main.c
View File

@ -13,10 +13,15 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.61 2006/11/12 14:58:15 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.62 2006/11/16 13:35:07 tg Exp $");
extern char **environ;
#if !HAVE_SETRESUGID
extern uid_t kshuid;
extern gid_t kshgid, kshegid;
#endif
static void reclaim(void);
static void remove_temps(struct temp *);
@ -220,7 +225,12 @@ main(int argc, char *argv[])
setstr(vp, safe_prompt, KSH_RETURN_ERROR);
/* Set this before parsing arguments */
#if HAVE_SETRESUGID
Flag(FPRIVILEGED) = getuid() != ksheuid || getgid() != getegid();
#else
Flag(FPRIVILEGED) = (kshuid = getuid()) != ksheuid ||
(kshgid = getgid()) != (kshegid = getegid());
#endif
/* this to note if monitor is set on command line (see below) */
Flag(FMONITOR) = 127;

12
misc.c
View File

@ -6,7 +6,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.42 2006/11/12 14:58:15 tg Exp $\t"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.43 2006/11/16 13:35:07 tg Exp $\t"
MKSH_SH_H_ID);
#undef USE_CHVT
@ -16,6 +16,11 @@ __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.42 2006/11/12 14:58:15 tg Exp $\t"
unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */
#if !HAVE_SETRESUGID
uid_t kshuid;
gid_t kshgid, kshegid;
#endif
static int do_gmatch(const unsigned char *, const unsigned char *,
const unsigned char *, const unsigned char *);
static const unsigned char *cclass(const unsigned char *, int);
@ -251,7 +256,10 @@ change_flag(enum sh_flag f,
#endif
setresuid(ksheuid, ksheuid, ksheuid);
#else
#error setresid/setresgid required at the moment
seteuid(ksheuid = kshuid = getuid());
setuid(ksheuid);
setegid(kshegid = kshgid = getgid());
setgid(kshegid);
#endif
} else if (f == FPOSIX && newval) {
Flag(FBRACEEXPAND) = 0;