-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathidled-utmp.patch
193 lines (176 loc) · 5.69 KB
/
idled-utmp.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
diff -ur idled-1.16/idled.c idled-1.16.utmp/idled.c
--- idled-1.16/idled.c Thu May 16 23:59:33 1996
+++ idled-1.16.utmp/idled.c Tue Nov 21 15:59:43 2000
@@ -131,7 +131,6 @@
int fl_session = 1;
int new;
int res;
- int utmpfd;
int isConsole;
char pathbuf[20];
char tmpname[NAMELEN + 1];
@@ -139,9 +138,9 @@
int nextcheck; /* Number of seconds to next check status */
FILE *logfd;
#ifdef HAVE_UTMPX
- struct utmpx utmpbuf;
+ struct utmpx *utmpbuf;
#else
- struct utmp utmpbuf;
+ struct utmp *utmpbuf;
#endif
struct stat statbuf;
struct passwd *pswd;
@@ -273,11 +272,11 @@
(void) time (&tempus);
- if ((utmpfd = open (UTMP_FILE, O_RDONLY, 0)) == SYSERROR)
- {
- logfile ("%19.19s: Cannot open %s.",ctime(&tempus),UTMP_FILE);
- exit (1);
- }
+#ifdef HAVE_UTMPX
+ setutxent();
+#else
+ setutent();
+#endif
/* Set our nextcheck time to the max (sleeptime), though it may
* be lowered in the coming for loop so that an idle tty gets
@@ -307,9 +306,9 @@
*/
#ifdef HAVE_UTMPX
- for (utmptr = 0, userptr = 0; (res = read (utmpfd, (char *) &utmpbuf, sizeof (struct utmpx))) > 0;)
+ for (utmptr = 0, userptr = 0; (utmpbuf = getutxent()) != NULL;)
#else
- for (utmptr = 0, userptr = 0; (res = read (utmpfd, (char *) &utmpbuf, sizeof (struct utmp))) > 0;)
+ for (utmptr = 0, userptr = 0; (utmpbuf = getutent()) != NULL;)
#endif
{
if (utmptr >= MAXUSERS)
@@ -318,24 +317,14 @@
break;
}
-#ifdef HAVE_UTMPX
- if (res != sizeof (struct utmpx))
-#else
- if (res != sizeof (struct utmp))
-#endif
- {
- logfile ("Error reading utmp file, continuing.");
- break;
- }
-
(void) time (&tempus);
#ifdef XDM_HACK
isConsole = FALSE;
- if (strcmp(utmpbuf.ut_line,XDM_DEV) == 0)
+ if (strcmp(utmpbuf->ut_line,XDM_DEV) == 0)
{
/* This is the console. Is there a real name attached? */
- if (strlen(utmpbuf.ut_name) > 0)
+ if (strlen(utmpbuf->ut_name) > 0)
isConsole = TRUE; /* Yes, use it */
else
strcpy(console_user,""); /* No, clear the console user */
@@ -343,16 +332,16 @@
#endif
#ifdef SYSV
- if (utmpbuf.ut_type == USER_PROCESS || isConsole)
+ if (utmpbuf->ut_type == USER_PROCESS || isConsole)
#else /* SYSV */
- if (utmpbuf.ut_name[0] != NULL || isConsole)
+ if (utmpbuf->ut_name[0] != NULL || isConsole)
#endif /* SYSV */
{
user = &users[utmptr];
- (void) strncpy (tmpname, utmpbuf.ut_name, NAMELEN);
+ (void) strncpy (tmpname, utmpbuf->ut_name, NAMELEN);
tmpname[NAMELEN] = 0;
- if (!strcmp (user->uid, tmpname) && user->time_on == utmpbuf.ut_xtime)
+ if (!strcmp (user->uid, tmpname) && user->time_on == utmpbuf->ut_xtime)
{
if (new)
setlimits (utmptr);
@@ -377,18 +366,18 @@
continue;
#ifdef UTMPPID
- user->pid = utmpbuf.ut_pid;
+ user->pid = utmpbuf->ut_pid;
#endif /* UTMPPID */
#ifdef UTMPHOST
- debug(4,("utmp host is %s",utmpbuf.ut_host));
- if ((int)strlen(utmpbuf.ut_host) <= 0)
+ debug(4,("utmp host is %s",utmpbuf->ut_host));
+ if ((int)strlen(utmpbuf->ut_host) <= 0)
(void) strncpy (user->host,"localhost",HOSTLEN);
else
- (void) strncpy (user->host,utmpbuf.ut_host,HOSTLEN);
+ (void) strncpy (user->host,utmpbuf->ut_host,HOSTLEN);
user->host[HOSTLEN] = '\0'; /* Make sure that it is null-terminated */
#endif /* UTMPHOST */
(void) strcpy (pathbuf, DEV);
- (void) strcat (pathbuf, utmpbuf.ut_line);
+ (void) strcat (pathbuf, utmpbuf->ut_line);
(void) strcpy (user->line, pathbuf);
#ifdef XDM_HACK
if (isConsole)
@@ -402,7 +391,7 @@
logfile ("Error: could not get info on supposed user %s.",user->uid);
else
getgroups_func (pswd->pw_name, user->groups, pswd->pw_gid);
- user->time_on = utmpbuf.ut_xtime;
+ user->time_on = utmpbuf->ut_xtime;
setlimits (utmptr);
user->next = tempus;
chk_session_refuse(user);
@@ -453,7 +442,7 @@
/* If this line is the console, then make our console_user
* string empty, since no one is on it!
*/
- if (strcmp(CONSOLE_NAME,utmpbuf.ut_line) == 0)
+ if (strcmp(CONSOLE_NAME,utmpbuf->ut_line) == 0)
{
strcpy(console_user,"");
}
@@ -463,7 +452,12 @@
}
debug(5,("Checked The entire UTMP file!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"));
- (void) close (utmpfd);
+#ifdef HAVE_UTMPX
+ endutxent();
+#else
+ endutent();
+#endif
+
#ifdef XDM_HACK
/* If the console user has been marked for killing, then do it. */
diff -ur idled-1.16/utmplines.c idled-1.16.utmp/utmplines.c
--- idled-1.16/utmplines.c Thu Mar 21 21:22:41 1996
+++ idled-1.16.utmp/utmplines.c Tue Nov 21 15:55:49 2000
@@ -26,29 +26,15 @@
int main()
{
-#ifdef HAVE_UTMPX
- int fd, numlines;
- struct utmpx uent;
+ int numlines;
- fd = open(UTMP_FILE,O_RDONLY,0);
+ setutent();
numlines = 0;
- while (read(fd,&uent,sizeof(struct utmpx)) > 0)
+ while (getutent())
numlines++;
-#else
- int fd, numlines;
- struct utmp uent;
-
- fd = open(UTMP_FILE,O_RDONLY,0);
-
- numlines = 0;
- while (read(fd,&uent,sizeof(struct utmp)) > 0)
- numlines++;
-
-#endif
-
- close(fd);
+ endutent();
printf("Number of lines in utmp file: %d\n",numlines);