This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Some more uid32 fixes and cleanups


Hi!

This is on top of the previous uid32 patch I've posted:

2000-01-17  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c: New file.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c: New file.
	* sysdeps/unix/sysv/linux/sparc/sparc32/Dist: Remove setres[ug]id.
	* sysdeps/unix/sysv/linux/sparc/sparc32/mmap64.c: Kill warnings.
	* sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list: Define needed
	syscalls.
	* sysdeps/unix/sysv/linux/pwrite64.c: Use proper prototype.
	* sysdeps/unix/sysv/linux/truncate64.c: Likewise.
	* sysdeps/unix/sysv/linux/kernel-features.h: [gs]etres[ug]id are
	available on sparc since 2.3.39.
	* sysdeps/unix/sysv/linux/execve.c: Kill warnings.

--- ./linux/sparc/sparc32/seteuid.c.jj2	Fri Oct 16 18:31:38 1998
+++ ./linux/sparc/sparc32/seteuid.c	Mon Jan 17 14:48:51 2000
@@ -1 +1,55 @@
-#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
+/* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "kernel-features.h"
+
+#if defined __NR_setresuid32 || __ASSUME_SETRESUID_SYSCALL > 0
+
+extern int __setresuid (uid_t ruid, uid_t euid, uid_t suid);
+
+int
+seteuid (uid_t uid)
+{
+  int result;
+
+  if (uid == (uid_t) ~0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  /* First try the syscall.  */
+  result = __setresuid (-1, uid, -1);
+# if __ASSUME_SETRESUID_SYSCALL == 0
+  if (result == -1 && errno == ENOSYS)
+    /* No system call available.  Use emulation.  This may not work
+       since `setreuid' also sets the saved user ID when UID is not
+       equal to the real user ID, making it impossible to switch back.  */
+    result = __setreuid (-1, uid);
+# endif
+
+  return result;
+}
+#else
+# include <sysdeps/unix/bsd/seteuid.c>
+#endif
--- ./linux/sparc/sparc32/Dist.jj2	Wed Feb  3 10:30:41 1999
+++ ./linux/sparc/sparc32/Dist	Mon Jan 17 14:35:46 2000
@@ -1,7 +1,5 @@
 clone.S
 kernel_stat.h
 init-first.h
-setresuid.c
-setresgid.c
 setfsuid.c
 setfsgid.c
--- ./linux/sparc/sparc32/mmap64.c.jj2	Mon Jan  3 07:35:31 2000
+++ ./linux/sparc/sparc32/mmap64.c	Mon Jan 17 15:09:16 2000
@@ -28,7 +28,7 @@
 #include "kernel-features.h"
 
 #ifdef __NR_mmap2
-extern int __syscall_mmap2(__ptr_t, size_t, int, int, int, off_t);
+extern __ptr_t __syscall_mmap2(__ptr_t, size_t, int, int, int, off_t);
 #ifndef __ASSUME_MMAP2_SYSCALL
 static int have_no_mmap2;
 #endif
@@ -48,11 +48,11 @@ __mmap64 (__ptr_t addr, size_t len, int 
       int saved_errno = errno;
 #endif
       /* This will be always 12, no matter what page size is.  */
-      int result = INLINE_SYSCALL (mmap2, 6, addr, len, prot, flags,
-				   fd, (off_t) (offset >> 12));
+      __ptr_t result = INLINE_SYSCALL (mmap2, 6, addr, len, prot, flags,
+				       fd, (off_t) (offset >> 12));
 
 #ifndef __ASSUME_MMAP2_SYSCALL
-      if (result != -1 || errno != ENOSYS)
+      if (result != (__ptr_t) -1 || errno != ENOSYS)
 #endif
 	return result;
 
--- ./linux/sparc/sparc32/syscalls.list.jj2	Mon Jan 17 09:03:50 2000
+++ ./linux/sparc/sparc32/syscalls.list	Mon Jan 17 14:59:33 2000
@@ -12,6 +12,10 @@ s_setreuid	setreuid setreuid	2	__syscall
 s_setrlimit	setrlimit setrlimit	3	__syscall_setrlimit
 s_ipc		msgget	ipc		5	__syscall_ipc
 s_setuid	setuid	setuid		1	__syscall_setuid
+setresuid	EXTRA	setresuid32	3	__setresuid	setresuid
+setresgid	EXTRA	setresgid32	3	__setresgid	setresgid
+getresuid	EXTRA	getresuid32	3	getresuid
+getresgid	EXTRA	getresgid32	3	getresgid
 
 # System calls with wrappers.
 rt_sigaction	-	rt_sigaction	4	__syscall_rt_sigaction
@@ -50,3 +52,25 @@ sys_mknod	xmknod	mknod		3	__syscall_mkno
 sys_readv	readv	readv		3	__syscall_readv
 sys_stat	xstat	stat		2	__syscall_stat
 sys_writev	writev	writev		3	__syscall_writev
+s_chown		chown	chown		3	__syscall_chown
+s_chown32	chown	chown32		3	__syscall_chown32
+s_fchown	fchown	fchown		3	__syscall_fchown
+s_fchown32	fchown	fchown32	3	__syscall_fchown32
+s_lchown	lchown	lchown		3	__syscall_lchown
+s_lchown32	lchown	lchown32	3	__syscall_lchown32
+s_getgid	getgid	getgid		0	__syscall_getgid
+s_getgid32	getgid	getgid32	0	__syscall_getgid32
+s_getuid	getuid	getuid		0	__syscall_getuid
+s_getuid32	getuid	getuid32	0	__syscall_getuid32
+s_getgroups32	getgroups getgroups32	2	__syscall_getgroups32
+s_setgroups32	setgroups setgroups32	2	__syscall_setgroups32
+s_setfsgid32	setfsgid setfsgid32	1	__syscall_setfsgid32
+s_setfsuid32	setfsuid setfsuid32	1	__syscall_setfsuid32
+s_setregid32	setregid setregid32	2	__syscall_setregid32
+s_setreuid32	setreuid setreuid32	2	__syscall_setreuid32
+s_getegid	getegid	getegid		0	__syscall_getegid
+s_geteuid	geteuid	geteuid		0	__syscall_geteuid
+s_getegid32	getegid	getegid32	0	__syscall_getegid32
+s_geteuid32	geteuid	geteuid32	0	__syscall_geteuid32
+s_setgid32	setgid	setgid32	1	__syscall_setgid32
+s_setuid32	setuid	setuid32	1	__syscall_setuid32
--- ./linux/sparc/sparc32/setegid.c.jj2	Fri Oct 16 18:31:05 1998
+++ ./linux/sparc/sparc32/setegid.c	Mon Jan 17 14:50:24 2000
@@ -1 +1,51 @@
-#include <sysdeps/unix/sysv/linux/i386/setegid.c>
+/* Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef __NR_setresgid32
+
+extern int __setresgid (gid_t rgid, gid_t egid, gid_t sgid);
+
+int
+setegid (gid_t gid)
+{
+  int result;
+
+  if (gid == (gid_t) ~0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  /* First try the syscall.  */
+  result = __setresgid (-1, gid, -1);
+  if (result == -1 && errno == ENOSYS)
+    /* No system call available.  Use emulation.  This may not work
+       since `setregid' also sets the saved group ID when GID is not
+       equal to the real group ID, making it impossible to switch back. */
+    result = __setregid (-1, gid);
+
+  return result;
+}
+#else
+# include <sysdeps/unix/bsd/setegid.c>
+#endif
--- ./linux/pwrite64.c.jj2	Tue Dec 21 11:08:05 1999
+++ ./linux/pwrite64.c	Mon Jan 17 15:06:10 2000
@@ -27,8 +27,8 @@
 
 #if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
 
-extern ssize_t __syscall_pwrite64 (int fd, const void *buf, size_t count,
-				   off_t offset_hi, off_t offset_lo);
+extern ssize_t __syscall_pwrite (int fd, const void *buf, size_t count,
+				 off_t offset_hi, off_t offset_lo);
 
 # if __ASSUME_PWRITE_SYSCALL == 0
 static ssize_t __emulate_pwrite64 (int fd, const void *buf, size_t count,
--- ./linux/kernel-features.h.jj2	Mon Jan 17 07:58:55 2000
+++ ./linux/kernel-features.h	Mon Jan 17 14:46:46 2000
@@ -66,7 +66,7 @@
 #endif
 
 /* When did the `setresuid' sysall became available?  */
-#if __LINUX_KERNEL_VERSION >= 131584
+#if __LINUX_KERNEL_VERSION >= 131584 && !defined __sparc__
 # define __ASSUME_SETRESUID_SYSCALL	1
 #endif
 
@@ -106,4 +106,7 @@
 /* Linux 2.3.39 introduced 32bit UID/GIDs.  */
 #if __LINUX_KERNEL_VERSION >= 131879
 # define __ASSUME_32BITUIDS		1
+# ifdef __sparc__
+#  define __ASSUME_SETRESUID_SYSCALL	1
+# endif
 #endif
--- ./linux/truncate64.c.jj2	Mon Jan 17 07:58:55 2000
+++ ./linux/truncate64.c	Mon Jan 17 15:07:43 2000
@@ -31,7 +31,7 @@
 int __have_no_truncate64;
 #endif
 
-extern int __syscall_truncate64 (int fd, int high_length, int low_length);
+extern int __syscall_truncate64 (const char *path, int high_length, int low_length);
 
 
 /* Truncate the file FD refers to to LENGTH bytes.  */
--- ./linux/execve.c.jj2	Tue Nov 16 21:18:17 1999
+++ ./linux/execve.c	Mon Jan 17 15:11:31 2000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -22,7 +22,8 @@
 #include <sysdep.h>
 #include <sys/syscall.h>
 
-extern int __syscall_execve (const char *file, char **argv, char **envp);
+extern int __syscall_execve (const char *file, char * const argv[],
+			     char * const envp[]);
 extern void __pthread_kill_other_threads_np __P ((void));
 weak_extern (__pthread_kill_other_threads_np)
 


Cheers,
    Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.39 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]