When working with OpenLDAP operations, encountering an "Invalid syntax (21)" error during ldapadd
typically indicates schema validation issues. The key error message objectClass: value #0 invalid per syntax
specifically points to problems with object class definitions in your LDIF file.
Based on the provided LDIF and error message, several potential issues emerge:
1. Missing required schema definitions (posixGroup, inetOrgPerson, etc.)
2. Incorrect DN references between entries
3. Schema loading order problems
4. Missing auxiliary objectClass dependencies
The immediate solution requires verifying that all necessary schemas are loaded. For the given LDIF containing posixGroup
, inetOrgPerson
, and shadowAccount
, you must ensure these schemas are active:
# Check loaded schemas
ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config dn
# Typical required schemas:
# core.schema
# cosine.schema
# nis.schema (for posix* objectClasses)
# inetorgperson.schema
Here's how to properly configure your OpenLDAP server:
# 1. Load required schemas if missing
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif
# 2. Verify schema loading order in slapd.conf
# Ensure nis.schema loads after core.schema
Here's an improved version of your LDIF with proper structural elements:
dn: ou=People,dc=example,dc=com
objectClass: top
objectClass: organizationalUnit
ou: People
dn: ou=Groups,dc=example,dc=com
objectClass: top
objectClass: organizationalUnit
ou: Groups
dn: cn=engineers,ou=Groups,dc=example,dc=com
objectClass: top
objectClass: posixGroup
cn: engineers
gidNumber: 5000
dn: uid=john,ou=People,dc=example,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: john
sn: Doe
givenName: John
cn: John Doe
displayName: John Doe
uidNumber: 10000
gidNumber: 5000
userPassword: {CRYPT}x
gecos: John Doe
loginShell: /bin/bash
homeDirectory: /home/john
Use these commands to verify your schema setup:
# Check objectClass definitions
ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config \
'(objectClass=olcSchemaConfig)' dn
# Verify specific objectClass attributes
ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config \
'(cn={1}nis)' objectClasses
If issues persist, enable debug logging:
# In slapd.conf
loglevel 256
# Or dynamically:
ldapmodify -Y EXTERNAL -H ldapi:/// <
When working with OpenLDAP, one of the most frustrating errors beginners encounter is the "Invalid syntax (21)" error during ldapadd
operations. The error message specifically indicates an issue with objectClass validation, which typically means:
- The schema definitions are missing or not loaded
- The objectClass hierarchy isn't properly defined
- Required attributes for the objectClass are missing
In your example, you're using several objectClasses that require specific schema files:
# Core schemas needed:
dn: cn=cosine,cn=schema,cn=config
dn: cn=nis,cn=schema,cn=config
dn: cn=inetorgperson,cn=schema,cn=config
First, check which schemas are actually loaded in your OpenLDAP server:
ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b cn=config cn=schema
If you don't see cosine.schema
, nis.schema
, and inetorgperson.schema
in the output, you'll need to load them.
For Ubuntu/Debian systems, schemas are typically in /etc/ldap/schema/
. To add missing schemas:
# Create an LDIF file (add_schema.ldif):
dn: cn=nis,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: nis
olcAttributeTypes: {0}( 1.3.6.1.1.1.1.0 NAME 'gidNumber' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
olcObjectClasses: {0}( 1.3.6.1.1.1.2.0 NAME 'posixGroup' SUP top STRUCTURAL MUST ( cn $ gidNumber ) MAY ( userPassword $ memberUid $ description ) )
# Then load it:
ldapadd -Y EXTERNAL -H ldapi:/// -f add_schema.ldif
If you're using the default Ubuntu OpenLDAP package, consider including these schemas in your slapd.conf or cn=config:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/nis.schema
include /etc/ldap/schema/inetorgperson.schema
Here's a verified LDIF that works with properly configured schemas:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People
dn: ou=Groups,dc=example,dc=com
objectClass: organizationalUnit
ou: Groups
dn: cn=engineers,ou=Groups,dc=example,dc=com
objectClass: posixGroup
cn: engineers
gidNumber: 5000
dn: uid=john,ou=People,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
uid: john
sn: Doe
givenName: John
cn: John Doe
uidNumber: 10000
gidNumber: 5000
homeDirectory: /home/john
loginShell: /bin/bash