File: usermod-binary-add-time

package info (click to toggle)
ruby-activeldap 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,588 kB
  • sloc: ruby: 18,143; sh: 12; makefile: 5
file content (54 lines) | stat: -rwxr-xr-x 1,217 bytes parent folder | download | duplicates (6)
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
50
51
52
53
54
#!/usr/bin/ruby

base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH << File.join(base, "lib")
$LOAD_PATH << File.join(base, "examples")

require 'active_ldap'
require 'objects/user'
require 'objects/group'

argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
  opts.banner += " USER_NAME CN UID"
end

if argv.size == 3
  name, cn, uid = argv
else
  $stderr.puts opts
  exit 1
end

pwb = Proc.new do |user|
  ActiveLdap::Command.read_password("[#{user}] Password: ")
end

ActiveLdap::Base.setup_connection(:password_block => pwb,
                                  :allow_anonymous => false)

unless User.exists?(name)
  $stderr.puts("User #{name} doesn't exist.")
  exit 1
end

100.times do |i|
  user = User.find(name)
  user.cn = cn
  user.uid_number = uid
  user.gid_number = uid

  user.add_class('strongAuthenticationUser')
  cert_file = File.join(File.dirname(__FILE__), 'example.der')
  File.open(cert_file) do |input|
    input.set_encoding("ascii-8bit") if input.respond_to?(:set_encoding)
    user.user_certificate = input.read
  end

  unless user.save
    puts "failed #{i}"
    puts user.errors.full_messages
    exit 1
  end

  # puts "success [#{i}]"
end