Initial import from FreeBSD RELENG_4:
[dragonfly.git] / share / man / man9 / suser.9
1 .\"
2 .\" Copyright (c) 1996 Julian R Elischer
3 .\" All rights reserved.
4 .\"
5 .\" This code is derived from software contributed by Kenneth Stailey.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed for the FreeBSD Project
18 .\"     by Julian R Elischer
19 .\" 4. The name of the author may not be used to endorse or promote products
20 .\"    derived from this software without specific prior written permission.
21 .\"
22 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" SUCH DAMAGE.
33 .\"
34 .\" $FreeBSD: src/share/man/man9/suser.9,v 1.9.2.5 2001/12/17 11:30:19 ru Exp $
35 .\"
36 .Dd October 15, 1996
37 .Dt SUSER 9
38 .Os
39 .Sh NAME
40 .Nm suser
41 .Nd check if we are superuser and note
42 .Sh SYNOPSIS
43 .In sys/param.h
44 .In sys/proc.h
45 .In sys/ucred.h
46 .Ft int
47 .Fn suser "struct proc *proc"
48 .Ft int
49 .Fn suser_xxx "struct ucred *cred" "struct proc *proc" "int flags"
50 .Sh DESCRIPTION
51 The
52 .Nm
53 and
54 .Nm suser_xxx
55 functions checks if the credentials given include superuser powers.
56 .Pp
57 The
58 .Nm
59 function is the most common, and should be used unless special
60 circumstances dictate otherwise.
61 .Pp
62 The
63 .Nm suser_xxx
64 function should be used when the credentials to be checked are
65 not the process' own, when there is no process or when superuser
66 powers should be extended to imprisoned roots.
67 .Pp
68 By default a process does not command superuser powers if it has
69 been imprisoned by the
70 .Xr jail 2
71 system call.
72 There are cases however where this is appropriate, and this can
73 be done by setting the
74 .Dv PRISON_ROOT
75 bit in the flags argument to the
76 .Nm suser_xxx
77 function.  It is important to review carefully in each case that
78 this does not weaken the prison.  Generally only where the action
79 is protected by the
80 .Xr chroot 2
81 implicit in
82 .Xr jail 2
83 call should such powers be granted.
84 .Pp
85 The
86 .Nm
87 and
88 .Nm suser_xxx
89 functions note the fact that superuser powers have been used in the
90 process structure of the process specified.
91 Because part of their function is to notice
92 whether superuser powers have been used,
93 the functions should only be called after other permission
94 possibilities have been exhausted.
95 .Sh RETURN VALUES
96 The
97 .Nm
98 and
99 .Nm suser_xxx
100 functions return 0 if the user has superuser powers and
101 .Er EPERM
102 otherwise.
103 This is the
104 .Em reverse logic
105 of some other implementations of
106 .Nm
107 in which a TRUE response indicates superuser powers.