Go to main content

man pages section 5: File Formats

Exit Print View

Updated: Thursday, June 13, 2019
 
 

nsswitch.conf (5)

Name

nsswitch.conf - configuration file for the name service switch

Synopsis

svc:/system/name-service/switch
/etc/nsswitch.conf

Description

The operating system uses a number of databases of information about hosts, ipnodes, users (passwd(5), shadow(5), and user_attr(5)), and groups. Data for these can come from a variety of sources: hostnames and host addresses, for example, can be found in /etc/hosts, NIS, LDAP , DNS, or Multicast DNS. Zero or more sources can be used for each database; the sources and their lookup order are specified in svc:/system/name-service/switch service. For the purposes of backwards compatibility, the /etc/nsswitch.conf file is regenerated from the SMF properties configured in the svc:/system/name-service/switch service. The /etc/nsswitch.conf file is considered obsolete.

The following databases use the switch file:

Database
Used By
alias
auth_attr
automount
bootparam
ether
group
host
gethostbyname(3C), getaddrinfo(3C). See Interaction with netconfig.
netgroup
netmask
network
passwd
prof_attr
project
protocol
publickey
rpc
service
See Interaction with netconfig.
user_attr
sudoers
sudo(8)

The following sources can be used:

Source
Uses
files
/etc/hosts, /etc/passwd, /etc/inet/ipnodes, /etc/shadow, /etc/security/auth_attr, /etc/user_attr
nis
NIS(YP)
ldap
LDAP
ad
Active Directory
dns
Valid only for hosts and ipnodes. Uses the Internet Domain Name Service.
mdns
Valid only for hosts and ipnodes. Uses the Multicast Domain Name Service.

/etc/inet/ipnodes is a symbolic link to /etc/hosts.

The config property group of the svc:/system/name-service/switch service contains the configuration for the nsswitch.conf file.

The config/default property sets the default property for all nsswitch databases, while the other properties can be used to override the default property if desired.

For instance:


config/default set to "files", and
config/host set to "files dns" defaults all
databases to local files database access, except for the
host database which will search files first and dns second,
if dns access is configured.

The following single-valued properties are supported:


config/default    Default db configuration
config/host       Override for host db
config/password   Override for passwd db
config/group      Override for group db
config/network    Override for network db
config/protocol   Override for protocol db
config/rpc        Override for rpc db
config/ether      Override for ether db
config/netmask    Override for netmask db
config/bootparam  Override for bootparam db
config/publickey  Override for publickey db
config/netgroup   Override for netgroup db
config/automount  Override for automount db
config/alias      Override for alias db
config/service    Override for service db
config/project    Override for project db
config/auth_attr  Override for auth_attr db
config/prof_attr  Override for prof_attr db
config/sudoer     Override for sudoers db
config/tnrhtp     Override for tnrhtp db
config/tnrhdb     Override for tnrhdb db

Typically the property values are simple, such as "files" "files nis". However, when multiple sources are specified, it is sometimes necessary to define precisely the circumstances under which each source is tried. A source can return one of the following codes:

Status
Meaning
SUCCESS
Requested database entry was found.
UNAVAIL
Source is not configured on this system or internal failure.
NOTFOUND
Source responded “no such entry
TRYAGAIN
Source is busy or not responding, might respond to retries.

For each status code, two actions are possible:

Action
Meaning
continue
Try the next source in the list.
return
Return now.

Additionally, for TRYAGAIN only, the following actions are possible:

Action
Meaning
forever
Retry the current source forever.
n
Retry the current source n more times, where n is an integer between 0 and MAX_INT (that is, 2.14 billion). After n retries has been exhausted, the TRYAGAIN action transitions to continue, until a future request receives a response, at which time TRYAGAIN=n is restored.

The complete syntax of an entry is:

<entry>     ::= <database> ":" [<source> [<criteria>]]*
<criteria>  ::= "[" <criterion>+ "]"
<criterion> ::= <status> "=" <action>
<status>    ::= "success" | "notfound" | "unavail" | "tryagain"

For every status except TRYAGAIN, the action syntax is:

<action>    ::= "return"  | "continue"

For the TRYAGAIN status, the action syntax is:

<action>    ::= "return"  | "continue" | "forever" | <n>
<n>         ::= 0...MAX_INT          

Each property is a single valued string. The <source> names are case-sensitive, but <action> and <status> names are case-insensitive.

If a database entry or default is absent, the system defaults to "files" in all situations. Additionally if the name service cache service (svc:/system/name-service-cache) is not enabled, all attempts to access remote file services can be ignored.

The default criteria for DNS and the NIS server in “DNS-forwarding mode” is [SUCCESS=return NOTFOUND=continue UNAVAIL=continue TRYAGAIN=3].

The default criteria for all other sources is [SUCCESS=return NOTFOUND=continue UNAVAIL=continue TRYAGAIN=forever].

The default, or explicitly specified, criteria are meaningless following the last source in an entry; and they are ignored, since the action is always to return to the caller irrespective of the status code the source returns.

Interaction with netconfig

In order to ensure that they all return consistent results, gethostbyname(3C), getaddrinfo(3C), getservbyname(3C), and netdir_getbyname(3C) functions are all implemented in terms of the same internal library function. This function obtains the system-wide source lookup policy for hosts , ipnodes, and services based on the inet family entries in netconfig(5) and uses the switch entries only if the netconfig entries have a - (hyphen) in the last column for nametoaddr libraries. See the Notes section in gethostbyname(3C) and getservbyname(3C) for details.

Interaction with server in DNS-forwarding Mode

The NIS (YP) server can be run in DNS-forwarding mode, where it forwards lookup requests to DNS for host-names and -addresses that do not exist in its database. In this case, specifying nis as a source for hosts is sufficient to get DNS lookups; dns need not be specified explicitly as a source.

Interaction with Password Aging

When password aging is turned on, only a limited set of possible name services are supported and must follow those rules:

  • passwd line must have 1, 2 or 3 entries

  • First passwd entry must be files

  • passwd entries other than files, nis and ldap are ignored and skipped during password update. (It is necessary to use source-specific tool to update password in such database).

Any other settings causes the passwd(1) command to fail when it attempts to change the password after expiration and prevents the user from logging in. These are the only permitted settings when password aging has been turned on. Otherwise, you can work around incorrect passwd: lines by using the -r repository argument to the passwd(1) command and using passwd -r repository to override the nsswitch.conf settings and specify in which name service you want to modify your password.

Hard-wired Policies

The compiled-in default entries for all databases is "files".

Useful Configuration Notes

The files source for the ipnodes and hosts databases is identical, as /etc/inet/ipnodes is a symbolic link to /etc/hosts. The host property is used for host lookups.

When using Active Directory, dns is required to perform hosts resolution.

In order to get information from the Internet Domain Name Service for hosts that are not listed in the enterprise level name service LDAP, use the following configuration and set up the /etc/resolv.conf file (see resolv.conf(5) for more details):

hosts:

files dns

Enumeration - getXXXent()

Many of the databases have enumeration functions: passwd has getpwent(), hosts has gethostent(), and so on. These were reasonable when the only source was files but often make little sense for hierarchically structured sources that contain large numbers of entries, much less for multiple sources. The interfaces are still provided and the implementations strive to provide reasonable results, but the data returned can be incomplete (enumeration for hosts is simply not supported by the dns source), inconsistent (if multiple sources are used), formatted in an unexpected fashion (for a host with a canonical name and three aliases, a source might return four hostents, and they might not be consecutive), or very expensive (enumerating a passwd database of 5,000 users is probably a bad idea). Furthermore, multiple threads in the same process using the same reentrant enumeration function (getXXXent_r() are supported beginning with SunOS 5.3) share the same enumeration position; if they interleave calls, they enumerate disjoint subsets of the same database.

In general, the use of the enumeration functions is deprecated. In the case of passwd, shadow, and group, it might sometimes be appropriate to use fgetgrent(), fgetpwent(), and fgetspent() (see getgrnam(3C), getpwnam(3C), and getspnam(3C), respectively), which use only the files source.

Files

A source named SSS is implemented by a shared object named nss_SSS.so.1 that resides in /usr/lib.

/etc/nsswitch.conf

Configuration file. (Obsolete.)

/usr/lib/nss_dns.so.1

Implements dns source.

/usr/lib/nss_files.so.1

Implements files source.

/usr/lib/nss_mdns.so.1

Implements mdns source.

/usr/lib/nss_nis.so.1

Implements nis source.

/usr/lib/nss_ldap.so.1

Implements ldap source.

/usr/lib/nss_ad.so.1

Implements ad source.

/etc/netconfig

Configuration file for netdir(3C) functions that redirects hosts/devices policy to the switch.

/etc/nsswitch.files

Sample configuration file that uses files only.

/etc/nsswitch.nis

Sample configuration file that uses files and nis.

/etc/nsswitch.ldap

Sample configuration file that uses files and ldap.

/etc/nsswitch.ad

Sample configuration file that uses files and ad.

/etc/nsswitch.dns

Sample configuration file that uses files, dns and mdns (dns and mdns only for hosts).

See Also

kpasswd(1), newtask(1), passwd(1), ethers(3C), getaddrinfo(3C), getauthnam(3C), getexecprof(3C), getgrnam(3C), gethostbyname(3C), getnetbyname(3C), getnetgrent(3C), getprofnam(3C), getprotobyname(3C), getpublickey(3C), getpwnam(3C), getrpcbyname(3C), getservbyname(3C), getspnam(3C), getuserattr(3C), getusernam(3C), netdir(3C), secure_rpc(3C), getdefaultproj(3PROJECT), getprojent(3PROJECT), inproj(3PROJECT), setproject(3PROJECT), auth_attr(5), hosts(5), netconfig(5), project(5), resolv.conf(5), user_attr(5), ypfiles(5), ad(7), ldap(7), pam_list(7), automount(8), ifconfig(8), mdnsd(8), rpc.bootparamd(8), sendmail(8)

Notes

Within each process that uses nsswitch.conf, the entire file is read only once; if the file is later changed, the process continues using the old configuration.

The use of both nis and ldap as sources for the same database is strongly discouraged since both the name services are expected to store similar information and the lookups on the database can yield different results depending on which name service is operational at the time of the request.

Do not use the ldap and ad keywords together when the Oracle Solaris LDAP client uses schema mapping to talk to Active Directory.

Misspelled names of sources and databases are treated as legitimate names of (most likely non-existent) sources and databases.

The compat backend and the use of '+' or '-' interactions in the password and group files is no longer supported.

nsswitch.conf does not control the name service configuration for everything in Oracle Solaris.

The following functions do not use the switch: fgetgrent(3C), fgetprojent(3PROJECT), fgetpwent(3C), fgetspent(3C), getpw(3C), putpwent(3C), shadow(5).