netkit-rusers-0.17/ 40700 144 144 0 7141142017 13452 5ustar dhollandpeoplenetkit-rusers-0.17/rup/ 40700 144 144 0 7141142017 14260 5ustar dhollandpeoplenetkit-rusers-0.17/rup/.cvsignore100644 144 144 30 6774164677 16353 0ustar dhollandpeoplerup rstat.h rstat_xdr.c netkit-rusers-0.17/rup/Makefile100644 144 144 1644 7024761720 16044 0ustar dhollandpeopleall: rup include ../MCONFIG include ../MRULES ifeq ($(USE_GLIBC),1) CFLAGS += -DGNU_LIBC -D_GNU_SOURCE endif CFLAGS += -I. #RPCGEN=../../netkit-base/rpcgen/rpcgen RPCGEN=rpcgen # Warning, do NOT put this in the current directory without updating # the clean target. RSTATX=/usr/include/rpcsvc/rstat.x rup: rup.o rstat_xdr.o err.o $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ rup.o: ../version.h install: rup install -s -m$(BINMODE) rup $(INSTALLROOT)$(BINDIR) install -m$(MANMODE) rup.1 $(INSTALLROOT)$(MANDIR)/man1 clean: rm -f *.o rup rstat.h rstat_xdr.c rstat.x rstat_xdr.o: rstat_xdr.c rstat.h # rpcgen includes the pathname you specify for the .x file as the # pathname of the .h file when it builds the .c file. Therefore, # do it in the current directory. rstat.x: ln -s $(RSTATX) $@ rstat.h: $(RSTATX) rstat.x $(RPCGEN) -h -o rstat.h rstat.x rstat_xdr.c: $(RSTATX) rstat.x $(RPCGEN) -c -C -o rstat_xdr.c rstat.x netkit-rusers-0.17/rup/err.3100644 144 144 7626 7141140321 15252 0ustar dhollandpeople.\" $OpenBSD: err.3,v 1.2 1996/08/19 08:22:28 tholo Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .Dd June 9, 1993 .Dt ERR 3 .Os "Linux NetKit (0.17)" .Sh NAME .Nm err , .Nm verr , .Nm errx , .Nm verrx , .Nm warn , .Nm vwarn , .Nm warnx , .Nm vwarnx .Nd formatted error messages .Sh SYNOPSIS .Fd #include .Ft void .Fn err "int eval" "const char *fmt" "..." .Ft void .Fn verr "int eval" "const char *fmt" "va_list args" .Ft void .Fn errx "int eval" "const char *fmt" "..." .Ft void .Fn verrx "int eval" "const char *fmt" "va_list args" .Ft void .Fn warn "const char *fmt" "..." .Ft void .Fn vwarn "const char *fmt" "va_list args" .Ft void .Fn warnx "const char *fmt" "..." .Ft void .Fn vwarnx "const char *fmt" "va_list args" .Sh DESCRIPTION The .Fn err and .Fn warn family of functions display a formatted error message on the standard error output. In all cases, the last component of the program name, a colon character, and a space are output. If the .Va fmt argument is not NULL, the formatted error message, a colon character, and a space are output. In the case of the .Fn err , .Fn verr , .Fn warn , and .Fn vwarn functions, the error message string affiliated with the current value of the global variable .Va errno is output. In all cases, the output is followed by a newline character. .Pp The .Fn err , .Fn verr , .Fn errx , and .Fn verrx functions do not return, but exit with the value of the argument .Fa eval . .Sh EXAMPLES Display the current errno information string and exit: .Bd -literal -offset indent if ((p = malloc(size)) == NULL) err(1, NULL); if ((fd = open(file_name, O_RDONLY, 0)) == -1) err(1, "%s", file_name); .Ed .Pp Display an error message and exit: .Bd -literal -offset indent if (tm.tm_hour < START_TIME) errx(1, "too early, wait until %s", start_time_string); .Ed .Pp Warn of an error: .Bd -literal -offset indent if ((fd = open(raw_device, O_RDONLY, 0)) == -1) warnx("%s: %s: trying the block device", raw_device, strerror(errno)); if ((fd = open(block_device, O_RDONLY, 0)) == -1) err(1, "%s", block_device); .Ed .Sh SEE ALSO .Xr strerror 3 .Sh HISTORY The .Fn err and .Fn warn functions first appeared in .Bx 4.4 . netkit-rusers-0.17/rup/err.c100644 144 144 1064 6321547213 15332 0ustar dhollandpeople/* * Reimplementation of err/warnx. */ char err_rcsid[] = "$Id: err.c,v 1.1 1997/04/05 22:13:31 dholland Exp $"; #include #include #include void err(int eval, const char *fmt, ...) { va_list ap; va_start(ap, fmt); fprintf(stderr, "rup: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "%m\n"); va_end(ap); exit(eval); } void warnx(const char *fmt, ...) { va_list ap; va_start(ap, fmt); fprintf(stderr, "rup: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); } netkit-rusers-0.17/rup/err.h100644 144 144 5167 6321547213 15347 0ustar dhollandpeople/*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)err.h 8.1 (Berkeley) 6/2/93 * NetBSD: err.h,v 1.11 1994/10/26 00:55:52 cgd Exp * From OpenBSD-current 1997/04/05 22:00 GMT */ #ifndef _ERR_H_ #define _ERR_H_ #include #ifdef __cplusplus extern "C" { #endif #define __PFX(a,b) __attribute__((noreturn, format (printf, a, b))) #define __PF(a,b) __attribute__((format (printf, a, b))) void err(int, const char *, ...) __PFX(2,3); void verr(int, const char *, va_list) __PFX(2,0); void errx(int, const char *, ...) __PFX(2,3); void verrx(int, const char *, va_list) __PFX(2,0); void warn(const char *, ...) __PF(1,2); void vwarn(const char *, va_list) __PF(1,0); void warnx(const char *, ...) __PF(1,2); void vwarnx(const char *, va_list) __PF(1,0); #undef __PFX #undef __PF #ifdef __cplusplus }; #endif #endif /* !_ERR_H_ */ netkit-rusers-0.17/rup/rup.1100644 144 144 7301 7141140321 15254 0ustar dhollandpeople.\" -*- nroff -*- .\" .\" Copyright (c) 1985, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $Id: rup.1,v 1.13 2000/07/30 23:57:05 dholland Exp $ .\" .Dd August 15, 1999 .Dt RUP 1 .Os "Linux NetKit (0.17)" .Sh NAME .Nm rup .Nd remote status display .Sh SYNOPSIS .Nm rup .Op Fl dshlt .Op Ar host ... .Sh DESCRIPTION .Nm rup displays a summary of the current system status of a particular .Em host or all hosts on the local network. The output shows the current time of day, how long the system has been up, and the load averages. The load average numbers give the number of jobs in the run queue averaged over 1, 5 and 15 minutes. .Pp The following options are available: .Bl -tag -width indent .It Fl d For each host, report what its local time is. This is useful for checking time syncronization on a network. .It Fl s Print time data in seconds (seconds of uptime or seconds since the epoch), for scripts. .It Fl h Sort the display alphabetically by host name. .It Fl l Sort the display by load average. .It Fl t Sort the display by up time. .El .Pp The .Xr rpc.rstatd 8 daemon must be running on the remote host for this command to work. .Nm rup uses an RPC protocol defined in /usr/include/rpcsvc/rstat.x. .Sh EXAMPLE .Bd -unfilled -offset indent -compact example% rup otherhost otherhost up 6 days, 16:45, load average: 0.20, 0.23, 0.18 example% .Ed .Sh DIAGNOSTICS .Bl -tag -width indent .It rup: RPC: Program not registered The .Xr rpc.rstatd 8 daemon has not been started on the remote host. .It rup: RPC: Timed out A communication error occurred. Either the network is excessively congested, or the .Xr rpc.rstatd 8 daemon has terminated on the remote host. .It rup: RPC: Port mapper failure - RPC: Timed out The remote host is not running the portmapper (see .Xr portmap 8 ), and cannot accomodate any RPC-based services. The host may be down. .El .Sh SEE ALSO .Xr ruptime 1 , .Xr portmap 8 , .Xr rpc.rstatd 8 .Sh HISTORY The .Nm rup command appeared in .Tn SunOS . netkit-rusers-0.17/rup/rup.c100644 144 144 17507 7136375514 15411 0ustar dhollandpeople/*- * Copyright (c) 1993, John Brezak * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ char rcsid[] = "$Id: rup.c,v 1.8 2000/07/22 19:51:40 dholland Exp $"; #include #include #include #include #include #include #include #include #include #include #include #include #undef FSHIFT /* Use protocol's shift and scale values */ #undef FSCALE #include #include "../version.h" #define HOST_WIDTH 24 static int print_rup_data(const char *host, statstime *host_stat); static int printtime; /* print the remote host(s)'s time */ static int printseconds; /* print in seconds, not formatted */ struct host_list { struct host_list *next; struct in_addr addr; } *hosts; static int search_host(struct in_addr addr) { struct host_list *hp; if (!hosts) return(0); for (hp = hosts; hp != NULL; hp = hp->next) { if (hp->addr.s_addr == addr.s_addr) return(1); } return(0); } static void remember_host(struct in_addr addr) { struct host_list *hp; if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) { err(1, "malloc"); /* NOTREACHED */ } hp->addr.s_addr = addr.s_addr; hp->next = hosts; hosts = hp; } struct rup_data { char *host; struct statstime statstime; }; struct rup_data *rup_data; int rup_data_idx = 0; int rup_data_max = 0; enum sort_type { SORT_NONE, SORT_HOST, SORT_LDAV, SORT_UPTIME }; enum sort_type sort_type; static int compare(const void *a1, const void *a2) { const struct rup_data *d1 = (const struct rup_data *) a1; const struct rup_data *d2 = (const struct rup_data *) a2; switch(sort_type) { case SORT_HOST: return strcmp(d1->host, d2->host); case SORT_LDAV: return d1->statstime.avenrun[0] - d2->statstime.avenrun[0]; case SORT_UPTIME: return d1->statstime.boottime.tv_sec - d2->statstime.boottime.tv_sec; default: /* something's really wrong here */ abort(); } } static void remember_rup_data(const char *host, const struct statstime *st) { if (rup_data_idx >= rup_data_max) { rup_data_max += 16; rup_data = realloc (rup_data, rup_data_max * sizeof(struct rup_data)); if (rup_data == NULL) { err (1, "realloc"); /* NOTREACHED */ } } rup_data[rup_data_idx].host = strdup(host); rup_data[rup_data_idx].statstime = *st; rup_data_idx++; } static int rstat_reply(char *replyp, struct sockaddr_in *raddrp) { struct hostent *hp; const char *host; statstime *host_stat = (statstime *)replyp; if (!search_host(raddrp->sin_addr)) { hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr, sizeof(struct in_addr), AF_INET); if (hp) host = hp->h_name; else host = inet_ntoa(raddrp->sin_addr); remember_host(raddrp->sin_addr); if (sort_type != SORT_NONE) { remember_rup_data(host, host_stat); } else { print_rup_data(host, host_stat); } } return 0; } static int print_rup_data(const char *host, statstime *host_stat) { time_t hosttime; long uptime; printf("%-*.*s", HOST_WIDTH, HOST_WIDTH, host); hosttime = host_stat->curtime.tv_sec; host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec; uptime = host_stat->curtime.tv_sec; /* uptime in seconds */ if (printtime) { if (printseconds) { printf(" %-12lld", (unsigned long long) hosttime); } else { struct tm *time = localtime(&hosttime); printf(" %2d:%02d%cm", time->tm_hour % 12, time->tm_min, (time->tm_hour >= 12) ? 'p' : 'a'); } } if (printseconds) { printf(" up %12ld", uptime); } else { uptime /= 60; /* convert to minutes */ printf(" up "); if (uptime > 24*60) { /* more than 1 day? */ int days = uptime/(24*60); printf("%3d %s ", days, days > 1 ? "days," : "day, "); uptime %= (24*60); } else { printf(" "); } if (uptime > 60) { int hours = uptime/60; int mins = uptime%60; printf("%2d:%02d, ", hours, mins); } else { printf("%2ld mins, ", uptime); } } printf(" load average: %.2f %.2f %.2f\n", (double)host_stat->avenrun[0]/FSCALE, (double)host_stat->avenrun[1]/FSCALE, (double)host_stat->avenrun[2]/FSCALE); return(0); } static void onehost(const char *host) { CLIENT *rstat_clnt; statstime host_stat; struct timeval foo; rstat_clnt = clnt_create(host, RSTATPROG, RSTATVERS_TIME, "udp"); if (rstat_clnt == NULL) { warnx("%s", clnt_spcreateerror(host)); return; } memset(&host_stat, 0, sizeof(host_stat)); if (clnt_call(rstat_clnt, RSTATPROC_STATS, (xdrproc_t) xdr_void, NULL, (xdrproc_t) xdr_statstime, &host_stat, foo) != RPC_SUCCESS) { warnx("%s", clnt_sperror(rstat_clnt, host)); return; } print_rup_data(host, &host_stat); clnt_destroy(rstat_clnt); } static void allhosts(void) { statstime host_stat; enum clnt_stat clnt_stat; int i; if (sort_type != SORT_NONE) { printf("collecting responses..."); fflush(stdout); } clnt_stat = clnt_broadcast(RSTATPROG, RSTATVERS_TIME, RSTATPROC_STATS, (xdrproc_t) xdr_void, NULL, (xdrproc_t) xdr_statstime, (char *) &host_stat, (resultproc_t) rstat_reply); if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) { warnx("%s", clnt_sperrno(clnt_stat)); exit(1); } if (sort_type != SORT_NONE) { putchar('\n'); qsort(rup_data, rup_data_idx, sizeof(struct rup_data), compare); for (i = 0; i < rup_data_idx; i++) { print_rup_data(rup_data[i].host, &rup_data[i].statstime); } } } static void usage(void) { fprintf(stderr, "Usage: rup [-dhlt] [hosts ...]\n"); exit(1); } int main(int argc, char *argv[]) { int ch; sort_type = SORT_NONE; while ((ch = getopt(argc, argv, "dshlt")) != -1) switch (ch) { case 'd': printtime = 1; break; case 's': printseconds = 1; break; case 'h': sort_type = SORT_HOST; break; case 'l': sort_type = SORT_LDAV; break; case 't': sort_type = SORT_UPTIME; break; default: usage(); /*NOTREACHED*/ } setlinebuf(stdout); if (argc == optind) allhosts(); else { for (; optind < argc; optind++) onehost(argv[optind]); } exit(0); } netkit-rusers-0.17/.cvsignore100644 144 144 10 7024703554 15521 0ustar dhollandpeopleMCONFIG netkit-rusers-0.17/BUGS100644 144 144 126 6751143534 14236 0ustar dhollandpeopleDoesn't compile cleanly. (This is more than half libc's fault.) Not y2038-compliant. netkit-rusers-0.17/ChangeLog100644 144 144 5534 7136461173 15355 0ustar dhollandpeople22-Jul-2000: Fixed bug in rup: it wasn't able to print uptimes > 1 year. (Stephen G. Roseman, sgr0@lehigh.edu) Rearranged uptime printing logic in rup and added -s option to print times and uptimes in seconds for scripting. Least privilege patches (and some other fixes) for rusersd from Olaf Kirch. 21-May-2000: Relax buffer paranoia a bit in rusersd to be able to send 8-character usernames. Should be safe. (Rune Andresen, di990013@diku.dk) 14-Dec-1999: netkit-rusers-0.16 is released. 12-Dec-1999: Backlogged fixes from Frodo Looijaard, frodol@dds.nl. 1-Aug-1999: Complete y2k and y2038 audit. Alas, we're not y2038-compliant. 31-Jul-1999: Redid makefiles/config stuff for new confgen version. 12-Oct-1997: Patches applied: Robert Bihlmeyer patches for compatibility with glibc 2.0.4's "rusers.x" patches for strings which are not null-terminated 23-Sep-1997: Fix suspicious strncpys in rusers. 02-Aug-1997: netkit-rusers-0.11 released. 02-Aug-1997: Fix buffer overrun security hole in rusers client. 12-Jun-1997: netkit-rusers-0.10 released. 08-Jun-1997: More adjustments for glibc. 05-Apr-1997: Added configure script to generate MCONFIG. glibc fixes from HJ Lu. rup now builds, thanks in part to HJ Lu. Better utmp handling in rusersd. 08-Mar-1997: Split from full NetKit package. Generated this change log from NetKit's. 29-Dec-1996 NetKit-0.09 released. Assorted alpha/glibc patches. (Erik Troan, ewt@redhat.com) Assorted bug fixes from Debian. (Peter Tobias, tobias@et-inf.fho-emden.de) Hardened programs against DNS h_length spoofing attacks. Use inet_aton() everywhere instead of inet_addr(). 22-Aug-1996 NetKit-B-0.08 released. fixed rusers to use the right .x files with rpcgen. fixed rusers and rwall to use rpcgen correctly. (almost) everything now compiles with lots of warnings turned on. 25-Jul-1996 NetKit-B-0.07A released. 23-Jul-1996 NetKit-B-0.07 released. Integrated a collection of patches that had been lurking on the net, including the 256-ptys support for telnetd and passive mode ftp. Major security fixes, including to fingerd, lpr, rlogin, rsh, talkd, and telnetd. Do *not* use the sliplogin from earlier versions of this package, either. Much of the code builds without libbsd.a or bsd includes. Massive code cleanup. Almost everything compiles clean with gcc -Wall now. rusers and rusersd do not; patches to rpcgen to fix this would be appreciated if anyone feels like it. New maintainer: David A. Holland, dholland@hcs.harvard.edu date not known NetKit-B-0.06 released. date not known NetKit-B-0.05 released. date not known NetKit-B-0.04 released. date not known NetKit-B-0.03 released. Changed rusers, rpc.ruserd, rwall, rpc.rwalld, rwho, rwhod to not require to copy ./include/*.h files into /usr/include netkit-rusers-0.17/MCONFIG.in100644 144 144 246 7004603221 15152 0ustar dhollandpeople# Dirs INSTALLROOT BINDIR MANDIR SBINDIR # Modes BINMODE DAEMONMODE MANMODE # Compiling ALLWARNINGS CC CFLAGS LDFLAGS LIBS # Features GLIBC BSDSIGNAL FN(snprintf) netkit-rusers-0.17/MRULES100644 144 144 173 6310305757 14505 0ustar dhollandpeople# Standard compilation rules (don't use make builtins) %.o: %.c $(CC) $(CFLAGS) $< -c %.o: %.cc $(CC) $(CFLAGS) $< -c netkit-rusers-0.17/Makefile100644 144 144 761 7024720306 15210 0ustar dhollandpeople# You can do "make SUB=blah" to make only a few, or edit here, or both # You can also run make directly in the subdirs you want. SUB = rpc.rusersd rusers rup %.build: (cd $(patsubst %.build, %, $@) && $(MAKE)) %.install: (cd $(patsubst %.install, %, $@) && $(MAKE) install) %.clean: (cd $(patsubst %.clean, %, $@) && $(MAKE) clean) all: $(patsubst %, %.build, $(SUB)) install: $(patsubst %, %.install, $(SUB)) clean: $(patsubst %, %.clean, $(SUB)) distclean: clean rm -f MCONFIG netkit-rusers-0.17/README100644 144 144 7767 7141137773 14477 0ustar dhollandpeopleThis is netkit-rusers-0.17 for Linux. This package updates netkit-rusers-0.16. If you're reading this off a CD, go right away and check the net archives for later versions and security fixes. As of this writing the home site for NetKit is ftp://ftp.uk.linux.org/pub/linux/Networking/netkit Contents: rup Program to print LAN uptimes rusers Program to print current LAN user logins rpc.rusersd Daemon to return data for rwho/ruptime Requires: Working compiler, libc, and kernel. Your rpcgen binary must be from netkit-base-0.10 or higher, or from glibc 2.x. Older rpcgens will croak on rup. Security: This release contains no known security fixes relative to netkit-rusers-0.16. However, it contains patches to enable running as a non-root user in a chroot area, so it provides a definite increment in security. netkit-rusers-0.10 and earlier are insecure and should not be used under any circumstances. Installation: If you like, apply the rusers.x patch to rusers.x in /usr/include/rpcsvc. This patch was supposed to have been merged into libc, but appears to not have been. It is not important, however - all it does is suppress compiler warnings. Do "./configure --help" and decide what options you want. The defaults should be suitable for most Linux systems. Then run the configure script. Do "make" to compile. Then (as root) do "make install". Save a backup copy of any mission-critical program in case the new one doesn't work, and so forth. We warned you. If you get gcc warnings from files in /usr/include, they are due to problems in your libc, not netkit. (You may only see them when compiling netkit because netkit turns on a lot of compiler warnings.) DEC CC: The DEC compiler for the Alpha is now freely available. This is a much better compiler with gcc, that is, it generates much better code. If you have the DEC compiler, you can explicitly use the DEC compiler instead of gcc by configuring like this: ./configure --with-c-compiler=ccc It is known to generate spurious warnings on some files. Also, some headers from some versions of glibc confuse it; that may prevent netkit from working. Other problems should be reported as bugs. Bugs: Please make sure the header files in /usr/include match the libc version installed in /lib and /usr/lib. If you have weird problems this is the most likely culprit. Also, before reporting a bug, be sure you're working with the latest version. If something doesn't compile for you, fix it and send diffs. If you can't, send the compiler's error output. If it compiles but doesn't work, send as complete a bug report as you can. Patches and fixes are welcome, as long as you describe adequately what they're supposed to fix. Please, one patch per distinct fix. Please do NOT send the whole archive back or reindent the source. Be sure to send all correspondence in e-mail to the netkit address. Postings to netnews or mailing lists will not be seen due to the enormous volume. Also, anything that doesn't get filed in the bug database is quite likely to end up forgotten. Please don't report known bugs (see the BUGS file(s)) unless you are including fixes. :-) Mail should be sent to: netbug@ftp.uk.linux.org Early in April 2000, a hacker broke into the machine that was hosting the netkit bug database for me and trashed it. Unfortunately, it seems backups hadn't gotten done for a while, so three months of mail (since mid-January) was lost. So, if you sent something and didn't hear back, or you sent something, heard back, but the changes failed to appear in this release (unlikely but possible) - please resend. Please see http://www.hcs.harvard.edu/~dholland/computers/netkit.html if you are curious why it was so long between the 0.10 and 0.16 releases. Future plans for netkit maintenance are still up in the air, but in the meantime new releases will still appear from time to time. I don't have a whole lot of cycles to spare to work on netkit, so things are likely to continue to be fairly slow. David A. Holland 23 July 2000 netkit-rusers-0.17/configure100755 144 144 17042 7140615675 15532 0ustar dhollandpeople#!/bin/sh # # This file was generated by confgen version 2. # Do not edit. # PREFIX='/usr' #EXECPREFIX='$PREFIX' INSTALLROOT='' BINMODE='755' #DAEMONMODE='$BINMODE' MANMODE='644' while [ x$1 != x ]; do case $1 in --help) cat < __conftest.c int main() { int class=0; return class; } EOF if [ x"$CC" = x ]; then echo -n 'Looking for a C compiler... ' for TRY in egcs gcc g++ CC c++ cc; do ( $TRY __conftest.c -o __conftest || exit 1; ./__conftest || exit 1; ) >/dev/null 2>&1 || continue; CC=$TRY break; done if [ x"$CC" = x ]; then echo 'failed.' echo 'Cannot find a C compiler. Run configure with --with-c-compiler.' rm -f __conftest* exit fi echo "$CC" else echo -n 'Checking if C compiler works... ' if ( $CC __conftest.c -o __conftest || exit 1 ./__conftest || exit 1 ) >/dev/null 2>&1; then echo 'yes' else echo 'no' echo 'Compiler '"$CC"' does not exist or cannot compile C; try another.' rm -f __conftest* exit fi fi echo -n "Checking if $CC accepts gcc warnings... " if ( $CC $WARNINGS __conftest.c -o __conftest || exit 1 ) >/dev/null 2>&1; then echo 'yes' CC_WARNINGS=1 else echo 'no' fi if [ x$DEBUG = x ]; then echo -n "Checking if $CC accepts -O2... " if ( $CC -O2 __conftest.c -o __conftest ) >/dev/null 2>&1; then echo 'yes' CFLAGS="$CFLAGS -O2" else echo 'no' echo -n "Checking if $CC accepts -O... " if ( $CC -O __conftest.c -o __conftest ) >/dev/null 2>&1; then echo 'yes' CFLAGS="$CFLAGS -O" else echo 'no' fi fi else echo -n "Checking if $CC accepts -g... " if ( $CC -g __conftest.c -o __conftest ) >/dev/null 2>&1; then echo 'yes' CFLAGS="$CFLAGS -g" else echo 'no' fi fi LDFLAGS= LIBS= rm -f __conftest* ################################################## echo -n 'Checking for BSD signal semantics... ' cat <__conftest.c #include #include int count=0; void handle(int foo) { count++; } int main() { int pid=getpid(); signal(SIGINT, handle); kill(pid,SIGINT); kill(pid,SIGINT); kill(pid,SIGINT); if (count!=3) return 1; return 0; } EOF if ( $CC $CFLAGS __conftest.c -o __conftest || exit 1 ./__conftest || exit 1 ) >/dev/null 2>&1; then echo 'yes' else if ( $CC $CFLAGS -D__USE_BSD_SIGNAL __conftest.c -o __conftest || exit 1 ./__conftest || exit 1 ) >/dev/null 2>&1; then echo '-D__USE_BSD_SIGNAL' CFLAGS="$CFLAGS -D__USE_BSD_SIGNAL" else echo 'no' echo 'This package needs BSD signal semantics to run.' rm -f __conftest* exit fi fi rm -f __conftest* ################################################## echo -n 'Checking for GNU libc... ' cat <__conftest.c #include #if defined(__GLIBC__) && (__GLIBC__ >= 2) int tester; #endif int main() { tester=6; return 0; } EOF if ( $CC $CFLAGS __conftest.c -o __conftest || exit 1 ) >/dev/null 2>&1; then echo 'yes' USE_GLIBC=1 else echo 'no' fi rm -f __conftest* ################################################## echo -n 'Checking for snprintf declaration... ' cat <__conftest.c #include int main() { void *x = (void *)snprintf; printf("%lx", (long)x); return 0; } EOF if ( $CC $CFLAGS __conftest.c -o __conftest || exit 1 ) >/dev/null 2>&1; then echo 'ok' else if ( $CC $CFLAGS -D_GNU_SOURCE __conftest.c -o __conftest || exit 1 ./__conftest || exit 1 ) >/dev/null 2>&1; then echo '-D_GNU_SOURCE' CFLAGS="$CFLAGS -D_GNU_SOURCE" else echo 'manual' CFLAGS="$CFLAGS -DDECLARE_SNPRINTF" fi fi rm -f __conftest* echo -n 'Checking for snprintf implementation... ' cat <__conftest.c #include #include #ifdef DECLARE_SNPRINTF #ifdef __cplusplus extern "C" #endif /*__cplusplus*/ int snprintf(char *, int, const char *, ...); #endif /*DECLARE_SNPRINTF*/ int main() { char buf[32]; snprintf(buf, 8, "%s", "1234567890"); if (strlen(buf)!=7) return 1; return 0; } EOF if ( $CC $CFLAGS __conftest.c $LIBBSD -o __conftest || exit 1 ./__conftest || exit 1 ) >/dev/null 2>&1; then echo 'ok' else if ( $CC $CFLAGS __conftest.c -lsnprintf $LIBBSD -o __conftest || exit 1 ./__conftest || exit 1 ) >/dev/null 2>&1; then echo '-lsnprintf' LIBS="$LIBS -lsnprintf" else if ( $CC $CFLAGS __conftest.c -ldb $LIBBSD -o __conftest || exit 1 ./__conftest || exit 1 ) >/dev/null 2>&1; then echo '-ldb' LIBS="$LIBS -ldb" else echo 'missing' echo 'This package requires snprintf.' rm -f __conftest* exit fi fi fi rm -f __conftest* ################################################## ## libbsd should go last in case it's broken if [ "x$LIBBSD" != x ]; then LIBS="$LIBS $LIBBSD" fi echo 'Generating MCONFIG...' ( echo -n '# Generated by configure (confgen version 2) on ' date echo '#' echo echo "BINDIR=$BINDIR" echo "SBINDIR=$SBINDIR" echo "MANDIR=$MANDIR" echo "BINMODE=$BINMODE" echo "DAEMONMODE=$DAEMONMODE" echo "MANMODE=$MANMODE" echo "PREFIX=$PREFIX" echo "EXECPREFIX=$EXECPREFIX" echo "INSTALLROOT=$INSTALLROOT" echo "CC=$CC" if [ x$CC_WARNINGS != x ]; then CFLAGS="$CFLAGS $WARNINGS" fi echo "CFLAGS=$CFLAGS" | sed 's/= */=/' echo "LDFLAGS=$LDFLAGS" | sed 's/= */=/' echo "LIBS=$LIBS" | sed 's/= */=/' echo "USE_GLIBC=$USE_GLIBC" ) > MCONFIG netkit-rusers-0.17/rusers.x.patch100644 144 144 3271 6201224733 16400 0ustar dhollandpeopleThis patch can be applied to /usr/include/rpcsvc/rusers.x to fix some compile warnings. Hopefully it will have been integrated into the most recent libcs. *** rusers.x Sun Aug 4 18:11:42 1996 --- rusers.x.orig Thu Aug 24 23:35:56 1995 *************** *** 166,170 **** %{ % if (!xdr_reference(xdrs, (char **) objpp, sizeof (struct ru_utmp), ! % (xdrproc_t) xdr_utmp)) { % return (FALSE); % } --- 166,170 ---- %{ % if (!xdr_reference(xdrs, (char **) objpp, sizeof (struct ru_utmp), ! % xdr_utmp)) { % return (FALSE); % } *************** *** 178,183 **** %{ % if (!xdr_array(xdrs, (char **)&objp->uta_arr, (u_int *)&objp->uta_cnt, ! % MAXUSERS, sizeof(struct ru_utmp *), ! % (xdrproc_t) xdr_utmpptr)) { % return (FALSE); % } --- 178,182 ---- %{ % if (!xdr_array(xdrs, (char **)&objp->uta_arr, (u_int *)&objp->uta_cnt, ! % MAXUSERS, sizeof(struct ru_utmp *), xdr_utmpptr)) { % return (FALSE); % } *************** *** 205,209 **** %{ % if (!xdr_reference(xdrs, (char **) objpp, sizeof (struct utmpidle), ! % (xdrproc_t) xdr_utmpidle)) { % return (FALSE); % } --- 204,208 ---- %{ % if (!xdr_reference(xdrs, (char **) objpp, sizeof (struct utmpidle), ! % xdr_utmpidle)) { % return (FALSE); % } *************** *** 217,222 **** %{ % if (!xdr_array(xdrs, (char **)&objp->uia_arr, (u_int *)&objp->uia_cnt, ! % MAXUSERS, sizeof(struct utmpidle *), ! % (xdrproc_t) xdr_utmpidleptr)) { % return (FALSE); % } --- 216,220 ---- %{ % if (!xdr_array(xdrs, (char **)&objp->uia_arr, (u_int *)&objp->uia_cnt, ! % MAXUSERS, sizeof(struct utmpidle *), xdr_utmpidleptr)) { % return (FALSE); % } netkit-rusers-0.17/version.h100644 144 144 147 7141140320 15374 0ustar dhollandpeople/* * String to embed in binaries to identify package */ char pkg[]="$NetKit: netkit-rusers-0.17 $"; netkit-rusers-0.17/rpc.rusersd/ 40700 144 144 0 7141142017 15724 5ustar dhollandpeoplenetkit-rusers-0.17/rpc.rusersd/.cvsignore100644 144 144 36 6774164677 20025 0ustar dhollandpeoplerusersd rusers.h rusers_xdr.c netkit-rusers-0.17/rpc.rusersd/Makefile100644 144 144 2101 7024761717 17503 0ustar dhollandpeopleall: rusersd include ../MCONFIG include ../MRULES ifeq ($(USE_GLIBC),1) CFLAGS += -DGNU_LIBC -D_GNU_SOURCE -D_NO_UT_TIME endif # .if exists(/usr/include/X11/extensions/xidle.h) #CFLAGS+= -DXIDLE #LDADD+= -L/usr/X386/lib -lXext -lX11 # .endif RPCGEN=rpcgen # Warning, do not put this in the current directory without updating # the clean target. RUSERSX=/usr/include/rpcsvc/rusers.x rusersd: rusersd.o rusers_proc.o rusers_xdr.o daemon.o $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ install: rusersd install -s -m$(DAEMONMODE) rusersd $(INSTALLROOT)$(SBINDIR)/rpc.rusersd install -m$(MANMODE) rpc.rusersd.8 $(INSTALLROOT)$(MANDIR)/man8 ln -sf rpc.rusersd.8 $(INSTALLROOT)$(MANDIR)/man8/rusersd.8 clean: rm -f *.o rusersd rusers.h rusers_xdr.c rusers.x rusersd.o: ../version.h rusersd.o rusers_proc.o: rusers.h rusers_xdr.o: rusers_xdr.c rusers.h # see rusers makefile for an explanation of why this is necessary rusers.x: ln -s $(RUSERSX) rusers.x rusers.h: $(RUSERSX) rusers.x $(RPCGEN) -h -o rusers.h rusers.x rusers_xdr.c: $(RUSERSX) $(RPCGEN) -c -C -o rusers_xdr.c rusers.x netkit-rusers-0.17/rpc.rusersd/daemon.3100644 144 144 5461 7141140321 17364 0ustar dhollandpeople.\" From: NetBSD: daemon.3,v 1.3 1995/02/25 13:41:12 cgd Exp .\" $Id: daemon.3,v 1.12 2000/07/30 23:57:05 dholland Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)daemon.3 8.1 (Berkeley) 6/9/93 .\" .Dd June 9, 1993 .Dt DAEMON 3 .Os "Linux NetKit (0.17)" .Sh NAME .Nm daemon .Nd run in the background .Sh SYNOPSIS .Fd #include .Fn daemon "int nochdir" "int noclose" .Sh DESCRIPTION .Pp The .Fn daemon function is for programs wishing to detach themselves from the controlling terminal and run in the background as system daemons. .Pp Unless the argument .Fa nochdir is non-zero, .Fn daemon changes the current working directory to the root (``/''). .Pp Unless the argument .Fa noclose is non-zero, .Fn daemon will redirect standard input, standard output and standard error to ``/dev/null''. .Sh ERRORS The function .Fn daemon may fail and set .Va errno for any of the errors specified for the library functions .Xr fork 2 and .Xr setsid 2 . .Sh SEE ALSO .Xr setsid 2 .Sh HISTORY The .Fn daemon function first appeared in .Bx 4.4 . netkit-rusers-0.17/rpc.rusersd/daemon.c100644 144 144 4714 6321541532 17454 0ustar dhollandpeople/*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * From: @(#)daemon.c 8.1 (Berkeley) 6/4/93 * NetBSD: daemon.c,v 1.4 1995/02/25 13:41:16 cgd Exp */ char daemon_rcsid[] = "$Id: daemon.c,v 1.1 1997/04/05 21:25:46 dholland Exp $"; #include #include #include #include "daemon.h" int daemon(int nochdir, int noclose) { int fd; switch (fork()) { case -1: return -1; case 0: break; default: _exit(0); } if (setsid() == -1) return -1; if (!nochdir) chdir("/"); if (noclose) return 0; fd = open(_PATH_DEVNULL, O_RDWR, 0); if (fd != -1) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (fd > 2) close(fd); } return 0; } netkit-rusers-0.17/rpc.rusersd/daemon.h100644 144 144 47 6321541532 17414 0ustar dhollandpeopleint daemon(int nochdir, int noclose); netkit-rusers-0.17/rpc.rusersd/rpc.rusersd.8100644 144 144 4716 7141140321 20402 0ustar dhollandpeople.\" -*- nroff -*- .\" .\" Copyright (c) 1985, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $Id: rpc.rusersd.8,v 1.13 2000/07/30 23:57:05 dholland Exp $ .\" .Dd June 7, 1993 .Dt RPC.RUSERSD 8 .Os "Linux NetKit (0.17)" .Sh NAME .Nm rpc.rusersd .Nd logged in users server .Sh SYNOPSIS .Nm /usr/sbin/rpc.rusersd .Sh DESCRIPTION .Nm rpc.rusersd is a server which returns information about users currently logged in to the system. .Pp The currently logged in users are queried using the .Xr rusers 1 command. The .Nm rpc.rusersd daemon is normally invoked by .Xr inetd 8 . .Pp .Nm rpc.rusersd uses an RPC protocol defined in .Pa /usr/include/rpcsvc/rusers.x . .Sh SEE ALSO .Xr rusers 1 , .Xr who 1 , .Xr w 1 , .Xr inetd 8 netkit-rusers-0.17/rpc.rusersd/rusers_proc.c100644 144 144 31277 7136461174 20613 0ustar dhollandpeople#/*- * Copyright (c) 1993 John Brezak * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ char rp_rcsid[] = "$Id: rusers_proc.c,v 1.16 2000/07/23 03:11:56 dholland Exp $"; #include #include #include #include #include #include #include #include #include #include #include #ifdef XIDLE #include #include #include #endif /* * Sigh. */ #ifdef __GLIBC__ #define UT_TIME ut_xtime #define RUT_TIME rut_time #else #define UT_TIME ut_time #define RUT_TIME ut_time #endif /* Glibc strikes again */ #ifdef __GLIBC__ #include #else #include "rusers.h" #endif void rusers_service(struct svc_req *rqstp, SVCXPRT *transp); #define IGNOREUSER "sleeper" #ifndef _PATH_DEV #define _PATH_DEV "/dev" #endif #ifndef UT_LINESIZE #define UT_LINESIZE sizeof(((struct utmp *)0)->ut_line) #endif #ifndef UT_NAMESIZE #define UT_NAMESIZE sizeof(((struct utmp *)0)->ut_name) #endif #ifndef UT_HOSTSIZE #define UT_HOSTSIZE sizeof(((struct utmp *)0)->ut_host) #endif typedef char ut_line_t[UT_LINESIZE+1]; typedef char ut_name_t[UT_NAMESIZE+1]; typedef char ut_host_t[UT_HOSTSIZE+1]; struct rusers_utmp utmps[MAXUSERS]; struct utmpidle *utmp_idlep[MAXUSERS]; struct utmpidle utmp_idle[MAXUSERS]; ut_line_t line[MAXUSERS]; ut_name_t name[MAXUSERS]; ut_host_t host[MAXUSERS]; extern int from_inetd; #ifdef XIDLE Display *dpy; static sigjmp_buf openAbort; static void abortOpen () { siglongjmp (openAbort, 1); } static long XqueryIdle(char *display) { int first_event, first_error; Time IdleTime; int result = -1; (void) signal (SIGALRM, abortOpen); (void) alarm ((unsigned) 10); if (!sigsetjmp(openAbort, 1)) { if (!(dpy= XOpenDisplay(display))) { syslog(LOG_ERR, "Cannot open display %s", display); goto out; } if (XidleQueryExtension(dpy, &first_event, &first_error)) { if (!XGetIdleTime(dpy, &IdleTime)) { syslog(LOG_ERR, "%s: Unable to get idle time.", display); goto out; } } else { syslog(LOG_ERR, "%s: Xidle extension not loaded.", display); goto out; } XCloseDisplay(dpy); } else { syslog(LOG_ERR, "%s: Server grabbed for over 10 seconds.", display); goto out; } IdleTime /= 1000; result = (IdleTime + 30) / 60; out: (void) signal (SIGALRM, SIG_DFL); (void) alarm ((unsigned) 0); return result; } #endif static u_int getidle(char *tty, char *display) { struct stat st; char devname[PATH_MAX]; time_t now; long idletime; (void)display; /* Don't trust utmp data */ if (strstr(tty, "../")) return 0; /* * If this is an X terminal or console, then try the * XIdle extension */ #ifdef XIDLE if (display && *display && (idletime = XqueryIdle(display)) >= 0) return(idletime); #endif idletime = 0; #if 0 if (*tty == 'X') { u_long kbd_idle, mouse_idle; #if !defined(i386) kbd_idle = getidle("kbd", NULL); #else #if (__GNUC__ >= 2) #warning i386 console hack here #endif kbd_idle = getidle("vga", NULL); #endif mouse_idle = getidle("mouse", NULL); idletime = (kbd_idle < mouse_idle)?kbd_idle:mouse_idle; } else { #endif { snprintf(devname, sizeof(devname), "%s/%s", _PATH_DEV, tty); if (stat(devname, &st) < 0) { #ifdef DEBUG printf("%s: %s\n", devname, strerror(errno)); #endif return(-1); } time(&now); #ifdef DEBUG printf("%s: now=%d atime=%d\n", devname, now, st.st_atime); #endif if (now < st.st_atime) idletime = 0; else idletime = now - st.st_atime; idletime = (idletime + 30) / 60; /* secs->mins */ } /* idletime is unsigned */ /* if (idletime < 0) idletime = 0; */ return idletime; } static char * rusers_num(void *ign1, struct svc_req *ign2) { static int num_users = 0; struct utmp *uptr; (void)ign1; (void)ign2; /* only use entries with both name and line fields */ setutent(); while ((uptr = getutent())!=NULL) { if (*uptr->ut_name && *uptr->ut_line && strncmp(uptr->ut_name, IGNOREUSER, sizeof(uptr->ut_name)) #ifdef USER_PROCESS && uptr->ut_type == USER_PROCESS #endif ) { num_users++; } } endutent(); return (char *) &num_users; } static utmp_array * do_names_3(int all) { static utmp_array ut; struct utmp *uptr; int nusers = 0; (void)all; memset(&ut, 0, sizeof(ut)); ut.utmp_array_val = &utmps[0]; /* only use entries with both name and line fields */ setutent(); while ((uptr = getutent())!=NULL && nusers < MAXUSERS) { if (*uptr->ut_name && *uptr->ut_line && strncmp(uptr->ut_name, IGNOREUSER, sizeof(uptr->ut_name)) #ifdef USER_PROCESS && uptr->ut_type == USER_PROCESS #endif ) { utmps[nusers].ut_type = RUSERS_USER_PROCESS; utmps[nusers].ut_time = uptr->UT_TIME; utmps[nusers].ut_idle = getidle(uptr->ut_line, uptr->ut_host); utmps[nusers].ut_line = line[nusers]; strncpy(line[nusers], uptr->ut_line, sizeof(line[nusers])); line[nusers][sizeof(line[nusers])-1] = 0; utmps[nusers].ut_user = name[nusers]; strncpy(name[nusers], uptr->ut_name, sizeof(name[nusers])); name[nusers][sizeof(name[nusers])-1] = 0; utmps[nusers].ut_host = host[nusers]; strncpy(host[nusers], uptr->ut_host, sizeof(host[nusers])); host[nusers][sizeof(host[nusers])-1] = 0; line[nusers][UT_LINESIZE] = '\0'; name[nusers][UT_NAMESIZE] = '\0'; host[nusers][UT_HOSTSIZE] = '\0'; nusers++; } } ut.utmp_array_len = nusers; endutent(); return &ut; } utmp_array * rusersproc_names_3(void *tmp1, CLIENT *tmp2) { (void)tmp1; (void)tmp2; return do_names_3(0); } utmp_array * rusersproc_allnames_3(void *tmp1, CLIENT *tmp2) { (void)tmp1; (void)tmp2; return do_names_3(1); } static void do_strncpy(char *tgt, const char *src, size_t len) { strncpy(tgt, src, len); tgt[len-1] = 0; } static struct utmpidlearr * do_names_2(int all) { static struct utmpidlearr ut; struct utmp *uptr; int nusers = 0; (void)all; memset(&ut, 0, sizeof(ut)); ut.uia_arr = utmp_idlep; ut.uia_cnt = 0; /* only use entries with both name and line fields */ setutent(); while ((uptr = getutent())!=NULL && nusers < MAXUSERS) { if (*uptr->ut_name && *uptr->ut_line && strncmp(uptr->ut_name, IGNOREUSER, sizeof(uptr->ut_name)) #ifdef USER_PROCESS && uptr->ut_type == USER_PROCESS #endif ) { utmp_idlep[nusers] = &utmp_idle[nusers]; utmp_idle[nusers].ui_utmp.ut_time = uptr->UT_TIME; utmp_idle[nusers].ui_idle = getidle(uptr->ut_line, uptr->ut_host); do_strncpy(utmp_idle[nusers].ui_utmp.ut_line, uptr->ut_line, sizeof(utmp_idle[nusers].ui_utmp.ut_line)); /* note NOT do_strncpy */ strncpy(utmp_idle[nusers].ui_utmp.ut_name, uptr->ut_name, sizeof(utmp_idle[nusers].ui_utmp.ut_name)); do_strncpy(utmp_idle[nusers].ui_utmp.ut_host, uptr->ut_host, sizeof(utmp_idle[nusers].ui_utmp.ut_host)); nusers++; } } ut.uia_cnt = nusers; endutent(); return(&ut); } static char * rusersproc_names_2(void) { return (char *) do_names_2(0); } static char * rusersproc_allnames_2(void) { return (char *) do_names_2(1); } void rusers_service(struct svc_req *rqstp, SVCXPRT *transp) { union { int fill; } argument; char *result; bool_t (*xdr_argument)(void); xdrproc_t xdr_result; typedef char *(*localproc_t)(void *, struct svc_req *); localproc_t local; switch (rqstp->rq_proc) { case NULLPROC: (void)svc_sendreply(transp, (xdrproc_t) xdr_void, NULL); goto leave; case RUSERSPROC_NUM: xdr_argument = xdr_void; xdr_result = (xdrproc_t) xdr_int; switch (rqstp->rq_vers) { case RUSERSVERS_3: case RUSERSVERS_IDLE: local = rusers_num; break; default: svcerr_progvers(transp, RUSERSVERS_IDLE, RUSERSVERS_3); goto leave; } break; case RUSERSPROC_NAMES: xdr_argument = xdr_void; xdr_result = (xdrproc_t) xdr_utmp_array; switch (rqstp->rq_vers) { case RUSERSVERS_3: local = (localproc_t) rusersproc_names_3; break; case RUSERSVERS_IDLE: xdr_result = (xdrproc_t) xdr_utmpidlearr; local = (localproc_t) rusersproc_names_2; break; default: svcerr_progvers(transp, RUSERSVERS_IDLE, RUSERSVERS_3); goto leave; /*NOTREACHED*/ } break; case RUSERSPROC_ALLNAMES: xdr_argument = xdr_void; xdr_result = (xdrproc_t) xdr_utmp_array; switch (rqstp->rq_vers) { case RUSERSVERS_3: local = (localproc_t) rusersproc_allnames_3; break; case RUSERSVERS_IDLE: xdr_result = (xdrproc_t) xdr_utmpidlearr; local = (localproc_t) rusersproc_allnames_2; break; default: svcerr_progvers(transp, RUSERSVERS_IDLE, RUSERSVERS_3); goto leave; /*NOTREACHED*/ } break; default: svcerr_noproc(transp); goto leave; } memset(&argument, 0, sizeof(argument)); if (!svc_getargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) { svcerr_decode(transp); goto leave; } result = (*local)(&argument, rqstp); if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { svcerr_systemerr(transp); } if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) { (void)fprintf(stderr, "unable to free arguments\n"); exit(1); } leave: if (from_inetd) exit(0); } netkit-rusers-0.17/rpc.rusersd/rusersd.c100644 144 144 7146 7136467770 17722 0ustar dhollandpeople/*- * Copyright (c) 1993 John Brezak * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ char rusersd_rcsid[] = "$Id: rusersd.c,v 1.10 2000/07/23 04:09:28 dholland Exp $"; #include #include #include #include #include #include #include #include #include #ifdef __GLIBC__ #include #else #include "rusers.h" #endif #include "../version.h" void rusers_service(struct svc_req *rqstp, SVCXPRT *transp); int daemon(int, int); int from_inetd = 1; static void cleanup(int ignore) { (void)ignore; pmap_unset(RUSERSPROG, RUSERSVERS_3); pmap_unset(RUSERSPROG, RUSERSVERS_IDLE); exit(0); } int main(void) { SVCXPRT *transp; int sock = 0; int proto = 0; struct sockaddr_in from; int fromlen = sizeof(from); /* Open syslog */ openlog("rpc.rusersd", LOG_PID, LOG_DAEMON); /* Drop privilege */ if (getuid() == 0) { struct passwd *pw; if ((pw = getpwnam("nobody")) == NULL) { syslog(LOG_WARNING, "Unable to find user nobody: %m"); exit(1); } if (setgroups(1, &pw->pw_gid) < 0 || setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) { syslog(LOG_WARNING, "Failed to drop privilege: %m"); exit(1); } } /* * See if inetd started us */ if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) { from_inetd = 0; sock = RPC_ANYSOCK; proto = IPPROTO_UDP; } if (!from_inetd) { daemon(0, 0); pmap_unset(RUSERSPROG, RUSERSVERS_3); pmap_unset(RUSERSPROG, RUSERSVERS_IDLE); signal(SIGINT, cleanup); signal(SIGTERM, cleanup); signal(SIGHUP, cleanup); } openlog("rpc.rusersd", LOG_PID, LOG_DAEMON); transp = svcudp_create(sock); if (transp == NULL) { syslog(LOG_ERR, "cannot create udp service."); exit(1); } if (!svc_register(transp, RUSERSPROG, RUSERSVERS_3, rusers_service, proto)) { syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_3, %s).", proto?"udp":"(inetd)"); exit(1); } if (!svc_register(transp, RUSERSPROG, RUSERSVERS_IDLE, rusers_service, proto)) { syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_IDLE, %s).", proto?"udp":"(inetd)"); exit(1); } svc_run(); syslog(LOG_ERR, "svc_run returned"); exit(1); } netkit-rusers-0.17/rusers/ 40700 144 144 0 7141142017 14775 5ustar dhollandpeoplenetkit-rusers-0.17/rusers/.cvsignore100644 144 144 35 6774164700 17060 0ustar dhollandpeoplerusers rusers.h rusers_xdr.c netkit-rusers-0.17/rusers/Makefile100644 144 144 2105 7024761720 16552 0ustar dhollandpeopleall: rusers include ../MCONFIG include ../MRULES ifeq ($(USE_GLIBC),1) CFLAGS += -DGNU_LIBC -D_GNU_SOURCE -D_NO_UT_TIME endif RPCGEN=rpcgen # Warning, do NOT put this in the current directory without updating # the clean target. RUSERSX = /usr/include/rpcsvc/rusers.x # The rusers.h file in /usr/include/rpcsvc (at least on my system) appears # to have been built with an ancient rpcgen. Therefore, make it anew. rusers: rusers.o rusers_xdr.o $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ install: rusers install -s -m$(BINMODE) rusers $(INSTALLROOT)$(BINDIR) install -m$(MANMODE) rusers.1 $(INSTALLROOT)$(MANDIR)/man1 clean: rm -f *.o rusers rusers.h rusers_xdr.c rusers.x rusers.o: rusers.h ../version.h rusers_xdr.o: rusers_xdr.c rusers.h # rpcgen includes the pathname you specify for the .x file as the # pathname of the .h file when it builds the .c file. Therefore, # do it in the current directory. rusers.x: ln -s $(RUSERSX) rusers.x rusers.h: $(RUSERSX) rusers.x $(RPCGEN) -h -o rusers.h rusers.x rusers_xdr.c: $(RUSERSX) rusers.x $(RPCGEN) -c -C -o rusers_xdr.c rusers.x netkit-rusers-0.17/rusers/rusers.1100644 144 144 7034 7141140321 16511 0ustar dhollandpeople.\" Copyright (c) 1983, 1990 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" from: @(#)rusers.1 6.7 (Berkeley) 4/23/91 .\" $Id: rusers.1,v 1.11 2000/07/30 23:57:05 dholland Exp $ .\" .Dd August 15, 1999 .Dt RUSERS 1 .Os "Linux NetKit (0.17)" .Sh NAME .Nm rusers .Nd who is logged in to machines on local network .Sh SYNOPSIS .Nm rusers .Op Fl al .Op Ar host ... .Sh DESCRIPTION The .Nm rusers command produces output similar to .Xr who , but for the list of hosts or all machines on the local network. For each host responding to the rusers query, the hostname with the names of the users currently logged on is printed on each line. The rusers command will wait for one minute to catch late responders. .Pp The following options are available: .Bl -tag -width indent .It Fl a Print all machines responding even if no one is currently logged in. .It Fl l Print a long format listing. This includes the user name, host name, tty that the user is logged in to, the date and time the user logged in, the amount of time since the user typed on the keyboard, and the remote host they logged in from (if applicable). .El .Sh DIAGNOSTICS .Bl -tag -width indent .It rusers: RPC: Program not registered The .Xr rpc.rusersd 8 daemon has not been started on the remote host. .It rusers: RPC: Timed out A communication error occurred. Either the network is excessively congested, or the .Xr rpc.rusersd 8 daemon has terminated on the remote host. .It rusers: RPC: Port mapper failure - RPC: Timed out The remote host is not running the portmapper (see .Xr portmap 8 ), and cannot accomodate any RPC-based services. The host may be down. .El .Sh SEE ALSO .Xr rwho 1 .Xr users 1 , .Xr who 1 , .Xr portmap 8 , .Xr rpc.rusersd 8 .Sh HISTORY The .Nm rusers command appeared in .Tn SunOS . .Sh BUGS The sorting options are not implemented. netkit-rusers-0.17/rusers/rusers.c100644 144 144 16506 7024774065 16641 0ustar dhollandpeople/*- * Copyright (c) 1993 John Brezak * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef lint char rusers_rcsid[] = "$Id: rusers.c,v 1.17 1999/12/12 19:32:05 dholland Exp $"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../version.h" /* * For now we only try version 2 of the protocol. The current * version is 3 (rusers.h), but only Solaris and NetBSD seem * to support it currently. */ /*#include */ /* Old version */ #include "rusers.h" /* get the one we just built with rpcgen */ /* * Sigh. */ #ifdef GNU_LIBC #define RUT_TIME ut_time #else #define RUT_TIME ut_time #endif #define MAX_INT 0x7fffffff #define HOST_WIDTH 20 #define LINE_WIDTH 8 char *argv0; struct timeval timeout = { 25, 0 }; int longopt; int allopt; struct host_list { struct host_list *next; struct in_addr addr; } *hosts; static int search_host(struct in_addr addr) { struct host_list *hp; if (!hosts) return(0); for (hp = hosts; hp != NULL; hp = hp->next) { if (hp->addr.s_addr == addr.s_addr) return(1); } return(0); } static void remember_host(struct in_addr addr) { struct host_list *hp; if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) { fprintf(stderr, "%s: no memory.\n", argv0); exit(1); } hp->addr.s_addr = addr.s_addr; hp->next = hosts; hosts = hp; } static int rusers_reply(char *replyp, struct sockaddr_in *raddrp) { int x, idlee; char date[32], idle_time[64], remote[64], local[64]; struct hostent *hp; struct utmpidlearr *up = (struct utmpidlearr *)replyp; const char *host; int days, hours, minutes, seconds; if (search_host(raddrp->sin_addr)) return(0); if (!allopt && !up->uia_cnt) return(0); hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr, sizeof(struct in_addr), AF_INET); if (hp) host = hp->h_name; else host = inet_ntoa(raddrp->sin_addr); if (!longopt) printf("%-*.*s ", HOST_WIDTH, HOST_WIDTH, host); for (x = 0; x < up->uia_cnt; x++) { time_t tmptime = up->uia_arr[x]->ui_utmp.RUT_TIME; strncpy(date, ctime(&tmptime) + 4, sizeof(date)-1); date[sizeof(date)-1] = 0; idlee = up->uia_arr[x]->ui_idle; snprintf(idle_time, sizeof(idle_time), " :%02d", idlee); if (idlee == MAX_INT) strcpy(idle_time, "??"); else if (idlee == 0) strcpy(idle_time, ""); else { seconds = idlee; days = seconds/(60*60*24); seconds %= (60*60*24); hours = seconds/(60*60); seconds %= (60*60); minutes = seconds/60; seconds %= 60; if (idlee > 60) snprintf(idle_time, sizeof(idle_time), "%2d:%02d", minutes, seconds); if (idlee >= (60*60)) snprintf(idle_time, sizeof(idle_time), "%2d:%02d:%02d", hours, minutes, seconds); if (idlee >= (24*60*60)) snprintf(idle_time, sizeof(idle_time), "%d days, %d:%02d:%02d", days, hours, minutes, seconds); } strncpy(remote, up->uia_arr[x]->ui_utmp.ut_host, sizeof(remote)-1); remote[sizeof(remote)-1] = 0; if (strlen(remote) != 0) snprintf(remote, sizeof(remote), "(%.16s)", up->uia_arr[x]->ui_utmp.ut_host); if (longopt) { /* Fit into HOST_WIDTH+LINE_WIDTH+1 chars */ int len1 = strlen(host); int len2 = strlen(up->uia_arr[x]->ui_utmp.ut_line); if (len1 + len2 > HOST_WIDTH+LINE_WIDTH+1) { int excess = len1 + len2 - HOST_WIDTH-LINE_WIDTH-1; if (excess < len1) len1 -= excess; else if (excess < len2) len2 -= excess; else { /* Hmm. Probably an attack... */ len1 = HOST_WIDTH; len2 = LINE_WIDTH; } } snprintf(local, sizeof(local), "%-.*s:%-.*s", len1, host, len2, up->uia_arr[x]->ui_utmp.ut_line); printf("%-8.8s %-*.*s %-12.12s %8s %.18s\n", up->uia_arr[x]->ui_utmp.ut_name, HOST_WIDTH+LINE_WIDTH+1, HOST_WIDTH+LINE_WIDTH+1, local, date, idle_time, remote); } else printf("%.8s ", up->uia_arr[x]->ui_utmp.ut_name); } if (!longopt) putchar('\n'); remember_host(raddrp->sin_addr); return(0); } static void onehost(char *host) { struct utmpidlearr up; CLIENT *rusers_clnt; struct sockaddr_in addr; struct hostent *hp; hp = gethostbyname(host); if (hp == NULL) { fprintf(stderr, "%s: unknown host \"%s\"\n", argv0, host); exit(1); } rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp"); if (rusers_clnt == NULL) { clnt_pcreateerror(argv0); exit(1); } memset(&up, 0, sizeof(up)); memset(&addr, 0, sizeof(addr)); if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, (xdrproc_t)xdr_void, NULL, (xdrproc_t) xdr_utmpidlearr, &up, timeout) != RPC_SUCCESS) { clnt_perror(rusers_clnt, argv0); exit(1); } if (hp->h_length > (int)sizeof(addr.sin_addr)) { hp->h_length = sizeof(addr.sin_addr); } memcpy(&addr.sin_addr, hp->h_addr, hp->h_length); rusers_reply((char *)&up, &addr); } static void allhosts(void) { struct utmpidlearr up; enum clnt_stat clnt_stat; bzero((char *)&up, sizeof(up)); clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE, RUSERSPROC_NAMES, (xdrproc_t) xdr_void, NULL, (xdrproc_t) xdr_utmpidlearr, (char *) &up, (resultproc_t) rusers_reply); if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) { fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat)); exit(1); } } static void usage(void) { fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0); exit(1); } int main(int argc, char *argv[]) { int ch; if (!(argv0 = rindex(argv[0], '/'))) argv0 = argv[0]; else argv0++; while ((ch = getopt(argc, argv, "al")) != -1) switch (ch) { case 'a': allopt++; break; case 'l': longopt++; break; default: usage(); /*NOTREACHED*/ } setlinebuf(stdout); if (argc == optind) allhosts(); else { for (; optind < argc; optind++) (void) onehost(argv[optind]); } exit(0); }