Solaris Naming Administration Guide

About the Name Service Switch

The name service switch is a file named nsswitch.conf. It controls how a client workstation or application obtains network information. It is used by client applications that call any of the getXbyY() interfaces such as:

The name service switch is often referred to as simply the switch or the switch file. Each workstation has a switch file in its /etc directory. Each line of that file identifies a particular type of network information, such as host, password, and group, followed by one or more sources where the client is to look for that information.

A client can obtain naming information from one or more of the switch's sources. For example, an NIS+ client could obtain its hosts information from an NIS+ table and its password information from a local /etc file. In addition, it could specify the conditions under which the switch must use each source (see"Search Criteria").

The Solaris 2.6 release software automatically loads an nsswitch.conf file into every workstation's /etc directory as part of the installation process. Three alternate (template) versions of the switch file are also loaded into /etc:

These three files are alternate default switch files. Each one is designed for a different primary naming service: /etc files, NIS, or NIS+. When Solaris 2.6 release software is first installed on a workstation, the installer selects the workstation's default name service: NIS+, NIS, or local files. During installation, the corresponding template file is copied to nsswitch.conf. For example, for a workstation client using NIS+, the installation process copies nsswitch.nisplus to nsswitch.conf. Unless you have an unusual namespace, the default template file as copied to nsswitch.conf should be sufficient for normal operation.

No default file is provided for DNS, but you can edit any of these files to use DNS (see "DNS and Internet Access").

If you later change a workstation's primary name service, you simply copy the appropriate alternate switch file to nsswitch.conf. (See "The nsswitch.conf Template Files".) You can also change the sources of particular types of network information used by the client by editing the appropriate lines of the /etc/nsswitch.conf file. The syntax for doing this is described below, and additional instructions are provided in Solaris Naming Setup and Configuration Guide.

Format of the nsswitch.conf File

The nsswitch.conf file is essentially a list of 15 types of information and the sources that getXXbyYY() routines search for that information. The 15 types of information, not necessarily in this order, are:

Table 2-1 provides a description of the kind of sources that can be listed in the switch file for the information types above.

Table 2-1 Switch File Information Sources

Information Sources 

Description 

files

A file stored in the client's /etc directory. For example, /etc/passwd

nisplus

An NIS+ table. For example, the hosts table.

nis

A NIS map. For example, the hosts map.

compat

Compat can be used for password and group information to support old-style + or - syntax in /etc/passwd, /etc/shadow, and /etc/group files.

dns

Can be used to specify that host information be obtain from DNS. 

Search Criteria

Single Source. If an information type has only one source, such as nisplus a routine using the switch searches for the information in that source only. If it finds the information, it returns a success status message. If it does not find the information, it stops searching and returns a different status message. What the routine does with the status message varies from routine to routine.

Multiple Sources. If a table has more than one source for a given information type, the switch directs the routine to start searching for the information in the first source that is listed. If it finds the information, it returns a success status message. If it does not find the information in the first source, it tries the next source. The routine will search through all of the sources until it has found the information it needs, or it is halted by encountering a return specification. If all of the listed sources are searched without find the information, the routine stops searching and returns a non-success status message.

Switch Status Messages

If a routine finds the information, it returns a success status message; if it does not find the information it is looking for, it returns one of three unsuccessful status messages, depending on the reason for not finding the information. Possible status messages are listed in Table 2-2.

Table 2-2 Switch Search Status Messages

Status Message 

Meaning of Message 

SUCCESS

The requested entry was found in the specified source. 

UNAVAIL

The source is not responding or is unavailable. That is, the NIS+ table, or NIS map, or /etc file could not be found or accessed.

NOTFOUND

The source responded with "No such entry." In other words, the table, map, or file was accessed but it did not contain the needed information. 

TRYAGAIN

The source is busy; it might respond next time. In other words, the table, map, or file was found, but it could not respond to the query. 

Switch Action Options

You can instruct the switch to respond to status messages with either of these two actions shown in Table 2-3.

Table 2-3 Responses to Switch Status Messages

Action 

Meaning 

return

Stop looking for the information. 

continue

Try the next source, if there is one. 

Default Search Criteria

The combination of nsswitch.conf file status message and action option determine what the routine does at each step. This combination of status and action is called the search criteria.

The switch's default search criteria are the same for every source. Described in terms of the status messages listed above, they are:

Because these are the default search criteria, they are assumed. That is, you do not have to explicitly specify them in the switch file. You can change these default search criteria by explicitly specifying some other criteria using the STATUS=action syntax show above. For example, the default action for a NOTFOUND condition is to continue the search to the next source. To specify that for a particular type of information, such as networks, the search is to halt on a NOTFOUND condition, you would edit the networks line of the switch file to read:


networks: nis [NOTFOUND=return] files

The networks: nis [NOTFOUND=return] files line specifies a nondefault criterion for the NOTFOUND status. (Nondefault criteria are delimited by square brackets.)

In this example, the search routine behaves as follows:

What if the Syntax is Wrong?

Client library routines contain compiled-in default entries that are used if an entry in the nsswitch.conf file is either missing or syntactically incorrect. These entries are the same as the switch file's defaults.

The name service switch assumes that the spelling of table and source names is correct. If you misspell a table or source name, the switch uses default values.

Auto_home and Auto_master

The switch search criteria for the auto_home and auto_master tables and maps is combined into one category called automount.

Timezone and the Switch File

The timezone table does not use the switch, so it is not included in the switch file's list.

Comments in nsswitch.conf Files

Any nsswitch.conf file line beginning with a hash character (#) is interpreted as a comment line and is ignored by routines that search the file.

When a hash character (#) is included in the middle of the line, characters to the left of the hash mark (before the hash mark) are interpreted by routines that search the nsswitch.conf file; characters to the right of the hash mark (after the hash mark) are interpreted as comments and not acted upon.

Table 2-4 Switch File Comment Examples

Type of Line 

Example 

Comment line (not interpreted). 

# hosts: nisplus [NOTFOUND=return] files 

Fully interpreted line. 

hosts: nisplus [NOTFOUND=return] file 

Partially interpreted line (the files element not interpreted)

hosts: nisplus [NOTFOUND=return] # files 

Keyserver and publickey Entry in the Switch File

The keyserver reads the publickey entry in the name service switch configuration file only when the keyserver is started. As a result, if you change the switch configuration file, the keyserver does not become aware of changes to the publickey entry until it is restarted.