Exemplo n.º 1
0
    def process(self, obj, key, valDict, maxGidValue=65500, maxUidValue=65500):

        try:
            maxUidValue = int(maxUidValue)
            maxGidValue = int(maxGidValue)
        except ValueError:
            raise PosixException(C.make_error("PARAMETER_NOT_NUMERIC", "GenerateIDs"))

        if "uidNumber" in valDict:
            if not(len(valDict['uidNumber']['value'])):
                if len(valDict["uidNumber"]['backend']) > 1:
                    raise PosixException(C.make_error("BACKEND_TOO_MANY", "GenerateIDs"))

                be = ObjectBackendRegistry.getBackend(valDict["uidNumber"]['backend'][0])
                uid = be.get_next_id("uidNumber")
                if uid > maxUidValue:
                    raise PosixException(C.make_error("POSIX_ID_POOL_EMPTY", "uidNumber", max=maxUidValue))

                valDict["uidNumber"]['value'] = [uid]

        if "gidNumber" in valDict:
            if not(len(valDict['gidNumber']['value'])):
                if len(valDict["gidNumber"]['backend']) > 1:
                    raise PosixException(C.make_error("BACKEND_TOO_MANY", "GenerateIDs"))

                be = ObjectBackendRegistry.getBackend(valDict["gidNumber"]['backend'][0])
                gid = be.get_next_id("gidNumber")
                if gid > maxGidValue:
                    raise PosixException(C.make_error("POSIX_ID_POOL_EMPTY", "gidNumber", max=maxGidValue))

                valDict["gidNumber"]['value'] = [gid]

        return key, valDict
Exemplo n.º 2
0
    def process(self, obj, key, valDict, attributeName="uidNumber", maxValue=65500):
        if len(valDict[key]['value']) and (valDict[key]['value'][0] == -1):
            maxValue = int(maxValue)

            if len(valDict[key]['backend']) > 1:
                raise PosixException(C.make_error("BACKEND_TOO_MANY", "GetNextID"))

            be = ObjectBackendRegistry.getBackend(valDict[key]['backend'][0])
            gid = be.get_next_id(attributeName)
            if gid > maxValue:
                raise PosixException(C.make_error("POSIX_ID_POOL_EMPTY", attributeName, max=maxValue))
            valDict[key]['value'] = [gid]

        return key, valDict