Module: ActiveSambaLdap::AccountEntry
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- NAME_RE_SRC =
"(?!\\d)[\\w @_\\-\\.]+"
Class Method Summary collapse
Instance Method Summary collapse
- #change_password(password) ⇒ Object
- #change_uid_number(uid, allow_non_unique = false) ⇒ Object
- #destroy(options = {}) ⇒ Object
- #fill_default_values(options = {}) ⇒ Object
- #setup_home_directory(options = {}) ⇒ Object
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(={}) if [:removed_from_group] groups.each do |group| remove_from_group(group) end end dir = home_directory need_remove_home_directory = [:remove_home_directory] && !new_entry? super() if need_remove_home_directory and File.directory?(dir) if [: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(={}) 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.login_shell ||= self.class.configuration[:user_login_shell] = .stringify_keys password = ["password"] change_password(password) if password self.user_password ||= "{crypt}x" uid_number = ["uid_number"] self.change_uid_number(uid_number) if uid_number primary_group = ["group"] || retrieve_default_primary_group() 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(={}) dest = home_directory return unless dest FileUtils.mkdir_p(dest) mode = [:mode] mode ||= self.class.configuration[:user_home_directory_mode] FileUtils.chmod(Integer(mode), dest) skel = [: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 |