add -s option which inserts/matches truncated member names
[unix-history] / usr / src / lib / libc / sys / getlogin.2
CommitLineData
1cde5d8e
KF
1.\" Copyright (c) 1989 The Regents of the University of California.
2.\" All rights reserved.
3.\"
d79c3924 4.\" %sccs.include.redist.man%
1cde5d8e 5.\"
554c3e4b 6.\" @(#)getlogin.2 6.1 (Berkeley) %G%
1cde5d8e 7.\"
d79c3924 8.TH GETLOGIN 2 ""
1cde5d8e
KF
9.UC 5
10.SH NAME
d79c3924 11getlogin, setlogin \- get/set login name
1cde5d8e
KF
12.SH SYNOPSIS
13.nf
14.ft B
d79c3924 15char *getlogin()
1cde5d8e
KF
16.PP
17.ft B
d79c3924 18setlogin(name)
1cde5d8e 19char *name;
1cde5d8e
KF
20.fi
21.SH DESCRIPTION
d79c3924
MK
22The
23.I getlogin
24routine
25returns the login name of the user associated with the current session,
26as previously set by
27.IR 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.IR su (1)
34is used.)
1cde5d8e 35.PP
d79c3924
MK
36.I Setlogin
37sets the login name of the user associated with the current session to
38.IR 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).
1cde5d8e 43.SH "RETURN VALUE
d79c3924
MK
44If a call to
45.I 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.I setlogin
50succeeds, a value of 0 is returned. If
51.I setlogin
1cde5d8e
KF
52fails, then a value of \-1 is returned and an error code is
53placed in the global location \fIerrno\fP.
54.SH "ERRORS
55The following errors may be returned by these calls:
56.TP 15
57[EFAULT]
d79c3924 58The \fIname\fP parameter gave an
1cde5d8e
KF
59invalid address.
60.TP 15
d79c3924
MK
61[EINVAL]
62The \fIname\fP parameter
63pointed to a string that was too long.
64Login names are limited to MAXLOGNAME (from
65.IR <sys/param.h> )
66characters, currently 12.
67.TP 15
1cde5d8e 68[EPERM]
d79c3924 69The caller tried to set the login name and was not the super-user.
1cde5d8e 70.SH SEE ALSO
d79c3924 71setsid(2)
1cde5d8e 72.SH BUGS
d79c3924
MK
73Login names are limited in length by
74.IR setlogin .
75However, lower limits are placed on login names elsewhere in the system
76(UT_NAMESIZE in
77.IR <utmp.h> ).
78.PP
79In earlier versions of the system,
80.I getlogin
81failed unless the process was associated with a login terminal.
82The current implementation (using
83.IR setlogin )
84allows getlogin to succeed even when the process has no controlling terminal.
85In earlier versions of the system, the value returned by
86.I getlogin
87could not be trusted without checking the user ID.
88Portable programs should probably still make this check.