File: cap_from_text.3

package info (click to toggle)
libcap 1.92-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 312 kB
  • ctags: 172
  • sloc: ansic: 1,294; makefile: 152; sh: 5
file content (153 lines) | stat: -rw-r--r-- 5,337 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
.\"
.\" $Id: cap_from_text.3,v 1.1.1.1 1999/04/17 22:16:31 morgan Exp $
.\" written by Andrew Main <zefram@dcs.warwick.ac.uk>
.\"
.TH CAP_FROM_TEXT 3 "26th May 1997" "" "Linux Programmer's Manual"
.SH NAME
cap_from_text, cap_to_text, _cap_names \- capability state textual representation translation
.SH SYNOPSIS
.B #include <sys/capability.h>
.sp
.BI "cap_t cap_from_text(const char *" buf_p );
.sp
.BI "char *cap_to_text(cap_t " caps ", ssize_t *" length_p );
.sp
.B extern char const *_cap_names[];
.SH USAGE
.br
.B cc ... -lcap
.SH DESCRIPTION
These functions translate a capability state from an internal representation
into a textual one.  The internal representation is managed by the capability
functions in working storage. The textual representation is a structured,
human-readable, string suitable for display.
.PP
.B cap_from_text
allocates and initializes a capability state in working storage. It then
sets the contents of this newly-created capability state to the state
represented by human-readable, null terminated character string pointed to by
.IR buf_p .
It returns a pointer to the newly created capability state.  The
caller should free any releasable memory, when the capability state in working
storage is no longer required, by calling
.B cap_free
with
.I cap_t
as an argument.  The function returns an error if it cannot parse the
contents of the string pointed to by
.I buf_p
or does not recognize any
.I capability_name
or flag character as valid.  The function also returns an error if any flag
is both set and cleared within a single clause.
.PP
.B cap_to_text
converts the capability state in working storage identified by
.I cap_p
into a null terminated human-readable string.  This function allocates any
memory necessary to contain the string, and returns a pointer to the string.  If
the pointer
.I len_p
is not
.BR NULL ,
the function shall also return the full length of the string (not including
the null terminator) in the location pointed to by
.IR len_p .
The capability state in working storage, identified by
.IR cap_p ,
is completely represented in the character string.  The caller should
free any releasable memory, when the capability state in working
storage is no longer required, by calling
.B cap_free
with
.B cap_p
as an argument.
.PP
.B _cap_names
is an array of textual names for capability numbers.  Unnamed capabilities
have a NULL entry.  (This array is not defined by POSIX.1e.)
.SH "TEXTUAL REPRESENTATION"
A textual representation of capability sets consists of one or more
whitespace-separated
.IR clauses .
Each clause specifies some operations to a capability set; the set
starts out with all capabilities lowered, and the meaning of the
string is the state of the capability set after all the clauses have
been applied in order.
.PP
Each clause consists of a list of comma-separated capability names
(or the word
.RB ` all '),
followed by an
.IR action-list .
An action-list consists of a sequence of
.I operator flag
pairs.  Legal operators are:
.RB ` = "', '" + "', and `" - "'."
Legal flags are:
.RB ` e "', `" i "', and `" p "'."
These flags are case-sensitive and specify the Effective, Inheritable
and Permitted sets respectively.
.PP
In the capability name lists, all names are case-insensitive.  The
special name
.RB ` all '
specifies all capabilities; it is equivalent to a list naming every
capability individually.
.PP
Although not defined by POSIX, unnamed capabilities can be specified
by number.
.PP
The
.RB ` = '
operator indicates that the listed capabilities are first reset in
all three capability sets.  The subsequent flags (which are optional
when associated with this operator) indicate that the listed
capabilities for the corresponding set are to be raised.  For example:
"all=p" means lower every capability in the Effective and Inheritable
sets but raise all of the Permitted capabilities;
or, "cap_fowner=ep" means raise the Effective and Permitted
override-file-ownership capability, while lowering this Inheritable
capability.
.PP
In the case that the leading operator is
.RB ` = ',
and no list of capabilities is provided, the action-list is assumed to
refer to `all' capabilities.  For example, the following three
clauses are equivalent to each other (and indicate a completely empty
capability set): "all="; "="; "cap_chown,<every-other-capability>=".
.PP
The operators, `+' and `-' both require an explicit preceding
capability list and one or more explicit trailing flags.  The `+'
operator will raise all of the listed capabilities in the flagged
capability sets.  The `-' operator will lower all of the listed
capabilities in the flagged capability sets.  For example:
"all+p" will raise all of the Permitted capabilities; "cap_fowner+p-i"
will raise the override-file-ownership capability in the Permitted
capability set and lower this Inheritable capability;
"cap_fowner+pe-i" and "cap_fowner=+pe" are equivalent.
.SH "RETURN VALUE"
.B cap_from_text
and
.B cap_to_text
return a non-NULL value on success, and NULL on failure.
.PP
On failure,
.BR errno (3)
is set to 
.BR EINVAL ,
or 
.BR ENOMEM .
.SH "CONFORMING TO"
.B cap_from_text
and
.B cap_to_text
are specified by POSIX.1e.
.B _cap_names
is a Linux extension.
.SH "SEE ALSO"
.IR cap_clear (3),
.IR cap_copy_ext (3),
.IR cap_get_file (3),
.IR cap_get_proc (3),
.IR cap_init (3)