scan for setresuid/setresgid and setgroups

no alternative implementation yet
This commit is contained in:
tg 2006-11-12 12:56:10 +00:00
parent 5b525d79fb
commit a799f50fea
3 changed files with 23 additions and 4 deletions

View File

@ -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 <sys/types.h>
#include <unistd.h>
int main(void) { setresuid(0,0,0); return (setresgid(0,0,0)); }
EOF
ac_test setgroups setresugid 0 <<-'EOF'
#include <sys/types.h>
#include <unistd.h>
int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
EOF
ac_test strlcpy <<-'EOF'
#include <string.h>
int main(int ac, char *av[]) { strlcpy(av[0], av[1], 1); return (ac); }

View File

@ -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

8
misc.c
View File

@ -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;
}