make setuid/setgid scripts and access() work again
by reverting some OpenBSD and applying some Debian diff
This commit is contained in:
29
var.c
29
var.c
@ -1,4 +1,4 @@
|
||||
/** $MirOS: src/bin/mksh/var.c,v 1.3 2005/05/23 15:36:56 tg Exp $ */
|
||||
/** $MirOS: src/bin/mksh/var.c,v 1.4 2005/05/25 13:46:02 tg Exp $ */
|
||||
/* $OpenBSD: var.c,v 1.26 2005/03/30 17:16:37 deraadt Exp $ */
|
||||
|
||||
#include "sh.h"
|
||||
@ -6,7 +6,7 @@
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.3 2005/05/23 15:36:56 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.4 2005/05/25 13:46:02 tg Exp $");
|
||||
|
||||
/*
|
||||
* Variables
|
||||
@ -981,7 +981,7 @@ setspec(struct tbl *vp)
|
||||
struct stat statb;
|
||||
|
||||
s = str_val(vp);
|
||||
if (s[0] == '/' && access(s, W_OK|X_OK) == 0 &&
|
||||
if (s[0] == '/' && eaccess(s, W_OK|X_OK) == 0 &&
|
||||
stat(s, &statb) == 0 && S_ISDIR(statb.st_mode))
|
||||
tmpdir = str_save(s, APERM);
|
||||
}
|
||||
@ -1179,3 +1179,26 @@ set_array(const char *var, int reset, char **vals)
|
||||
setstr(vq, vals[i], KSH_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
eaccess(const char *pathname, int mode)
|
||||
{
|
||||
bool need_uid, need_gid;
|
||||
int rv, _errno;
|
||||
|
||||
if ((need_gid = (kshgid != kshegid)))
|
||||
setregid(kshegid, kshgid);
|
||||
if ((need_uid = (kshuid != ksheuid)))
|
||||
setreuid(ksheuid, kshuid);
|
||||
|
||||
rv = access(pathname, mode);
|
||||
_errno = errno;
|
||||
|
||||
if (need_gid)
|
||||
setregid(kshgid, kshegid);
|
||||
if (need_uid)
|
||||
setreuid(kshuid, ksheuid);
|
||||
|
||||
errno = _errno;
|
||||
return (rv);
|
||||
}
|
||||
|
Reference in New Issue
Block a user