Beispiel #1
0
    def run(self):
        """Thread that does the actual job of processing RADIUS packets"""
        # since this method is assigned to thread we have to catch all exceptions
        # by ourselves
        try:
            threadnum = self.getName()
            hosts = self.server.hosts
            packets = self.server.packets
            auth_timeout = main_config["AUTHORIZATION"]["packet_timeout"]

            info("--- started %s ---" % threadnum)
            while self.threadMayRun:
                # grab a RADIUS packet and process it
                pkt = packets.remove_packet(blocking=False)
                if not pkt:
                    continue

                # check if this thread should be allowed for logging
                if pkt.source[0] in hosts and hosts[
                        pkt.source[0]].enableLogging:
                    logger.addUnrestrictedThread()

                info('thread "%s" grabbed a packet for processing' % threadnum)
                if isinstance(pkt, packet.AuthPacket):

                    # check if packet is too old
                    if (time.time() - pkt.timestamp > auth_timeout):
                        continue

                    try:
                        authResult = self.ProcessAuthPacket(pkt)
                    except AuthFailure, err:
                        error("auth failure: ", err)
                        continue
                    except:
                        misc.printException()
                        continue

                    # create and send a reply packet
                    address = pkt.source[0]
                    client = hosts[address]
                    if authResult[0]:
                        # access accept
                        code = packet.AccessAccept
                        debug("Sending Authorization ACCEPT to %s (%s)" %
                              (client.name, address))
                    else:
                        # access reject
                        code = packet.AccessReject
                        debug("Sending Authorization REJECT to %s (%s)" %
                              (client.name, address))

                    reply = pkt.CreateReply(**authResult[1])
                    reply.source = pkt.source
                    reply.code = code
                    debug(reply)
                    pkt.fd.sendto(reply.ReplyPacket(), reply.source)
	def run(self):
		"""Thread that does the actual job of processing RADIUS packets"""
		# since this method is assigned to thread we have to catch all exceptions
		# by ourselves
		try:
			threadnum = self.getName()
			hosts = self.server.hosts
			packets = self.server.packets
			auth_timeout = main_config["AUTHORIZATION"]["packet_timeout"]
			
			info("--- started %s ---" % threadnum)
			while self.threadMayRun:
				# grab a RADIUS packet and process it
				pkt = packets.remove_packet(blocking = False)
				if not pkt:
					continue
				
				# check if this thread should be allowed for logging
				if pkt.source[0] in hosts and hosts[pkt.source[0]].enableLogging:
					logger.addUnrestrictedThread()
				
				info('thread "%s" grabbed a packet for processing' % threadnum)
				if isinstance(pkt, packet.AuthPacket):
					
					# check if packet is too old
					if (time.time() - pkt.timestamp > auth_timeout):
						continue
					
					try:
						authResult = self.ProcessAuthPacket(pkt)		
					except AuthFailure, err:
						error ("auth failure: ", err)
						continue
					except:
						misc.printException()
						continue
	
					# create and send a reply packet
					address = pkt.source[0]
					client = hosts[address]
					if authResult[0]:
						# access accept
						code = packet.AccessAccept
						debug ("Sending Authorization ACCEPT to %s (%s)" % (client.name, address))
					else:
						# access reject
						code = packet.AccessReject
						debug ("Sending Authorization REJECT to %s (%s)" % (client.name, address))
						
					reply = pkt.CreateReply(**authResult[1])
					reply.source = pkt.source
					reply.code = code
					debug (reply)
					pkt.fd.sendto(reply.ReplyPacket(), reply.source)
Beispiel #3
0
	def applyConfig(self):
		"""Apply configuration 
		"""
		# apply options
		if self['SERVER']['debug_mode']:
			self['SERVER']['foreground'] = True
			self['SERVER']['no_threads'] = True
			self['SERVER']['log_to_screen'] = True
		if self['SERVER']['log_to_screen']:
			self['SERVER']['log_to_file'] = False
			logger.logToScreen = True
		if self['SERVER']['log_client']:
			# restrict all threads from logger
			info ('--- Enabling threads logging restrictions ---')
			logger.restrictThreads = True
			# add this (main) thread to unrestricted threads to allow print log messages
			logger.addUnrestrictedThread()
Beispiel #4
0
    def applyConfig(self):
        """Apply configuration 
		"""
        # apply options
        if self['SERVER']['debug_mode']:
            self['SERVER']['foreground'] = True
            self['SERVER']['no_threads'] = True
            self['SERVER']['log_to_screen'] = True
        if self['SERVER']['log_to_screen']:
            self['SERVER']['log_to_file'] = False
            logger.logToScreen = True
        if self['SERVER']['log_client']:
            # restrict all threads from logger
            info('--- Enabling threads logging restrictions ---')
            logger.restrictThreads = True
            # add this (main) thread to unrestricted threads to allow print log messages
            logger.addUnrestrictedThread()
Beispiel #5
0
    def applyConfig(self):
        """Apply configuration 
		"""
        # apply options
        if self["SERVER"]["debug_mode"]:
            self["SERVER"]["foreground"] = True
            self["SERVER"]["no_threads"] = True
            self["SERVER"]["log_to_screen"] = True
        if self["SERVER"]["log_to_screen"]:
            self["SERVER"]["log_to_file"] = False
            logger.logToScreen = True
        if self["SERVER"]["log_client"]:
            # restrict all threads from logger
            info("--- Enabling threads logging restrictions ---")
            logger.restrictThreads = True
            # add this (main) thread to unrestricted threads to allow print log messages
            logger.addUnrestrictedThread()
Beispiel #6
0
    def run(self):
        """Thread that does the actual job of processing RADIUS packets"""
        # since this method is assigned to thread we have to catch all exceptions
        # by ourselves
        try:
            threadnum = self.getName()
            hosts = self.server.hosts
            packets = self.server.packets
            auth_timeout = main_config["AUTHORIZATION"]["packet_timeout"]

            info("--- started %s ---" % threadnum)
            while self.threadMayRun:
                # grab a RADIUS packet and process it
                pkt = packets.remove_packet(blocking=False)
                if not pkt:
                    continue

                # check if this thread should be allowed for logging
                if pkt.source[0] in hosts and hosts[
                        pkt.source[0]].enableLogging:
                    logger.addUnrestrictedThread()

                info('thread "%s" grabbed a packet for processing' % threadnum)
                if isinstance(pkt, packet.AuthPacket):

                    # check if packet is too old
                    if (time.time() - pkt.timestamp > auth_timeout):
                        # Dump timed out auth packet
                        dumpPacket.dumpUnhandledAuthPacket(pkt)
                        continue

                    try:
                        authResult = self.ProcessAuthPacket(pkt)
                    except AuthFailure, err:
                        error("auth failure: ", err)
                        continue
                    except:
                        misc.printException()
                        continue

                    # create and send a reply packet
                    self.sendAuthResponse(pkt, authResult)
	def run(self):
		"""Thread that does the actual job of processing RADIUS packets"""
		# since this method is assigned to thread we have to catch all exceptions
		# by ourselves
		try:
			threadnum = self.getName()
			hosts = self.server.hosts
			packets = self.server.packets
			auth_timeout = main_config["AUTHORIZATION"]["packet_timeout"]
			
			info("--- started %s ---" % threadnum)
			while self.threadMayRun:
				# grab a RADIUS packet and process it
				pkt = packets.remove_packet(blocking = False)
				if not pkt:
					continue
				
				# check if this thread should be allowed for logging
				if pkt.source[0] in hosts and hosts[pkt.source[0]].enableLogging:
					logger.addUnrestrictedThread()
				
				info('thread "%s" grabbed a packet for processing' % threadnum)
				if isinstance(pkt, packet.AuthPacket):
					
					# check if packet is too old
					if (time.time() - pkt.timestamp > auth_timeout):
						# Dump timed out auth packet
						dumpPacket.dumpUnhandledAuthPacket(pkt)
						continue
					
					try:
						authResult = self.ProcessAuthPacket(pkt)		
					except AuthFailure, err:
						error ("auth failure: ", err)
						continue
					except:
						misc.printException()
						continue
	
					# create and send a reply packet
					self.sendAuthResponse(pkt, authResult)
Beispiel #8
0
    def run(self):
        """Listen to sockets and put received packets in raw
			data queue for later operations.
			Input: none
			Output: none
		"""
        # since this method is assigned to thread we have to catch all exceptions
        # by ourselves
        try:
            info('--- Started Listen thread ---')
            # poll packets and put them onto rawpacket sync queue
            while self.threadMayRun:
                for (socknum, event) in self.server.pollobj.poll(1000):
                    if event != select.POLLIN:
                        logger.addUnrestrictedThread()
                        error("unexpected event!")
                        logger.rmUnrestrictedThread()
                        continue

                    # receive packet
                    (sock, socktype) = self.server.fdmap[socknum]
                    (data, addr) = sock.recvfrom(MAXPACKETSZ)

                    # process the raw packet
                    if addr[0] in self.server.hosts and self.server.hosts[
                            addr[0]].enableLogging:
                        logger.addUnrestrictedThread()
                    self.ProcessPacket(data, addr, sock, socktype)
                    logger.rmUnrestrictedThread()
        except:
            logger.addUnrestrictedThread()
            misc.printException()
            error('Error in listen thread')
            logger.rmUnrestrictedThread()
	def run(self):
		"""Listen to sockets and put received packets in raw
			data queue for later operations.
			Input: none
			Output: none
		"""
		# since this method is assigned to thread we have to catch all exceptions
		# by ourselves
		try:
			info ('--- Started Listen thread ---')
			# poll packets and put them onto rawpacket sync queue
			while self.threadMayRun:
				for (socknum, event) in self.server.pollobj.poll(1000):
					if event != select.POLLIN:
						logger.addUnrestrictedThread()
						error ("unexpected event!")
						logger.rmUnrestrictedThread()
						continue
						
					# receive packet
					(sock, socktype) = self.server.fdmap[socknum]
					(data, addr) = sock.recvfrom(MAXPACKETSZ)
	
					# process the raw packet
					if addr[0] in self.server.hosts and self.server.hosts[addr[0]].enableLogging:
						logger.addUnrestrictedThread()
					self.ProcessPacket(data, addr, sock, socktype)
					logger.rmUnrestrictedThread()
		except:
			logger.addUnrestrictedThread()
			misc.printException()
			error ('Error in listen thread')
			logger.rmUnrestrictedThread()
Beispiel #10
0
                    # send accounting reply if processing packet was ok
                    # send acct response to client only after processing the packet
                    if acctResult is True and not main_config['SERVER'][
                            'fast_accounting']:
                        self.sendAcctResponse(pkt)

                else:
                    error('Wrong packet received: ', pkt)

                info('%s\n\n' % ('=' * 62))

                # remove this thread from non-restricted thread list
                logger.rmUnrestrictedThread()
        except:
            logger.addUnrestrictedThread()
            misc.printException()
            error('Error in working thread')
            logger.rmUnrestrictedThread()

    def ProcessAuthPacket(self, pkt):
        # decrypt crypted attributes
        pkt.decryptAttributes()
        #debug (pkt)

        received = dict(pkt)  # don't use packet instance any more
        check = {'Auth-Type': [None]}
        reply = {}

        debug(misc.authPacketToStr(received))
						self.ProcessAcctPacket(pkt)
					except AcctFailure, err:
						error ("acct failure: ", err)
						continue
					except:
						misc.printException()
						continue
				else:
					error('Wrong packet received: ', pkt)
						
				info ('%s\n\n' % ('=' * 62))
				
				# remove this thread from non-restricted thread list
				logger.rmUnrestrictedThread()
		except:
			logger.addUnrestrictedThread()
			misc.printException()
			error ('Error in working thread')
			logger.rmUnrestrictedThread()


			
	def ProcessAuthPacket(self, pkt):
		# decrypt crypted attributes
		pkt.decryptAttributes()
		#debug (pkt)
		
		received = dict(pkt) # don't use packet instance any more
		check = {'Auth-Type': [None]}
		reply = {}