From a799f50fea511549a95d31e4f5f52fbae2c33c89 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 12 Nov 2006 12:56:10 +0000 Subject: [PATCH] scan for setresuid/setresgid and setgroups no alternative implementation yet --- Build.sh | 14 +++++++++++++- Makefile | 5 +++-- misc.c | 8 +++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Build.sh b/Build.sh index 230b3c5..2eff9da 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $MirOS: src/bin/mksh/Build.sh,v 1.75 2006/11/10 07:18:56 tg Exp $ +# $MirOS: src/bin/mksh/Build.sh,v 1.76 2006/11/12 12:56:09 tg Exp $ #- # Environment: CC, CFLAGS, CPPFLAGS, LDFLAGS, LIBS, NROFF @@ -236,6 +236,18 @@ ac_test setmode mksh_full 1 <<-'EOF' int main(int ac, char *av[]) { setmode(av[0]); return (ac); } EOF +ac_test setresugid <<-'EOF' + #include + #include + int main(void) { setresuid(0,0,0); return (setresgid(0,0,0)); } +EOF + +ac_test setgroups setresugid 0 <<-'EOF' + #include + #include + int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); } +EOF + ac_test strlcpy <<-'EOF' #include int main(int ac, char *av[]) { strlcpy(av[0], av[1], 1); return (ac); } diff --git a/Makefile b/Makefile index d2de953..6ac1335 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ -# $MirOS: src/bin/mksh/Makefile,v 1.17 2006/11/09 15:03:56 tg Exp $ +# $MirOS: src/bin/mksh/Makefile,v 1.18 2006/11/12 12:56:09 tg Exp $ PROG= mksh SRCS= alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c \ jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c CPPFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_ARC4RANDOM_PUSH -DHAVE_SYS_PARAM_H CPPFLAGS+= -DHAVE_LANGINFO_CODESET -DHAVE_SETLOCALE_CTYPE -CPPFLAGS+= -DHAVE_SETMODE -DHAVE_STRLCPY +CPPFLAGS+= -DHAVE_SETMODE -DHAVE_SETRESUGID -DHAVE_SETGROUPS +CPPFLAGS+= -DHAVE_STRLCPY CDIAGFLAGS+= -Wno-cast-qual LINKS+= ${BINDIR}/${PROG} ${BINDIR}/sh diff --git a/misc.c b/misc.c index 51cd29c..ebb4365 100644 --- a/misc.c +++ b/misc.c @@ -3,7 +3,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.39 2006/11/10 19:11:57 tg Exp $\t" +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.40 2006/11/12 12:56:10 tg Exp $\t" MKSH_SH_H_ID); #undef USE_CHVT @@ -239,11 +239,17 @@ change_flag(enum sh_flag f, Flag(f) = newval; } else if (f == FPRIVILEGED && oldval && !newval) { /* Turning off -p? */ +#if HAVE_SETRESUGID gid_t kshegid = getgid(); setresgid(kshegid, kshegid, kshegid); +#if HAVE_SETGROUPS setgroups(1, &kshegid); +#endif setresuid(ksheuid, ksheuid, ksheuid); +#else +#error setresid/setresgid required at the moment +#endif } else if (f == FPOSIX && newval) { Flag(FBRACEEXPAND) = 0; }