11eaf0ac3Slogwang.\" Copyright (c) 1995 David Nugent <[email protected]> 21eaf0ac3Slogwang.\" All rights reserved. 31eaf0ac3Slogwang.\" 41eaf0ac3Slogwang.\" Redistribution and use in source and binary forms, with or without 51eaf0ac3Slogwang.\" modification, is permitted provided that the following conditions 61eaf0ac3Slogwang.\" are met: 71eaf0ac3Slogwang.\" 1. Redistributions of source code must retain the above copyright 81eaf0ac3Slogwang.\" notice immediately at the beginning of the file, without modification, 91eaf0ac3Slogwang.\" this list of conditions, and the following disclaimer. 101eaf0ac3Slogwang.\" 2. Redistributions in binary form must reproduce the above copyright 111eaf0ac3Slogwang.\" notice, this list of conditions and the following disclaimer in the 121eaf0ac3Slogwang.\" documentation and/or other materials provided with the distribution. 131eaf0ac3Slogwang.\" 3. This work was done expressly for inclusion into FreeBSD. Other use 141eaf0ac3Slogwang.\" is permitted provided this notation is included. 151eaf0ac3Slogwang.\" 4. Absolutely no warranty of function or purpose is made by the author 161eaf0ac3Slogwang.\" David Nugent. 171eaf0ac3Slogwang.\" 5. Modifications may be freely made to this file providing the above 181eaf0ac3Slogwang.\" conditions are met. 191eaf0ac3Slogwang.\" 201eaf0ac3Slogwang.\" $FreeBSD$ 211eaf0ac3Slogwang.\" 22*22ce4affSfengbojiang.Dd May 10, 2020 231eaf0ac3Slogwang.Dt LOGIN_CLASS 3 241eaf0ac3Slogwang.Os 251eaf0ac3Slogwang.Sh NAME 261eaf0ac3Slogwang.Nm setclasscontext , 271eaf0ac3Slogwang.Nm setclasscpumask , 281eaf0ac3Slogwang.Nm setclassenvironment , 291eaf0ac3Slogwang.Nm setclassresources , 301eaf0ac3Slogwang.Nm setusercontext 311eaf0ac3Slogwang.Nd "functions for using the login class capabilities database" 321eaf0ac3Slogwang.Sh LIBRARY 331eaf0ac3Slogwang.Lb libutil 341eaf0ac3Slogwang.Sh SYNOPSIS 351eaf0ac3Slogwang.In sys/types.h 361eaf0ac3Slogwang.In login_cap.h 371eaf0ac3Slogwang.Ft int 381eaf0ac3Slogwang.Fn setclasscontext "const char *classname" "unsigned int flags" 391eaf0ac3Slogwang.Ft void 401eaf0ac3Slogwang.Fn setclasscpumask "login_cap_t *lc" 411eaf0ac3Slogwang.Ft void 421eaf0ac3Slogwang.Fn setclassenvironment "login_cap_t *lc" "const struct passwd *pwd" "int paths" 431eaf0ac3Slogwang.Ft void 441eaf0ac3Slogwang.Fn setclassresources "login_cap_t *lc" 451eaf0ac3Slogwang.Ft int 461eaf0ac3Slogwang.Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags" 471eaf0ac3Slogwang.Sh DESCRIPTION 481eaf0ac3SlogwangThese functions provide a higher level interface to the login class 491eaf0ac3Slogwangdatabase than those documented in 501eaf0ac3Slogwang.Xr login_cap 3 . 511eaf0ac3SlogwangThese functions are used to set resource limits, environment and 521eaf0ac3Slogwangaccounting settings for users on logging into the system and when 531eaf0ac3Slogwangselecting an appropriate set of environment and resource settings 541eaf0ac3Slogwangfor system daemons based on login classes. 551eaf0ac3SlogwangThese functions may only be called if the current process is 561eaf0ac3Slogwangrunning with root privileges. 571eaf0ac3SlogwangIf the LOGIN_SETLOGIN flag is used this function calls 581eaf0ac3Slogwang.Xr setlogin 2 , 591eaf0ac3Slogwangand due care must be taken as detailed in the manpage for that 601eaf0ac3Slogwangfunction and this affects all processes running in the same session 611eaf0ac3Slogwangand not just the current process. 621eaf0ac3Slogwang.Pp 631eaf0ac3SlogwangThe 641eaf0ac3Slogwang.Fn setclasscontext 651eaf0ac3Slogwangfunction sets various class context values (resource limits, umask and 661eaf0ac3Slogwangprocess priorities) based on values for a specific named class. 671eaf0ac3Slogwang.Pp 681eaf0ac3SlogwangThe 691eaf0ac3Slogwang.Fn setusercontext 701eaf0ac3Slogwangfunction sets class context values based on a given login_cap_t 711eaf0ac3Slogwangobject and a specific passwd record (if login_cap_t is NULL), 721eaf0ac3Slogwangthe current session's login, and the current process 731eaf0ac3Slogwanguser and group ownership. 741eaf0ac3SlogwangEach of these actions is selectable via bit-flags passed 751eaf0ac3Slogwangin the 761eaf0ac3Slogwang.Ar flags 771eaf0ac3Slogwangparameter, which is comprised of one or more of the following: 781eaf0ac3Slogwang.Bl -tag -width LOGIN_SETLOGINCLASS 791eaf0ac3Slogwang.It LOGIN_SETLOGIN 801eaf0ac3SlogwangSet the login associated with the current session to the user 811eaf0ac3Slogwangspecified in the passwd structure using 821eaf0ac3Slogwang.Xr setlogin 2 . 831eaf0ac3SlogwangThe 841eaf0ac3Slogwang.Ar pwd 851eaf0ac3Slogwangparameter must not be NULL if this option is used. 861eaf0ac3Slogwang.It LOGIN_SETUSER 871eaf0ac3SlogwangSet ownership of the current process to the uid specified in the 881eaf0ac3Slogwang.Ar uid 891eaf0ac3Slogwangparameter using 901eaf0ac3Slogwang.Xr setuid 2 . 911eaf0ac3Slogwang.It LOGIN_SETGROUP 921eaf0ac3SlogwangSet group ownership of the current process to the group id 931eaf0ac3Slogwangspecified in the passwd structure using 941eaf0ac3Slogwang.Xr setgid 2 , 951eaf0ac3Slogwangand calls 961eaf0ac3Slogwang.Xr initgroups 3 971eaf0ac3Slogwangto set up the group access list for the current process. 981eaf0ac3SlogwangThe 991eaf0ac3Slogwang.Ar pwd 1001eaf0ac3Slogwangparameter must not be NULL if this option is used. 1011eaf0ac3Slogwang.It LOGIN_SETRESOURCES 1021eaf0ac3SlogwangSet resource limits for the current process based on values 1031eaf0ac3Slogwangspecified in the system login class database. 1041eaf0ac3SlogwangClass capability tags used, with and without -cur (soft limit) 1051eaf0ac3Slogwangor -max (hard limit) suffixes and the corresponding resource 1061eaf0ac3Slogwangsetting: 1071eaf0ac3Slogwang.Bd -literal 1081eaf0ac3Slogwangcputime RLIMIT_CPU 1091eaf0ac3Slogwangfilesize RLIMIT_FSIZE 1101eaf0ac3Slogwangdatasize RLIMIT_DATA 1111eaf0ac3Slogwangstacksize RLIMIT_STACK 1121eaf0ac3Slogwangcoredumpsize RLIMIT_CORE 1131eaf0ac3Slogwangmemoryuse RLIMIT_RSS 1141eaf0ac3Slogwangmemorylocked RLIMIT_MEMLOCK 1151eaf0ac3Slogwangmaxproc RLIMIT_NPROC 1161eaf0ac3Slogwangopenfiles RLIMIT_NOFILE 1171eaf0ac3Slogwangsbsize RLIMIT_SBSIZE 1181eaf0ac3Slogwangvmemoryuse RLIMIT_VMEM 1191eaf0ac3Slogwangpseudoterminals RLIMIT_NPTS 1201eaf0ac3Slogwangswapuse RLIMIT_SWAP 1211eaf0ac3Slogwangkqueues RLIMIT_KQUEUES 1221eaf0ac3Slogwangumtxp RLIMIT_UMTXP 1231eaf0ac3Slogwang.Ed 1241eaf0ac3Slogwang.It LOGIN_SETPRIORITY 1251eaf0ac3SlogwangSet the scheduling priority for the current process based on the 1261eaf0ac3Slogwangvalue specified in the system login class database. 1271eaf0ac3SlogwangClass capability tags used: 1281eaf0ac3Slogwang.Bd -literal 1291eaf0ac3Slogwangpriority 1301eaf0ac3Slogwang.Ed 1311eaf0ac3Slogwang.It LOGIN_SETUMASK 1321eaf0ac3SlogwangSet the umask for the current process to a value in the user or 1331eaf0ac3Slogwangsystem login class database. 1341eaf0ac3SlogwangClass capability tags used: 1351eaf0ac3Slogwang.Bd -literal 1361eaf0ac3Slogwangumask 1371eaf0ac3Slogwang.Ed 1381eaf0ac3Slogwang.It LOGIN_SETPATH 1391eaf0ac3SlogwangSet the "path" and "manpath" environment variables based on values 1401eaf0ac3Slogwangin the user or system login class database. 1411eaf0ac3SlogwangClass capability tags used with the corresponding environment 1421eaf0ac3Slogwangvariables set: 1431eaf0ac3Slogwang.Bd -literal 1441eaf0ac3Slogwangpath PATH 1451eaf0ac3Slogwangmanpath MANPATH 1461eaf0ac3Slogwang.Ed 1471eaf0ac3Slogwang.It LOGIN_SETENV 1481eaf0ac3SlogwangSet various environment variables based on values in the user or 1491eaf0ac3Slogwangsystem login class database. 1501eaf0ac3SlogwangClass capability tags used with the corresponding environment 1511eaf0ac3Slogwangvariables set: 1521eaf0ac3Slogwang.Bd -literal 1531eaf0ac3Slogwanglang LANG 1541eaf0ac3Slogwangcharset MM_CHARSET 1551eaf0ac3Slogwangtimezone TZ 1561eaf0ac3Slogwangterm TERM 1571eaf0ac3Slogwang.Ed 1581eaf0ac3Slogwang.Pp 1591eaf0ac3SlogwangAdditional environment variables may be set using the list type 1601eaf0ac3Slogwangcapability "setenv=var1 val1,var2 val2..,varN valN". 1611eaf0ac3Slogwang.It LOGIN_SETMAC 1621eaf0ac3SlogwangSet the MAC label for the current process to the label specified 1631eaf0ac3Slogwangin system login class database. 1641eaf0ac3Slogwang.It LOGIN_SETCPUMASK 1651eaf0ac3SlogwangCreate a new 1661eaf0ac3Slogwang.Xr cpuset 2 1671eaf0ac3Slogwangand set the cpu affinity to the specified mask. 1681eaf0ac3SlogwangThe string may contain a comma separated list of numbers and/or number 1691eaf0ac3Slogwangranges as handled by the 1701eaf0ac3Slogwang.Xr cpuset 1 1711eaf0ac3Slogwangutility or the case-insensitive string 1721eaf0ac3Slogwang.Ql default . 1731eaf0ac3SlogwangIf the string is 1741eaf0ac3Slogwang.Ql default 1751eaf0ac3Slogwangno action will be taken. 1761eaf0ac3Slogwang.It LOGIN_SETLOGINCLASS 1771eaf0ac3SlogwangSet the login class of the current process using 1781eaf0ac3Slogwang.Xr setloginclass 2 . 1791eaf0ac3Slogwang.It LOGIN_SETALL 1801eaf0ac3SlogwangEnables all of the above settings. 1811eaf0ac3Slogwang.El 1821eaf0ac3Slogwang.Pp 1831eaf0ac3SlogwangNote that when setting environment variables and a valid passwd 1841eaf0ac3Slogwangpointer is provided in the 1851eaf0ac3Slogwang.Ar pwd 1861eaf0ac3Slogwangparameter, the characters 1871eaf0ac3Slogwang.Ql \&~ 1881eaf0ac3Slogwangand 1891eaf0ac3Slogwang.Ql \&$ 1901eaf0ac3Slogwangare substituted for the user's home directory and login name 1911eaf0ac3Slogwangrespectively. 1921eaf0ac3Slogwang.Pp 1931eaf0ac3SlogwangThe 1941eaf0ac3Slogwang.Fn setclasscpumask , 1951eaf0ac3Slogwang.Fn setclassresources 1961eaf0ac3Slogwangand 1971eaf0ac3Slogwang.Fn setclassenvironment 1981eaf0ac3Slogwangfunctions are subsets of the setcontext functions above, but may 1991eaf0ac3Slogwangbe useful in isolation. 2001eaf0ac3Slogwang.Sh RETURN VALUES 2011eaf0ac3SlogwangThe 2021eaf0ac3Slogwang.Fn setclasscontext 2031eaf0ac3Slogwangand 2041eaf0ac3Slogwang.Fn setusercontext 2051eaf0ac3Slogwangfunctions return -1 if an error occurred, or 0 on success. 2061eaf0ac3SlogwangIf an error occurs when attempting to set the user, login, group 2071eaf0ac3Slogwangor resources, a message is reported to 2081eaf0ac3Slogwang.Xr syslog 3 , 2091eaf0ac3Slogwangwith LOG_ERR priority and directed to the currently active facility. 2101eaf0ac3Slogwang.Sh SEE ALSO 2111eaf0ac3Slogwang.Xr cpuset 1 , 2121eaf0ac3Slogwang.Xr ps 1 , 2131eaf0ac3Slogwang.Xr cpuset 2 , 2141eaf0ac3Slogwang.Xr setgid 2 , 2151eaf0ac3Slogwang.Xr setlogin 2 , 2161eaf0ac3Slogwang.Xr setloginclass 2 , 2171eaf0ac3Slogwang.Xr setuid 2 , 2181eaf0ac3Slogwang.Xr getcap 3 , 2191eaf0ac3Slogwang.Xr initgroups 3 , 2201eaf0ac3Slogwang.Xr login_cap 3 , 2211eaf0ac3Slogwang.Xr mac_set_proc 3 , 2221eaf0ac3Slogwang.Xr login.conf 5 , 2231eaf0ac3Slogwang.Xr termcap 5 224*22ce4affSfengbojiang.Sh HISTORY 225*22ce4affSfengbojiangThe functions 226*22ce4affSfengbojiang.Fn setclasscontext , 227*22ce4affSfengbojiang.Fn setclasscpumask , 228*22ce4affSfengbojiang.Fn setclassenvironment , 229*22ce4affSfengbojiang.Fn setclassresources 230*22ce4affSfengbojiangand 231*22ce4affSfengbojiang.Fn setusercontext 232*22ce4affSfengbojiangfirst appeared in 233*22ce4affSfengbojiang.Fx 2.1.5 . 234