13.5.3.4. Netgroup エントリーのインポート
/etc/netgroup ファイルには、全 NIS netgroup 情報が含まれます。このエントリーを使用して、NIS エントリーをミラーリングする IdM netgroup アカウントを作成できます。
たとえば、以下は
nis-netgroup.sh
の例です。
1 is the nis domain, 2 is the nis master server
#!/bin/sh
# 1 is the nis domain, 2 is the nis master server
ypcat -k -d $1 -h $2 netgroup > /dev/shm/nis-map.netgroup 2>&1
IFS=$'\n'
for line in $(cat /dev/shm/nis-map.netgroup); do
IFS=' '
netgroupname=$(echo $line|awk '{print $1}')
triples=$(echo $line|sed "s/^$netgroupname //")
echo "ipa netgroup-add $netgroupname --desc=NIS_NG_$netgroupname"
if [ $(echo $line|grep "(,"|wc -l) -gt 0 ]; then
echo "ipa netgroup-mod $netgroupname --hostcat=all"
fi
if [ $(echo $line|grep ",,"|wc -l) -gt 0 ]; then
echo "ipa netgroup-mod $netgroupname --usercat=all"
fi
for triple in $triples; do
triple=$(echo $triple|sed -e 's/-//g' -e 's/(//' -e 's/)//')
if [ $(echo $triple|grep ",.*,"|wc -l) -gt 0 ]; then
hostname=$(echo $triple|cut -f1 -d,)
username=$(echo $triple|cut -f2 -d,)
domain=$(echo $triple|cut -f3 -d,)
hosts=""; users=""; doms="";
[ -n "$hostname" ] && hosts="--hosts=$hostname"
[ -n "$username" ] && users="--users=$username"
[ -n "$domain" ] && doms="--nisdomain=$domain"
echo "ipa netgroup-add-member $hosts $users $doms"
else
netgroup=$triple
echo "ipa netgroup-add $netgroup --desc=NIS_NG_$netgroup"
fi
done
done
「NIS および Identity Management の概要」で簡単に説明したように、NIS エントリーはトリプルと呼ばれる 3 つの値セットに存在します。トリプルは host,user,domain ですが、すべてのコンポーネントが必要な訳ではありません。通常、トリプルで、ホストとドメイン、またはユーザーとドメインのみを定義します。このスクリプトの記述の仕方から、ipa netgroup-add-member コマンドは常に、netgroup にホスト、ユーザー、ドメインのトリプルを追加します。
if [ $(echo $triple|grep ",.*,"|wc -l) -gt 0 ]; then hostname=$(echo $triple|cut -f1 -d,) username=$(echo $triple|cut -f2 -d,) domain=$(echo $triple|cut -f3 -d,) hosts=""; users=""; doms=""; [ -n "$hostname" ] && hosts="--hosts=$hostname" [ -n "$username" ] && users="--users=$username" [ -n "$domain" ] && doms="--nisdomain=$domain" echo "ipa netgroup-add-member $hosts $users $doms"
if [ $(echo $triple|grep ",.*,"|wc -l) -gt 0 ]; then
hostname=$(echo $triple|cut -f1 -d,)
username=$(echo $triple|cut -f2 -d,)
domain=$(echo $triple|cut -f3 -d,)
hosts=""; users=""; doms="";
[ -n "$hostname" ] && hosts="--hosts=$hostname"
[ -n "$username" ] && users="--users=$username"
[ -n "$domain" ] && doms="--nisdomain=$domain"
echo "ipa netgroup-add-member $hosts $users $doms"
要素が抜けている箇所は、空白として追加されるので、トリプルは正しく移行されます。たとえば、server,,domain のトリプルの場合は、メンバー追加コマンドのオプションは、--hosts=server --users="" --nisdomain=domain です。
これは、NIS ドメインと NIS サーバーを指定して、特定の NIS ドメインに対して実行できます。
kinit admin ./nis-hosts.sh nisdomain nis-master.example.com
[root@nis-server ~]# kinit admin
[root@nis-server ~]# ./nis-hosts.sh nisdomain nis-master.example.com