Method: Net::LDAP#add

Defined in:
lib/net/ldap.rb

#add(args) ⇒ Object

Adds a new entry to the remote LDAP server. Supported arguments:

:dn

Full DN of the new entry

:attributes

Attributes of the new entry.

The attributes argument is supplied as a Hash keyed by Strings or Symbols giving the attribute name, and mapping to Strings or Arrays of Strings giving the actual attribute values. Observe that most LDAP directories enforce schema constraints on the attributes contained in entries. #add will fail with a server-generated error if your attributes violate the server-specific constraints.

Here’s an example:

dn = "cn=George Smith, ou=people, dc=example, dc=com"
attr = {
  :cn => "George Smith",
  :objectclass => ["top", "inetorgperson"],
  :sn => "Smith",
  :mail => "gsmith@example.com"
}
Net::LDAP.open(:host => host) do |ldap|
  ldap.add(:dn => dn, :attributes => attr)
end
[View source]

964
965
966
967
968
969
970
971
# File 'lib/net/ldap.rb', line 964

def add(args)
  instrument "add.net_ldap", args do |payload|
    @result = use_connection(args) do |conn|
      conn.add(args)
    end
    @result.success?
  end
end