Exemple #1
0
 def service_help(self, context, *arguments):
     """
     Display help of a component or a service.
     Usage: "help component" or "help component service"
     """
     component_name = None
     service_name = 'getComponentVersion'
     prototype = None
     if len(arguments) == 1:
         component_name = getUnicode("component", arguments[0], 1, 100)
         obj = self.core.getComponent(context, component_name)
     elif len(arguments) == 2:
         component_name = getUnicode("component", arguments[0], 1, 100)
         service_name = getUnicode("service", arguments[1], 1, 100)
         component, obj = self.core.getService(context,
             component_name, service_name, component_check=False)
         prototype = getPrototype(obj, skip=1)
         if prototype.startswith("service_"):
             prototype = prototype[8:]
     else:
         return u'Usage: "help component" or "help component service"'
     doc = readDocumentation(obj)
     if prototype:
         doc = list(doc)
         if doc:
             doc = [prototype+':', ''] + list(doc)
         else:
             doc = [prototype]
     return doc
Exemple #2
0
 def service_getAcl(self, context, group='', role=''):
     """
     Get the ACLs (group, role): all arguments are optional.
     """
     group = getUnicode("group", group, 0, 100)
     if not group:
         group = None
     role = getUnicode("role", role, 0, 100)
     if not role:
         role = None
     acls = self.store.get_acl(group, role)
     return ( map(formatSqliteItem, acl) for acl in acls )
Exemple #3
0
    def create(self, context, data):
        "Create an anonymous session"

        client_name = getUnicode("client_name", data['client_name'], 3, 100)
        protocol_version = getUnicode("protocol_version", data['protocol_version'], 3, 100)

        # Check client name and protocol version
        if not client_name or not (3 <= len(client_name) <= 20):
            raise SessionError(SESSION_INVALID_ARG,
                tr("Invalid client name: need a string with length in 3..20"))
        if not protocol_version or not (3 <= len(protocol_version) <= 10):
            raise SessionError(SESSION_INVALID_ARG,
                tr("Invalid protocol version: need a string with length in 3..10"))

        # Check protocol version
        if protocol_version != PROTOCOL_VERSION:
            raise SessionError(SESSION_INVALID_VERSION,
                tr("Invalid protocol version: %s"),
                repr(protocol_version))

        # Only a user with no session can create a new session
        if not context.user:
            raise SessionError(SESSION_NO_USER,
                tr("Only a user can create a session!"))
        if context.hasSession():
            raise SessionError(SESSION_DUPLICATE,
                tr("You already own a session!"))


        # Fill the user context
        user = context.user
        if 'client_release' in data:
            #size between 3 and 100
            user.client_release = getUnicode('client_release', data['client_release'], 3, 100)
        user.groups = ["anonymous"]
        user.client_name = client_name
        user.protocol_version = protocol_version

        # Create the session
        cookie = self.createCookie()
        filename = b32encode(cookie).strip("=") + ".pickle"
        filename = path_join(self.path, filename)
        cookie = b64encode(cookie)
        session = Session(cookie, filename, user)

        # Register the session and write it to the disk
        self.sessions[session.cookie] = session
        context.setSession(session)
        session.save()

        # Session created
        return session.cookie
Exemple #4
0
def getPassword(password, mandatory=True):
    if (not mandatory) and (not password):
        return None
    password = getUnicode("password", password, 1, 100)
    if not PASSWORD_REGEX.match(password):
        raise AuthError(AUTH_INVALID_PARAMETER, tr("The password you entered is not valid."))
    return password
Exemple #5
0
    def callService(self, args, request):
        context = Context.fromClient(request)
        component_name = None
        service_name = None
        try:
            # Read the arguments
            if len(args) < 3:
                raise CoreError(CORE_CALL_SERVICE_ERROR,
                    tr("callService(cookie, component, service, *args)"
                       " requires at least 3 parameters"))
            cookie, component_name, service_name = args[:3]
            args = args[3:]

            # Validate arguments
            cookie = getUnicode("cookie", cookie, 0, COOKIE_BASE64_LENGTH)
            component_name = getUnicode("component", component_name, 1, 100)
            service_name = getUnicode("service", service_name, 1, 100)

            return self._callService(context, cookie, component_name, service_name, args)
        except SessionError, err:
            self.core.critical("Session error from %s: %s" % (unicode(context.user), exceptionAsUnicode(err)))
            return self.serviceError(err, context, component_name, service_name, display=False)
Exemple #6
0
def getParameter(name, value, error_message):
    name = getUnicode(name, value, 1, 100)
    if not NAME_REGEX.match(value):
        raise AuthError(AUTH_INVALID_PARAMETER, error_message, repr(name))
    return name