rusers.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <netconfig.h>
#include <netdir.h>
#include <string.h>
#include <limits.h>
#define NUMENTRIES 256
#define min(a, b) ((a) < (b) ? (a) : (b))
struct entry {
int cnt;
int idle; /* set to INT_MAX if not present */
char *machine;
};
static int curentry;
static int total_entries;
static int hflag; /* host: sort by machine name */
static int iflag; /* idle: sort by idle time */
static int uflag; /* users: sort by number of users */
static int lflag; /* print out long form */
static int aflag; /* all: list all machines */
static int dflag; /* debug: list only first n machines */
static int sorted;
static int debug;
static int debugcnt;
static char *nettype;
static int print_info(struct utmpidlearr *, const char *);
static int print_info_3(utmp_array *, const char *);
static void singlehost(char *);
static void printnames(void);
static void putline_3(char *, rusers_utmp *);
static void usage(void);
/*
* rusers [-ahilu] [host...]
*/
int
{
int c;
struct utmpidlearr utmpidlearr;
curentry = 0;
switch (c) {
case 'a':
aflag++;
break;
case 'd':
dflag++;
break;
case 'h':
hflag++;
sorted++;
errflag++;
break;
case 'i':
iflag++;
sorted++;
errflag++;
break;
case 'u':
uflag++;
sorted++;
errflag++;
break;
case 'l':
lflag++;
break;
case ':': /* required operand missing */
errflag++;
break;
case 'n':
break;
default:
case '?': /* Unrecognized option */
errflag++;
break;
}
}
if (errflag)
usage();
single++;
}
if (single) {
if (sorted)
printnames();
exit(0);
}
if (sorted) {
(void) printf("Collecting responses...\n");
}
(void) printf("Sending broadcast for rusersd protocol version 3...\n");
(void) printf("Sending broadcast for rusersd protocol version 2...\n");
if (sorted)
printnames();
return (0);
}
static void
singlehost(char *name)
{
struct utmpidlearr utmpidlearr;
if (curentry >= total_entries) {
* total_entries)) == NULL)
return;
}
nettype);
if (err == RPC_SUCCESS) {
return;
}
if (err == RPC_PROGVERSMISMATCH) {
(char *)&utmpidlearr, nettype);
}
if (err != RPC_SUCCESS) {
return;
}
}
/*
* Collect responses from RUSERSVERS_IDLE broadcast, convert to
* RUSERSVERS_3 format, and store in entry database.
*/
static int
{
struct utmpidlearr utmpidlearr;
struct nd_hostservlist *hs;
return (0);
#ifdef DEBUG
netdir_perror("netdir_getbyaddr");
#endif
/* netdir routine couldn't resolve addr;just print out uaddr */
} else {
}
/*
* need to realloc more space if we have more than 256 machines
* that respond to broadcast
*/
if (curentry >= total_entries) {
* total_entries)) == NULL)
return (1);
}
/*
* weed out duplicates
*/
return (0);
}
}
static int
{
/*
* if raw, print this entry out immediately
* otherwise store for later sorting
*/
if (!sorted) {
for (i = 0; i < cnt; i++)
else {
for (i = 0; i < cnt; i++) {
NMAX + 1);
}
(void) printf("\n");
}
/* store just the name */
exit(1);
}
return (1);
return (0);
}
exit(1);
}
for (i = 0; i < cnt; i++) {
}
curentry++;
return (1);
return (0);
}
/*
* Collect responses from RUSERSVERS_3 broadcast.
*/
static int
{
struct nd_hostservlist *hs;
return (0);
#ifdef DEBUG
netdir_perror("netdir_getbyaddr");
#endif
/* netdir routine couldn't resolve addr;just print out uaddr */
} else {
}
/*
* need to realloc more space if we have more than 256 machines
* that respond to broadcast
*/
if (curentry >= total_entries) {
* total_entries)) == NULL)
return (1);
}
/*
* weed out duplicates
*/
return (0);
}
}
static int
{
/*
* if raw, print this entry out immediately
* otherwise store for later sorting
*/
if (!sorted) {
for (i = 0; i < cnt; i++)
else {
for (i = 0; i < cnt; i++)
(void) printf("\n");
}
/* store just the name */
exit(1);
}
return (1);
return (0);
}
exit(1);
}
sizeof (rusers_utmp));
for (i = 0; i < cnt; i++) {
}
curentry++;
return (1);
return (0);
}
static void
printnames(void)
{
int i, j;
int (*compare)(const void *, const void *);
/* the name of the machine should already be in the structure */
if (iflag)
else if (hflag)
else
for (i = 0; i < curentry; i++) {
(void) printf("\n");
} else {
}
}
}
static int
{
}
static int
{
}
static int
{
}
static void
{
char *cbuf;
char buf[100];
/* Try and align this up nicely */
/*
* We copy the strings into a buffer because they aren't strictly
* speaking strings but byte arrays (and they may not have a
* terminating NULL.
*/
(void) printf(" ??");
else
}
(void) putchar('\n');
}
static void
{
char *cbuf;
char buf[100];
(void) printf(" ??");
else
(void) putchar('\n');
}
/*
* prttime prints a time in hours and minutes.
* The character string tail is printed at the end, obvious
* strings to pass are "", " ", or "am".
*/
static void
{
int didhrs = 0;
if (tim >= 60) {
didhrs++;
} else {
(void) printf(" ");
}
tim %= 60;
} else {
(void) printf(" ");
}
}
#ifdef DEBUG
/*
* for debugging
*/
int
printit(int i)
{
int j, v;
(void) printf("\t");
}
} else
(void) printf("\n");
}
#endif
static void
usage(void)
{
exit(1);
}