NSSWITCH.CONF(5) Linux Programmer’s Manual NSSWITCH.CONF(5) 名前 nsswitch.conf - システムデータベースとネームサービススイッチの設定ファ イル 説明 C ライブラリの機能の中には、ローカルな環境で正しく動作させるには設定 が 必 要 なものが多数存在する。伝統的にこれはファイル (例えば /etc/passwd) を用いることで実現されてきた。しかし他のネームサービス (Network Infor- mation Service (NIS) や Domain Name Service (DNS)) が一般的になり、これ らが C ライブラリに取り込まれるようになっていった。ただし通常、検索の順 序は固定されていた。 NYS をサポートした Linux libc5 や GNU C Linrary 2.x (libc.so.6) では、 この問題はより見通し良く解決できるようになってい る 。 こ れ ら は Sun Microsystems が Solaris 2 の C ライブラリで用いた方法にならっている。以 下ではこの仕組みを "Name Service Switch" (NSS) と呼ぶ。データベースの情 報 源と、それらを閲覧する順序を指定したのが /etc/nsswitch.conf ファイル である。 NSS(ネームサービススィッチ) では以下のデータベースを扱うことができる。 aliases sendmail(8) で用いられるメールエイリアス。現在は無視される。 ethers イーサーネット番号。 group ユーザーのグループ。 getgrent(3) 関数によって用いられる。 hosts ホスト名とホスト番号。 gethostbyname(3) などの関数によって用いら れる。 netgroup ネットワークワイドに用いられるホストやユーザーのリスト。アクセス 制限に利用される。 glibc 2.1 以前の C ライブラリは、 NIS 上で だ け netgroup をサポートしている。 networks ネットワーク名と番号。 getnetent(3) 関数によって用いられる。 passwd ユーザーパスワード。 getpwent(3) 関数によって用いられる。 protocols ネットワークプロトコル。 getprotoent(3) 関数によって用いられる。 publickey NIS+ と NFS によって用いられる secure_rpc の公開鍵と秘密鍵。 rpc リモートプロシジャーコール (remote procedure call) の名前と番 号 。 getrpcbyname(3) などの関数によって用いられる。 services ネットワークサービス。 getservent(3) 関数によって用いられる。 shadow シャドウユーザーパスワード。 getspnam(3) によって用いられる。 /etc/nsswitch.conf フ ァ イ ル の 一 例を以下に示す (ここに示す内容は /etc/nsswitch.conf ファイルがない場合のデフォルトと同じである)。 passwd: compat group: compat shadow: compat hosts: dns [!UNAVAIL=return] files networks: nis [NOTFOUND=return] files ethers: nis [NOTFOUND=return] files protocols: nis [NOTFOUND=return] files rpc: nis [NOTFOUND=return] files services: nis [NOTFOUND=return] files 最初のカラムはデータベース名である。行の残りでは閲覧プロセスの動作を 指 定 している。それぞれのデータベースに対して、閲覧方法は独立に設定できる 。 各々のデータベースの設定には以下の 2 種類の内容を指定することができる。 * サービスの指定。 ‘files’, ‘db’, ‘nis’ など。 * 閲覧結果に対するリアクション。 ‘[NOTFOUND=return]’ など。 NYS 機能を組み込んだ libc5 では、指定できるサービスは ‘files’、 ‘nis’、 ‘nisplus’ のいずれかである。 hosts に対しては ‘dns’ も指定できる。ま た passwd と group に対しては ‘compat’ も指定できる。 shadow には ‘compat’ の指定はできない。 glibc では、利用しようとするサービス SERVICE それぞれに対して /lib/lib- nss_SERVICE.so.X というファイルが必要になる。標準的なインストールでは ‘files’、 ‘db’、 ‘nis’、 ‘nisplus’ が利用できるようになっていることが多 い。 hosts に対しては ‘dns’ も指定でき、 passwd、 group、 shadow に対し ては ‘compat’ も指定できる。これらのサービスは libc5+NYS の環境では利用 できない。バージョン番号 X は、 glibc 2.0 用なら 1、 glibc 2.1 用なら 2 である。 二つめの指定方法は閲覧プロセスをより詳細に制御するためのものである。 ア クション指定 (action item) はサービス名の間に、角かっこ [] で括られて記 述される。一般的な書式は以下の通り。 ‘[’ ( ‘!’? STATUS ‘=’ ACTION )+ ‘]’ ここでそれぞれ STATUS => success | notfound | unavail | tryagain ACTION => return | continue である。 キーワードの大文字小文字は区別されない。 STATUS の値は特定の機能に対 し て閲覧を行った結果である。それぞれの意味は以下の通り。 success エラーは起こらず、必要なエントリが返された。この結果に対するデフ ォルトのアクションは ‘return’ である。 notfound 閲覧プロセスは機能しているが、必要な値が見つからなかった。デフォ ルトのアクションは ‘continue’。 unavail サ ー ビスが(永続的に)利用できない。必要なファイルが存在しない 、DNS の場合にはサーバに対する問い合わせが許可されていない、など がありうる。デフォルトのアクションは ‘continue’。 tryagain サービスが一時的に利用できない。ファイルがロックされている、サー バの接続数がリミットを越えていて現在利用できない、などが考えられ る。デフォルトのアクションは ‘continue’。 +/- 書式との関係 (compat モード) NYS 機能を組み込んでいない libc5 は、ネームサービススイッチの機能を持っ ていない。しかしある程度のポリシー制御は行うことができる。 /etc/passwd で は +user や +@netgroup (NIS の passwd マップから指定したユーザを取り 込む)、 -user や -@netgroup (指定したユーザを除外する) 、 + (NIS の passwd マップから、除外されたユーザ以外の全てのエントリを取り込む) など を指定することができる。ほとんどの場合は /etc/passwd の最後に + を付 け て NIS のすべてを取り込んでいるだけなので、ネームサービススイッチを用い て (‘passwd: files nis’) のようにすればより高速な動作が期待でき、 ま た /etc/passwd, /etc/group, /etc/shadow に + だけのエントリを書かなくてす む。より細かな制御を行いたい場合は、 NSS の ‘compat’ サービスを用いれば +/- 書式をフルに用いることができる。デフォルトではソースは ‘nis’ になっ ているが、これは擬似データベース passwd_compat,group_compat,shadow_com- pat などに ‘nisplus’ を指定することで上書きできる。これらの擬似データベ ースは GNU C ライブラリでしか利用できない。 ファイル SERVICE という名前のサービスは libnss_SERVICE.so.1 という名前の共有オブ ジェクトライブラリで実装されている。これは /lib に置かれる。 /etc/nsswitch.conf 設定ファイル。 /lib/libnss_compat.so.X glibc2 に対して ‘compat’ ソースを実装したもの 。 /lib/libnss_db.so.X glibc2 に対して ‘db’ ソースを実装したもの。 /lib/libnss_dns.so.X glibc2 に対して ‘dns’ ソースを実装したもの。 /lib/libnss_files.so.X glibc2 に対して ‘files’ ソースを実装したもの。 /lib/libnss_hesoid.so.X glibc2 に対して ‘hesoid’ ソースを実装したもの 。 /lib/libnss_nis.so.X glibc2 に対して ‘nis’ ソースを実装したもの。 /lib/libnss_nisplus.so.X glibc2 に対して ‘nisplus’ ソースを実装したもの 。 /lib/libnss_nisplus.so.2 glibc 2.1 に対して ‘nisplus’ ソースを実装した もの。 注意 nsswitch.conf を利用するそれぞれのプロセスでは、ファイルは一度しか読 み 込まれない。もし nsswitch.conf があとで書き換えられても、そのプロセスは 古い設定のままで動作を継続する。 Solaris では NSS サービスを用いたプログラムをスタティックにリンクするこ とはできない。 Linux では問題なくスタティックリンクできる。 Linux 1999-01-17 NSSWITCH.CONF(5)
NSSWITCH.CONF(5) Linux Programmer’s Manual NSSWITCH.CONF(5) NAME nsswitch.conf - System Databases and Name Service Switch configuration file DESCRIPTION Various functions in the C Library need to be configured to work cor- rectly in the local environment. Traditionally, this was done by using files (e.g., /etc/passwd), but other nameservices (like the Network Information Service (NIS) and the Domain Name Service (DNS)) became popular, and were hacked into the C library, usually with a fixed search order. The Linux libc5 with NYS support and the GNU C Library 2.x (libc.so.6) contain a cleaner solution of this problem. It is designed after a method used by Sun Microsystems in the C library of Solaris 2. We fol- low their name and call this scheme "Name Service Switch" (NSS). The sources for the "databases" and their lookup order are specified in the /etc/nsswitch.conf file. The following databases are available in the NSS: aliases Mail aliases, provides a system-wide mechanism to redirect mail for local recipients. Used by mail transfer agents such as Post- fix or sendmail(8). Note: On Linux, not like on other Unices, Sendmail uses its own aliases resolution system independent on ‘/etc/nsswitch.conf’. ethers Ethernet numbers. group Groups of users, used by getgrent(3) functions. hosts Host names and numbers, used by gethostbyname(3) and similar functions. netgroup Network wide list of hosts and users, used for access rules. C libraries before glibc 2.1 only support netgroups over NIS. networks Network names and numbers, used by getnetent(3) functions. passwd User passwords, used by getpwent(3) functions. protocols Network protocols, used by getprotoent(3) functions. publickey Public and secret keys for Secure_RPC used by NFS and NIS+. rpc Remote procedure call names and numbers, used by getrpcbyname(3) and similar functions. services Network services, used by getservent(3) functions. shadow Shadow user passwords, used by getspnam(3). An example /etc/nsswitch.conf (namely, the default used when /etc/nss- witch.conf is missing): passwd: compat group: compat shadow: compat hosts: dns [!UNAVAIL=return] files networks: nis [NOTFOUND=return] files ethers: nis [NOTFOUND=return] files protocols: nis [NOTFOUND=return] files rpc: nis [NOTFOUND=return] files services: nis [NOTFOUND=return] files The first column is the database. The rest of the line specifies how the lookup process works. You can specify the way it works for each database individually. The configuration specification for each database can contain two dif- ferent items: * The service specification like ‘files’, ‘db’, or ‘nis’. * The reaction on lookup result like ‘[NOTFOUND=return]’. For libc5 with NYS, the allowed service specifications are ‘files’, ‘nis’, and ‘nisplus’. For hosts, you could specify ‘dns’ as extra ser- vice, for passwd and group ‘compat’, but not for shadow. For glibc, you must have a file called /lib/libnss_SERVICE.so.X for every SERVICE you are using. On a standard installation, you could use ‘files’, ‘db’, ‘nis’, and ‘nisplus’. For hosts, you could specify ‘dns’ as extra service, for passwd, group, and shadow ‘compat’. These services will not be used by libc5 with NYS. The version number X is 1 for glibc 2.0 and 2 for glibc 2.1. If System Security Services Daemon (SSSD) is installed on your system, you can use this service with the ‘sss’ keyword. SSSD supports the following databases: passwd, group, services and netgroup. The second item in the specification gives the user much finer control on the lookup process. Action items are placed between two service names and are written within brackets. The general form is ‘[’ ( ‘!’? STATUS ‘=’ ACTION )+ ‘]’ where STATUS => success | notfound | unavail | tryagain ACTION => return | continue The case of the keywords is insignificant. The STATUS values are the results of a call to a lookup function of a specific service. They mean: success No error occurred and the wanted entry is returned. The default action for this is ‘return’. notfound The lookup process works ok but the needed value was not found. The default action is ‘continue’. However, if the selected action for the ‘group’ database is ‘return’, the next lookup function is always called, without affecting the search result. unavail The service is permanently unavailable. This can either mean the needed file is not available, or, for DNS, the server is not available or does not allow queries. The default action is ‘continue’. tryagain The service is temporarily unavailable. This could mean a file is locked or a server currently cannot accept more connections. The default action is ‘continue’. Interaction with +/- syntax (compat mode) Linux libc5 without NYS does not have the name service switch but does allow the user some policy control. In /etc/passwd you could have entries of the form +user or +@netgroup (include the specified user from the NIS passwd map), -user or -@netgroup (exclude the specified user), and + (include every user, except the excluded ones, from the NIS passwd map). Since most people only put a + at the end of /etc/passwd to include everything from NIS, the switch provides a faster alternative for this case (‘passwd: files nis’) which doesn’t require the single + entry in /etc/passwd, /etc/group, and /etc/shadow. If this is not sufficient, the NSS ‘compat’ service provides full +/- semantics. By default, the source is ‘nis’, but this may be overridden by specifying any NSS service except ‘compat’ itself as the source for the pseudo-databases passwd_compat, group_compat and shadow_compat. These pseudo-databases are only available in GNU C Library. If SSSD is installed on your system, you can use ‘sss’ as the source for these pseudo-databases. FILES A service named SERVICE is implemented by a shared object library named libnss_SERVICE.so.X that resides in /lib. /etc/nsswitch.conf configuration file /lib/libnss_compat.so.X implements ‘compat’ source for glibc2 /lib/libnss_db.so.X implements ‘db’ source for glibc2 /lib/libnss_dns.so.X implements ‘dns’ source for glibc2 /lib/libnss_files.so.X implements ‘files’ source for glibc2 /lib/libnss_hesiod.so.X implements ‘hesiod’ source for glibc2 /lib/libnss_nis.so.X implements ‘nis’ source for glibc2 /lib/libnss_nisplus.so.2 implements ‘nisplus’ source for glibc 2.1 The following files are read when "files" source is specified for respective databases: aliases /etc/aliases ethers /etc/ethers group /etc/group hosts /etc/hosts initgroups /etc/group netgroup /etc/netgroup networks /etc/networks passwd /etc/passwd protocols /etc/protocols publickey /etc/publickey rpc /etc/rpc services /etc/services shadow /etc/shadow NOTES Within each process that uses nsswitch.conf, the entire file is read only once; if the file is later changed, the process will continue using the old configuration. With Solaris, it isn’t possible to link programs using the NSS Service statically. With Linux, this is no problem. COLOPHON This page is part of release 3.22 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 1999-01-17 NSSWITCH.CONF(5)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa