def handle_update_password(self, request): parameters = request.get_query_dictionary() parameters.update(request.get_post_data()) # POST value for destination overrides query-string if both provided. username = parameters.get("username", "") password = parameters.get("password", "") newpwd = parameters.get("newpwd", "") confirm_newpwd = parameters.get("confirm_newpwd", "") try: if Properties.get_boolean('PAM_ENABLE'): user = self.manager.user_from_pam(username, password) else: user = self.manager.user_from_cleartext(username, password) except (PAMError, EAuthenticationFailed): msglog.exception(prefix="Handled") msg = "Invalid old password. Enter correct old password for authentication." self.handle_form(request, "update_password", "Authentication Failed", msg) else: if newpwd == confirm_newpwd: try: user.set_password(newpwd) except EInvalidValue, e: msglog.exception(prefix="Handled") msg = "".join(e[1].splitlines()) self.handle_form(request, "update_password", "Invalid new password. Please try again", msg) else: msg = "Password updated successfully for %s." % (username) msglog.log("broadway", msglog.types.INFO, msg) self.handle_form(request, "information", msg) else:
def _get_exception_msg(self,e): import traceback exc_type,exc_value,exc_tb = sys.exc_info() exc_lines = traceback.format_exception_only(exc_type,exc_value) del exc_type del exc_value tb_lines = traceback.format_tb(exc_tb) tb_lines = map(cgi.escape, tb_lines) del exc_tb exc_split = exc_lines[0].split(":",1) exc_name = exc_split.pop(0) if exc_split: exc_text = exc_split.pop(0) else: exc_text = '' error_msg = """\ <span style="color:red"><b>%(name)s:</b>%(text)s</span> """ % { "name":exc_name, "text":exc_text } if not properties.get_boolean('TRACEBACKS'): return error_msg return """%(error_msg)s<span style="color:black"> <br>\n%(traceback)s</span>""" % { "error_msg":error_msg, "traceback":"<br/>".join(tb_lines) }
def _get_exception_msg(self,e): import traceback exc_type,exc_value,exc_tb = sys.exc_info() exc_lines = traceback.format_exception_only(exc_type,exc_value) del exc_type del exc_value tb_lines = traceback.format_tb(exc_tb) del exc_tb exc_split = exc_lines[0].split(":",1) exc_name = exc_split.pop(0) if exc_split: exc_text = exc_split.pop(0) else: exc_text = '' error_msg = """\ <span style="color:red"><b>%(name)s:</b>%(text)s</span> """ % { "name":exc_name, "text":exc_text } if not properties.get_boolean('TRACEBACKS'): return error_msg return """%(error_msg)s<span style="color:black"> <br>\n%(traceback)s</span>""" % { "error_msg":error_msg, "traceback":"<br/>".join(tb_lines) }
def _update_motd(self): # Gather the bits and pieces of information we need to insert into # the message-of-the-day file. if properties.get_boolean('UPDATE_MOTD', 'false'): self.options.normal_message("Updating message-of-the-day file") if self.options.test: return # Get the format string from the template text = motd.as_string() # Create a new message-of-the-day file. motd_file_name = os.path.join(ETC_DIR, 'motd') motd_file = open(motd_file_name, 'w') try: motd_file.write(text) finally: motd_file.close()
def _update_motd(self): # Gather the bits and pieces of information we need to insert into # the message-of-the-day file. if properties.get_boolean("UPDATE_MOTD", "false"): self.options.normal_message("Updating message-of-the-day file") if self.options.test: return # Get the format string from the template text = motd.as_string() # Create a new message-of-the-day file. motd_file_name = os.path.join(ETC_DIR, "motd") motd_file = open(motd_file_name, "w") try: motd_file.write(text) finally: motd_file.close()
def handle_login(self, request): parameters = request.get_query_dictionary() destination = parameters.get("destination", "/") if parameters.has_key("password"): msg = "Unsafe use of query-string for user credentials: %r." msglog.log("broadway", msglog.types.WARN, msg % (parameters,)) parameters.update(request.get_post_data()) # POST value for destination overrides query-string if both provided. destination = parameters.get("destination", destination) destination = urllib.quote(destination, '/') username = parameters.get("username", "") password = parameters.get("password", "") sessionManager = as_internal_node('/services/session_manager') try: if Properties.get_boolean('PAM_ENABLE'): user = self.manager.user_from_pam(username, password) else: user = self.manager.user_from_cleartext(username, password) user.password_expired() except PAMError, e: msglog.exception(prefix="Handled") self.handle_form(request, "warning", "Authentication failure", e)
def create(self, user, password=None): if not isinstance(user, User): if properties.get_boolean('PAM_ENABLE'): authenticator = self.user_manager.user_from_pam else: authenticator = self.user_manager.user_from_cleartext try: user = authenticator(user, password) except EAuthenticationFailed: raise ESessionDenied("User credentials invalid.") self._begin_critical_section() try: sid = self._next_session_id() username = None if isinstance(user, User): username = user.name if isinstance(user, _User): username = user.name() self._sessions[sid] = Session(session_id=sid, ttl=self.ttl, username=username, password=password) finally: self._end_critical_section() return sid
'oname': oname }, shell=True, stdout=subprocess.PIPE) assert p.wait() == 0 os.unlink('%(oname)s' % {'oname': oname}) f.close() return int(p.stdout.read()) SYS_gettid = _get_SYS_gettid() from ctypes import CDLL _syscall = CDLL('libc.so.6').syscall def gettid(): global _syscall return _syscall(SYS_gettid) del CDLL ######################################################################## # LOCK DEBUGGING HOOKS. ######################################################################## if properties.get_boolean('DEBUG_LOCKS', 0): from debugging_locks import approach # @todo Support LockType. from debugging_locks import _LockAssertion from debugging_locks import _InternalAssertion from debugging_locks import _WrongThreadAssertion from debugging_locks import allocate from debugging_locks import allocate_lock
self._underflow.release() return result def add_listener(self, listener): self._listeners.append(listener) def lookup_by_pid(pid): for t in enumerate(): if hasattr(t, 'pid'): if t.pid() == pid: return t return None def lookup_by_tid(tid): for t in enumerate(): if hasattr(t, 'tid'): if t.tid() == tid: return t return None lookup_by_spid = lookup_by_tid lookup_by_lwp = lookup_by_tid from mpx import properties ######################################################################## # LOCK DEBUGGING HOOKS. ######################################################################## if properties.get_boolean('DEBUG_LOCKS', 0): # @fixme Support RLock, Cond, and our Queue. from debugging_locks import Lock from debugging_locks import set_lock_attributes