Should not be able to restrict myself

Bug #286529 reported by Even Nedberg
6
Affects Status Importance Assigned to Milestone
timekpr
Fix Released
Low
Savvas Radevic

Bug Description

In timekpr Control Panel I can set limits for myself (administrator). This should not be possible.

Revision history for this message
crjackson (crjackson) wrote :

Just confirming.

Changed in timekpr:
status: New → Confirmed
Revision history for this message
Savvas Radevic (medigeek) wrote : Re: [Bug 286529] [NEW] Should not be able to restrict first user

I was thinking we should add an 'Options' tab with a check box to
limit or not members of admin (or wheel?) group, the value would be
saved in timekpr.conf
Maybe postpone this for the next release? :)

Revision history for this message
Even Nedberg (nedberg) wrote : Re: Should not be able to restrict first user

Good idea Savvas!

Save it for later!

This is really just an annoyance. But it would not be wise to limit administrators (they would be able to 'unlimit' themselves anyway...).

Changed in timekpr:
importance: Undecided → Low
Revision history for this message
Savvas Radevic (medigeek) wrote :

will do :)

Changed in timekpr:
assignee: nobody → medigeek
Revision history for this message
crjackson (crjackson) wrote :

While I personally love options. Knowing that my wife WILL accidentally lock herself out when changing things, I think it would be better to eliminate the primary administrator from being limited. She does have her own login with admin rights as do I. I don't want her to have the ability to lock me out as the primary admin user. If she locks herself out it won't be that bad provided she CAN'T lock out the primary account. It's a safety net. I know I'll be here at work late at night, and the phone will ring... Honey! I've locked the computer by accident. No one can login. Tell me how to fix it. If she locked me out, there is no fix until tomorrow. As unlikly as you may think this sounds, it will happen.

My vote goes with Even’s first idea. Primary Administrator can’t be limited.

Just my 2¢

-Charles

Revision history for this message
Savvas Radevic (medigeek) wrote : Re: [Bug 286529] Re: Should not be able to restrict first user

Defining the first user ever created is a tricky thing to do I'm afraid.
I don't think there is a thing such as a primary administrator, if we
look at it in a broad manner, anyone can make the primary
administrator as user id 1002, and make the first user with id 1000
normal... I hope you understand what I mean :)

I'll disable it for now for userid 1000 and userid 500 (fedora), but I
think that would not be recommended for later releases

Revision history for this message
Savvas Radevic (medigeek) wrote : Re: Should not be able to restrict first user

applying fix

Changed in timekpr:
status: Confirmed → In Progress
Revision history for this message
Savvas Radevic (medigeek) wrote :

rev #117

Changed in timekpr:
status: In Progress → Fix Committed
Revision history for this message
crjackson (crjackson) wrote :

Understood perfectly. There's only so much that can be done.

Revision history for this message
Savvas Radevic (medigeek) wrote :

updated in #121 (using UID_MIN from login.defs to define first user)

Can you checkout the beta 2:
http://savvas.radevic.com/timekpr/timekpr_0.2.2~b2_all.deb

Changed in timekpr:
status: Fix Committed → Fix Released
Revision history for this message
crjackson (crjackson) wrote :

I'll get right on it. At work right now (as usual), I'll try to have some results by tomorrow. I plan to give it a rigorous test drive this weekend.

Revision history for this message
crjackson (crjackson) wrote :

Follow-up Report: After testing for several days on multiple systems, I'm happy to report EVERYTHING is working flawlessly sp far. The UID_MIN fix seems to be the perfect ticket here. Thanks for the hard work on this beta release.

Revision history for this message
manic (nicolas-launchpad-iselin) wrote :

I have the following situation: I have multiple PCs that I am responsible for, I force every person to have same uid on all my PCs. On many locations (Kids home, my home, grandparents) the Kids have a login and there are different grown-ups around to restrict kids access. None of the grown-ups (except me) has admin rights. All grown-ups should be able to restrict the access of all kids, but no grown-up should be able to restrict another grown-up.

My setup for timekpr is as follows:

/etc/sudoers:
...
User_Alias TIMEKPRS = administrator, parent1, parent2, grandpa, grandma
...
TIMEKPRS ALL=(root) NOPASSWD: /usr/bin/timekpr-gui ""

this survives a reinstall of timekpr. However, the next fix I apply always manually after a reinstall.

/var/lib/python-support/python2.5/timekpr-gui.py
def isnormal(username):
    ...
    elif userid == 1001 or userid == 2000 or userid == 2004 or userid == 2005 :
        return False
    ...

of course, 1001=parent1, 2000=parent2, 2004=grandpa, 2005=grandma.

I don't think this is the best implementation, but it is the simplest for me. I think it is very important, that you DO NOT use a "root" group to determine the "grown-up/kid" state. Maybe creating an own group "timekprs" would make sense...

Revision history for this message
lykwydchykyn (me-alandmoore) wrote :

How do I undo this fix? I have computers where uid 1000 is not an admin and needs to be restricted.
Why not just check to see if users are members of the admins group? That seems more to the point.

Revision history for this message
Even Nedberg (nedberg) wrote :

In /usr/share/python-support/timekpr/timekpr-gui.py find

def isnormal(username):

change

if userid == uidmin:
        return False
    elif uidmin < userid <= uidmax:
        return True

into

if userid == <your admin userid>:
        return False
    elif uidmin <= userid <= uidmax:
        return True

It should work after this. We will try to fix this in a later release!

If you apply this "fix" it will be overwritten if you update timekpr.

Savvas, would it be possible to get the username of the user running timekpr-gui? Then make it impossible to restrict oneself?
What about sorting the list of users in reverse order. That way the pre-selected user would not be the first user created (who, most probably, is an administrator).
Make a list of users NOT to be restricted and check against this when populating the drop down? The list could be created when a user first starts timekpr-gui.

I am just making suggestions here. But I think we need to get this sorted out...

Revision history for this message
Savvas Radevic (medigeek) wrote :

You have to remove two lines in timekpr-gui.py file:
 #FIXME: Temporary fix for: https://bugs.launchpad.net/bugs/286529
 if userid == "1000" or userid == "500": return 0

Revision history for this message
Savvas Radevic (medigeek) wrote :

> Savvas, would it be possible to get the username of the user running timekpr-gui? Then make it impossible to restrict oneself?

Looking for it, I'll let you know :)

Revision history for this message
Savvas Radevic (medigeek) wrote :

os.getlogin() = active user

Revision history for this message
Even Nedberg (nedberg) wrote :

Savvas, I think those lines was removed before we released 0.2.2...

I will have a look at os.getlogin()!

Revision history for this message
Savvas Radevic (medigeek) wrote :

Correct, sorry, I was looking at the old #117 revision

Even, can you test revision #202 ?:)
It's supposed to hide the active user

Revision history for this message
Even Nedberg (nedberg) wrote :

No, it did not work. Here is the error:
  File "/usr/share/python-support/timekpr/timekpr-gui.py", line 585, in
<module>
    timekprGUI()
  File "/usr/share/python-support/timekpr/timekpr-gui.py", line 150, in
__init__
    if isnormal(userinfo[0]):
  File "/usr/share/python-support/timekpr/timekpr-gui.py", line 70, in
isnormal
    if username == getlogin(): return False
OSError: [Errno 22] Invalid argument

Sorry, I don't have time to do more testing right now. I had to do some changes (import os.getlogin() among other things). So bzr pull before you do anything more!

I also found this:
http://bugs.python.org/issue678077

stating that os.getlogin() is not good! I tried pwd.getpwuid(os.getuid())[0], but that returned 'root' as user...

Revision history for this message
Savvas Radevic (medigeek) wrote : Re: [Bug 286529] Re: Should not be able to restrict first user

Ah, thanks - I tested #203 locally - it works, thanks!

> pwd.getpwuid(os.getuid())[0], but that returned 'root' as user...

I know, that's why I suggested using getlogin. :)

The other way to get this is to use:

from os import getenv
getenv("LOGNAME")
getenv("SUDO_USER")

Revision history for this message
Savvas Radevic (medigeek) wrote :

I think the solution Even suggested fits... no need to check for other administrators, but perhaps in the future to make a way to customize the list :)

description: updated
Revision history for this message
Even Nedberg (nedberg) wrote :

#203 does not work in my VMs. When I start timekpr-gui with

gksu timekpr-gui
or
gksudo timekpr-gui

I get the error above.

When I run it with

sudo timekpr-gui

it works fine. But I don't think you should run GUI-apps with sudo (also the menu launcher uses gksu).

Revision history for this message
Savvas Radevic (medigeek) wrote :

OK, then we have a problem.

We could use the values I mentioned above:
$ gksu -- python -c 'from os import getenv ; print(getenv("LOGNAME"),getenv("SUDO_USER"))'
('root', 'forger')

I'll test a check locally and let you know

Changed in timekpr:
status: Fix Released → In Progress
Revision history for this message
Savvas Radevic (medigeek) wrote :

How about this?
from os import remove, mkdir, geteuid, getenv

def isnormal(username):
    #FIXME: Hide active user - bug #286529
    if (getenv('SUDO_USER') and username == getenv('SUDO_USER')) or username == 'root':
        return False

Revision history for this message
Savvas Radevic (medigeek) wrote :

Tested with gksu, gksudo and sudo.

Revision history for this message
Savvas Radevic (medigeek) wrote :

Err... actually I don't think there's a need to check username == 'root', since root has user id 0.

I think this should do fine:

from os import remove, mkdir, geteuid, getenv

def isnormal(username):
    #FIXME: Hide active user - bug #286529
    if (getenv('SUDO_USER') and username == getenv('SUDO_USER')):
        return False

Revision history for this message
Savvas Radevic (medigeek) wrote :

rev. 204 - I hope there are no problems now :)

Changed in timekpr:
status: In Progress → Fix Committed
Revision history for this message
Even Nedberg (nedberg) wrote :

#204 works fine here!

Revision history for this message
Savvas Radevic (medigeek) wrote : Re: [Bug 286529] Re: Should not be able to restrict myself

> #204 works fine here!

Thanks for testing it - thank you everyone for your input! :)

Even Nedberg (nedberg)
Changed in timekpr:
status: Fix Committed → Fix Released
Revision history for this message
Savvas Radevic (medigeek) wrote :

milestone 0.3.0

Revision history for this message
Savvas Radevic (medigeek) wrote :

milestone 0.3.0

Changed in timekpr:
milestone: none → 0.3.0
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.