From 595553ae0b921cf749563d9c61a83d5d16703c94 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Thu, 23 Dec 1999 13:08:51 +0000 Subject: [PATCH] Removed all remote communication support from LibGTop. 1999-12-23 Martin Baulig Removed all remote communication support from LibGTop. * include/glibtop/gnuserv.h: Removed. * sysdeps/common/gnuslib.c: Removed. * src/daemon/Makefile.am: Don't build the `libgtop_daemon' binary any longer. * src/daemon/server_config.pl: Removed. * src/daemon/server_config.h.in: Removed. * src/daemon/server_config.h: Removed. --- ChangeLog | 15 ++ include/glibtop/Makefile.am | 2 +- include/glibtop/gnuserv.h | 161 --------------- po/POTFILES.in | 3 - src/daemon/Makefile.am | 18 +- src/daemon/server_config.h | 11 - src/daemon/server_config.h.in | 44 ---- src/daemon/server_config.pl | 111 ---------- src/daemon/slave.c | 2 +- sysdeps/common/Makefile.am | 2 +- sysdeps/common/gnuslib.c | 375 ---------------------------------- 11 files changed, 19 insertions(+), 725 deletions(-) delete mode 100644 include/glibtop/gnuserv.h delete mode 100644 src/daemon/server_config.h delete mode 100644 src/daemon/server_config.h.in delete mode 100755 src/daemon/server_config.pl delete mode 100644 sysdeps/common/gnuslib.c diff --git a/ChangeLog b/ChangeLog index a9a255cd..9ea71002 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +1999-12-23 Martin Baulig + + Removed all remote communication support from LibGTop. + + * include/glibtop/gnuserv.h: Removed. + + * sysdeps/common/gnuslib.c: Removed. + + * src/daemon/Makefile.am: Don't build the `libgtop_daemon' + binary any longer. + + * src/daemon/server_config.pl: Removed. + * src/daemon/server_config.h.in: Removed. + * src/daemon/server_config.h: Removed. + 1999-12-22 Martin Baulig * lib/errors.c (glibtop_get_errno_l): New global function diff --git a/include/glibtop/Makefile.am b/include/glibtop/Makefile.am index 2e1fe413..06c6530e 100644 --- a/include/glibtop/Makefile.am +++ b/include/glibtop/Makefile.am @@ -5,7 +5,7 @@ glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \ proctime.h shm_limits.h version.h cpu.h msg_limits.h \ procmem.h procuid.h swap.h write.h error.h open.h \ procsegment.h read.h sysdeps.h xmalloc.h global.h \ - procsignal.h read_data.h union.h types.h gnuserv.h \ + procsignal.h read_data.h union.h types.h \ parameter.h mountlist.h fsusage.h procmap.h signal.h \ inodedb.h sysinfo.h ppp.h procargs.h netload.h \ netinfo.h interfaces.h limits.h array.h compat_10.h \ diff --git a/include/glibtop/gnuserv.h b/include/glibtop/gnuserv.h deleted file mode 100644 index 6f945c71..00000000 --- a/include/glibtop/gnuserv.h +++ /dev/null @@ -1,161 +0,0 @@ -/* -*-C-*- - - Header file for the GNU Emacs server and client C code. - - This file is part of GNU Emacs. - - Copying is permitted under those conditions described by the GNU - General Public License. - - Copyright (C) 1989 Free Software Foundation, Inc. - - Author: Andy Norman (ange@hplb.hpl.hp.com), based on - 'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU - Emacs distribution. - - Please mail bugs and suggestions to the author at the above address. -*/ - -/* HISTORY - * 11-Nov-1990 bristor@simba - * Added EOT stuff. - */ - -/* - * This file incorporates new features added by Bob Weiner , - * Darrell Kindred and Arup Mukherjee . - * Please see the note at the end of the README file for details. - * - * (If gnuserv came bundled with your emacs, the README file is probably - * ../etc/gnuserv.README relative to the directory containing this file) - */ - -#if 0 -static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup alpha !"; -#endif - -#define NO_SHORTNAMES - -#define PATCHLEVEL 2 - -#define NO_SHORTNAMES -/* gnuserv should not be compiled using SOCKS */ -#define DO_NOT_SOCKSIFY -#include -#include -#undef read -#undef write -#undef open -#undef close -#undef signal - -/* Define the communication method between server and clients: - * You can have either or both kinds of sockets, but you can't mix - * sockets with sysv ipc - */ - -#define INTERNET_DOMAIN_SOCKETS -#define UNIX_DOMAIN_SOCKETS - -/* - * Define additional authentication protocols to be used. These methods will - * be tried before falling back to the default gnuserv protocol (based on - * the GNU_SECURE environment variable). Currently, only MIT-MAGIC-COOKIE-1 - * is also supported. - * - * Comment out the next line(s) if you don't want to enable the - * appropriate authentication protocol. - */ - -#if defined (HAVE_XAUTH) -#define AUTH_MAGIC_COOKIE -#endif /* HAVE_XAUTH */ - -/* - * stuff related to supporting MIT-MAGIC-COOKIE-1 - */ - -#if 0 -#define MCOOKIE_SCREEN "42980" /* screen # to use as the gnuserv cookie */ -#endif -#define MCOOKIE_NAME "MAGIC-1" /* authentication protocol name */ -#define MCOOKIE_X_NAME "MIT-MAGIC-COOKIE-1" /* as needed by X */ - - -#define DEFAUTH_NAME "GNU-SECURE" /* name of default auth protocol */ -#define AUTH_TIMEOUT 15 /* # seconds to wait for auth data */ -#define AUTH_NAMESZ 15 /* max allows auth protocol name size */ - - -/* - * Pick a default communication scheme, if none was specified. - */ - -#if !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS) - -/* BSD systems use Unix Domain sockets by default */ - -#ifdef BSD -#define UNIX_DOMAIN_SOCKETS -#endif - -#endif /* No communication method pre-defined */ - -/* - * If you are using SYSV_IPC, you might want to make the buffer size bigger - * since it limits the size of requests and responses. Don't make it bigger - * than your system's max message size though (usually a couple of k) or else - * msgsend will start failing. For sockets, using the system BUFSIZ is usually - * what you want. - */ - -#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS) -#include -#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */ - -#ifdef INTERNET_DOMAIN_SOCKETS -#include -#include -#include -#define TABLE_SIZE 101 /* The number of entries in the hash table */ -#define HASH(host) host /* Rather simplistic hash function */ -#define DEFAULT_PORT 21490 /* default port number to use is - * DEFAULT_PORT + uid */ -#endif /* INTERNET_DOMAIN_SOCKETS */ - -#ifdef UNIX_DOMAIN_SOCKETS -#include -#define HIDE_UNIX_SOCKET /* put the unix socket in a protected dir */ -#endif /* UNIX_DOMAIN_SOCKETS */ - -#define HOSTNAMSZ 255 /* max size of a hostname */ -#define REPLYSIZ 300 /* max size of reply from server to client */ -#undef FALSE -#define FALSE 0 -#undef TRUE -#define TRUE 1 - -/* The casts shut Sun's compiler up and are safe in the context these - are actually used. */ -#define max2(x,y) (((int) (x) > (int) (y)) ? (x) : (y)) -#define min2(x,y) (((int) (x) < (int) (y)) ? (x) : (y)) - -#ifndef _NFILE /* rough guess at maximum number of open files */ -#define _NFILE 20 -#endif - -#define EOT_STR "\004" -#define EOT_CHR '\004' - -/* connection types */ -#define CONN_UNIX 0 -#define CONN_INTERNET 1 -#define CONN_IPC 2 - -/* function declarations */ -int glibtop_make_connection (const char *hostarg, int portarg, int *s); - -#ifdef INTERNET_DOMAIN_SOCKETS -long glibtop_internet_addr (const char *host); -#endif - diff --git a/po/POTFILES.in b/po/POTFILES.in index 2eeef4db..3f016531 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -38,7 +38,6 @@ include/glibtop/cpu.h include/glibtop/error.h include/glibtop/fsusage.h include/glibtop/global.h -include/glibtop/gnuserv.h include/glibtop/inodedb.h include/glibtop/loadavg.h include/glibtop/mem.h @@ -71,7 +70,6 @@ include/glibtop/write.h include/glibtop/xmalloc.h src/inodedb/file_by_inode.c src/inodedb/mkinodedb.c -src/daemon/gnuserv.c src/daemon/io.c src/daemon/main.c src/daemon/server.c @@ -79,7 +77,6 @@ src/daemon/slave.c src/daemon/version.c sysdeps/common/error.c sysdeps/common/fsusage.c -sysdeps/common/gnuslib.c sysdeps/common/inodedb.c sysdeps/common/mountlist.c sysdeps/common/sysdeps_suid.c diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index 50c7a7fb..da581fa0 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am @@ -27,24 +27,10 @@ suid_sysdeps = suid_common = endif -bin_PROGRAMS = libgtop_daemon @server_programs@ +bin_PROGRAMS = @server_programs@ EXTRA_PROGRAMS = libgtop_server -libgtop_daemon_SOURCES = gnuserv.c slave.c main.c io.c version.c \ - daemon.h server_config.h -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)\ - $(GLIB_LIBS)\ - @LIBSUPPORT@ @INTLLIBS@ @libs_xauth@ - -if ENABLE_STATIC -libgtop_daemon_LDFLAGS = -static -endif - libgtop_server_SOURCES = server.c slave.c io.c version.c daemon.h libgtop_server_LDADD = $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps_suid.la \ $(top_builddir)/sysdeps/common/libgtop_suid_common.la \ @@ -54,8 +40,6 @@ if ENABLE_STATIC libgtop_server_LDFLAGS = -static endif -EXTRA_DIST = server_config.h.in server_config.pl - install-exec-hook: -@libgtop_postinstall@ diff --git a/src/daemon/server_config.h b/src/daemon/server_config.h deleted file mode 100644 index 09ae9ae8..00000000 --- a/src/daemon/server_config.h +++ /dev/null @@ -1,11 +0,0 @@ -#define SERVER_PORT 42800 - -#define SERVER_UID 99 -#define SERVER_GID 99 - -#define HOST_TABLE_ENTRIES 1 - -const char *permitted_host_names [HOST_TABLE_ENTRIES] = -{ NULL }; - -unsigned long permitted_hosts [HOST_TABLE_ENTRIES]; diff --git a/src/daemon/server_config.h.in b/src/daemon/server_config.h.in deleted file mode 100644 index f7884c8d..00000000 --- a/src/daemon/server_config.h.in +++ /dev/null @@ -1,44 +0,0 @@ -/* -*-c-*- */ - -/* This is a sample config file. - * - * Copy this file to 'server_config.h' and edit it to fix your needs ! - * - * You can also use the 'server_config.pl' script to create 'server_config.h'. - * - */ - -#define SERVER_PORT 42800 /* Port the server should listen on. */ - -/* NOTE: On RedHat 5.1 nobody is UID 99 and GID 99. - * - * The 'server_config.pl' script will use the real UID and GID of 'nobody' - * on your system as default. - * - * NOTE: This only works if the server is started as root or SUID to root. - */ - -#define SERVER_UID 99 /* User ID the server should run as. */ -#define SERVER_GID 99 /* Group ID the server should run as. */ - -#define HOST_TABLE_ENTRIES 1 /* Number of entries in the host table. */ - -/* List of hosts that should be authorized to connect to the server. - * - * SECURITY WARNING: - * Enabling access for a particular hosts means the ALL USERS on this host - * will be allowed to connect to the server ! - * - * If you want security, let this table empty and use the 'xauth' method - * instead. - * - * Look at the manpage of gnuserv (1) as shipped with GNU Emacs for more - * details about security. The server uses the same security mechanisms - * like gnuserv from XEmacs 20.3. - */ - -const char *permitted_host_names [HOST_TABLE_ENTRIES] = -{ NULL }; - -unsigned long permitted_hosts [HOST_TABLE_ENTRIES]; - diff --git a/src/daemon/server_config.pl b/src/daemon/server_config.pl deleted file mode 100755 index 3e78ca8f..00000000 --- a/src/daemon/server_config.pl +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/perl -w - -require 5.004; -use strict; - -print "Enter port the server should listen on [42800]: "; - -my $port = ; chop $port; -$port = 42800 unless $port =~ /^\d+$/; - -print "\nUser name or UID to run as [nobody]: "; - -my $user = ; chop $user; $user = 'nobody' if $user eq ''; - -my ($login, $pass, $uid, $gid); - -unless ($user =~ /^\d+$/) { - ($login, $pass, $uid, $gid) = getpwnam ($user) or - die "User '$user' not in passwd file."; -} - -my $g_default = (defined $gid) ? $gid : 'nogroup'; - -print "Group name or GID to run as [$g_default]: "; - -my $group = ; chop $group; $group = $g_default if $group eq ''; - -unless ($group =~ /^\d+$/) { - $gid = getgrnam ($group) or - die "Group '$group' not in group file."; -} - -print "\nEnter list of hosts which should be authorized to"; -print "\nconnect to the server (terminate with a blank line):\n\n"; - -print "SECURITY WARNING:\n"; -print " Enabling access for a particular hosts means the ALL USERS on this host will\n"; -print " be allowed to connect to the server !\n\n"; - -print " If you want security, let this table empty and use the 'xauth' method instead.\n"; -print " Look at the manpage of gnuserv (1) as shipped with GNU Emacs for more details\n"; -print " about security. The server uses the same security mechanisms like gnuserv from\n"; -print " XEmacs 20.3\n\n"; - -my @hosts = (); -my @host_addrs = (); -my @host_names = (); - -while (1) { - print "Host: "; - - my $host = ; chop $host; - last if $host eq ''; - - my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname ($host) or - die "gethostbyname (): Can't resolve '$host'"; - - my ($a,$b,$c,$d) = unpack('C4',$addrs[0]); - - push @hosts, sprintf ("0x%02X%02X%02X%02X", $d, $c, $b, $a); - push @host_addrs, sprintf ("%d.%d.%d.%d", $a, $b, $c, $d); - push @host_names, $name; -}; - -print "\n"; -print "This is your config:\n"; -print "====================\n\n"; - -printf qq[%-30s: %d\n\n], 'Port', $port; -printf qq[%-30s: %d\n], 'UID', $uid; -printf qq[%-30s: %d\n\n], 'GID', $gid; - -foreach (0..$#hosts) { - printf qq[%-30s (%s - %s)\n], $host_names[$_], $hosts[$_], $host_addrs [$_]; -} - -print "\n"; - -print "Accept? (yes/no) "; - -my $accept = ; chop $accept; - -exit unless $accept eq 'yes'; - -print "\n"; - -open CONFIG, "> server_config.h" or - die "open (server_config.h): $!"; -select CONFIG; - -printf qq[\#define SERVER_PORT\t\t%d\n\n], $port; - -printf qq[\#define SERVER_UID\t\t%d\n], $uid; -printf qq[\#define SERVER_GID\t\t%d\n\n], $gid; - -printf qq[\#define HOST_TABLE_ENTRIES\t%d\n\n], $#hosts + 1; - -foreach (@host_names) { - $_ = qq["$_"]; -} - -printf qq[const char *permitted_host_names [HOST_TABLE_ENTRIES] = \n]; -printf qq[{ %s };\n\n], join (', ', @host_names); - -printf qq[unsigned long permitted_hosts [HOST_TABLE_ENTRIES];\n]; - -close CONFIG; - -select STDOUT; - -print "Your config has successfully been written to 'server_config.h'.\n"; diff --git a/src/daemon/slave.c b/src/daemon/slave.c index 3682c5d1..9b471b7c 100644 --- a/src/daemon/slave.c +++ b/src/daemon/slave.c @@ -97,7 +97,7 @@ handle_slave_connection (int input, int output) sizeof (max_len)); ptr = glibtop_get_proc_args_p (server, &resp->u.data.proc_args, - pid, max_len); + pid); do_output (output, resp, _offset_data (proc_args), ptr ? resp->u.data.proc_args.size+1 : 0, ptr, (ptr != NULL) ? 0 : -1); diff --git a/sysdeps/common/Makefile.am b/sysdeps/common/Makefile.am index ceae07e7..c05075c1 100644 --- a/sysdeps/common/Makefile.am +++ b/sysdeps/common/Makefile.am @@ -14,7 +14,7 @@ CFLAGS = @CFLAGS@ $(inodedb_DEFS) lib_LTLIBRARIES = libgtop_common.la libgtop_suid_common.la -libgtop_common_la_SOURCES = xmalloc.c error.c gnuslib.c \ +libgtop_common_la_SOURCES = xmalloc.c error.c \ fsusage.c fsusage.h mountlist.c mountlist.h \ $(inodedb_SRCLIST) diff --git a/sysdeps/common/gnuslib.c b/sysdeps/common/gnuslib.c deleted file mode 100644 index 67abf508..00000000 --- a/sysdeps/common/gnuslib.c +++ /dev/null @@ -1,375 +0,0 @@ -/* -*-C-*- - * Common library code for the GNU Emacs server and client. - * - * This file is part of GNU Emacs. - * - * Copying is permitted under those conditions described by the GNU - * General Public License. - * - * Copyright (C) 1989 Free Software Foundation, Inc. - * - * Author: Andy Norman (ange@hplb.hpl.hp.com), based on - * 'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU - * Emacs distribution. - * - * Please mail bugs and suggestions to the author at the above address. - */ - -/* HISTORY - * 11-Nov-1990 bristor@simba - * Added EOT stuff. - */ - -/* - * This file incorporates new features added by Bob Weiner , - * Darrell Kindred and Arup Mukherjee . - * Please see the note at the end of the README file for details. - * - * (If gnuserv came bundled with your emacs, the README file is probably - * ../etc/gnuserv.README relative to the directory containing this file) - */ - -#include -#include - -#include - -#ifdef UNIX_DOMAIN_SOCKETS -static int connect_to_unix_server (void); -#endif - -#ifdef INTERNET_DOMAIN_SOCKETS -static int connect_to_internet_server (const char *serverhost, u_short port); -#endif - -/* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */ -#ifdef HAVE_BROKEN_INET_ADDR -#define IN_ADDR struct in_addr -#define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == 0xffffffff) -#else -#if (LONGBITS > 32) -#define IN_ADDR unsigned int -#else -#define IN_ADDR unsigned long -#endif -#define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) 0xffffffff) -#endif - -#include - -int -glibtop_make_connection (hostarg, portarg, s) - const char *hostarg; - int portarg; - int *s; -{ -#ifdef INTERNET_DOMAIN_SOCKETS - char *ptr; - - if (hostarg == NULL) - hostarg = getenv ("LIBGTOP_HOST"); - if (portarg == 0 && (ptr = getenv ("LIBGTOP_PORT")) != NULL) - portarg = atoi (ptr); -#endif - - if (hostarg != NULL) { - /* hostname was given explicitly, via cmd line arg or - * LIBGTOP_HOST, * so obey it. */ -#ifdef UNIX_DOMAIN_SOCKETS - if (!strcmp (hostarg, "unix")) { - *s = connect_to_unix_server (); - return (int) CONN_UNIX; - } -#endif /* UNIX_DOMAIN_SOCKETS */ -#ifdef INTERNET_DOMAIN_SOCKETS - *s = connect_to_internet_server (hostarg, portarg); - return (int) CONN_INTERNET; -#endif - } else { - /* no hostname given. Use unix-domain/sysv-ipc, or * - * internet-domain connection to local host if they're not - * available. */ -#if defined(UNIX_DOMAIN_SOCKETS) - *s = connect_to_unix_server (); - return (int) CONN_UNIX; -#elif defined(INTERNET_DOMAIN_SOCKETS) - { - char localhost[HOSTNAMSZ]; - - gethostname (localhost, HOSTNAMSZ); /* use this - * host by - * default */ - *s = connect_to_internet_server (localhost, portarg); - return (int) CONN_INTERNET; - } -#endif /* IPC type */ - } -} - -#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS) -/* - * send_string -- send string to socket. - */ -#if 0 -static void -send_string (s, msg) - int s; - const char *msg; -{ -#if 0 - if (send (s, msg, strlen (msg), 0) < 0) { - perror (progname); - fprintf (stderr, "%s: unable to send\n", progname); - exit (1); - }; /* if */ -#else - int len, left = strlen (msg); - - while (left > 0) { - if ((len = write (s, msg, min2 (left, GSERV_BUFSZ))) < 0) { - /* XEmacs addition: robertl@arnet.com */ - if (errno == EPIPE) { - return; - } - perror (progname); - fprintf (stderr, "%s: unable to send\n", progname); - exit (1); - }; /* if */ - left -= len; - msg += len; - }; /* while */ -#endif -} /* send_string */ - -/* - * read_line -- read a \n terminated line from a socket - */ -static int -read_line (int s, char *dest) -{ - int length; - int offset = 0; - char buffer[GSERV_BUFSZ + 1]; - - while ((length = read (s, buffer + offset, 1) > 0) && buffer[offset] != '\n' - && buffer[offset] != EOT_CHR) { - offset += length; - if (offset >= GSERV_BUFSZ) - break; - } - buffer[offset] = '\0'; - strcpy (dest, buffer); - return 1; -} /* read_line */ -#endif -#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */ - - -#ifdef UNIX_DOMAIN_SOCKETS -/* - * connect_to_unix_server -- establish connection with server process via a unix- - * domain socket. Returns socket descriptor for server - * if successful. - */ -static int -connect_to_unix_server (void) -{ - int s; /* connected socket descriptor */ - struct sockaddr_un server; /* for unix connections */ - - if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) - glibtop_error_io ("unable to create socket"); - - server.sun_family = AF_UNIX; -#ifdef HIDE_UNIX_SOCKET - sprintf (server.sun_path, "/tmp/lgtddir%d/lgtd", (int) geteuid ()); -#else /* HIDE_UNIX_SOCKET */ - sprintf (server.sun_path, "/tmp/lgtd%d", (int) geteuid ()); -#endif /* HIDE_UNIX_SOCKET */ - if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0) - glibtop_error_io ("unable to connect to local"); - - return (s); - -} /* connect_to_unix_server */ -#endif /* UNIX_DOMAIN_SOCKETS */ - - -#ifdef INTERNET_DOMAIN_SOCKETS -/* - * internet_addr -- return the internet addr of the hostname or - * internet address passed. Return -1 on error. - */ -long -glibtop_internet_addr (host) - const char *host; -{ - struct hostent *hp; /* pointer to host info for remote host */ - IN_ADDR numeric_addr; /* host address */ - - numeric_addr = inet_addr (host); - if (!NUMERIC_ADDR_ERROR) - return numeric_addr; - else if ((hp = gethostbyname (host)) != NULL) - return ((struct in_addr *) (hp->h_addr))->s_addr; - else { - glibtop_warn_io ("gethostbyname (%s)", host); - return -1; - } - -} /* glibtop_internet_addr */ - -#ifdef AUTH_MAGIC_COOKIE -#include -#include - -static Xauth *server_xauth = NULL; - -#endif - -/* - * connect_to_internet_server -- establish connection with server process via - * an internet domain socket. Returns socket - * descriptor for server if successful. - */ -static int -connect_to_internet_server (const char *serverhost, u_short port) -{ - int s; /* connected socket descriptor */ - struct servent *sp; /* pointer to service information */ - struct sockaddr_in peeraddr_in; /* for peer socket address */ - char buf[512]; /* temporary buffer */ - - /* clear out address structures */ - memset ((char *) &peeraddr_in, 0, sizeof (struct sockaddr_in)); - - /* Set up the peer address to which we will connect. */ - peeraddr_in.sin_family = AF_INET; - - /* look up the server host's internet address */ - peeraddr_in.sin_addr.s_addr = glibtop_internet_addr (serverhost); - if ((long) peeraddr_in.sin_addr.s_addr == -1) - glibtop_error ("unable to find %s in /etc/hosts or from YP", serverhost); - - if (port == 0) { - if ((sp = getservbyname ("gtopd", "tcp")) == NULL) - peeraddr_in.sin_port = htons (DEFAULT_PORT + getuid ()); - else - peeraddr_in.sin_port = sp->s_port; - } - /* if */ - else - peeraddr_in.sin_port = htons (port); - - /* Create the socket. */ - if ((s = socket (AF_INET, SOCK_STREAM, 0)) == -1) - glibtop_error_io ("unable to create socket"); - - /* Try to connect to the remote server at the address * which was - * just built into peeraddr. */ - if (connect (s, (struct sockaddr *) &peeraddr_in, - sizeof (struct sockaddr_in)) == -1) - glibtop_error_io ("unable to connect to remote"); - -#ifdef AUTH_MAGIC_COOKIE - - /* send credentials using MIT-MAGIC-COOKIE-1 protocol */ - - sprintf (buf, "%d", port); - - server_xauth = - XauGetAuthByAddr (FamilyInternet, - sizeof (peeraddr_in.sin_addr.s_addr), - (char *) &peeraddr_in.sin_addr.s_addr, - strlen (buf), buf, - strlen (MCOOKIE_X_NAME), MCOOKIE_X_NAME); - - if (server_xauth && server_xauth->data) { - sprintf (buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length); - write (s, buf, strlen (buf)); - write (s, server_xauth->data, server_xauth->data_length); - - return (s); - } -#endif /* AUTH_MAGIC_COOKIE */ - - sprintf (buf, "%s\n", DEFAUTH_NAME); - write (s, buf, strlen (buf)); - - return (s); - -} /* connect_to_internet_server */ -#endif /* INTERNET_DOMAIN_SOCKETS */ - - -#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS) -/* - * disconnect_from_server -- inform the server that sending has finished, and wait for - * its reply. - */ -#if 0 -static void -disconnect_from_server (s, echo) - int s; - int echo; -{ -#if 0 - char buffer[REPLYSIZ + 1]; - -#else - char buffer[GSERV_BUFSZ + 1]; - -#endif - int add_newline = 1; - int length; - - send_string (s, EOT_STR); /* make sure server gets string */ - -#if !defined (linux) && !defined (_SCO_DS) - /* - * shutdown is completely hozed under linux. If s is a unix domain socket, - * you'll get EOPNOTSUPP back from it. If s is an internet socket, you get - * a broken pipe when you try to read a bit later. The latter - * problem is fixed for linux versions >= 1.1.46, but the problem - * with unix sockets persists. Sigh. - */ - - if (shutdown (s, 1) == -1) { - perror (progname); - fprintf (stderr, "%s: unable to shutdown socket\n", progname); - exit (1); - }; /* if */ -#endif - -#if 0 - while ((length = recv (s, buffer, REPLYSIZ, 0)) > 0) { - buffer[length] = '\0'; - if (echo) - fputs (buffer, stdout); - add_newline = (buffer[length - 1] != '\n'); - }; /* while */ -#else - while ((length = read (s, buffer, GSERV_BUFSZ)) > 0 || - (length == -1 && errno == EINTR)) { - if (length) { - buffer[length] = '\0'; - if (echo) { - fputs (buffer, stdout); - add_newline = (buffer[length - 1] != '\n'); - }; /* if */ - }; /* if */ - }; /* while */ -#endif - - if (echo && add_newline) - putchar ('\n'); - - if (length < 0) { - perror (progname); - fprintf (stderr, "%s: unable to read the reply from the server\n", progname); - exit (1); - }; /* if */ - -} /* disconnect_from_server */ -#endif -#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */