Commit | Line | Data |
---|---|---|
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 | 11 | getlogin, setlogin \- get/set login name |
1cde5d8e KF |
12 | .SH SYNOPSIS |
13 | .nf | |
14 | .ft B | |
d79c3924 | 15 | char *getlogin() |
1cde5d8e KF |
16 | .PP |
17 | .ft B | |
d79c3924 | 18 | setlogin(name) |
1cde5d8e | 19 | char *name; |
1cde5d8e KF |
20 | .fi |
21 | .SH DESCRIPTION | |
d79c3924 MK |
22 | The |
23 | .I getlogin | |
24 | routine | |
25 | returns the login name of the user associated with the current session, | |
26 | as previously set by | |
27 | .IR setlogin . | |
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 | |
33 | .IR su (1) | |
34 | is used.) | |
1cde5d8e | 35 | .PP |
d79c3924 MK |
36 | .I Setlogin |
37 | sets the login name of the user associated with the current session to | |
38 | .IR name . | |
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). | |
1cde5d8e | 43 | .SH "RETURN VALUE |
d79c3924 MK |
44 | If a call to |
45 | .I getlogin | |
46 | succeeds, it returns a pointer to a null-terminated string in a static buffer. | |
47 | If the name has not been set, it returns NULL. | |
48 | If a call to | |
49 | .I setlogin | |
50 | succeeds, a value of 0 is returned. If | |
51 | .I setlogin | |
1cde5d8e KF |
52 | fails, then a value of \-1 is returned and an error code is |
53 | placed in the global location \fIerrno\fP. | |
54 | .SH "ERRORS | |
55 | The following errors may be returned by these calls: | |
56 | .TP 15 | |
57 | [EFAULT] | |
d79c3924 | 58 | The \fIname\fP parameter gave an |
1cde5d8e KF |
59 | invalid address. |
60 | .TP 15 | |
d79c3924 MK |
61 | [EINVAL] |
62 | The \fIname\fP parameter | |
63 | pointed to a string that was too long. | |
64 | Login names are limited to MAXLOGNAME (from | |
65 | .IR <sys/param.h> ) | |
66 | characters, currently 12. | |
67 | .TP 15 | |
1cde5d8e | 68 | [EPERM] |
d79c3924 | 69 | The caller tried to set the login name and was not the super-user. |
1cde5d8e | 70 | .SH SEE ALSO |
d79c3924 | 71 | setsid(2) |
1cde5d8e | 72 | .SH BUGS |
d79c3924 MK |
73 | Login names are limited in length by |
74 | .IR setlogin . | |
75 | However, lower limits are placed on login names elsewhere in the system | |
76 | (UT_NAMESIZE in | |
77 | .IR <utmp.h> ). | |
78 | .PP | |
79 | In earlier versions of the system, | |
80 | .I getlogin | |
81 | failed unless the process was associated with a login terminal. | |
82 | The current implementation (using | |
83 | .IR setlogin ) | |
84 | allows getlogin to succeed even when the process has no controlling terminal. | |
85 | In earlier versions of the system, the value returned by | |
86 | .I getlogin | |
87 | could not be trusted without checking the user ID. | |
88 | Portable programs should probably still make this check. |