File: misc1.rb

package info (click to toggle)
ruby-ldap 0.9.20-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 452 kB
  • sloc: ansic: 4,097; ruby: 1,525; makefile: 5
file content (49 lines) | stat: -rw-r--r-- 974 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- ruby -*-

$test = File.dirname($0)
require "#{$test}/conf"
require "./ldap"

def admin_bind
  @ldap_conn.bind("cn=root, dc=localhost, dc=localdomain", 'secret')
end

#test method goes here

def add_ou(agency)
  #creates an organizational unit and places an agency inside
  begin
    entry = {
      'objectclass' => ['organizationalUnit'],
      'ou'          => [agency]
    }
    admin_bind.add("ou=#{entry['ou'][0]}, dc=localhost, dc=localdomain", entry)
    return(true)
  rescue LDAP::ResultError => error
    return(false)
  end
end

def delete_ou(agency)
  #removes an agency organizational unit
  begin
    admin_bind.delete("ou=#{agency}, dc=localhost, dc=localdomain")
    return(true)
  rescue LDAP::ResultError => error
    return(false)
  end
end

@ldap_conn = LDAP::Conn.new($HOST, $PORT)

p LDAP::VERSION
begin
  (1..1000).each do |count|
    p count
    p add_ou("an_agency")
    p delete_ou("an_agency")
  end
rescue LDAP::Error
  exit(0)
end
exit(1)