+ def _format_oidentd(self):
+ ident = self.parent.user
+ fport = self.parent.port
+ from_ = self.bind
+ lport = self.socket.getsockname()[1]
+ if from_:
+ return 'fport %s from %s lport %s { reply "%s" }\n' % (fport, from_, lport, ident)
+ else:
+ return 'fport %s lport %s { reply "%s" }\n' % (fport, lport, ident)
+ def _write_oidentd(self):
+ path = self.parent.parent.cfg.get('erebus', 'oidentd_path')
+ if path is not None:
+ with open(path, 'a') as fh:
+ fcntl.lockf(fh, fcntl.LOCK_EX)
+ fh.write(self._format_oidentd())
+ fcntl.lockf(fh, fcntl.LOCK_UN)
+ def _unwrite_oidentd(self):
+ path = self.parent.parent.cfg.get('erebus', 'oidentd_path')
+ if path is not None:
+ with open(path, 'r+') as fh:
+ fcntl.lockf(fh, fcntl.LOCK_EX)
+ data = fh.read()
+ newdata = data.replace(self._format_oidentd(), '')
+ fh.seek(0)
+ fh.write(newdata)
+ fh.truncate()
+ fcntl.lockf(fh, fcntl.LOCK_UN)
+