Method: Puppet::Util::SUIDManager.change_user
- Defined in:
- lib/vendor/puppet/util/suidmanager.rb
.change_user(user, permanently = false) ⇒ Object
As change_group, but operates on uids. If changing user permanently, supplementary groups will be set the to default groups for the new uid.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/vendor/puppet/util/suidmanager.rb', line 121 def change_user(user, permanently=false) uid = convert_xid(:uid, user) raise Puppet::Error, "No such user #{user}" unless uid if permanently # If changing uid, we must be root. So initgroups first here. initgroups(uid) Process::UID.change_privilege(uid) else # We must be root to initgroups, so initgroups before dropping euid if # we're root, otherwise elevate euid before initgroups. # change euid (to root) first. if Process.euid == 0 initgroups(uid) Process.euid = uid else Process.euid = uid initgroups(uid) end end end |