2
# shadow.py - lookup functions for shadownet addresses
4
# Copyright (C) 2010, 2011 Arthur de Jong
6
# This library is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU Lesser General Public
8
# License as published by the Free Software Foundation; either
9
# version 2.1 of the License, or (at your option) any later version.
11
# This library is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
# Lesser General Public License for more details.
16
# You should have received a copy of the GNU Lesser General Public
17
# License along with this library; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27
attmap = common.Attributes(uid='uid',
29
shadowLastChange='"${shadowLastChange:--1}"',
30
shadowMin='"${shadowMin:--1}"',
31
shadowMax='"${shadowMax:--1}"',
32
shadowWarning='"${shadowWarning:--1}"',
33
shadowInactive='"${shadowInactive:--1}"',
34
shadowExpire='"${shadowExpire:--1}"',
35
shadowFlag='"${shadowFlag:-0}"')
36
filter = '(objectClass=shadowAccount)'
37
bases = ( 'ou=people,dc=test,dc=tld', )
40
class ShadowRequest(common.Request):
42
def write(self, dn, attributes, parameters):
43
# get name and check against requested name
44
names = attributes['uid']
46
print 'Error: entry %s does not contain %s value' % ( dn, attmap['uid'] )
48
if 'uid' in parameters:
49
if parameters['uid'] not in names:
51
names = ( parameters['uid'], )
53
(passwd, ) = attributes['userPassword']
54
if not passwd or self.calleruid != 0:
56
# function for making an int
63
lastchangedate = int(attributes.get('shadowLastChange', [0])[0])
64
# we expect an AD 64-bit datetime value;
65
# we should do date=date/864000000000-134774
66
# but that causes problems on 32-bit platforms,
67
# first we devide by 1000000000 by stripping the
68
# last 9 digits from the string and going from there */
69
if attmap['shadowLastChange'] == 'pwdLastSet':
70
lastchangedate = ( lastchangedate / 864000000000 ) - 134774
72
mindays = int(attributes.get('shadowMin', [-1])[0])
73
maxdays = int(attributes.get('shadowMax', [-1])[0])
74
warndays = int(attributes.get('shadowWarning', [-1])[0])
75
inactdays = int(attributes.get('shadowInactive', [-1])[0])
76
expiredate = int(attributes.get('shadowExpire', [-1])[0])
77
flag = int(attributes.get('shadowFlag', [0])[0])
78
if attmap['shadowFlag'] == 'pwdLastSet':
84
self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
85
self.fp.write_string(name)
86
self.fp.write_string(passwd)
87
self.fp.write_int32(lastchangedate)
88
self.fp.write_int32(mindays)
89
self.fp.write_int32(maxdays)
90
self.fp.write_int32(warndays)
91
self.fp.write_int32(inactdays)
92
self.fp.write_int32(expiredate)
93
self.fp.write_int32(flag)
96
class ShadowByNameRequest(ShadowRequest):
98
action = constants.NSLCD_ACTION_SHADOW_BYNAME
100
def read_parameters(self, fp):
101
return dict(uid=fp.read_string())
104
class ShadowAllRequest(ShadowRequest):
106
action = constants.NSLCD_ACTION_SHADOW_ALL