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 => "[email protected]"
}
Net::LDAP.open (:host => host) do |ldap|
ldap.add( :dn => dn, :attributes => attr )
end
792 793 794 795 796 797 798 799 800 801 802 803 804 |
# File 'lib/net/ldap.rb', line 792 def add args if @open_connection @result = @open_connection.add( args ) else @result = 0 conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption) if (@result = conn.bind( args[:auth] || @auth )) == 0 @result = conn.add( args ) end conn.close end @result == 0 end |