Page 1
1
MOODLEMOODLEMOODLEMOODLE 採採採採 LDAPLDAPLDAPLDAP 認證模式之實作認證模式之實作認證模式之實作認證模式之實作
李嘉彪 [email protected] 2010-07-05
太多的帳號及密碼太多的帳號及密碼太多的帳號及密碼太多的帳號及密碼
隨著網路服務發達與多樣性,個人在不同服務平台上所申請的帳號、密碼,
可說是琳瑯滿目,每一個人擁有多組帳號密碼,早已是習以為常的事,而不同服
務平台上所申的帳號、密碼為了管理方便,基於資訊安全考量緣故,所以規定格
式也不盡相同,有的在乎帳號的格式需要特定字元數,有的在密碼的規定上需要
有好幾位數,而且還要有特定字元的組合,如此一來,每一個人常常需要牢記多
組帳號、密碼,時間一久,不常使用到的帳號、密碼無形中,就被遺忘了,為了
解決每一個人擁有多組帳號、密碼的問題,本文嘗試提出以 LDAP 整合帳號、密
碼,讓多個不同服務平台都可以使用同一個帳號、密碼登入,以解決每
一個人需要牢記多組帳號、密碼的問題。
MoodleMoodleMoodleMoodle 以以以以 LDAPLDAPLDAPLDAP 認證認證認證認證((((多個多個多個多個 MOODLEMOODLEMOODLEMOODLE 平台的單一帳號認證平台的單一帳號認證平台的單一帳號認證平台的單一帳號認證))))
LDAP 代 表 Lightweight Directory Access Protocol 的 縮 寫 , , 它 是 一 種
protocol,可不是一種資料庫,Moodle 可以採取多種帳號密碼認證,其中一項即
是以 LDAP 認證,如果你有多個 MOODLE 學習平台,您可以先架設一個 LDAP
Server,再將 這幾個 MOODLE 端的認證方式設定為 LDAP 認證,即可達到 SSO
的理想 ,本文件嘗試建立 LDAP server 看的懂得資料結構(即 LDIF 檔,
Leightweight Directory Interchange Format 建立 LDAP Server 上的使用者帳號,再由
Moodle 端設定以 LDAP 認證帳號密碼,達到 Single sign on(SSO)的理想,同時
Moodle 端的使用者也可以經由 Moodle 的修改個人資料的頁面,更改自己的密
碼、個人資訊再將這些更動回寫到 LDAP 中。
Page 2
2
為什麼要用為什麼要用為什麼要用為什麼要用 LDAPLDAPLDAPLDAP 做做做做 Single sign on(SSO) Single sign on(SSO) Single sign on(SSO) Single sign on(SSO)
LDAP 代表 Lightweight Directory Access Protocol 的縮寫,它是基於 X.500 所發
展出來的輕量級的目錄服務,發展至今,已經成為一種標準,以這篇文件撰寫的
時間來說,許多的 Server 端以及 Client 端應用程式或模組,如 Microsoft 的 Outlook、
Active Directory 與 GNU 的 snedmail、ftpd 及系統上 PAM 帳號、Openwebmail....等,
都可以同時以 LDAP 的帳號密碼認證,LDAP 儼然就是一種眾多程式開發者依循
的共通標準,而本文當中所提到 MOODLE 與 XOOP 當然也支援 LDAP 的認證方
式,MOODLE 與 XOOP 也已經將 LDAP 當成其中的一種認證方式。此外,LDAP
也可以針對本身所提供不足的部份,由使用者的需要自訂 Schema,相當的具有
擴充性,而 LDAP 本身就是一種目錄服務,它可以將所有的資訊寫入,藉由 LDAP
做共通的查詢,本文僅僅用到其中的帳號密碼屬性而已,再來,LDAP 的後端資
料,可選用多種資料庫,也因為 LDAP 常用於查詢次數多,而更動次數少,使得
LDAP 的效率無形之中也提高許多。
LDAP 可用多種網頁程式開發前端介面,如 PHP、PERL....等,基於以上幾點,
所以本文將以實做文件的方式,帶領大家一步一步的完成
三三三三、、、、MOODLEMOODLEMOODLEMOODLE 採用採用採用採用 LDAP SSOLDAP SSOLDAP SSOLDAP SSO 認證認證認證認證
本文件將從 LDAP 的架設以及 MOODLE 的設定開始說明;再使用者帳號以
及密碼 DN(Distinguish Name)匯入 LDAP 中,完成之後,MOODLE 即可以建立的
使用者帳號以及密碼 DN(Distinguish Name)認證登入 MOODLE 系統中。
四四四四、、、、安裝環境安裝環境安裝環境安裝環境 FreeBSD8.0
Page 3
3
取得 FreeBSDFreeBSDFreeBSDFreeBSD 8.08.08.08.0
ftp://freebsd.csie.nctu.edu.tw/pub/ISO-IMAGES-i386/8.0/
ftp://freebsd.csie.nctu.edu.tw/pub/ISO-IMAGES-i386/8.0/8.0-RELEASE-i386-disc1.iso
以 Minimun 安裝,約 5 分鐘可以完成 FreeBSD 8.0 的 OS
將上面網址下載的 ISO 檔,燒錄成光碟片開機,會出現下面的畫面
地區選擇 213 Taiwan
Page 4
4
選擇鍵盤配置 USA ISO�
選擇 Express 快速安裝�
選擇 A 整顆硬碟規劃給 FreeBSD 用�
Page 5
5
再將光棒上移,按鍵盤上的選擇 S 設定成可開機�
選標準 MBR�
按鍵盤 A,讓系統自動分割磁區�
Page 6
6
選用最小安裝�
從光碟安裝 FreeBSD�
直接確認即可�
Page 7
7
開始安裝的畫面�
開始安裝的畫面�
開始安裝的畫面�
Page 8
8
是否需要設定其他項目�
回到前一個畫面�
提示系統將會重新開機�
Page 9
9
將光碟片取出後,按 enter�
重新開機中�
按 Enter 繼續�
Page 10
10
開機畫面�
登入輸入「root」,第一次進入,沒有密碼�
「root」登入成功�
Page 11
11
登入後輸入「passwd root」,設定 root 的密碼�
輸入「sysinstall」,設定網路相關功能�
移到「Configure」,按 ENTER 做安裝後的設定�
Page 12
12
移到「Networking」,按 ENTER 做網卡的設定�
移到「Interfaces」,按 ENTER 後,再按「TAB」移到 [OK]後按 ENTER�
系統會自己抓取網卡,按「TAB」移到 [OK]後按 ENTER�
Page 13
13
是否使用 IPV6,選 [NO]即可�
主機是否使用 DHCP 方式取得 IP,選 [NO]即可�
手動設定固定 IP(依照實際情況,自行輸入) �
Page 14
14
是否要讓網卡馬上作用,選擇 [Yes] 即可�
回到前一個畫面,按 TAB,選擇 [Cancel] ,按 ENTER 即可�
Page 15
15
回到前一個畫面,按 TAB,選擇 [Exit] 後,按 ENTER 即可�
有些機器需要 reboot 重新開機�
開機後,測試網路是否連通,以 ping 140.113.1.1 測試�
Page 16
16
網路已經通了�
到此已經完成 FreeBSD 8.0 的安裝了
Page 17
17
五五五五、、、、取得取得取得取得 openldap openldap openldap openldap 的程式的程式的程式的程式
Open LDAP 的官方網站 http://www.openldap.org/
Open LDAP 的官方網站快速安裝說明
文 http://www.openldap.org/doc/admin/quickstart.html
[myLDAP]# mkdir /usr/source
[myLDAP]# cd /usr/source
[myLDAP]# fetch ftp://ftp.openldap.org/pub/OpenLDAP/openldap-stable/openldap-stable-20100219.tgz
[myLDAP]# tar zxvf openldap-stable-20100219.tgz
[myLDAP]# cd openldap-2.4.21[
查看一下說明檔
========================================================
REQUIRED SOFTWARE
Building OpenLDAP Software requires a number of software packages
to be preinstalled. Additional information regarding prerequisite
software can be found in the OpenLDAP Administrator's Guide.
Base system (libraries and tools):
Standard C compiler (required)
Cyrus SASL 2.1.21+ (recommended)
OpenSSL 0.9.7+ (recommended)
Reentrant POSIX REGEX software (required)
SLAPD:
BDB and HDB backends require Oracle Berkeley DB 4.4, 4.5,
4.6, 4.7, or 4.8. It is highly recommended to apply the
patches from Oracle for a given release.
雖然雖然雖然雖然 Berkeley DB 最新版為最新版為最新版為最新版為 5.0.26,,,,但是是但是是但是是但是是以以以以 Berkeley DB-5.0.26 搭配搭配搭配搭配
Oenldap-2.4.21,,,,會導致無法編譯成功會導致無法編譯成功會導致無法編譯成功會導致無法編譯成功,,,,還是建議使用還是建議使用還是建議使用還是建議使用 Berkeley DB-4.5.20
Page 18
18
CLIENTS/CONTRIB ware:
Depends on package. See per package README.
========================================================
安裝 oracle Software Berkeley DB
http://www.oracle.com/technology/software/products/berkeley-db/index.html
[myLDAP]# fetch http://download.oracle.com/berkeley-db/db-4.5.20.tar.gz
[myLDAP]# tar zxvf db-4.5.20.tar.gz
[myLDAP]# cd db-4.5.20/build_unix
[myLDAP]# ../dist/configure
[myLDAP]# make
[myLDAP]# make install
[myLDAP]# cd /usr/source/openldap-2.4.21
[myLDAP]# env CPPFLAGS="-I/usr/local/BerkeleyDB.4.5/include" LDFLAGS="-L/usr/local/lib
-L/usr/local/BerkeleyDB.4.5/lib -R/usr/local/lib"
LD_LIBRARY_PATH="/usr/local/BerkeleyDB.4.5/lib" ./configure --enable-crypt --with-pam
上面 3 行為同一行指令
[myLDAP]# openldap-2.3.27]# make depend
[myLDAP]# openldap-2.3.27]# make
[myLDAP]# openldap-2.3.27]# make install
到此已經將 LDAP 安裝 到你的 OS 上了 下一步是要去做 LDAP 的設定
六六六六、、、、編輯編輯編輯編輯/usr/local/etc/openldap/slapd.conf/usr/local/etc/openldap/slapd.conf/usr/local/etc/openldap/slapd.conf/usr/local/etc/openldap/slapd.conf((((紅色字體紅色字體紅色字體紅色字體是需要加入或修改部分是需要加入或修改部分是需要加入或修改部分是需要加入或修改部分))))
LDAP openldap]# ee /usr/local/etc/openldap/slapd.conf
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include /usr/local/etc/openldap/schema/core.schema
Page 19
19
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/nis.schema
# Define global ACLs to disable default read access.
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral ldap://root.openldap.org
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
# Load dynamic backend modules:
# modulepath /usr/local/libexec/openldap
# moduleload back_bdb.la
# moduleload back_hdb.la
# moduleload back_ldap.la
# Sample security restrictions
# Require integrity protection (prevent hijacking)
# Require 112-bit (3DES or better) encryption for updates
# Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64
# Sample access control policy:
# Root DSE: allow anyone to read it
# Subschema (sub)entry DSE: allow anyone to read it
# Other DSEs:
# Allow self write access
# Allow authenticated users read access
# Allow anonymous users to authenticate
# Directives needed to implement policy:
#不讓匿名者存取
#(一定要保留底下幾行的 TAB 空格,這是 ACL 的格式,若不遵守,將導致 slapd 無法啟動)
access to attrs=userPassword
by self write
by anonymous auth
Page 20
20
by dn.base="cn=Manager,dc=myLDAP,dc=edu,dc=tw" write
by * none
access to *
by self write
by dn.base="cn=Manager,dc=myLDAP,dc=edu,dc=tw" write
by * none
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
# by self write
# by users read
# by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!
#######################################################################
# BDB database definitions
#######################################################################
database bdb
suffix "dc=myLDAP,dc=edu,dc=tw"
rootdn " cn=Manager,dc=myLDAP,dc=edu,dc=tw "
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw {CRYPT}kxvFbqTRndFBc
secret 是登入 LDAP 的管理者密碼 在這裡使用的是明碼(不安全)
建議到命令將密碼編碼
[myLDAP]# cp /usr/local/BerkeleyDB.4.5/lib/libdb-4.5.so /usr/lib
先執行此命令,不然會出現
/usr/local/sbin/slappasswd: error while loading shared libraries: libdb-4.5.so: cannot open shared object
file: No such file or directory 錯誤
Page 21
21
[myLDAP openldap]# /usr/local/sbin/slappasswd -v -u -s 123456 -h {crypt} -c '%1$8s'
在 FreeBSD 系統上需加入紅色字部分 指定密碼格式 /usr/local/sbin/slappasswd -v -u -s 123456 -h
{CRYPT} -c '%1$8s'
註: '%1$8s'表示會產生 $1$後接 8 字元的密碼格式,"123456"是你要用的的密碼
之後便會產生一組加密密碼 再將 {CRYPT}kxvFbqTRndFBc 複製到 rootpw 之後 變成
rootpw {CRYPT}kxvFbqTRndFBc
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory /usr/local/var/openldap-data
# Indices to maintain
index objectClass eq
上面這行的「eq」表示往後在搜尋 objectClass 屬性時,所要尋找的屬性必須要完全相等才符合搜尋的條
件,如 objectClass="abc" abc 代表屬性值「eq」還可以設成「sub」、「pres」、「approx」,若你將
index objectClass eq 改成 index objectClass sub,那就表示你可以使用如
objectClass="abc*" 的萬用字元 來尋找相關屬性,abc 代表屬性值
存檔離開~~~,測試 slapd 是否正常運作
[myLDAP]# /usr/local/libexec/slapd
[myLDAP]# ps auxw | grep slapd
root 69628 2.0 2.8 11324 6912 ?? Ss 2:56PM 0:00.18 /usr/local/libexec/slapd
root 69631 0.0 0.4 3492 948 0 S+ 2:56PM 0:00.02 grep slapd
先看看有沒有 slapd 正在執行,如果有請將該 process 刪除掉,如果沒則省略此一
步驟
[myLDAP openldap]# kill -9 8516
Page 22
22
重新啟動 slapd
[myLDAP]]# /usr/local/libexec/slapd
[myLDAP]# ps auxw | grep slapd
再檢查一次 slapd 有沒有執行,如果看不到如
root 69628 2.0 2.8 11324 6912 ?? Ss 2:56PM 0:00.18 /usr/local/libexec/slapd 的字樣,
則代表你的/usr/local/etc/openldap/slapd.conf 有設定上的錯誤,如語法錯誤
如果正常啟動的話,接下來就是要將帳號 DIT 匯入 LDAP 內的 BDB 資料庫
我們規劃的 DIT(Document information tree)大概長的像下面這個樣子...
uid=userx,ou=People,dc=LDAP,dc=edu,dc=edu 這一整串叫做 DN
ou=People 即是代表 dc=myLDAP,dc=edu,dc=tw(dc 代表 domain component)
下的的一個 RDN( Relative Distinguish Name) , 而 uid=userx 又是
ou=People,dc=LDAP,dc=edu,dc=edu 下的的一個 RDN( Relative Distinguish
Page 23
23
Name)
我們先得建立 ou=People 的 RDN 值
[myLDAP]# ee /usr/source/addOU.ldif
註:addOU 是由你自己設定的檔名,如果要複製以下的文字,必須小心紅色字的
說明部分
addOU.ldif 範例
ou=People,dc=myLDAP,dc=edu,ed=tw
dc=myLDAP,dc=edu,ed=tw
cn=Manager,dc=myLDAP,dc=edu,ed=tw
uid=user1,ou=People,dc=myLDAP,dc=edu,ed=tw
uid=user2,ou=People,dc=myLDAP,dc=edu,ed=tw
uid=user3,ou=People,dc=myLDAP,dc=edu,ed=tw
Page 24
24
version: 1
dn: dc=myLDAP,dc=edu,dc=tw
objectclass: dcObject
objectclass: organization
o: school
dc: MyLDAP
dn: cn=Manager,dc=myLDAP,dc=edu,dc=tw
objectclass: organizationalRole
cn: Manager
dn: ou=People,dc=myLDAP,dc=edu,dc=tw
objectClass: organizationalUnit
ou: People
version: 1 這行可以不要 不過值得把它列進去,「:」之後有一個空格
以下五行之間不得有空行,而且在每一行的最後一個字元,都不可帶有空白字元
dn: dc=myLDAP,dc=edu,dc=tw
objectclass: dcObject
objectclass: organization
o: school
dc: MyLDAP
這裡必需空一行(一定要一定要一定要一定要)
以下三行之間不得有空行,而且在每一行的最後一個字元,都不可帶有空白字元
dn: cn=Manager,dc=myLDAP,dc=edu,dc=tw
objectclass: organizationalRole
cn: Manager
這裡必需空一行(一定要一定要一定要一定要)
以下三行之間不得有空行,而且在每一行的最後一個字元,都不可帶有空白字元
Page 25
25
dn: ou=People,dc=LDAP,dc=edu,dc=tw
objectClass: organizationalUnit
ou: People
[myLDAP]# ldapadd -x -D "cn=Manager,dc=myLDAP,dc=edu,dc=tw" -f
/usr/source/addOU.ldif -w 123456
-x 表示使用 simple authentication
-D 代表 binding 到 cn=Manager,dc=myLDAP,dc=edu,dc=tw
-f 代表所要匯入的 LDIF 檔
-w(小寫) 之後 接 123456,也可以使用 –W(大寫),且後面空白,程式將會提醒
你輸入密碼
(123456 代表你在 /usr/local/etc/openldap/slapd.conf 中的 rootpw 密碼值)
如果成功匯入的話,會出現
adding new entry "dc=myLDAP,dc=edu,dc=tw"
adding new entry "cn=Manager,dc=myLDAP,dc=edu,dc=tw"
adding new entry "ou=People,dc=myLDAP,dc=edu,dc=tw"
不會出現任何的錯誤訊息。
若要刪除"dc=myLDAP,dc=edu,dc=tw"這筆 DN 值的方法
[myLDAP]# /usr/local/bin/ldapdelete -x -D "cn=Manager,dc=myLDAP,dc=edu,dc=tw" -w
123456 "dc=myLDAP,dc=edu,dc=tw"
[myLDAP]# ee /usr/source/user.ldif
Page 26
26
看看 user.ldif 檔的樣子
version: 1
dn: uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw
uid: user1
cn: user1
sn: SIRNAME
mail: [email protected]
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
userPassword: {crypt}$1$59327363$kGGOo8nxczmwgvb6YcLI41
shadowLastChange: 13418
loginShell: /bin/sh
uidNumber: 501
gidNumber: 501
homeDirectory: /home/user1
dn: uid=user2,ou=People,dc=myLDAP,dc=edu,dc=tw
uid: user2
cn: user2
sn: SIRNAME
mail: [email protected]
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
userPassword: {crypt}$1$59327363$kGGOo8nxczmwgvb6YcLI41
shadowLastChange: 13418
loginShell: /bin/sh
uidNumber: 502
gidNumber: 501
homeDirectory: /home/user2
dn: uid=user3,ou=People,dc=myLDAP,dc=edu,dc=tw
uid: user3
cn: user3
sn: SIRNAME
mail: [email protected]
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
userPassword: {crypt}$1$59327363$kGGOo8nxczmwgvb6YcLI41
shadowLastChange: 13418
loginShell: /bin/sh
uidNumber: 503
gidNumber: 501
homeDirectory: /home/user3
Page 27
27
LDAP 的 schema 可以到 http://ldap.akbkhome.com/index.php/objectclass.html 查
詢,以 user.ldif 為例,所引用到的 objectClass 有 person、organizationalPerson、
inetOrgPerson、posixAccount、posixAccount、shadowAccount,以 person 這個 objectClass
為例,從 http://ldap.akbkhome.com/index.php/objectclass/person.html 查詢到 user.ldif
中必須包含「cn」與「sn」的屬性,如果 user.ldif 中沒有將「cn」與「sn」的屬性
列進去,將 user.ldif 匯入到 LDAP 資料庫時就會出現 ldap_add: Object class violation
(65) additional info: object class 'person' requires attribute 'sn'的錯誤訊息。
dn: uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw
uid: user1
cn: user1
sn: SIRNAME
mail: [email protected]
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
userPassword: {crypt}$1$59327363$kGGOo8nxczmwgvb6YcLI41
{crypt}$1$59327363$kGGOo8nxczmwgvb6YcLI41 可從 FreeBSD 密碼檔中獲得
[myLDAP]# vipw
user1: $1$59327363$kGGOo8nxczmwgvb6YcLI41:1001:1001::0:0:User &:/home/biau:/bin/sh
shadowLastChange: 13418
Page 28
28
loginShell: /bin/sh
uidNumber: 501
gidNumber: 501
homeDirectory: /home/user1
ldif 檔的格式要求,可說是非常的嚴謹,許多無法將資料匯入的情形都是因為多
出空格或少了空格,還有斷行符號的問題,也會造成 LDIF 檔錯誤而無法匯入,
在底下的說明中,將會提到一些 LDIF 檔常發生的錯誤...
而 user.ldif 的 DN 都是在 ou=People,dc=myLDAP,dc=edu,dc=tw 之下所以我們將
/usr/source/user.ldif 餵給 LDAP server 吃
[myLDAP]# /usr/local/bin/ldapadd -x -D "cn=Manager,dc=myLDAP,dc=edu,dc=tw" -f
/usr/source/user.ldif -w 123456
你會看到一串,如下面的訊息「飛過去」...
adding new entry "uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"
adding new entry "uid=user2,ou=People,dc=myLDAP,dc=edu,dc=tw"
adding new entry "uid=user3,ou=People,dc=myLDAP,dc=edu,dc=tw"
測試以 anonymous 查詢 LDAP 的 DIT
[myLDAP]/usr/local/bin/ldapsearch -h 192.168.1.120 -b
"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"
受限於/usr/local/etc/openldap/slapd.conf 設定的 ACL(不讓匿名存取 DIT),無法查詢
到"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"相關的屬性
Page 29
29
# extended LDIF
#
# LDAPv3
# base <uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# search result
search: 2
result: 32 No such object
# numResponses: 1
測試以管理者登入查詢 LDAP 的 DIT
[myLDAP] /usr/local/bin/ldapsearch -h 192.168.1.120 -x -D
"cn=Manager,dc=myLDAP,dc=edu,dc=tw" -w 123456 -b
"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"
可以查詢到"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"相關的屬性
# extended LDIF
#
# LDAPv3
# base <uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# user1, People, myLDAP.edu.tw
dn: uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw
uid: user1
cn: user1
sn: SIRNAME
mail: [email protected]
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
userPassword:: e2NyeXB0fSQxJDU5MzI3MzYzJGtHR09vOG54Y3ptd2d2YjZZY0xJNDE=
shadowLastChange: 13418
loginShell: /bin/sh
uidNumber: 501
gidNumber: 501
homeDirectory: /home/user1
# search result
search: 2
result: 0 Success
Page 30
30
# numResponses: 2
# numEntries: 1
測試以"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"登入
"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"查詢 LDAP 的 uid=user1 的 RDN
[myLDAP] /usr/local/bin/ldapsearch -h 192.168.1.120 -x -D
"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw" -W -b
"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"
Enter LDAP Password:
輸入 user1 的密碼
user1 可以查詢到"uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw"自己相關的屬性
# extended LDIF
#
# LDAPv3
# base <uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# user1, People, myLDAP.edu.tw
dn: uid=user1,ou=People,dc=myLDAP,dc=edu,dc=tw
uid: user1
cn: user1
sn: SIRNAME
mail: [email protected]
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
userPassword:: e2NyeXB0fSQxJFIyQXBKTlV5JDN0NUVadzViV0gvbGsxVXJPZW1Ody4=
shadowLastChange: 13418
loginShell: /bin/sh
uidNumber: 501
gidNumber: 501
homeDirectory: /home/user1
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
Page 31
31
我們已經成功的將帳號建立到 LDAP server 上 BDB 資料庫中了,下一步,是要去
Moodle 裡面,設定認證方式....
八八八八、、、、MOODLEMOODLEMOODLEMOODLE 中文版安裝中文版安裝中文版安裝中文版安裝
安裝安裝安裝安裝 MYSQLMYSQLMYSQLMYSQL
[myLDAP]# adduser mysql 手動增加 mysql 的使用者與 mysql 群組
Username:mysql
:
:
[myLDAP]# cd /usr/source
[myLDAP]# fetch
http://www.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.48.tar.gz/from/http://mysql.c
s.pu.edu.tw/
[myLDAP]# mv fetch.out mysql-5.1.48.tar.gz
[myLDAP]# tar zxvf mysql-5.1.48.tar.gz
[myLDAP]# cd mysql-5.1.48
[myLDAP]# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-low-memory
[myLDAP]# make
[myLDAP]# make install
[myLDAP]# cp support-files/my-medium.cnf /etc/my.cnf
[myLDAP]# chown -R mysql /usr/local/mysql/.
[myLDAP]# chgrp -R mysql /usr/local/mysql/.
[myLDAP]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[myLDAP]# chown -R mysql /usr/local/mysql/var
[myLDAP]# /usr/local/mysql/share/mysql/mysql.server restart
[myLDAP]# /usr/local/mysql/bin/mysqladmin -u root password '123456'
設定 Mysql 管理者的密碼為 123456
Page 32
32
安裝安裝安裝安裝 APACHEAPACHEAPACHEAPACHE
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://ftp.stut.edu.tw/var/ftp/pub/OpenSource/apache/httpd/httpd-2.2.15.tar.gz
[myLDAP]# tar zxvf httpd-2.2.15.tar.gz
[myLDAP]# cd httpd-2.2.15
[myLDAP]# ./configure --prefix=/usr/local/apache2 --enable-shared=max
-enable-module=most --enable-so
[myLDAP]# make
[myLDAP]# make install
安裝安裝安裝安裝 zlibzlibzlibzlib、、、、libpnglibpnglibpnglibpng、、、、freetypefreetypefreetypefreetype、、、、jpegjpegjpegjpeg 函式函式函式函式、、、、GDGDGDGD 函式庫函式庫函式庫函式庫、、、、xmlxmlxmlxml 函式庫函式庫函式庫函式庫、、、、iconviconviconviconv 函式庫函式庫函式庫函式庫
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://zlib.net/zlib-1.2.5.tar.gz
[myLDAP]# tar zxvf zlib-1.2.5.tar.gz
[myLDAP]# cd zlib-1.2.5
[myLDAP]# ./configure
[myLDAP]# make
[myLDAP]# make install
[myLDAP]# cd /usr/source
[myLDAP]# fetch ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.4.3.tar.gz
[myLDAP]# tar zxvf libpng-1.4.3.tar.gz
[myLDAP]# cd libpng-1.4.3
[myLDAP]# ./configure
[myLDAP]# make
[myLDAP]# make install
Freetype2 需要 gmake 版本 >=3.81,需要更新 gmake
[myLDAP]# cd /usr/source
[myLDAP]# mv /usr/bin/make /usr/bin/make_old
[myLDAP]# fetch http://ftp.gnu.org/gnu/make/make-3.81.tar.gz
[myLDAP]# tar zxvf make-3.81.tar.gz
[myLDAP]# cd make-3.81
[myLDAP]# . ./configure --prefix=/usr/local/make
[myLDAP]# /usr/bin/make_old
[myLDAP]# /usr/bin/make_old install
[myLDAP]# ln -s /usr/local/make/bin/make /usr/bin/make
Page 33
33
[myLDAP]# cp -rp /usr/local/jpeg/lib/* /usr/lib
[myLDAP]# cp -rp /usr/local/jpeg/include/* /usr/include
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.3.12.tar.gz
[myLDAP]# tar zxvf freetype-2.3.12.tar.gz
[myLDAP]# cd freetype-2.3.12
[myLDAP]# ./configure
[myLDAP]# make
[myLDAP]# make install
[myLDAP]# cd /usr/source
[myLDAP]# fetch
ftp://ftp.uni-frankfurt.de/pub/Mirrors2/gentoo.org/distfiles/jpegsrc.v6b.tar.gz
[myLDAP]# tar zxvf jpegsrc.v6b.tar.gz
[myLDAP]#cd jpeg-6b
[myLDAP]#mkdir /usr/local/jpeg
[myLDAP]#mkdir /usr/local/jpeg/man
[myLDAP]#mkdir /usr/local/jpeg/man/man1
[myLDAP]#mkdir /usr/local/jpeg/bin
[myLDAP]#mkdir /usr/local/jpeg/lib
[myLDAP]#mkdir /usr/local/jpeg/include
[myLDAP]#./configure --prefix=/usr/local/jpeg --enable-shared
[myLDAP]#make
[myLDAP]#make install
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://www.libgd.org/releases/gd-2.0.35.tar.gz
[myLDAP]# tar zxvf gd-2.0.35.tar.gz
[myLDAP]#cd gd-2.0.35
[myLDAP]#./configure --with-freetype --with-jpeg=/usr/local/jpeg/include --with-png
[myLDAP]#make
[myLDAP]#make install
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://ftp.se.debian.org/pub/gnome/sources/libxml2/2.6/libxml2-2.6.30.tar.gz
[myLDAP]# tar zxvf libxml2-2.6.30.tar.gz
Page 34
34
[myLDAP]#cd libxml2-2.6.30
[myLDAP]#./configure
[myLDAP]#make
[myLDAP]#make install
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
[myLDAP]# tar zxvf libiconv-1.13.1.tar.gz
[myLDAP]# cd libiconv-1.13.1
[myLDAP]#./configure
[myLDAP]# make
[myLDAP]# make install
安裝安裝安裝安裝 PerlPerlPerlPerl,,,,APACHE2APACHE2APACHE2APACHE2 的的的的 apxsapxsapxsapxs,,,,需需需需要用到要用到要用到要用到 perlperlperlperl
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://www.cpan.org/src/perl-5.10.1.tar.gz
[myLDAP]# tar zxvf perl-5.10.1.tar.gz
[myLDAP]# cd perl-5.10.1
[myLDAP]# sh Configure -de
[myLDAP]# make
[myLDAP]# make test
[myLDAP]# make install
再重新編譯再重新編譯再重新編譯再重新編譯 APACHAPACHAPACHAPACHEEEE
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://ftp.stut.edu.tw/var/ftp/pub/OpenSource/apache/httpd/httpd-2.2.15.tar.gz
[myLDAP]# tar zxvf httpd-2.2.15.tar.gz
[myLDAP]# cd httpd-2.2.15
[myLDAP]# ./configure --prefix=/usr/local/apache2 --enable-shared=max
-enable-module=most --enable-so
Page 35
35
[myLDAP]# make
[myLDAP]# make install
安裝安裝安裝安裝 PHPPHPPHPPHP
[myLDAP]# cd /usr/source
[myLDAP]# fetch http://ftp.ntu.edu.tw/php/distributions/php-5.3.2.tar.gz
[myLDAP]# tar zxvf php-5.3.2.tar.gz
[myLDAP]# cd php-5.3.2
[myLDAP]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
--with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql --with-gd
--with-jpeg-dir=/usr/local/jpeg/include --with-zlib --with-libxml-dir=/usr/local --with-iconv
--with-pear --enable-zend-multibyte --with-ldap 如果你的 MOODLE 要加入 LDAP 認證方式 ./configure 之後還要在加入 ‘--with-ldap'參數 ,而且必須先完成安裝 LDAP,否則會出現找不到 ldap.h錯誤訊息,..
[myLDAP]# make
[myLDAP]# make install
[myLDAP]# cp php.ini-dist /usr/local/php/php.ini
[myLDAP]# ee /usr/local/apache2/conf/httpd.conf #AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php (加入這行)
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
Page 36
36
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi
# For type maps (negotiated resources):
#AddHandler type-map var
#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
</IfModule>
</Directory>
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.php (加入 index.php)
</IfModule>
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
啟動 apache
[myLDAP]# /usr/local/apache2/bin/apachectl start
安裝安裝安裝安裝 MOODLEMOODLEMOODLEMOODLE
[myLDAP]# cd /usr/source
Page 37
37
[myLDAP]# fetch http://www.sfr-fresh.com/unix/www/moodle-1.9.9.tar
[myLDAP]# tar zxvf moodle-1.9.9.tar
[myLDAP]# mv moodle /usr/local/apache2/htdocs/
[myLDAP]# mkdir /usr/local/apache2/moodledata
[myLDAP]# chmod 777 /usr/local/apache2/moodledata
建立建立建立建立 MOODLEMOODLEMOODLEMOODLE 資料庫資料庫資料庫資料庫
[myLDAP]# /usr/local/mysql/bin/mysql –u root –p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.48-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database moodle; (建立一個資料庫,名稱為”moodle”)
Query OK, 1 row affected (0.12 sec)
mysql>exit;
Bye
myLDAP#
Page 70
70
以上是主要的 MOODLE 以 LDAP 認證的設定選項,而其他欄位,在此暫時可以
Page 71
71
不設定,如果 MOODLE 採 LDAP 認證成功的話,將可以以/usr/source/user.ldif 檔
中的使用者帳號以及密碼登入。但是如果以 LDAP 認證失敗的話,請用下列方式
回復原先系統預設的 E-mail 認證方式。
方法一
在 phpmyadmin 後端 找到資料表: mdl_config
id 229 中
229 enrol_plugins_enabled manual,flatfile,ldap
把 ",ldap" 拿掉
或以 admin 登入 修改認證方式看看
方法二
如果不行的話 再到 mysql server 下
[myLDAP]# /usr/local/mysql/bin/mysql -u root –p123456 (123456 為進入 Mysql
的密碼)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.20
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use moodle; (切換到 MOODLE 所使用的資料庫)
mysql>update mdl_config set value = 'email' where name = 'auth';
mysql>exit;
[myLDAP]#
或用 phpMyAdmin 修改 mdl_config 的 name value
Page 72
72
到這裡為止,已經完成了 MOODLE,以 LDAP 做帳號的認證,在實做的過
程當中,發現 MOODLE_1.9.9 中文化的版本,以 LDAP 認證之後,使用者如果在
MOODLE 中修改自己的密碼,可以達到 LDAP 後端資料庫的密碼同步修改的效
果
Reference
1. 線上查詢 LDAP schema http://schemareg.daasi.de/cgi/w2l.schemareg
2. 線上查詢 LDAP schema http://ldap.akbkhome.com/index.php/objectclass.html
3. 介紹 LDAP 的網站 http://www.zytrax.com/books/ldap/ape/
4. OpenLDAP 的官方網站 http://www.openldap.org
Page 73
73
【修改 IP,不需重新開機】
在#後輸入 ifconfig,取得網卡代號,如下圖所示,取得的代號是「em0em0em0em0」
設定網路介面「em0em0em0em0」的 IP、網路遮罩、getway
# ifconfig em0 em0 em0 em0 down
# ifconfig em0 192.168.1.10 netmask 255.255.255.0
# route add default 192.168.1.254
add net default: getway 192.168.1.254
# ifconfig em0 up
#