|
Packit |
3a1417 |
.\"
|
|
Packit |
3a1417 |
.\" written by Andrew Main <zefram@dcs.warwick.ac.uk>
|
|
Packit |
3a1417 |
.\"
|
|
Packit |
3a1417 |
.TH CAP_GET_FILE 3 "2008-05-11" "" "Linux Programmer's Manual"
|
|
Packit |
3a1417 |
.SH NAME
|
|
Packit |
3a1417 |
cap_get_file, cap_set_file, cap_get_fd, cap_set_fd \- capability
|
|
Packit |
3a1417 |
manipulation on files
|
|
Packit |
3a1417 |
.SH SYNOPSIS
|
|
Packit |
3a1417 |
.B
|
|
Packit |
3a1417 |
.sp
|
|
Packit |
3a1417 |
.B #include <sys/capability.h>
|
|
Packit |
3a1417 |
.sp
|
|
Packit |
3a1417 |
.BI "cap_t cap_get_file(const char *" path_p );
|
|
Packit |
3a1417 |
.sp
|
|
Packit |
3a1417 |
.BI "int cap_set_file(const char *" path_p ", cap_t " cap_p );
|
|
Packit |
3a1417 |
.sp
|
|
Packit |
3a1417 |
.BI "cap_t cap_get_fd(int " fd );
|
|
Packit |
3a1417 |
.sp
|
|
Packit |
3a1417 |
.BI "int cap_set_fd(int " fd ", cap_t " caps );
|
|
Packit |
3a1417 |
.sp
|
|
Packit |
3a1417 |
.BI "uid_t cap_get_nsowner(cap_t " caps );
|
|
Packit |
3a1417 |
.sp
|
|
Packit |
3a1417 |
.BI "int cap_set_nsowner(cap_t " caps ", uid_t " rootid );
|
|
Packit |
3a1417 |
.sp
|
|
Packit |
3a1417 |
Link with \fI-lcap\fP.
|
|
Packit |
3a1417 |
.SH DESCRIPTION
|
|
Packit |
3a1417 |
.BR cap_get_file ()
|
|
Packit |
3a1417 |
and
|
|
Packit |
3a1417 |
.BR cap_get_fd ()
|
|
Packit |
3a1417 |
allocate a capability state in working storage and set it to represent the
|
|
Packit |
3a1417 |
capability state of the pathname pointed to by
|
|
Packit |
3a1417 |
.I path_p
|
|
Packit |
3a1417 |
or the file open on descriptor
|
|
Packit |
3a1417 |
.IR fd .
|
|
Packit |
3a1417 |
These functions return a pointer to the newly created capability
|
|
Packit |
3a1417 |
state. The effects of reading the capability state from any file
|
|
Packit |
3a1417 |
other than a regular file is undefined. The caller should free any
|
|
Packit |
3a1417 |
releasable memory, when the capability state in working storage is no
|
|
Packit |
3a1417 |
longer required, by calling
|
|
Packit |
3a1417 |
.BR cap_free ()
|
|
Packit |
3a1417 |
with the used
|
|
Packit |
3a1417 |
.I cap_t
|
|
Packit |
3a1417 |
as an argument.
|
|
Packit |
3a1417 |
.PP
|
|
Packit |
3a1417 |
.BR cap_set_file ()
|
|
Packit |
3a1417 |
and
|
|
Packit |
3a1417 |
.BR cap_set_fd ()
|
|
Packit |
3a1417 |
set the values for all capability flags for all capabilities for the pathname
|
|
Packit |
3a1417 |
pointed to by
|
|
Packit |
3a1417 |
.I path_p
|
|
Packit |
3a1417 |
or the file open on descriptor
|
|
Packit |
3a1417 |
.IR fd ,
|
|
Packit |
3a1417 |
with the capability state identified by
|
|
Packit |
3a1417 |
.IR cap_p .
|
|
Packit |
3a1417 |
The new capability state of the file is completely determined by the
|
|
Packit |
3a1417 |
contents of
|
|
Packit |
3a1417 |
.IR cap_p .
|
|
Packit |
3a1417 |
A NULL value for
|
|
Packit |
3a1417 |
.IR cap_p
|
|
Packit |
3a1417 |
is used to indicate that capabilities for the file should be deleted.
|
|
Packit |
3a1417 |
For these functions to succeed, the calling process must have the
|
|
Packit |
3a1417 |
effective capability,
|
|
Packit |
3a1417 |
.BR CAP_SETFCAP ,
|
|
Packit |
3a1417 |
enabled and either the effective user ID of the process must match the
|
|
Packit |
3a1417 |
file owner or the calling process must have the
|
|
Packit |
3a1417 |
.B CAP_FOWNER
|
|
Packit |
3a1417 |
flag in its effective capability set. The effects of writing the
|
|
Packit |
3a1417 |
capability state to any file type other than a regular file are
|
|
Packit |
3a1417 |
undefined.
|
|
Packit |
3a1417 |
.PP
|
|
Packit |
3a1417 |
A capability set held in memory can be associated with the rootid in
|
|
Packit |
3a1417 |
use in a specific namespace. It is possible to get and set this value
|
|
Packit |
3a1417 |
(in the memory copy) with
|
|
Packit |
3a1417 |
.BR cap_get_nsowner ()
|
|
Packit |
3a1417 |
and
|
|
Packit |
3a1417 |
.BR cap_set_nsowner ()
|
|
Packit |
3a1417 |
respectively. The rootid is ignored by the libcap library in all cases
|
|
Packit |
3a1417 |
other than when the capability is written to a file. Only if the value
|
|
Packit |
3a1417 |
is non-zero will the library attempt to include it in the written file
|
|
Packit |
3a1417 |
capability set.
|
|
Packit |
3a1417 |
.SH "RETURN VALUE"
|
|
Packit |
3a1417 |
.BR cap_get_file ()
|
|
Packit |
3a1417 |
and
|
|
Packit |
3a1417 |
.BR cap_get_fd ()
|
|
Packit |
3a1417 |
return a non-NULL value on success, and NULL on failure.
|
|
Packit |
3a1417 |
.PP
|
|
Packit |
3a1417 |
.BR cap_set_file ()
|
|
Packit |
3a1417 |
and
|
|
Packit |
3a1417 |
.BR cap_set_fd ()
|
|
Packit |
3a1417 |
return zero on success, and \-1 on failure.
|
|
Packit |
3a1417 |
.PP
|
|
Packit |
3a1417 |
On failure,
|
|
Packit |
3a1417 |
.I errno
|
|
Packit |
3a1417 |
is set to
|
|
Packit |
3a1417 |
.BR EACCES ,
|
|
Packit |
3a1417 |
.BR EBADFD ,
|
|
Packit |
3a1417 |
.BR ENAMETOOLONG ,
|
|
Packit |
3a1417 |
.BR ENOENT ,
|
|
Packit |
3a1417 |
.BR ENOMEM ,
|
|
Packit |
3a1417 |
.BR ENOTDIR ,
|
|
Packit |
3a1417 |
.BR EPERM ,
|
|
Packit |
3a1417 |
or
|
|
Packit |
3a1417 |
.BR EROFS .
|
|
Packit |
3a1417 |
.SH "CONFORMING TO"
|
|
Packit |
3a1417 |
These functions are specified by withdrawn POSIX.1e draft specification.
|
|
Packit |
3a1417 |
.SH NOTES
|
|
Packit |
3a1417 |
Support for file capabilities is provided on Linux since version 2.6.24.
|
|
Packit |
3a1417 |
|
|
Packit |
3a1417 |
On Linux, the file Effective set is a single bit.
|
|
Packit |
3a1417 |
If it is enabled, then all Permitted capabilities are enabled
|
|
Packit |
3a1417 |
in the Effective set of the calling process when the file is executed;
|
|
Packit |
3a1417 |
otherwise, no capabilities are enabled in the process's Effective set
|
|
Packit |
3a1417 |
following an
|
|
Packit |
3a1417 |
.BR execve (2).
|
|
Packit |
3a1417 |
Because the file Effective set is a single bit,
|
|
Packit |
3a1417 |
if any capability is enabled in the Effective set of the
|
|
Packit |
3a1417 |
.I cap_t
|
|
Packit |
3a1417 |
given to
|
|
Packit |
3a1417 |
.BR cap_set_file ()
|
|
Packit |
3a1417 |
or
|
|
Packit |
3a1417 |
.BR cap_set_fd (),
|
|
Packit |
3a1417 |
then all capabilities whose Permitted or Inheritable flag
|
|
Packit |
3a1417 |
is enabled must also have the Effective flag enabled.
|
|
Packit |
3a1417 |
Conversely, if the Effective bit is enabled on a file, then the
|
|
Packit |
3a1417 |
.I cap_t
|
|
Packit |
3a1417 |
returned by
|
|
Packit |
3a1417 |
.BR cap_get_file()
|
|
Packit |
3a1417 |
and
|
|
Packit |
3a1417 |
.BR cap_get_fd()
|
|
Packit |
3a1417 |
will have the Effective flag enabled for each capability that has the
|
|
Packit |
3a1417 |
Permitted or Inheritable flag enabled.
|
|
Packit |
3a1417 |
.SH "SEE ALSO"
|
|
Packit |
3a1417 |
.BR libcap (3),
|
|
Packit |
3a1417 |
.BR cap_clear (3),
|
|
Packit |
3a1417 |
.BR cap_copy_ext (3),
|
|
Packit |
3a1417 |
.BR cap_from_text (3),
|
|
Packit |
3a1417 |
.BR cap_get_proc (3),
|
|
Packit |
3a1417 |
.BR cap_init (3),
|
|
Packit |
3a1417 |
.BR capabilities (7)
|