2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * rusers_simple.c
2N/A * These are the "easy to use" interfaces to rusers.
2N/A *
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#include <string.h>
2N/A#include <rpc/rpc.h>
2N/A#include <rpcsvc/rusers.h>
2N/A#include <stdlib.h>
2N/A
2N/Aint
2N/Arusers3(host, uap)
2N/A char *host;
2N/A utmp_array *uap;
2N/A{
2N/A struct utmpidlearr up;
2N/A
2N/A if (rpc_call(host, RUSERSPROG, RUSERSVERS_3, RUSERSPROC_NAMES,
2N/A xdr_void, (char *) NULL,
2N/A xdr_utmp_array, (char *) uap, (char *) NULL) != 0) {
2N/A /*
2N/A * If version 3 isn't available, try version 2. We'll have to
2N/A * convert a utmpidlearr structure into a utmp_array.
2N/A */
2N/A up.uia_cnt = 0;
2N/A up.uia_arr = NULL;
2N/A if (rusers(host, &up) != 0)
2N/A return (-1);
2N/A else {
2N/A int i;
2N/A struct ru_utmp forsize;
2N/A rusers_utmp *rutp;
2N/A
2N/A uap->utmp_array_val = (rusers_utmp *)malloc(up.uia_cnt
2N/A * sizeof (rusers_utmp));
2N/A if (uap->utmp_array_val == NULL) {
2N/A xdr_free(xdr_utmpidlearr, (char *)&up);
2N/A return (-1);
2N/A }
2N/A uap->utmp_array_len = up.uia_cnt;
2N/A for (rutp = uap->utmp_array_val, i = 0;
2N/A i < up.uia_cnt; rutp++, i++) {
2N/A rutp->ut_line = (char *)malloc(sizeof
2N/A (forsize.ut_line)+1);
2N/A rutp->ut_user = (char *)malloc(sizeof
2N/A (forsize.ut_name)+1);
2N/A rutp->ut_host = (char *)malloc(sizeof
2N/A (forsize.ut_host)+1);
2N/A if (rutp->ut_line == NULL ||
2N/A rutp->ut_user == NULL ||
2N/A rutp->ut_host == NULL) {
2N/A
2N/A while (--rutp >= uap->utmp_array_val) {
2N/A free(rutp->ut_line);
2N/A free(rutp->ut_user);
2N/A free(rutp->ut_host);
2N/A }
2N/A free(uap->utmp_array_val);
2N/A xdr_free(xdr_utmpidlearr, (char *)&up);
2N/A return (-1);
2N/A }
2N/A strncpy(rutp->ut_line,
2N/A up.uia_arr[i]->ui_utmp.ut_line,
2N/A sizeof (forsize.ut_line)+1);
2N/A strncpy(rutp->ut_user,
2N/A up.uia_arr[i]->ui_utmp.ut_name,
2N/A sizeof (forsize.ut_name)+1);
2N/A strncpy(rutp->ut_host,
2N/A up.uia_arr[i]->ui_utmp.ut_host,
2N/A sizeof (forsize.ut_host)+1);
2N/A rutp->ut_idle = up.uia_arr[i]->ui_idle;
2N/A rutp->ut_time = up.uia_arr[i]->ui_utmp.ut_time;
2N/A rutp->ut_type = RUSERS_USER_PROCESS;
2N/A /* assume this */
2N/A }
2N/A xdr_free(xdr_utmpidlearr, (char *)&up);
2N/A }
2N/A }
2N/A return (0);
2N/A}
2N/A
2N/Aint
2N/Arnusers(host)
2N/A char *host;
2N/A{
2N/A int nusers;
2N/A
2N/A if (rpc_call(host, RUSERSPROG, RUSERSVERS_3, RUSERSPROC_NUM,
2N/A xdr_void, (char *) NULL,
2N/A xdr_u_int, (char *) &nusers, (char *) NULL) != 0) {
2N/A if (rpc_call(host, RUSERSPROG, RUSERSVERS_IDLE, RUSERSPROC_NUM,
2N/A xdr_void, (char *) NULL,
2N/A xdr_u_int, (char *) &nusers, (char *) NULL) != 0)
2N/A return (-1);
2N/A }
2N/A return (nusers);
2N/A}
2N/A
2N/Aenum clnt_stat
2N/Arusers(host, up)
2N/A char *host;
2N/A struct utmpidlearr *up;
2N/A{
2N/A return (rpc_call(host, RUSERSPROG, RUSERSVERS_IDLE, RUSERSPROC_NAMES,
2N/A xdr_void, (char *) NULL,
2N/A xdr_utmpidlearr, (char *) up, (char *) NULL));
2N/A}
2N/A