CAP_FROM_TEXT - Online Linux Manual PageSection : 3
Updated : 2008-05-10
Source :
Note : Linux Programmer's Manual
NAMEcap_from_text, cap_to_text, cap_to_name, cap_from_name − capability state textual representation translation
SYNOPSIS#include <sys/capability.h>
cap_t cap_from_text(const char* buf_p );
char *cap_to_text(cap_t caps, ssize_t * length_p);
int cap_from_name(const char* name , cap_value_t* cap_p);
char *cap_to_name(cap_value_t cap);Link with −lcap.
DESCRIPTIONThese functions translate a capability state between an internal representation and 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. 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 a human-readable, nul-terminated character string pointed to by buf_p. It returns a pointer to the newly created capability state. When the capability state in working storage is no longer required, the caller should free any releasable memory by calling cap_free() with cap_t as an argument. The function returns an error if it cannot parse the contents of the string pointed to by buf_p or does not recognize any 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. cap_to_text() converts the capability state in working storage identified by cap_p into a nul-terminated human-readable string. This function allocates any memory necessary to contain the string, and returns a pointer to the string. If the pointer len_p is not NULL, the function shall also return the full length of the string (not including the nul terminator) in the location pointed to by len_p. The capability state in working storage, identified by cap_p, is completely represented in the character string. When the capability state in working storage is no longer required, the caller should free any releasable memory by calling cap_free() with the returned string pointer as an argument. cap_from_name() converts a text representation of a capability, such as "cap_chown", to its numerical representation (CAP_CHOWN=0), writing the decoded value into *cap_p. If cap_p is NULL no result is written, but the return code of the function indicates whether or not the specified capability can be represented by the library. cap_to_name() converts a capability index value, cap, to a libcap-allocated textual string. This string should be deallocated with cap_free().
TEXTUAL REPRESENTATIONA textual representation of capability sets consists of one or more whitespace-separated clauses. Each clause specifies some operations on 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. Each clause consists of a list of comma-separated capability names (or the word `all'), followed by an action-list. An action-list consists of a sequence of operator flag pairs. Legal operators are: `=', '+', and `−'. Legal flags are: `e', `i', and `p'. These flags are case-sensitive and specify the Effective, Inheritable and Permitted sets respectively. In the capability name lists, all names are case-insensitive. The special name `all' specifies all capabilities; it is equivalent to a list naming every capability individually. Unnamed capabilities can also be specified by number. This feature ensures that libcap can support capabilities that were not allocated at the time libcap was compiled. However, generally upgrading libcap will add names for recently allocated capabilities. The `=' 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. In the case that the leading operator is `=', 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>=". 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 and "cap_fowner−i" will lower the override-file-ownership in the Inheritable set. The action list can consist of multiple operator flag pairs; the actions are performed in left-to-right order. Thus, for example, "cap_fowner+p−i" is equivalent to "cap_fowner+p cap_fowner−i". As another example, "cap_fowner+pe−i" and "cap_fowner=+pe" are equivalent.
RETURN VALUEcap_from_text(), cap_to_text() and cap_to_name() return a non-NULL value on success, and NULL on failure. cap_from_name() returns 0 for success, and −1 on failure (unknown capability). On failure, errno is set to EINVAL, or ENOMEM.
CONFORMING TOcap_from_text() and cap_to_text() are specified by the withdrawn POSIX.1e draft specification. cap_from_name() and cap_to_name() are Linux extensions.
EXAMPLEThe example program below demonstrates the use of cap_from_text() and cap_to_text(). The following shell session shows some example runs: $ ./a.out "cap_chown=p cap_chown+e"
caps_to_text() returned "cap_chown=ep"
$ ./a.out "all=pe cap_chown−e cap_kill−pe"
caps_to_text() returned "=ep cap_chown−e cap_kill−ep"
The source code of the program is as follows: #include <stdlib.h>
#include <stdio.h>
#include <sys/capability.h>
#define handle_error(msg)
do { perror(msg); exit(EXIT_FAILURE); } while (0)
int
main(int argc, char *argv[])
{
cap_t caps;
char *txt_caps;
if (argc != 2) {
fprintf(stderr, "%s <textual−cap−set>\n", argv[0]);
exit(EXIT_FAILURE);
}
caps = cap_from_text(argv[1]);
if (caps == NULL)
handle_error("cap_from_text");
txt_caps = cap_to_text(caps, NULL);
if (txt_caps == NULL)
handle_error("cap_to_text");
printf("caps_to_text() returned \"%s\\"\\n", txt_caps);
if (cap_free(txt_caps) != 0 || cap_free(caps) != 0)
handle_error("cap_free");
exit(EXIT_SUCCESS);
}
SEE ALSOlibcap(3), cap_clear(3), cap_copy_ext(3), cap_get_file(3), cap_get_proc(3), cap_init(3), capabilities(7) 0
Johanes Gumabo
Data Size : 18,514 byte
man-cap_to_text.3Build : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 2 / 199,590
Visitor ID : :
Visitor IP : 3.139.86.74 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (rof_nr_x|149|cap_from_text.3|208|\n", argv[0]);| fprintf(stderr, "%s \\n", argv[0]);
) (rof_escape_sequence|91|cap_from_text.3|220|\"%s\\"\\n", txt_caps);| printf("caps_to_text() returned \\"%s\\"\\n", txt_caps);
)