xref: /original-bsd/lib/libc/sys/getlogin.2 (revision 95a66346)
1.\" Copyright (c) 1989, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)getlogin.2	6.2 (Berkeley) 03/10/91
7.\"
8.Dd
9.Dt GETLOGIN 2
10.Os BSD 4.2
11.Sh NAME
12.Nm getlogin ,
13.Nm setlogin
14.Nd get/set login name
15.Sh SYNOPSIS
16.Fd #include <unistd.h>
17.Ft char *
18.Fn getlogin void
19.Ft int
20.Fn setlogin "const char *name"
21.Sh DESCRIPTION
22The
23.Fn getlogin
24routine
25returns the login name of the user associated with the current session,
26as previously set by
27.Fn setlogin .
28The name is normally associated with a login shell
29at the time a session is created,
30and is inherited by all processes descended from the login shell.
31(This is true even if some of those processes assume another user ID,
32for example when
33.Xr su 1
34is used.)
35.Pp
36.Fn Setlogin
37sets the login name of the user associated with the current session to
38.Fa name .
39This call is restricted to the super-user, and
40is normally used only when a new session is being created on behalf
41of the named user
42(for example, at login time, or when a remote shell is invoked).
43.Sh RETURN VALUES
44If a call to
45.Fn getlogin
46succeeds, it returns a pointer to a null-terminated string in a static buffer.
47If the name has not been set, it returns NULL.
48If a call to
49.Fn setlogin
50succeeds, a value of 0 is returned.  If
51.Fn setlogin
52fails, a value of -1 is returned and an error code is
53placed in the global location
54.Va errno .
55.Sh ERRORS
56The following errors may be returned by these calls:
57.Bl -tag -width Er
58.It Bq Er EFAULT
59The
60.Fa name
61parameter gave an
62invalid address.
63.It Bq Er EINVAL
64The
65.Fa name
66parameter
67pointed to a string that was too long.
68Login names are limited to
69.Dv MAXLOGNAME
70(from
71.Ao Pa sys/param.h Ac )
72characters, currently 12.
73.It Bq Er EPERM
74The caller tried to set the login name and was not the super-user.
75.El
76.Sh SEE ALSO
77.Xr setsid 2
78.Sh BUGS
79Login names are limited in length by
80.Fn setlogin .
81However, lower limits are placed on login names elsewhere in the system
82.Pf ( Dv UT_NAMESIZE
83in
84.Ao Pa utmp.h Ac ) .
85.Pp
86In earlier versions of the system,
87.Fn getlogin
88failed unless the process was associated with a login terminal.
89The current implementation (using
90.Fn setlogin )
91allows getlogin to succeed even when the process has no controlling terminal.
92In earlier versions of the system, the value returned by
93.Fn getlogin
94could not be trusted without checking the user ID.
95Portable programs should probably still make this check.
96.Sh HISTORY
97The
98.Nm
99function call is currently under development.
100