rusers from FreeBSD 1.1.5.1
Reviewed by: Geoff. Submitted by: John Brezak
This commit is contained in:
parent
a82f86e105
commit
61ce166c6c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/FBSD_1/; revision=2345
9
usr.bin/rusers/Makefile
Normal file
9
usr.bin/rusers/Makefile
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# $Id: Makefile,v 1.2 1993/11/10 03:47:23 smace Exp $
|
||||||
|
|
||||||
|
PROG = rusers
|
||||||
|
MAN1 = rusers.1
|
||||||
|
|
||||||
|
DPADD= ${LIBRPCSVC}
|
||||||
|
LDADD= -lrpcsvc
|
||||||
|
|
||||||
|
.include <bsd.prog.mk>
|
93
usr.bin/rusers/rusers.1
Normal file
93
usr.bin/rusers/rusers.1
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
.\" 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.1 1993/09/16 01:15:47 jtc Exp $
|
||||||
|
.\"
|
||||||
|
.Dd April 23, 1991
|
||||||
|
.Dt RUSERS 1
|
||||||
|
.Os BSD 4.2
|
||||||
|
.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 portmap 8 ,
|
||||||
|
.Xr who 1 ,
|
||||||
|
.Xr rpc.rusersd 8
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Nm rusers
|
||||||
|
command
|
||||||
|
appeared in
|
||||||
|
.Em Sun-OS .
|
||||||
|
.Sh BUGS
|
||||||
|
The sorting options are not implemented.
|
249
usr.bin/rusers/rusers.c
Normal file
249
usr.bin/rusers/rusers.c
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
/*-
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static char rcsid[] = "$Id: rusers.c,v 1.1 1993/09/16 01:15:48 jtc Exp $";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <rpc/rpc.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <rpcsvc/rnusers.h>
|
||||||
|
|
||||||
|
#define MAX_INT 0x7fffffff
|
||||||
|
#define HOST_WIDTH 20
|
||||||
|
#define LINE_WIDTH 15
|
||||||
|
char *argv0;
|
||||||
|
|
||||||
|
int longopt;
|
||||||
|
int allopt;
|
||||||
|
|
||||||
|
struct host_list {
|
||||||
|
struct host_list *next;
|
||||||
|
struct in_addr addr;
|
||||||
|
} *hosts;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
rusers_reply(char *replyp, struct sockaddr_in *raddrp)
|
||||||
|
{
|
||||||
|
int x, idle;
|
||||||
|
char date[32], idle_time[64], remote[64];
|
||||||
|
struct hostent *hp;
|
||||||
|
utmpidlearr *up = (utmpidlearr *)replyp;
|
||||||
|
char *host;
|
||||||
|
int days, hours, minutes, seconds;
|
||||||
|
|
||||||
|
if (search_host(raddrp->sin_addr))
|
||||||
|
return(0);
|
||||||
|
|
||||||
|
if (!allopt && !up->utmpidlearr_len)
|
||||||
|
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);
|
||||||
|
|
||||||
|
for (x = 0; x < up->utmpidlearr_len; x++) {
|
||||||
|
strncpy(date,
|
||||||
|
&(ctime((time_t *)&(up->utmpidlearr_val[x].ui_utmp.ut_time))[4]),
|
||||||
|
sizeof(date)-1);
|
||||||
|
|
||||||
|
idle = up->utmpidlearr_val[x].ui_idle;
|
||||||
|
sprintf(idle_time, " :%02d", idle);
|
||||||
|
if (idle == MAX_INT)
|
||||||
|
strcpy(idle_time, "??");
|
||||||
|
else if (idle == 0)
|
||||||
|
strcpy(idle_time, "");
|
||||||
|
else {
|
||||||
|
seconds = idle;
|
||||||
|
days = seconds/(60*60*24);
|
||||||
|
seconds %= (60*60*24);
|
||||||
|
hours = seconds/(60*60);
|
||||||
|
seconds %= (60*60);
|
||||||
|
minutes = seconds/60;
|
||||||
|
seconds %= 60;
|
||||||
|
if (idle > 60)
|
||||||
|
sprintf(idle_time, "%d:%02d",
|
||||||
|
minutes, seconds);
|
||||||
|
if (idle >= (60*60))
|
||||||
|
sprintf(idle_time, "%d:%02d:%02d",
|
||||||
|
hours, minutes, seconds);
|
||||||
|
if (idle >= (24*60*60))
|
||||||
|
sprintf(idle_time, "%d days, %d:%02d:%02d",
|
||||||
|
days, hours, minutes, seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(remote, up->utmpidlearr_val[x].ui_utmp.ut_host, sizeof(remote)-1);
|
||||||
|
if (strlen(remote) != 0)
|
||||||
|
sprintf(remote, "(%.16s)", up->utmpidlearr_val[x].ui_utmp.ut_host);
|
||||||
|
|
||||||
|
if (longopt)
|
||||||
|
printf("%-8.8s %*s:%-*.*s %-12.12s %6s %.18s\n",
|
||||||
|
up->utmpidlearr_val[x].ui_utmp.ut_name,
|
||||||
|
HOST_WIDTH, host,
|
||||||
|
LINE_WIDTH, LINE_WIDTH, up->utmpidlearr_val[x].ui_utmp.ut_line,
|
||||||
|
date,
|
||||||
|
idle_time,
|
||||||
|
remote
|
||||||
|
);
|
||||||
|
else
|
||||||
|
printf("%s ",
|
||||||
|
up->utmpidlearr_val[x].ui_utmp.ut_name);
|
||||||
|
}
|
||||||
|
if (!longopt)
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
|
remember_host(raddrp->sin_addr);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
onehost(char *host)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero((char *)&up, sizeof(up));
|
||||||
|
if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, &up, NULL) != RPC_SUCCESS) {
|
||||||
|
clnt_perror(rusers_clnt, argv0);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
addr.sin_addr.s_addr = *(int *)hp->h_addr;
|
||||||
|
rusers_reply((char *)&up, &addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
allhosts()
|
||||||
|
{
|
||||||
|
utmpidlearr up;
|
||||||
|
enum clnt_stat clnt_stat;
|
||||||
|
|
||||||
|
bzero((char *)&up, sizeof(up));
|
||||||
|
clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE, RUSERSPROC_NAMES,
|
||||||
|
xdr_void, NULL,
|
||||||
|
xdr_utmpidlearr, &up, rusers_reply);
|
||||||
|
if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {
|
||||||
|
fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
extern int optind;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user