<?xml version="1.0" encoding="UTF-8" ?><oembed><version>1.0</version><provider_name>Jui-Nan Lin&#039;s Blog</provider_name><provider_url>https://jnlin.org</provider_url><author_name>jnlin</author_name><author_url>https://jnlin.org/author/jnlin/</author_url><title>Migrate From UNIX/NIS Password to LDAP</title><html>首先先安裝 LDAP 並設定好。請參考 &lt;a href=&quot;/?p=91&gt;Install OpenLDAP on FreeBSD&lt;/a&gt;。
&lt;a href=&quot;http://www.padl.com/&quot;&gt;PADL Software Pty Ltd&lt;/a&gt; 這家公司提供了一套 Open Source 的 Migration Tools，可以在&lt;a href=&quot;http://www.padl.com/download/MigrationTools.tgz&quot;&gt;這裡&lt;/a&gt;下載。
&lt;!--more--&gt;
下載之後請解壓縮：&lt;ul&gt;&lt;code&gt;
      #tar zxvf MigrationTools.tgz
      #cd MigrationTools-46
&lt;/code&gt;&lt;/ul&gt;
接著請修改 migrate_common.ph:
&lt;ul&gt;
      $DEFAULT_MAIL_DOMAIN
      $DEFAULT_MAIL_HOST
      LDAP 的 mail 屬性的 Domain ，例如：cs.nctu.edu.tw

      $DEFAULT_BASE
      LDAP 的 Base DN，例如：dc=cs,dc=nctu,dc=edu,dc=tw。

      $EXTENDED_SCHEMA
      是否加入 organizationalPerson 與 inetOrgPerson 的資料。
&lt;/ul&gt;
再接下來請修改 migrate_passwd.pl，找到local($user, $pwd, $uid, $gid, $gecos, $homedir, $shell) = split(/:/);這一段，將他改成可以分析 master.passwd (或任何 shadow檔) 的格式。另外要將與 kerberos 有關的程式碼全部註解起來（應該有兩段）。

如果你的 gecos 有 multibyte 的資料，必須先轉成 utf-8 才能開始匯入 LDAP。

如果你有需要讓 Linux 也吃 LDAP 的帳號密碼，必須在加上兩行：
&lt;ul&gt;&lt;code&gt;
      print $HANDLE &quot;objectClass: shadowAccount\n&quot;;
      print $HANDLE &quot;shadowLastChange: 0\n&quot;; 
&lt;/code&gt;&lt;/ul&gt;
如果你有需要讓 Samba 也吃 LDAP 的帳號密碼，必須在加上兩行：
&lt;ul&gt;&lt;code&gt;
      print $HANDLE &quot;objectClass: sambaSamAccount\n&quot;;
      print $HANDLE &quot;sambaSID: S-1-5-21-4000614413-3301257388-2182072073-$uid\n&quot;; 
&lt;/code&gt;&lt;/ul&gt;
其中 sambaSID: S-1-5-21-4000614413-3301257388-2182072073 的部份，請參考 Samba with LDAP 這分文件。

接著就可以執行 migrate_all_online.sh，將系統的資料匯入 LDAP。

如果你想要讓 FreeBSD 用 LDAP 的帳號密碼作認證，請看 &lt;a href=&quot;/?p=93&quot;&gt;Enable nss_ldap in FreeBSD&lt;/a&gt;。

附註:
這是我另外設定的環境變數，主要是因為 hosts 檔案會有兩個 localhost entry，還有我想順便把使用者的密碼也匯入 LDAP。
/tmp/master.passwd 是除去系統帳號（root, toor, dump...）之後的密碼檔。
&lt;ul&gt;&lt;code&gt;
      # setenv LDAPADD &quot;`which ldapadd` -c&quot;
      # setenv ETC_PASSWD /tmp/master.passwd 
&lt;/code&gt;&lt;/ul&gt;</html><type>rich</type></oembed>