235
240
"""A representation of a client host served by this server.
238
name: string; from the config file, used in log messages and
240
fingerprint: string (40 or 32 hexadecimal digits); used to
241
uniquely identify the client
242
secret: bytestring; sent verbatim (over TLS) to client
243
host: string; available for use by the checker command
244
created: datetime.datetime(); (UTC) object creation
245
last_enabled: datetime.datetime(); (UTC)
247
last_checked_ok: datetime.datetime(); (UTC) or None
248
timeout: datetime.timedelta(); How long from last_checked_ok
249
until this client is disabled
250
interval: datetime.timedelta(); How often to start a new checker
251
disable_hook: If set, called by disable() as disable_hook(self)
243
_approved: bool(); 'None' if not yet approved/disapproved
244
approval_delay: datetime.timedelta(); Time to wait for approval
245
approval_duration: datetime.timedelta(); Duration of one approval
252
246
checker: subprocess.Popen(); a running checker process used
253
247
to see if the client lives.
254
248
'None' if no process is running.
255
checker_initiator_tag: a gobject event source tag, or None
256
disable_initiator_tag: - '' -
257
249
checker_callback_tag: - '' -
258
checker_command: string; External command which is run to check if
259
client lives. %() expansions are done at
250
checker_command: string; External command which is run to check
251
if client lives. %() expansions are done at
260
252
runtime with vars(self) as dict, so that for
261
253
instance %(name)s can be used in the command.
254
checker_initiator_tag: a gobject event source tag, or None
255
created: datetime.datetime(); (UTC) object creation
262
256
current_checker_command: string; current running checker_command
263
approved_delay: datetime.timedelta(); Time to wait for approval
264
_approved: bool(); 'None' if not yet approved/disapproved
265
approved_duration: datetime.timedelta(); Duration of one approval
257
disable_hook: If set, called by disable() as disable_hook(self)
258
disable_initiator_tag: - '' -
260
fingerprint: string (40 or 32 hexadecimal digits); used to
261
uniquely identify the client
262
host: string; available for use by the checker command
263
interval: datetime.timedelta(); How often to start a new checker
264
last_checked_ok: datetime.datetime(); (UTC) or None
265
last_enabled: datetime.datetime(); (UTC)
266
name: string; from the config file, used in log messages and
268
secret: bytestring; sent verbatim (over TLS) to client
269
timeout: datetime.timedelta(); How long from last_checked_ok
270
until this client is disabled
271
runtime_expansions: Allowed attributes for runtime expansion.
274
runtime_expansions = (u"approval_delay", u"approval_duration",
275
u"created", u"enabled", u"fingerprint",
276
u"host", u"interval", u"last_checked_ok",
277
u"last_enabled", u"name", u"timeout")
269
280
def _timedelta_to_milliseconds(td):
270
281
"Convert a datetime.timedelta() to milliseconds"
917
# approved_pending - property
937
# ApprovalPending - property
918
938
@dbus_service_property(_interface, signature=u"b", access=u"read")
919
def approved_pending_dbus_property(self):
939
def ApprovalPending_dbus_property(self):
920
940
return dbus.Boolean(bool(self.approvals_pending))
922
# approved_by_default - property
942
# ApprovedByDefault - property
923
943
@dbus_service_property(_interface, signature=u"b",
924
944
access=u"readwrite")
925
def approved_by_default_dbus_property(self):
926
return dbus.Boolean(self.approved_by_default)
928
# approved_delay - property
929
@dbus_service_property(_interface, signature=u"t",
931
def approved_delay_dbus_property(self):
932
return dbus.UInt64(self.approved_delay_milliseconds())
934
# approved_duration - property
935
@dbus_service_property(_interface, signature=u"t",
937
def approved_duration_dbus_property(self):
938
return dbus.UInt64(self._timedelta_to_milliseconds(
939
self.approved_duration))
945
def ApprovedByDefault_dbus_property(self, value=None):
946
if value is None: # get
947
return dbus.Boolean(self.approved_by_default)
948
self.approved_by_default = bool(value)
950
self.PropertyChanged(dbus.String(u"ApprovedByDefault"),
951
dbus.Boolean(value, variant_level=1))
953
# ApprovalDelay - property
954
@dbus_service_property(_interface, signature=u"t",
956
def ApprovalDelay_dbus_property(self, value=None):
957
if value is None: # get
958
return dbus.UInt64(self.approval_delay_milliseconds())
959
self.approval_delay = datetime.timedelta(0, 0, 0, value)
961
self.PropertyChanged(dbus.String(u"ApprovalDelay"),
962
dbus.UInt64(value, variant_level=1))
964
# ApprovalDuration - property
965
@dbus_service_property(_interface, signature=u"t",
967
def ApprovalDuration_dbus_property(self, value=None):
968
if value is None: # get
969
return dbus.UInt64(self._timedelta_to_milliseconds(
970
self.approval_duration))
971
self.approval_duration = datetime.timedelta(0, 0, 0, value)
973
self.PropertyChanged(dbus.String(u"ApprovalDuration"),
974
dbus.UInt64(value, variant_level=1))
942
977
@dbus_service_property(_interface, signature=u"s", access=u"read")
943
def name_dbus_property(self):
978
def Name_dbus_property(self):
944
979
return dbus.String(self.name)
946
# fingerprint - property
981
# Fingerprint - property
947
982
@dbus_service_property(_interface, signature=u"s", access=u"read")
948
def fingerprint_dbus_property(self):
983
def Fingerprint_dbus_property(self):
949
984
return dbus.String(self.fingerprint)
952
987
@dbus_service_property(_interface, signature=u"s",
953
988
access=u"readwrite")
954
def host_dbus_property(self, value=None):
989
def Host_dbus_property(self, value=None):
955
990
if value is None: # get
956
991
return dbus.String(self.host)
957
992
self.host = value
958
993
# Emit D-Bus signal
959
self.PropertyChanged(dbus.String(u"host"),
994
self.PropertyChanged(dbus.String(u"Host"),
960
995
dbus.String(value, variant_level=1))
963
998
@dbus_service_property(_interface, signature=u"s", access=u"read")
964
def created_dbus_property(self):
999
def Created_dbus_property(self):
965
1000
return dbus.String(self._datetime_to_dbus(self.created))
967
# last_enabled - property
1002
# LastEnabled - property
968
1003
@dbus_service_property(_interface, signature=u"s", access=u"read")
969
def last_enabled_dbus_property(self):
1004
def LastEnabled_dbus_property(self):
970
1005
if self.last_enabled is None:
971
1006
return dbus.String(u"")
972
1007
return dbus.String(self._datetime_to_dbus(self.last_enabled))
1009
# Enabled - property
975
1010
@dbus_service_property(_interface, signature=u"b",
976
1011
access=u"readwrite")
977
def enabled_dbus_property(self, value=None):
1012
def Enabled_dbus_property(self, value=None):
978
1013
if value is None: # get
979
1014
return dbus.Boolean(self.enabled)
994
1029
return dbus.String(self._datetime_to_dbus(self
995
1030
.last_checked_ok))
1032
# Timeout - property
998
1033
@dbus_service_property(_interface, signature=u"t",
999
1034
access=u"readwrite")
1000
def timeout_dbus_property(self, value=None):
1035
def Timeout_dbus_property(self, value=None):
1001
1036
if value is None: # get
1002
1037
return dbus.UInt64(self.timeout_milliseconds())
1003
1038
self.timeout = datetime.timedelta(0, 0, 0, value)
1004
1039
# Emit D-Bus signal
1005
self.PropertyChanged(dbus.String(u"timeout"),
1040
self.PropertyChanged(dbus.String(u"Timeout"),
1006
1041
dbus.UInt64(value, variant_level=1))
1007
1042
if getattr(self, u"disable_initiator_tag", None) is None:
1022
1057
self.disable_initiator_tag = (gobject.timeout_add
1023
1058
(time_to_die, self.disable))
1025
# interval - property
1060
# Interval - property
1026
1061
@dbus_service_property(_interface, signature=u"t",
1027
1062
access=u"readwrite")
1028
def interval_dbus_property(self, value=None):
1063
def Interval_dbus_property(self, value=None):
1029
1064
if value is None: # get
1030
1065
return dbus.UInt64(self.interval_milliseconds())
1031
1066
self.interval = datetime.timedelta(0, 0, 0, value)
1032
1067
# Emit D-Bus signal
1033
self.PropertyChanged(dbus.String(u"interval"),
1068
self.PropertyChanged(dbus.String(u"Interval"),
1034
1069
dbus.UInt64(value, variant_level=1))
1035
1070
if getattr(self, u"checker_initiator_tag", None) is None:
1040
1075
(value, self.start_checker))
1041
1076
self.start_checker() # Start one now, too
1043
# checker - property
1078
# Checker - property
1044
1079
@dbus_service_property(_interface, signature=u"s",
1045
1080
access=u"readwrite")
1046
def checker_dbus_property(self, value=None):
1081
def Checker_dbus_property(self, value=None):
1047
1082
if value is None: # get
1048
1083
return dbus.String(self.checker_command)
1049
1084
self.checker_command = value
1050
1085
# Emit D-Bus signal
1051
self.PropertyChanged(dbus.String(u"checker"),
1086
self.PropertyChanged(dbus.String(u"Checker"),
1052
1087
dbus.String(self.checker_command,
1053
1088
variant_level=1))
1055
# checker_running - property
1090
# CheckerRunning - property
1056
1091
@dbus_service_property(_interface, signature=u"b",
1057
1092
access=u"readwrite")
1058
def checker_running_dbus_property(self, value=None):
1093
def CheckerRunning_dbus_property(self, value=None):
1059
1094
if value is None: # get
1060
1095
return dbus.Boolean(self.checker is not None)
1189
1224
client.Rejected("Disabled")
1192
if client._approved or not client.approved_delay:
1227
if client._approved or not client.approval_delay:
1193
1228
#We are approved or approval is disabled
1195
1230
elif client._approved is None:
1196
logger.info(u"Client %s need approval",
1231
logger.info(u"Client %s needs approval",
1198
1233
if self.server.use_dbus:
1199
1234
# Emit D-Bus signal
1200
1235
client.NeedApproval(
1201
client.approved_delay_milliseconds(),
1236
client.approval_delay_milliseconds(),
1202
1237
client.approved_by_default)
1204
1239
logger.warning(u"Client %s was not approved",
1206
1241
if self.server.use_dbus:
1207
1242
# Emit D-Bus signal
1208
client.Rejected("Disapproved")
1243
client.Rejected("Denied")
1211
1246
#wait until timeout or approved
1728
1759
tcp_server = MandosServer((server_settings[u"address"],
1729
1760
server_settings[u"port"]),
1731
interface=server_settings[u"interface"],
1762
interface=(server_settings[u"interface"]
1732
1764
use_ipv6=use_ipv6,
1733
1765
gnutls_priority=
1734
1766
server_settings[u"priority"],
1735
1767
use_dbus=use_dbus)
1736
pidfilename = u"/var/run/mandos.pid"
1738
pidfile = open(pidfilename, u"w")
1740
logger.error(u"Could not open file %r", pidfilename)
1769
pidfilename = u"/var/run/mandos.pid"
1771
pidfile = open(pidfilename, u"w")
1773
logger.error(u"Could not open file %r", pidfilename)
1743
1776
uid = pwd.getpwnam(u"_mandos").pw_uid