168bbf3adSDavid Nugent.\" Copyright (c) 1995 David Nugent <davidn@blaze.net.au> 268bbf3adSDavid Nugent.\" All rights reserved. 368bbf3adSDavid Nugent.\" 468bbf3adSDavid Nugent.\" Redistribution and use in source and binary forms, with or without 568bbf3adSDavid Nugent.\" modification, is permitted provided that the following conditions 668bbf3adSDavid Nugent.\" are met: 768bbf3adSDavid Nugent.\" 1. Redistributions of source code must retain the above copyright 868bbf3adSDavid Nugent.\" notice immediately at the beginning of the file, without modification, 968bbf3adSDavid Nugent.\" this list of conditions, and the following disclaimer. 1068bbf3adSDavid Nugent.\" 2. Redistributions in binary form must reproduce the above copyright 1168bbf3adSDavid Nugent.\" notice, this list of conditions and the following disclaimer in the 1268bbf3adSDavid Nugent.\" documentation and/or other materials provided with the distribution. 1368bbf3adSDavid Nugent.\" 3. This work was done expressly for inclusion into FreeBSD. Other use 1468bbf3adSDavid Nugent.\" is permitted provided this notation is included. 1568bbf3adSDavid Nugent.\" 4. Absolutely no warranty of function or purpose is made by the author 1668bbf3adSDavid Nugent.\" David Nugent. 1768bbf3adSDavid Nugent.\" 5. Modifications may be freely made to this file providing the above 1868bbf3adSDavid Nugent.\" conditions are met. 1968bbf3adSDavid Nugent.\" 20bc89b58dSGordon Bergling.Dd May 10, 2020 2168bbf3adSDavid Nugent.Dt LOGIN_CLASS 3 22aa12cea2SUlrich Spörlein.Os 2368bbf3adSDavid Nugent.Sh NAME 2468bbf3adSDavid Nugent.Nm setclasscontext , 2592657d3cSDag-Erling Smørgrav.Nm setclasscpumask , 263dc329d1SAlexey Zelkin.Nm setclassenvironment , 2768bbf3adSDavid Nugent.Nm setclassresources , 283dc329d1SAlexey Zelkin.Nm setusercontext 29eb083802SRuslan Ermilov.Nd "functions for using the login class capabilities database" 303dc329d1SAlexey Zelkin.Sh LIBRARY 313dc329d1SAlexey Zelkin.Lb libutil 3268bbf3adSDavid Nugent.Sh SYNOPSIS 3332eef9aeSRuslan Ermilov.In sys/types.h 3432eef9aeSRuslan Ermilov.In login_cap.h 3568bbf3adSDavid Nugent.Ft int 36c5a44d91SBruce Evans.Fn setclasscontext "const char *classname" "unsigned int flags" 3768bbf3adSDavid Nugent.Ft void 3892657d3cSDag-Erling Smørgrav.Fn setclasscpumask "login_cap_t *lc" 3968bbf3adSDavid Nugent.Ft void 4068bbf3adSDavid Nugent.Fn setclassenvironment "login_cap_t *lc" "const struct passwd *pwd" "int paths" 4192657d3cSDag-Erling Smørgrav.Ft void 4292657d3cSDag-Erling Smørgrav.Fn setclassresources "login_cap_t *lc" 4392657d3cSDag-Erling Smørgrav.Ft int 4492657d3cSDag-Erling Smørgrav.Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags" 4568bbf3adSDavid Nugent.Sh DESCRIPTION 4668bbf3adSDavid NugentThese functions provide a higher level interface to the login class 4768bbf3adSDavid Nugentdatabase than those documented in 4868bbf3adSDavid Nugent.Xr login_cap 3 . 4968bbf3adSDavid NugentThese functions are used to set resource limits, environment and 5068bbf3adSDavid Nugentaccounting settings for users on logging into the system and when 5168bbf3adSDavid Nugentselecting an appropriate set of environment and resource settings 5268bbf3adSDavid Nugentfor system daemons based on login classes. 5368bbf3adSDavid NugentThese functions may only be called if the current process is 549c727d2cSJoseph Koshyrunning with root privileges. 5568bbf3adSDavid NugentIf the LOGIN_SETLOGIN flag is used this function calls 5668bbf3adSDavid Nugent.Xr setlogin 2 , 5768bbf3adSDavid Nugentand due care must be taken as detailed in the manpage for that 5868bbf3adSDavid Nugentfunction and this affects all processes running in the same session 5968bbf3adSDavid Nugentand not just the current process. 6068bbf3adSDavid Nugent.Pp 610552350eSPhilippe CharnierThe 6268bbf3adSDavid Nugent.Fn setclasscontext 630552350eSPhilippe Charnierfunction sets various class context values (resource limits, umask and 6468bbf3adSDavid Nugentprocess priorities) based on values for a specific named class. 6568bbf3adSDavid Nugent.Pp 660552350eSPhilippe CharnierThe 6768bbf3adSDavid Nugent.Fn setusercontext 680552350eSPhilippe Charnierfunction sets class context values based on a given login_cap_t 6926eff9e8SDiomidis Spinellisobject and a specific passwd record (if login_cap_t is NULL), 7026eff9e8SDiomidis Spinellisthe current session's login, and the current process 7168bbf3adSDavid Nugentuser and group ownership. 7226eff9e8SDiomidis SpinellisEach of these actions is selectable via bit-flags passed 7368bbf3adSDavid Nugentin the 7468bbf3adSDavid Nugent.Ar flags 7568bbf3adSDavid Nugentparameter, which is comprised of one or more of the following: 76ffa51010SEdward Tomasz Napierala.Bl -tag -width LOGIN_SETLOGINCLASS 7768bbf3adSDavid Nugent.It LOGIN_SETLOGIN 7868bbf3adSDavid NugentSet the login associated with the current session to the user 790552350eSPhilippe Charnierspecified in the passwd structure using 8068bbf3adSDavid Nugent.Xr setlogin 2 . 8168bbf3adSDavid NugentThe 8268bbf3adSDavid Nugent.Ar pwd 8368bbf3adSDavid Nugentparameter must not be NULL if this option is used. 8468bbf3adSDavid Nugent.It LOGIN_SETUSER 85613c94acSMaxim KonovalovSet ownership of the current process to the uid specified in the 8668bbf3adSDavid Nugent.Ar uid 8768bbf3adSDavid Nugentparameter using 8868bbf3adSDavid Nugent.Xr setuid 2 . 8968bbf3adSDavid Nugent.It LOGIN_SETGROUP 9068bbf3adSDavid NugentSet group ownership of the current process to the group id 9168bbf3adSDavid Nugentspecified in the passwd structure using 9268bbf3adSDavid Nugent.Xr setgid 2 , 9368bbf3adSDavid Nugentand calls 9468bbf3adSDavid Nugent.Xr initgroups 3 9568bbf3adSDavid Nugentto set up the group access list for the current process. 9668bbf3adSDavid NugentThe 9768bbf3adSDavid Nugent.Ar pwd 9868bbf3adSDavid Nugentparameter must not be NULL if this option is used. 9968bbf3adSDavid Nugent.It LOGIN_SETRESOURCES 10068bbf3adSDavid NugentSet resource limits for the current process based on values 10168bbf3adSDavid Nugentspecified in the system login class database. 10268bbf3adSDavid NugentClass capability tags used, with and without -cur (soft limit) 10368bbf3adSDavid Nugentor -max (hard limit) suffixes and the corresponding resource 10468bbf3adSDavid Nugentsetting: 10568bbf3adSDavid Nugent.Bd -literal 10668bbf3adSDavid Nugentcputime RLIMIT_CPU 10768bbf3adSDavid Nugentfilesize RLIMIT_FSIZE 10868bbf3adSDavid Nugentdatasize RLIMIT_DATA 10968bbf3adSDavid Nugentstacksize RLIMIT_STACK 11068bbf3adSDavid Nugentcoredumpsize RLIMIT_CORE 11168bbf3adSDavid Nugentmemoryuse RLIMIT_RSS 11268bbf3adSDavid Nugentmemorylocked RLIMIT_MEMLOCK 11368bbf3adSDavid Nugentmaxproc RLIMIT_NPROC 11468bbf3adSDavid Nugentopenfiles RLIMIT_NOFILE 1156b3ced11SBrian Feldmansbsize RLIMIT_SBSIZE 1166c4e78aeSTom Rhodesvmemoryuse RLIMIT_VMEM 117c6b2aa68SSergey Kandaurovpseudoterminals RLIMIT_NPTS 118c6b2aa68SSergey Kandaurovswapuse RLIMIT_SWAP 11985a0ddfdSKonstantin Belousovkqueues RLIMIT_KQUEUES 120250d9fd8SKonstantin Belousovumtxp RLIMIT_UMTXP 121*a4c04958SKonstantin Belousovpipebuf RLIMIT_PIPEBUF 12268bbf3adSDavid Nugent.Ed 12368bbf3adSDavid Nugent.It LOGIN_SETPRIORITY 12468bbf3adSDavid NugentSet the scheduling priority for the current process based on the 12568bbf3adSDavid Nugentvalue specified in the system login class database. 12668bbf3adSDavid NugentClass capability tags used: 12768bbf3adSDavid Nugent.Bd -literal 12868bbf3adSDavid Nugentpriority 12968bbf3adSDavid Nugent.Ed 13068bbf3adSDavid Nugent.It LOGIN_SETUMASK 13168bbf3adSDavid NugentSet the umask for the current process to a value in the user or 13268bbf3adSDavid Nugentsystem login class database. 13368bbf3adSDavid NugentClass capability tags used: 13468bbf3adSDavid Nugent.Bd -literal 13568bbf3adSDavid Nugentumask 13668bbf3adSDavid Nugent.Ed 13768bbf3adSDavid Nugent.It LOGIN_SETPATH 13868bbf3adSDavid NugentSet the "path" and "manpath" environment variables based on values 13968bbf3adSDavid Nugentin the user or system login class database. 14068bbf3adSDavid NugentClass capability tags used with the corresponding environment 14168bbf3adSDavid Nugentvariables set: 14268bbf3adSDavid Nugent.Bd -literal 14368bbf3adSDavid Nugentpath PATH 14468bbf3adSDavid Nugentmanpath MANPATH 14568bbf3adSDavid Nugent.Ed 14668bbf3adSDavid Nugent.It LOGIN_SETENV 14768bbf3adSDavid NugentSet various environment variables based on values in the user or 14868bbf3adSDavid Nugentsystem login class database. 14968bbf3adSDavid NugentClass capability tags used with the corresponding environment 15068bbf3adSDavid Nugentvariables set: 15168bbf3adSDavid Nugent.Bd -literal 15268bbf3adSDavid Nugentlang LANG 15368bbf3adSDavid Nugentcharset MM_CHARSET 15468bbf3adSDavid Nugenttimezone TZ 15568bbf3adSDavid Nugentterm TERM 15668bbf3adSDavid Nugent.Ed 15768bbf3adSDavid Nugent.Pp 15868bbf3adSDavid NugentAdditional environment variables may be set using the list type 15968bbf3adSDavid Nugentcapability "setenv=var1 val1,var2 val2..,varN valN". 160111a16a8SChristian S.J. Peron.It LOGIN_SETMAC 161111a16a8SChristian S.J. PeronSet the MAC label for the current process to the label specified 162111a16a8SChristian S.J. Peronin system login class database. 163d84c4292SBrooks Davis.It LOGIN_SETCPUMASK 164d84c4292SBrooks DavisCreate a new 165d84c4292SBrooks Davis.Xr cpuset 2 166d84c4292SBrooks Davisand set the cpu affinity to the specified mask. 167d84c4292SBrooks DavisThe string may contain a comma separated list of numbers and/or number 168d84c4292SBrooks Davisranges as handled by the 169d84c4292SBrooks Davis.Xr cpuset 1 170d84c4292SBrooks Davisutility or the case-insensitive string 171d84c4292SBrooks Davis.Ql default . 172d84c4292SBrooks DavisIf the string is 173d84c4292SBrooks Davis.Ql default 174d84c4292SBrooks Davisno action will be taken. 175ffa51010SEdward Tomasz Napierala.It LOGIN_SETLOGINCLASS 176ffa51010SEdward Tomasz NapieralaSet the login class of the current process using 177ffa51010SEdward Tomasz Napierala.Xr setloginclass 2 . 17868bbf3adSDavid Nugent.It LOGIN_SETALL 17968bbf3adSDavid NugentEnables all of the above settings. 18068bbf3adSDavid Nugent.El 18168bbf3adSDavid Nugent.Pp 18268bbf3adSDavid NugentNote that when setting environment variables and a valid passwd 18368bbf3adSDavid Nugentpointer is provided in the 18468bbf3adSDavid Nugent.Ar pwd 18568bbf3adSDavid Nugentparameter, the characters 18668bbf3adSDavid Nugent.Ql \&~ 18768bbf3adSDavid Nugentand 18868bbf3adSDavid Nugent.Ql \&$ 18968bbf3adSDavid Nugentare substituted for the user's home directory and login name 19068bbf3adSDavid Nugentrespectively. 19168bbf3adSDavid Nugent.Pp 19268bbf3adSDavid NugentThe 19392657d3cSDag-Erling Smørgrav.Fn setclasscpumask , 19468bbf3adSDavid Nugent.Fn setclassresources 19568bbf3adSDavid Nugentand 19668bbf3adSDavid Nugent.Fn setclassenvironment 19768bbf3adSDavid Nugentfunctions are subsets of the setcontext functions above, but may 19868bbf3adSDavid Nugentbe useful in isolation. 19968bbf3adSDavid Nugent.Sh RETURN VALUES 2000552350eSPhilippe CharnierThe 20168bbf3adSDavid Nugent.Fn setclasscontext 20268bbf3adSDavid Nugentand 20368bbf3adSDavid Nugent.Fn setusercontext 2040552350eSPhilippe Charnierfunctions return -1 if an error occurred, or 0 on success. 20568bbf3adSDavid NugentIf an error occurs when attempting to set the user, login, group 20668bbf3adSDavid Nugentor resources, a message is reported to 20768bbf3adSDavid Nugent.Xr syslog 3 , 20868bbf3adSDavid Nugentwith LOG_ERR priority and directed to the currently active facility. 20968bbf3adSDavid Nugent.Sh SEE ALSO 210d84c4292SBrooks Davis.Xr cpuset 1 , 211ffa51010SEdward Tomasz Napierala.Xr ps 1 , 212d84c4292SBrooks Davis.Xr cpuset 2 , 21375141cc9SWolfram Schneider.Xr setgid 2 , 21468bbf3adSDavid Nugent.Xr setlogin 2 , 215ffa51010SEdward Tomasz Napierala.Xr setloginclass 2 , 21668bbf3adSDavid Nugent.Xr setuid 2 , 21775141cc9SWolfram Schneider.Xr getcap 3 , 21868bbf3adSDavid Nugent.Xr initgroups 3 , 21968bbf3adSDavid Nugent.Xr login_cap 3 , 220111a16a8SChristian S.J. Peron.Xr mac_set_proc 3 , 22168bbf3adSDavid Nugent.Xr login.conf 5 , 22275141cc9SWolfram Schneider.Xr termcap 5 223bc89b58dSGordon Bergling.Sh HISTORY 224bc89b58dSGordon BerglingThe functions 225bc89b58dSGordon Bergling.Fn setclasscontext , 226bc89b58dSGordon Bergling.Fn setclasscpumask , 227bc89b58dSGordon Bergling.Fn setclassenvironment , 228bc89b58dSGordon Bergling.Fn setclassresources 229bc89b58dSGordon Berglingand 230bc89b58dSGordon Bergling.Fn setusercontext 231bc89b58dSGordon Berglingfirst appeared in 232bc89b58dSGordon Bergling.Fx 2.1.5 . 233