| 275 | | class Proxy(Server): |
| 276 | | """Base class for RADIUS proxies. |
| 277 | | |
| 278 | | This class extends tha RADIUS server class with the capability to |
| 279 | | handle communication with other RADIUS servers as well. |
| 280 | | |
| 281 | | @ivar _proxyfd: network socket used to communicate with other servers |
| 282 | | @type _proxyfd: socket class instance |
| 283 | | |
| 284 | | """ |
| 285 | | |
| 286 | | def _PrepareSockets(self): |
| 287 | | Server._PrepareSockets(self) |
| 288 | | |
| 289 | | self._proxyfd=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 290 | | self._fdmap[self._proxyfd.fileno()]=self._proxyfd |
| 291 | | self._poll.register(self._proxyfd.fileno(), (select.POLLIN|select.POLLPRI|select.POLLERR)) |
| 292 | | |
| 293 | | |
| 294 | | def _HandleProxyPacket(self, fd, pkt): |
| 295 | | """Process a packet received on the reply socket. |
| 296 | | |
| 297 | | If this packet should be dropped instead of processed a |
| 298 | | PacketError exception should be raised. The main loop will |
| 299 | | drop the packet and log the reason. |
| 300 | | |
| 301 | | @param fd: socket to read packet from |
| 302 | | @type fd: socket class instance |
| 303 | | @param pkt: packet to process |
| 304 | | @type pkt: Packet class instance |
| 305 | | """ |
| 306 | | if not self.hosts.has_key(pkt.source[0]): |
| 307 | | raise PacketError, "Received packet from unknown host" |
| 308 | | |
| 309 | | pkt.secret=self.hosts[pkt.source[0]].secret |
| 310 | | |
| 311 | | if not pkt.code in [ packet.AccessAccept, packet.AccessReject, packet.AccountingResponse ]: |
| 312 | | raise PacketError, "Received non-response on proxy socket" |
| 313 | | |
| 314 | | |
| 315 | | |
| 316 | | def _ProcessInput(self, fd): |
| 317 | | """Process available data. |
| 318 | | |
| 319 | | If this packet should be dropped instead of processed a |
| 320 | | PacketError exception should be raised. The main loop will |
| 321 | | drop the packet and log the reason. |
| 322 | | |
| 323 | | This function calls either HandleAuthPacket(), |
| 324 | | HandleAcctPacket() or _HandleProxyPacket() depending on which |
| 325 | | socket is being processed. |
| 326 | | |
| 327 | | @param fd: socket to read packet from |
| 328 | | @type fd: socket class instance |
| 329 | | @param pkt: packet to process |
| 330 | | @type pkt: Packet class instance |
| 331 | | """ |
| 332 | | if fd.fileno()==self._proxyfd.fileno(): |
| 333 | | pkt=self._GrabPacket(lambda data, s=self: s.CreatePacket(packet=data), fd) |
| 334 | | self._HandleProxyPacket(fd, pkt) |
| 335 | | else: |
| 336 | | Server._ProcessInput(self, fd) |
| 337 | | |
| 338 | | |