日本語を使用する

LDAPのデータとして日本語を使用する場合の記述法について説明する.

プロトコル上の日本語の扱い

LDAPString

RFC2251 Lightweight Directory Access Protocol (v3)で, 次のようにLDAPStringが定義されている.

4.1.2. String Types

   The LDAPString is a notational convenience to indicate that, although
   strings of LDAPString type encode as OCTET STRING types, the ISO
   10646 [13] character set (a superset of Unicode) is used, encoded
   following the UTF-8 algorithm [14]. 

        LDAPString ::= OCTET STRING

属性型で使用できる文字集合

属性型は上記のLDAPStringを使用する.

上の定義より,ISO 10646文字集合のすべての文字が使えるように見えるが, 実際には下に示すように制限がある.

RFC2251 Lightweight Directory Access Protocol (v3)より抜粋

4.1.4. Attribute Type

        AttributeType ::= LDAPString


   A specification may also assign one or more textual names for an
   attribute type.  These names MUST begin with a letter, and only
   contain ASCII letters, digit characters and hyphens.  They are case
   insensitive.  (These ASCII characters are identical to ISO 10646
   characters whose UTF-8 encoding is a single byte between 0x00 and
   0x7F.)

属性値で使用できる文字集合・エンコーディング

属性値に関しては,RFC2251上は,4.1.6. Attribute Valueにおいて,

        AttributeValue ::= OCTET STRING
と定めているだけである. というのも, 属性値は,その属性の定義により使用できる文字集合やエンコーディングなどが決まってくるため, プロトコル上の定義はできないのである.

以下,いくつかの属性について,日本語の扱いがどうなっているかを見ていく.

cn

cnはRFC2256において,
5.4. cn

   This is the X.500 commonName attribute, which contains a name of an
   object.  If the object corresponds to a person, it is typically the
   person's full name.

    ( 2.5.4.3 NAME 'cn' SUP name )
と定義されている.

これより,cnはnameクラスのサブクラスであることがわかるので,nameの定義を見てみると, 同じくRFC2256で,

5.42. name

    ( 2.5.4.41 NAME 'name' EQUALITY caseIgnoreMatch
      SUBSTR caseIgnoreSubstringsMatch
      SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )
と定義されている.

ここで定義されているSYNTAX 1.3.6.1.4.1.1466.115.121.1.15は何かというと, RFC2252中で次のように定義されている.

6.10. Directory String

   ( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )

   A string in this syntax is encoded in the UTF-8 form of ISO 10646 (a
   superset of Unicode).  Servers and clients MUST be prepared to
   receive encodings of arbitrary Unicode characters, including
   characters not presently assigned to any character set.

これより,cn属性の値には,ISO 10646文字集合をUTF-8エンコードしたものが使用できることがわかる.

その他の属性

sn,c,l,st,o,ou,titleといった各属性はいずれもnameのサブクラスなので,cnと同様にISO 10646文字集合をUTF-8エンコードしたものが使用できる.

DNで使用できる文字集合・エンコーディング

DNはRDN(Relative Distinguished Name)を「,」で区切って並べたものであり,RDNは,属性型と属性値を「=」で並べたものであるので, 属性型と属性値における日本語の扱いにのっとる.

LDIFファイル上の日本語の扱い

RFC2849 The LDAP Data Interchange Format (LDIF) - Technical Specification で,日本語の扱いに関する部分には以下のようなものがある.

      4)  Any dn or rdn that contains characters other than those
          defined as "SAFE-UTF8-CHAR", or begins with a character other
          than those defined as "SAFE-INIT-UTF8-CHAR", above, MUST be
          base-64 encoded.  Other values MAY be base-64 encoded.  Any
          value that contains characters other than those defined as
          "SAFE-CHAR", or begins with a character other than those
          defined as "SAFE-INIT-CHAR", above, MUST be base-64 encoded.
          Other values MAY be base-64 encoded.


      7)  Distinguished names, relative distinguished names, and
          attribute values of DirectoryString syntax MUST be valid UTF-8
          strings.  Implementations that read LDIF MAY interpret files
          in which these entities are stored in some other character set
          encoding, but implementations MUST NOT generate LDIF content
          which does not contain valid UTF-8 data.
なお,この中で述べられているSAFE-UTF8-CHAR等は,同じRFCの中で,以下のように定義されている, と書こうと思ったら,SAFE-UTF8-CHARとSAFE-INIT-UTF8-CHARは定義されていなかった・・・.
SAFE-CHAR                = %x01-09 / %x0B-0C / %x0E-7F
                           ; any value <= 127 decimal except NUL, LF,
                           ; and CR

SAFE-INIT-CHAR           = %x01-09 / %x0B-0C / %x0E-1F /
                           %x21-39 / %x3B / %x3D-7F
                           ; any value <= 127 except NUL, LF, CR,
                           ; SPACE, colon (":", ASCII 58 decimal)
                           ; and less-than ("<" , ASCII 60 decimal)

これらより,LDIFファイルに日本語を記述する場合には,ISO 10646文字集合をUTF-8エンコードした上で, base64エンコードして記述する必要があることがわかる.

ただし,上記の7)の後半部分より,実装によっては,UTF-8エンコードをbase64エンコードするというエンコード以外の エンコードにも対応しているかもしれない.

OpenLDAPの実装上の日本語の扱い

OpenLDAPは,上で述べた仕様はきちんと満たしているようである.

さらに,LDIFファイルに日本語を記述する際には,わざわざbase64エンコードしなくても,そのままUTF-8エンコーディングの文字列を記述するだけできちんと認識してくれる. 一度そのようなLDIFファイルを読み込んだ後にslapcat(8)コマンドでデータベースの内容をダンプさせると,きちんとbase64エンコードされた状態となる.


← 新しいschemaの定義   ↑ 目次   アクセス制御 →


桑山雅行(CACAnet福岡)