1 diff -urN autolog-0.34.orig/Makefile autolog-0.34/Makefile
2 --- autolog-0.34.orig/Makefile Fri Oct 16 20:38:44 1998
3 +++ autolog-0.34/Makefile Fri Oct 16 20:39:16 1998
5 # The -g flag is to include debugging information. It gets
6 # stripped back out in the install command anyway.
11 +CFLAGS = -O2 -g -Wall
12 +MANDIR = $(DESTDIR)/usr/man
13 +BINDIR = $(DESTDIR)/usr/sbin
14 # *********************************************************
20 install -s autolog $(BINDIR)
21 - install -m644 autolog.conf.5 $(MANDIR)/man5
22 - install -m644 autolog.8 $(MANDIR)/man8
23 + install -p -m644 autolog.conf.5 $(MANDIR)/man5
24 + install -p -m644 autolog.8 $(MANDIR)/man8
25 + install -p -m644 crontab $(DESTDIR)/etc/cron.d/autolog
30 diff -urN autolog-0.34.orig/autolog.8 autolog-0.34/autolog.8
31 --- autolog-0.34.orig/autolog.8 Fri Oct 16 20:38:44 1998
32 +++ autolog-0.34/autolog.8 Fri Oct 16 20:39:16 1998
34 -.TH AUTOLOG 1L "Administrative Utilities" "Linux" \" -*- nroff -*-
35 +.TH AUTOLOG 8 "Administrative Utilities" "Linux" \" -*- nroff -*-
37 autolog \- Log out idle users
42 The program reads the utmp file, entry by entry. The
43 -username for each 'user process' is compared to the entries in the
44 -configuration file (see
46 -). The first entry to match both the name, the group,
47 +username for each `user process' is compared to the entries in the
50 +The first entry to match both the name, the group,
51 and the tty line of the process will be used to conduct the automatic
58 (all processes) Print information on ALL utmp entries--not just user processes.
62 (debug mode) This is helpful in setting up your configuration file.
63 The program runs in foreground rather than forking and it prints
64 out verbose messages about what it is doing.
68 (nokill) Use this to prevent autolog from actually "killing"
69 anyone. Use -d and -n together when setting up a new
72 -.B -f config_file_name
73 -Use this to override the default: "/etc/autolog.conf"
76 -Use this to override the default: "/var/log/autolog.log".
77 +.I -f config_file_name
78 +Use this to override the default:
82 +Use this to override the default:
83 +.IR /var/log/autolog.log .
84 Note that if this file doesn't exist, no logging will happen.
85 Create the file (with touch) to enable logging.
89 Use this to override the internal default idle time (minutes)
93 Use this to override the internal default grace period (seconds)
97 Use this to override the internal mailing switch. If "yes"
98 the program will send mail to the users right after killing them.
102 Use this to override the internal "pre-clear" switch. If "yes"
103 the program will clear the terminal screen before warning the user.
107 Do timeouts based on total session time--not idle time. (hard)
111 If set to "yes" activities will be written to the logfile if
114 +.BR autolog.conf (5)
116 Kyle Bateman <kyle@actarg.com>
117 diff -urN autolog-0.34.orig/autolog.c autolog-0.34/autolog.c
118 --- autolog-0.34.orig/autolog.c Fri Oct 16 20:38:44 1998
119 +++ autolog-0.34/autolog.c Fri Oct 16 20:39:16 1998
121 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
128 #include <sys/types.h>
129 #include <sys/stat.h>
135 conf_el c_arr[MAXCONF];
138 -main(int argc, char *argv[])
139 +void eat_confile(void);
140 +int check_idle(void);
141 +void bailout(const char *message, int status) __attribute__ ((noreturn));
142 +void mesg(int flag, char *name, char *dev, int stime, int idle, conf_el *ce);
143 +int killit(pid_t pid);
145 +int main(int argc, char *argv[])
148 for (i = 1; i < argc; i++)
149 @@ -132,15 +140,15 @@
150 eat_confile(); /* read config file */
151 if (!debug) /* if not in debug mode, */
152 if (fork()) /* the parent process */
153 - exit(0); /* exits */
154 + return 0; /* exits */
156 /* the child processes all utmp file entries: */
157 while ((utmpp = getutent()) != (struct utmp *) NULL)
159 - exit(0); /* done, so bye */
160 + return 0; /* done, so bye */
164 +void set_defs(int i)
166 c_arr[i].name = anystrg;
167 c_arr[i].group = anystrg;
169 c_arr[i].log = g_log;
173 +void eat_confile(void)
176 char *s, iline[LINELEN];
179 while (fgets(iline, LINELEN, f))
181 - if (*iline == '#' || strlen(iline) <= 1)
182 + if (*iline == '#' || !iline[0] || !iline[1])
185 s=strtok(iline,delims);
187 printf("Unknown token in file: %s: %s\n",confname,s);
190 - while(s=strtok(0,delims));
191 + while((s=strtok(NULL,delims)));
196 /* versions of the routine should work for you. */
197 #define AVOID_REGEX_BUG
198 #ifdef AVOID_REGEX_BUG /* some strange bug in re_exec */
199 -pat_match(char *patt, char *strg)
200 +int pat_match(char *patt, char *strg)
202 struct re_pattern_buffer rpb;
204 @@ -249,16 +257,16 @@
207 /* return true if strg matches the regex in pattern */
208 -pat_match(char *pattern,char *strg)
209 +int pat_match(char *pattern,char *strg)
212 return(re_exec(strg));
216 -check_idle() /* select utmp entries needing killing */
217 +int check_idle(void) /* select utmp entries needing killing */
219 - char dev[STRLEN], name[STRLEN], prname[STRLEN], *gn = "";
220 + char dev[STRLEN], name[STRLEN], *gn = "";
222 time_t idle, pres_time, start, time(), stime, atime;
223 struct passwd *passwd_entry;
225 printf("Non-user process: N:%-8s P:%5d Login:%s",utmpp->ut_user,utmpp->ut_pid,ctime(&utmpp->ut_time));
226 return(0); /* skip the utmp entry */
228 - sprintf(prname,"/proc/%d",utmpp->ut_pid); /* make filename to check in /proc */
229 - if (stat(prname, &status)) /* is this a current process */
230 + if (kill(utmpp->ut_pid,0)) /* is this a current process? */
233 printf("Dead process: N:%-8s P:%5d Login:%s",utmpp->ut_user,utmpp->ut_pid,ctime(&utmpp->ut_time));
235 name[UT_NAMESIZE] = '\0'; /* null terminate user name string */
238 - printf("\nChecking: %-11s on %-12s I:%-4d T:%d Login: %s",name,dev,idle,utmpp->ut_type,ctime(&utmpp->ut_time));
239 + printf("\nChecking: %-11s on %-12s I:%-4ld T:%d Login: %s",name,dev,idle,utmpp->ut_type,ctime(&utmpp->ut_time));
241 /* now try to find the group of this person */
242 /* if usernames in utmp are limited to 8 chars, we will may fail on */
246 strcpy(name,passwd_entry->pw_name);
247 - if(group_entry = getgrgid( passwd_entry->pw_gid ))
248 + if((group_entry = getgrgid( passwd_entry->pw_gid )))
249 gn = group_entry->gr_name;
251 printf("Can't find group entry for user: %s\n",name);
253 pat_match(c_arr[i].line,utmpp->ut_line))
256 - printf("Match #%2d: U:%-12s Grp:%-8s Line:%-9s Pid:%-6d Sess:%3d:%02d\n",
257 - i+1,name,gn,utmpp->ut_line,utmpp->ut_pid,stime/60,stime%60);
258 + printf("Match #%2d: U:%-12s Grp:%-8s Line:%-9s Pid:%-6d Sess:%3ld:%02d\n",
259 + i+1,name,gn,utmpp->ut_line,utmpp->ut_pid,stime/60,(int)(stime%60));
260 if (!c_arr[i].idle) /* if user exempt (idle=0) */
263 @@ -338,14 +345,14 @@
264 if (!c_arr[i].hard) /* if considering idle time */
267 - printf("Subject to logout Idle time: %4d (%2d allowed)\n",idle,ce->idle);
268 + printf("Subject to logout Idle time: %4ld (%2d allowed)\n",idle,ce->idle);
269 if (idle < ce->idle) /* if user was recently active */
270 return(0); /* let it live */
275 - printf("Subject to logout Total time: %4d (%2d allowed)\n",stime,ce->idle);
276 + printf("Subject to logout Total time: %4ld (%2d allowed)\n",stime,ce->idle);
277 if (stime < ce->idle) /* if user still under limit */
278 return(0); /* let it live */
284 -mesg(int flag, char *name, char *dev, int stime, int idle, conf_el *ce)
285 +void mesg(int flag, char *name, char *dev, int stime, int idle, conf_el *ce)
287 char mbuf[LINELEN]; /* message buffer */
289 @@ -417,10 +424,10 @@
290 fprintf(log, "** LOGOFF ** %s %s idle:%d sess:%d %s",name, dev+5, idle, stime, ctime(&tvec)+3);
293 - sprintf(mbuf, "/bin/mail %s", name);
294 + sprintf(mbuf, "/usr/sbin/sendmail %s", name);
295 /* open pipe to mail program for writing */
296 if (!(mprog = popen(mbuf, "w")) )
297 - bailout("Can't use /bin/mail program", 6);
298 + bailout("Can't use /usr/sbin/sendmail program", 6);
299 fprintf(mprog, "Subject: Excess Idle Time\nLogged off - excess idle time - %s %s\ntty = %s\n",name, ctime(&tvec), dev+5);
302 @@ -431,18 +438,18 @@
303 fprintf(log, "** LOGOFF-FAIL ** %s (pid = %d) %s (%d min idle time) %s",name, utmpp->ut_pid, dev+5, idle, ctime(&tvec)+3);
306 - sprintf(mbuf, "/bin/mail root");
307 + sprintf(mbuf, "/usr/sbin/sendmail root");
308 if ((mprog = popen(mbuf, "w")) == (FILE *) NULL)
309 - bailout("Can't use /bin/mail program", 7);
310 + bailout("Can't use /usr/sbin/sendmail program", 7);
311 fprintf(mprog, "Subject: Can't logoff %s\nCan't Log off - %s %s\ntty = %s\n", name, name, ctime(&tvec), dev+5);
321 -killit(int pid) /* terminate process using SIGHUP, then SIGKILL */
322 +int killit(pid_t pid) /* terminate process using SIGHUP, then SIGKILL */
324 kill(pid, SIGHUP); /* first send "hangup" signal */
327 return(1); /* successful kill with SIGHUP */
330 -bailout(char *message, int status) /* display error message and exit */
331 +void bailout(const char *message, int status) /* display error message and exit */
333 - fprintf(stderr,"autologout: %s\n", message);
334 + fprintf(stderr,"autologout: %s (%m)\n", message);
337 diff -urN autolog-0.34.orig/autolog.conf.5 autolog-0.34/autolog.conf.5
338 --- autolog-0.34.orig/autolog.conf.5 Fri Oct 16 20:38:44 1998
339 +++ autolog-0.34/autolog.conf.5 Fri Oct 16 20:39:16 1998
341 -.TH autolog.conf 1L "Configuration Files" "Linux" \" -*- nroff -*-
342 +.TH autolog.conf 5 "Configuration Files" "Linux" \" -*- nroff -*-
344 autolog.conf \- Configuration file for the autolog command
347 entry which has all values set from the defaults. This entry will match
348 any process on any port (name=.+ line=.+ group=.+). Therefore, the default
349 action is to kill all processes.
354 A regular expression specifying which username(s) to match.
355 diff -urN autolog-0.34.orig/crontab autolog-0.34/crontab
356 --- autolog-0.34.orig/crontab Thu Jan 1 01:00:00 1970
357 +++ autolog-0.34/crontab Fri Oct 16 20:39:17 1998
359 +*/10 * * * * root test -x /usr/sbin/autolog && /usr/sbin/autolog