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