Moved them into the setgid server since they need to access kvm data.
1999-05-08 Martin Baulig <martin@home-of-linux.org> * shm_limits.c, msg_limits.c, sem_limits.c: Moved them into the setgid server since they need to access kvm data. * open_suid.c, close_suid.c: New file. We do the initialization and cleanup for the setgid server here. * glibtop_suid.h: New file. We include this in the setgid files. * open.c: Moved kvm opening code into open_suid.c.
This commit is contained in:
committed by
Martin Baulig
parent
3a7d7778a0
commit
e8a3a40691
@@ -4,3 +4,4 @@ Makefile
|
||||
Makefile.in
|
||||
libgtop_sysdeps.la
|
||||
*.lo
|
||||
libgtop_sysdeps_suid.la
|
||||
|
@@ -1,3 +1,17 @@
|
||||
1999-05-08 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Use the setgid server for IPC Limits.
|
||||
|
||||
* shm_limits.c, msg_limits.c, sem_limits.c: Moved them into the
|
||||
setgid server since they need to access kvm data.
|
||||
|
||||
* open_suid.c, close_suid.c: New file. We do the initialization and cleanup
|
||||
for the setgid server here.
|
||||
|
||||
* glibtop_suid.h: New file. We include this in the setgid files.
|
||||
|
||||
* open.c: Moved kvm opening code into open_suid.c.
|
||||
|
||||
1999-05-07 Drazen Kacar <dave@srce.hr>
|
||||
|
||||
* glibtop_machine.h, open.c, mem.c, procmem.c: machine.pagesize
|
||||
|
@@ -2,17 +2,22 @@ LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = @INCLUDES@
|
||||
|
||||
lib_LTLIBRARIES = libgtop_sysdeps.la
|
||||
lib_LTLIBRARIES = libgtop_sysdeps.la libgtop_sysdeps_suid.la
|
||||
|
||||
libgtop_sysdeps_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
|
||||
uptime.c loadavg.c shm_limits.c msg_limits.c \
|
||||
sem_limits.c proclist.c procstate.c procuid.c \
|
||||
uptime.c loadavg.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c procargs.c procmap.c netload.c \
|
||||
ppp.c procdata.c
|
||||
|
||||
libgtop_sysdeps_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
libgtop_sysdeps_suid_la_SOURCES = open_suid.c close_suid.c \
|
||||
shm_limits.c msg_limits.c sem_limits.c
|
||||
|
||||
libgtop_sysdeps_suid_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
|
||||
include_HEADERS = glibtop_server.h glibtop_machine.h
|
||||
noinst_HEADERS = glibtop_private.h
|
||||
|
||||
|
30
sysdeps/solaris/close_suid.c
Normal file
30
sysdeps/solaris/close_suid.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop 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 General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop/close.h>
|
||||
|
||||
/* Closes pipe to gtop server. */
|
||||
|
||||
void
|
||||
glibtop_close_p (glibtop *server)
|
||||
{ }
|
@@ -31,9 +31,9 @@ BEGIN_LIBGTOP_DECLS
|
||||
#define GLIBTOP_SUID_SWAP 0
|
||||
#define GLIBTOP_SUID_UPTIME 0
|
||||
#define GLIBTOP_SUID_LOADAVG 0
|
||||
#define GLIBTOP_SUID_SHM_LIMITS 0
|
||||
#define GLIBTOP_SUID_MSG_LIMITS 0
|
||||
#define GLIBTOP_SUID_SEM_LIMITS 0
|
||||
#define GLIBTOP_SUID_SHM_LIMITS (1L << GLIBTOP_SYSDEPS_SHM_LIMITS)
|
||||
#define GLIBTOP_SUID_MSG_LIMITS (1L << GLIBTOP_SYSDEPS_MSG_LIMITS)
|
||||
#define GLIBTOP_SUID_SEM_LIMITS (1L << GLIBTOP_SYSDEPS_SEM_LIMITS)
|
||||
#define GLIBTOP_SUID_PROCLIST 0
|
||||
#define GLIBTOP_SUID_PROC_STATE 0
|
||||
#define GLIBTOP_SUID_PROC_UID 0
|
||||
|
48
sysdeps/solaris/glibtop_suid.h
Normal file
48
sysdeps/solaris/glibtop_suid.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop 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 General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_SUID_H__
|
||||
#define __GLIBTOP_SUID_H__
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setreuid (server->machine.uid, server->machine.euid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
void
|
||||
glibtop_init_p (glibtop *server, const unsigned long features,
|
||||
const unsigned flags);
|
||||
void
|
||||
glibtop_open_p (glibtop *server, const char *program_name,
|
||||
const unsigned long features,
|
||||
const unsigned flags);
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -37,7 +37,7 @@ static const unsigned long _glibtop_sysdeps_msg_limits =
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_msg_limits_s (glibtop *server)
|
||||
glibtop_init_msg_limits_p (glibtop *server)
|
||||
{
|
||||
kvm_t *kd = server->machine.kd;
|
||||
|
||||
@@ -50,7 +50,7 @@ glibtop_init_msg_limits_s (glibtop *server)
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
|
||||
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
||||
{
|
||||
kvm_t *kd = server->machine.kd;
|
||||
struct msginfo minfo;
|
||||
|
@@ -189,11 +189,4 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
server->machine.kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
|
||||
if(!server->machine.kd)
|
||||
glibtop_warn_io_r(server, "kvm_open()");
|
||||
|
||||
fprintf (stderr, "Sleeping 2 seconds, please wait ...\n");
|
||||
sleep (2);
|
||||
}
|
||||
|
92
sysdeps/solaris/open_suid.c
Normal file
92
sysdeps/solaris/open_suid.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop 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 General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/open.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
|
||||
|
||||
void
|
||||
glibtop_init_p (glibtop *server, const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
glibtop_init_func_t *init_fkt;
|
||||
|
||||
if (server == NULL)
|
||||
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
|
||||
|
||||
/* Do the initialization, but only if not already initialized. */
|
||||
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
|
||||
glibtop_open_p (server, "glibtop", features, flags);
|
||||
|
||||
for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
|
||||
(*init_fkt) (server);
|
||||
|
||||
server->flags |= _GLIBTOP_INIT_STATE_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
|
||||
|
||||
void
|
||||
glibtop_open_p (glibtop *server, const char *program_name,
|
||||
const unsigned long features, const unsigned flags)
|
||||
{
|
||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
|
||||
server->machine.kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
|
||||
if(!server->machine.kd)
|
||||
glibtop_warn_io_r(server, "kvm_open()");
|
||||
|
||||
/* Drop priviledges; we only become root when necessary.
|
||||
|
||||
setreuid (ruid, euid) - set real and effective user id;
|
||||
setregid (rgid, egid) - set real and effective group id;
|
||||
|
||||
*/
|
||||
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
||||
/* Our effective uid is now those of the user invoking the server,
|
||||
so we do no longer have any priviledges.
|
||||
*/
|
||||
}
|
@@ -38,7 +38,7 @@ static const unsigned long _glibtop_sysdeps_sem_limits =
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_sem_limits_s (glibtop *server)
|
||||
glibtop_init_sem_limits_p (glibtop *server)
|
||||
{
|
||||
kvm_t *kd = server->machine.kd;
|
||||
|
||||
@@ -51,7 +51,7 @@ glibtop_init_sem_limits_s (glibtop *server)
|
||||
/* Provides information about sysv sem limits. */
|
||||
|
||||
void
|
||||
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
|
||||
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||
{
|
||||
kvm_t *kd = server->machine.kd;
|
||||
struct seminfo sinfo;
|
||||
|
@@ -35,7 +35,7 @@ static const unsigned long _glibtop_sysdeps_shm_limits =
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_shm_limits_s (glibtop *server)
|
||||
glibtop_init_shm_limits_p (glibtop *server)
|
||||
{
|
||||
kvm_t *kd = server->machine.kd;
|
||||
|
||||
@@ -48,7 +48,7 @@ glibtop_init_shm_limits_s (glibtop *server)
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
|
||||
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||
{
|
||||
kvm_t *kd = server->machine.kd;
|
||||
struct shminfo sinfo;
|
||||
|
Reference in New Issue
Block a user