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