Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def CreateAcctPacket(self, **args):
"""Create a new RADIUS packet.
This utility function creates a new RADIUS packet which can
be used to communicate with the RADIUS server this client
talks to. This is initializing the new packet with the
dictionary and secret used for the client.
:return: a new empty packet instance
:rtype: pyrad.packet.Packet
"""
if not self.protocol_acct:
raise Exception('Transport not initialized')
return AcctPacket(id=self.protocol_acct.create_id(),
dict=self.dict,
secret=self.secret, **args)
elif self.server_type == ServerType.Coa:
if req.code != DisconnectRequest and req.code != CoARequest:
raise ServerPacketError('Received non-coa packet on coa port')
req = CoAPacket(secret=remote_host.secret,
dict=self.server.dict,
packet=data)
if self.server.enable_pkt_verify:
if req.VerifyCoARequest():
raise PacketError('Packet verification failed')
elif self.server_type == ServerType.Acct:
if req.code != AccountingRequest:
raise ServerPacketError('Received non-acct packet on acct port')
req = AcctPacket(secret=remote_host.secret,
dict=self.server.dict,
packet=data)
if self.server.enable_pkt_verify:
if req.VerifyAcctRequest():
raise PacketError('Packet verification failed')
# Call request callback
self.request_callback(self, req, addr)
except Exception as exc:
if self.server.debug:
self.logger.exception('[%s:%d] Error for packet from %s', self.ip, self.port, addr)
else:
self.logger.error('[%s:%d] Error for packet from %s: %s', self.ip, self.port, addr, exc)
process_date = datetime.utcnow()
self.logger.debug('[%s:%d] Request from %s processed in %d ms', self.ip, self.port, addr, (process_date-receive_date).microseconds/1000)
def CreateAcctPacket(self, **args):
"""Create a new accounting RADIUS packet.
This utility function creates a new accouting RADIUS packet
which can be used to communicate with the RADIUS server this
client talks to. This is initializing the new packet with the
dictionary and secret used for the client.
:return: a new empty packet instance
:rtype: pyrad.packet.AcctPacket
"""
return packet.AcctPacket(dict=self.dict, **args)
if not self.authenticator:
self.authenticator = self.CreateAuthenticator()
_pwd = md5_constructor("%s%s%s"%(chapid,userpwd,self.authenticator)).digest()
for i in range(16):
if password[i] != _pwd[i]:
return False
return True
def is_valid_pwd(self,userpwd):
if not self.get_chappwd():
return userpwd == self.get_passwd()
else:
return self.verifyChapEcrypt(userpwd)
class AcctPacket2(AcctPacket):
def __init__(self, code=AccountingRequest, id=None, secret=six.b(''),
authenticator=None, **attributes):
AcctPacket.__init__(self, code, id, secret, authenticator, **attributes)
def get_username(self):
try:return tools.DecodeString(self.get(1)[0])
except:return None
def get_macaddr(self):
try:return tools.DecodeString(self.get(31)[0]).replace("-",":")
except:return None
def get_nasaddr(self):
try:return tools.DecodeAddress(self.get(4)[0])
except:return None
:param pkt: the packet to send
:type pkt: pyrad.packet.Packet
:return: Future related with packet to send
:rtype: asyncio.Future
"""
ans = asyncio.Future(loop=self.loop)
if isinstance(pkt, AuthPacket):
if not self.protocol_auth:
raise Exception('Transport not initialized')
self.protocol_auth.send_packet(pkt, ans)
elif isinstance(pkt, AcctPacket):
if not self.protocol_acct:
raise Exception('Transport not initialized')
elif isinstance(pkt, CoAPacket):
if not self.protocol_coa:
raise Exception('Transport not initialized')
else:
raise Exception('Unsupported packet')
return ans
def __init__(self, code=AccountingRequest, id=None, secret=six.b(''),
authenticator=None, **attributes):
AcctPacket.__init__(self, code, id, secret, authenticator, **attributes)
def CreateReply(self, **attributes):
"""Create a new packet as a reply to this one. This method
makes sure the authenticator and secret are copied over
to the new instance.
"""
return AcctPacket(AccountingResponse, self.id,
self.secret, self.authenticator, dict=self.dict,
**attributes)