#NEWLINE# def get_group_list( user = None , include_default = True ) : #NEWLINE# #INDENT# '\n    Returns a list of all of the system group names of which the user\n    is a member.\n    ' #NEWLINE# if ( ( HAS_GRP is False ) or ( HAS_PWD is False ) ) : #NEWLINE# #INDENT# return [ ] #NEWLINE# #UNINDENT# group_names = None #NEWLINE# ugroups = set ( ) #NEWLINE# if ( not isinstance ( user , six . string_types ) ) : #NEWLINE# #INDENT# raise Exception #NEWLINE# #UNINDENT# if hasattr ( os , 'getgrouplist' ) : #NEWLINE# #INDENT# log . trace ( "Trying os.getgrouplist for '{0}'" . format ( user ) ) #NEWLINE# try : #NEWLINE# #INDENT# group_names = [ grp . getgrgid ( grpid ) . gr_name for grpid in os . getgrouplist ( user , pwd . getpwnam ( user ) . pw_gid ) ] #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# log . trace ( "Trying pysss.getgrouplist for '{0}'" . format ( user ) ) #NEWLINE# try : #NEWLINE# #INDENT# import pysss #NEWLINE# group_names = list ( pysss . getgrouplist ( ugroups ) ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( group_names is None ) : #NEWLINE# #INDENT# log . trace ( "Trying generic group list for '{0}'" . format ( user ) ) #NEWLINE# group_names = [ g . gr_name for g in grp . getgrall ( ) if ( user in g . gr_mem ) ] #NEWLINE# try : #NEWLINE# #INDENT# default_group = grp . getgrgid ( pwd . getpwnam ( user ) . pw_gid ) . gr_name #NEWLINE# if ( default_group not in group_names ) : #NEWLINE# #INDENT# group_names . append ( default_group ) #NEWLINE# #UNINDENT# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# ugroups . update ( group_names ) #NEWLINE# if ( include_default is False ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# default_group = grp . getgrgid ( pwd . getpwnam ( user ) . pw_gid ) . gr_name #NEWLINE# ugroups . remove ( default_group ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# log . trace ( "Group list for user '{0}': '{1}'" . format ( user , sorted ( ugroups ) ) ) #NEWLINE# return sorted ( ugroups )