def authenticate(self, db, user, passwd, client_address): """ authenticate, but also allow the False db, meaning to skip authentication when no db is specified. """ if db is False: return True try: uid = security.login(db, user, passwd) if uid is False: return False return user, passwd, db, uid except Exception, e: _logger.debug("Fail auth: %s" % e) return False
def bot_login(self, mess, args): """Executes the login process. It expects only two parameters: user and password """ (user, password) = args.split()[0:2] uid = login(self._dbname, user, password) if uid: self._sessions.login(mess.getFrom(), datetime.datetime.now(), uid, password) if self._sessions.sessions().has_key(mess.getFrom()): self.log("Login successful for user %s" % (mess.getFrom(),)) return "You're now logged in." else: self.elog("Somethin nasty occured with the login process of %s." % (mess.getFrom(),)) return "Something nasty occured with your login process. Try again." else: self.elog("Failed login for user %s." % (mess.getFrom(),)) return "The supplied credentials were not valid."
def get_crdata(self, line, mode='file'): """ Get database cursor, node and remainder data, for commands This is the helper function that will prepare the arguments for any of the subsequent commands. It returns a tuple in the form of: @code ( cr, node, rem_path=None ) @param line An absolute or relative ftp path, as passed to the cmd. @param mode A word describing the mode of operation, so that this function behaves properly in the different commands. """ path = self.ftpnorm(line) if self.cwd_node is None: if not os.path.isabs(path): path = os.path.join(self.root, path) if path == '/' and mode in ('list', 'cwd'): return (None, None, None) if path == '..': path = self.cwd + '/..' path = _to_unicode(os.path.normpath(path)) # again, for '/db/../ss' if path == '.': path = '' if os.path.isabs(path) and self.cwd_node is not None \ and path.startswith(self.cwd): # make relative, so that cwd_node is used again path = path[len(self.cwd):] if path.startswith('/'): path = path[1:] p_parts = path.split(os.sep) assert '..' not in p_parts rem_path = None if mode in ('create', ): rem_path = p_parts[-1] p_parts = p_parts[:-1] if os.path.isabs(path): # we have to start from root, again while p_parts and p_parts[0] == '': p_parts = p_parts[1:] # self._log.debug("Path parts: %r ", p_parts) if not p_parts: raise IOError(errno.EPERM, 'Cannot perform operation at root directory.') dbname = p_parts[0] if dbname not in self.db_list(): raise IOError(errno.ENOENT, 'Invalid database path: %s.' % dbname) try: db = openerp.sql_db.db_connect(dbname) except Exception: raise OSError(1, 'Database cannot be used.') cr = db.cursor() try: uid = security.login(dbname, self.username, self.password) except Exception: cr.close() raise if not uid: cr.close() raise OSError(2, 'Authentification required.') n = document.get_node_context(cr, uid, {}) node = n.get_uri(cr, p_parts[1:]) return (cr, node, rem_path) else: # we never reach here if cwd_node is not set if p_parts and p_parts[-1] == '': p_parts = p_parts[:-1] cr, uid = self.get_node_cr_uid(self.cwd_node) if p_parts: node = self.cwd_node.get_uri(cr, p_parts) else: node = self.cwd_node if node is False and mode not in ('???'): cr.close() raise IOError(errno.ENOENT, 'Path does not exist.') return (cr, node, rem_path)
def get_crdata(self, line, mode="file"): """ Get database cursor, node and remainder data, for commands This is the helper function that will prepare the arguments for any of the subsequent commands. It returns a tuple in the form of: @code ( cr, node, rem_path=None ) @param line An absolute or relative ftp path, as passed to the cmd. @param mode A word describing the mode of operation, so that this function behaves properly in the different commands. """ path = self.ftpnorm(line) if self.cwd_node is None: if not os.path.isabs(path): path = os.path.join(self.root, path) if path == "/" and mode in ("list", "cwd"): return (None, None, None) path = _to_unicode(os.path.normpath(path)) # again, for '/db/../ss' if path == ".": path = "" if os.path.isabs(path) and self.cwd_node is not None and path.startswith(self.cwd): # make relative, so that cwd_node is used again path = path[len(self.cwd) :] if path.startswith("/"): path = path[1:] p_parts = path.split(os.sep) assert ".." not in p_parts rem_path = None if mode in ("create",): rem_path = p_parts[-1] p_parts = p_parts[:-1] if os.path.isabs(path): # we have to start from root, again while p_parts and p_parts[0] == "": p_parts = p_parts[1:] # self._log.debug("Path parts: %r ", p_parts) if not p_parts: raise IOError(errno.EPERM, "Cannot perform operation at root directory.") dbname = p_parts[0] if dbname not in self.db_list(): raise IOError(errno.ENOENT, "Invalid database path: %s." % dbname) try: db = pooler.get_db(dbname) except Exception: raise OSError(1, "Database cannot be used.") cr = db.cursor() try: uid = security.login(dbname, self.username, self.password) except Exception: cr.close() raise if not uid: cr.close() raise OSError(2, "Authentification required.") n = get_node_context(cr, uid, {}) node = n.get_uri(cr, p_parts[1:]) return (cr, node, rem_path) else: # we never reach here if cwd_node is not set if p_parts and p_parts[-1] == "": p_parts = p_parts[:-1] cr, uid = self.get_node_cr_uid(self.cwd_node) if p_parts: node = self.cwd_node.get_uri(cr, p_parts) else: node = self.cwd_node if node is False and mode not in ("???"): cr.close() raise IOError(errno.ENOENT, "Path does not exist.") return (cr, node, rem_path)