Module: ActiveSambaLdap::AccountEntry

Included in:
Computer, User
Defined in:
lib/active_samba_ldap/account_entry.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

NAME_RE_SRC =
"(?!\\d)[\\w @_\\-\\.]+"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



11
12
13
14
# File 'lib/active_samba_ldap/account_entry.rb', line 11

def self.included(base)
  super
  base.extend(ClassMethods)
end

Instance Method Details

#change_password(password) ⇒ Object



135
136
137
138
139
# File 'lib/active_samba_ldap/account_entry.rb', line 135

def change_password(password)
  hash_type = self.class.configuration[:password_hash_type]
  hashed_password = ActiveLdap::UserPassword.__send__(hash_type, password)
  self.user_password = hashed_password
end

#change_uid_number(uid, allow_non_unique = false) ⇒ Object



130
131
132
133
# File 'lib/active_samba_ldap/account_entry.rb', line 130

def change_uid_number(uid, allow_non_unique=false)
  check_unique_uid_number(uid) unless allow_non_unique
  self.uid_number = Integer(uid)
end

#destroy(options = {}) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/active_samba_ldap/account_entry.rb', line 110

def destroy(options={})
  if options[:removed_from_group]
    groups.each do |group|
      remove_from_group(group)
    end
  end
  dir = home_directory
  need_remove_home_directory =
    options[:remove_home_directory] && !new_entry?
  super()
  if need_remove_home_directory and File.directory?(dir)
    if options[:remove_home_directory_interactive]
      system("rm", "-r", "-i", dir)
    else
      FileUtils.rm_r(dir)
    end
  end
  new_entry?
end

#fill_default_values(options = {}) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/active_samba_ldap/account_entry.rb', line 87

def fill_default_values(options={})
  self.cn ||= uid
  self.sn ||= uid
  self.given_name ||= uid
  self.display_name ||= cn
  self.gecos ||= substituted_value(:user_gecos) {cn}
  self.home_directory ||= substituted_value(:user_home_directory)
  self. ||= self.class.configuration[:user_login_shell]

  options = options.stringify_keys
  password = options["password"]
  change_password(password) if password
  self.user_password ||= "{crypt}x"

  uid_number = options["uid_number"]
  self.change_uid_number(uid_number) if uid_number

  primary_group = options["group"] || retrieve_default_primary_group(options)
  self.primary_group = primary_group if primary_group

  self
end

#setup_home_directory(options = {}) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/active_samba_ldap/account_entry.rb', line 141

def setup_home_directory(options={})
  dest = home_directory
  return unless dest

  FileUtils.mkdir_p(dest)
  mode = options[:mode]
  mode ||= self.class.configuration[:user_home_directory_mode]
  FileUtils.chmod(Integer(mode), dest)
  skel = options[:skeleton_directory]
  skel ||= self.class.configuration[:skeleton_directory]
  FileUtils.cp_r(Dir.glob(File.join(skel, ".*")) +
                 Dir.glob(File.join(skel, "*")) -
                 [File.join(skel, "."), File.join(skel, "..")],
                 dest)
  FileUtils.chown_R(uid_number.to_s, gid_number.to_s, dest)
end