Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dbus service to support telemetry jwt operation #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions host_modules/user_auth_mgmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
""" Host User Authentication management dbus endpoint handler"""
import host_service
import pwd, grp, syslog

mod_name= 'user_auth_mgmt'

class UserAuthMgmt(host_service.HostModule):
"""DBus endpoint that handles Infra user authentication related operations """


def __init__(self, name):
super().__init__(name)

@staticmethod
def get_user_roles(username):
""" Return the user role to the provided username"""
output = ","
roles = []
try:
pwd.getpwnam(username)
except:
syslog.syslog(syslog.LOG_ERR,"Invalid user")
return 1,"Invalid user"
gids = [g.gr_gid for g in grp.getgrall() if username in g.gr_mem]
gid = pwd.getpwnam(username).pw_gid
gids.append(grp.getgrgid(gid).gr_gid)
roles = [grp.getgrgid(gid).gr_name for gid in gids]
if len(roles) > 0:
output = output.join(roles)
else:
return 1,"No roles for the user"
return 0,output

@host_service.method(host_service.bus_name(mod_name), in_signature='s', out_signature='is')
def retrieve_user_roles(self, options):
return UserAuthMgmt.get_user_roles(options)


def register():
"""Return class name"""
return UserAuthMgmt, mod_name
Loading