[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

personae management revised again



Hi there,

here is a small patch to MH-MiNT 1.12h2 that enhances the P_setre?id
functions a little bit. Now you can change your effective user/group id
back to your saved user/group id again.

Furthermore I have revised the MiNTLib binding for the set[r][e][ug]id.c
functions. The set[re][ug]id functions now check whether the
Psetre[ug]id call is present, if it is not, they will fall back to the
old behaviour by calling Pset[ug]id instead.

Instructions and patches follow after my signature.


       Sascha Blank
       Trier, den 28. Dezember 1994

/--------------------+---------------------------------------------------\
| Sascha Blank       | Voice (FAX/Data by arrangement): +49 (0)651 84831 |
| Brentanostrasse 21 |             FAX (always online): +49 (0)651 49895 |
| D-54294 Trier      |             InterNet: inf03@apollo23.uni-trier.de |
| Deutschland        |       PGP Key: available on request or use finger |
\--------------------+---------------------------------------------------/


Here's the patch to MiNT:

*** dos.c.orig	Wed Dec 28 14:19:00 1994
--- dos.c	Wed Dec 28 14:24:18 1994
***************
*** 203,209 ****
  	else if ((uid == curproc->ruid) || (uid == curproc->suid))
  		curproc->euid = uid;
  	else
! 	return EACCDN;
  
  	return uid;
  }
--- 203,209 ----
  	else if ((uid == curproc->ruid) || (uid == curproc->suid))
  		curproc->euid = uid;
  	else
! 		return EACCDN;
  
  	return uid;
  }
***************
*** 217,223 ****
  	else if ((gid == curproc->rgid) || (gid == curproc->sgid))
  		curproc->egid = gid;
  	else
! 	return EACCDN;
  
  	return gid;
  }
--- 217,223 ----
  	else if ((gid == curproc->rgid) || (gid == curproc->sgid))
  		curproc->egid = gid;
  	else
! 		return EACCDN;
  
  	return gid;
  }
***************
*** 237,243 ****
  	}
  
  	if (euid != -1) {
! 		if ((old_ruid == euid) || (curproc->euid == euid) || (curproc->euid == 0))
  			curproc->euid = euid;
  		else {
  			curproc->ruid = old_ruid;
--- 237,243 ----
  	}
  
  	if (euid != -1) {
! 		if ((curproc->euid == euid) || (old_ruid == euid) || (curproc->suid = euid) || (curproc->euid == 0))
  			curproc->euid = euid;
  		else {
  			curproc->ruid = old_ruid;
***************
*** 265,271 ****
  	}
  
  	if (egid != -1) {
! 		if ((old_rgid == egid) || (curproc->egid == egid) || (curproc->euid == 0))
  			curproc->egid = egid;
  		else {
  			curproc->rgid = old_rgid;
--- 265,271 ----
  	}
  
  	if (egid != -1) {
! 		if ((curproc->egid == egid) || (old_rgid == egid) || (curproc->sgid == egid) || (curproc->euid == 0))
  			curproc->egid = egid;
  		else {
  			curproc->rgid = old_rgid;



Here are the patches to the MiNTLibs:

a) Check if mintbind.h contains any the following lines; if not, add
those missing:

#define Pseteuid(id)						\
		(int)trap_1_ww(0x143, (short)(id))
#define Psetegid(id)						\
		(int)trap_1_ww(0x144, (short)(id))
#define Psetreuid(rid, eid)					\
		(int)trap_1_www(0x14E, (short)(rid), (short)(eid))
#define Psetregid(rid, eid)					\
		(int)trap_1_www(0x14F, (short)(rid), (short)(eid))

b) Check if unistd.h and unixlib.h contain any of the following lines; if not,
add those missing to both files:

__EXTERN int	setegid	__PROTO((int));
__EXTERN int	seteuid	__PROTO((int));
__EXTERN int	setrgid	__PROTO((int));
__EXTERN int	setruid	__PROTO((int));
__EXTERN int	setregid __PROTO((int, int));
__EXTERN int	setreuid __PROTO((int, int));

c) unshar the following file, compile all set*.c files and replace the
old ones in your gnu.olb, bgnu.olb, gnu16.olb and bgnu16.olb

---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1994-12-28 14:54 MET by <root@sliphost39>.
# Source directory was `/e'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    381 -rw-r--r-- setegid.c
#    381 -rw-r--r-- seteuid.c
#    412 -rw-r--r-- setregid.c
#    412 -rw-r--r-- setreuid.c
#    386 -rw-r--r-- setrgid.c
#    386 -rw-r--r-- setruid.c
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  echo 'WARNING: not restoring timestamps.  Consider getting and'
  echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
# ============= setegid.c ==============
if test -f 'setegid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping setegid.c (file already exists)'
else
  echo 'x - extracting setegid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'setegid.c' &&
#include <types.h>
#include <unistd.h>
#include <osbind.h>
#include <mintbind.h>
#include <errno.h>
X
extern int __mint;
X
int
setegid(x)
X  int x;
{
X  int r = 0;
X
X  if (__mint) {
X    r = Psetegid(x);
X
X    if (r == -EINVAL) {		/* function does not exist, call emulation */
X      r = setgid (x);
X    } else if (r < 0) {
X      errno = (int) -r;
X      r = -1;
X    }
X  }
X
X  return (r);
}
SHAR_EOF
  $shar_touch -am 1228143994 'setegid.c' &&
  chmod 0644 'setegid.c' ||
  echo 'restore of setegid.c failed'
  shar_count="`wc -c < 'setegid.c'`"
  test 381 -eq "$shar_count" ||
    echo "setegid.c: original size 381, current size $shar_count"
fi
# ============= seteuid.c ==============
if test -f 'seteuid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping seteuid.c (file already exists)'
else
  echo 'x - extracting seteuid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'seteuid.c' &&
#include <types.h>
#include <unistd.h>
#include <osbind.h>
#include <mintbind.h>
#include <errno.h>
X
extern int __mint;
X
int
seteuid(x)
X  int x;
{
X  int r = 0;
X
X  if (__mint) {
X    r = Pseteuid(x);
X
X    if (r == -EINVAL) {		/* function does not exist, call emulation */
X      r = setuid (x);
X    } else if (r < 0) {
X      errno = (int) -r;
X      r = -1;
X    }
X  }
X
X  return (r);
}
SHAR_EOF
  $shar_touch -am 1228143994 'seteuid.c' &&
  chmod 0644 'seteuid.c' ||
  echo 'restore of seteuid.c failed'
  shar_count="`wc -c < 'seteuid.c'`"
  test 381 -eq "$shar_count" ||
    echo "seteuid.c: original size 381, current size $shar_count"
fi
# ============= setregid.c ==============
if test -f 'setregid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping setregid.c (file already exists)'
else
  echo 'x - extracting setregid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'setregid.c' &&
#include <types.h>
#include <unistd.h>
#include <osbind.h>
#include <mintbind.h>
#include <errno.h>
X
extern int __mint;
X
int
setregid(rgid, egid)
X  int rgid, egid;
{
X  int r = 0;
X
X  if (__mint) {
X    r = Psetregid(rgid, egid);
X
X    if (r == -EINVAL) {		/* function does not exist, call emulation */
X      r = setgid (egid);
X    } else if (r < 0) {
X      errno = (int) -r;
X      r = -1;
X    }
X  }
X
X  return r;
}
X
SHAR_EOF
  $shar_touch -am 1228143994 'setregid.c' &&
  chmod 0644 'setregid.c' ||
  echo 'restore of setregid.c failed'
  shar_count="`wc -c < 'setregid.c'`"
  test 412 -eq "$shar_count" ||
    echo "setregid.c: original size 412, current size $shar_count"
fi
# ============= setreuid.c ==============
if test -f 'setreuid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping setreuid.c (file already exists)'
else
  echo 'x - extracting setreuid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'setreuid.c' &&
#include <types.h>
#include <unistd.h>
#include <osbind.h>
#include <mintbind.h>
#include <errno.h>
X
extern int __mint;
X
int
setreuid(ruid, euid)
X  int ruid, euid;
{
X  int r = 0;
X
X  if (__mint) {
X    r = Psetreuid(ruid, euid);
X
X    if (r == -EINVAL) {		/* function does not exist, call emulation */
X      r = setuid (euid);
X    } else if (r < 0) {
X      errno = (int) -r;
X      r = -1;
X    }
X  }
X
X  return r;
}
X
SHAR_EOF
  $shar_touch -am 1228143994 'setreuid.c' &&
  chmod 0644 'setreuid.c' ||
  echo 'restore of setreuid.c failed'
  shar_count="`wc -c < 'setreuid.c'`"
  test 412 -eq "$shar_count" ||
    echo "setreuid.c: original size 412, current size $shar_count"
fi
# ============= setrgid.c ==============
if test -f 'setrgid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping setrgid.c (file already exists)'
else
  echo 'x - extracting setrgid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'setrgid.c' &&
#include <types.h>
#include <unistd.h>
#include <osbind.h>
#include <mintbind.h>
#include <errno.h>
X
extern int __mint;
X
int
setrgid(x)
X  int x;
{
X  int r = 0;
X
X  if (__mint) {
X    r = Psetregid(x, -1);
X
X    if (r == -EINVAL) {		/* function does not exist, call emulation */
X      r = setgid (x);
X    } else if (r < 0) {
X      errno = (int) -r;
X      r = -1;
X    }
X  }
X
X  return (r);
}
SHAR_EOF
  $shar_touch -am 1228143994 'setrgid.c' &&
  chmod 0644 'setrgid.c' ||
  echo 'restore of setrgid.c failed'
  shar_count="`wc -c < 'setrgid.c'`"
  test 386 -eq "$shar_count" ||
    echo "setrgid.c: original size 386, current size $shar_count"
fi
# ============= setruid.c ==============
if test -f 'setruid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping setruid.c (file already exists)'
else
  echo 'x - extracting setruid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'setruid.c' &&
#include <types.h>
#include <unistd.h>
#include <osbind.h>
#include <mintbind.h>
#include <errno.h>
X
extern int __mint;
X
int
setruid(x)
X  int x;
{
X  int r = 0;
X
X  if (__mint) {
X    r = Psetreuid(x, -1);
X
X    if (r == -EINVAL) {		/* function does not exist, call emulation */
X      r = setuid (x);
X    } else if (r < 0) {
X      errno = (int) -r;
X      r = -1;
X    }
X  }
X
X  return (r);
}
SHAR_EOF
  $shar_touch -am 1228143994 'setruid.c' &&
  chmod 0644 'setruid.c' ||
  echo 'restore of setruid.c failed'
  shar_count="`wc -c < 'setruid.c'`"
  test 386 -eq "$shar_count" ||
    echo "setruid.c: original size 386, current size $shar_count"
fi
exit 0