]> git.saurik.com Git - apple/xnu.git/blob - bsd/man/man2/getlogin.2
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / man / man2 / getlogin.2
1 .\" $NetBSD: getlogin.2,v 1.4 1995/02/27 12:33:03 cgd Exp $
2 .\"
3 .\" Copyright (c) 1989, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
21 .\"
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, 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 .\" @(#)getlogin.2 8.1 (Berkeley) 6/9/93
35 .\"
36 .Dd June 9, 1993
37 .Dt GETLOGIN 2
38 .Os BSD 4.2
39 .Sh NAME
40 .Nm getlogin ,
41 .Nm setlogin
42 .Nd get/set login name
43 .Sh SYNOPSIS
44 .Fd #include <unistd.h>
45 .Ft char *
46 .Fn getlogin void
47 .Ft int
48 .Fn setlogin "const char *name"
49 .Sh DESCRIPTION
50 The
51 .Fn getlogin
52 routine
53 returns the login name of the user associated with the current session,
54 as previously set by
55 .Fn setlogin .
56 The name is normally associated with a login shell
57 at the time a session is created,
58 and is inherited by all processes descended from the login shell.
59 (This is true even if some of those processes assume another user ID,
60 for example when
61 .Xr su 1
62 is used.)
63 .Pp
64 .Fn Setlogin
65 sets the login name of the user associated with the current session to
66 .Fa name .
67 This call is restricted to the super-user, and
68 is normally used only when a new session is being created on behalf
69 of the named user
70 (for example, at login time, or when a remote shell is invoked).
71 .Sh RETURN VALUES
72 If a call to
73 .Fn getlogin
74 succeeds, it returns a pointer to a null-terminated string in a static buffer.
75 If the name has not been set, it returns
76 .Dv NULL .
77 If a call to
78 .Fn setlogin
79 succeeds, a value of 0 is returned. If
80 .Fn setlogin
81 fails, a value of -1 is returned and an error code is
82 placed in the global location
83 .Va errno .
84 .Sh ERRORS
85 The following errors may be returned by these calls:
86 .Bl -tag -width Er
87 .It Bq Er EFAULT
88 The
89 .Fa name
90 parameter gave an
91 invalid address.
92 .It Bq Er EINVAL
93 The
94 .Fa name
95 parameter
96 pointed to a string that was too long.
97 Login names are limited to
98 .Dv MAXLOGNAME
99 (from
100 .Ao Pa sys/param.h Ac )
101 characters, currently 12.
102 .It Bq Er EPERM
103 The caller tried to set the login name and was not the super-user.
104 .El
105 .Sh SEE ALSO
106 .Xr setsid 2
107 .Sh BUGS
108 Login names are limited in length by
109 .Fn setlogin .
110 However, lower limits are placed on login names elsewhere in the system
111 .Pf ( Dv UT_NAMESIZE
112 in
113 .Ao Pa utmp.h Ac ) .
114 .Pp
115 In earlier versions of the system,
116 .Fn getlogin
117 failed unless the process was associated with a login terminal.
118 The current implementation (using
119 .Fn setlogin )
120 allows getlogin to succeed even when the process has no controlling terminal.
121 In earlier versions of the system, the value returned by
122 .Fn getlogin
123 could not be trusted without checking the user ID.
124 Portable programs should probably still make this check.
125 .Sh HISTORY
126 The
127 .Fn getlogin
128 function first appeared in 4.4BSD.