| 1 |
lars |
1 |
Examples:
|
|
|
2 |
|
|
|
3 |
First of all connect to your server as usual. (Some servers require
|
|
|
4 |
authentication to get the Subschema entry)
|
|
|
5 |
|
|
|
6 |
$config = array( 'host' => 'localhost' );
|
|
|
7 |
$ldap = Net_LDAP2::connect( $config );
|
|
|
8 |
if( Net_LDAP2::isError( $ldap ) ) die ( $ldap->getMessage() )
|
|
|
9 |
|
|
|
10 |
Then we can get the schema.
|
|
|
11 |
|
|
|
12 |
$schema = $ldap->schema();
|
|
|
13 |
if( Net_LDAP2::isError( $schema ) ) die ( $schema->getMessage() );
|
|
|
14 |
|
|
|
15 |
You can give a parameter to $ldap->schema() which sets the Subschema Entry dn.
|
|
|
16 |
If it is omitted, the entry dn will be fetched internally via rootDSE().
|
|
|
17 |
If that fails it will be set to "cn=Subschema".
|
|
|
18 |
|
|
|
19 |
$schema = $ldap->schema( 'cn=Subschema' );
|
|
|
20 |
|
|
|
21 |
Now you can work with the schema and retrieve information:
|
|
|
22 |
|
|
|
23 |
$attrs = $schema->getAll( 'attributes' );
|
|
|
24 |
|
|
|
25 |
This returns an array with all attributes and their information such as syntax,
|
|
|
26 |
equality, max_length etc. Look at the returned array to see what information was
|
|
|
27 |
passed.
|
|
|
28 |
|
|
|
29 |
Valid options to getAll() are:
|
|
|
30 |
|
|
|
31 |
objectclasses
|
|
|
32 |
attributes
|
|
|
33 |
ditcontentrules
|
|
|
34 |
ditstructurerules
|
|
|
35 |
matchingrules
|
|
|
36 |
matchingruleuses
|
|
|
37 |
nameforms
|
|
|
38 |
syntaxes
|
|
|
39 |
|
|
|
40 |
If you know the the name of an attribute or objectclass you can get the
|
|
|
41 |
information directly.
|
|
|
42 |
|
|
|
43 |
$attr = $schema->get('attribute', 'userPassword');
|
|
|
44 |
$oc = $schema->get('objectclass', 'posixAccount');
|
|
|
45 |
|
|
|
46 |
The first parameter determines the type of entry to be fetched and can be one
|
|
|
47 |
of:
|
|
|
48 |
|
|
|
49 |
attribute
|
|
|
50 |
ditcontentrule
|
|
|
51 |
ditstructurerule
|
|
|
52 |
matchingrule
|
|
|
53 |
matchingruleuse
|
|
|
54 |
nameform
|
|
|
55 |
objectclass
|
|
|
56 |
syntax
|
|
|
57 |
|
|
|
58 |
The second parameter can be the name or the oid of the entry.
|
|
|
59 |
|
|
|
60 |
You can retrieve a list of required and optional attributes of an object class
|
|
|
61 |
via must( $oc ) or may( $oc ). Both return a list of attributes in an array.
|
|
|
62 |
|
|
|
63 |
$required = $schema->must( 'posixAccount' );
|
|
|
64 |
$optional = $schema->may( 'posixAccount' );
|