mirror of
https://github.com/samba-team/samba.git
synced 2025-08-03 04:22:09 +03:00
samba-tool domain: move timestamp functions to common
Other tools use identical functions, and they too can use common.py Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
This commit is contained in:
committed by
Noel Power
parent
14768d0d54
commit
c8d3547c5f
@ -22,6 +22,11 @@ from samba.dcerpc import nbt
|
|||||||
from samba.net import Net
|
from samba.net import Net
|
||||||
import ldb
|
import ldb
|
||||||
|
|
||||||
|
|
||||||
|
# In MS AD, setting a timeout to '(never)' corresponds to this value
|
||||||
|
NEVER_TIMESTAMP = int(-0x8000000000000000)
|
||||||
|
|
||||||
|
|
||||||
def _get_user_realm_domain(user):
|
def _get_user_realm_domain(user):
|
||||||
r""" get the realm or the domain and the base user
|
r""" get the realm or the domain and the base user
|
||||||
from user like:
|
from user like:
|
||||||
@ -112,3 +117,19 @@ def get_ldif_for_editor(samdb, msg):
|
|||||||
result_ldif = samdb.write_ldif(m, ldb.CHANGETYPE_NONE)
|
result_ldif = samdb.write_ldif(m, ldb.CHANGETYPE_NONE)
|
||||||
|
|
||||||
return result_ldif
|
return result_ldif
|
||||||
|
|
||||||
|
|
||||||
|
def timestamp_to_mins(timestamp_str):
|
||||||
|
"""Converts a timestamp in -100 nanosecond units to minutes"""
|
||||||
|
# treat a timestamp of 'never' the same as zero (this should work OK for
|
||||||
|
# most settings, and it displays better than trying to convert
|
||||||
|
# -0x8000000000000000 to minutes)
|
||||||
|
if int(timestamp_str) == NEVER_TIMESTAMP:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return abs(int(timestamp_str)) / (1e7 * 60)
|
||||||
|
|
||||||
|
|
||||||
|
def timestamp_to_days(timestamp_str):
|
||||||
|
"""Converts a timestamp in -100 nanosecond units to days"""
|
||||||
|
return timestamp_to_mins(timestamp_str) / (60 * 24)
|
||||||
|
@ -62,6 +62,9 @@ from samba.netcmd import (
|
|||||||
)
|
)
|
||||||
from samba.netcmd.fsmo import get_fsmo_roleowner
|
from samba.netcmd.fsmo import get_fsmo_roleowner
|
||||||
from samba.netcmd.common import netcmd_get_domain_infos_via_cldap
|
from samba.netcmd.common import netcmd_get_domain_infos_via_cldap
|
||||||
|
from samba.netcmd.common import (NEVER_TIMESTAMP,
|
||||||
|
timestamp_to_mins,
|
||||||
|
timestamp_to_days)
|
||||||
from samba.samba3 import Samba3
|
from samba.samba3 import Samba3
|
||||||
from samba.samba3 import param as s3param
|
from samba.samba3 import param as s3param
|
||||||
from samba.upgrade import upgrade_from_samba3
|
from samba.upgrade import upgrade_from_samba3
|
||||||
@ -1210,26 +1213,6 @@ class cmd_domain_level(Command):
|
|||||||
raise CommandError("invalid argument: '%s' (choose from 'show', 'raise')" % subcommand)
|
raise CommandError("invalid argument: '%s' (choose from 'show', 'raise')" % subcommand)
|
||||||
|
|
||||||
|
|
||||||
# In MS AD, setting a timeout to '(never)' corresponds to this value
|
|
||||||
NEVER_TIMESTAMP = int(-0x8000000000000000)
|
|
||||||
|
|
||||||
|
|
||||||
def timestamp_to_mins(timestamp_str):
|
|
||||||
"""Converts a timestamp in -100 nanosecond units to minutes"""
|
|
||||||
# treat a timestamp of 'never' the same as zero (this should work OK for
|
|
||||||
# most settings, and it displays better than trying to convert
|
|
||||||
# -0x8000000000000000 to minutes)
|
|
||||||
if int(timestamp_str) == NEVER_TIMESTAMP:
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
return abs(int(timestamp_str)) / (1e7 * 60)
|
|
||||||
|
|
||||||
|
|
||||||
def timestamp_to_days(timestamp_str):
|
|
||||||
"""Converts a timestamp in -100 nanosecond units to days"""
|
|
||||||
return timestamp_to_mins(timestamp_str) / (60 * 24)
|
|
||||||
|
|
||||||
|
|
||||||
class cmd_domain_passwordsettings_show(Command):
|
class cmd_domain_passwordsettings_show(Command):
|
||||||
"""Display current password settings for the domain."""
|
"""Display current password settings for the domain."""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user