'python-ldap / active-directory / replace accountExpires value
I try to update the "accountExpires" Active Directory attribute with a python3 script, without success.
Here's the code :
import ldap,os,time,datetime
from dateutil.relativedelta import relativedelta
today = datetime.datetime.now()
today_plus_1y = today + relativedelta(years = 1)
unix_date_timestamp = time.mktime(today_plus_1y.timetuple())
diff_seconds_ad_stupid_timestamp = 11644473600
ad_stupid_timestamp_plus_1y = (unix_date_timestamp + diff_seconds_ad_stupid_timestamp) * 10000000
ad_stupid_timestamp_plus_1y_int = int(float(ad_stupid_timestamp_plus_1y))
ldap_server = "ldaps://dc.domain.local:636"
svc_username = "CN=svc.username,DC=domain,DC=local"
svc_password = "Password"
username = 'CN=username.test,DC=domain,DC=local'
cert = os.path.join('./cert.cer')
l = ldap.initialize(ldap_server)
l.protocol_version=ldap.VERSION3
ldap.set_option(ldap.OPT_DEBUG_LEVEL,255)
l.set_option(ldap.OPT_REFERRALS, 0)
l.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_ALLOW)
l.set_option(ldap.OPT_X_TLS_CACERTFILE,cert)
l.set_option(ldap.OPT_X_TLS_NEWCTX,0)
l.simple_bind_s(svc_username, svc_password)
change_date = [(ldap.MOD_REPLACE, 'accountExpires', ad_stupid_timestamp_plus_1y_int)]
l.modify_s(username, change_date)
l.unbind_s()
I get this error, and I don't know why :
ldap.UNWILLING_TO_PERFORM: {'msgtype': 103, 'msgid': 2, 'result': 53, 'desc': 'Server is unwilling to perform', 'ctrls': [], 'info': '00002077: SvcErr: DSID-031903D1, problem 5003 (WILL_NOT_PERFORM), data 0\n'}
This script runs well for changing a user password, or replace simple "String" attributes such as "company", "comment", etc ...
Anyone encounters this problem before ?
Thank you ! :)
EDIT :
I found the solution. I had to encode the timestamp, like this :
ad_stupid_timestamp_plus_1y_int = str(int(float(ad_stupid_timestamp_plus_1y)))
account_expires_1y = ad_stupid_timestamp_plus_1y_int.encode('utf-8')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
