// 掛載外部資源用
yum install nfs-utils -y
//compile check 用
yum install gcc -y
yum install openldap openldap-servers openldap-clients openldap-devel compat-openldap -y
用 slapd.conf 的方式已棄用,參考
http://www.thegeekstuff.com/2015/01/openldap-linux/
直接修改
/etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif
(但是裡面建議要用 ldapmodify , 不要直接改, 裡面有 CRC32
把 olcRootDN 跟 olcSuffix 改掉
然後用 ldappasswd 產生新密碼 在後面多加一行
olcRootPW: {SSHA}ooxxooxx <--剛剛產生的
然後測試
slaptest -u
會抱怨 CRC 不對
5a0e8ba7 ldif_read_file: checksum error on "/etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif"
參考 https://gist.github.com/Shaltz/1d65a07a0901a36fb7f1
到
http://freecode.com/projects/checkcrc/ 下 check-4.3-src.tgz
用 tar xvf 解開 (雖然副檔名是 tgz 但是其實好像是 tar 而已)
下 zlib-devel
yum install zlib-devel -y
然後
# cd check-4.3
check4-3# gcc -O3 -Wall -DUSE_ZLIB -I/usr/include -o check check.c -L/usr/lib64 -lz
cp /etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif /tmp
tail -n +3 /tmp/olcDatabase={2}hdb.ldif > fixed.ldif
./check /tmp/fixed.ldif
fixed.ldif CRC-32 = 61e6182a, size = 582 bytes
把算好的值填回原本的檔案
# vi /etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif
AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
CRC32 61e6182a
再跑測試
[root@localhost ~]# slaptest -u
config file testing succeeded
#service slapd start
ldapsearch -x -b "o=XXXXX,c=XX"
# extended LDIF
#
# LDAPv3
# base <o=vghtc,c=tw> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# search result
search: 2
result: 32 No such object
# numResponses: 1
####
防火牆
參考
CentOS 7 以後用 Firewalld , 不用 iptables
[root@localhost worktmp]# cat /usr/lib/firewalld/services/ldap.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>LDAP</short>
<description>Lightweight Directory Access Protocol (LDAP) server</description>
<port protocol="tcp" port="389"/>
</service>
[root@localhost worktmp]# firewall-cmd --add-service=ldap --permanent
success
[root@localhost worktmp]# firewall-cmd --reload
success
用 olc 的方式自訂 schema
http://www.zytrax.com/books/ldap/ch6/slapd-config.html#use-schemas
自訂的時候
*****************問題**********************
5a0eacd5 /etc/openldap/schema/00001.schema: line 21 attributetype: AttributeType inappropriate matching rule: "1.3.6.1.4.1.1466.109.114.1"
*******************************************
attributetype ( 1.3.6.1.4.1.9883.1001.1.2.1 NAME 'user' DESC 'User Name of FTO M2 System' SUP 2.5.4.41 EQUALITY 2.5.13.2 ORDERING 2.5.13.3 SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.9883.1001.1.2.2 NAME 'gp' DESC 'Group Name of FTO M2 System' SUP 2.5.4.41 EQUALITY 2.5.13.2 ORDERING 2.5.13.3 SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.9883.1001.1.2.3 NAME 'firstName' SUP 2.5.4.41 EQUALITY 2.5.13.2 ORDERING 2.5.13.3 SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.9883.1001.1.2.4 NAME 'lastName' SUP 2.5.4.41 EQUALITY 2.5.13.2 ORDERING 2.5.13.3 SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.9883.1001.1.2.5 NAME 'loginCount' EQUALITY 2.5.13.14 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.9883.1001.1.2.6 NAME 'lastLoginTime' EQUALITY 2.5.13.27 ORDERING 2.5.13.28 SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.9883.1001.2.2.1 NAME 'prop' DESC 'Extended attribute values of FTO M2 System' EQUALITY 1.3.6.1.4.1.1466.109.114.1 SUBSTR 1.3.6.1.4.1.1466.109.114.1 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{20000} )
attributetype ( 1.3.6.1.4.1.9883.1001.2.2.2 NAME 'pn' DESC 'Permission name of FTO M2 SYSTEM' SUP 2.5.4.41 EQUALITY 1.3.6.1.4.1.1466.109.114.1 SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.9883.1001.2.2.3 NAME 'permissionIDs' DESC 'The DN of a permission.' SUP 2.5.4.49 )
紅字的部分會炸掉
改成這樣
attributetype ( 1.3.6.1.4.1.9883.1001.2.2.1
NAME 'prop'
DESC 'Extended attribute values of FTO M2 System'
EQUALITY 2.5.13.5
SUBSTR 2.5.13.7
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{20000} )
attributetype ( 1.3.6.1.4.1.9883.1001.2.2.2
NAME 'pn'
DESC 'Permission name of FTO M2 SYSTEM'
SUP 2.5.4.41
EQUALITY 2.5.13.5
SINGLE-VALUE )
根據 這個 https://www.ldap.com/ldap-oid-reference
1.3.6.1.4.1.1466.109.114.1: caseExactIA5Match (RFC 4517)
1.3.6.1.4.1.1466.115.121.1.15: Directory String (RFC 4517)
根據這個 https://lists.clug.org.za/pipermail/clug-tech/2005-January/021211.html
--
I just noticed on
http://www.openldap.org/doc/admin21/guide.html
that IA5... pertains to ASCII!
directoryString 1.3.6.1.4.1.1466.115.121.1.15 UTF-8 string
IA5String 1.3.6.1.4.1.1466.115.121.1.26 ASCII string
--
根據 這個 http://www.openldap.org/doc/admin24/schema.html
[ "SUBSTR" woid ] ; Matching Rule name
[ "SYNTAX" whsp noidlen whsp ] ; Syntax OID
[ "EQUALITY" woid ; Matching Rule name
所以根據這個 http://www.openldap.org/doc/admin21/guide.html#Extending Schema
caseExactIA5Match (case sensitive, space insensitive)
好像應該要換成
caseExactMatch (case sensitive, space insensitive)
查 https://www.ldap.com/ldap-oid-reference 知
2.5.13.5: caseExactMatch (RFC 4517)
2.5.13.7: caseExactSubstringsMatch (RFC 4517)
把 EQUALITY 改成 2.5.13.5 , SUBSTR 改成 2.5.13.7
*************************************問題***************************
AttributeType not found: "javaClassName"
*************************************
這個其實在 java.schema 裡面 , 測試的時候可以用 slapd.conf 先拉進來
不過好像也可以直接把定義抄到自己的 schema file 裡
另外還會缺的東西有
isAccountEnabled , fullName 先從原本那台的定義檔抄過來
測試方式
寫一個 slapd.conf 裡面放
include /etc/openldap/schema/My.schema 之類的
然後 mkdir testDIR
然後用 slaptest
slaptest -f slapd.conf -F testDIR/
就會測試 然後轉 ok 的話就會把 LDIF 生在 testDIR/
參考這個 http://www.zytrax.com/books/ldap/ch6/slapd-config.html#use-schemas
要加 schame 的 LDIF 進去的話 因為要改 cn=config , 要這樣加
ldapadd -Y EXTERNAL -H ldapi:/// -f r3.ldif
不然還是會說權限不夠
--
http://idmoim.blogspot.tw/2014/05/ldapadd-insufficient-access-50-openldap.html
這篇是說直接去改 config.ldif 可是還是需要足夠的權限
--
加完這樣查
ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config
加使用者設定檔進去
ldapadd -x -D '{RootDN}' -w {RootPW} -H ldapi:/// -f u01.ldif
********************問題**********************
adding new entry "cn=administrator,ou=users,o=XXXXX,c=XX"
ldap_add: Invalid syntax (21)
additional info: isaccountenabled: value #0 invalid per syntax
http://speeves.erikin.com/2007/01/openldap-booleanmatch-values-truefalse.html
The boolean values (TRUE/FALSE) in the LDIF file need to be UPPERCASE
**********************************************
整團加進去
ldapadd -x -D '{RootDN}' -w {RootPW} -H ldapi:/// -f group.ldif
整團砍掉 ( 加 -r ) <-- 會連頭一起砍掉
ldapdelete -x -r -D '{RootDN}' -w {RootPW} -H ldapi:/// "ou=groups, o=XXXXX,c=XX"
-----------------------------------------------
不加 -r 的話要從底下開砍 不然會
ldap_delete: Operation not allowed on non-leaf (66)
additional info: subordinate objects must be deleted first
--------------------------------------------------
***************************問題******************
description::
description:
定義上預期要有 description::
所以 LDIF 裡面碰到的是 description: 的話會炸掉
--先用 SED 處理
************************************************
lsaccountenabled 找不到?
沒有加 booleanMatch ?
-------------------------------------------
查詢RFC
[RFC4519] https://tools.ietf.org/html/rfc4519#section-2.5
Lightweight Directory Access Protocol (LDAP):Schema for User Applications
The 'description' attribute type contains human-readable descriptive
phrases about the object. Each description is one value of this
multi-valued attribute.
(Source: X.520 [X.520])
( 2.5.4.13 NAME 'description'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
1.3.6.1.4.1.1466.115.121.1.15 refers to the Directory String syntax
[RFC4517].
Examples: "a color printer", "Maintenance is done every Monday, at
1pm.", and "distribution list for all technical staff".
[RFC4517 ] https://docs.ldap.com/specs/rfc4517.txt
3.3.6. Directory String
A value of the Directory String syntax is a string of one or more
arbitrary characters from the Universal Character Set (UCS) [UCS]. A
zero-length character string is not permitted. The LDAP-specific
encoding of a value of this syntax is the UTF-8 encoding [RFC3629] of
the character string. Such encodings conform to the following ABNF:
DirectoryString = 1*UTF8
The <UTF8> rule is defined in [RFC4512].
Example:
This is a value of Directory String containing #!%#@.
Servers and clients MUST be prepared to receive arbitrary UCS code
points, including code points outside the range of printable ASCII
and code points not presently assigned to any character.
Attribute type definitions using the Directory String syntax should
not restrict the format of Directory String values, e.g., by
requiring that the character string conforms to specific patterns
described by ABNF. A new syntax should be defined in such cases.
The LDAP definition for the Directory String syntax is:
( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )
This syntax corresponds to the DirectoryString parameterized ASN.1
type from [X.520].
The DirectoryString ASN.1 type allows a choice between the
TeletexString, PrintableString, or UniversalString ASN.1 types from
[ASN.1]. However, note that the chosen alternative is not indicated
in the LDAP-specific encoding of a Directory String value.
Implementations that convert Directory String values from the LDAP-
specific encoding to the BER encoding used by X.500 must choose an
alternative that permits the particular characters in the string and
must convert the characters from the UTF-8 encoding into the
character encoding of the chosen alternative. When converting
Directory String values from the BER encoding to the LDAP-specific
encoding, the characters must be converted from the character
encoding of the chosen alternative into the UTF-8 encoding. These
conversions SHOULD be done in a manner consistent with the Transcode
step of the string preparation algorithms [RFC4518] for LDAP.
------------------------------------
http://www.zytrax.com/books/ldap/apc/rfc4512.txt
<numericoid> is object identifier assigned to this attribute type;
NAME <qdescrs> are short names (descriptors) identifying this
attribute type;
DESC <qdstring> is a short descriptive string;
OBSOLETE indicates this attribute type is not active;
SUP oid specifies the direct supertype of this type;
EQUALITY, ORDERING, and SUBSTR provide the oid of the equality,
ordering, and substrings matching rules, respectively;
SYNTAX identifies value syntax by object identifier and may suggest
a minimum upper bound;
SINGLE-VALUE indicates attributes of this type are restricted to a
single value;
COLLECTIVE indicates this attribute type is collective
[X.501][RFC3671];
NO-USER-MODIFICATION indicates this attribute type is not user
modifiable;
USAGE indicates the application of this attribute type; and
<extensions> describe extensions.
Each attribute type description must contain at least one of the SUP
or SYNTAX fields. If no SYNTAX field is provided, the attribute type
description takes its value from the supertype.
--------------------------------------------
用 ldapmodify 會把整個砍掉(?
Don't use replace, that will delete all the values. Use delete/add of the specific value.
ldapmodify -b cn={12}uri,cn=schema,cn=config
changetype: modify
delete: olcObjectClasses
olcObjectClasses: {7}
-
add: olcObjectClasses
olcObjectClasses: {7}(1.3.6.1.4.1.14092...
http://www.openldap.org/lists/openldap-technical/201408/msg00041.html
-------------------------------------------------------------
isAccountEnabled 加上 EQUALITY 2.5.13.13
依據 https://docs.ldap.com/specs/rfc4517.txt
( 2.5.13.13 NAME 'booleanMatch'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )
------------------------------------------------------------------------
修改的方式
參考 https://serverfault.com/questions/659928/how-to-change-openldap-core-attributes
dn: cn={1}vghtc,cn=schema,cn=config
changetype: modify
delete: olcAttributeTypes
olcAttributeTypes: {10}( 1.3.18.0.2.4.726 NAME 'isAccountEnabled' DESC 'indica
tes whether users are allowed to login using an account (true) or not (false)
' SYNTAX 1.3.6.1.4.1.1466.115.121.1.7{5} SINGLE-VALUE )
-
add: olcAttributeTypes
olcAttributeTypes: {10}( 1.3.18.0.2.4.726 NAME 'isAccountEnabled' DESC 'indi
cates whether users are allowed to login using an account (true) or not (fa
lse)' EQUALITY 2.5.13.13 SYNTAX 1.3.6.1.4.1.1466.115.121.1.7{5} SINGLE-VALU
E )
存成 modify001.ldif 然後
ldapmodify -QY EXTERNAL -H ldapi:/// -f modify001.ldif
然後用
ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config
查看看
***************************問題*******************************
ldapadd -QY EXTERNAL -H ldapi:/// -f r0.ldif
adding new entry "o=XXXXX,c=XX"
ldap_add: Insufficient access (50)
additional info: no write access to parent
改用
ldapadd -x -W -D "cn=root,o=XX,c=XX" -f r0.ldif
Enter LDAP Password:
adding new entry "o=XXXXX,c=XX"
***************************************************************
****************************問題*******************************
description: 格式不合
依據定義檔, description 是 Directory String 不允許空白.
( ITDS 是怎麼允許它過的? 應該有什麼覆寫吧)
所以 description: 是空的會被擋下來
先不管怎麼覆寫 用SED 全都改成新值好了
--然後用 grep 比對不到, 原來是我的匯出檔是 dos format ,
用 0A0D (CRLF) 換行
-- 用 hexdump (要另外裝) 可以把 hex dump 出來看
然後發現字碼好像是小端序(?
--用 dos2unix 這個工具轉掉就好了 (要另外裝
dos2unix -k -n 原檔名 新檔名
-k 代表保持原本時間戳
-n 代表把改完的檔案另寫新檔 不然會直接在舊的上面改
******************************************************************
isAccountEnabled 可以 SEARCH 了,不過要用 TRUE / FALSE
[ RFC2252 ] https://www.ietf.org/rfc/rfc2252.txt
Boolean
( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )
Values in this syntax are encoded according to the following BNF:
boolean = "TRUE" / "FALSE"
Boolean values have an encoding of "TRUE" if they are logically true,
and have an encoding of "FALSE" otherwise.
ITDS 似乎是 case-insensitive 的 = =
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
整理一下要匯入 LDIF 要留意的事
1. 根要先建,建根的時候要 bind RootDN 進去不然權限不夠
2. resource , group , users 不要用 ITDS dump 的,那會帶一堆 ITDS 參數
用 LBE 匯出。匯出後要用 dos2unix 把 CRLF 抓掉
3. 抓掉 CRLF 之後用 grep 找 ": $" 空值結尾的,如果是description 這類定義成 Directory String 的就一定要給值
4. 把 isAccountEnabled 這類的 Boolean 值從 true / false 換成 TRUE / FALSE
(Ref:RFC)
--
schema_init.c:1648:booleanMatch
這邊的實作怎麼好像看起來跟實際動作不一樣?
--
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
在建SERVER時要注意的事
先用標配安裝好
然後建 db , 改 RootDN , RootPW , suffix 然後用 check 改 CRC32 填回去
vim /etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif
**
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
這不知要做啥
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
=====================================================
REF :
https://docs.ldap.com/specs/rfc4517.txt RFC4517 ,
定義
Matching Rule
查這個比較方便(?
https://www.iana.org/assignments/ldap-parameters/ldap-parameters.xhtml