SUDO_PLUGIN(5) File Formats Manual SUDO_PLUGIN(5)
NAME
sudo_plugin - Sudo Plugin API
DESCRIPTION
Starting with version 1.8, sudo supports a plugin API for policy and
session logging. Plugins may be compiled as dynamic shared objects (the
default on systems that support them) or compiled statically into the
sudo binary itself. By default, the sudoers plugin provides audit,
security policy and I/O logging capabilities. Via the plugin API, sudo
can be configured to use alternate plugins provided by third parties.
The plugins to be used are specified in the sudo.conf(5) file.
The API is versioned with a major and minor number. The minor version
number is incremented when additions are made. The major number is
incremented when incompatible changes are made. A plugin should be check
the version passed to it and make sure that the major version matches.
The plugin API is defined by the header file.
Policy plugin API
A policy plugin must declare and populate a struct policy_plugin in the
global scope. This structure contains pointers to the functions that
implement the sudo policy checks. The name of the symbol should be
specified in sudo.conf(5) along with a path to the plugin so that sudo
can load it.
struct policy_plugin {
#define SUDO_POLICY_PLUGIN 1
unsigned int type; /* always SUDO_POLICY_PLUGIN */
unsigned int version; /* always SUDO_API_VERSION */
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], char * const user_env[],
char * const plugin_options[], const char **errstr);
void (*close)(int exit_status, int error);
int (*show_version)(int verbose);
int (*check_policy)(int argc, char * const argv[],
char *env_add[], char **command_info[],
char **argv_out[], char **user_env_out[], const char **errstr);
int (*list)(int argc, char * const argv[], int verbose,
const char *user, const char **errstr);
int (*validate)(const char **errstr);
void (*invalidate)(int rmcred);
int (*init_session)(struct passwd *pwd, char **user_env[],
const char **errstr);
void (*register_hooks)(int version,
int (*register_hook)(struct sudo_hook *hook));
void (*deregister_hooks)(int version,
int (*deregister_hook)(struct sudo_hook *hook));
struct sudo_plugin_event * (*event_alloc)(void);
};
A struct policy_plugin has the following fields:
type The type field should always be set to SUDO_POLICY_PLUGIN.
version
The version field should be set to SUDO_API_VERSION.
This allows sudo to determine the API version the plugin was built
against.
open
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], char * const user_env[],
char * const plugin_options[], const char **errstr);
Returns 1 on success, 0 on failure, -1 if a general error occurred,
or -2 if there was a usage error. In the latter case, sudo will
print a usage message before it exits. If an error occurs, the
plugin may optionally call the conversation() or
sudo_plugin_printf() function with SUDO_CONF_ERROR_MSG to present
additional error information to the user.
The function arguments are as follows:
version
The version passed in by sudo allows the plugin to determine
the major and minor version number of the plugin API
supported by sudo.
conversation
A pointer to the conversation() function that can be used by
the plugin to interact with the user (see Conversation API
for details). Returns 0 on success and -1 on failure.
sudo_plugin_printf
A pointer to a printf()-style function that may be used to
display informational or error messages (see Conversation API
for details). Returns the number of characters printed on
success and -1 on failure.
settings
A vector of user-supplied sudo settings in the form of
"name=value" strings. The vector is terminated by a NULL
pointer. These settings correspond to options the user
specified when running sudo. As such, they will only be
present when the corresponding option has been specified on
the command line.
When parsing settings, the plugin should split on the first
equal sign (`=') since the name field will never include one
itself but the value might.
The following values may be set by sudo:
bsdauth_type=string
Authentication type, if specified by the -a option, to
use on systems where BSD authentication is supported.
closefrom=number
If specified, the user has requested via the -C option
that sudo close all files descriptors with a value of
number or higher. The plugin may optionally pass this,
or another value, back in the command_info list.
cmnd_chroot=string
The root directory (see chroot(2)) to run the command
in, as specified by the user via the -R option. The
plugin may ignore or restrict the user's ability to
specify a new root directory. Only available starting
with API version 1.16.
cmnd_cwd=string
The working directory to run the command in, as
specified by the user via the -D option. The plugin
may ignore or restrict the user's ability to specify a
new working directory. Only available starting with
API version 1.16.
debug_flags=string
A debug file path name followed by a space and a comma-
separated list of debug flags that correspond to the
plugin's Debug entry in sudo.conf(5), if there is one.
The flags are passed to the plugin exactly as they
appear in sudo.conf(5). The syntax used by sudo and
the sudoers plugin is subsystem@priority but a plugin
is free to use a different format so long as it does
not include a comma (`,'). Prior to sudo 1.8.12, there
was no way to specify plugin-specific debug_flags so
the value was always the same as that used by the sudo
front-end and did not include a path name, only the
flags themselves. As of version 1.7 of the plugin
interface, sudo will only pass debug_flags if
sudo.conf(5) contains a plugin-specific Debug entry.
ignore_ticket=bool
Set to true if the user specified the -k option along
with a command, indicating that the user wishes to
ignore any cached authentication credentials.
implied_shell to true. This allows sudo with no
arguments to be used similarly to su(1). If the plugin
does not to support this usage, it may return a value
of -2 from the check_policy() function, which will
cause sudo to print a usage message and exit.
implied_shell=bool
If the user does not specify a program on the command
line, sudo will pass the plugin the path to the user's
shell and set implied_shell.
intercept_ptrace=bool
Indicates whether or not the system supports intercept
mode using ptrace(2). This is currently only true for
Linux systems that support seccomp(2) filtering and the
"trap" action. Other systems will use a dynamic shared
object to implement intercept. Only available starting
with API version 1.19.
intercept_setid=bool
Indicates whether or not the system supports running
set-user-ID and set-group-ID binaries in intercept
mode. This is currently only true for Linux systems
that support seccomp(2) filtering and the "trap"
action. On systems that use a dynamic shared object to
implement intercept, the dynamic linker (ld.so or the
equivalent) will disable preloading of shared objects
when executing a set-user-ID or set-group-ID binary.
This will disable intercept mode for that program and
any other programs that it executes. The policy plugin
may refuse to execute a set-user-ID or set-group-ID
binary in intercept mode to avoid this. Only available
starting with API version 1.19.
login_class=string
BSD login class to use when setting resource limits and
nice value, if specified by the -c option.
login_shell=bool
Set to true if the user specified the -i option,
indicating that the user wishes to run a login shell.
max_groups=int
The maximum number of groups a user may belong to.
This will only be present if there is a corresponding
setting in sudo.conf(5).
network_addrs=list
A space-separated list of IP network addresses and
netmasks in the form "addr/netmask", e.g.,
"192.168.1.2/255.255.255.0". The address and netmask
pairs may be either IPv4 or IPv6, depending on what the
operating system supports. If the address contains a
colon (`:'), it is an IPv6 address, else it is IPv4.
noninteractive=bool
Set to true if the user specified the -n option,
indicating that sudo should operate in non-interactive
mode. The plugin may reject a command run in non-
interactive mode if user interaction is required.
plugin_dir=string
The default plugin directory used by the sudo front-
end. This is the default directory set at compile time
and may not correspond to the directory the running
plugin was loaded from. It may be used by a plugin to
locate support files.
plugin_path=string
The path name of plugin loaded by the sudo front-end.
The path name will be a fully-qualified unless the
plugin was statically compiled into sudo.
preserve_environment=bool
Set to true if the user specified the -E option,
indicating that the user wishes to preserve the
environment.
preserve_groups=bool
Set to true if the user specified the -P option,
indicating that the user wishes to preserve the group
vector instead of setting it based on the runas user.
progname=string
The command name that sudo was run as, typically "sudo"
or "sudoedit".
prompt=string
The prompt to use when requesting a password, if
specified via the -p option.
remote_host=string
The name of the remote host to run the command on, if
specified via the -h option. Support for running the
command on a remote host is meant to be implemented via
a helper program that is executed in place of the user-
specified command. The sudo front-end is only capable
of executing commands on the local host. Only
available starting with API version 1.4.
run_shell=bool
Set to true if the user specified the -s option,
indicating that the user wishes to run a shell.
runas_group=string
The group name or group-ID to run the command as, if
specified via the -g option.
runas_user=string
The user name or user-ID to run the command as, if
specified via the -u option.
selinux_role=string
SELinux role to use when executing the command, if
specified by the -r option.
selinux_type=string
SELinux type to use when executing the command, if
specified by the -t option.
set_home=bool
Set to true if the user specified the -H option. If
true, set the HOME environment variable to the target
user's home directory.
sudoedit=bool
Set to true when the -e option is specified or if
invoked as sudoedit. The plugin shall substitute an
editor into argv in the check_policy() function or
return -2 with a usage error if the plugin does not
support sudoedit. For more information, see the
check_policy() section.
timeout=string
Command timeout specified by the user via the -T
option. Not all plugins support command timeouts and
the ability of the user to set a timeout may be
restricted by policy. The format of the timeout string
is plugin-specific.
update_ticket=bool
Set to false if the user specified the -N option,
indicating that the user wishes to avoid updating any
cached authentication credentials. Only available
starting with API version 1.20.
Additional settings may be added in the future so the plugin
should silently ignore settings that it does not recognize.
user_info
A vector of information about the user running the command in
the form of "name=value" strings. The vector is terminated
by a NULL pointer.
When parsing user_info, the plugin should split on the first
equal sign (`=') since the name field will never include one
itself but the value might.
The following values may be set by sudo:
cols=int
The number of columns the user's terminal supports. If
there is no terminal device available, a default value
of 80 is used.
cwd=string
The user's current working directory.
egid=gid_t
The effective group-ID of the user invoking sudo.
euid=uid_t
The effective user-ID of the user invoking sudo.
gid=gid_t
The real group-ID of the user invoking sudo.
groups=list
The user's supplementary group list formatted as a
string of comma-separated group-IDs.
host=string
The local machine's hostname as returned by the
gethostname(2) system call.
lines=int
The number of lines the user's terminal supports. If
there is no terminal device available, a default value
of 24 is used.
pgid=int
The ID of the process group that the running sudo
process is a member of. Only available starting with
API version 1.2.
pid=int
The process ID of the running sudo process. Only
available starting with API version 1.2.
ppid=int
The parent process ID of the running sudo process.
Only available starting with API version 1.2.
rlimit_as=soft,hard
The maximum size to which the process's address space
may grow (in bytes), if supported by the operating
system. The soft and hard limits are separated by a
comma. A value of "infinity" indicates that there is
no limit. Only available starting with API version
1.16.
rlimit_core=soft,hard
The largest size core dump file that may be created (in
bytes). The soft and hard limits are separated by a
comma. A value of "infinity" indicates that there is
no limit. Only available starting with API version
1.16.
rlimit_cpu=soft,hard
The maximum amount of CPU time that the process may use
(in seconds). The soft and hard limits are separated
by a comma. A value of "infinity" indicates that there
is no limit. Only available starting with API version
1.16.
rlimit_data=soft,hard
The maximum size of the data segment for the process
(in bytes). The soft and hard limits are separated by
a comma. A value of "infinity" indicates that there is
no limit. Only available starting with API version
1.16.
rlimit_fsize=soft,hard
The largest size file that the process may create (in
bytes). The soft and hard limits are separated by a
comma. A value of "infinity" indicates that there is
no limit. Only available starting with API version
1.16.
rlimit_locks=soft,hard
The maximum number of locks that the process may
establish, if supported by the operating system. The
soft and hard limits are separated by a comma. A value
of "infinity" indicates that there is no limit. Only
available starting with API version 1.16.
rlimit_memlock=soft,hard
The maximum size that the process may lock in memory
(in bytes), if supported by the operating system. The
soft and hard limits are separated by a comma. A value
of "infinity" indicates that there is no limit. Only
available starting with API version 1.16.
rlimit_nofile=soft,hard
The maximum number of files that the process may have
open. The soft and hard limits are separated by a
comma. A value of "infinity" indicates that there is
no limit. Only available starting with API version
1.16.
rlimit_nproc=soft,hard
The maximum number of processes that the user may run
simultaneously. The soft and hard limits are separated
by a comma. A value of "infinity" indicates that there
is no limit. Only available starting with API version
1.16.
rlimit_rss=soft,hard
The maximum size to which the process's resident set
size may grow (in bytes). The soft and hard limits are
separated by a comma. A value of "infinity" indicates
that there is no limit. Only available starting with
API version 1.16.
rlimit_stack=soft,hard
The maximum size to which the process's stack may grow
(in bytes). The soft and hard limits are separated by
a comma. A value of "infinity" indicates that there is
no limit. Only available starting with API version
1.16.
sid=int
The session ID of the running sudo process or 0 if sudo
is not part of a POSIX job control session. Only
available starting with API version 1.2.
tcpgid=int
The ID of the foreground process group associated with
the terminal device associated with the sudo process or
0 if there is no terminal present. Only available
starting with API version 1.2.
tty=string
The path to the user's terminal device, if one exists.
This entry is only present if the user has a terminal
device associated with the session.
ttydev=dev_t
The number of the user's terminal device, if one
exists, formatted as a long long value. This entry is
only present if the user has a terminal device
associated with the session. Only available starting
with API version 1.22.
uid=uid_t
The real user-ID of the user invoking sudo.
umask=octal
The invoking user's file creation mask. Only available
starting with API version 1.10.
user=string
The name of the user invoking sudo.
user_env
The user's environment in the form of a NULL-terminated
vector of "name=value" strings.
When parsing user_env, the plugin should split on the first
equal sign (`=') since the name field will never include one
itself but the value might.
plugin_options
Any (non-comment) strings immediately after the plugin path
are passed as arguments to the plugin. These arguments are
split on a white space boundary and are passed to the plugin
in the form of a NULL-terminated array of strings. If no
arguments were specified, plugin_options will be the NULL
pointer.
The plugin_options parameter is only available starting with
API version 1.2. A plugin must check the API version
specified by the sudo front-end before using plugin_options.
Failure to do so may result in a crash.
errstr
If the open() function returns a value other than 1, the
plugin may store a message describing the failure or error in
errstr. The sudo front-end will then pass this value to any
registered audit plugins. The string stored in errstr must
remain valid until the plugin's close() function is called.
The errstr parameter is only available starting with API
version 1.15. A plugin must check the API version specified
by the sudo front-end before using errstr. Failure to do so
may result in a crash.
close
void (*close)(int exit_status, int error);
The close() function is called when sudo is finished, shortly
before it exits. Starting with API version 1.15, close() is called
regardless of whether or not a command was actually executed. This
makes it possible for plugins to perform cleanup even when a
command was not run. It is not possible to tell whether a command
was run based solely on the arguments passed to the close()
function. To determine if a command was actually run, the plugin
must keep track of whether or not the check_policy() function
returned successfully.
The function arguments are as follows:
exit_status
The command's exit status, as returned by the wait(2) system
call, or zero if no command was run. The value of
exit_status is undefined if error is non-zero.
error
If the command could not be executed, this is set to the
value of errno set by the execve(2) system call. The plugin
is responsible for displaying error information via the
conversation() or sudo_plugin_printf() function. If the
command was successfully executed, the value of error is
zero.
If no close() function is defined, no I/O logging plugins are
loaded, and neither the timeout nor use_pty options are set in the
command_info list, the sudo front-end may execute the command
directly instead of running it as a child process.
show_version
int (*show_version)(int verbose);
The show_version() function is called by sudo when the user
specifies the -V option. The plugin may display its version
information to the user via the conversation() or
sudo_plugin_printf() function using SUDO_CONV_INFO_MSG. If the
user requests detailed version information, the verbose flag will
be non-zero.
Returns 1 on success, 0 on failure, -1 if a general error occurred,
or -2 if there was a usage error, although the return value is
currently ignored.
check_policy
int (*check_policy)(int argc, char * const argv[], char *env_add[],
char **command_info[], char **argv_out[], char **user_env_out[],
const char **errstr);
The check_policy() function is called by sudo to determine whether
the user is allowed to run the specified commands.
If the sudoedit option was enabled in the settings array passed to
the open() function, the user has requested sudoedit mode.
sudoedit is a mechanism for editing one or more files where an
editor is run with the user's credentials instead of with elevated
privileges. sudo achieves this by creating user-writable temporary
copies of the files to be edited and then overwriting the originals
with the temporary copies after editing is complete. If the plugin
supports sudoedit, it must set sudoedit=true in the command_info
list. The plugin is responsible for choosing the editor to be
used, potentially from a variable in the user's environment, such
as EDITOR, and should be stored in argv_out (environment variables
may include command line options). The files to be edited should
be copied from argv to argv_out, separated from the editor and its
arguments by a `--' element. The `--' will be removed by sudo
before the editor is executed. The plugin may also set
sudoedit_nfiles to the number of files to be edited in the
command_info list; this will only be used by the sudo front-end
starting with API version 1.21.
The check_policy() function returns 1 if the command is allowed, 0
if not allowed, -1 for a general error, or -2 for a usage error or
if sudoedit was specified but is unsupported by the plugin. In the
latter case, sudo will print a usage message before it exits. If
an error occurs, the plugin may optionally call the conversation()
or sudo_plugin_printf() function with SUDO_CONF_ERROR_MSG to
present additional error information to the user.
The function arguments are as follows:
argc The number of elements in argv, not counting the final NULL
pointer.
argv The argument vector describing the command the user wishes to
run, in the same form as what would be passed to the
execve(2) system call. The vector is terminated by a NULL
pointer.
env_add
Additional environment variables specified by the user on the
command line in the form of a NULL-terminated vector of
"name=value" strings. The plugin may reject the command if
one or more variables are not allowed to be set, or it may
silently ignore such variables.
When parsing env_add, the plugin should split on the first
equal sign (`=') since the name field will never include one
itself but the value might.
command_info
Information about the command being run in the form of
"name=value" strings. These values are used by sudo to set
the execution environment when running a command. The plugin
is responsible for creating and populating the vector, which
must be terminated with a NULL pointer. The following values
are recognized by sudo:
apparmor_profile=string
AppArmor profile to transition to when executing the
command. Only available starting with API version
1.19.
chroot=string
The root directory to use when running the command.
closefrom=number
If specified, sudo will close all files descriptors
with a value of number or higher.
command=string
Fully qualified path to the command to be executed.
cwd=string
The current working directory to change to when
executing the command. If sudo is unable to change to
the new working directory, the command will not be run
unless cwd_optional is also set (see below).
cwd_optional=bool
If set, sudo will treat an inability to change to the
new working directory as a non-fatal error. This
setting has no effect unless cwd is also set.
exec_background=bool
By default, sudo runs a command as the foreground
process as long as sudo itself is running in the
foreground. When exec_background is enabled and the
command is being run in a pseudo-terminal (due to I/O
logging or the use_pty setting), the command will be
run as a background process. Attempts to read from the
controlling terminal (or to change terminal settings)
will result in the command being suspended with the
SIGTTIN signal (or SIGTTOU in the case of terminal
settings). If this happens when sudo is a foreground
process, the command will be granted the controlling
terminal and resumed in the foreground with no user
intervention required. The advantage of initially
running the command in the background is that sudo need
not read from the terminal unless the command
explicitly requests it. Otherwise, any terminal input
must be passed to the command, whether it has required
it or not (the kernel buffers terminals so it is not
possible to tell whether the command really wants the
input). This is different from historic sudo behavior
or when the command is not being run in a pseudo-
terminal.
For this to work seamlessly, the operating system must
support the automatic restarting of system calls.
Unfortunately, not all operating systems do this by
default, and even those that do may have bugs. For
example, macOS fails to restart the tcgetattr() and
tcsetattr() system calls (this is a bug in macOS).
Furthermore, because this behavior depends on the
command stopping with the SIGTTIN or SIGTTOU signals,
programs that catch these signals and suspend
themselves with a different signal (usually SIGTOP)
will not be automatically foregrounded. Some versions
of the linux su(1) command behave this way. Because of
this, a plugin should not set exec_background unless it
is explicitly enabled by the administrator and there
should be a way to enabled or disable it on a per-
command basis.
This setting has no effect unless I/O logging is
enabled or use_pty is enabled.
execfd=number
If specified, sudo will use the fexecve(2) system call
to execute the command instead of execve(2). The
specified number must refer to an open file descriptor.
intercept=bool
If set, sudo will intercept attempts to execute a
subsequent command and perform a policy check via the
policy plugin's check_policy() function to determine
whether or not the command is permitted. This can be
used to prevent shell escapes on supported platforms
but it has a number of limitations. See Preventing
shell escapes in sudoers(5) for details. Only
available starting with API version 1.18.
intercept_verify=bool
If set, sudo will attempt to verify that a command run
in intercept mode has the expected path name, command
line arguments and environment. This setting has no
effect unless use_ptrace is also enabled. Only
available starting with API version 1.20.
iolog_compress=bool
Set to true if the I/O logging plugins, if any, should
compress the log data. This is a hint to the I/O
logging plugin which may choose to ignore it.
iolog_group=string
The group that will own newly created I/O log files and
directories. This is a hint to the I/O logging plugin
which may choose to ignore it.
iolog_mode=octal
The file permission mode to use when creating I/O log
files and directories. This is a hint to the I/O
logging plugin which may choose to ignore it.
iolog_user=string
The user that will own newly created I/O log files and
directories. This is a hint to the I/O logging plugin
which may choose to ignore it.
iolog_path=string
Fully qualified path to the file or directory in which
I/O log is to be stored. This is a hint to the I/O
logging plugin which may choose to ignore it. If no
I/O logging plugin is loaded, this setting has no
effect.
iolog_stdin=bool
Set to true if the I/O logging plugins, if any, should
log the standard input if it is not connected to a
terminal device. This is a hint to the I/O logging
plugin which may choose to ignore it.
iolog_stdout=bool
Set to true if the I/O logging plugins, if any, should
log the standard output if it is not connected to a
terminal device. This is a hint to the I/O logging
plugin which may choose to ignore it.
iolog_stderr=bool
Set to true if the I/O logging plugins, if any, should
log the standard error if it is not connected to a
terminal device. This is a hint to the I/O logging
plugin which may choose to ignore it.
iolog_ttyin=bool
Set to true if the I/O logging plugins, if any, should
log all terminal input. This only includes input typed
by the user and not from a pipe or redirected from a
file. This is a hint to the I/O logging plugin which
may choose to ignore it.
iolog_ttyout=bool
Set to true if the I/O logging plugins, if any, should
log all terminal output. This only includes output to
the screen, not output to a pipe or file. This is a
hint to the I/O logging plugin which may choose to
ignore it.
login_class=string
BSD login class to use when setting resource limits and
nice value (optional). This option is only set on
systems that support login classes.
nice=int
Nice value (priority) to use when executing the
command. The nice value, if specified, overrides the
priority associated with the login_class on BSD
systems.
log_subcmds=bool
If set, sudo will call the audit plugin's accept()
function to log when the command runs a subsequent
command, if supported by the system. If intercept is
also specified, log_subcmds will be ignored. See
Preventing shell escapes in sudoers(5) for more
information. Only available starting with API version
1.18.
noexec=bool
If set, prevent the command from executing other
programs.
preserve_fds=list
A comma-separated list of file descriptors that should
be preserved, regardless of the value of the closefrom
setting. Only available starting with API version 1.5.
preserve_groups=bool
If set, sudo will preserve the user's group vector
instead of initializing the group vector based on
runas_user.
rlimit_as=soft,hard
The maximum size to which the process's address space
may grow (in bytes), if supported by the operating
system. The soft and hard limits are separated by a
comma. If only a single value is specified, both the
hard and soft limits are set. A value of "infinity"
indicates that there is no limit. A value of "user"
will cause the invoking user's resource limit to be
preserved. A value of "default" will cause the target
user's default resource limit to be used on systems
that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
rlimit_core=soft,hard
The largest size core dump file that may be created (in
bytes). The soft and hard limits are separated by a
comma. If only a single value is specified, both the
hard and soft limits are set. A value of "infinity"
indicates that there is no limit. A value of "user"
will cause the invoking user's resource limit to be
preserved. A value of "default" will cause the target
user's default resource limit to be used on systems
that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
rlimit_cpu=soft,hard
The maximum amount of CPU time that the process may use
(in seconds). The soft and hard limits are separated
by a comma. If only a single value is specified, both
the hard and soft limits are set. A value of
"infinity" indicates that there is no limit. A value
of "user" will cause the invoking user's resource limit
to be preserved. A value of "default" will cause the
target user's default resource limit to be used on
systems that allow per-user resource limits to be
configured. Only available starting with API version
1.18.
rlimit_data=soft,hard
The maximum size of the data segment for the process
(in bytes). The soft and hard limits are separated by
a comma. If only a single value is specified, both the
hard and soft limits are set. A value of "infinity"
indicates that there is no limit. A value of "user"
will cause the invoking user's resource limit to be
preserved. A value of "default" will cause the target
user's default resource limit to be used on systems
that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
rlimit_fsize=soft,hard
The largest size file that the process may create (in
bytes). The soft and hard limits are separated by a
comma. If only a single value is specified, both the
hard and soft limits are set. A value of "infinity"
indicates that there is no limit. A value of "user"
will cause the invoking user's resource limit to be
preserved. A value of "default" will cause the target
user's default resource limit to be used on systems
that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
rlimit_locks=soft,hard
The maximum number of locks that the process may
establish, if supported by the operating system. The
soft and hard limits are separated by a comma. If only
a single value is specified, both the hard and soft
limits are set. A value of "infinity" indicates that
there is no limit. A value of "user" will cause the
invoking user's resource limit to be preserved. A
value of "default" will cause the target user's default
resource limit to be used on systems that allow per-
user resource limits to be configured. Only available
starting with API version 1.18.
rlimit_memlock=soft,hard
The maximum size that the process may lock in memory
(in bytes), if supported by the operating system. The
soft and hard limits are separated by a comma. If only
a single value is specified, both the hard and soft
limits are set. A value of "infinity" indicates that
there is no limit. A value of "user" will cause the
invoking user's resource limit to be preserved. A
value of "default" will cause the target user's default
resource limit to be used on systems that allow per-
user resource limits to be configured. Only available
starting with API version 1.18.
rlimit_nofile=soft,hard
The maximum number of files that the process may have
open. The soft and hard limits are separated by a
comma. If only a single value is specified, both the
hard and soft limits are set. A value of "infinity"
indicates that there is no limit. A value of "user"
will cause the invoking user's resource limit to be
preserved. A value of "default" will cause the target
user's default resource limit to be used on systems
that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
rlimit_nproc=soft,hard
The maximum number of processes that the user may run
simultaneously. The soft and hard limits are separated
by a comma. If only a single value is specified, both
the hard and soft limits are set. A value of
"infinity" indicates that there is no limit. A value
of "user" will cause the invoking user's resource limit
to be preserved. A value of "default" will cause the
target user's default resource limit to be used on
systems that allow per-user resource limits to be
configured. Only available starting with API version
1.18.
rlimit_rss=soft,hard
The maximum size to which the process's resident set
size may grow (in bytes). The soft and hard limits are
separated by a comma. If only a single value is
specified, both the hard and soft limits are set. A
value of "infinity" indicates that there is no limit.
A value of "user" will cause the invoking user's
resource limit to be preserved. A value of "default"
will cause the target user's default resource limit to
be used on systems that allow per-user resource limits
to be configured. Only available starting with API
version 1.18.
rlimit_stack=soft,hard
The maximum size to which the process's stack may grow
(in bytes). The soft and hard limits are separated by
a comma. If only a single value is specified, both the
hard and soft limits are set. A value of "infinity"
indicates that there is no limit. A value of "user"
will cause the invoking user's resource limit to be
preserved. A value of "default" will cause the target
user's default resource limit to be used on systems
that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
runas_egid=gid
Effective group-ID to run the command as. If not
specified, the value of runas_gid is used.
runas_euid=uid
Effective user-ID to run the command as. If not
specified, the value of runas_uid is used.
runas_gid=gid
Group-ID to run the command as.
runas_group=string
The name of the group the command will run as, if it is
different from the runas_user's default group. This
value is provided for auditing purposes only, the sudo
front-end uses runas_egid and runas_gid when executing
the command.
runas_groups=list
The supplementary group vector to use for the command
in the form of a comma-separated list of group-IDs. If
preserve_groups is set, this option is ignored.
runas_uid=uid
User-ID to run the command as.
runas_user=string
The name of the user the command will run as, which
should correspond to runas_euid (or runas_uid if
runas_euid is not set). This value is provided for
auditing purposes only, the sudo front-end uses
runas_euid and runas_uid when executing the command.
selinux_role=string
SELinux role to use when executing the command.
selinux_type=string
SELinux type to use when executing the command.
set_utmp=bool
Create a utmp (or utmpx) entry when a pseudo-terminal
is allocated. By default, the new entry will be a copy
of the user's existing utmp entry (if any), with the
tty, time, type, and pid fields updated.
sudoedit=bool
Set to true when in sudoedit mode. The plugin may
enable sudoedit mode even if sudo was not invoked as
sudoedit. This allows the plugin to perform command
substitution and transparently enable sudoedit when the
user attempts to run an editor.
sudoedit_checkdir=bool
Set to false to disable directory writability checks in
sudoedit. By default, sudoedit 1.8.16 and higher will
check all directory components of the path to be edited
for writability by the invoking user. Symbolic links
will not be followed in writable directories and
sudoedit will refuse to edit a file located in a
writable directory. These restrictions are not
enforced when sudoedit is run by root. The
sudoedit_checkdir option can be set to false to disable
this check. Only available starting with API version
1.8.
sudoedit_follow=bool
Set to true to allow sudoedit to edit files that are
symbolic links. By default, sudoedit 1.8.15 and higher
will refuse to open a symbolic link. The
sudoedit_follow option can be used to restore the older
behavior and allow sudoedit to open symbolic links.
Only available starting with API version 1.8.
sudoedit_nfiles=number
The number of files to be edited by the user. If
present, this is will be used by the sudo front-end to
determine which elements of the argv_out vector are
files to be edited. The `--' element must immediately
precede the first file to be edited. If
sudoedit_nfiles is not specified, the sudo front-end
will use the position of the `--' element to determine
where the file list begins. Only available starting
with API version 1.21.
timeout=int
Command timeout. If non-zero then when the timeout
expires the command will be killed.
umask=octal
The file creation mask to use when executing the
command. This value may be overridden by PAM or
login.conf on some systems unless the umask_override
option is also set.
umask_override=bool
Force the value specified by the umask option to
override any umask set by PAM or login.conf.
use_ptrace=bool
If set, sudo will use ptrace(2) to implement intercept
mode if supported by the system. This setting has no
effect unless intercept is also set. Only available
starting with API version 1.19.
use_pty=bool
Allocate a pseudo-terminal to run the command in,
regardless of whether or not I/O logging is in use. By
default, sudo will only run the command in a pseudo-
terminal when an I/O log plugin is loaded.
utmp_user=string
User name to use when constructing a new utmp (or
utmpx) entry when set_utmp is enabled. This option can
be used to set the user field in the utmp entry to the
user the command runs as rather than the invoking user.
If not set, sudo will base the new entry on the
invoking user's existing entry.
Unsupported values will be ignored.
argv_out
The NULL-terminated argument vector to pass to the execve(2)
system call when executing the command. The plugin is
responsible for allocating and populating the vector.
user_env_out
The NULL-terminated environment vector to use when executing
the command. The plugin is responsible for allocating and
populating the vector.
errstr
If the check_policy() function returns a value other than 1,
the plugin may store a message describing the failure or
error in errstr. The sudo front-end will then pass this
value to any registered audit plugins. The string stored in
errstr must remain valid until the plugin's close() function
is called.
The errstr parameter is only available starting with API
version 1.15. A plugin must check the API version specified
by the sudo front-end before using errstr. Failure to do so
may result in a crash.
list
int (*list)(int argc, char * const argv[], int verbose,
const char *user, const char **errstr);
List available privileges for the invoking user. Returns 1 on
success, 0 on failure, and -1 on error. On error, the plugin may
optionally call the conversation() or sudo_plugin_printf() function
with SUDO_CONF_ERROR_MSG to present additional error information to
the user.
Privileges should be output via the conversation() or
sudo_plugin_printf() function using SUDO_CONV_INFO_MSG.
The function arguments are as follows:
argc The number of elements in argv, not counting the final NULL
pointer.
argv If non-NULL, an argument vector describing a command the user
wishes to check against the policy in the same form as what
would be passed to the execve(2) system call. If the command
is permitted by the policy, the fully-qualified path to the
command should be displayed along with any command line
arguments.
verbose
Flag indicating whether to list in verbose mode or not.
user The name of a different user to list privileges for if the
policy allows it. If NULL, the plugin should list the
privileges of the invoking user.
errstr
If the list() function returns a value other than 1, the
plugin may store a message describing the failure or error in
errstr. The sudo front-end will then pass this value to any
registered audit plugins. The string stored in errstr must
remain valid until the plugin's close() function is called.
The errstr parameter is only available starting with API
version 1.15. A plugin must check the API version specified
by the sudo front-end before using errstr. Failure to do so
may result in a crash.
validate
int (*validate)(const char **errstr);
The validate() function is called when sudo is run with the -v
option. For policy plugins such as sudoers that cache
authentication credentials, this function will validate and cache
the credentials.
The validate() function should be NULL if the plugin does not
support credential caching.
Returns 1 on success, 0 on failure, and -1 on error. On error, the
plugin may optionally call the conversation() or
sudo_plugin_printf() function with SUDO_CONF_ERROR_MSG to present
additional error information to the user.
The function arguments are as follows:
errstr
If the validate() function returns a value other than 1, the
plugin may store a message describing the failure or error in
errstr. The sudo front-end will then pass this value to any
registered audit plugins. The string stored in errstr must
remain valid until the plugin's close() function is called.
The errstr parameter is only available starting with API
version 1.15. A plugin must check the API version specified
by the sudo front-end before using errstr. Failure to do so
may result in a crash.
invalidate
void (*invalidate)(int rmcred);
The invalidate() function is called when sudo is run with the -k or
-K option. For policy plugins such as sudoers that cache
authentication credentials, this function will invalidate the
credentials. If the rmcred flag is non-zero, the plugin may remove
the credentials instead of simply invalidating them.
The invalidate() function should be NULL if the plugin does not
support credential caching.
init_session
int (*init_session)(struct passwd *pwd, char **user_env[],
const char **errstr);
The init_session() function is called before sudo sets up the
execution environment for the command. It is run in the parent
sudo process before any user-ID or group-ID changes. This can be
used to perform session setup that is not supported by
command_info, such as opening the PAM session. The close()
function can be used to tear down the session that was opened by
init_session().
Returns 1 on success, 0 on failure, and -1 on error. On error, the
plugin may optionally call the conversation() or
sudo_plugin_printf() function with SUDO_CONF_ERROR_MSG to present
additional error information to the user.
The function arguments are as follows:
pwd If the user-ID the command will run as was found in the
password database, pwd will describe that user, otherwise it
will be NULL.
user_env_out
The NULL-terminated environment vector to use when executing
the command. This is the same string passed back to the
front-end via the Policy Plugin's user_env_out parameter. If
the init_session() function needs to modify the user
environment, it should update the pointer stored in
user_env_out. The expected use case is to merge the contents
of the PAM environment (if any) with the contents of
user_env_out. The user_env_out parameter is only available
starting with API version 1.2. A plugin must check the API
version specified by the sudo front-end before using
user_env_out. Failure to do so may result in a crash.
errstr
If the init_session() function returns a value other than 1,
the plugin may store a message describing the failure or
error in errstr. The sudo front-end will then pass this
value to any registered audit plugins. The string stored in
errstr must remain valid until the plugin's close() function
is called.
The errstr parameter is only available starting with API
version 1.15. A plugin must check the API version specified
by the sudo front-end before using errstr. Failure to do so
may result in a crash.
register_hooks
void (*register_hooks)(int version,
int (*register_hook)(struct sudo_hook *hook));
The register_hooks() function is called by the sudo front-end to
register any hooks the plugin needs. If the plugin does not
support hooks, register_hooks should be set to the NULL pointer.
The version argument describes the version of the hooks API
supported by the sudo front-end.
The register_hook() function should be used to register any
supported hooks the plugin needs. It returns 0 on success, 1 if
the hook type is not supported, and -1 if the major version in
struct sudo_hook does not match the front-end's major hook API
version.
See the Hook function API section below for more information about
hooks.
The register_hooks() function is only available starting with API
version 1.2. If the sudo front-end doesn't support API version 1.2
or higher, register_hooks() will not be called.
deregister_hooks
void (*deregister_hooks)(int version,
int (*deregister_hook)(struct sudo_hook *hook));
The deregister_hooks() function is called by the sudo front-end to
deregister any hooks the plugin has registered. If the plugin does
not support hooks, deregister_hooks should be set to the NULL
pointer.
The version argument describes the version of the hooks API
supported by the sudo front-end.
The deregister_hook() function should be used to deregister any
hooks that were put in place by the register_hook() function. If
the plugin tries to deregister a hook that the front-end does not
support, deregister_hook() will return an error.
See the Hook function API section below for more information about
hooks.
The deregister_hooks() function is only available starting with API
version 1.2. If the sudo front-end doesn't support API version 1.2
or higher, deregister_hooks() will not be called.
event_alloc
struct sudo_plugin_event * (*event_alloc)(void);
The event_alloc() function is used to allocate a struct
sudo_plugin_event which provides access to the main sudo event
loop. Unlike the other fields, the event_alloc pointer is filled
in by the sudo front-end, not by the plugin.
See the Event API section below for more information about events.
The event_alloc() function is only available starting with API
version 1.15. If the sudo front-end doesn't support API version
1.15 or higher, event_alloc will not be set.
Policy Plugin Version Macros
/* Plugin API version major/minor. */
#define SUDO_API_VERSION_MAJOR 1
#define SUDO_API_VERSION_MINOR 13
#define SUDO_API_MKVERSION(x, y) ((x > 16)
#define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
#define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \
*(vp) = (*(vp) & 0x0000ffff) | ((n) (private).
Please do not report security vulnerabilities through public GitHub
issues, Bugzilla or mailing lists. Instead, report them via email to
. You may encrypt your message with PGP if you
would like, using the key found at https://www.sudo.ws/dist/PGPKEYS.
SUPPORT
Limited free support is available via the sudo-users mailing list, see
https://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or search
the archives.
DISCLAIMER
sudo is provided "AS IS" and any express or implied warranties,
including, but not limited to, the implied warranties of merchantability
and fitness for a particular purpose are disclaimed. See the LICENSE.md
file distributed with sudo or https://www.sudo.ws/about/license/ for
complete details.
Sudo 1.9.17p2 August 14, 2024 Sudo 1.9.17p2