xref: /freebsd/lib/libutil/login_cap.3 (revision 0ddf9be1f0723916ebd4feb7313d64dffab0c2bb)
1.\" Copyright (c) 1995 David Nugent <davidn@blaze.net.au>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, is permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice immediately at the beginning of the file, without modification,
9.\"    this list of conditions, and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\" 3. This work was done expressly for inclusion into FreeBSD.  Other use
14.\"    is permitted provided this notation is included.
15.\" 4. Absolutely no warranty of function or purpose is made by the author
16.\"    David Nugent.
17.\" 5. Modifications may be freely made to this file providing the above
18.\"    conditions are met.
19.\"
20.\" $Id: login_cap.3,v 1.5 1997/02/22 15:08:19 peter Exp $
21.\"
22.Dd December 27, 1996
23.Os FreeBSD
24.Dt LOGIN_CAP 3
25.Sh NAME
26.Nm login_getclassbyname ,
27.Nm login_close ,
28.Nm login_getclass ,
29.Nm login_getuserclass ,
30.Nm login_getcapstr ,
31.Nm login_getcaplist ,
32.Nm login_getcaptime ,
33.Nm login_getcapnum ,
34.Nm login_getcapsize ,
35.Nm login_getcapbool ,
36.Nm login_getstyle
37.Nd functions for accessing the login class capabilities database.
38.Sh SYNOPSIS
39.Fd #include <sys/types.h>
40.Fd #include <login_cap.h>
41.Ft void
42.Fn login_close "login_cap_t * lc"
43.Ft login_cap_t *
44.Fn login_getclassbyname "const char *nam" "const char *dir"
45.Ft login_cap_t *
46.Fn login_getclass "const struct passwd *pwd"
47.Ft login_cap_t *
48.Fn login_getuserclass "const struct passwd *pwd"
49.Ft char *
50.Fn login_getcapstr "login_cap_t *lc" "const char *cap" "char *def" "char *error"
51.Ft char **
52.Fn login_getcaplist "login_cap_t *lc" "const char *cap" "const char *chars"
53.Ft char *
54.Fn login_getpath "login_cap_t *lc" "const char *cap" "char *error"
55.Ft rlim_t
56.Fn login_getcaptime "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
57.Ft rlim_t
58.Fn login_getcapnum "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
59.Ft rlim_t
60.Fn login_getcapsize "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
61.Ft int
62.Fn login_getcapbool "login_cap_t *lc" "const char *cap" "int def"
63.Ft char *
64.Fn login_getstyle "login_cap_t *lc" "char *style" "const char *auth"
65.Pp
66.Sh DESCRIPTION
67These functions represent a programming interface to the login
68classes database provided in
69.Xr login.conf 5 .
70This database contains capabilities, attributes and default environment
71and accounting settings for users and programs running as specific users,
72as determined by the login class field within entries in
73.Pa /etc/master.passwd .
74.Pp
75Entries in
76.Xr login.conf 5
77consist of colon
78.Ql \&:
79separated fields, the first field in each record being one or more
80identifiers for the record which must be unique for the entire database
81each separated by a '|' and may optionally include a description as
82the last 'name'.
83Remaining fields in the record consist of keyword/data pairs.
84Long lines may be continued with a backslash within empty entries
85with the second and subsequent lines optionally indented for readability.
86This is similar to the format used in
87.Xr termcap 5
88except that keywords are not limited to two significant characters,
89and are usually longer for improved readability.
90As with termcap entries, multiple records can be linked together
91(one record including another) using a field containing tc=<recordid>,
92the result is that the entire record referenced by <recordid> replaces
93the tc= field at the point at which it occurs.
94See
95.Xr getcap 3
96for further details on the format and use of a capabilities database.
97.Pp
98The
99.Nm login_cap
100interface provides a convenient means of retrieving login class
101records with all tc= references expanded.
102A program will typically call one of
103.Fn login_getclass ,
104.Fn login_getuserclass
105or
106.Fn login_getclassbyname
107according to its requirements.
108Each of these functions returns a login capabilities structure,
109.Ft login_cap_t
110which may subsequently be used to interrogate the database for
111specific values using the rest of the API.
112Once the login_cap_t is of no further use, the
113.Fn login_close
114function should be called to free all resources used.
115.Pp
116The structure of login_cap_t is defined in login_cap.h, as:
117.Bd -literal -offset indent
118typedef struct {
119	char *lc_class;
120	char *lc_cap;
121	char *lc_style;
122} login_cap_t;
123.Ed
124.Pp
125The
126.Ar lc_class
127member contains a pointer to the name of the login class
128retrieved.
129This may not necessarily be the same as the one requested,
130either directly via
131.Fn login_getclassbyname ,
132or indirectly via a user's login record using
133.Fn login_getclass
134or
135.Fn login_getuserclass .
136If the referenced user has no login class specified in
137.Pa /etc/master.passwd ,
138the class name is NULL or an empty string, or if the class
139specified does not exist in the database, each of these
140functions will search for a record with an id of "default",
141with that name returned in the
142.Ar lc_class
143field.
144.Pp
145The
146.Ar lc_cap
147field is used internally by the library to contain the
148expanded login capabilities record.
149Programs with unusual requirements may wish to use this
150with the lower-level
151.Fn getcap
152style functions to access the record directly.
153.Pp
154The
155.Ar lc_style
156field is set by the
157.Fn login_getstyle
158function to the authorisation style according to the requirements
159of the program handling a login itself.
160.Pp
161As noted above, the
162.Fn get*class
163functions return a login_cap_t object which is used to access
164the matching or default record in the capabilities database.
165.Fn getclassbyname
166accepts two arguments: the first one is the record identifier of the
167record to be retrieved, the second being an optional directory name.
168If the first
169.Ar name
170argument is NULL, an empty string, or a class that does not exist
171in the supplimental or system login class database, then the system
172.Em default
173record is returned instead.
174If the second
175.Ar dir
176parameter is NULL, then only the system login class database is
177used, but when not NULL, the named directory is searched for
178a login database file called ".login_conf", and capability records
179contained within it may override the system defaults.
180This scheme allows users to override some login settings from
181those in the system login class database by creating class records
182for their own private class with a record id of `me'.
183In the context of a
184.Em login ,
185it should be noted that some options cannot by overridden by
186users for two reasons; many options, such as resource settings
187and deafult process priorities, require root privileges
188in order to take effect, and other fields in the user's file are
189not be consulted at all during the early phases of login for
190security or administrative reasons.
191See
192.Xr login.conf 5
193for more information on which settings a user is able to override.
194Typically, these are limited purely to the user's default login
195environment which might otherwise have been overridden in shell
196startup scripts in any case.
197The user's
198.Pa .login_conf
199merely provides a convenient way for a user to set up their preferred
200login environment before the shell is invoked on login.
201.Pp
202If the specified record is NULL, empty or does not exist, and the
203system has no "default" record available to fallback, there is a
204memory allocation error or for some reason
205.Xr cgetent 3
206is unable to access the login capabilities database, this function
207returns NULL.
208.Pp
209The functions
210.Fn login_getclass
211and
212.Fn login_getuserclass
213retrieve the applicable login class record for the user's passwd
214entry by calling
215.Fn login_getclassbyname .
216On failure, NULL is returned.
217The difference between the two functions is that
218.Fn login_getuserclass
219includes the user's overriding
220.Pa .login_conf
221that exists in the user's home directory, while
222.Fn login_getclass
223restricts itself only to the system login class database in
224.Pa /etc/login.conf .
225In either case, if the passwd pointer is NULL, or the user has
226no class, then the system "default" entry is retrieved.
227.Pp
228Once a program no longer wishes to use a login_cap_t object,
229.Fn login_close
230may be called to free all resources used by the login class.
231.Fn login_close
232may be passed a NULL pointer with no harmful side-effects.
233.Pp
234The remaining functions may be used to retrieve individual
235capability records.
236Each function takes a login_cap_t object as its first parameter,
237a capability tag as the second, and remaining parameters being
238default and error values that are returned if the capability is
239not found.
240The type of the additional parameters passed and returned depend
241on the
242.Em type
243of capability each deals with, be it a simple string, a list,
244a time value, a file or memory size value, a path (consisting of
245a colon-separated list of directories) or a boolean flag.
246The manpage for
247.Xr login.conf 5
248deals in specific tags and their type.
249.Pp
250Note that with all functions in this group, you should not call
251.Xr free 3
252on any pointers returned.
253Memory allocated during retrieval or processing of capability
254tags is automatically reused by subsequent calls to functions
255in this group, or deallocated on calling
256.Fn login_close .
257.Bl -tag -width "login_getcaplist()"
258.It Fn login_getcapstr
259This function returns a simple string capability.
260If the string is not found, then the value in
261.Ar def
262is returned as the default value, or if an error
263occurs, the value in the
264.Ar error
265parameter is returned.
266.It Fn login_getcaplist
267This function returns the value corresponding to the named
268capability tag as a list of values in a NULL terminated
269array.
270Within the login class database, some tags are of type
271.Em list ,
272which consist of one or more comma- or space separated
273values.
274Usually, this function is not called directly from an
275application, but is used indirectly via
276.Fn login_getstyle .
277.It Fn login_getpath
278This function returns a list of directories separated by colons
279.Ql &: .
280Capability tags for which this function is called consist of a list of
281directories separated by spaces.
282.It Fn login_getcaptime
283This function returns a
284.Em time value
285associated with a particular capability tag with the value expressed
286in seconds (the default), minutes, hours, days, weeks or (365 day)
287years or any combination of these.
288A suffix determines the units used: S for seconds, M for minutes,
289H for hours, D for days, W for weeks and Y for 365 day years.
290Case of the units suffix is ignored.
291.Pp
292Time values are normally used for setting resource, accounting and
293session limits.
294If supported by the operating system and compiler (which is true of
295FreeBSD), the value returned is a quad (long long), of type
296.Em rlim_t .
297A value "inf" or "infinity" may be used to express an infinite
298value, in which case RLIM_INFINITY is returned.
299.It Fn login_getcapnum
300This function returns a numeric value for a tag, expressed either as
301tag=<value> or the standard
302.Fn cgetnum
303format tag#<value>.
304The first format should be used in preference to the second, the
305second format is provided for compatibility and consistency with the
306.Xr getcap 3
307database format where numeric types use the
308.Ql \&#
309as the delimiter for numeric values.
310If in the first format, then the value given may be "inf" or
311"infinity" which results in a return value of RLIM_INFINITY.
312If the given capability tag cannot be found, the
313.Ar def
314parameter is returned, and if an error occurs, the
315.Ar error
316parameter is returned.
317.It Fn login_getcapsize
318.Fn login_getcapsize
319returns a value representing a size (typicially, file or memory)
320which may be expressed as bytes (the default), 512 byte blocks,
321kilobytes, megabytes, gigabytes, and on systems that support the
322.Ar long long
323type, terrabytes.
324The suffix used determines the units, and multiple values and
325units may be used in combination (e.g. 1m500k = 1.5 megabytes).
326A value with no suffix is interpreted as bytes,  B as 512-byte
327blocks, K as kilobytes, M as megabytes, G as gigabytes and T as
328terrabytes.
329Case is ignored.
330The error value is returned if there is a login capabilities database
331error, if an invalid suffix is used, or if a numeric value cannot be
332interpreted.
333.It Fn login_getcapbool
334This function returns a boolean value tied to a particular flag.
335It returns 0 if the given capability tag is not present or is
336negated by the presence of a "tag@" (See
337.Xr getcap 3
338for more information on boolean flags), and returns 1 if the tag
339is found.
340.It Fn login_getstyle
341This function is used by the login authorisation system to determine
342the style of login available in a particular case.
343The function accepts three parameters, the login_cap entry itself and
344two optional parameters, and authorisation type 'auth' and 'style', and
345applies these to determine the authorisation style that best suites
346these rules.
347.Bl -bullet -indent offset
348.It
349If 'auth' is neither NULL nor an empty string, look for a tag of type
350"auth-<auth>" in the capability record.
351If not present, then look for the default default tag "auth=".
352.It
353If no valid authorisation list was found from the previous step, then
354default to "passwd" as the authorisation list.
355.It
356If 'style' is not NULL or empty, look for it in the list of authorisation
357methods found from the pprevious step.
358If 'style' is NULL or an empty string, then default to "passwd"
359authorisation.
360.It
361If 'style' is found in the chosen list of authorisation methods, then
362return that, otherwise return NULL.
363.El
364.Pp
365This scheme allows the administrator to determine the types of
366authorisation methods accepted by the system, depending on the
367means by which the access occurs.
368For example, the administrator may require skey or kerberos as
369the authentication method used for access to the system via the
370network, and standard methods via direct dialup or console
371logins, significantly reducing the risk of password discovery
372by "snooping" network packets.
373.El
374.Sh SEE ALSO
375.Xr getcap 3 ,
376.Xr login_class 3 ,
377.Xr login.conf 5 ,
378.Xr termcap 5
379