1 .\" Copyright (c) 1995 David Nugent <davidn@blaze.net.au>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, is permitted provided that the following conditions
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
17 .\" 5. Modifications may be freely made to this file providing the above
18 .\" conditions are met.
20 .\" $FreeBSD: head/lib/libutil/login_cap.3 233648 2012-03-29 05:02:12Z eadler $
27 .Nm login_getcapbool ,
28 .Nm login_getcaplist ,
31 .Nm login_getcapsize ,
32 .Nm login_getcaptime ,
34 .Nm login_getclassbyname ,
35 .Nm login_getpwclass ,
37 .Nm login_getuserclass ,
39 .Nd "functions for accessing the login class capabilities database"
46 .Fn login_close "login_cap_t *lc"
48 .Fn login_getclassbyname "const char *nam" "const struct passwd *pwd"
50 .Fn login_getclass "const char *nam"
52 .Fn login_getpwclass "const struct passwd *pwd"
54 .Fn login_getuserclass "const struct passwd *pwd"
56 .Fn login_getcapstr "login_cap_t *lc" "const char *cap" "const char *def" "const char *error"
58 .Fn login_getcaplist "login_cap_t *lc" "const char *cap" "const char *chars"
60 .Fn login_getpath "login_cap_t *lc" "const char *cap" "const char *error"
62 .Fn login_getcaptime "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
64 .Fn login_getcapnum "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
66 .Fn login_getcapsize "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
68 .Fn login_getcapbool "login_cap_t *lc" "const char *cap" "int def"
70 .Fn login_getstyle "login_cap_t *lc" "const char *style" "const char *auth"
72 .Fn login_setcryptfmt "login_cap_t *lc" "const char *def" "const char *error"
74 These functions represent a programming interface to the login
75 classes database provided in
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 .
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),
90 and may optionally include a description as
93 Remaining fields in the record consist of keyword/data pairs.
94 Long lines may be continued with a backslash within empty entries,
95 with the second and subsequent lines optionally indented for readability.
96 This is similar to the format used in
98 except that keywords are not limited to two significant characters,
99 and are usually longer for improved readability.
100 As with termcap entries, multiple records can be linked together
101 (one record including another) using a field containing
102 .Ql tc= Ns Va <recordid> .
103 The result is that the entire record referenced by
107 field at the point at which it occurs.
110 for further details on the format and use of a capabilities database.
114 interface provides a convenient means of retrieving login class
118 A program will typically call one of
120 .Fn login_getpwclass ,
121 .Fn login_getuserclass
123 .Fn login_getclassbyname
124 according to its requirements.
125 Each of these functions returns a login capabilities structure,
127 which may subsequently be used to interrogate the database for
128 specific values using the rest of the API.
131 is of no further use, the
133 function should be called to free all resources used.
140 .Bd -literal -offset indent
150 member contains a pointer to the name of the login class
152 This may not necessarily be the same as the one requested,
154 .Fn login_getclassbyname ,
155 or indirectly via a user's login record using
156 .Fn login_getpwclass ,
159 If the referenced user has no login class specified in
160 .Pa /etc/master.passwd ,
165 specified does not exist in the database, each of these
166 functions will search for a record with an id of
168 with that name returned in the
171 In addition, if the referenced user has a UID of 0 (normally,
173 although the user name is not considered) then
175 will search for a record with an id of
178 for the record with the id of
183 field is used internally by the library to contain the
184 expanded login capabilities record.
185 Programs with unusual requirements may wish to use this
188 style functions to access the record directly.
194 function to the authorisation style, according to the requirements
195 of the program handling a login itself.
198 .Fn login_getclassbyname
199 function is the basic means to get a
202 It accepts two arguments: the first one,
204 is the record identifier of the
205 record to be retrieved; the second,
207 is an optional pointer to a
210 First of all, its arguments are used by the function
211 to choose between system and user modes of operation.
212 When in system mode, only the system login class database is used.
213 When in user mode, the supplemental login class database in the
214 user's home directory is allowed to override settings from the system
215 database in a limited way as noted below.
216 To minimize security implications, user mode is entered by
217 .Fn login_getclassbyname
227 Otherwise system mode is chosen.
229 In system mode, any record in the system database
232 and a fallback to the default record is provided as follows.
237 an empty string, or a class that does not exist
238 in the login class database, then the
244 In user mode, only the
248 is accessed and no fallback to the
251 The directory specified by
254 a login database file called
259 contained within it may override the system record with the same name
260 while other records are ignored.
261 Using this scheme, an application can explicitly
262 allow users to override a selected subset of login settings.
263 To do so, the application should obtain two
265 objects, one in user mode and the other in system mode,
266 and then query the user object before the
267 system object for login parameters that are allowed to
268 be overridden by the user.
269 For example, the user's
271 can provide a convenient way for a user to set up their preferred
272 login environment before the shell is invoked on login if supported by
275 Note that access to the
279 files will only be performed subject to the security checks documented in
285 If the specified record is
287 empty or does not exist, and the
290 record available to fall back to, there is a
291 memory allocation error or for some reason
293 is unable to access the login capabilities database, this function
301 .Fn login_getuserclass
302 retrieve the applicable login class record for the user's passwd
303 entry or class name by calling
304 .Fn login_getclassbyname .
308 The difference between these functions is that
309 .Fn login_getuserclass
310 includes the user's overriding
312 that exists in the user's home directory, and
316 restrict lookup only to the system login class database in
317 .Pa /etc/login.conf .
318 As explained earlier,
322 in that it allows the default class for a super-user as
324 if none has been specified in the password database.
325 Otherwise, if the passwd pointer is
328 has no login class, then the system
332 .Fn login_getclass name
334 .Fn login_getclassbyname name NULL
336 .Fn login_getuserclass pwd
338 .Fn login_getclassbyname LOGIN_MECLASS pwd .
340 Once a program no longer wishes to use a
344 may be called to free all resources used by the login class.
347 function may be passed a
349 pointer with no harmful side-effects.
351 The remaining functions may be used to retrieve individual
353 Each function takes a
355 object as its first parameter,
356 a capability tag as the second, and remaining parameters being
357 default and error values that are returned if the capability is
359 The type of the additional parameters passed and returned depend
362 of capability each deals with, be it a simple string, a list,
363 a time value, a file or memory size value, a path (consisting of
364 a colon-separated list of directories) or a boolean flag.
367 deals in specific tags and their type.
369 Note that with all functions in this group, you should not call
371 on any pointers returned.
372 Memory allocated during retrieval or processing of capability
373 tags is automatically reused by subsequent calls to functions
374 in this group, or deallocated on calling
376 .Bl -tag -width "login_getcaplist()"
377 .It Fn login_getcapstr
378 This function returns a simple string capability.
379 If the string is not found, then the value in
381 is returned as the default value, or if an error
382 occurs, the value in the
384 parameter is returned.
385 .It Fn login_getcaplist
386 This function returns the value corresponding to the named
387 capability tag as a list of values in a
390 Within the login class database, some tags are of type
392 which consist of one or more comma- or space separated
394 Usually, this function is not called directly from an
395 application, but is used indirectly via
398 This function returns a list of directories separated by colons
400 Capability tags for which this function is called consist of a list of
401 directories separated by spaces.
402 .It Fn login_getcaptime
403 This function returns a
405 associated with a particular capability tag with the value expressed
406 in seconds (the default), minutes, hours, days, weeks or (365 day)
407 years or any combination of these.
408 A suffix determines the units used:
421 Case of the units suffix is ignored.
423 Time values are normally used for setting resource, accounting and
425 If supported by the operating system and compiler (which is true of
427 the value returned is a
436 may be used to express an infinite
440 .It Fn login_getcapnum
441 This function returns a numeric value for a tag, expressed either as
447 The first format should be used in preference to the second, the
448 second format is provided for compatibility and consistency with the
450 database format where numeric types use the
452 as the delimiter for numeric values.
453 If in the first format, then the value given may be
457 which results in a return value of
459 If the given capability tag cannot be found, the
461 parameter is returned, and if an error occurs, the
463 parameter is returned.
464 .It Fn login_getcapsize
466 returns a value representing a size (typically, file or memory)
467 which may be expressed as bytes (the default), 512 byte blocks,
468 kilobytes, megabytes, gigabytes, and on systems that support the
471 The suffix used determines the units, and multiple values and
472 units may be used in combination (e.g.\& 1m500k = 1.5 megabytes).
473 A value with no suffix is interpreted as bytes,
485 The error value is returned if there is a login capabilities database
486 error, if an invalid suffix is used, or if a numeric value cannot be
488 .It Fn login_getcapbool
489 This function returns a boolean value tied to a particular flag.
490 It returns 0 if the given capability tag is not present or is
491 negated by the presence of a
495 for more information on boolean flags), and returns 1 if the tag
497 .It Fn login_getstyle
498 This function is used by the login authorisation system to determine
499 the style of login available in a particular case.
500 The function accepts three parameters, the
503 two optional parameters, and authorisation type
508 applies these to determine the authorisation style that best suites
516 nor an empty string, look for a tag of type
517 .Ql auth- Ns Fa <auth>
518 in the capability record.
519 If not present, then look for the default tag
522 If no valid authorisation list was found from the previous step, then
525 as the authorisation list.
531 or empty, look for it in the list of authorisation
532 methods found from the previous step.
537 or an empty string, then default to
543 is found in the chosen list of authorisation methods, then
544 return that, otherwise return
548 This scheme allows the administrator to determine the types of
549 authorisation methods accepted by the system, depending on the
550 means by which the access occurs.
551 For example, the administrator may require skey or kerberos as
552 the authentication method used for access to the system via the
553 network, and standard methods via direct dialup or console
554 logins, significantly reducing the risk of password discovery
555 by "snooping" network packets.
556 .It Fn login_setcryptfmt
558 .Fn login_setcryptfmt
559 function is used to set the
564 If no entry is found,
566 is taken to be used as the fallback.
568 .Xr crypt_set_format 3
569 on the specifier fails,
571 is returned to indicate this.