8

Is there any generic solution to use a single NSS library two (or more) times?

In my case I have two LDAP servers, one local on the machine itself and one remote. I need to make NSS work with both of them (it uses the remote one if local doesn't have required entries).

Currently it was solved so that single library (PADL/nss_ldap) is build twice. In both cases before building sed is used to change all nss_ldap occurences in sources to something else. For each case a different text is used (like nss_ldap_1 and nss_ldap_2). The build result is renamed accordingly. Both binaries are stored on target system and referred to in /etc/nsswitch.conf.

Also both of those libraries use different configuration files in /etc/ (otherwise it wouldn't make any sense!). This however is done easily by just changing argument in in configure script of the library run before building.

But it doesn't "feel right". Is there any other approach?

What I could imagine is that NSS library itself could support multiple configurations so that it would work as two "single instances". But this is hard to achieve if you are not author of the library. Also it requires subsequent invocation of the library for both configurations while one might prefer to have some other library in between.

Another approach would be to write a simple forwarder that just calls some other library with different configuration. But this again requires that other library be somehow reconfigurable (if it just uses some fixed config files in /etc the forwarder will work just as the first version). And also it works only once - to have a library used three times or more the same problem returns now with forwarder itself.

  • Wow, surprised that worked—don't they try to read from the same configuration file? Or did you change the config file name as well? – derobert May 19 '15 at 15:25
  • 1
    How about using sss? – Stéphane Chazelas May 19 '15 at 15:42
  • @StéphaneChazelas I think sssd is intended to work with one authoritative LDAP system, where all the LDAP servers it talks to have the same data. OP seems to want multiple servers with different data, and some lookups to go against server1 and other lookups against server2. – derobert May 19 '15 at 15:59
  • @derobert, no, sssd should work with several independent providers. – Stéphane Chazelas May 19 '15 at 16:05
  • 2
    On the other hand you may find that it solves a few other things like proper credential caching and more flexibility in the configuration. – Stéphane Chazelas May 20 '15 at 6:34
4

Unfortunately, you can't do this with the NSS implementation of GNU libc. You noticed the fundamental problem, just let me present it from a different angle: the nsswitch.conf syntax does not allow for providing any additional info to the NSS service modules, thus they couldn't behave differently on repeated invocations anyway. So it isn't supported from the libc side nor from the module side. Moreover, glibc makes a point of keeping the service modules directly linkable shared objects, which excludes any linking trickery.

What you can do instead is to create a meta directory out of your two LDAP directories and use that in your NSS config. OpenLDAP supports this nicely, see the slapd-meta(5) manual page or this merge intro for example. Of course you don't need a new slapd instance for this if you can configure either of the two.

(And instead of nss-ldap use nss-ldapd if you can.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.