xref: /freebsd/lib/libutil/login_class.3 (revision 6b3ced11a2b9225041e40efc39c5ffbcda94dab1)
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 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 "const 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 privileges.
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
112sbsize        RLIMIT_SBSIZE
113.Ed
114.It LOGIN_SETPRIORITY
115Set the scheduling priority for the current process based on the
116value specified in the system login class database.
117Class capability tags used:
118.Bd -literal
119priority
120.Ed
121.It LOGIN_SETUMASK
122Set the umask for the current process to a value in the user or
123system login class database.
124Class capability tags used:
125.Bd -literal
126umask
127.Ed
128.It LOGIN_SETPATH
129Set the "path" and "manpath" environment variables based on values
130in the user or system login class database.
131Class capability tags used with the corresponding environment
132variables set:
133.Bd -literal
134path          PATH
135manpath       MANPATH
136.Ed
137.It LOGIN_SETENV
138Set various environment variables based on values in the user or
139system login class database.
140Class capability tags used with the corresponding environment
141variables set:
142.Bd -literal
143lang          LANG
144charset       MM_CHARSET
145timezone      TZ
146term          TERM
147.Ed
148.Pp
149Additional environment variables may be set using the list type
150capability "setenv=var1 val1,var2 val2..,varN valN".
151.It LOGIN_SETALL
152Enables all of the above settings.
153.El
154.Pp
155Note that when setting environment variables and a valid passwd
156pointer is provided in the
157.Ar pwd
158parameter, the characters
159.Ql \&~
160and
161.Ql \&$
162are substituted for the user's home directory and login name
163respectively.
164.Pp
165The
166.Fn setclassresources
167and
168.Fn setclassenvironment
169functions are subsets of the setcontext functions above, but may
170be useful in isolation.
171.Sh RETURN VALUES
172.Fn setclasscontext
173and
174.Fn setusercontext
175return -1 if an error occurred, or 0 on success.
176If an error occurs when attempting to set the user, login, group
177or resources, a message is reported to
178.Xr syslog 3 ,
179with LOG_ERR priority and directed to the currently active facility.
180.Sh SEE ALSO
181.Xr setgid 2 ,
182.Xr setlogin 2 ,
183.Xr setuid 2 ,
184.Xr getcap 3 ,
185.Xr initgroups 3 ,
186.Xr login_cap 3 ,
187.Xr login.conf 5 ,
188.Xr termcap 5
189