xref: /freebsd/lib/libutil/login_class.3 (revision 111a16a8eeef4f82ac89e7eaa330d8bb6c337639)
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.\"
207f3dea24SPeter Wemm.\" $FreeBSD$
2168bbf3adSDavid Nugent.\"
2268bbf3adSDavid Nugent.Dd December 28, 1996
23a307d598SRuslan Ermilov.Os
2468bbf3adSDavid Nugent.Dt LOGIN_CLASS 3
2568bbf3adSDavid Nugent.Sh NAME
2668bbf3adSDavid Nugent.Nm setclasscontext ,
273dc329d1SAlexey Zelkin.Nm setclassenvironment ,
2868bbf3adSDavid Nugent.Nm setclassresources ,
293dc329d1SAlexey Zelkin.Nm setusercontext
30eb083802SRuslan Ermilov.Nd "functions for using the login class capabilities database"
313dc329d1SAlexey Zelkin.Sh LIBRARY
323dc329d1SAlexey Zelkin.Lb libutil
3368bbf3adSDavid Nugent.Sh SYNOPSIS
3432eef9aeSRuslan Ermilov.In sys/types.h
3532eef9aeSRuslan Ermilov.In login_cap.h
3668bbf3adSDavid Nugent.Ft int
37c5a44d91SBruce Evans.Fn setclasscontext "const char *classname" "unsigned int flags"
3868bbf3adSDavid Nugent.Ft int
3968bbf3adSDavid Nugent.Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags"
4068bbf3adSDavid Nugent.Ft void
4168bbf3adSDavid Nugent.Fn setclassresources "login_cap_t *lc"
4268bbf3adSDavid Nugent.Ft void
4368bbf3adSDavid Nugent.Fn setclassenvironment "login_cap_t *lc" "const struct passwd *pwd" "int paths"
4468bbf3adSDavid Nugent.Sh DESCRIPTION
4568bbf3adSDavid NugentThese functions provide a higher level interface to the login class
4668bbf3adSDavid Nugentdatabase than those documented in
4768bbf3adSDavid Nugent.Xr login_cap 3 .
4868bbf3adSDavid NugentThese functions are used to set resource limits, environment and
4968bbf3adSDavid Nugentaccounting settings for users on logging into the system and when
5068bbf3adSDavid Nugentselecting an appropriate set of environment and resource settings
5168bbf3adSDavid Nugentfor system daemons based on login classes.
5268bbf3adSDavid NugentThese functions may only be called if the current process is
539c727d2cSJoseph Koshyrunning with root privileges.
5468bbf3adSDavid NugentIf the LOGIN_SETLOGIN flag is used this function calls
5568bbf3adSDavid Nugent.Xr setlogin 2 ,
5668bbf3adSDavid Nugentand due care must be taken as detailed in the manpage for that
5768bbf3adSDavid Nugentfunction and this affects all processes running in the same session
5868bbf3adSDavid Nugentand not just the current process.
5968bbf3adSDavid Nugent.Pp
600552350eSPhilippe CharnierThe
6168bbf3adSDavid Nugent.Fn setclasscontext
620552350eSPhilippe Charnierfunction sets various class context values (resource limits, umask and
6368bbf3adSDavid Nugentprocess priorities) based on values for a specific named class.
6468bbf3adSDavid Nugent.Pp
650552350eSPhilippe CharnierThe
6668bbf3adSDavid Nugent.Fn setusercontext
670552350eSPhilippe Charnierfunction sets class context values based on a given login_cap_t
6826eff9e8SDiomidis Spinellisobject and a specific passwd record (if login_cap_t is NULL),
6926eff9e8SDiomidis Spinellisthe current session's login, and the current process
7068bbf3adSDavid Nugentuser and group ownership.
7126eff9e8SDiomidis SpinellisEach of these actions is selectable via bit-flags passed
7268bbf3adSDavid Nugentin the
7368bbf3adSDavid Nugent.Ar flags
7468bbf3adSDavid Nugentparameter, which is comprised of one or more of the following:
7568bbf3adSDavid Nugent.Bl -tag -width LOGIN_SETRESOURCES
7668bbf3adSDavid Nugent.It LOGIN_SETLOGIN
7768bbf3adSDavid NugentSet the login associated with the current session to the user
780552350eSPhilippe Charnierspecified in the passwd structure using
7968bbf3adSDavid Nugent.Xr setlogin 2 .
8068bbf3adSDavid NugentThe
8168bbf3adSDavid Nugent.Ar pwd
8268bbf3adSDavid Nugentparameter must not be NULL if this option is used.
8368bbf3adSDavid Nugent.It LOGIN_SETUSER
8468bbf3adSDavid NugentSet ownship of the current process to the uid specified in the
8568bbf3adSDavid Nugent.Ar uid
8668bbf3adSDavid Nugentparameter using
8768bbf3adSDavid Nugent.Xr setuid 2 .
8868bbf3adSDavid Nugent.It LOGIN_SETGROUP
8968bbf3adSDavid NugentSet group ownership of the current process to the group id
9068bbf3adSDavid Nugentspecified in the passwd structure using
9168bbf3adSDavid Nugent.Xr setgid 2 ,
9268bbf3adSDavid Nugentand calls
9368bbf3adSDavid Nugent.Xr initgroups 3
9468bbf3adSDavid Nugentto set up the group access list for the current process.
9568bbf3adSDavid NugentThe
9668bbf3adSDavid Nugent.Ar pwd
9768bbf3adSDavid Nugentparameter must not be NULL if this option is used.
9868bbf3adSDavid Nugent.It LOGIN_SETRESOURCES
9968bbf3adSDavid NugentSet resource limits for the current process based on values
10068bbf3adSDavid Nugentspecified in the system login class database.
10168bbf3adSDavid NugentClass capability tags used, with and without -cur (soft limit)
10268bbf3adSDavid Nugentor -max (hard limit) suffixes and the corresponding resource
10368bbf3adSDavid Nugentsetting:
10468bbf3adSDavid Nugent.Bd -literal
10568bbf3adSDavid Nugentcputime       RLIMIT_CPU
10668bbf3adSDavid Nugentfilesize      RLIMIT_FSIZE
10768bbf3adSDavid Nugentdatasize      RLIMIT_DATA
10868bbf3adSDavid Nugentstacksize     RLIMIT_STACK
10968bbf3adSDavid Nugentcoredumpsize  RLIMIT_CORE
11068bbf3adSDavid Nugentmemoryuse     RLIMIT_RSS
11168bbf3adSDavid Nugentmemorylocked  RLIMIT_MEMLOCK
11268bbf3adSDavid Nugentmaxproc       RLIMIT_NPROC
11368bbf3adSDavid Nugentopenfiles     RLIMIT_NOFILE
1146b3ced11SBrian Feldmansbsize        RLIMIT_SBSIZE
1156c4e78aeSTom Rhodesvmemoryuse    RLIMIT_VMEM
11668bbf3adSDavid Nugent.Ed
11768bbf3adSDavid Nugent.It LOGIN_SETPRIORITY
11868bbf3adSDavid NugentSet the scheduling priority for the current process based on the
11968bbf3adSDavid Nugentvalue specified in the system login class database.
12068bbf3adSDavid NugentClass capability tags used:
12168bbf3adSDavid Nugent.Bd -literal
12268bbf3adSDavid Nugentpriority
12368bbf3adSDavid Nugent.Ed
12468bbf3adSDavid Nugent.It LOGIN_SETUMASK
12568bbf3adSDavid NugentSet the umask for the current process to a value in the user or
12668bbf3adSDavid Nugentsystem login class database.
12768bbf3adSDavid NugentClass capability tags used:
12868bbf3adSDavid Nugent.Bd -literal
12968bbf3adSDavid Nugentumask
13068bbf3adSDavid Nugent.Ed
13168bbf3adSDavid Nugent.It LOGIN_SETPATH
13268bbf3adSDavid NugentSet the "path" and "manpath" environment variables based on values
13368bbf3adSDavid Nugentin the user or system login class database.
13468bbf3adSDavid NugentClass capability tags used with the corresponding environment
13568bbf3adSDavid Nugentvariables set:
13668bbf3adSDavid Nugent.Bd -literal
13768bbf3adSDavid Nugentpath          PATH
13868bbf3adSDavid Nugentmanpath       MANPATH
13968bbf3adSDavid Nugent.Ed
14068bbf3adSDavid Nugent.It LOGIN_SETENV
14168bbf3adSDavid NugentSet various environment variables based on values in the user or
14268bbf3adSDavid Nugentsystem login class database.
14368bbf3adSDavid NugentClass capability tags used with the corresponding environment
14468bbf3adSDavid Nugentvariables set:
14568bbf3adSDavid Nugent.Bd -literal
14668bbf3adSDavid Nugentlang          LANG
14768bbf3adSDavid Nugentcharset       MM_CHARSET
14868bbf3adSDavid Nugenttimezone      TZ
14968bbf3adSDavid Nugentterm          TERM
15068bbf3adSDavid Nugent.Ed
15168bbf3adSDavid Nugent.Pp
15268bbf3adSDavid NugentAdditional environment variables may be set using the list type
15368bbf3adSDavid Nugentcapability "setenv=var1 val1,var2 val2..,varN valN".
154111a16a8SChristian S.J. Peron.It LOGIN_SETMAC
155111a16a8SChristian S.J. PeronSet the MAC label for the current process to the label specified
156111a16a8SChristian S.J. Peronin system login class database.
157111a16a8SChristian S.J. Peron.Pp
15868bbf3adSDavid Nugent.It LOGIN_SETALL
15968bbf3adSDavid NugentEnables all of the above settings.
16068bbf3adSDavid Nugent.El
16168bbf3adSDavid Nugent.Pp
16268bbf3adSDavid NugentNote that when setting environment variables and a valid passwd
16368bbf3adSDavid Nugentpointer is provided in the
16468bbf3adSDavid Nugent.Ar pwd
16568bbf3adSDavid Nugentparameter, the characters
16668bbf3adSDavid Nugent.Ql \&~
16768bbf3adSDavid Nugentand
16868bbf3adSDavid Nugent.Ql \&$
16968bbf3adSDavid Nugentare substituted for the user's home directory and login name
17068bbf3adSDavid Nugentrespectively.
17168bbf3adSDavid Nugent.Pp
17268bbf3adSDavid NugentThe
17368bbf3adSDavid Nugent.Fn setclassresources
17468bbf3adSDavid Nugentand
17568bbf3adSDavid Nugent.Fn setclassenvironment
17668bbf3adSDavid Nugentfunctions are subsets of the setcontext functions above, but may
17768bbf3adSDavid Nugentbe useful in isolation.
17868bbf3adSDavid Nugent.Sh RETURN VALUES
1790552350eSPhilippe CharnierThe
18068bbf3adSDavid Nugent.Fn setclasscontext
18168bbf3adSDavid Nugentand
18268bbf3adSDavid Nugent.Fn setusercontext
1830552350eSPhilippe Charnierfunctions return -1 if an error occurred, or 0 on success.
18468bbf3adSDavid NugentIf an error occurs when attempting to set the user, login, group
18568bbf3adSDavid Nugentor resources, a message is reported to
18668bbf3adSDavid Nugent.Xr syslog 3 ,
18768bbf3adSDavid Nugentwith LOG_ERR priority and directed to the currently active facility.
18868bbf3adSDavid Nugent.Sh SEE ALSO
18975141cc9SWolfram Schneider.Xr setgid 2 ,
19068bbf3adSDavid Nugent.Xr setlogin 2 ,
19168bbf3adSDavid Nugent.Xr setuid 2 ,
19275141cc9SWolfram Schneider.Xr getcap 3 ,
19368bbf3adSDavid Nugent.Xr initgroups 3 ,
19468bbf3adSDavid Nugent.Xr login_cap 3 ,
195111a16a8SChristian S.J. Peron.Xr mac_set_proc 3 ,
19668bbf3adSDavid Nugent.Xr login.conf 5 ,
19775141cc9SWolfram Schneider.Xr termcap 5
198