Index: stable/12/lib/libutil/_secure_path.3 =================================================================== --- stable/12/lib/libutil/_secure_path.3 (revision 362661) +++ stable/12/lib/libutil/_secure_path.3 (revision 362662) @@ -1,75 +1,79 @@ .\" Copyright (c) 1997 David Nugent .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, is permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. This work was done expressly for inclusion into FreeBSD. Other use .\" is permitted provided this notation is included. .\" 4. Absolutely no warranty of function or purpose is made by the author .\" David Nugent. .\" 5. Modifications may be freely made to this file providing the above .\" conditions are met. .\" .\" $FreeBSD$ .\" -.Dd May 2, 1997 +.Dd May 10, 2020 .Dt _SECURE_PATH 3 .Os .Sh NAME .Nm _secure_path .Nd determine if a file appears to be secure .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In libutil.h .Ft int .Fn _secure_path "const char *path" "uid_t uid" "gid_t gid" .Sh DESCRIPTION This function does some basic security checking on a given path. It is intended to be used by processes running with root privileges in order to decide whether or not to trust the contents of a given file. It uses a method often used to detect system compromise. .Pp A file is considered .Sq secure if it meets the following conditions: .Bl -enum .It The file exists, and is a regular file (not a symlink, device special or named pipe, etc.), .It Is not world writable. .It Is owned by the given uid or uid 0, if uid is not -1, .It Is not group writable or it has group ownership by the given gid, if gid is not -1. .El .Sh RETURN VALUES This function returns zero if the file exists and may be considered secure, -2 if the file does not exist, and -1 otherwise to indicate a security failure. The .Xr syslog 3 function is used to log any failure of this function, including the reason, at LOG_ERR priority. .Sh SEE ALSO .Xr lstat 2 , .Xr syslog 3 .Sh HISTORY Code from which this function was derived was contributed to the .Fx project by Berkeley Software Design, Inc. +The function +.Fn _secure_path +first appeared in +.Fx 2.2.5 . .Sh BUGS The checks carried out are rudimentary and no attempt is made to eliminate race conditions between use of this function and access to the file referenced. Index: stable/12/lib/libutil/hexdump.3 =================================================================== --- stable/12/lib/libutil/hexdump.3 (revision 362661) +++ stable/12/lib/libutil/hexdump.3 (revision 362662) @@ -1,88 +1,93 @@ .\" -*- nroff -*- .\" .\" Copyright (c) 2003 Scott Long .\" .\" All rights reserved. .\" .\" This program is free software. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd March 21, 2017 +.Dd May 8, 2020 .Dt HEXDUMP 3 .Os .Sh NAME .Nm hexdump .Nd "dump a block of bytes to standard out in hexadecimal form" .Sh SYNOPSIS .In libutil.h .Ft void .Fn hexdump "void *ptr" "int length" "const char *hdr" "int flags" .Sh DESCRIPTION The .Fn hexdump function prints an array of bytes to standard out in hexadecimal form, along with the ASCII representation of the bytes, if possible. By default, each line of output will start with an offset count, followed by 16 hexadecimal values, followed by 16 ASCII characters. .Bl -tag -width indent .It Fa ptr Pointer to the array of bytes to print. It does not need to be .Dv NUL Ns -terminated. .It Fa length Number of bytes to print. .It Fa hdr Pointer to a .Dv NUL Ns -terminated character string that will be prepended to each line of output. A value of .Dv NULL implies that no header will be printed. .It Fa flags Flags for controlling the formatting of the output. .Bl -tag -width ".Dv HD_OMIT_COUNT" .It Bits 0-7 Integer value of the number of bytes to display on each line. A value of 0 implies that the default value of 16 will be used. .It Bits 8-15 Character ASCII value to use as the separator for the hexadecimal output. A value of 0 implies that the default value of 32 .Pq ASCII space will be used. .It Dv HD_OMIT_COUNT Do not print the offset column at the beginning of each line. .It Dv HD_OMIT_HEX Do not print the hexadecimal values on each line. .It Dv HD_OMIT_CHARS Do not print the character values on each line. .El .El .Sh SEE ALSO .Xr ascii 7 , .Xr sbuf_hexdump 9 +.Sh HISTORY +The +.Fn hexdump +function first appeared in +.Fx 6.4 . .Sh AUTHORS This manual page was written by .An Scott Long . Index: stable/12/lib/libutil/kinfo_getallproc.3 =================================================================== --- stable/12/lib/libutil/kinfo_getallproc.3 (revision 362661) +++ stable/12/lib/libutil/kinfo_getallproc.3 (revision 362662) @@ -1,75 +1,80 @@ .\" .\" Copyright (c) 2009 Ulf Lilleengen .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd May 27, 2015 +.Dd May 8, 2020 .Dt KINFO_GETALLPROC 3 .Os .Sh NAME .Nm kinfo_getallproc .Nd function for getting process information of all processes from kernel .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In sys/user.h .In libutil.h .Ft struct kinfo_proc * .Fn kinfo_getallproc "int *cntp" .Sh DESCRIPTION This function is used for obtaining process information of all processes from the kernel. .Pp The .Ar cntp field is a pointer containing the number of process structures returned. This function is a wrapper around .Xr sysctl 3 with the .Dv KERN_PROC_PROC mib. While the kernel returns a packed structure, this function expands the data into a fixed record format. .Sh RETURN VALUES On success the .Fn kinfo_getallproc function returns a pointer to .Ar cntp .Vt struct kinfo_proc structures as defined by .In sys/user.h . The pointer was obtained by an internal call to .Xr malloc 3 and must be freed by the caller with a call to .Xr free 3 . On failure the .Fn kinfo_getallproc function returns .Dv NULL . .Sh SEE ALSO .Xr free 3 , .Xr malloc 3 , .Xr sysctl 3 +.Sh HISTORY +The +.Fn kinfo_getallproc +function first appeared in +.Fx 8.3 . Index: stable/12/lib/libutil/kinfo_getfile.3 =================================================================== --- stable/12/lib/libutil/kinfo_getfile.3 (revision 362661) +++ stable/12/lib/libutil/kinfo_getfile.3 (revision 362662) @@ -1,80 +1,85 @@ .\" .\" Copyright (c) 2008 Peter Wemm .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" .Dd May 27, 2015 .Dt KINFO_GETFILE 3 .Os .Sh NAME .Nm kinfo_getfile .Nd function for getting per-process file descriptor information .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In sys/user.h .In libutil.h .Ft struct kinfo_file * .Fn kinfo_getfile "pid_t pid" "int *cntp" .Sh DESCRIPTION This function is used for obtaining the file descriptor information of a particular process. .Pp The .Ar pid field contains the process identifier. This should be the a process that you have privilege to access. The .Ar cntp field allows the caller to know how many records are returned. .Pp This function is a wrapper around .Xr sysctl 3 with the .Dv KERN_PROC_FILEDESC mib. While the kernel returns a packed structure, this function expands the data into a fixed record format. .Sh RETURN VALUES On success the .Fn kinfo_getfile function returns a pointer to an array of .Vt struct kinfo_file structures as defined by .In sys/user.h . The array was obtained by an internal call to .Xr malloc 3 and must be freed by the caller with a call to .Xr free 3 . On failure the .Fn kinfo_getfile function returns .Dv NULL . .Sh SEE ALSO .Xr free 3 , .Xr kinfo_getvmmap 3 , .Xr malloc 3 , .Xr sysctl 3 +.Sh HISTORY +The +.Fn kinfo_getfile +function first appeared in +.Fx 7.0 . Index: stable/12/lib/libutil/kinfo_getproc.3 =================================================================== --- stable/12/lib/libutil/kinfo_getproc.3 (revision 362661) +++ stable/12/lib/libutil/kinfo_getproc.3 (revision 362662) @@ -1,74 +1,79 @@ .\" .\" Copyright (c) 2009 Ulf Lilleengen .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd May 27, 2015 +.Dd May 10, 2020 .Dt KINFO_GETPROC 3 .Os .Sh NAME .Nm kinfo_getproc .Nd function for getting process information from kernel .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In sys/user.h .In libutil.h .Ft struct kinfo_proc * .Fn kinfo_getproc "pid_t pid" .Sh DESCRIPTION This function is used for obtaining process information from the kernel. .Pp The .Ar pid field contains the process identifier. This should be a process that you have privilege to access. This function is a wrapper around .Xr sysctl 3 with the .Dv KERN_PROC_PID mib. While the kernel returns a packed structure, this function expands the data into a fixed record format. .Sh RETURN VALUES On success the .Fn kinfo_getproc function returns a pointer to a .Vt struct kinfo_proc structure as defined by .In sys/user.h . The pointer was obtained by an internal call to .Xr malloc 3 and must be freed by the caller with a call to .Xr free 3 . On failure the .Fn kinfo_getproc function returns .Dv NULL . .Sh SEE ALSO .Xr free 3 , .Xr malloc 3 , .Xr sysctl 3 +.Sh HISTORY +The +.Fn kinfo_getproc +function first appeared in +.Fx 7.0 . Index: stable/12/lib/libutil/kinfo_getvmmap.3 =================================================================== --- stable/12/lib/libutil/kinfo_getvmmap.3 (revision 362661) +++ stable/12/lib/libutil/kinfo_getvmmap.3 (revision 362662) @@ -1,86 +1,91 @@ .\" .\" Copyright (c) 2008 Peter Wemm .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd August 18, 2017 +.Dd May 10, 2020 .Dt KINFO_GETVMMAP 3 .Os .Sh NAME .Nm kinfo_getvmmap .Nd function for getting per-process memory map information .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In sys/user.h .In libutil.h .Ft struct kinfo_vmentry * .Fn kinfo_getvmmap "pid_t pid" "int *cntp" .Sh DESCRIPTION This function is used for obtaining virtual memory mapping information of a particular process. .Pp The .Ar pid field contains the process identifier. This should be the a process that you have privilege to access. The .Ar cntp field is allows the caller to know how many records are returned. .Pp This function is a wrapper around .Xr sysctl 3 with the .Dv KERN_PROC_VMMAP mib. While the kernel returns a packed structure, this function expands the data into a fixed record format. .Sh CAVEAT .Fn kinfo_getvmmap calls can cause significant CPU consumption because calculating the residency counts requires iterating over all memory pages of the process. Setting the sysctl variable .Va kern.proc_vmmap_skip_resident_count to 1 prevents this calculation. .Sh RETURN VALUES On success the .Fn kinfo_getvmmap function returns a pointer to an array of .Vt struct kinfo_vmentry structures as defined by .In sys/user.h . The array was obtained by an internal call to .Xr malloc 3 and must be freed by the caller with a call to .Xr free 3 . On failure the .Fn kinfo_getvmmap function returns .Dv NULL . .Sh SEE ALSO .Xr free 3 , .Xr kinfo_getfile 3 , .Xr malloc 3 +.Sh HISTORY +The +.Fn kinfo_getvmmap +function first appeared in +.Fx 7.0 . Index: stable/12/lib/libutil/kinfo_getvmobject.3 =================================================================== --- stable/12/lib/libutil/kinfo_getvmobject.3 (revision 362661) +++ stable/12/lib/libutil/kinfo_getvmobject.3 (revision 362662) @@ -1,74 +1,79 @@ .\" .\" Copyright (c) 2015 John Baldwin .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd May 27, 2015 +.Dd May 20, 2020 .Dt KINFO_GETVMOBJECT 3 .Os .Sh NAME .Nm kinfo_getvmobject .Nd function for getting system-wide memory information .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In sys/user.h .In libutil.h .Ft struct kinfo_vmobject * .Fn kinfo_getvmobject "int *cntp" .Sh DESCRIPTION This function is used to obtain information about the objects using memory in the system. .Pp The .Ar cntp argument allows the caller to know how many records are returned. .Pp This function is a wrapper around the .Dq vm.objects .Xr sysctl 3 MIB. While the kernel returns a packed structure, this function expands the data into a fixed record format. .Sh RETURN VALUES On success the .Fn kinfo_getvmobject function returns a pointer to an array of .Vt struct kinfo_vmobject structures as defined by .In sys/user.h . The array is allocated by an internal call to .Xr malloc 3 and must be freed by the caller with a call to .Xr free 3 . On failure the .Fn kinfo_getvmobject function returns .Dv NULL . .Sh SEE ALSO .Xr free 3 , .Xr kinfo_getvmmap 3 , .Xr malloc 3 +.Sh HISTORY +The +.Fn kinfo_getvmobject +function first appeared in +.Fx 10.2 . Index: stable/12/lib/libutil/login.conf.5 =================================================================== --- stable/12/lib/libutil/login.conf.5 (revision 362661) +++ stable/12/lib/libutil/login.conf.5 (revision 362662) @@ -1,473 +1,478 @@ .\" Copyright (c) 1996 David Nugent .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, is permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. This work was done expressly for inclusion into FreeBSD. Other use .\" is permitted provided this notation is included. .\" 4. Absolutely no warranty of function or purpose is made by the author .\" David Nugent. .\" 5. Modifications may be freely made to this file providing the above .\" conditions are met. .\" .\" $FreeBSD$ .\" -.Dd January 19, 2020 +.Dd May 10, 2020 .Dt LOGIN.CONF 5 .Os .Sh NAME .Nm login.conf .Nd login class capability database .Sh SYNOPSIS .Pa /etc/login.conf , .Pa ~/.login_conf .Sh DESCRIPTION .Nm contains various attributes and capabilities of login classes. A login class (an optional annotation against each record in the user account database, .Pa /etc/master.passwd ) determines session accounting, resource limits and user environment settings. It is used by various programs in the system to set up a user's login environment and to enforce policy, accounting and administrative restrictions. It also provides the means by which users are able to be authenticated to the system and the types of authentication available. Attributes in addition to the ones described here are available with third-party packages. .Pp A special record "default" in the system user class capability database .Pa /etc/login.conf is used automatically for any non-root user without a valid login class in .Pa /etc/master.passwd . A user with a uid of 0 without a valid login class will use the record "root" if it exists, or "default" if not. .Pp Users may individually create a file called .Pa .login_conf in their home directory using the same format, consisting of a single entry with a record id of "me". If present, this file is used by .Xr login 1 to set user-defined environment settings which override those specified in the system login capabilities database. Only a subset of login capabilities may be overridden, typically those which do not involve authentication, resource limits and accounting. .Pp Records in a class capabilities database consist of a number of colon-separated fields. The first entry for each record gives one or more names that a record is to be known by, each separated by a '|' character. The first name is the most common abbreviation. The last name given should be a long name that is more descriptive of the capability entry, and all others are synonyms. All names but the last should be in lower case and contain no blanks; the last name may contain upper case characters and blanks for readability. .Pp Note that since a colon .Pq Ql :\& is used to separate capability entries, a .Ql \ec escape sequence must be used to embed a literal colon in the value or name of a capability. .Pp The default .Pa /etc/login.conf shipped with .Fx is an out of the box configuration. Whenever changes to this, or the user's .Pa ~/.login_conf , file are made, the modifications will not be picked up until .Xr cap_mkdb 1 is used to compile the file into a database. This database file will have a .Pa .db extension and is accessed through .Xr cgetent 3 . See .Xr getcap 3 for a more in-depth description of the format of a capability database. .Sh CAPABILITIES Fields within each record in the database follow the .Xr getcap 3 conventions for boolean, type string .Ql \&= and type numeric .Ql \&# , although type numeric is deprecated in favour of the string format and either form is accepted for a numeric datum. Values fall into the following categories: .Bl -tag -width "program" .It bool If the name is present, then the boolean value is true; otherwise, it is false .It file Path name to a data file .It program Path name to an executable file .It list A list of values (or pairs of values) separated by commas or spaces .It path A space or comma separated list of path names, following the usual csh conventions (leading tilde with and without username being expanded to home directories etc.) .It number A numeric value, either decimal (default), hexadecimal (with leading 0x), or octal (with a leading 0). With a numeric type, only one numeric value is allowed. Numeric types may also be specified in string format (i.e., the capability tag being delimited from the value by '=' instead of '#'). Whichever method is used, then all records in the database must use the same method to allow values to be correctly overridden in interpolated records. A numeric value may be infinite. .It size A number which expresses a size. The default interpretation of a value is the number of bytes, but a suffix may specify alternate units: .Bl -tag -offset indent -compact -width xxxx .It b explicitly selects 512-byte blocks .It k selects kilobytes (1024 bytes) .It m specifies a multiplier of 1 megabyte (1048576 bytes), .It g specifies units of gigabytes, and .It t represents terabytes. .El A size value is a numeric quantity and case of the suffix is not significant. Concatenated values are added together. A size value may be infinite. .It time A period of time, by default in seconds. A prefix may specify a different unit: .Bl -tag -offset indent -compact -width xxxx .It y indicates the number of 365 day years, .It w indicates the number of weeks, .It d the number of days, .It h the number of hours, .It m the number of minutes, and .It s the number of seconds. .El Concatenated values are added together. For example, 2 hours and 40 minutes may be written either as 9600s, 160m or 2h40m. A time value may be infinite. .El .Pp .Dq infinity , .Dq inf , .Dq unlimited , .Dq unlimit, and -1 are considered infinite values. .Pp The usual convention to interpolate capability entries using the special .Em tc=value notation may be used. .Sh RESOURCE LIMITS .Bl -column pseudoterminals indent indent .It Sy "Name Type Notes Description" .It "coredumpsize size Maximum coredump size limit." .It "cputime time CPU usage limit." .It "datasize size Maximum data size limit." .It "filesize size Maximum file size limit." .It "maxproc number Maximum number of processes." .It "memorylocked size Maximum locked in core memory size limit." .It "memoryuse size Maximum of core memory use size limit." .It "openfiles number Maximum number of open files per process." .It "sbsize size Maximum permitted socketbuffer size." .It "vmemoryuse size Maximum permitted total VM usage per process." .It "stacksize size Maximum stack size limit." .It "pseudoterminals number Maximum number of pseudo-terminals." .It "swapuse size Maximum swap space size limit." .It "umtxp number Maximum number of process-shared pthread locks." .El .Pp These resource limit entries actually specify both the maximum and current limits (see .Xr getrlimit 2 ) . The current (soft) limit is the one normally used, although the user is permitted to increase the current limit to the maximum (hard) limit. The maximum and current limits may be specified individually by appending a -max or -cur to the capability name. .Sh ENVIRONMENT .Bl -column ignorenologin indent xbinxxusrxbin .It Sy "Name Type Notes Description" .It "charset string Set $MM_CHARSET environment variable to the specified" value. .It "cpumask string List of cpus to bind the user to." The syntax is the same as for the .Fl l argument of .Xr cpuset 1 or the word .Ql default . If set to .Ql default no action is taken. .It "hushlogin bool false Same as having a ~/.hushlogin file." .It "ignorenologin bool false Login not prevented by nologin." .It "ftp-chroot bool false Limit FTP access with" .Xr chroot 2 to the .Ev HOME directory of the user. See .Xr ftpd 8 for details. .It "label string Default MAC policy; see" .Xr maclabel 7 . .It "lang string Set $LANG environment variable to the specified value." .It "mail string Set $MAIL environment variable to the specified value." .It "manpath path Default search path for manpages." .It "nocheckmail bool false Display mail status at login." .It "nologin file If the file exists it will be displayed and" the login session will be terminated. .It "path path /bin /usr/bin Default search path." .It "priority number Initial priority (nice) level." .It "requirehome bool false Require a valid home directory to login." .It "setenv list A comma-separated list of environment variables and" values to which they are to be set. .It "shell prog Session shell to execute rather than the" shell specified in the passwd file. The SHELL environment variable will contain the shell specified in the password file. .It "term string Default terminal type if not able to determine" from other means. .It "timezone string Default value of $TZ environment variable." .It "umask number 022 Initial umask. Should always have a leading 0 to" ensure octal interpretation. .It "welcome file /etc/motd File containing welcome message." .El .Sh AUTHENTICATION .Bl -column passwd_prompt indent indent .It Sy "Name Type Notes Description" .\" .It "approve program Program to approve login. .It "copyright file File containing additional copyright information" .It "host.allow list List of remote host wildcards from which users in" the class may access. .It "host.deny list List of remote host wildcards from which users" in the class may not access. .It "login_prompt string The login prompt given by" .Xr login 1 .It "login-backoff number 3 The number of login attempts" allowed before the backoff delay is inserted after each subsequent attempt. The backoff delay is the number of tries above .Em login-backoff multiplied by 5 seconds. .It "login-retries number 10 The number of login attempts" allowed before the login fails. .It "passwd_format string sha512 The encryption format that new or" changed passwords will use. Valid values include "des", "md5", "blf", "sha256" and "sha512"; see .Xr crypt 3 for details. NIS clients using a .No non- Ns Fx NIS server should probably use "des". .It "passwd_prompt string The password prompt presented by" .Xr login 1 .It "times.allow list List of time periods during which" logins are allowed. .It "times.deny list List of time periods during which logins are" disallowed. .It "ttys.allow list List of ttys and ttygroups which users" in the class may use for access. .It "ttys.deny list List of ttys and ttygroups which users" in the class may not use for access. .It "warnexpire time Advance notice for pending account expiry." .It "warnpassword time Advance notice for pending password expiry." .\".It "widepasswords bool false Use the wide password format. The wide password .\" format allows up to 128 significant characters in the password. .El .Pp These fields are intended to be used by .Xr passwd 1 and other programs in the login authentication system. .Pp Capabilities that set environment variables are scanned for both .Ql \&~ and .Ql \&$ characters, which are substituted for a user's home directory and name respectively. To pass these characters literally into the environment variable, escape the character by preceding it with a backslash '\\'. .Pp The .Em host.allow and .Em host.deny entries are comma separated lists used for checking remote access to the system, and consist of a list of hostnames and/or IP addresses against which remote network logins are checked. Items in these lists may contain wildcards in the form used by shell programs for wildcard matching (See .Xr fnmatch 3 for details on the implementation). The check on hosts is made against both the remote system's Internet address and hostname (if available). If both lists are empty or not specified, then logins from any remote host are allowed. If host.allow contains one or more hosts, then only remote systems matching any of the items in that list are allowed to log in. If host.deny contains one or more hosts, then a login from any matching hosts will be disallowed. .Pp The .Em times.allow and .Em times.deny entries consist of a comma-separated list of time periods during which the users in a class are allowed to be logged in. These are expressed as one or more day codes followed by a start and end times expressed in 24 hour format, separated by a hyphen or dash. For example, MoThSa0200-1300 translates to Monday, Thursday and Saturday between the hours of 2 am and 1 p.m.. If both of these time lists are empty, users in the class are allowed access at any time. If .Em times.allow is specified, then logins are only allowed during the periods given. If .Em times.deny is specified, then logins are denied during the periods given, regardless of whether one of the periods specified in .Em times.allow applies. .Pp Note that .Xr login 1 enforces only that the actual login falls within periods allowed by these entries. Further enforcement over the life of a session requires a separate daemon to monitor transitions from an allowed period to a non-allowed one. .Pp The .Em ttys.allow and .Em ttys.deny entries contain a comma-separated list of tty devices (without the /dev/ prefix) that a user in a class may use to access the system, and/or a list of ttygroups (See .Xr getttyent 3 and .Xr ttys 5 for information on ttygroups). If neither entry exists, then the choice of login device used by the user is unrestricted. If only .Em ttys.allow is specified, then the user is restricted only to ttys in the given group or device list. If only .Em ttys.deny is specified, then the user is prevented from using the specified devices or devices in the group. If both lists are given and are non-empty, the user is restricted to those devices allowed by ttys.allow that are not available by ttys.deny. .Pp The .Em minpasswordlen and .Em minpasswordcase facilities for enforcing restrictions on password quality, which used to be supported by .Nm , have been superseded by the .Xr pam_passwdqc 8 PAM module. .Sh RESERVED CAPABILITIES The following capabilities are reserved for the purposes indicated and may be supported by third-party software. They are not implemented in the base system. .Bl -column host.accounted indent indent .It Sy "Name Type Notes Description" .It "accounted bool false Enable session time accounting for all users" in this class. .It "auth list passwd Allowed authentication styles." The first item is the default style. .It "auth-" Ns Ar type Ta "list Allowed authentication styles for the" authentication .Ar type . .It "autodelete time Time after expiry when account is auto-deleted." .It "bootfull bool false Enable 'boot only if ttygroup is full' strategy" when terminating sessions. .It "daytime time Maximum login time per day." .It "expireperiod time Time for expiry allocation." .It "graceexpire time Grace days for expired account." .It "gracetime time Additional grace login time allowed." .It "host.accounted list List of remote host wildcards from which" login sessions will be accounted. .It "host.exempt list List of remote host wildcards from which" login session accounting is exempted. .It "idletime time Maximum idle time before logout." .It "minpasswordlen number 6 The minimum length a local" password may be. .It "mixpasswordcase bool true Whether" .Xr passwd 1 will warn the user if an all lower case password is entered. .It "monthtime time Maximum login time per month." .It "passwordtime time Used by" .Xr passwd 1 to set next password expiry date. .It "refreshtime time New time allowed on account refresh." .It "refreshperiod str How often account time is refreshed." .It "sessiontime time Maximum login time per session." .It "sessionlimit number Maximum number of concurrent" login sessions on ttys in any group. .It "ttys.accounted list List of ttys and ttygroups for which" login accounting is active. .It "ttys.exempt list List of ttys and ttygroups for which login accounting" is exempt. .It "warntime time Advance notice for pending out-of-time." .It "weektime time Maximum login time per week." .El .Pp The .Em ttys.accounted and .Em ttys.exempt fields operate in a similar manner to .Em ttys.allow and .Em ttys.deny as explained above. Similarly with the .Em host.accounted and .Em host.exempt lists. .Sh SEE ALSO .Xr cap_mkdb 1 , .Xr login 1 , .Xr chroot 2 , .Xr getcap 3 , .Xr getttyent 3 , .Xr login_cap 3 , .Xr login_class 3 , .Xr pam 3 , .Xr passwd 5 , .Xr ttys 5 , .Xr ftpd 8 , .Xr pam_passwdqc 8 +.Sh HISTORY +The file +.Nm +first appeared in +.Fx 2.1.5 . Index: stable/12/lib/libutil/login_auth.3 =================================================================== --- stable/12/lib/libutil/login_auth.3 (revision 362661) +++ stable/12/lib/libutil/login_auth.3 (revision 362662) @@ -1,72 +1,79 @@ .\" Copyright (c) 1995 David Nugent .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, is permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. This work was done expressly for inclusion into FreeBSD. Other use .\" is permitted provided this notation is included. .\" 4. Absolutely no warranty of function or purpose is made by the author .\" David Nugent. .\" 5. Modifications may be freely made to this file providing the above .\" conditions are met. .\" .\" $FreeBSD$ .\" -.Dd December 29, 1996 +.Dd May 10, 2020 .Dt LOGIN_AUTH 3 .Os .Sh NAME .\" .Nm authenticate .\" .Nm auth_script .\" .Nm auth_env .\" .Nm auth_scan .\" .Nm auth_rmfiles .Nm auth_checknologin , .Nm auth_cat .\" .Nm auth_ttyok .\" .Nm auth_hostok .\" .Nm auth_timesok .Nd "authentication style support library for login class capabilities database" .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In login_cap.h .\" .Ft int .\". Fn authenticate "const char *name" "const char *classname" "const char *style" "const char *service" .\" .Ft int .\" .Fn auth_script "const char * path" ... .\" .Ft void .\" .Fn auth_env "void" .\" .Ft int .\" .Fn auth_scan "int ok" .\" .Ft void .\" .Fn auth_rmfiles "void" .Ft void .Fn auth_checknologin "login_cap_t *lc" .Ft int .Fn auth_cat "const char *file" .\" .Ft int .\" .Fn auth_ttyok "login_cap_t *lc" "const char *tty" .\" .Ft int .\" .Fn auth_hostok "login_cap_t *lc" "const char *hostname" "char const *ip" .\" .Ft int .\" .Fn auth_timesok "login_cap_t *lc" "time_t now" .Sh DESCRIPTION This set of functions support the login class authorisation style interface provided by .Xr login.conf 5 . .\" .Sh RETURN VALUES .Sh SEE ALSO .Xr getcap 3 , .Xr login_cap 3 , .Xr login_class 3 , .Xr login.conf 5 , .Xr termcap 5 +.Sh HISTORY +The functions +.Fn auth_checknologin +and +.Fn auth_cat +first appeared in +.Fx 2.1.5 . Index: stable/12/lib/libutil/login_cap.3 =================================================================== --- stable/12/lib/libutil/login_cap.3 (revision 362661) +++ stable/12/lib/libutil/login_cap.3 (revision 362662) @@ -1,579 +1,597 @@ .\" Copyright (c) 1995 David Nugent .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, is permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. This work was done expressly for inclusion into FreeBSD. Other use .\" is permitted provided this notation is included. .\" 4. Absolutely no warranty of function or purpose is made by the author .\" David Nugent. .\" 5. Modifications may be freely made to this file providing the above .\" conditions are met. .\" .\" $FreeBSD$ .\" -.Dd June 14, 2007 +.Dd May 10, 2020 .Dt LOGIN_CAP 3 .Os .Sh NAME .Nm login_close , .Nm login_getcapbool , .Nm login_getcaplist , .Nm login_getcapnum , .Nm login_getcapstr , .Nm login_getcapsize , .Nm login_getcaptime , .Nm login_getclass , .Nm login_getclassbyname , .Nm login_getpwclass , .Nm login_getstyle , .Nm login_getuserclass , .Nm login_setcryptfmt .Nd "functions for accessing the login class capabilities database" .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In login_cap.h .Ft void .Fn login_close "login_cap_t *lc" .Ft login_cap_t * .Fn login_getclassbyname "const char *nam" "const struct passwd *pwd" .Ft login_cap_t * .Fn login_getclass "const char *nam" .Ft login_cap_t * .Fn login_getpwclass "const struct passwd *pwd" .Ft login_cap_t * .Fn login_getuserclass "const struct passwd *pwd" .Ft "const char *" .Fn login_getcapstr "login_cap_t *lc" "const char *cap" "const char *def" "const char *error" .Ft "const char **" .Fn login_getcaplist "login_cap_t *lc" "const char *cap" "const char *chars" .Ft "const char *" .Fn login_getpath "login_cap_t *lc" "const char *cap" "const char *error" .Ft rlim_t .Fn login_getcaptime "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error" .Ft rlim_t .Fn login_getcapnum "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error" .Ft rlim_t .Fn login_getcapsize "login_cap_t *lc" "const char *cap" "rlim_t def" "rlim_t error" .Ft int .Fn login_getcapbool "login_cap_t *lc" "const char *cap" "int def" .Ft "const char *" .Fn login_getstyle "login_cap_t *lc" "const char *style" "const char *auth" .Ft const char * .Fn login_setcryptfmt "login_cap_t *lc" "const char *def" "const char *error" .Sh DESCRIPTION These functions represent a programming interface to the login classes database provided in .Xr login.conf 5 . This database contains capabilities, attributes and default environment and accounting settings for users and programs running as specific users, as determined by the login class field within entries in .Pa /etc/master.passwd . .Pp Entries in .Xr login.conf 5 consist of colon .Ql \&: separated fields, the first field in each record being one or more identifiers for the record (which must be unique for the entire database), each separated by a .Ql | , and may optionally include a description as the last .Sq name . Remaining fields in the record consist of keyword/data pairs. Long lines may be continued with a backslash within empty entries, with the second and subsequent lines optionally indented for readability. This is similar to the format used in .Xr termcap 5 , except that keywords are not limited to two significant characters, and are usually longer for improved readability. As with termcap entries, multiple records can be linked together (one record including another) using a field containing .Ql tc= Ns Va . The result is that the entire record referenced by .Va replaces the .Va tc= field at the point at which it occurs. See .Xr getcap 3 for further details on the format and use of a capabilities database. .Pp The .Nm login_cap interface provides a convenient means of retrieving login class records with all .Va tc= references expanded. A program will typically call one of .Fn login_getclass , .Fn login_getpwclass , .Fn login_getuserclass or .Fn login_getclassbyname according to its requirements. Each of these functions returns a login capabilities structure, .Vt login_cap_t , which may subsequently be used to interrogate the database for specific values using the rest of the API. Once the .Vt login_cap_t is of no further use, the .Fn login_close function should be called to free all resources used. .Pp The structure of .Vt login_cap_t is defined in .In login_cap.h , as: .Bd -literal -offset indent typedef struct { char *lc_class; char *lc_cap; char *lc_style; } login_cap_t; .Ed .Pp The .Fa lc_class member contains a pointer to the name of the login class retrieved. This may not necessarily be the same as the one requested, either directly via .Fn login_getclassbyname , or indirectly via a user's login record using .Fn login_getpwclass , by class name using .Fn login_getclass . If the referenced user has no login class specified in .Pa /etc/master.passwd , the class name is .Dv NULL or an empty string. If the class specified does not exist in the database, each of these functions will search for a record with an id of .Ql default , with that name returned in the .Fa lc_class field. In addition, if the referenced user has a UID of 0 (normally, .Ql root , although the user name is not considered) then .Fn login_getpwclass will search for a record with an id of .Ql root before it searches for the record with the id of .Ql default . .Pp The .Fa lc_cap field is used internally by the library to contain the expanded login capabilities record. Programs with unusual requirements may wish to use this with the lower-level .Fn getcap style functions to access the record directly. .Pp The .Fa lc_style field is set by the .Fn login_getstyle function to the authorisation style, according to the requirements of the program handling a login itself. .Pp The .Fn login_getclassbyname function is the basic means to get a .Vt login_cap_t object. It accepts two arguments: the first one, .Fa name , is the record identifier of the record to be retrieved; the second, .Fa pwd , is an optional pointer to a .Vt passwd structure. First of all, its arguments are used by the function to choose between system and user modes of operation. When in system mode, only the system login class database is used. When in user mode, the supplemental login class database in the user's home directory is allowed to override settings from the system database in a limited way as noted below. To minimize security implications, user mode is entered by .Fn login_getclassbyname if and only if .Fa name is .Dv LOGIN_MECLASS .Pq Ql me and .Fa pwd is not .Dv NULL . Otherwise system mode is chosen. .Pp In system mode, any record in the system database .Pa /etc/login.conf can be accessed, and a fallback to the default record is provided as follows. If .Fa name is .Dv NULL , an empty string, or a class that does not exist in the login class database, then the .Dv LOGIN_DEFCLASS record .Pq Ql default is returned instead. .Pp In user mode, only the .Dv LOGIN_MECLASS record .Pq Ql me is accessed and no fallback to the .Ql default record is provided. The directory specified by .Fa pwd->pw_dir is searched for a login database file called .Pa .login_conf , and only the .Ql me capability record contained within it may override the system record with the same name while other records are ignored. Using this scheme, an application can explicitly allow users to override a selected subset of login settings. To do so, the application should obtain two .Vt login_cap_t objects, one in user mode and the other in system mode, and then query the user object before the system object for login parameters that are allowed to be overridden by the user. For example, the user's .Pa .login_conf can provide a convenient way for a user to set up their preferred login environment before the shell is invoked on login if supported by .Xr login 1 . .Pp Note that access to the .Pa /etc/login.conf and .Pa .login_conf files will only be performed subject to the security checks documented in .Xr _secure_path 3 for the uids 0 and .Fa pwd->pw_uid respectively. .Pp If the specified record is .Dv NULL , empty or does not exist, and the system has no .Ql default record available to fall back to, there is a memory allocation error or for some reason .Xr cgetent 3 is unable to access the login capabilities database, this function returns .Dv NULL . .Pp The functions .Fn login_getclass , .Fn login_getpwclass and .Fn login_getuserclass retrieve the applicable login class record for the user's passwd entry or class name by calling .Fn login_getclassbyname . On failure, .Dv NULL is returned. The difference between these functions is that .Fn login_getuserclass includes the user's overriding .Pa .login_conf that exists in the user's home directory, and .Fn login_getpwclass and .Fn login_getclass restrict lookup only to the system login class database in .Pa /etc/login.conf . As explained earlier, .Fn login_getpwclass differs from .Fn login_getclass in that it allows the default class for a super-user as .Ql root if none has been specified in the password database. Otherwise, if the passwd pointer is .Dv NULL , or the user record has no login class, then the system .Ql default entry is retrieved. Essentially, .Fn login_getclass name is equivalent to .Fn login_getclassbyname name NULL and .Fn login_getuserclass pwd to .Fn login_getclassbyname LOGIN_MECLASS pwd . .Pp Once a program no longer wishes to use a .Vt login_cap_t object, .Fn login_close may be called to free all resources used by the login class. The .Fn login_close function may be passed a .Dv NULL pointer with no harmful side-effects. .Pp The remaining functions may be used to retrieve individual capability records. Each function takes a .Vt login_cap_t object as its first parameter, a capability tag as the second, and remaining parameters being default and error values that are returned if the capability is not found. The type of the additional parameters passed and returned depend on the .Em type of capability each deals with, be it a simple string, a list, a time value, a file or memory size value, a path (consisting of a colon-separated list of directories) or a boolean flag. The manpage for .Xr login.conf 5 deals in specific tags and their type. .Pp Note that with all functions in this group, you should not call .Xr free 3 on any pointers returned. Memory allocated during retrieval or processing of capability tags is automatically reused by subsequent calls to functions in this group, or deallocated on calling .Fn login_close . .Bl -tag -width "login_getcaplist()" .It Fn login_getcapstr This function returns a simple string capability. If the string is not found, then the value in .Fa def is returned as the default value, or if an error occurs, the value in the .Fa error parameter is returned. .It Fn login_getcaplist This function returns the value corresponding to the named capability tag as a list of values in a .Dv NULL terminated array. Within the login class database, some tags are of type .Vt list , which consist of one or more comma- or space separated values. Usually, this function is not called directly from an application, but is used indirectly via .Fn login_getstyle . .It Fn login_getpath This function returns a list of directories separated by colons .Ql \&: . Capability tags for which this function is called consist of a list of directories separated by spaces. .It Fn login_getcaptime This function returns a .Vt time value associated with a particular capability tag with the value expressed in seconds (the default), minutes, hours, days, weeks or (365 day) years or any combination of these. A suffix determines the units used: .Ql S for seconds, .Ql M for minutes, .Ql H for hours, .Ql D for days, .Ql W for weeks and .Ql Y for 365 day years. Case of the units suffix is ignored. .Pp Time values are normally used for setting resource, accounting and session limits. If supported by the operating system and compiler (which is true of .Fx ) , the value returned is a .Vt quad .Pq Vt long long , of type .Vt rlim_t . A value .Ql inf or .Ql infinity may be used to express an infinite value, in which case .Dv RLIM_INFINITY is returned. .It Fn login_getcapnum This function returns a numeric value for a tag, expressed either as .Ql tag= or the standard .Fn cgetnum format .Ql tag# . The first format should be used in preference to the second, the second format is provided for compatibility and consistency with the .Xr getcap 3 database format where numeric types use the .Ql \&# as the delimiter for numeric values. If in the first format, then the value given may be .Ql inf or .Ql infinity which results in a return value of .Dv RLIM_INFINITY . If the given capability tag cannot be found, the .Fa def parameter is returned, and if an error occurs, the .Fa error parameter is returned. .It Fn login_getcapsize .Fn login_getcapsize returns a value representing a size (typically, file or memory) which may be expressed as bytes (the default), 512 byte blocks, kilobytes, megabytes, gigabytes, and on systems that support the .Vt long long type, terabytes. The suffix used determines the units, and multiple values and units may be used in combination (e.g.\& 1m500k = 1.5 megabytes). A value with no suffix is interpreted as bytes, .Ql B as 512-byte blocks, .Ql K as kilobytes, .Ql M as megabytes, .Ql G as gigabytes and .Ql T as terabytes. Case is ignored. The error value is returned if there is a login capabilities database error, if an invalid suffix is used, or if a numeric value cannot be interpreted. .It Fn login_getcapbool This function returns a boolean value tied to a particular flag. It returns 0 if the given capability tag is not present or is negated by the presence of a .Ql tag@ (see .Xr getcap 3 for more information on boolean flags), and returns 1 if the tag is found. .It Fn login_getstyle This function is used by the login authorisation system to determine the style of login available in a particular case. The function accepts three parameters, the .Fa lc entry itself and two optional parameters, and authorisation type .Fa auth and .Fa style , and applies these to determine the authorisation style that best suites these rules. .Bl -bullet .It If .Fa auth is neither .Dv NULL nor an empty string, look for a tag of type .Ql auth- Ns Fa in the capability record. If not present, then look for the default tag .Va auth= . .It If no valid authorisation list was found from the previous step, then default to .Ql passwd as the authorisation list. .It If .Fa style is not .Dv NULL or empty, look for it in the list of authorisation methods found from the previous step. If .Fa style is .Dv NULL or an empty string, then default to .Ql passwd authorisation. .It If .Fa style is found in the chosen list of authorisation methods, then return that, otherwise return .Dv NULL . .El .Pp This scheme allows the administrator to determine the types of authorisation methods accepted by the system, depending on the means by which the access occurs. For example, the administrator may require skey or kerberos as the authentication method used for access to the system via the network, and standard methods via direct dialup or console logins, significantly reducing the risk of password discovery by "snooping" network packets. .It Fn login_setcryptfmt The .Fn login_setcryptfmt function is used to set the .Xr crypt 3 format using the .Va passwd_format configuration entry. If no entry is found, .Fa def is taken to be used as the fallback. If calling .Xr crypt_set_format 3 on the specifier fails, .Fa error is returned to indicate this. .El .Sh SEE ALSO .Xr login 1 , .Xr crypt 3 , .Xr getcap 3 , .Xr login_class 3 , .Xr login.conf 5 , .Xr termcap 5 +.Sh HISTORY +The functions +.Fn login_close , +.Fn login_getcapbool , +.Fn login_getcaplist , +.Fn login_getcapnum , +.Fn login_getcapstr , +.Fn login_getcapsize , +.Fn login_getcaptime , +.Fn login_getclass , +.Fn login_getclassbyname , +.Fn login_getpwclass , +.Fn login_getstyle , +.Fn login_getuserclass +and +.Fn login_setcryptfmt +first appeared in +.Fx 2.1.5 . Index: stable/12/lib/libutil/login_class.3 =================================================================== --- stable/12/lib/libutil/login_class.3 (revision 362661) +++ stable/12/lib/libutil/login_class.3 (revision 362662) @@ -1,223 +1,233 @@ .\" Copyright (c) 1995 David Nugent .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, is permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. This work was done expressly for inclusion into FreeBSD. Other use .\" is permitted provided this notation is included. .\" 4. Absolutely no warranty of function or purpose is made by the author .\" David Nugent. .\" 5. Modifications may be freely made to this file providing the above .\" conditions are met. .\" .\" $FreeBSD$ .\" -.Dd March 24, 2011 +.Dd May 10, 2020 .Dt LOGIN_CLASS 3 .Os .Sh NAME .Nm setclasscontext , .Nm setclasscpumask , .Nm setclassenvironment , .Nm setclassresources , .Nm setusercontext .Nd "functions for using the login class capabilities database" .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In login_cap.h .Ft int .Fn setclasscontext "const char *classname" "unsigned int flags" .Ft void .Fn setclasscpumask "login_cap_t *lc" .Ft void .Fn setclassenvironment "login_cap_t *lc" "const struct passwd *pwd" "int paths" .Ft void .Fn setclassresources "login_cap_t *lc" .Ft int .Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags" .Sh DESCRIPTION These functions provide a higher level interface to the login class database than those documented in .Xr login_cap 3 . These functions are used to set resource limits, environment and accounting settings for users on logging into the system and when selecting an appropriate set of environment and resource settings for system daemons based on login classes. These functions may only be called if the current process is running with root privileges. If the LOGIN_SETLOGIN flag is used this function calls .Xr setlogin 2 , and due care must be taken as detailed in the manpage for that function and this affects all processes running in the same session and not just the current process. .Pp The .Fn setclasscontext function sets various class context values (resource limits, umask and process priorities) based on values for a specific named class. .Pp The .Fn setusercontext function sets class context values based on a given login_cap_t object and a specific passwd record (if login_cap_t is NULL), the current session's login, and the current process user and group ownership. Each of these actions is selectable via bit-flags passed in the .Ar flags parameter, which is comprised of one or more of the following: .Bl -tag -width LOGIN_SETLOGINCLASS .It LOGIN_SETLOGIN Set the login associated with the current session to the user specified in the passwd structure using .Xr setlogin 2 . The .Ar pwd parameter must not be NULL if this option is used. .It LOGIN_SETUSER Set ownership of the current process to the uid specified in the .Ar uid parameter using .Xr setuid 2 . .It LOGIN_SETGROUP Set group ownership of the current process to the group id specified in the passwd structure using .Xr setgid 2 , and calls .Xr initgroups 3 to set up the group access list for the current process. The .Ar pwd parameter must not be NULL if this option is used. .It LOGIN_SETRESOURCES Set resource limits for the current process based on values specified in the system login class database. Class capability tags used, with and without -cur (soft limit) or -max (hard limit) suffixes and the corresponding resource setting: .Bd -literal cputime RLIMIT_CPU filesize RLIMIT_FSIZE datasize RLIMIT_DATA stacksize RLIMIT_STACK coredumpsize RLIMIT_CORE memoryuse RLIMIT_RSS memorylocked RLIMIT_MEMLOCK maxproc RLIMIT_NPROC openfiles RLIMIT_NOFILE sbsize RLIMIT_SBSIZE vmemoryuse RLIMIT_VMEM pseudoterminals RLIMIT_NPTS swapuse RLIMIT_SWAP kqueues RLIMIT_KQUEUES umtxp RLIMIT_UMTXP .Ed .It LOGIN_SETPRIORITY Set the scheduling priority for the current process based on the value specified in the system login class database. Class capability tags used: .Bd -literal priority .Ed .It LOGIN_SETUMASK Set the umask for the current process to a value in the user or system login class database. Class capability tags used: .Bd -literal umask .Ed .It LOGIN_SETPATH Set the "path" and "manpath" environment variables based on values in the user or system login class database. Class capability tags used with the corresponding environment variables set: .Bd -literal path PATH manpath MANPATH .Ed .It LOGIN_SETENV Set various environment variables based on values in the user or system login class database. Class capability tags used with the corresponding environment variables set: .Bd -literal lang LANG charset MM_CHARSET timezone TZ term TERM .Ed .Pp Additional environment variables may be set using the list type capability "setenv=var1 val1,var2 val2..,varN valN". .It LOGIN_SETMAC Set the MAC label for the current process to the label specified in system login class database. .It LOGIN_SETCPUMASK Create a new .Xr cpuset 2 and set the cpu affinity to the specified mask. The string may contain a comma separated list of numbers and/or number ranges as handled by the .Xr cpuset 1 utility or the case-insensitive string .Ql default . If the string is .Ql default no action will be taken. .It LOGIN_SETLOGINCLASS Set the login class of the current process using .Xr setloginclass 2 . .It LOGIN_SETALL Enables all of the above settings. .El .Pp Note that when setting environment variables and a valid passwd pointer is provided in the .Ar pwd parameter, the characters .Ql \&~ and .Ql \&$ are substituted for the user's home directory and login name respectively. .Pp The .Fn setclasscpumask , .Fn setclassresources and .Fn setclassenvironment functions are subsets of the setcontext functions above, but may be useful in isolation. .Sh RETURN VALUES The .Fn setclasscontext and .Fn setusercontext functions return -1 if an error occurred, or 0 on success. If an error occurs when attempting to set the user, login, group or resources, a message is reported to .Xr syslog 3 , with LOG_ERR priority and directed to the currently active facility. .Sh SEE ALSO .Xr cpuset 1 , .Xr ps 1 , .Xr cpuset 2 , .Xr setgid 2 , .Xr setlogin 2 , .Xr setloginclass 2 , .Xr setuid 2 , .Xr getcap 3 , .Xr initgroups 3 , .Xr login_cap 3 , .Xr mac_set_proc 3 , .Xr login.conf 5 , .Xr termcap 5 +.Sh HISTORY +The functions +.Fn setclasscontext , +.Fn setclasscpumask , +.Fn setclassenvironment , +.Fn setclassresources +and +.Fn setusercontext +first appeared in +.Fx 2.1.5 . Index: stable/12/lib/libutil/login_ok.3 =================================================================== --- stable/12/lib/libutil/login_ok.3 (revision 362661) +++ stable/12/lib/libutil/login_ok.3 (revision 362662) @@ -1,142 +1,150 @@ .\" Copyright (c) 1995 David Nugent .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, is permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. This work was done expressly for inclusion into FreeBSD. Other use .\" is permitted provided this notation is included. .\" 4. Absolutely no warranty of function or purpose is made by the author .\" David Nugent. .\" 5. Modifications may be freely made to this file providing the above .\" conditions are met. .\" .\" $FreeBSD$ .\" -.Dd January 2, 1997 +.Dd May 10, 2020 .Dt LOGIN_OK 3 .Os .Sh NAME .Nm auth_ttyok , .Nm auth_hostok , .Nm auth_timeok .Nd functions for checking login class based login restrictions .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In time.h .In login_cap.h .Ft int .Fn auth_ttyok "login_cap_t *lc" "const char *tty" .Ft int .Fn auth_hostok "login_cap_t *lc" "const char *host" "char const *ip" .Ft int .Fn auth_timeok "login_cap_t *lc" "time_t t" .Sh DESCRIPTION This set of functions checks to see if login is allowed based on login class capability entries in the login database, .Xr login.conf 5 . .Pp The .Fn auth_ttyok function checks to see if the named tty is available to users of a specific class, and is either in the .Em ttys.allow access list, and not in the .Em ttys.deny access list. An empty .Em ttys.allow list (or if no such capability exists for the given login class) logins via any tty device are allowed unless the .Em ttys.deny list exists and is non-empty, and the device or its tty group (see .Xr ttys 5 ) is not in the list. Access to ttys may be allowed or restricted specifically by tty device name, a device name which includes a wildcard (e.g.\& ttyD* or cuaD*), or may name a ttygroup, when group= tags have been assigned in .Pa /etc/ttys . Matching of ttys and ttygroups is case sensitive. Passing a .Dv NULL or empty string as the .Ar tty parameter causes the function to return a non-zero value. .Pp The .Fn auth_hostok function checks for any host restrictions for remote logins. The function checks on both a host name and IP address (given in its text form, typically n.n.n.n) against the .Em host.allow and .Em host.deny login class capabilities. As with ttys and their groups, wildcards and character classes may be used in the host allow and deny capability records. The .Xr fnmatch 3 function is used for matching, and the matching on hostnames is case insensitive. Note that this function expects that the hostname is fully expanded (i.e., the local domain name added if necessary) and the IP address is in its canonical form. No hostname or address lookups are attempted. .Pp It is possible to call this function with either the hostname or the IP address missing (i.e.\& .Dv NULL ) and matching will be performed only on the basis of the parameter given. Passing .Dv NULL or empty strings in both parameters will result in a non-zero return value. .Pp The .Fn auth_timeok function checks to see that a given time value is within the .Em times.allow login class capability and not within the .Em times.deny access lists. An empty or non-existent .Em times.allow list allows access at any time, except if a given time is falls within a period in the .Em times.deny list. The format of time period records contained in both .Em times.allow and .Em times.deny capability fields is explained in detail in the .Xr login_times 3 manual page. .Sh RETURN VALUES A non-zero return value from any of these functions indicates that login access is granted. A zero return value means either that the item being tested is not in the .Em allow access list, or is within the .Em deny access list. .Sh SEE ALSO .Xr getcap 3 , .Xr login_cap 3 , .Xr login_class 3 , .Xr login_times 3 , .Xr login.conf 5 , .Xr termcap 5 +.Sh HISTORY +The functions +.Fn auth_ttyok , +.Fn auth_hostok + and +.Fn auth_timeok +functions first appeared in +.Fx 2.1.5 . Index: stable/12/lib/libutil/login_times.3 =================================================================== --- stable/12/lib/libutil/login_times.3 (revision 362661) +++ stable/12/lib/libutil/login_times.3 (revision 362662) @@ -1,179 +1,189 @@ .\" Copyright (c) 1995 David Nugent .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, is permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. This work was done expressly for inclusion into FreeBSD. Other use .\" is permitted provided this notation is included. .\" 4. Absolutely no warranty of function or purpose is made by the author .\" David Nugent. .\" 5. Modifications may be freely made to this file providing the above .\" conditions are met. .\" .\" $FreeBSD$ .\" -.Dd October 20, 2008 +.Dd May 10, 2020 .Dt LOGIN_TIMES 3 .Os .Sh NAME .Nm parse_lt , .Nm in_lt , .Nm in_ltm , .Nm in_ltms , .Nm in_lts .Nd functions for parsing and checking login time periods .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In time.h .In login_cap.h .Ft login_time_t .Fn parse_lt "const char *str" .Ft int .Fn in_lt "const login_time_t *lt" "time_t *ends" .Ft int .Fn in_ltm "const login_time_t *lt" "struct tm *t" "time_t *ends" .Ft int .Fn in_ltms "const login_time_t *lt" "struct tm *t" "time_t *ends" .Ft int .Fn in_lts "const login_time_t *lt" "time_t *ends" .Sh DESCRIPTION This set of functions may be used for parsing and checking login and session times against a predefined list of allowed login times as used in .Xr login.conf 5 . .Pp The format of allowed and disallowed session times specified in the .Ar times.allow and .Ar times.deny capability fields in a login class are comprised of a prefix which specifies one or more 2- or 3-character day codes, followed by a start and end time in 24 hour format separated by a hyphen. Day codes may be concatenated together to select specific days, or the special mnemonics "Any" and "All" (for any/all days of the week), "Wk" for any day of the week (excluding Saturdays and Sundays) and "Wd" for any weekend day may be used. .Pp For example, the following time period: .Dl MoThFrSa1400-2200 is interpreted as Monday, Thursday through Saturday between the hours of 2pm and 10pm. .Dl Wd0600-1800 means Saturday and Sunday, between the hours of 6am through 6pm, and .Dl Any0400-1600 means any day of the week, between 4am and 4pm. .Pp Note that all time periods reference system local time. .Pp The .Fn parse_lt function converts the ASCII representation of a time period into a structure of type .Ft login_time_t . This is defined as: .Bd -literal typedef struct login_time { u_short lt_start; /* Start time */ u_short lt_end; /* End time */ u_char lt_dow; /* Days of week */ } login_time_t; .Ed .Pp The .Ar lt_start and .Ar lt_end fields contain the number of minutes past midnight at which the described period begins and ends. The .Ar lt_dow field is a bit field, containing one bit for each day of the week and one bit unused. A series .Em LTM_* macros may be used for testing bits individually and in combination. If no bits are set in this field - i.e., it contains the value .Em LTM_NONE - then the entire period is assumed invalid. This is used as a convention to mark the termination of an array of login_time_t values. If .Fn parse_lt returns a .Ar login_time_t with .Ar lt_dow equal to .Em LTM_NONE then a parsing error was encountered. .Pp The remaining functions provide the ability to test a given time_t or struct tm value against a specific time period or array of time periods. The .Fn in_ltm function determines whether the given time described by the struct tm passed as the second parameter falls within the period described by the first parameter. A boolean value is returned, indicating whether or not the time specified falls within the period. If the time does fall within the time period, and the third parameter to the function is not NULL, the time at which the period ends relative to the time passed is returned. .Pp The .Fn in_ltms function is similar to .Fn in_ltm except that the first parameter must be a pointer to an array of login_time_t objects, which is up to LC_MAXTIMES (64) elements in length, and terminated by an element with its .Ar lt_dow field set to .Em LTM_NONE . .Pp The .Fn in_lt and .Fn in_lts functions are equivalent to .Fn in_ltm and .Fn in_ltms , respectively, with the second argument set to the current time as returned by .Xr localtime 3 . .Sh RETURN VALUES The .Fn parse_lt function returns a filled in structure of type login_time_t containing the parsed time period. If a parsing error occurs, the lt_dow field is set to .Em LTM_NONE (i.e., 0). .Pp The .Fn in_ltm function returns non-zero if the given time falls within the period described by the login_time_t passed as the first parameter. .Pp The .Fn in_ltms function returns the index of the first time period found in which the given time falls, or -1 if none of them apply. .Sh SEE ALSO .Xr getcap 3 , .Xr login_cap 3 , .Xr login_class 3 , .Xr login.conf 5 , .Xr termcap 5 +.Sh HISTORY +The functions +.Fn parse_lt , +.Fn in_lt , +.Fn in_ltm , +.Fn in_ltms +and +.Fn in_lts +first appeared in +.Fx 2.1.5 . Index: stable/12/lib/libutil/login_tty.3 =================================================================== --- stable/12/lib/libutil/login_tty.3 (revision 362661) +++ stable/12/lib/libutil/login_tty.3 (revision 362662) @@ -1,65 +1,71 @@ .\" .\" Copyright (c) 1996 Joerg Wunsch .\" .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" " -.Dd December 29, 1996 +.Dd May 10, 2020 .Dt LOGIN_TTY 3 .Os .Sh NAME .Nm login_tty .Nd prepare a tty for a new login session .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In libutil.h .Ft int .Fn login_tty "int fd" .Sh DESCRIPTION The function .Fn login_tty prepares a terminal for a new login session. The file descriptor .Ar fd passed to .Fn login_tty must be opened for reading and writing on a terminal device. It will be made the controlling terminal for the calling process, after allocating a new session with .Xr setsid 2 . This terminal device will also be made the standard input, standard output, and standard error output of the calling process. .Sh RETURN VALUES The .Fn login_tty function returns -1 if it could not make the device referenced by .Ar fd the controlling terminal of the calling process, and 0 otherwise. .Sh SEE ALSO .Xr dup2 2 , .Xr ioctl 2 , .Xr setsid 2 , .Xr tty 4 +.Sh HISTORY +The function +.Fn login_tty +first appeared in +.Bx 4.4 . + Index: stable/12/lib/libutil/pidfile.3 =================================================================== --- stable/12/lib/libutil/pidfile.3 (revision 362661) +++ stable/12/lib/libutil/pidfile.3 (revision 362662) @@ -1,297 +1,306 @@ .\" Copyright (c) 2005 Pawel Jakub Dawidek .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd February 8, 2012 +.Dd May 10, 2020 .Dt PIDFILE 3 .Os .Sh NAME .Nm pidfile_open , .Nm pidfile_write , .Nm pidfile_close , .Nm pidfile_remove .Nd "library for PID files handling" .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In libutil.h .Ft "struct pidfh *" .Fn pidfile_open "const char *path" "mode_t mode" "pid_t *pidptr" .Ft int .Fn pidfile_write "struct pidfh *pfh" .Ft int .Fn pidfile_close "struct pidfh *pfh" .Ft int .Fn pidfile_remove "struct pidfh *pfh" .Ft int .Fn pidfile_fileno "struct pidfh *pfh" .Sh DESCRIPTION The .Nm pidfile family of functions allows daemons to handle PID files. It uses .Xr flopen 3 to lock a pidfile and detect already running daemons. .Pp The .Fn pidfile_open function opens (or creates) a file specified by the .Fa path argument and locks it. If .Fa pidptr argument is not .Dv NULL and file can not be locked, the function will use it to store a PID of an already running daemon or .Li -1 in case daemon did not write its PID yet. The function does not write process' PID into the file here, so it can be used before .Fn fork Ns ing and exit with a proper error message when needed. If the .Fa path argument is .Dv NULL , .Pa /var/run/ Ns Ao Va progname Ac Ns Pa .pid file will be used. The .Fn pidfile_open function sets the O_CLOEXEC close-on-exec flag when opening the pidfile. .Pp The .Fn pidfile_write function writes process' PID into a previously opened file. The file is truncated before write, so calling the .Fn pidfile_write function multiple times is supported. .Pp The .Fn pidfile_close function closes a pidfile. It should be used after daemon .Fn fork Ns s to start a child process. .Pp The .Fn pidfile_remove function closes and removes a pidfile. .Pp The .Fn pidfile_fileno function returns the file descriptor for the open pidfile. .Sh RETURN VALUES The .Fn pidfile_open function returns a valid pointer to a .Vt pidfh structure on success, or .Dv NULL if an error occurs. If an error occurs, .Va errno will be set. .Pp .Rv -std pidfile_write pidfile_close pidfile_remove .Pp The .Fn pidfile_fileno function returns the low-level file descriptor. It returns .Li -1 and sets .Va errno if a NULL .Vt pidfh is specified, or if the pidfile is no longer open. .Sh EXAMPLES The following example shows in which order these functions should be used. Note that it is safe to pass .Dv NULL to .Fn pidfile_write , .Fn pidfile_remove , .Fn pidfile_close and .Fn pidfile_fileno functions. .Bd -literal struct pidfh *pfh; pid_t otherpid, childpid; pfh = pidfile_open("/var/run/daemon.pid", 0600, &otherpid); if (pfh == NULL) { if (errno == EEXIST) { errx(EXIT_FAILURE, "Daemon already running, pid: %jd.", (intmax_t)otherpid); } /* If we cannot create pidfile from other reasons, only warn. */ warn("Cannot open or create pidfile"); /* * Even though pfh is NULL we can continue, as the other pidfile_* * function can handle such situation by doing nothing except setting * errno to EDOOFUS. */ } if (daemon(0, 0) == -1) { warn("Cannot daemonize"); pidfile_remove(pfh); exit(EXIT_FAILURE); } pidfile_write(pfh); for (;;) { /* Do work. */ childpid = fork(); switch (childpid) { case -1: syslog(LOG_ERR, "Cannot fork(): %s.", strerror(errno)); break; case 0: pidfile_close(pfh); /* Do child work. */ break; default: syslog(LOG_INFO, "Child %jd started.", (intmax_t)childpid); break; } } pidfile_remove(pfh); exit(EXIT_SUCCESS); .Ed .Sh ERRORS The .Fn pidfile_open function will fail if: .Bl -tag -width Er .It Bq Er EEXIST Some process already holds the lock on the given pidfile, meaning that a daemon is already running. If .Fa pidptr argument is not .Dv NULL the function will use it to store a PID of an already running daemon or .Li -1 in case daemon did not write its PID yet. .It Bq Er ENAMETOOLONG Specified pidfile's name is too long. .It Bq Er EINVAL Some process already holds the lock on the given pidfile, but PID read from there is invalid. .El .Pp The .Fn pidfile_open function may also fail and set .Va errno for any errors specified for the .Xr fstat 2 , .Xr open 2 , and .Xr read 2 calls. .Pp The .Fn pidfile_write function will fail if: .Bl -tag -width Er .It Bq Er EDOOFUS Improper function use. Probably called before .Fn pidfile_open . .El .Pp The .Fn pidfile_write function may also fail and set .Va errno for any errors specified for the .Xr fstat 2 , .Xr ftruncate 2 , and .Xr write 2 calls. .Pp The .Fn pidfile_close function may fail and set .Va errno for any errors specified for the .Xr close 2 and .Xr fstat 2 calls. .Pp The .Fn pidfile_remove function will fail if: .Bl -tag -width Er .It Bq Er EDOOFUS Improper function use. Probably called not from the process which made .Fn pidfile_write . .El .Pp The .Fn pidfile_remove function may also fail and set .Va errno for any errors specified for the .Xr close 2 , .Xr fstat 2 , .Xr write 2 , and .Xr unlink 2 system calls and the .Xr flopen 3 library function. .Pp The .Fn pidfile_fileno function will fail if: .Bl -tag -width Er .It Bq Er EDOOFUS Improper function use. Probably called not from the process which used .Fn pidfile_open . .El .Sh SEE ALSO .Xr open 2 , .Xr daemon 3 , .Xr flopen 3 +.Sh HISTORY +The functions +.Fn pidfile_open , +.Fn pidfile_write , +.Fn pidfile_close +and +.Fn pidfile_remove +first appeared in +.Fx 5.5 . .Sh AUTHORS .An -nosplit The .Nm pidfile functionality is based on ideas from .An John-Mark Gurney Aq Mt jmg@FreeBSD.org . .Pp The code and manual page was written by .An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org . Index: stable/12/lib/libutil/pw_util.3 =================================================================== --- stable/12/lib/libutil/pw_util.3 (revision 362661) +++ stable/12/lib/libutil/pw_util.3 (revision 362662) @@ -1,301 +1,304 @@ .\" Copyright (c) 2012 Baptiste Daroussin .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd July 26, 2018 +.Dd May 10, 2020 .Dt PW_UTIL 3 .Os .Sh NAME .Nm pw_copy , .Nm pw_dup , .Nm pw_edit , .Nm pw_equal , .Nm pw_fini , .Nm pw_init , .Nm pw_make , .Nm pw_make_v7 , .Nm pw_mkdb , .Nm pw_lock , .Nm pw_scan , .Nm pw_tempname , .Nm pw_tmp .Nd "functions for passwd file handling" .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In pwd.h .In libutil.h .Ft int .Fn pw_copy "int ffd" "int tfd" "const struct passwd *pw" "struct passwd *oldpw" .Ft "struct passwd *" .Fn pw_dup "const struct passwd *pw" .Ft int .Fn pw_edit "int nosetuid" .Ft int .Fn pw_equal "const struct passwd *pw1" "const struct passwd *pw2" .Ft void .Fn pw_fini "void" .Ft int .Fn pw_init "const char *dir" "const char *master" .Ft void .Fn pw_initpwd "struct passwd *pw" .Ft "char *" .Fn pw_make "const struct passwd *pw" .Ft "char *" .Fn pw_make_v7 "const struct passwd *pw" .Ft int .Fn pw_mkdb "const char *user" .Ft int .Fn pw_lock "void" .Ft "struct passwd *" .Fn pw_scan "const char *line" "int flags" .Ft "const char *" .Fn pw_tempname "void" .Ft int .Fn pw_tmp "int mfd" .Sh DESCRIPTION The .Fn pw_copy function reads a password file from .Vt ffd and writes it back out to .Vt tfd possibly with modifications: .Bl -dash .It If .Fa pw is .Dv NULL and .Fa oldpw is not .Dv NULL , then the record represented by .Fa oldpw will not be copied (corresponding to user deletion). .It If .Fa pw and .Fa oldpw are not .Dv NULL then the record corresponding to .Fa pw will be replaced by the record corresponding to .Fa oldpw . .It If .Vt pw is set and .Vt oldpw is .Dv NULL then the record corresponding to .Vt pw will be appended (corresponding to user addition). .El .Pp The .Fn pw_copy function returns -1 in case of failure otherwise 0. .Pp The .Fn pw_dup function duplicates the .Vt struct passwd pointed to by .Fa pw and returns a pointer to the copy, or .Dv NULL in case of failure. The new .Vt struct passwd is allocated with .Xr malloc 3 , and it is the caller's responsibility to free it with .Xr free 3 . .Pp The .Fn pw_edit function invokes the command specified by the .Ev EDITOR environment variable (or .Pa /usr/bin/vi if .Ev EDITOR is not defined) on a temporary copy of the master password file created by .Fn pw_tmp . If the file was modified, .Fn pw_edit installs it and regenerates the password database. The .Fn pw_edit function returns -1 in case of failure, 0 if the file was not modified, and a non-zero positive number if the file was modified and successfully installed. .Pp The .Fn pw_equal function compares two .Vt struct passwd and returns 0 if they are equal. .Pp The .Fn pw_fini function destroy the temporary file created by .Fn pw_tmp if any, kills any running instance of .Ev EDITOR executed by .Fn pw_edit if any, and closes the lock created by .Fn pw_lock if any. .Pp The .Fn pw_init initializes the static variable representing the path to a password file. .Fa dir is the directory where the password file is located. If set to .Dv NULL , it will default to .Pa /etc . .Fa master is the name of the password file. If set to .Dv NULL? it will default to .Pa master.passwd .Pp The .Fn pw_initpwd function initializes the .Vt passwd struct to canonical values. The entire structure is zeroed, then .Va pw_uid and .Va pw_gid are set to -1, and all string pointers are set to point at an internally-defined zero-length string. .Pp The .Fn pw_make function creates a properly formatted .Bx .Xr passwd 5 line from a .Vt struct passwd , and returns a pointer to the resulting string. The string is allocated with .Xr malloc 3 , and it is the caller's responsibility to free it with .Xr free 3 . .Pp The .Fn pw_make_v7 function creates a properly formatted .Ux V7 .Xr passwd 5 line from a .Vt struct passwd , and returns a pointer to the resulting string. The string is allocated with .Xr malloc 3 , and it is the caller's responsibility to free it with .Xr free 3 . .Pp The .Fn pw_mkdb function regenerates the password database by running .Xr pwd_mkdb 8 . If .Fa user only the record corresponding to that user will be updated. The .Fn pw_mkdb function returns 0 in case of success and -1 in case of failure. .Pp The .Fn pw_lock function locks the master password file. It returns a file descriptor to the master password file on success and -1 on failure. .Pp The .Fn pw_scan function is a wrapper around the internal libc function .Fn __pw_scan . It scans the master password file for a line corresponding to the .Fa line provided and return a .Vt struct passwd if it matched an existing record. In case of failure, it returns .Dv NULL . Otherwise, it returns a pointer to a .Vt struct passwd containing the matching record. The .Vt struct passwd is allocated with .Xr malloc 3 , and it is the caller's responsibility to free it with .Xr free 3 . .Pp The .Fn pw_tempname function returns the temporary name of the masterfile created via .Fn pw_tmp . .Pp The .Fn pw_tmp creates and opens a presumably safe temporary password file. If .Fa mfd is a file descriptor to an open password file, it will be read and written back to the temporary password file. Otherwise if should be set -1. The .Fn pw_tmp returns an open file descriptor to the temporary password file or -1 in case of failure. +.Sh HISTORY +The functions for passwd file handling first appeared in +.Bx 4.4 . .Sh AUTHORS Portions of this software were developed for the .Fx Project by ThinkSec AS and Network Associates Laboratories, the Security Research Division of Network Associates, Inc.\& under DARPA/SPAWAR contract N66001-01-C-8035 .Pq Dq CBOSS , as part of the DARPA CHATS research program. .Pp This manual page was written by .An Baptiste Daroussin Aq Mt bapt@FreeBSD.org . Index: stable/12/lib/libutil/realhostname.3 =================================================================== --- stable/12/lib/libutil/realhostname.3 (revision 362661) +++ stable/12/lib/libutil/realhostname.3 (revision 362662) @@ -1,102 +1,107 @@ .\" Copyright (c) 1999 Brian Somers .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" .Dd April 6, 1999 .Dt REALHOSTNAME 3 .Os .Sh NAME .Nm realhostname .Nd "convert an IP number to the real host name" .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In libutil.h .Ft int .Fn realhostname "char *host" "size_t hsize" "const struct in_addr *ip" .Sh DESCRIPTION The function .Fn realhostname converts .Ar ip to the corresponding host name. This is done by resolving .Ar ip to a host name and then ensuring that the host name resolves back to .Ar ip . .Pp .Ar host must point to a buffer of at least .Ar hsize bytes, and will always be written to by this function. .Pp If the name resolution does not work both ways or if the host name is longer than .Ar hsize bytes, .Xr inet_ntoa 3 is used to convert .Ar ip to an ASCII form. .Pp If the string written to .Ar host is .Ar hsize bytes long, .Ar host will not be NUL terminated. .Sh RETURN VALUES The .Fn realhostname function will return one of the following constants which are defined in .In libutil.h : .Bl -tag -width XXX -offset XXX .It Li HOSTNAME_FOUND A valid host name was found. .It Li HOSTNAME_INCORRECTNAME A host name was found, but it did not resolve back to the passed .Ar ip . .Ar host now contains the numeric value of .Ar ip . .It Li HOSTNAME_INVALIDADDR .Ar ip could not be resolved. .Ar host now contains the numeric value of .Ar ip . .It Li HOSTNAME_INVALIDNAME A host name was found, but it could not be resolved back to any ip number. .Ar host now contains the numeric value of .Ar ip . .El .Sh SEE ALSO .Xr gethostbyaddr 3 , .Xr gethostbyname 3 , .Xr inet_ntoa 3 , .Xr realhostname_sa 3 +.Sh HISTORY +The +.Fn realhostname +function first appeared in +.Fx 3.2 . Index: stable/12/lib/libutil/trimdomain.3 =================================================================== --- stable/12/lib/libutil/trimdomain.3 (revision 362661) +++ stable/12/lib/libutil/trimdomain.3 (revision 362662) @@ -1,85 +1,90 @@ .\" Copyright (c) 1999 Brian Somers .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" .Dd April 7, 1999 .Dt TRIMDOMAIN 3 .Os .Sh NAME .Nm trimdomain .Nd "trim the current domain name from a host name" .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In libutil.h .Ft void .Fn trimdomain "char *fullhost" "int hostsize" .Sh DESCRIPTION The function .Fn trimdomain removes the current domain name from the passed .Ar fullhost name by writing a .Dv NUL character over the first period of the passed name. The current domain name is determined by calling .Xr gethostname 3 and removing everything up to the first period. The name is determined the first time this function is called and is cached for future use. .Pp The .Fn trimdomain function will only trim the domain name if the passed .Ar fullname ends with the current domain name and if the length of the resulting host name does not exceed .Ar hostsize . .Pp If the passed .Ar fullname is actually a .Dv DISPLAY specification of the form .Sm off .Ar host . domain : nn Oo . .Ar nn .Oc .Sm on and the domain name is the same as the local domain name, .Fn trimdomain will remove the embedded domain name, copying the screen and display numbers to the end of the base host name and resulting in .Sm off .Ar host : nn Op . Ar nn . .Sm on .Sh RETURN VALUES The .Fn trimdomain function does not return a value. .Sh SEE ALSO .Xr gethostname 3 +.Sh HISTORY +The function +.Fn trimdomain +first appeared in +.Fx 3.2 . Index: stable/12/lib/libutil/uucplock.3 =================================================================== --- stable/12/lib/libutil/uucplock.3 (revision 362661) +++ stable/12/lib/libutil/uucplock.3 (revision 362662) @@ -1,183 +1,191 @@ .\" .\" Copyright (c) 1996 Brian Somers .\" .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" " -.Dd March 30, 1997 +.Dd May 10, 2020 .Dt UUCPLOCK 3 .Os .Sh NAME .Nm uu_lock , .Nm uu_unlock , .Nm uu_lockerr .Nd acquire and release control of a serial device .Sh LIBRARY .Lb libutil .Sh SYNOPSIS .In sys/types.h .In libutil.h .Ft int .Fn uu_lock "const char *ttyname" .Ft int .Fn uu_lock_txfr "const char *ttyname" "pid_t pid" .Ft int .Fn uu_unlock "const char *ttyname" .Ft const char * .Fn uu_lockerr "int uu_lockresult" .Sh DESCRIPTION The .Fn uu_lock function attempts to create a lock file called .Pa /var/spool/lock/LCK.. with a suffix given by the passed .Fa ttyname . If the file already exists, it is expected to contain the process id of the locking program. .Pp If the file does not already exist, or the owning process given by the process id found in the lock file is no longer running, .Fn uu_lock will write its own process id into the file and return success. .Pp .Fn uu_lock_txfr transfers lock ownership to another process. .Fn uu_lock must have previously been successful. .Pp .Fn uu_unlock removes the lockfile created by .Fn uu_lock for the given .Fa ttyname . Care should be taken that .Fn uu_lock was successful before calling .Fn uu_unlock . .Pp .Fn uu_lockerr returns an error string representing the error .Fa uu_lockresult , as returned from .Fn uu_lock . .Sh RETURN VALUES .Fn uu_unlock returns 0 on success and -1 on failure. .Pp .Fn uu_lock may return any of the following values: .Pp .Dv UU_LOCK_INUSE : The lock is in use by another process. .Pp .Dv UU_LOCK_OK : The lock was successfully created. .Pp .Dv UU_LOCK_OPEN_ERR : The lock file could not be opened via .Xr open 2 . .Pp .Dv UU_LOCK_READ_ERR : The lock file could not be read via .Xr read 2 . .Pp .Dv UU_LOCK_CREAT_ERR : Cannot create temporary lock file via .Xr creat 2 . .Pp .Dv UU_LOCK_WRITE_ERR : The current process id could not be written to the lock file via a call to .Xr write 2 . .Pp .Dv UU_LOCK_LINK_ERR : Cannot link temporary lock file via .Xr link 2 . .Pp .Dv UU_LOCK_TRY_ERR : Locking attempts are failed after 5 tries. .Pp If a value of .Dv UU_LOCK_OK is passed to .Fn uu_lockerr , an empty string is returned. Otherwise, a string specifying the reason for failure is returned. .Fn uu_lockerr uses the current value of .Va errno to determine the exact error. Care should be made not to allow .Va errno to be changed between calls to .Fn uu_lock and .Fn uu_lockerr . .Pp .Fn uu_lock_txfr may return any of the following values: .Pp .Dv UU_LOCK_OK : The transfer was successful. The specified process now holds the device lock. .Pp .Dv UU_LOCK_OWNER_ERR : The current process does not already own a lock on the specified device. .Pp .Dv UU_LOCK_WRITE_ERR : The new process id could not be written to the lock file via a call to .Xr write 2 . .Sh ERRORS If .Fn uu_lock returns one of the error values above, the global value .Va errno can be used to determine the cause. Refer to the respective manual pages for further details. .Pp .Fn uu_unlock will set the global variable .Va errno to reflect the reason that the lock file could not be removed. Refer to the description of .Xr unlink 2 for further details. .Sh SEE ALSO .Xr lseek 2 , .Xr open 2 , .Xr read 2 , .Xr write 2 +.Sh HISTORY +The functions +.Fn uu_lock , +.Fn uu_unlock +and +.Fn uu_lockerr +first appeared in +.Fx 2.0.5 . .Sh BUGS It is possible that a stale lock is not recognised as such if a new processes is assigned the same processes id as the program that left the stale lock. .Pp The calling process must have write permissions to the .Pa /var/spool/lock directory. There is no mechanism in place to ensure that the permissions of this directory are the same as those of the serial devices that might be locked. Index: stable/12 =================================================================== --- stable/12 (revision 362661) +++ stable/12 (revision 362662) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r362169