]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libutil/login_cap.3
zfs: merge openzfs/zfs@a03ebd9be
[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 .Dd May 10, 2020
21 .Dt LOGIN_CAP 3
22 .Os
23 .Sh NAME
24 .Nm login_close ,
25 .Nm login_getcapbool ,
26 .Nm login_getcaplist ,
27 .Nm login_getcapnum ,
28 .Nm login_getcapstr ,
29 .Nm login_getcapsize ,
30 .Nm login_getcaptime ,
31 .Nm login_getclass ,
32 .Nm login_getclassbyname ,
33 .Nm login_getpwclass ,
34 .Nm login_getstyle ,
35 .Nm login_getuserclass ,
36 .Nm login_setcryptfmt
37 .Nd "functions for accessing the login class capabilities database"
38 .Sh LIBRARY
39 .Lb libutil
40 .Sh SYNOPSIS
41 .In sys/types.h
42 .In login_cap.h
43 .Ft void
44 .Fn login_close "login_cap_t *lc"
45 .Ft login_cap_t *
46 .Fn login_getclassbyname "const char *nam" "const struct passwd *pwd"
47 .Ft login_cap_t *
48 .Fn login_getclass "const char *nam"
49 .Ft login_cap_t *
50 .Fn login_getpwclass "const struct passwd *pwd"
51 .Ft login_cap_t *
52 .Fn login_getuserclass "const struct passwd *pwd"
53 .Ft "const char *"
54 .Fn login_getcapstr "login_cap_t *lc" "const char *cap" "const char *def" "const char *error"
55 .Ft "const char **"
56 .Fn login_getcaplist "login_cap_t *lc" "const char *cap" "const char *chars"
57 .Ft "const char *"
58 .Fn login_getpath "login_cap_t *lc" "const char *cap" "const char *error"
59 .Ft rlim_t
60 .Fn login_getcaptime "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
61 .Ft rlim_t
62 .Fn login_getcapnum "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
63 .Ft rlim_t
64 .Fn login_getcapsize "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error"
65 .Ft int
66 .Fn login_getcapbool "login_cap_t *lc" "const char *cap" "int def"
67 .Ft "const char *"
68 .Fn login_getstyle "login_cap_t *lc" "const char *style" "const char *auth"
69 .Ft const char *
70 .Fn login_setcryptfmt "login_cap_t *lc" "const char *def" "const char *error"
71 .Sh DESCRIPTION
72 These functions represent a programming interface to the login
73 classes database provided in
74 .Xr login.conf 5 .
75 This database contains capabilities, attributes and default environment
76 and accounting settings for users and programs running as specific users,
77 as determined by the login class field within entries in
78 .Pa /etc/master.passwd .
79 .Pp
80 Entries in
81 .Xr login.conf 5
82 consist of colon
83 .Ql \&:
84 separated fields, the first field in each record being one or more
85 identifiers for the record (which must be unique for the entire database),
86 each separated by a
87 .Ql | ,
88 and may optionally include a description as
89 the last
90 .Sq name .
91 Remaining fields in the record consist of keyword/data pairs.
92 Long lines may be continued with a backslash within empty entries,
93 with the second and subsequent lines optionally indented for readability.
94 This is similar to the format used in
95 .Xr termcap 5 ,
96 except that keywords are not limited to two significant characters,
97 and are usually longer for improved readability.
98 As with termcap entries, multiple records can be linked together
99 (one record including another) using a field containing
100 .Ql tc= Ns Va <recordid> .
101 The result is that the entire record referenced by
102 .Va <recordid>
103 replaces the
104 .Va tc=
105 field at the point at which it occurs.
106 See
107 .Xr getcap 3
108 for further details on the format and use of a capabilities database.
109 .Pp
110 The
111 .Nm login_cap
112 interface provides a convenient means of retrieving login class
113 records with all
114 .Va tc=
115 references expanded.
116 A program will typically call one of
117 .Fn login_getclass ,
118 .Fn login_getpwclass ,
119 .Fn login_getuserclass
120 or
121 .Fn login_getclassbyname
122 according to its requirements.
123 Each of these functions returns a login capabilities structure,
124 .Vt login_cap_t ,
125 which may subsequently be used to interrogate the database for
126 specific values using the rest of the API.
127 Once the
128 .Vt login_cap_t
129 is of no further use, the
130 .Fn login_close
131 function should be called to free all resources used.
132 .Pp
133 The structure of
134 .Vt login_cap_t
135 is defined in
136 .In login_cap.h ,
137 as:
138 .Bd -literal -offset indent
139 typedef struct {
140         char *lc_class;
141         char *lc_cap;
142         char *lc_style;
143 } login_cap_t;
144 .Ed
145 .Pp
146 The
147 .Fa lc_class
148 member contains a pointer to the name of the login class
149 retrieved.
150 This may not necessarily be the same as the one requested,
151 either directly via
152 .Fn login_getclassbyname ,
153 or indirectly via a user's login record using
154 .Fn login_getpwclass ,
155 by class name using
156 .Fn login_getclass .
157 If the referenced user has no login class specified in
158 .Pa /etc/master.passwd ,
159 the class name is
160 .Dv NULL
161 or an empty string.
162 If the class
163 specified does not exist in the database, each of these
164 functions will search for a record with an id of
165 .Ql default ,
166 with that name returned in the
167 .Fa lc_class
168 field.
169 In addition, if the referenced user has a UID of 0 (normally,
170 .Ql root ,
171 although the user name is not considered) then
172 .Fn login_getpwclass
173 will search for a record with an id of
174 .Ql root
175 before it searches
176 for the record with the id of
177 .Ql default .
178 .Pp
179 The
180 .Fa lc_cap
181 field is used internally by the library to contain the
182 expanded login capabilities record.
183 Programs with unusual requirements may wish to use this
184 with the lower-level
185 .Fn getcap
186 style functions to access the record directly.
187 .Pp
188 The
189 .Fa lc_style
190 field is set by the
191 .Fn login_getstyle
192 function to the authorisation style, according to the requirements
193 of the program handling a login itself.
194 .Pp
195 The
196 .Fn login_getclassbyname
197 function is the basic means to get a
198 .Vt login_cap_t
199 object.
200 It accepts two arguments: the first one,
201 .Fa name ,
202 is the record identifier of the
203 record to be retrieved; the second,
204 .Fa pwd ,
205 is an optional pointer to a
206 .Vt passwd
207 structure.
208 First of all, its arguments are used by the function
209 to choose between system and user modes of operation.
210 When in system mode, only the system login class database is used.
211 When in user mode, the supplemental login class database in the
212 user's home directory is allowed to override settings from the system
213 database in a limited way as noted below.
214 To minimize security implications, user mode is entered by
215 .Fn login_getclassbyname
216 if and only if
217 .Fa name
218 is
219 .Dv LOGIN_MECLASS
220 .Pq Ql me
221 and
222 .Fa pwd
223 is not
224 .Dv NULL .
225 Otherwise system mode is chosen.
226 .Pp
227 In system mode, any record in the system database
228 .Pa /etc/login.conf
229 can be accessed,
230 and a fallback to the default record is provided as follows.
231 If
232 .Fa name
233 is
234 .Dv NULL ,
235 an empty string, or a class that does not exist
236 in the login class database, then the
237 .Dv LOGIN_DEFCLASS
238 record
239 .Pq Ql default
240 is returned instead.
241 .Pp
242 In user mode, only the
243 .Dv LOGIN_MECLASS
244 record
245 .Pq Ql me
246 is accessed and no fallback to the
247 .Ql default
248 record is provided.
249 The directory specified by
250 .Fa pwd->pw_dir
251 is searched for
252 a login database file called
253 .Pa .login_conf ,
254 and only the
255 .Ql me
256 capability record
257 contained within it may override the system record with the same name
258 while other records are ignored.
259 Using this scheme, an application can explicitly
260 allow users to override a selected subset of login settings.
261 To do so, the application should obtain two
262 .Vt login_cap_t
263 objects, one in user mode and the other in system mode,
264 and then query the user object before the
265 system object for login parameters that are allowed to
266 be overridden by the user.
267 For example, the user's
268 .Pa .login_conf
269 can provide a convenient way for a user to set up their preferred
270 login environment before the shell is invoked on login if supported by
271 .Xr login 1 .
272 .Pp
273 Note that access to the
274 .Pa /etc/login.conf
275 and
276 .Pa .login_conf
277 files will only be performed subject to the security checks documented in
278 .Xr _secure_path 3
279 for the uids 0 and
280 .Fa pwd->pw_uid
281 respectively.
282 .Pp
283 If the specified record is
284 .Dv NULL ,
285 empty or does not exist, and the
286 system has no
287 .Ql default
288 record available to fall back to, there is a
289 memory allocation error or for some reason
290 .Xr cgetent 3
291 is unable to access the login capabilities database, this function
292 returns
293 .Dv NULL .
294 .Pp
295 The functions
296 .Fn login_getclass ,
297 .Fn login_getpwclass
298 and
299 .Fn login_getuserclass
300 retrieve the applicable login class record for the user's passwd
301 entry or class name by calling
302 .Fn login_getclassbyname .
303 On failure,
304 .Dv NULL
305 is returned.
306 The difference between these functions is that
307 .Fn login_getuserclass
308 includes the user's overriding
309 .Pa .login_conf
310 that exists in the user's home directory, and
311 .Fn login_getpwclass
312 and
313 .Fn login_getclass
314 restrict lookup only to the system login class database in
315 .Pa /etc/login.conf .
316 As explained earlier,
317 .Fn login_getpwclass
318 differs from
319 .Fn login_getclass
320 in that it allows the default class for a super-user as
321 .Ql root
322 if none has been specified in the password database.
323 Otherwise, if the passwd pointer is
324 .Dv NULL ,
325 or the user record
326 has no login class, then the system
327 .Ql default
328 entry is retrieved.
329 Essentially,
330 .Fn login_getclass name
331 is equivalent to
332 .Fn login_getclassbyname name NULL
333 and
334 .Fn login_getuserclass pwd
335 to
336 .Fn login_getclassbyname LOGIN_MECLASS pwd .
337 .Pp
338 Once a program no longer wishes to use a
339 .Vt login_cap_t
340 object,
341 .Fn login_close
342 may be called to free all resources used by the login class.
343 The
344 .Fn login_close
345 function may be passed a
346 .Dv NULL
347 pointer with no harmful side-effects.
348 .Pp
349 The remaining functions may be used to retrieve individual
350 capability records.
351 Each function takes a
352 .Vt login_cap_t
353 object as its first parameter,
354 a capability tag as the second, and remaining parameters being
355 default and error values that are returned if the capability is
356 not found.
357 The type of the additional parameters passed and returned depend
358 on the
359 .Em type
360 of capability each deals with, be it a simple string, a list,
361 a time value, a file or memory size value, a path (consisting of
362 a colon-separated list of directories) or a boolean flag.
363 The manpage for
364 .Xr login.conf 5
365 deals in specific tags and their type.
366 .Pp
367 Note that with all functions in this group, you should not call
368 .Xr free 3
369 on any pointers returned.
370 Memory allocated during retrieval or processing of capability
371 tags is automatically reused by subsequent calls to functions
372 in this group, or deallocated on calling
373 .Fn login_close .
374 .Bl -tag -width "login_getcaplist()"
375 .It Fn login_getcapstr
376 This function returns a simple string capability.
377 If the string is not found, then the value in
378 .Fa def
379 is returned as the default value, or if an error
380 occurs, the value in the
381 .Fa error
382 parameter is returned.
383 .It Fn login_getcaplist
384 This function returns the value corresponding to the named
385 capability tag as a list of values in a
386 .Dv NULL
387 terminated array.
388 Within the login class database, some tags are of type
389 .Vt list ,
390 which consist of one or more comma- or space separated
391 values.
392 Usually, this function is not called directly from an
393 application, but is used indirectly via
394 .Fn login_getstyle .
395 .It Fn login_getpath
396 This function returns a list of directories separated by colons
397 .Ql \&: .
398 Capability tags for which this function is called consist of a list of
399 directories separated by spaces.
400 .It Fn login_getcaptime
401 This function returns a
402 .Vt time value
403 associated with a particular capability tag with the value expressed
404 in seconds (the default), minutes, hours, days, weeks or (365 day)
405 years or any combination of these.
406 A suffix determines the units used:
407 .Ql S
408 for seconds,
409 .Ql M
410 for minutes,
411 .Ql H
412 for hours,
413 .Ql D
414 for days,
415 .Ql W
416 for weeks and
417 .Ql Y
418 for 365 day years.
419 Case of the units suffix is ignored.
420 .Pp
421 Time values are normally used for setting resource, accounting and
422 session limits.
423 If supported by the operating system and compiler (which is true of
424 .Fx ) ,
425 the value returned is a
426 .Vt quad
427 .Pq Vt long long ,
428 of type
429 .Vt rlim_t .
430 A value
431 .Ql inf
432 or
433 .Ql infinity
434 may be used to express an infinite
435 value, in which case
436 .Dv RLIM_INFINITY
437 is returned.
438 .It Fn login_getcapnum
439 This function returns a numeric value for a tag, expressed either as
440 .Ql tag=<value>
441 or the standard
442 .Fn cgetnum
443 format
444 .Ql tag#<value> .
445 The first format should be used in preference to the second, the
446 second format is provided for compatibility and consistency with the
447 .Xr getcap 3
448 database format where numeric types use the
449 .Ql \&#
450 as the delimiter for numeric values.
451 If in the first format, then the value given may be
452 .Ql inf
453 or
454 .Ql infinity
455 which results in a return value of
456 .Dv RLIM_INFINITY .
457 If the given capability tag cannot be found, the
458 .Fa def
459 parameter is returned, and if an error occurs, the
460 .Fa error
461 parameter is returned.
462 .It Fn login_getcapsize
463 .Fn login_getcapsize
464 returns a value representing a size (typically, file or memory)
465 which may be expressed as bytes (the default), 512 byte blocks,
466 kilobytes, megabytes, gigabytes, and on systems that support the
467 .Vt long long
468 type, terabytes.
469 The suffix used determines the units, and multiple values and
470 units may be used in combination (e.g.\& 1m500k = 1.5 megabytes).
471 A value with no suffix is interpreted as bytes,
472 .Ql B
473 as 512-byte blocks,
474 .Ql K
475 as kilobytes,
476 .Ql M
477 as megabytes,
478 .Ql G
479 as gigabytes and
480 .Ql T
481 as terabytes.
482 Case is ignored.
483 The error value is returned if there is a login capabilities database
484 error, if an invalid suffix is used, or if a numeric value cannot be
485 interpreted.
486 .It Fn login_getcapbool
487 This function returns a boolean value tied to a particular flag.
488 It returns 0 if the given capability tag is not present or is
489 negated by the presence of a
490 .Ql tag@
491 (see
492 .Xr getcap 3
493 for more information on boolean flags), and returns 1 if the tag
494 is found.
495 .It Fn login_getstyle
496 This function is used by the login authorisation system to determine
497 the style of login available in a particular case.
498 The function accepts three parameters, the
499 .Fa lc
500 entry itself and
501 two optional parameters, and authorisation type
502 .Fa auth
503 and
504 .Fa style ,
505 and
506 applies these to determine the authorisation style that best suites
507 these rules.
508 .Bl -bullet
509 .It
510 If
511 .Fa auth
512 is neither
513 .Dv NULL
514 nor an empty string, look for a tag of type
515 .Ql auth- Ns Fa <auth>
516 in the capability record.
517 If not present, then look for the default tag
518 .Va auth= .
519 .It
520 If no valid authorisation list was found from the previous step, then
521 default to
522 .Ql passwd
523 as the authorisation list.
524 .It
525 If
526 .Fa style
527 is not
528 .Dv NULL
529 or empty, look for it in the list of authorisation
530 methods found from the previous step.
531 If
532 .Fa style
533 is
534 .Dv NULL
535 or an empty string, then default to
536 .Ql passwd
537 authorisation.
538 .It
539 If
540 .Fa style
541 is found in the chosen list of authorisation methods, then
542 return that, otherwise return
543 .Dv NULL .
544 .El
545 .Pp
546 This scheme allows the administrator to determine the types of
547 authorisation methods accepted by the system, depending on the
548 means by which the access occurs.
549 For example, the administrator may require skey or kerberos as
550 the authentication method used for access to the system via the
551 network, and standard methods via direct dialup or console
552 logins, significantly reducing the risk of password discovery
553 by "snooping" network packets.
554 .It Fn login_setcryptfmt
555 The
556 .Fn login_setcryptfmt
557 function is used to set the
558 .Xr crypt 3
559 format using the
560 .Va passwd_format
561 configuration entry.
562 If no entry is found,
563 .Fa def
564 is taken to be used as the fallback.
565 If calling
566 .Xr crypt_set_format 3
567 on the specifier fails,
568 .Fa error
569 is returned to indicate this.
570 .El
571 .Sh SEE ALSO
572 .Xr login 1 ,
573 .Xr crypt 3 ,
574 .Xr getcap 3 ,
575 .Xr login_class 3 ,
576 .Xr login.conf 5 ,
577 .Xr termcap 5
578 .Sh HISTORY
579 The functions
580 .Fn login_close ,
581 .Fn login_getcapbool ,
582 .Fn login_getcaplist ,
583 .Fn login_getcapnum ,
584 .Fn login_getcapstr ,
585 .Fn login_getcapsize ,
586 .Fn login_getcaptime ,
587 .Fn login_getclass ,
588 .Fn login_getclassbyname ,
589 .Fn login_getpwclass ,
590 .Fn login_getstyle ,
591 .Fn login_getuserclass
592 and
593 .Fn login_setcryptfmt
594 first appeared in
595 .Fx 2.1.5 .