1 .\" Copyright (c) 1992, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Casey Leedom of Lawrence Livermore National Laboratory.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)getcap.3 8.4 (Berkeley) 5/13/94
32 .\" $FreeBSD: src/lib/libc/gen/getcap.3,v 1.30 2007/02/11 18:14:49 maxim Exp $
33 .\" $DragonFly: src/lib/libc/gen/getcap.3,v 1.4 2008/05/02 02:05:03 swildner Exp $
49 .Nd capability database access routines
55 .Fn cgetent "char **buf" "char **db_array" "const char *name"
57 .Fn cgetset "const char *ent"
59 .Fn cgetmatch "const char *buf" "const char *name"
61 .Fn cgetcap "char *buf" "const char *cap" "int type"
63 .Fn cgetnum "char *buf" "const char *cap" "long *num"
65 .Fn cgetstr "char *buf" "const char *cap" "char **str"
67 .Fn cgetustr "char *buf" "const char *cap" "char **str"
69 .Fn cgetfirst "char **buf" "char **db_array"
71 .Fn cgetnext "char **buf" "char **db_array"
77 function extracts the capability
79 from the database specified by the
83 and returns a pointer to a
89 function will first look for files ending in
93 before accessing the ASCII file.
97 must be retained through all subsequent calls to
106 On success 0 is returned, 1 if the returned
107 record contains an unresolved
110 \-1 if the requested record could not be found,
111 \-2 if a system error was encountered (could not open/read a file, etc.) also
114 and \-3 if a potential reference loop is detected (see
120 function enables the addition of a character buffer containing a single capability
122 to the capability database.
123 Conceptually, the entry is added as the first ``file'' in the database, and
124 is therefore searched first on the call to
126 The entry is passed in
132 the current entry is removed from the database.
135 must precede the database traversal.
136 It must be called before the
139 If a sequential access is being performed (see below), it must be called
140 before the first sequential access call
144 or be directly preceded by a
147 On success 0 is returned and \-1 on failure.
151 function will return 0 if
153 is one of the names of the capability record
160 function searches the capability record
168 is specified using any single character.
169 If a colon (`:') is used, an
170 untyped capability will be searched for (see below for explanation of
172 A pointer to the value of
176 is returned on success,
178 if the requested capability could not be
180 The end of the capability value is signaled by a `:' or
183 (see below for capability database syntax).
187 function retrieves the value of the numeric capability
189 from the capability record pointed to by
191 The numeric value is returned in the
195 0 is returned on success, \-1 if the requested numeric capability could not
200 function retrieves the value of the string capability
202 from the capability record pointed to by
204 A pointer to a decoded,
208 copy of the string is returned in the
212 The number of characters in the decoded string not including the trailing
214 is returned on success, \-1 if the requested string capability could not
215 be found, \-2 if a system error was encountered (storage allocation
220 function is identical to
222 except that it does not expand special characters, but rather returns each
223 character of the capability string literally.
229 functions comprise a function group that provides for sequential
232 pointer terminated array of file names,
236 function returns the first record in the database and resets the access
240 function returns the next record in the database with respect to the
241 record returned by the previous
246 If there is no such previous call, the first record in the database is
248 Each record is returned in a
253 expansion is done (see
256 Upon completion of the database 0 is returned, 1 is returned upon successful
257 return of record with possibly more remaining (we have not reached the end of
258 the database yet), 2 is returned if the record contains an unresolved
260 expansion, \-1 is returned if a system error occurred, and \-2
261 is returned if a potential reference loop is detected (see
264 Upon completion of database (0 return) the database is closed.
268 function closes the sequential access and frees any memory and file descriptors
270 Note that it does not erase the buffer pushed by a call to
272 .Sh CAPABILITY DATABASE SYNTAX
273 Capability databases are normally
275 and may be edited with standard
277 Blank lines and lines beginning with a `#' are comments
279 Lines ending with a `\|\e' indicate that the next line
280 is a continuation of the current line; the `\|\e' and following newline
282 Long lines are usually continued onto several physical
283 lines by ending each line except the last with a `\|\e'.
285 Capability databases consist of a series of records, one per logical
287 Each record contains a variable number of `:'-separated fields
289 Empty fields consisting entirely of white space
290 characters (spaces and tabs) are ignored.
292 The first capability of each record specifies its names, separated by `|'
294 These names are used to reference records in the database.
295 By convention, the last name is usually a comment and is not intended as
303 .Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:"
305 giving four names that can be used to access the record.
307 The remaining non-empty capabilities describe a set of (name, value)
308 bindings, consisting of a names optionally followed by a typed value:
309 .Bl -column "nameTvalue"
310 .It name Ta "typeless [boolean] capability"
311 .Em name No "is present [true]"
312 .It name Ns Em \&T Ns value Ta capability
316 .It name@ Ta "no capability" Em name No exists
317 .It name Ns Em T Ns \&@ Ta capability
322 Names consist of one or more characters.
323 Names may contain any character
324 except `:', but it is usually best to restrict them to the printable
325 characters and avoid use of graphics like `#', `=', `%', `@', etc.
327 are single characters used to separate capability names from their
328 associated typed values.
329 Types may be any character except a `:'.
330 Typically, graphics like `#', `=', `%', etc.\& are used.
332 number of characters and may contain any character except `:'.
333 .Sh CAPABILITY DATABASE SEMANTICS
334 Capability records describe a set of (name, value) bindings.
335 Names may have multiple values bound to them.
336 Different values for a name are
337 distinguished by their
341 function will return a pointer to a value of a name given the capability
342 name and the type of the value.
344 The types `#' and `=' are conventionally used to denote numeric and
345 string typed values, but no restriction on those types is enforced.
351 can be used to implement the traditional syntax and semantics of `#'
353 Typeless capabilities are typically used to denote boolean objects with
354 presence or absence indicating truth and false values respectively.
355 This interpretation is conveniently represented by:
357 .Dl "(getcap(buf, name, ':') != NULL)"
359 A special capability,
361 is used to indicate that the record specified by
363 should be substituted for the
367 capabilities may interpolate records which also contain
369 capabilities and more than one
371 capability may be used in a record.
374 expansion scope (i.e., where the argument is searched for) contains the
377 is declared and all subsequent files in the file array.
379 When a database is searched for a capability record, the first matching
380 record in the search is returned.
381 When a record is scanned for a
382 capability, the first matching capability is returned; the capability
384 will hide any following definition of a value of type
390 will prevent any following values of
394 These features combined with
396 capabilities can be used to generate variations of other databases and
397 records by either adding new capabilities, overriding definitions with new
398 definitions, or hiding following definitions via `@' capabilities.
400 .Bd -unfilled -offset indent
401 example\||\|an example of binding multiple values to names:\e
402 :foo%bar:foo^blah:foo@:\e
403 :abc%xyz:abc^frap:abc$@:\e
407 The capability foo has two values bound to it (bar of type `%' and blah of
408 type `^') and any other value bindings are hidden.
410 also has two values bound but only a value of type `$' is prevented from
411 being defined in the capability record more.
412 .Bd -unfilled -offset indent
414 new\||\|new_record\||\|a modification of "old":\e
415 :fript=bar:who-cares@:tc=old:blah:tc=extensions:
417 old\||\|old_record\||\|an old database record:\e
418 :fript=foo:who-cares:glork#200:
421 The records are extracted by calling
423 with file1 preceding file2.
424 In the capability record new in file1, fript=bar overrides the definition
425 of fript=foo interpolated from the capability record old in file2,
426 who-cares@ prevents the definition of any who-cares definitions in old
427 from being seen, glork#200 is inherited from old, and blah and anything
428 defined by the record extensions is added to those definitions in old.
429 Note that the position of the fript=bar and who-cares@ definitions before
430 tc=old is important here.
431 If they were after, the definitions in old
432 would take precedence.
433 .Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS
434 Two types are predefined by
438 .Bl -column "nameXnumber"
440 .It Em name No \&# Em number Ta numeric
447 .It Em name No = Em string Ta "string capability"
453 .It Em name No \&#@ Ta "the numeric capability"
458 .It Em name No \&=@ Ta "the string capability"
464 Numeric capability values may be given in one of three numeric bases.
465 If the number starts with either
469 it is interpreted as a hexadecimal number (both upper and lower case a-f
470 may be used to denote the extended hexadecimal digits).
471 Otherwise, if the number starts with a
473 it is interpreted as an octal number.
474 Otherwise the number is interpreted as a decimal number.
476 String capability values may contain any character.
479 codes, new lines, and colons may be conveniently represented by the use
481 .Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)"
482 ^X ('X' & 037) control-X
483 \e\|b, \e\|B (ASCII 010) backspace
484 \e\|t, \e\|T (ASCII 011) tab
485 \e\|n, \e\|N (ASCII 012) line feed (newline)
486 \e\|f, \e\|F (ASCII 014) form feed
487 \e\|r, \e\|R (ASCII 015) carriage return
488 \e\|e, \e\|E (ASCII 027) escape
489 \e\|c, \e\|C (:) colon
490 \e\|\e (\e\|) back slash
492 \e\|nnn (ASCII octal nnn)
495 A `\|\e' may be followed by up to three octal digits directly specifies
496 the numeric code for a character.
501 encoded, causes all sorts of problems and must be used with care since
503 are typically used to denote the end of strings; many applications
504 use `\e\|200' to represent a
518 return a value greater than or equal to 0 on success and a value less
522 function returns a character pointer on success and a
530 functions may fail and set
532 for any of the errors specified for the library functions:
551 No memory to allocate.
557 Colons (`:') cannot be used in names, types, or values.
559 There are no checks for
560 .Ic tc Ns = Ns Ic name
564 The buffer added to the database by a call to
566 is not unique to the database but is rather prepended to any database used.