Removed. New files. Added `libgtop_server'; this has been moved here from

1998-08-07  Martin Baulig  <martin@home-of-linux.org>

	* src/server: Removed.
	* src/daemon/{server, version}.c: New files.
	* src/daemon/Makefile.am: Added `libgtop_server'; this has been
	moved here from `src/server' since it shares some source code files
	with the `libgtop_daemon'.

	* LIBGTOP-VERSION: Added `LIBGTOP_SERVER_VERSION'.
	* src/daemon/gnuserv.c, lib/open.c: Improved version check between
	client and server.

	* include/glibtop/output.h: Removed.

	* sysdeps/stub_suid: New directory. This is mainly used as example
	for people porting libgtop to other systems.

	* sysdeps/common/sysdeps_suid.c: New file.
	Defines `glibtop_init_hook_p'.

	* sysdeps/osf1/*.c (glibtop_init_<no-suid-feature>_s): New functions.
	(glibtop_init_<suid-feature>_p): New functions.
This commit is contained in:
Martin Baulig
1998-08-07 12:59:00 +00:00
committed by Martin Baulig
parent 3b4e0378f9
commit a510ed1271
35 changed files with 473 additions and 65 deletions

View File

@@ -1,10 +1,4 @@
if NEED_LIBGTOP
server_SUBDIRS = server
else
server_SUBDIRS =
endif
SUBDIRS = daemon
SUBDIRS = $(server_SUBDIRS) daemon
DIST_SUBDIRS = server daemon
DIST_SUBDIRS = daemon

View File

@@ -5,18 +5,30 @@ CFLAGS = -Wall -W @CFLAGS@ \
-DPARENT_DEBUG -DSLAVE_DEBUG \
-DGLIBTOP_DAEMON_SLAVE
bin_PROGRAMS = libgtop_daemon
if NEED_LIBGTOP
suid_sysdeps = $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps_suid.la
suid_common = $(top_builddir)/sysdeps/common/libgtop_suid_common.la
else
suid_sysdeps =
suid_common =
endif
libgtop_daemon_SOURCES = gnuserv.c slave.c main.c io.c
bin_PROGRAMS = libgtop_daemon @server_programs@
EXTRA_PROGRAMS = libgtop_server
libgtop_daemon_SOURCES = gnuserv.c slave.c main.c io.c version.c
libgtop_daemon_LDADD = $(top_builddir)/lib/libgtop.la \
$(top_builddir)/sysdeps/common/libgtop_common.la \
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
@sysdeps_suid_lib@ \
$(suid_sysdeps) $(suid_common)\
@INTLLIBS@ @LIBSUPPORT@ @X_LIBS@ -lXau
libgtop_daemon_LDFLAGS = -static
libgtop_server_SOURCES = server.c slave.c io.c version.c
libgtop_server_LDADD = $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps_suid.la \
$(top_builddir)/sysdeps/common/libgtop_suid_common.la \
@LIBSUPPORT@
libgtop_server_LDFLAGS = -static

View File

@@ -32,17 +32,27 @@ do_output (int s, glibtop_response *resp, off_t offset,
resp->offset = offset;
resp->data_size = data_size;
if (send (s, resp, sizeof (glibtop_response), 0) < 0)
glibtop_warn_io ("send");
if (s == 0) {
if (write (1, resp, sizeof (glibtop_response)) < 0)
glibtop_warn_io ("write");
} else {
if (send (s, resp, sizeof (glibtop_response), 0) < 0)
glibtop_warn_io ("send");
}
if (resp->data_size) {
#ifdef REAL_DEBUG
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
#endif
if (send (s, data, resp->data_size, 0) , 0)
glibtop_warn_io ("send");
if (s == 0) {
if (write (1, data, resp->data_size) < 0)
glibtop_warn_io ("write");
} else {
if (send (s, data, resp->data_size, 0) , 0)
glibtop_warn_io ("send");
}
}
}

View File

@@ -33,6 +33,8 @@ handle_parent_connection (int s)
pid_t pid;
void *ptr;
glibtop_send_version (glibtop_global_server, s);
fprintf (stderr, "Parent features = %lu\n", glibtop_server_features);
#ifdef DEBUG

88
src/daemon/server.c Normal file
View File

@@ -0,0 +1,88 @@
/* $Id$ */
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top 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 Gnome Top 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 "daemon.h"
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = &_glibtop_global_server;
#include <glibtop.h>
#include <glibtop/union.h>
#include <glibtop/sysdeps.h>
const unsigned long glibtop_server_features =
GLIBTOP_SUID_CPU +
GLIBTOP_SUID_MEM +
GLIBTOP_SUID_SWAP +
GLIBTOP_SUID_UPTIME +
GLIBTOP_SUID_LOADAVG +
GLIBTOP_SUID_SHM_LIMITS +
GLIBTOP_SUID_MSG_LIMITS +
GLIBTOP_SUID_SEM_LIMITS +
GLIBTOP_SUID_PROCLIST +
GLIBTOP_SUID_PROC_STATE +
GLIBTOP_SUID_PROC_UID +
GLIBTOP_SUID_PROC_MEM +
GLIBTOP_SUID_PROC_TIME +
GLIBTOP_SUID_PROC_SIGNAL +
GLIBTOP_SUID_PROC_KERNEL +
GLIBTOP_SUID_PROC_SEGMENT;
#include <fcntl.h>
#include <locale.h>
#if defined(HAVE_GETDTABLESIZE)
#define GET_MAX_FDS() getdtablesize()
#else
/* Fallthrough case - please add other #elif cases above
for different OS's as necessary */
#define GET_MAX_FDS() 256
#endif
int
main(int argc, char *argv[])
{
int fd, max_fd;
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
int uid, euid, gid, egid;
uid = getuid (); euid = geteuid ();
gid = getgid (); egid = getegid ();
glibtop_open_p (glibtop_global_server, argv [0], 0, 0);
if (setreuid (euid, uid)) _exit (1);
if (setregid (egid, gid)) _exit (1);
/* !!! END OF SUID ROOT PART !!! */
/* close all file descriptors except ones used by the pipes (0 and 1). */
max_fd = GET_MAX_FDS();
for(fd = 3 /* The first fd after the pipes */; fd < max_fd; fd++)
close(fd);
handle_slave_connection (0, 0);
_exit (0);
}

View File

@@ -30,6 +30,8 @@ handle_slave_connection (int input, int output)
char parameter [BUFSIZ];
void *ptr;
glibtop_send_version (glibtop_global_server, output);
while (do_read (input, cmnd, sizeof (glibtop_command))) {
#ifdef SLAVE_DEBUG
fprintf (stderr, "Slave %d received command "

58
src/daemon/version.c Normal file
View File

@@ -0,0 +1,58 @@
/* $Id$ */
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top 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 Gnome Top 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 <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/version.h>
void
glibtop_send_version (glibtop *server, int fd)
{
char buffer [BUFSIZ];
size_t size;
sprintf (buffer, LIBGTOP_VERSION_STRING,
LIBGTOP_VERSION, LIBGTOP_SERVER_VERSION,
sizeof (glibtop_command),
sizeof (glibtop_response),
sizeof (glibtop_union),
sizeof (glibtop_sysdeps));
size = strlen (buffer) + 1;
fprintf (stderr, "SERVER ID: |%s|\n", buffer);
if (fd == 0) {
if (write (1, &size, sizeof (size)) < 0)
glibtop_warn_io_r (server, "write");
} else {
if (send (fd, &size, sizeof (size), 0) < 0)
glibtop_warn_io_r (server, "send");
}
if (fd == 0) {
if (write (1, buffer, size) < 0)
glibtop_warn_io_r (server, "write");
} else {
if (send (fd, buffer, size, 0) < 0)
glibtop_warn_io_r (server, "send");
}
}