diff options
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | Makefile.in | 7 | ||||
-rw-r--r-- | src/py-libs/uid.py | 56 |
3 files changed, 64 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am index cefe1b2..37710b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,10 +51,11 @@ man_MANS = docs/mock.1 pkgpython_PYTHON = \ src/py-libs/__init__.py \ src/py-libs/exception.py \ - src/py-libs/util.py \ - src/py-libs/backend.py \ + src/py-libs/util.py \ + src/py-libs/backend.py \ src/py-libs/decorator.py \ - src/py-libs/trace_decorator.py + src/py-libs/trace_decorator.py \ + src/py-libs/uid.py src/mock.py: configure.ac Makefile.am src/mock.py echo Updating $@, current pwd: $$(pwd) diff --git a/Makefile.in b/Makefile.in index 0506b6d..68cb6bd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -278,10 +278,11 @@ man_MANS = docs/mock.1 pkgpython_PYTHON = \ src/py-libs/__init__.py \ src/py-libs/exception.py \ - src/py-libs/util.py \ - src/py-libs/backend.py \ + src/py-libs/util.py \ + src/py-libs/backend.py \ src/py-libs/decorator.py \ - src/py-libs/trace_decorator.py + src/py-libs/trace_decorator.py \ + src/py-libs/uid.py all: all-recursive diff --git a/src/py-libs/uid.py b/src/py-libs/uid.py new file mode 100644 index 0000000..57142ff --- /dev/null +++ b/src/py-libs/uid.py @@ -0,0 +1,56 @@ +#!/usr/bin/python -tt +# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0: +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Written by Seth Vidal +# Sections taken from Mach by Thomas Vander Stichele +# revised and adapted by Michael Brown + +# python library imports +import os + +# our imports +from mock.trace_decorator import trace + +# functions + +origruid=os.getruid() # 500 +origeuid=os.geteuid() # 0 + +@trace +def savePerms(): + global origruid + global origeuid + origruid = os.getruid() + origeuid = os.geteuid() + +@trace +def elevatePerms(): + os.setreuid(0, 0) + +@trace +def dropPermsTemp(): + elevatePerms() + os.setreuid(0, origruid) + +@trace +def dropPermsForever(): + elevatePerms() + os.setreuid(origruid, origruid) + +@trace +def becomeUser(uid): + elevatePerms() + os.setreuid(0, uid) |