From: Ralf Ertzinger Date: Thu, 20 Feb 2014 21:06:21 +0000 (+0100) Subject: Add linux version of rbac module X-Git-Tag: 0.2.98.python3.1~33 X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=time-slider.git;a=commitdiff_plain;h=fbd70d0b815503960adc2c3e5ec1a1247523087c Add linux version of rbac module --- diff --git a/usr/share/time-slider/lib/time_slider/linuxrbac.py b/usr/share/time-slider/lib/time_slider/linuxrbac.py new file mode 100755 index 0000000..6421fa4 --- /dev/null +++ b/usr/share/time-slider/lib/time_slider/linuxrbac.py @@ -0,0 +1,67 @@ +#!/usr/bin/python2 +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +import os +import pwd + +import util + +class RBACprofile: + + def __init__(self, name = None): + # Filtering through the pwd module is beneficial because + # it will raise a KeyError exception for an invalid + # name argument + if name == None: + euid = os.geteuid() + pwnam = pwd.getpwuid(euid) + self.uid = euid + self.name = pwnam[0] + else: + pwnam = pwd.getpwnam(name) + self.name = pwnam[0] + self.uid = pwnam[2] + + self.profiles = [] + self.auths = [] + + def has_profile(self, profile): + # root is all powerful + if self.uid == 0: + return True + else: + return False + + def has_auth(self, auth): + # root is all powerful + if self.uid == 0: + return True + else: + return False + +if __name__ == "__main__": + rbac = RBACprofile() + print rbac.name + print rbac.uid + print rbac.profiles + print rbac.auths + diff --git a/usr/share/time-slider/lib/time_slider/timesliderd.py b/usr/share/time-slider/lib/time_slider/timesliderd.py index 08a2937..194d8b1 100755 --- a/usr/share/time-slider/lib/time_slider/timesliderd.py +++ b/usr/share/time-slider/lib/time_slider/timesliderd.py @@ -46,7 +46,7 @@ import smf import timeslidersmf import autosnapsmf import plugin -from rbac import RBACprofile +from linuxrbac import RBACprofile import util _MINUTE = 60