1GETLOGIN(2)                   System Calls Manual                  GETLOGIN(2)
2
3
4

NAME

6       getlogin, setlogin - get/set login name
7

SYNOPSIS

9       #include <unistd.h>
10
11       char *
12       getlogin()
13
14       int
15       setlogin(name)
16            char *name;
17

DESCRIPTION

19       The getlogin routine returns the login name of the user associated with
20       the current session, as previously set by setlogin.  The name  is  nor‐
21       mally  associated  with a login shell at the time a session is created,
22       and is inherited by all  processes  descended  from  the  login  shell.
23       (This  is  true even if some of those processes assume another user ID,
24       for example when su(1) is used.)
25
26       Setlogin sets the login name of the user associated  with  the  current
27       session  to  name.   This  call is restricted to the super-user, and is
28       normally used only when a new session is being created on behalf of the
29       named  user  (for  example,  at  login  time, or when a remote shell is
30       invoked).
31

RETURN VALUES

33       If a call to getlogin succeeds, it returns a pointer to  a  null-termi‐
34       nated  string  in  a  static  buffer.  If the name has not been set, it
35       returns NULL.  If a  call  to  setlogin  succeeds,  a  value  of  0  is
36       returned.   If  setlogin  fails, a value of -1 is returned and an error
37       code is placed in the global location errno.
38

ERRORS

40       The following errors may be returned by these calls:
41
42       EFAULT         The name parameter gave an invalid address.
43
44       EINVAL         The name parameter pointed to  a  string  that  was  too
45                      long.   Login  names  are  limited  to  MAXLOGNAME (from
46                      <sys/param.h>) characters, currently 16.
47
48       EPERM          The caller tried to set the login name and was  not  the
49                      super-user.
50

SEE ALSO

52       setsid(2)
53

BUGS

55       Login  names  are limited in length by setlogin.  However, lower limits
56       are placed on login names  elsewhere  in  the  system  (UT_NAMESIZE  in
57       <utmp.h>).
58
59       In  earlier  versions of the system, getlogin failed unless the process
60       was associated with  a  login  terminal.   The  current  implementation
61       (using  setlogin)  allows getlogin to succeed even when the process has
62       no controlling terminal.  In earlier versions of the system, the  value
63       returned by getlogin could not be trusted without checking the user ID.
64       Portable programs should probably still make this check.
65

HISTORY

67       The setlogin function first appeared in 4.4BSD.  The getlogin  function
68       was present in V7.
69
70
71
724.2 Berkeley Distribution     September 23, 1997                   GETLOGIN(2)
Impressum