# Group name
var group: nullable String
- # Drop privileges of a user and set his privileges back to default (program privileges)
+ # Drop privileges of the running program to those of `self`
+ #
+ # require: `user.user_exists and (group == null or group.group_exists)`
fun drop_privileges
do
var passwd = new Passwd.from_name(user)
+ assert not passwd.address_is_null
var uid = passwd.uid
var group = group
var gid
if group != null then
var gpasswd = new Group.from_name(group)
+ assert not gpasswd.address_is_null
gid = gpasswd.gid
else gid = passwd.gid
redef type VALUE: nullable UserGroup
- init for_dropping_privileges do init("Drop privileges to user:group or simply user", "-u", "--usergroup")
- init(help: String, names: String...) do super(help, null, names)
+ # Create an `OptionUserAndGroup` for dropping privileges
+ init for_dropping_privileges
+ do
+ init("Drop privileges to user:group or simply user", null, ["-u", "--usergroup"])
+ end
redef fun convert(str)
do
return new UserGroup(words[0], words[1])
else
errors.add("Option {names.join(", ")} expected parameter in the format \"user:group\" or simply \"user\".\n")
- abort # FIXME only for nitc, remove and replace with next line when FFI is working in nitg
- #return null
+ return null
end
end
end