set.user: Switch user for the current process

Description Usage Arguments Details Value Note Author(s) Examples

Description

set.user attempts to change the user running the current process. Note that this is only possible if the process has the privilege to do so.

Usage

1
set.user(name, gid = NA)

Arguments

name

either a string specifying the username or an integer specifying the uid

gid

optional, integer, desired gid

Details

set.user can be used in two ways: with a user name or with a specific uid/gid combination. If used with a user name, then set.user attempts to find the user in the user database, changes the uid, gid and supplemental groups according to the user database.

When name is a number, then set.user only sets the uid and (if gid is specified) gid. Supplemental groups are not changed in that case.

This function is typically used when R is started with elevated privileges (or is suid) and it needs to relinquish those to run as a particular user. The recommended way is to use the username and not the uid/gid specification.

The function will raise an error if either of the required steps fails.

Value

integer, uid if used with a username, TRUE otherwise

Note

When changing users, make sure you also change the permissions for tempdir() before you change the user. Otherwise R will not function properly as it cannot create temporary files.

Author(s)

Simon Urbanek

Examples

1
2
3
4
## Not run: 
set.user("myname")

## End(Not run)

s-u/unixtools documentation built on May 28, 2019, 10:49 a.m.