2005-08-02 01:08:34 +04:00
|
|
|
/* $NetBSD: rusers_proc.c,v 1.25 2005/08/01 21:08:34 christos Exp $ */
|
1996-08-31 00:15:06 +04:00
|
|
|
|
1993-06-03 23:26:09 +04:00
|
|
|
/*-
|
1993-11-21 21:56:33 +03:00
|
|
|
* 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.
|
1993-06-03 23:26:09 +04:00
|
|
|
*/
|
|
|
|
|
1997-09-17 20:35:54 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:48:44 +04:00
|
|
|
#ifndef lint
|
2005-08-02 01:08:34 +04:00
|
|
|
__RCSID("$NetBSD: rusers_proc.c,v 1.25 2005/08/01 21:08:34 christos Exp $");
|
1993-08-02 21:48:44 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1998-04-01 18:47:01 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
1997-09-17 20:35:54 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
1998-04-01 18:47:01 +04:00
|
|
|
#include <time.h>
|
1997-09-17 20:35:54 +04:00
|
|
|
#include <unistd.h>
|
1993-06-03 23:26:09 +04:00
|
|
|
#include <signal.h>
|
1997-09-17 20:35:54 +04:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <utmp.h>
|
|
|
|
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
|
|
|
|
#include "rusers_proc.h"
|
2002-11-05 01:03:38 +03:00
|
|
|
#include "utmpentry.h"
|
1997-09-17 20:35:54 +04:00
|
|
|
|
1993-06-03 23:26:09 +04:00
|
|
|
#ifdef XIDLE
|
1993-06-11 05:10:14 +04:00
|
|
|
#include <setjmp.h>
|
1993-06-03 23:26:09 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/xidle.h>
|
|
|
|
#endif
|
2005-08-02 01:08:34 +04:00
|
|
|
|
1993-11-21 21:56:33 +03:00
|
|
|
#include <rpcsvc/rusers.h> /* New version */
|
2005-08-02 01:08:34 +04:00
|
|
|
static size_t maxusers3 = 0;
|
|
|
|
static struct rusers_utmp *utmps;
|
|
|
|
|
1993-11-21 21:56:33 +03:00
|
|
|
#include <rpcsvc/rnusers.h> /* Old version */
|
2005-08-02 01:08:34 +04:00
|
|
|
static size_t maxusers2 = 0;
|
|
|
|
static struct utmpidle **utmp_idlep;
|
|
|
|
static struct utmpidle *utmp_idle;
|
|
|
|
|
|
|
|
typedef char *(*rusersproc)(void *, struct svc_req *);
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
#ifndef _PATH_DEV
|
|
|
|
#define _PATH_DEV "/dev"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
extern int from_inetd;
|
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
static int getarrays2(int);
|
|
|
|
static int getarrays3(int);
|
2000-06-03 23:06:25 +04:00
|
|
|
static int getidle(char *, char *);
|
|
|
|
static int *rusers_num_svc(void *, struct svc_req *);
|
|
|
|
static utmp_array *do_names_3(int);
|
|
|
|
static struct utmpidlearr *do_names_2(int);
|
1997-09-17 20:35:54 +04:00
|
|
|
|
|
|
|
/* XXX */
|
2000-06-03 23:06:25 +04:00
|
|
|
struct utmpidlearr *rusersproc_names_2_svc(void *, struct svc_req *);
|
|
|
|
struct utmpidlearr *rusersproc_allnames_2_svc(void *, struct svc_req *);
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
|
1997-09-17 20:35:54 +04:00
|
|
|
#ifdef XIDLE
|
|
|
|
static Display *dpy;
|
1995-01-13 22:59:13 +03:00
|
|
|
static sigjmp_buf openAbort;
|
1993-06-03 23:26:09 +04:00
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
static int XqueryIdle(char *);
|
|
|
|
static void abortOpen(int);
|
1997-09-17 20:35:54 +04:00
|
|
|
|
1993-06-03 23:26:09 +04:00
|
|
|
static void
|
2000-06-03 23:06:25 +04:00
|
|
|
abortOpen(int n)
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-01-13 22:59:13 +03:00
|
|
|
siglongjmp(openAbort, 1);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
1997-09-17 20:35:54 +04:00
|
|
|
static int
|
2000-06-03 23:06:25 +04:00
|
|
|
XqueryIdle(char *display)
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-01-13 22:59:13 +03:00
|
|
|
int first_event, first_error;
|
|
|
|
Time IdleTime;
|
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
(void)signal(SIGALRM, abortOpen);
|
|
|
|
(void)alarm(10);
|
1997-09-17 20:35:54 +04:00
|
|
|
if (!sigsetjmp(openAbort, 0)) {
|
1995-01-13 22:59:13 +03:00
|
|
|
if ((dpy = XOpenDisplay(display)) == NULL) {
|
1998-01-20 20:39:14 +03:00
|
|
|
syslog(LOG_DEBUG, "cannot open display %s", display);
|
2005-08-02 01:08:34 +04:00
|
|
|
return -1;
|
1995-01-13 22:59:13 +03:00
|
|
|
}
|
|
|
|
if (XidleQueryExtension(dpy, &first_event, &first_error)) {
|
|
|
|
if (!XGetIdleTime(dpy, &IdleTime)) {
|
2002-11-05 01:03:38 +03:00
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"%s: unable to get idle time", display);
|
2005-08-02 01:08:34 +04:00
|
|
|
return -1;
|
1995-01-13 22:59:13 +03:00
|
|
|
}
|
|
|
|
} else {
|
1998-01-20 20:39:14 +03:00
|
|
|
syslog(LOG_DEBUG, "%s: Xidle extension not loaded",
|
1997-09-19 04:50:04 +04:00
|
|
|
display);
|
2005-08-02 01:08:34 +04:00
|
|
|
return -1;
|
1995-01-13 22:59:13 +03:00
|
|
|
}
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
} else {
|
1998-01-20 20:39:14 +03:00
|
|
|
syslog(LOG_DEBUG, "%s: server grabbed for over 10 seconds",
|
1997-09-19 04:50:04 +04:00
|
|
|
display);
|
2005-08-02 01:08:34 +04:00
|
|
|
return -1;
|
1995-01-13 22:59:13 +03:00
|
|
|
}
|
2005-08-02 01:08:34 +04:00
|
|
|
(void)alarm(0);
|
|
|
|
(void)signal(SIGALRM, SIG_DFL);
|
1995-01-13 22:59:13 +03:00
|
|
|
|
|
|
|
IdleTime /= 1000;
|
2005-08-02 01:08:34 +04:00
|
|
|
return (IdleTime + 30) / 60;
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
1997-09-19 04:50:04 +04:00
|
|
|
#endif /* XIDLE */
|
1993-06-03 23:26:09 +04:00
|
|
|
|
1998-08-12 18:47:30 +04:00
|
|
|
static int
|
2005-08-02 01:08:34 +04:00
|
|
|
getarrays2(int ne)
|
|
|
|
{
|
|
|
|
struct utmpidle **nutmp_idlep;
|
|
|
|
struct utmpidle *nutmp_idle;
|
|
|
|
|
|
|
|
/* Limit to MAXUSERS for version 2 */
|
|
|
|
if (ne > MAXUSERS)
|
|
|
|
ne = MAXUSERS;
|
|
|
|
|
|
|
|
if (maxusers2 == 0) {
|
|
|
|
nutmp_idlep = malloc(sizeof(*nutmp_idlep) * ne);
|
|
|
|
nutmp_idle = malloc(sizeof(*nutmp_idle) * ne);
|
|
|
|
} else {
|
|
|
|
nutmp_idlep = realloc(utmp_idlep, sizeof(*nutmp_idlep) * ne);
|
|
|
|
nutmp_idle = realloc(utmp_idle, sizeof(*nutmp_idle) * ne);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nutmp_idlep == NULL || nutmp_idle == NULL) {
|
|
|
|
syslog(LOG_WARNING, "Cannot allocate data for %u users (%m)",
|
|
|
|
ne);
|
|
|
|
free(nutmp_idlep);
|
|
|
|
free(nutmp_idle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
utmp_idlep = nutmp_idlep;
|
|
|
|
utmp_idle = nutmp_idle;
|
|
|
|
return maxusers2 = ne;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
getarrays3(int ne)
|
|
|
|
{
|
|
|
|
struct rusers_utmp *nutmps;
|
|
|
|
|
|
|
|
if (maxusers3 == 0) {
|
|
|
|
nutmps = malloc(sizeof(*nutmps) * ne);
|
|
|
|
} else {
|
|
|
|
nutmps = realloc(utmps, sizeof(*nutmps) * ne);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nutmps == NULL) {
|
|
|
|
syslog(LOG_WARNING, "Cannot allocate data for %u users (%m)",
|
|
|
|
ne);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
utmps = nutmps;
|
|
|
|
return maxusers3 = ne;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
/*ARGUSED*/
|
2000-06-03 23:06:25 +04:00
|
|
|
getidle(char *tty, char *display)
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-01-13 22:59:13 +03:00
|
|
|
struct stat st;
|
2005-08-02 01:08:34 +04:00
|
|
|
char dev_name[PATH_MAX];
|
1995-01-13 22:59:13 +03:00
|
|
|
time_t now;
|
1998-08-12 18:47:30 +04:00
|
|
|
long idle;
|
1995-01-13 22:59:13 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is an X terminal or console, then try the
|
|
|
|
* XIdle extension
|
|
|
|
*/
|
1993-06-03 23:26:09 +04:00
|
|
|
#ifdef XIDLE
|
1998-01-20 20:39:14 +03:00
|
|
|
if (display && *display && strchr(display, ':') != NULL &&
|
|
|
|
(idle = XqueryIdle(display)) >= 0)
|
2005-08-02 01:08:34 +04:00
|
|
|
return idle;
|
1993-06-03 23:26:09 +04:00
|
|
|
#endif
|
1995-01-13 22:59:13 +03:00
|
|
|
idle = 0;
|
|
|
|
if (*tty == 'X') {
|
1998-08-12 18:47:30 +04:00
|
|
|
long kbd_idle, mouse_idle;
|
1995-01-13 22:59:13 +03:00
|
|
|
#if !defined(i386)
|
|
|
|
kbd_idle = getidle("kbd", NULL);
|
1993-07-16 18:57:19 +04:00
|
|
|
#else
|
1995-12-15 00:58:33 +03:00
|
|
|
/*
|
|
|
|
* XXX Icky i386 console hack.
|
|
|
|
*/
|
1995-01-13 22:59:13 +03:00
|
|
|
kbd_idle = getidle("vga", NULL);
|
1993-07-16 18:57:19 +04:00
|
|
|
#endif
|
1995-01-13 22:59:13 +03:00
|
|
|
mouse_idle = getidle("mouse", NULL);
|
|
|
|
idle = (kbd_idle < mouse_idle) ? kbd_idle : mouse_idle;
|
|
|
|
} else {
|
2005-08-02 01:08:34 +04:00
|
|
|
snprintf(dev_name, sizeof dev_name, "%s/%s", _PATH_DEV, tty);
|
|
|
|
if (stat(dev_name, &st) == -1) {
|
|
|
|
syslog(LOG_WARNING, "Cannot stat %s (%m)", dev_name);
|
1998-08-12 18:47:30 +04:00
|
|
|
return 0;
|
1995-01-13 22:59:13 +03:00
|
|
|
}
|
1998-08-12 18:47:30 +04:00
|
|
|
(void)time(&now);
|
1993-06-03 23:26:09 +04:00
|
|
|
#ifdef DEBUG
|
2005-08-02 01:08:34 +04:00
|
|
|
printf("%s: now=%ld atime=%ld\n", dev_name,
|
1998-08-12 18:47:30 +04:00
|
|
|
(long)now, (long)st.st_atime);
|
1993-06-03 23:26:09 +04:00
|
|
|
#endif
|
1995-01-13 22:59:13 +03:00
|
|
|
idle = now - st.st_atime;
|
|
|
|
idle = (idle + 30) / 60; /* secs->mins */
|
|
|
|
}
|
|
|
|
if (idle < 0)
|
|
|
|
idle = 0;
|
1993-06-03 23:26:09 +04:00
|
|
|
|
1998-08-12 18:47:30 +04:00
|
|
|
return idle;
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
1995-01-13 22:59:13 +03:00
|
|
|
|
2002-11-05 01:03:38 +03:00
|
|
|
static struct utmpentry *ue = NULL;
|
|
|
|
static int nusers = 0;
|
|
|
|
|
1997-09-17 20:35:54 +04:00
|
|
|
static int *
|
2005-08-02 01:08:34 +04:00
|
|
|
/*ARGSUSED*/
|
2000-06-03 23:06:25 +04:00
|
|
|
rusers_num_svc(void *arg, struct svc_req *rqstp)
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
2002-11-05 01:03:38 +03:00
|
|
|
nusers = getutentries(NULL, &ue);
|
|
|
|
return &nusers;
|
1993-11-21 21:56:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static utmp_array *
|
2000-06-03 23:06:25 +04:00
|
|
|
do_names_3(int all)
|
1993-11-21 21:56:33 +03:00
|
|
|
{
|
1995-01-13 22:59:13 +03:00
|
|
|
static utmp_array ut;
|
2002-11-05 01:03:38 +03:00
|
|
|
struct utmpentry *e;
|
2005-08-02 01:08:34 +04:00
|
|
|
size_t nu;
|
|
|
|
int idle;
|
2002-11-05 01:03:38 +03:00
|
|
|
|
|
|
|
nusers = getutentries(NULL, &ue);
|
2005-08-02 01:08:34 +04:00
|
|
|
nusers = getarrays3(nusers);
|
|
|
|
|
|
|
|
(void)memset(&ut, 0, sizeof(ut));
|
|
|
|
ut.utmp_array_val = utmps;
|
2002-11-05 01:03:38 +03:00
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
for (nu = 0, e = ue; e != NULL && nu < nusers; e = e->next) {
|
|
|
|
if ((idle = getidle(e->line, e->host)) > 0 && !all)
|
|
|
|
continue;
|
2002-11-05 01:03:38 +03:00
|
|
|
utmps[nu].ut_type = RUSERS_USER_PROCESS;
|
|
|
|
utmps[nu].ut_time = e->tv.tv_sec;
|
2005-08-02 01:08:34 +04:00
|
|
|
utmps[nu].ut_idle = idle;
|
2002-11-05 01:03:38 +03:00
|
|
|
utmps[nu].ut_line = e->line;
|
|
|
|
utmps[nu].ut_user = e->name;
|
|
|
|
utmps[nu].ut_host = e->host;
|
2005-08-02 01:08:34 +04:00
|
|
|
nu++;
|
1995-01-13 22:59:13 +03:00
|
|
|
}
|
|
|
|
|
2002-11-05 01:03:38 +03:00
|
|
|
ut.utmp_array_len = nu;
|
1995-01-13 22:59:13 +03:00
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
return &ut;
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
1993-11-21 21:56:33 +03:00
|
|
|
utmp_array *
|
2005-08-02 01:08:34 +04:00
|
|
|
/*ARGSUSED*/
|
2000-06-03 23:06:25 +04:00
|
|
|
rusersproc_names_3_svc(void *arg, struct svc_req *rqstp)
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1998-07-03 15:49:50 +04:00
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
return do_names_3(0);
|
1993-11-21 21:56:33 +03:00
|
|
|
}
|
1993-06-03 23:26:09 +04:00
|
|
|
|
1993-11-21 21:56:33 +03:00
|
|
|
utmp_array *
|
2005-08-02 01:08:34 +04:00
|
|
|
/*ARGSUSED*/
|
2000-06-03 23:06:25 +04:00
|
|
|
rusersproc_allnames_3_svc(void *arg, struct svc_req *rqstp)
|
1993-11-21 21:56:33 +03:00
|
|
|
{
|
1998-07-03 15:49:50 +04:00
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
return do_names_3(1);
|
1993-11-21 21:56:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct utmpidlearr *
|
|
|
|
do_names_2(int all)
|
|
|
|
{
|
1995-01-13 22:59:13 +03:00
|
|
|
static struct utmpidlearr ut;
|
2002-11-05 01:03:38 +03:00
|
|
|
struct utmpentry *e;
|
2005-08-02 01:08:34 +04:00
|
|
|
size_t nu;
|
|
|
|
int idle;
|
1997-09-19 04:50:04 +04:00
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
nusers = getutentries(NULL, &ue);
|
|
|
|
nusers = getarrays2(nusers);
|
2002-11-05 01:03:38 +03:00
|
|
|
(void)memset(&ut, 0, sizeof(ut));
|
1995-01-13 22:59:13 +03:00
|
|
|
ut.uia_arr = utmp_idlep;
|
|
|
|
ut.uia_cnt = 0;
|
|
|
|
|
2005-08-02 01:08:34 +04:00
|
|
|
for (nu = 0, e = ue; e != NULL && nu < nusers; e = e->next) {
|
|
|
|
if ((idle = getidle(e->line, e->host)) > 0 && !all)
|
|
|
|
continue;
|
2002-11-05 01:03:38 +03:00
|
|
|
utmp_idlep[nu] = &utmp_idle[nu];
|
|
|
|
utmp_idle[nu].ui_utmp.ut_time = e->tv.tv_sec;
|
2005-08-02 01:08:34 +04:00
|
|
|
utmp_idle[nu].ui_idle = idle;
|
2002-11-05 01:03:38 +03:00
|
|
|
(void)strncpy(utmp_idle[nu].ui_utmp.ut_line, e->line,
|
|
|
|
sizeof(utmp_idle[nu].ui_utmp.ut_line));
|
|
|
|
(void)strncpy(utmp_idle[nu].ui_utmp.ut_name, e->name,
|
|
|
|
sizeof(utmp_idle[nu].ui_utmp.ut_name));
|
|
|
|
(void)strncpy(utmp_idle[nu].ui_utmp.ut_host, e->host,
|
|
|
|
sizeof(utmp_idle[nu].ui_utmp.ut_host));
|
2005-08-02 01:08:34 +04:00
|
|
|
nu++;
|
1995-01-13 22:59:13 +03:00
|
|
|
}
|
|
|
|
|
2002-11-05 01:03:38 +03:00
|
|
|
ut.uia_cnt = nu;
|
2005-08-02 01:08:34 +04:00
|
|
|
return &ut;
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
1993-11-21 21:56:33 +03:00
|
|
|
struct utmpidlearr *
|
2005-08-02 01:08:34 +04:00
|
|
|
/*ARGSUSED*/
|
2000-06-03 23:06:25 +04:00
|
|
|
rusersproc_names_2_svc(void *arg, struct svc_req *rqstp)
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
2005-08-02 01:08:34 +04:00
|
|
|
return do_names_2(0);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
1993-11-21 21:56:33 +03:00
|
|
|
struct utmpidlearr *
|
2005-08-02 01:08:34 +04:00
|
|
|
/*ARGSUSED*/
|
2000-06-03 23:06:25 +04:00
|
|
|
rusersproc_allnames_2_svc(void *arg, struct svc_req *rqstp)
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
2005-08-02 01:08:34 +04:00
|
|
|
return do_names_2(1);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-03 23:06:25 +04:00
|
|
|
rusers_service(struct svc_req *rqstp, SVCXPRT *transp)
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
int fill;
|
|
|
|
} argument;
|
|
|
|
char *result;
|
1995-07-09 04:30:11 +04:00
|
|
|
xdrproc_t xdr_argument, xdr_result;
|
2005-08-02 01:08:34 +04:00
|
|
|
rusersproc local;
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
switch (rqstp->rq_proc) {
|
|
|
|
case NULLPROC:
|
2005-08-02 01:08:34 +04:00
|
|
|
(void)svc_sendreply(transp, xdr_void, NULL);
|
1993-06-03 23:26:09 +04:00
|
|
|
goto leave;
|
|
|
|
|
|
|
|
case RUSERSPROC_NUM:
|
1995-07-09 04:30:11 +04:00
|
|
|
xdr_argument = (xdrproc_t)xdr_void;
|
|
|
|
xdr_result = (xdrproc_t)xdr_int;
|
1995-01-13 22:59:13 +03:00
|
|
|
switch (rqstp->rq_vers) {
|
|
|
|
case RUSERSVERS_3:
|
|
|
|
case RUSERSVERS_IDLE:
|
2005-08-02 01:08:34 +04:00
|
|
|
local = (char *(*)(void *, struct svc_req *))
|
1998-07-03 15:49:50 +04:00
|
|
|
rusers_num_svc;
|
1995-01-13 22:59:13 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
svcerr_progvers(transp, RUSERSVERS_IDLE, RUSERSVERS_3);
|
|
|
|
goto leave;
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RUSERSPROC_NAMES:
|
1995-07-09 04:30:11 +04:00
|
|
|
xdr_argument = (xdrproc_t)xdr_void;
|
|
|
|
xdr_result = (xdrproc_t)xdr_utmp_array;
|
1995-01-13 22:59:13 +03:00
|
|
|
switch (rqstp->rq_vers) {
|
|
|
|
case RUSERSVERS_3:
|
2005-08-02 01:08:34 +04:00
|
|
|
local = (rusersproc)rusersproc_names_3_svc;
|
1995-01-13 22:59:13 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RUSERSVERS_IDLE:
|
1995-07-09 04:30:11 +04:00
|
|
|
xdr_result = (xdrproc_t)xdr_utmpidlearr;
|
2005-08-02 01:08:34 +04:00
|
|
|
local = (rusersproc)rusersproc_names_2_svc;
|
1995-01-13 22:59:13 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
svcerr_progvers(transp, RUSERSVERS_IDLE, RUSERSVERS_3);
|
|
|
|
goto leave;
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RUSERSPROC_ALLNAMES:
|
1995-07-09 04:30:11 +04:00
|
|
|
xdr_argument = (xdrproc_t)xdr_void;
|
|
|
|
xdr_result = (xdrproc_t)xdr_utmp_array;
|
1995-01-13 22:59:13 +03:00
|
|
|
switch (rqstp->rq_vers) {
|
|
|
|
case RUSERSVERS_3:
|
2005-08-02 01:08:34 +04:00
|
|
|
local = (rusersproc)rusersproc_allnames_3_svc;
|
1995-01-13 22:59:13 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RUSERSVERS_IDLE:
|
1995-07-09 04:30:11 +04:00
|
|
|
xdr_result = (xdrproc_t)xdr_utmpidlearr;
|
2005-08-02 01:08:34 +04:00
|
|
|
local = (rusersproc)rusersproc_allnames_2_svc;
|
1995-01-13 22:59:13 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
svcerr_progvers(transp, RUSERSVERS_IDLE, RUSERSVERS_3);
|
|
|
|
goto leave;
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
svcerr_noproc(transp);
|
|
|
|
goto leave;
|
|
|
|
}
|
2005-08-02 01:08:34 +04:00
|
|
|
(void)memset(&argument, 0, sizeof(argument));
|
|
|
|
if (!svc_getargs(transp, xdr_argument, (caddr_t)(void *)&argument)) {
|
1993-06-03 23:26:09 +04:00
|
|
|
svcerr_decode(transp);
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
result = (*local)(&argument, rqstp);
|
|
|
|
if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
|
|
|
|
svcerr_systemerr(transp);
|
|
|
|
}
|
2005-08-02 01:08:34 +04:00
|
|
|
if (!svc_freeargs(transp, xdr_argument, (caddr_t)(void *)&argument)) {
|
1999-07-06 18:36:10 +04:00
|
|
|
syslog(LOG_ERR, "unable to free arguments");
|
1993-06-03 23:26:09 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
leave:
|
1995-01-13 22:59:13 +03:00
|
|
|
if (from_inetd)
|
|
|
|
exit(0);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|