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