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