login_activity doesn't work on Ubuntu precise 12.04

Bug #1072298 reported by Thomas Gutzler
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
TurnOff
Fix Released
Undecided
Unassigned

Bug Description

I believe the output of "who" has changed and the simple check
if login != "" and "(:0" not in login:
doesn't work any more. This is what it looks like now:
$ who
mythtv tty7 2012-10-28 09:27
tom pts/6 2012-10-28 19:49 (192.168.1.11)

My solution is to match against pts/x to find out if anyone's logged in remotely as local logins show up as tty/x.

Patch:
=== modified file 'src/turnoff/login_activity.py' (properties changed: +x to -x)
--- src/turnoff/login_activity.py 2012-02-02 12:15:19 +0000
+++ src/turnoff/login_activity.py 2012-10-28 08:46:53 +0000
@@ -19,7 +19,7 @@
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 """

-import activity
+import activity, re
 from activity import Activity
 from globals import log, run

@@ -31,7 +31,8 @@
     def is_idle(self):
         logins = run("who").strip().split('\n')
         for login in logins:
- if login != "" and "(:0" not in login:
+ #if login != "" and "(:0" not in login:
+ if re.match('.*\spts\/\d+\s', login):
                 return False
         return True

Related branches

Revision history for this message
Pekka Jääskeläinen (pekka-jaaskelainen) wrote :

OK, this fix committed, thanks. Please test.

Changed in turnoff:
status: New → Fix Committed
Revision history for this message
Pekka Jääskeläinen (pekka-jaaskelainen) wrote :

Unfortunately it broke my Debian Sid with the output:

visit0r pts/0 :0 Tue17 16:00m 1:51 1:51 /usr/local/bin/mythwelcome
visit0r pts/1 192.168.1.2 09:02 0.00s 0.17s 0.00s w

I.e. both local and remove consoles are shown as pts/X.

Changed in turnoff:
status: Fix Committed → Triaged
Revision history for this message
Pekka Jääskeläinen (pekka-jaaskelainen) wrote :

Sorry, that was for 'w'. 'who':

visit0r pts/0 2012-11-06 17:01 (:0)
visit0r pts/1 2012-11-07 09:02 (192.168.1.2)

Revision history for this message
Thomas Gutzler (78luphr0rnk2nuqimstywepozxn9kl19tqh0tx66b5dki1xxsh5mkz9gl21a5rlwfnr8jn6ln0-launchpad-a811i2i3ytqlsztthjth0svbccw8inm65tmkqp9sarr553jq53in4xm1m8wn3o4rlwaer06ogw) wrote :

How about we search for IP addresses in brackets at the end of the line. Instead of looking for pts
if re.match('.*\spts\/\d+\s', login):
use:
if re.search('\(([0-2]?\d{0,2}\.){3}([0-2]?\d{0,2})(:S\.\d+){0,1}\)$', login):

This will match
tom pts/5 2012-11-07 21:20 (192.168.1.11:S.1)
tom pts/6 2012-11-07 21:47 (192.168.1.11)
visit0r pts/1 2012-11-07 09:02 (192.168.1.2)

but not
visit0r pts/0 2012-11-06 17:01 (:0)
mythtv tty7 2012-11-07 18:31

Revision history for this message
Pekka Jääskeläinen (pekka-jaaskelainen) wrote :

What about ipv6? Maybe inverted logic to strip the (:\d*) and tty cases is more robust?

Revision history for this message
Thomas Gutzler (78luphr0rnk2nuqimstywepozxn9kl19tqh0tx66b5dki1xxsh5mkz9gl21a5rlwfnr8jn6ln0-launchpad-a811i2i3ytqlsztthjth0svbccw8inm65tmkqp9sarr553jq53in4xm1m8wn3o4rlwaer06ogw) wrote :

The question is, how do other OS's present the 'who' output. I have a feeling it might be more robust to rely on an IP address being shown (indicating a remote login) rather than anything else. Unfortunately, I have no other unixes to play with.
An ipv6 regex isn't very difficult to make up. After all, you're looking for a remote login - it seems logical to search for indicators resulting from remote logins rather than not all indicators that aren't remote logins...
Your call

Revision history for this message
Pekka Jääskeläinen (pekka-jaaskelainen) wrote :

Yep, you are right. I'll test the ip recheck for some days in my Debian Sid box and commit if it seems alright.

Revision history for this message
Thomas Gutzler (78luphr0rnk2nuqimstywepozxn9kl19tqh0tx66b5dki1xxsh5mkz9gl21a5rlwfnr8jn6ln0-launchpad-a811i2i3ytqlsztthjth0svbccw8inm65tmkqp9sarr553jq53in4xm1m8wn3o4rlwaer06ogw) wrote :

You can always do this for ipv6:
if re.search('\(([0-2]?\d{0,2}\.){3}([0-2]?\d{0,2})(:S\.\d+){0,1}\)$', login) or re.search('\(([\da-fA-F]{1,4}:){7}([\da-fA-F]{1,4})(:S\.\d+){0,1}\)$', login)
but I haven't tested that

Revision history for this message
Pekka Jääskeläinen (pekka-jaaskelainen) wrote :

I committed an ipv4-only version for now.

Changed in turnoff:
status: Triaged → Fix Committed
Revision history for this message
Paul Rensing (prensing) wrote :

Unfortunately, that does not work on my system (Ubuntu 12.04). It appears if you can DNS resolve the IP address, then who prints the host name, not the IP address. For instance, I have:
prensing pts/1 2013-04-20 16:50 (pollux.rensing)

Revision history for this message
Pekka Jääskeläinen (pekka-jaaskelainen) wrote :

Can you try changing "who" in src/turnoff/login_activity.py to "who --ips" and test if it works?

Changed in turnoff:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.