1 .\" Copyright (c) 1989, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)getlogin.2 8.1 (Berkeley) 6/9/93
29 .\" $FreeBSD: src/lib/libc/sys/getlogin.2,v 1.14.2.6 2001/12/14 18:34:00 ru Exp $
30 .\" $DragonFly: src/lib/libc/sys/getlogin.2,v 1.5 2007/07/30 22:11:33 swildner Exp $
39 .Nd get/set login name
48 .Fn getlogin_r "char *name" "int len"
50 .Fn setlogin "const char *name"
55 returns the login name of the user associated with the current session,
58 The name is normally associated with a login shell
59 at the time a session is created,
60 and is inherited by all processes descended from the login shell.
61 (This is true even if some of those processes assume another user ID,
67 provides the same service as
69 except the caller must provide the buffer
74 to hold the result. The buffer should be at least
79 sets the login name of the user associated with the current session to
81 This call is restricted to the super-user, and
82 is normally used only when a new session is being created on behalf
84 (for example, at login time, or when a remote shell is invoked).
87 There is only one login name per session.
91 important to ensure that
93 is only ever called after the process has taken adequate steps to ensure
94 that it is detached from its parent's session.
103 which is an ideal way of detaching from a controlling terminal and
104 forking into the background.
106 In particular, doing a
107 .Fn ioctl ttyfd TIOCNOTTY ...\&
114 Once a parent process does a
116 call, it is acceptable for some child of that process to then do a
118 even though it is not the session leader, but beware that ALL processes
119 in the session will change their login name at the same time, even the
122 This is not the same as the traditional
124 behavior of inheriting privilege.
128 system call is restricted to the super-user, it is assumed that (like
129 all other privileged programs) the programmer has taken adequate
130 precautions to prevent security violations.
134 succeeds, it returns a pointer to a null-terminated string in a static buffer,
137 if the name has not been set.
139 returns zero if successful, or the error number upon failure.
143 The following errors may be returned by these calls:
154 pointed to a string that was too long.
155 Login names are limited to
159 characters, currently 17 including null.
161 The caller tried to set the login name and was not the super-user.
163 The size of the buffer is smaller than the result to be returned.
177 function first appeared in
181 was changed from earlier versions of
183 to be conformant with
186 In earlier versions of the system,
188 failed unless the process was associated with a login terminal.
189 The current implementation (using
191 allows getlogin to succeed even when the process has no controlling terminal.
192 In earlier versions of the system, the value returned by
194 could not be trusted without checking the user ID.
195 Portable programs should probably still make this check.