4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 #pragma ident "%Z%%M% %I% %E% SMI"
26 * These are the "easy to use" interfaces to rusers.
28 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
29 * Use is subject to license terms.
34 #include <rpcsvc/rusers.h>
42 struct utmpidlearr up
;
44 if (rpc_call(host
, RUSERSPROG
, RUSERSVERS_3
, RUSERSPROC_NAMES
,
45 xdr_void
, (char *) NULL
,
46 xdr_utmp_array
, (char *) uap
, (char *) NULL
) != 0) {
48 * If version 3 isn't available, try version 2. We'll have to
49 * convert a utmpidlearr structure into a utmp_array.
53 if (rusers(host
, &up
) != 0)
57 struct ru_utmp forsize
;
60 uap
->utmp_array_val
= (rusers_utmp
*)malloc(up
.uia_cnt
61 * sizeof (rusers_utmp
));
62 if (uap
->utmp_array_val
== NULL
) {
63 xdr_free(xdr_utmpidlearr
, (char *)&up
);
66 uap
->utmp_array_len
= up
.uia_cnt
;
67 for (rutp
= uap
->utmp_array_val
, i
= 0;
68 i
< up
.uia_cnt
; rutp
++, i
++) {
69 rutp
->ut_line
= (char *)malloc(sizeof
71 rutp
->ut_user
= (char *)malloc(sizeof
73 rutp
->ut_host
= (char *)malloc(sizeof
75 if (rutp
->ut_line
== NULL
||
76 rutp
->ut_user
== NULL
||
77 rutp
->ut_host
== NULL
) {
79 while (--rutp
>= uap
->utmp_array_val
) {
84 free(uap
->utmp_array_val
);
85 xdr_free(xdr_utmpidlearr
, (char *)&up
);
88 strncpy(rutp
->ut_line
,
89 up
.uia_arr
[i
]->ui_utmp
.ut_line
,
90 sizeof (forsize
.ut_line
)+1);
91 strncpy(rutp
->ut_user
,
92 up
.uia_arr
[i
]->ui_utmp
.ut_name
,
93 sizeof (forsize
.ut_name
)+1);
94 strncpy(rutp
->ut_host
,
95 up
.uia_arr
[i
]->ui_utmp
.ut_host
,
96 sizeof (forsize
.ut_host
)+1);
97 rutp
->ut_idle
= up
.uia_arr
[i
]->ui_idle
;
98 rutp
->ut_time
= up
.uia_arr
[i
]->ui_utmp
.ut_time
;
99 rutp
->ut_type
= RUSERS_USER_PROCESS
;
102 xdr_free(xdr_utmpidlearr
, (char *)&up
);
114 if (rpc_call(host
, RUSERSPROG
, RUSERSVERS_3
, RUSERSPROC_NUM
,
115 xdr_void
, (char *) NULL
,
116 xdr_u_int
, (char *) &nusers
, (char *) NULL
) != 0) {
117 if (rpc_call(host
, RUSERSPROG
, RUSERSVERS_IDLE
, RUSERSPROC_NUM
,
118 xdr_void
, (char *) NULL
,
119 xdr_u_int
, (char *) &nusers
, (char *) NULL
) != 0)
128 struct utmpidlearr
*up
;
130 return (rpc_call(host
, RUSERSPROG
, RUSERSVERS_IDLE
, RUSERSPROC_NAMES
,
131 xdr_void
, (char *) NULL
,
132 xdr_utmpidlearr
, (char *) up
, (char *) NULL
));