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