cgetent() extracts the capability
name from the database specified by the
NULL terminated file array
db_array and returns a pointer to a
malloc(3)'d copy of it in
buf.
cgetent() will first look for files ending in
.db (see
cap_mkdb(1)) before accessing the ASCII file.
buf must be retained through all subsequent calls to
cgetmatch(),
cgetcap(),
cgetnum(),
cgetstr(), and
cgetustr(), but may then be
free(3)'d.
On success 0 is returned, 1 if the returned record contains an unresolved “tc” expansion, -1 if the requested record couldn't be found, -2 if a system error was encountered (couldn't open/read a file, etc.) also setting
errno, and -3 if a potential reference loop is detected (see “tc=name” comments below).
cgetset() enables the addition of a character buffer containing a single capability record entry to the capability database. Conceptually, the entry is added as the first “file” in the database, and is therefore searched first on the call to
cgetent(). The entry is passed in
ent. If
ent is
NULL, the current entry is removed from the database.
cgetset() must precede the database traversal. It must be called before the
cgetent() call. If a sequential access is being performed (see below), it must be called before the first sequential access call (
cgetfirst() or
cgetnext()), or be directly preceded by a
cgetclose() call. On success 0 is returned and -1 on failure.
cgetmatch() will return 0 if
name is one of the names of the capability record
buf, -1 if not.
cgetcap() searches the capability record
buf for the capability
cap with type
type. A
type is specified using any single character. If a colon (‘:') is used, an untyped capability will be searched for (see below for explanation of types). A pointer to the value of
cap in
buf is returned on success,
NULL if the requested capability couldn't be found. The end of the capability value is signaled by a ‘:' or ASCII
NUL (see below for capability database syntax).
cgetnum() retrieves the value of the numeric capability
cap from the capability record pointed to by
buf. The numeric value is returned in the
long pointed to by
num. 0 is returned on success, -1 if the requested numeric capability couldn't be found.
cgetstr() retrieves the value of the string capability
cap from the capability record pointed to by
buf. A pointer to a decoded,
NUL terminated,
malloc(3)'d copy of the string is returned in the
char * pointed to by
str. The number of characters in the decoded string not including the trailing
NUL is returned on success, -1 if the requested string capability couldn't be found, -2 if a system error was encountered (storage allocation failure).
cgetustr() is identical to
cgetstr() except that it does not expand special characters, but rather returns each character of the capability string literally.
cgetfirst(),
cgetnext(), comprise a function group that provides for sequential access of the
NULL pointer terminated array of file names,
db_array.
cgetfirst() returns the first record in the database and resets the access to the first record.
cgetnext() returns the next record in the database with respect to the record returned by the previous
cgetfirst() or
cgetnext() call. If there is no such previous call, the first record in the database is returned. Each record is returned in a
malloc(3)'d copy pointed to by
buf. “tc” expansion is done (see “tc=name” comments below).
Upon completion of the database 0 is returned, 1 is returned upon successful return of record with possibly more remaining (we haven't reached the end of the database yet), 2 is returned if the record contains an unresolved “tc” expansion, -1 is returned if an system error occurred, and -2 is returned if a potential reference loop is detected (see “tc=name” comments below). Upon completion of database (0 return) the database is closed.
cgetclose() closes the sequential access and frees any memory and file descriptors being used. Note that it does not erase the buffer pushed by a call to
cgetset().