名前


setnetgrent, endnetgrent, getnetgrent, getnetgrent_r, innetgr - ネットワーク・グループのエントリを操作する

書式


#include <netdb.h>

int setnetgrent(const char *netgroup); void endnetgrent(void); int getnetgrent(char **host, char **user, char **domain);

int getnetgrent_r(char **host, char **user, char **domain, char *buf, int buflen);

int innetgr(const char *netgroup, const char *host, const char *user, const char *domain);

説明


netgroup は SunOS で考案されたものである。ネットグループのデータベースの エントリは、 3 つの文字列のリスト (hostname,username,domainname) もしくはネットグループ名である。 前記のリストの各要素は空であってもよい。 空は何とでも一致することを意味する。 本ページで説明する関数を使うことで、ネットグループのデータベースに アクセスすることができる。どのデータベースが検索されるかは /etc/nsswitch.conf ファイルで定義されている。

setnetgrent() コールは、この後で呼ばれる getnetgrent() コールが検索するネットグループを定める。 getnetgrent() 関数はネットグループの次のエントリを取得し、 host, user, domain にポインタを入れて返る。 NULL ポインタは、対応するエントリがどんな文字列とも一致することを意味する。 得られたポインタは、ネットグループ関係の関数のいずれかが呼ばれるまでの 間だけ有効である。この問題を避けるためには GNU 拡張の関数 getnetgrent_r() を使うとよい。この関数は呼び出し側が用意したバッファに 文字列を格納する。割り当て済のバッファを全て解放するには endnetgrent() を使用する。

ほとんどの場合、 (hostname,username,domainname) の3要素の組がネットグループのメンバーかどうかを確認したいだけであろう。 innetgr() 関数を使うと、上記の3つの関数を呼び出さずにこの目的を達成できる。 もう一度書いておくが、NULL ポインタはワイルドカードであり、 あらゆる文字列と一致する。この関数はスレッドセーフである。

返り値


これらの関数は成功すると 1 を、失敗すると 0 を返す。

ファイル


/etc/netgroup /etc/nsswitch.conf

注意


BSD の実装では setnetgrent() は void を返す。

関連項目


sethostent(3), setservent(3), setprotoent(3)

openSUSE Logo

コンテンツ