def change_password(dta): """Return a string with a message describing how the request went.""" if cereconf.ENABLE_BOFHD_CRYPTO: # TODO: Check server cert from M2Crypto.m2xmlrpclib import Server, SSL_Transport svr = Server(cereconf.BOFH_URL, SSL_Transport(), encoding='iso8859-1') else: svr = xmlrpclib.Server(cereconf.BOFH_URL, encoding='iso8859-1') # Simple sanity check of values for k in 'newpass', 'pass', 'uname': if dta.getfirst(k, '') == '': return "Field %s cannot be blank" % k if dta.getfirst('newpass') != dta.getfirst('newpass2'): return "New passwords must be equal" try: secret = svr.login(dta.getfirst('uname'), dta.getfirst('pass')) svr.run_command(secret, "account_password", dta.getfirst('uname'), dta.getfirst('newpass')) except xmlrpclib.Fault, m: if m.faultCode == 666: return "The operation did not succeed: <pre>%s</pre>" % m.faultString else: return _internalError(m.faultString, sys.exc_info())