1 .\" $NetBSD: getlogin.2,v 1.22 2009/01/11 02:46:30 christos Exp $
3 .\" Copyright (c) 1989, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)getlogin.2 8.1 (Berkeley) 6/9/93
39 .Nd get/set login name
47 .Fn getlogin_r "char *name" "size_t len"
49 .Fn setlogin "const char *name"
54 returns the login name of the user associated with the current session,
57 The name is normally associated with a login shell
58 at the time a session is created,
59 and is inherited by all processes descended from the login shell.
60 (This is true even if some of those processes assume another user ID,
68 provides the same service as
70 however the caller must provide the buffer
76 The buffer should be at least
81 sets the login name of the user associated with the current session to
83 This call is restricted to the super-user, and
84 is normally used only when a new session is being created on behalf
86 (for example, at login time, or when a remote shell is invoked).
89 There is only one login name per session.
93 important to ensure that
95 is only ever called after the process has taken adequate steps to ensure
96 that it is detached from its parent's session.
99 way to do this is via the
106 which is an ideal way of detaching from a controlling terminal and
107 forking into the background.
109 In particular, neither
110 .Fn ioctl ttyfd TIOCNOTTY ...
113 is sufficient to create a new session.
115 Once a parent process has called
117 it is acceptable for some child of that process to then call
119 even though it is not the session leader.
120 Beware, however, that
122 processes in the session will change their login name at the same time,
125 This is different from traditional
127 privilege inheritance and as such can be counter-intuitive.
131 routine is restricted to the super-user, it is assumed that (like
132 all other privileged programs) the programmer has taken adequate
133 precautions to prevent security violations.
137 succeeds, it returns a pointer to a null-terminated string in a static buffer.
138 If the name has not been set, it returns
143 succeeds, a value of 0 is returned.
146 fails, a value of \-1 is returned and an error code is
147 placed in the global location
153 returns zero if successful, or the error number upon failure.
155 The following errors may be returned by these calls:
166 pointed to a string that was too long.
167 Login names are limited to
170 .Ao Pa sys/param.h Ac )
171 characters, currently 16.
173 The caller tried to set the login name and was not the super-user.
175 The size of the buffer is smaller than the result to be returned.
189 function first appeared in
192 Login names are limited in length by
194 However, lower limits are placed on login names elsewhere in the system
199 In earlier versions of the system,
201 failed unless the process was associated with a login terminal.
202 The current implementation (using
204 allows getlogin to succeed even when the process has no controlling terminal.
205 In earlier versions of the system, the value returned by
207 could not be trusted without checking the user ID.
208 Portable programs should probably still make this check.