Sha256: 7d4f3fd36d05ae8a5eaab7a515c4037613fef8e0402a98f59aafb6b7d4d11ff1

Contents?: true

Size: 1.94 KB

Versions: 5

Compression:

Stored size: 1.94 KB

Contents

#!/usr/bin/env ruby

require 'active_samba_ldap'
require 'active_samba_ldap/command'

include ActiveSambaLdap::GetTextSupport

argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
  options.computer_account = false
  options.gid = nil

  opts.banner += " USER_NAME"

  opts.on("-c", "--[no-]computer-account",
          _("is a Windows Workstation"),
          _("(otherwise, Windows user)"),
          "(#{options.computer_account})") {|options.computer_account|}

  opts.on("-g", "--gid=GID", _("gid")) {|options.gid|}
end

name = nil
if argv.size == 1
  name = argv.first
else
  $stderr.puts opts
  exit 1
end

ActiveSambaLdap::Base.setup_connection("update")

class User < ActiveSambaLdap::User
  ldap_mapping :recommended_classes => []
end

class Computer < ActiveSambaLdap::Computer
  ldap_mapping :recommended_classes => []
end

class Group < ActiveSambaLdap::Group
  ldap_mapping :recommended_classes => []
end

options.computer_account = true if /\$$/ =~ name

if options.computer_account
  member_class = Computer
  member_type = _("computer")
else
  member_class = User
  member_type = _("user")
end

if options.computer_account
  name = name.chomp("$") + "$"
end

unless member_class.exists?(name)
  $stderr.puts(_("%s doesn't exist: %s") % [member_type, name])
  exit 1
end
member = member_class.find(name)

unless Process.uid.zero?
  password = ActiveSambaLdap::Command.read_password(_("Enter your password: "))

  begin
    member.bind(password)
  rescue ActiveLdap::AuthenticationError
    $stderr.puts(_("password doesn't match."))
    exit 1
  end
  member.remove_connection
end

if options.gid
  begin
    member.primary_group = Group.find_by_name_or_gid_number(options.gid)
  rescue ActiveSambaLdap::Error
    $stderr.puts $!.message
    exit 1
  end
end

unless member.save
  member.errors.each_full do |message|
    $stderr.puts(message)
  end
  exit 1
end

ActiveSambaLdap::Base.restart_nscd

ActiveSambaLdap::Base.clear_active_connections!

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
activesambaldap-0.1.0 bin/asl-samba-usermod
activesambaldap-0.0.9 bin/asl-samba-usermod
activesambaldap-0.0.8 bin/asl-samba-usermod
ActiveSambaLdap-0.0.7 bin/asl-samba-usermod
activesambaldap-0.0.7 bin/asl-samba-usermod