#NEWLINE# def rotate( record , newpassword ) : #NEWLINE# #INDENT# user = record . login #NEWLINE# oldpassword = record . password #NEWLINE# prompt = '.*\\$ ' #NEWLINE# p = pexpect . spawn ( 'bash' ) #NEWLINE# i = p . expect ( prompt ) #NEWLINE# p . sendline ( ( 'su - %s' % user ) ) #NEWLINE# i = p . expect ( '[Pp]assword' ) #NEWLINE# p . sendline ( oldpassword ) #NEWLINE# i = p . expect ( prompt ) #NEWLINE# p . sendline ( 'passwd' ) #NEWLINE# i = p . expect ( [ '[Oo]ld [Pp]assword' , '.current.*password' , '[Nn]ew [Pp]assword' ] ) #NEWLINE# l = p . before #NEWLINE# if ( ( i == 0 ) or ( i == 1 ) ) : #NEWLINE# #INDENT# p . sendline ( oldpassword ) #NEWLINE# i = p . expect ( '[Nn]ew [Pp]assword' ) #NEWLINE# #UNINDENT# p . sendline ( newpassword ) #NEWLINE# i = p . expect ( '[Rr]etype [Nn]ew [Pp]assword:' ) #NEWLINE# p . sendline ( newpassword ) #NEWLINE# i = p . expect ( [ '.try again' , '.authentication' , '.failure' , prompt ] ) #NEWLINE# if ( i == 0 ) : #NEWLINE# #INDENT# print ( 'Password change failed' ) #NEWLINE# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( i == 1 ) : #NEWLINE# #INDENT# print ( 'Current password is incorrect' ) #NEWLINE# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( i == 2 ) : #NEWLINE# #INDENT# print ( 'General failure in password update' ) #NEWLINE# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( i == 3 ) : #NEWLINE# #INDENT# print ( 'Password changed successfully' ) #NEWLINE# record . password = newpassword #NEWLINE# return True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return False