#NEWLINE# def check_user( user ) : #NEWLINE# #INDENT# '\n    Check user and assign process uid/gid.\n    ' #NEWLINE# if salt . utils . is_windows ( ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# if ( user == salt . utils . get_user ( ) ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# import pwd #NEWLINE# try : #NEWLINE# #INDENT# pwuser = pwd . getpwnam ( user ) #NEWLINE# try : #NEWLINE# #INDENT# if hasattr ( os , 'initgroups' ) : #NEWLINE# #INDENT# os . initgroups ( user , pwuser . pw_gid ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# os . setgroups ( salt . utils . get_gid_list ( user , include_default = False ) ) #NEWLINE# #UNINDENT# os . setgid ( pwuser . pw_gid ) #NEWLINE# os . setuid ( pwuser . pw_uid ) #NEWLINE# if ( 'HOME' in os . environ ) : #NEWLINE# #INDENT# os . environ [ 'HOME' ] = pwuser . pw_dir #NEWLINE# #UNINDENT# if ( 'SHELL' in os . environ ) : #NEWLINE# #INDENT# os . environ [ 'SHELL' ] = pwuser . pw_shell #NEWLINE# #UNINDENT# for envvar in ( 'USER' , 'LOGNAME' ) : #NEWLINE# #INDENT# if ( envvar in os . environ ) : #NEWLINE# #INDENT# os . environ [ user ] = pwuser . pw_name #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except OSError : #NEWLINE# #INDENT# msg = 'Salt configured to run as user "{0}" but unable to switch.' #NEWLINE# msg = msg . format ( user ) #NEWLINE# if is_console_configured ( ) : #NEWLINE# #INDENT# log . critical ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sys . stderr . write ( 'CRITICAL: {0}\n' . format ( msg ) ) #NEWLINE# #UNINDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# except KeyError : #NEWLINE# #INDENT# msg = 'User not found: "{0}"' . format ( user ) #NEWLINE# if is_console_configured ( ) : #NEWLINE# #INDENT# log . critical ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sys . stderr . write ( 'CRITICAL: {0}\n' . format ( msg ) ) #NEWLINE# #UNINDENT# return False #NEWLINE# #UNINDENT# return True