Showing posts with label ldap. Show all posts
Showing posts with label ldap. Show all posts

Change return values in nss_ldap

After some time searching I found the nss_override_attribute_value config file parameter for /etc/ldap.conf. This has the effect that you can overwrite the ldap return value through a standard value. So as an example:
nss_override_attribute_value unixHomeDirectory /var
This will change the home directories of all users returned through ldap to /var.
NOTE: the nss_override_attribute_value has to come before the nss_map_attribute in the config file.
Further there is the nss_default_attribute_value entry which can be quite usefull for the shell for example.

ldap_open and ldap_init with Active Directory

All my ldap programs have till now used the OpenLdap server. As we are now migrating to the Ldap fronted of Active Directory I had to migrate quite a few c programs. But here is the problem:
If I use ldap_init it will fail and shout at me
ldap_simple_bind_s: Can't contact LDAP server 
but if I use ldap_open it all works. No idea why this is happening. But ldap_open is deprecated so lots of fun coming up. That's what you get for writing c programs.

pam_filter not working

So here is the problem you want to limit your cluster to a special user group. You have everything LDAP managed and use pam_ldap for authentication. But when you edit the /etc/ldap.conf and set a pam_filter nothing happens. First of all the the syntax of pam_filter :
(|(gidNumber=1028)(gidNumber=1160))
Will not work
Literally only
pam_filter gidNumber=1028
Will work. This is the way they stupidly implemented it
      else if (!strcasecmp (k, "pam_filter"))
{
CHECKPOINTER (result->filter = strdup (v));
}

where v is everything after the ' '

while (*v != '\0' && *v != ' ' && *v != '\t')
v++;

*(v++) = '\0';

For those that know C
So you can give it one value max. Now you have to modify the /etc/pam.d/system-auth file. The default configuration is:
[root@lxb5477 ~]# cat /etc/pam.d/system-auth.back | grep ldap
auth sufficient /lib/security/$ISA/pam_ldap.so use_first_pass
account [default=bad success=ok user_unknown=ignore] /lib/security/$ISA/pam_ldap.so
password sufficient /lib/security/$ISA/pam_ldap.so use_authtok
session optional /lib/security/$ISA/pam_ldap.so

But of course a optional is not really enough. You, of course, want that if the user doesn't fulfill your filter he should be chucked into nirvana. So change to:
[root@lxb5477 ~]# cat /etc/pam.d/system-auth | grep ldap
auth required /lib/security/$ISA/pam_ldap.so
account required /lib/security/$ISA/pam_ldap.so
password requried /lib/security/$ISA/pam_ldap.so use_authtok
session required /lib/security/$ISA/pam_ldap.so

Through this if ldap fails the login fails.

But be aware that in /etc/nsswitch.conf files is before ldap
passwd:     files ldap
shadow: files ldap
group: files ldap

Otherwise you have locked yourself out :)