Skip to content

Commit

Permalink
added Esky.drop_root() method
Browse files Browse the repository at this point in the history
  • Loading branch information
rfk committed May 25, 2010
1 parent 030b491 commit a537e70
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

v0.6.1:
v0.7.0:

* Renamed "esky.helper" to "esky.sudo" along with much refactoring:
* esky.use_helper_app is now esky.allow_from_sudo() and is used to
declare a type signatures.
declare a type signature.
* Esky.helper_app is now Esky.sudo_proxy and is always an instance
of esky.sudo.SudoProxy.
* added Esky.drop_root() method to drop root privileges.
* Use a separate file "esky-lockfile.txt" for version locking. This
will help protect against strange behaviour when fcntl.flock is
simulated using fcntl.lockf (which released the lock when *any* handle
Expand Down
2 changes: 2 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ following methods control this behaviour:

app.get_root(): escalate to root privs by spawning helper app.

app.drop_root(): kill helper app and drop root privileges


When properly installed, the on-disk layout of an app managed by esky looks
like this:
Expand Down
8 changes: 8 additions & 0 deletions esky/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
app.get_root(): escalate to root privs by spawning helper app.
app.drop_root(): kill helper app and drop root privileges
When properly installed, the on-disk layout of an app managed by esky looks
like this:
Expand Down Expand Up @@ -328,6 +330,12 @@ def get_root(self):
if not self.sudo_proxy.has_root():
raise OSError(None,"could not escalate to root privileges")

def drop_root(self):
"""Drop root privileges by killing the helper app."""
if self.sudo_proxy is not None:
self.sudo_proxy.close()
self.sudo_proxy = None

@allow_from_sudo()
def cleanup(self):
"""Perform cleanup tasks in the app directory.
Expand Down
10 changes: 7 additions & 3 deletions esky/sudo/sudo_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ def close(self):
self.wfd = None
if os.path.isfile(self.wnm):
os.unlink(self.wnm)
if not os.listdir(self.tdir):
os.rmdir(self.tdir)
try:
if not os.listdir(self.tdir):
os.rmdir(self.tdir)
except EnvironmentError, e:
if e.errno != errno.ENOENT:
raise
super(SecureStringPipe,self).close()


Expand Down Expand Up @@ -126,7 +130,7 @@ def spawn_sudo(proxy):
exe = exe + [b64encode(pickle.dumps(proxy,HIGHEST_PROTOCOL))]
# Look for a variety of sudo-like programs
sudo = None
display_name = "%s updater" % (proxy.name,)
display_name = "%s update" % (proxy.name,)
if "DISPLAY" in os.environ:
sudo = find_exe("gksudo","-k","-D",display_name,"--")
if sudo is None:
Expand Down
8 changes: 6 additions & 2 deletions esky/tests/eskytester/script1.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ def cleanup():

# Upgrade to the next version (0.2, even though 0.3 is available)
if os.environ.get("ESKY_NEEDSROOT",""):
print "GETTING ROOT"
already_root = app.has_root()
app.get_root()
print "GOT ROOT"
assert app.has_root()
app.drop_root()
assert app.has_root() == already_root
app.get_root()


app.install_version("0.2")
app.reinitialize()
Expand Down

0 comments on commit a537e70

Please sign in to comment.