1 |
|
/* |
2 |
|
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
4 |
< |
* Copyright (C) 2000-2002 i-scream |
3 |
> |
* http://www.i-scream.org |
4 |
> |
* Copyright (C) 2000-2003 i-scream |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or |
7 |
|
* modify it under the terms of the GNU General Public License |
25 |
|
#include <stdlib.h> |
26 |
|
#include <stdio.h> |
27 |
|
#include <string.h> |
28 |
– |
#include <utmp.h> |
28 |
|
#include "statgrab.h" |
29 |
+ |
#ifdef ALLBSD |
30 |
+ |
#include <sys/types.h> |
31 |
+ |
#endif |
32 |
+ |
#include <utmp.h> |
33 |
|
|
34 |
+ |
#ifdef SOLARIS |
35 |
+ |
#define MAX_LOGIN_NAME_SIZE 8 |
36 |
+ |
#endif |
37 |
+ |
#if defined(LINUX) || defined(FREEBSD) |
38 |
+ |
#define MAX_LOGIN_NAME_SIZE UT_NAMESIZE |
39 |
+ |
#endif |
40 |
+ |
#ifdef NETBSD |
41 |
+ |
#define MAX_LOGIN_NAME_SIZE _POSIX_LOGIN_NAME_MAX |
42 |
+ |
#endif |
43 |
+ |
#if defined(CYGWIN) |
44 |
+ |
#define MAX_LOGIN_NAME_SIZE _SC_LOGIN_NAME_MAX |
45 |
+ |
#endif |
46 |
+ |
|
47 |
|
#define START_VAL (5*(1+MAX_LOGIN_NAME_SIZE)) |
48 |
|
|
49 |
|
user_stat_t *get_user_stats(){ |
52 |
|
static user_stat_t user_stats; |
53 |
|
static int size_of_namelist=-1; |
54 |
|
char *tmp; |
55 |
+ |
#if defined(SOLARIS) || defined(LINUX) || defined(CYGWIN) |
56 |
|
struct utmp *entry; |
57 |
+ |
#endif |
58 |
+ |
#ifdef ALLBSD |
59 |
+ |
struct utmp entry; |
60 |
+ |
FILE *f; |
61 |
+ |
#endif |
62 |
|
|
63 |
|
/* First case call */ |
64 |
|
if (size_of_namelist==-1){ |
71 |
|
|
72 |
|
/* Essentially blank the list, or give it a inital starting string */ |
73 |
|
strcpy(user_stats.name_list, ""); |
74 |
+ |
|
75 |
+ |
#if defined(SOLARIS) || defined(LINUX) || defined(CYGWIN) |
76 |
|
setutent(); |
77 |
|
while((entry=getutent()) != NULL) { |
78 |
|
if(entry->ut_type==USER_PROCESS) { |
92 |
|
} |
93 |
|
} |
94 |
|
endutent(); |
95 |
+ |
#endif |
96 |
+ |
#ifdef ALLBSD |
97 |
+ |
if ((f=fopen(_PATH_UTMP, "r")) == NULL){ |
98 |
+ |
return NULL; |
99 |
+ |
} |
100 |
+ |
while((fread(&entry, sizeof(entry),1,f)) != 0){ |
101 |
+ |
if (entry.ut_name[0] == '\0') continue; |
102 |
+ |
if((strlen(user_stats.name_list)+MAX_LOGIN_NAME_SIZE+2) > size_of_namelist){ |
103 |
+ |
tmp=user_stats.name_list; |
104 |
+ |
user_stats.name_list=realloc(user_stats.name_list, 1+(size_of_namelist*2)); |
105 |
+ |
if(user_stats.name_list==NULL){ |
106 |
+ |
user_stats.name_list=tmp; |
107 |
+ |
return NULL; |
108 |
+ |
} |
109 |
+ |
size_of_namelist=1+(size_of_namelist*2); |
110 |
+ |
|
111 |
+ |
} |
112 |
+ |
strncat(user_stats.name_list, entry.ut_name, MAX_LOGIN_NAME_SIZE); |
113 |
+ |
strcat(user_stats.name_list, " "); |
114 |
+ |
num_users++; |
115 |
+ |
} |
116 |
+ |
fclose(f); |
117 |
|
|
118 |
+ |
#endif |
119 |
|
/* We want to remove the last " " */ |
120 |
|
if(num_users!=0){ |
121 |
|
tmp=strrchr(user_stats.name_list, ' '); |