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$ 21.\" 22.Dd December 28, 1996 23.Os FreeBSD 24.Dt LOGIN_CLASS 3 25.Sh NAME 26.Nm setclasscontext , 27.Nm setusercontext , 28.Nm setclassresources , 29.Nm setclassenvironment 30.Nd functions for using the login class capabilities database. 31.Sh SYNOPSIS 32.Fd #include <sys/types.h> 33.Fd #include <login_cap.h> 34.Ft int 35.Fn setclasscontext "char *classname" "unsigned int flags" 36.Ft int 37.Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags" 38.Ft void 39.Fn setclassresources "login_cap_t *lc" 40.Ft void 41.Fn setclassenvironment "login_cap_t *lc" "const struct passwd *pwd" "int paths" 42.Pp 43.Sh DESCRIPTION 44These functions provide a higher level interface to the login class 45database than those documented in 46.Xr login_cap 3 . 47These functions are used to set resource limits, environment and 48accounting settings for users on logging into the system and when 49selecting an appropriate set of environment and resource settings 50for system daemons based on login classes. 51These functions may only be called if the current process is 52running with root priviledges. 53If the LOGIN_SETLOGIN flag is used this function calls 54.Xr setlogin 2 , 55and due care must be taken as detailed in the manpage for that 56function and this affects all processes running in the same session 57and not just the current process. 58.Pp 59.Fn setclasscontext 60sets various class context values (resource limits, umask and 61process priorities) based on values for a specific named class. 62.Pp 63The function 64.Fn setusercontext 65sets class context values based on a given login_cap_t 66object, a specific passwd record (if login_cap_t is NULL), 67sets the current session's login and the current process 68user and group ownership. 69Each of these functions is selectable via bit-flags passed 70in the 71.Ar flags 72parameter, which is comprised of one or more of the following: 73.Bl -tag -width LOGIN_SETRESOURCES 74.It LOGIN_SETLOGIN 75Set the login associated with the current session to the user 76specified in the passwd structure. 77.Xr setlogin 2 . 78The 79.Ar pwd 80parameter must not be NULL if this option is used. 81.It LOGIN_SETUSER 82Set ownship of the current process to the uid specified in the 83.Ar uid 84parameter using 85.Xr setuid 2 . 86.It LOGIN_SETGROUP 87Set group ownership of the current process to the group id 88specified in the passwd structure using 89.Xr setgid 2 , 90and calls 91.Xr initgroups 3 92to set up the group access list for the current process. 93The 94.Ar pwd 95parameter must not be NULL if this option is used. 96.It LOGIN_SETRESOURCES 97Set resource limits for the current process based on values 98specified in the system login class database. 99Class capability tags used, with and without -cur (soft limit) 100or -max (hard limit) suffixes and the corresponding resource 101setting: 102.Bd -literal 103cputime RLIMIT_CPU 104filesize RLIMIT_FSIZE 105datasize RLIMIT_DATA 106stacksize RLIMIT_STACK 107coredumpsize RLIMIT_CORE 108memoryuse RLIMIT_RSS 109memorylocked RLIMIT_MEMLOCK 110maxproc RLIMIT_NPROC 111openfiles RLIMIT_NOFILE 112.Ed 113.It LOGIN_SETPRIORITY 114Set the scheduling priority for the current process based on the 115value specified in the system login class database. 116Class capability tags used: 117.Bd -literal 118priority 119.Ed 120.It LOGIN_SETUMASK 121Set the umask for the current process to a value in the user or 122system login class database. 123Class capability tags used: 124.Bd -literal 125umask 126.Ed 127.It LOGIN_SETPATH 128Set the "path" and "manpath" environment variables based on values 129in the user or system login class database. 130Class capability tags used with the corresponding environment 131variables set: 132.Bd -literal 133path PATH 134manpath MANPATH 135.Ed 136.It LOGIN_SETENV 137Set various environment variables based on values in the user or 138system login class database. 139Class capability tags used with the corresponding environment 140variables set: 141.Bd -literal 142lang LANG 143charset MM_CHARSET 144timezone TZ 145term TERM 146.Ed 147.Pp 148Additional environment variables may be set using the list type 149capability "setenv=var1 val1,var2 val2..,varN valN". 150.It LOGIN_SETALL 151Enables all of the above settings. 152.El 153.Pp 154Note that when setting environment variables and a valid passwd 155pointer is provided in the 156.Ar pwd 157parameter, the characters 158.Ql \&~ 159and 160.Ql \&$ 161are substituted for the user's home directory and login name 162respectively. 163.Pp 164The 165.Fn setclassresources 166and 167.Fn setclassenvironment 168functions are subsets of the setcontext functions above, but may 169be useful in isolation. 170.Sh RETURN VALUES 171.Fn setclasscontext 172and 173.Fn setusercontext 174return -1 if an error occured, or 0 on success. 175If an error occurs when attempting to set the user, login, group 176or resources, a message is reported to 177.Xr syslog 3 , 178with LOG_ERR priority and directed to the currently active facility. 179.Sh SEE ALSO 180.Xr setgid 2 , 181.Xr setlogin 2 , 182.Xr setuid 2 , 183.Xr getcap 3 , 184.Xr initgroups 3 , 185.Xr login_cap 3 , 186.Xr login.conf 5 , 187.Xr termcap 5 188