Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ldap_override_shell config option #79

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nss_cache/sources/ldapsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,9 @@ def Transform(self, obj):
if hasattr(self, 'uidregex'):
pw.name = ''.join([x for x in self.uidregex.findall(pw.name)])

if 'loginShell' in obj:
if 'override_shell' in self.conf:
pw.shell = self.conf['override_shell']
elif 'loginShell' in obj:
pw.shell = obj['loginShell'][0]
else:
pw.shell = ''
Expand Down
53 changes: 53 additions & 0 deletions nss_cache/sources/ldapsource_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,59 @@ def testGetPasswdMap(self):

self.assertEqual('Testguy McTest', first.name)

def testGetPasswdMapWithShellOverride(self):
test_posix_account = ('cn=test,ou=People,dc=example,dc=com',
{'uidNumber': [1000],
'gidNumber': [1000],
'uid': ['Testguy McTest'],
'cn': ['test'],
'homeDirectory': ['/home/test'],
'loginShell': ['/bin/sh'],
'userPassword': ['p4ssw0rd'],
'modifyTimestamp': ['20070227012807Z']})
config = dict(self.config)
config['override_shell'] = '/bin/false'
attrlist = ['uid', 'uidNumber', 'gidNumber',
'gecos', 'cn', 'homeDirectory',
'fullName',
'loginShell', 'modifyTimestamp']

mock_rlo = self.mox.CreateMock(ldap.ldapobject.ReconnectLDAPObject)
mock_rlo.simple_bind_s(
cred='TEST_BIND_PASSWORD',
who='TEST_BIND_DN')
mock_rlo.search_ext(base='TEST_BASE',
filterstr='TEST_FILTER',
scope=ldap.SCOPE_ONELEVEL,
attrlist=mox.SameElementsAs(attrlist),
serverctrls=mox.Func(self.compareSPRC())).AndReturn('TEST_RES')

mock_rlo.result3('TEST_RES',
all=0,
timeout='TEST_TIMELIMIT').AndReturn(
(ldap.RES_SEARCH_ENTRY, [test_posix_account], None, []))
mock_rlo.result3('TEST_RES',
all=0,
timeout='TEST_TIMELIMIT').AndReturn(
(ldap.RES_SEARCH_RESULT, None, None, []))

self.mox.StubOutWithMock(ldap, 'ldapobject')
ldap.ldapobject.ReconnectLDAPObject(
uri='TEST_URI',
retry_max='TEST_RETRY_MAX',
retry_delay='TEST_RETRY_DELAY').AndReturn(mock_rlo)

self.mox.ReplayAll()

source = ldapsource.LdapSource(config)
data = source.GetPasswdMap()

self.assertEqual(1, len(data))

first = data.PopItem()

self.assertEqual('/bin/false', first.shell)

def testGetGroupMap(self):
test_posix_group = ('cn=test,ou=Group,dc=example,dc=com',
{'gidNumber': [1000],
Expand Down
3 changes: 3 additions & 0 deletions nsscache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ ldap_filter = (objectclass=posixAccount)
# the @example.com domain. Default is no regex.
#ldap_groupregex = ''

# Replace all users' shells with the specified one.
#ldap_override_shell='/bin/bash'

# Default uses rfc2307 schema. If rfc2307bis (groups stored as a list of DNs
# in 'member' attr), set this to 1
#ldap_rfc2307bis = 0
Expand Down
5 changes: 5 additions & 0 deletions nsscache.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ memberOf attributes. All matching groups are concatenated without spaces.
For example: '(.*)@example.com' would return a member without the
the @example.com domain. Default is no regex.

.TP
.B ldap_override_shell
If specified, set every user's login shell to the given one. May be
useful on bastion hosts or to ensure uniformity.

.TP
.B ldap_rfc2307bis
Default uses rfc2307 schema. If rfc2307bis (groups stored as a list of DNs
Expand Down