/*
* 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
*
* 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 <stdio.h>
#include <signal.h>
#include <memory.h>
#include <netconfig.h>
#include <stropts.h>
#include <syslog.h>
#include <utmpx.h>
#include <sys/resource.h>
#include <limits.h>
#ifdef DEBUG
#define RPC_SVC_FG
#endif
static void rusers_service();
static void closedown();
static void msgout();
static unsigned min();
/* and cleared by closedown() routine */
#define REAL_USERS 0
int used_array_len = 0;
int
{
int i;
/*
* Set non-blocking mode and maximum record size for
* connection oriented RPC transports.
*/
msgout("unable to set maximum RPC record size");
}
/*
* If stdin looks like a TLI endpoint, we assume
* that we were started by a port monitor. If
* t_getstate fails with TBADF, this is not a
* TLI endpoint.
*/
char *netid;
int pmclose;
extern char *getenv();
_rpcpmstart = 1;
#ifdef DEBUG
msgout("cannot get transport name");
#endif
#ifdef DEBUG
msgout("cannot get transport info");
#endif
}
msgout("cannot create server handle");
exit(1);
}
if (nconf)
0)) {
msgout("unable to register (RUSERSPROG, RUSERSVERS_3).");
exit(1);
}
rusers_service, 0)) {
msgout("unable to register (RUSERSPROG, RUSERSVERS_IDLE).");
exit(1);
}
(void) alarm(_RPCSVC_CLOSEDOWN);
svc_run();
msgout("svc_run returned");
exit(1);
/* NOTREACHED */
}
#ifndef RPC_SVC_FG
if (pid < 0) {
perror("rpc.rusersd: cannot fork");
exit(1);
}
if (pid)
exit(0);
for (i = 0; i < 20; i++)
(void) close(i);
setsid();
#endif
msgout("unable to create (RUSERSPROG, RUSERSVERS_3) for netpath");
exit(1);
}
"netpath")) {
"unable to create (RUSERSPROG, RUSERSVERS_IDLE) for netpath");
exit(1);
}
svc_run();
msgout("svc_run returned");
return (1);
}
/*
* This routine gets the user information.
* "all" specifies whether all listings should be counted, or only those of
* type "USER_PROCESS".
* "version" is either RUSERSVERS_IDLE or RUSERSVERS_3. If anything else,
* just a count is returned.
* "limit" specifies the maximum number of entries to be processed.
*
* For both versions, the results are placed into an external variable.
* For RUSERSVERS_IDLE, this routine mallocs entries in a vector as it
* processed each utmpx entry. These malloc'd entries must be freed after the
* results are returned.
* For RUSERSVERS_3, this routine uses array entries that are malloc'd prior
* to this routine being called. "limit" is the number of elements available.
*/
int
int all; /* give all listings? */
int version; /* version 2 or 3 */
int limit; /* limits users returned, 0 means no limit */
{
int minidle;
int cnt = 0;
extern char *s_malodup();
setutxent(); /* reset the utmpx file */
continue;
/*
* List only user processes.
* XXX modified to exclude cmdtool style window entries.
*/
continue;
if (version == RUSERSVERS_IDLE) {
/*
* need to free this; done after svc_sendreply.
*/
*q = (struct utmpidle *)
strlen("console")) == 0) {
console_idle(now));
}
#ifdef DEBUG
printf("%-*s %-*s %s; idle %d",
(*q)->ui_idle);
#endif
q++;
} else if (version == RUSERSVERS_3) {
strlen("console")) == 0) {
console_idle(now));
}
#ifdef DEBUG
printf("user: %-10s line: %-10s %s; idle %d (%s)\n",
#endif
}
cnt++;
}
return (cnt);
}
/*
* "string" is a character array with maximum size "size". Return a
* malloc'd string that's a duplicate of the string.
*/
char *
char *string;
int size;
{
char *tmp;
msgout("rpc.rusersd: malloc failed (2)");
return (NULL);
}
return (tmp);
}
int
{
/*
* On the console, the user may be running a window system; if so,
* their activity will show up in the last-access times of
* the idle time.
*/
}
static void
{
int i;
int cnt;
case 0:
}
break;
case RUSERSPROC_NUM:
break;
case RUSERSPROC_NAMES:
case RUSERSPROC_ALLNAMES:
(caddr_t)&utmpidlearr))
for (i = 0; i < utmpidlearr.uia_cnt; i++) {
}
/*
* Always free strings from previous results array
*/
for (i = 0; i < used_array_len; i++) {
}
msgout("rpc.rusersd: malloc failed (1)");
break;
}
} else {
}
}
break;
default:
break;
}
_rpcsvcdirty = 0;
}
static void
{
return;
}
/* find & return number of minutes current tty has been idle */
static int
{
return (INT_MAX);
return (diff);
}
static void
{
int i;
#ifdef DEBUG
#endif
}
static void
char *msg;
{
#ifdef RPC_SVC_FG
if (_rpcpmstart)
else
#else
#endif
}
static void
int sig;
{
if (_rpcsvcrecent) {
_rpcsvcrecent = 0;
} else {
if (_rpcsvcdirty == 0) {
int i, openfd;
exit(0);
for (i = 0, openfd = 0;
i++) {
if (svc_pollfd[i].fd >= 0)
openfd++;
}
if (openfd <= 1)
exit(0);
}
}
(void) alarm(_RPCSVC_CLOSEDOWN);
}
unsigned
min(a, b)
unsigned a;
unsigned b;
{
if (a < b)
return (a);
else
return (b);
}