segunda-feira, 28 de setembro de 2009

Bug in autolog - User name with more then 8 characters

Autolog is a tool that helps the management of user sessions, the idea is to control the time that users are allowed to use the computer, and check for idle users.

The code that i'm working on has a bug that users with more then 8 characters (like leonardol, for instance) cannot be logged out due to the use of ps command. The ps command shows the userid instead of the user name if that user name has more than 8 chars.

So, this patch can fix the autolog.c code, if you need the files used to build this patch, send me an email.

I could not find the original developers of this tool, and the debian package has been abandoned also.

--- autolog.c 2009-09-23 12:07:41.000000000 -0300
+++ /tmp/autolog.c.old 2009-09-23 11:23:35.000000000 -0300
@@ -548,7 +548,6 @@
{
char ddev[STRLEN],*gn = "";
char dev[STRLEN], name[STRLEN], prname[STRLEN];
- char name_to_kill[STRLEN];
int idle;
struct stat status;
time_t start, stime;
@@ -556,12 +555,8 @@
struct group *group_entry;
conf_el *ce;
int i;
- int larger_than_eight; /* for usernames greater than 8 characters */

strcpy(name,akt_usr->Name );
-
- larger_than_eight = (strlen(name)>8);
-
strcpy(dev, akt_usr->Device);
idle = akt_usr->IdleTime;
stime = pres_time - akt_usr->SessStrt;
@@ -581,7 +576,6 @@
if (listall)
printf("\nChecking: %-11s on %-12s I:%-4d\n",name,dev,idle);

-
/* now try to find the group of this person */
/* if usernames in utmp are limited to 8 chars, we will may fail on */
/* names that are longer than this, so we'll try to find it by uid */
@@ -682,18 +676,11 @@

/*.. action either warning or killing. */
// if (akt_usr->WarnEndsed && (pres_time > akt_usr->Ban_Ends) ) {
-
- strcpy(name_to_kill,name);
-/* name is larger than_eight characters, get UID */
- if (larger_than_eight){
- name_to_kill[0] = '\0';
- sprintf(name_to_kill,"%d",passwd_entry->pw_uid);
-}
if (0WarnEnds && (pres_time > akt_usr->WarnEnds) ) {
if (debug)
printf("Killing user, now.\n");

- if (kill_PIDs(name_to_kill)==1) /* try to kill users' processes */
+ if (kill_PIDs(name)==1) /* try to kill users' processes */
mesg(LOGOFF, name, ddev, stime/60, idle, ce); /* mail to user */
else mesg(NOLOGOFF,name, ddev, stime/60, idle, ce); /* couldn't kill */
if (ce->hard)
@@ -715,7 +702,7 @@
mesg(ANGRY, name, ddev, stime/60, idle, ce); /* angry about user. */
if (debug)
printf("I am angry, user returned...\n");
- if (kill_PIDs(name_to_kill)==1) /* try to kill user, at once */
+ if (kill_PIDs(name)==1) /* try to kill user, at once */
mesg(LOGOFF, name, ddev, stime/60, idle, ce); /* mail to user */
else mesg(NOLOGOFF,name, ddev, stime/60, idle, ce); /* couldn't kill */
}

Nenhum comentário: