cgetcap(3) - NetBSD Manual Pages

Command: Section: Arch: Collection:  
CGETCAP(3)              NetBSD Library Functions Manual             CGETCAP(3)


NAME
cgetent, cgetset, cgetmatch, cgetcap, cgetnum, cgetstr, cgetustr, cgetfirst, cgetnext, cgetclose, csetexpandtc -- capability database access routines
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdlib.h> int cgetent(char **buf, const char * const *db_array, const char *name); int cgetset(const char *ent); int cgetmatch(const char *buf, const char *name); char * cgetcap(char *buf, const char *cap, int type); int cgetnum(char *buf, const char *cap, long *num); int cgetstr(char *buf, const char *cap, char **str); int cgetustr(char *buf, const char *cap, char **str); int cgetfirst(char **buf, const char * const *db_array); int cgetnext(char **buf, const char * const *db_array); int cgetclose(void); void csetexpandtc(int expandtc);
DESCRIPTION
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 end- ing 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 set- ting 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 `:'. See capfile(5) for a description of the capability 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 capa- bility 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 capabil- ity 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 spe- cial 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 previ- ous 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 suc- cessful 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().
CAPABILITY DATABASE SEMANTICS
Capability records describe a set of (name, value) bindings. Names may have multiple values bound to them. Different values for a name are dis- tinguished by their types. cgetcap() will return a pointer to a value of a name given the capability name and the type of the value. The types `#' and `=' are conventionally used to denote numeric and string typed values, but no restriction on those types is enforced. The functions cgetnum() and cgetstr() can be used to implement the tradi- tional syntax and semantics of `#' and `='. Typeless capabilities are typically used to denote boolean objects with presence or absence indi- cating truth and false values respectively. This interpretation is con- veniently represented by: (getcap(buf, name, ':') != NULL) A special capability, "tc=name", is used to indicate that the record specified by name should be substituted for the "tc" capability. "tc" capabilities may interpolate records which also contain "tc" capabilities and more than one "tc" capability may be used in a record. A "tc" expan- sion scope (i.e. where the argument is searched for) contains the file in which the "tc" is declared and all subsequent files in the file array. csetexpandtc() can be used to control if "tc" expansion is performed or not.
DIAGNOSTICS
cgetent(), cgetset(), cgetmatch(), cgetnum(), cgetstr(), cgetustr(), cgetfirst(), and cgetnext() return a value greater than or equal to 0 on success and a value less than 0 on failure. cgetcap() returns a charac- ter pointer on success and a NULL on failure. cgetclose(), cgetent(), cgetfirst(), and cgetnext() may fail and set errno for any of the errors specified for the library functions: fopen(3), fclose(3), open(2), and close(2). cgetent(), cgetset(), cgetstr(), and cgetustr() may fail and set errno as follows: [ENOMEM] No memory to allocate.
SEE ALSO
cap_mkdb(1), malloc(3), capfile(5)
BUGS
There are no checks for "tc=name" loops in cgetent(). The buffer added to the database by a call to cgetset() is not unique to the database but is rather prepended to any database used. NetBSD 9.0 April 5, 2012 NetBSD 9.0
Powered by man-cgi (2021-06-01). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.