logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

getlogin.3p (6629B)


  1. '\" et
  2. .TH GETLOGIN "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. getlogin,
  12. getlogin_r
  13. \(em get login name
  14. .SH SYNOPSIS
  15. .LP
  16. .nf
  17. #include <unistd.h>
  18. .P
  19. char *getlogin(void);
  20. int getlogin_r(char *\fIname\fP, size_t \fInamesize\fP);
  21. .fi
  22. .SH DESCRIPTION
  23. The
  24. \fIgetlogin\fR()
  25. function shall return a pointer to a string containing the user name
  26. associated by the login activity with the controlling terminal of the
  27. current process. If
  28. \fIgetlogin\fR()
  29. returns a non-null pointer, then that pointer points to the name that
  30. the user logged in under, even if there are several login names with
  31. the same user ID.
  32. .P
  33. The
  34. \fIgetlogin\fR()
  35. function need not be thread-safe.
  36. .P
  37. The
  38. \fIgetlogin_r\fR()
  39. function shall put the name associated by the login activity with the
  40. controlling terminal of the current process in the character array
  41. pointed to by
  42. .IR name .
  43. The array is
  44. .IR namesize
  45. characters long and should have space for the name and the terminating
  46. null character. The maximum size of the login name is
  47. {LOGIN_NAME_MAX}.
  48. .P
  49. If
  50. \fIgetlogin_r\fR()
  51. is successful,
  52. .IR name
  53. points to the name the user used at login, even if there are several
  54. login names with the same user ID.
  55. .P
  56. The
  57. \fIgetlogin\fR()
  58. and
  59. \fIgetlogin_r\fR()
  60. functions may make use of file descriptors 0, 1, and 2 to find the
  61. controlling terminal of the current process, examining each in turn
  62. until the terminal is found. If in this case none of these three file
  63. descriptors is open to the controlling terminal, these functions may
  64. fail. The method used to find the terminal associated with a file
  65. descriptor may depend on the file descriptor being open to the actual
  66. terminal device, not
  67. .BR /dev/tty .
  68. .SH "RETURN VALUE"
  69. Upon successful completion,
  70. \fIgetlogin\fR()
  71. shall return a pointer to the login name or a null pointer if the
  72. user's login name cannot be found. Otherwise, it shall return a null
  73. pointer and set
  74. .IR errno
  75. to indicate the error.
  76. .P
  77. The application shall not modify the string returned. The returned
  78. pointer might be invalidated or the string content might be overwritten
  79. by a subsequent call to
  80. \fIgetlogin\fR().
  81. The returned pointer and the string content might also be invalidated
  82. if the calling thread is terminated.
  83. .P
  84. If successful, the
  85. \fIgetlogin_r\fR()
  86. function shall return zero; otherwise, an error number shall be
  87. returned to indicate the error.
  88. .SH ERRORS
  89. These functions may fail if:
  90. .TP
  91. .BR EMFILE
  92. All file descriptors available to the process are currently open.
  93. .TP
  94. .BR ENFILE
  95. The maximum allowable number of files is currently open in the system.
  96. .TP
  97. .BR ENOTTY
  98. None of the file descriptors 0, 1, or 2 is open to the controlling
  99. terminal of the current process.
  100. .TP
  101. .BR ENXIO
  102. The calling process has no controlling terminal.
  103. .P
  104. The
  105. \fIgetlogin_r\fR()
  106. function may fail if:
  107. .TP
  108. .BR ERANGE
  109. The value of
  110. .IR namesize
  111. is smaller than the length of the string to be returned including the
  112. terminating null character.
  113. .LP
  114. .IR "The following sections are informative."
  115. .SH EXAMPLES
  116. .SS "Getting the User Login Name" S
  117. .P
  118. The following example calls the
  119. \fIgetlogin\fR()
  120. function to obtain the name of the user associated with the calling
  121. process, and passes this information to the
  122. \fIgetpwnam\fR()
  123. function to get the associated user database information.
  124. .sp
  125. .RS 4
  126. .nf
  127. #include <unistd.h>
  128. #include <sys/types.h>
  129. #include <pwd.h>
  130. #include <stdio.h>
  131. \&...
  132. char *lgn;
  133. struct passwd *pw;
  134. \&...
  135. if ((lgn = getlogin()) == NULL || (pw = getpwnam(lgn)) == NULL) {
  136. fprintf(stderr, "Get of user information failed.\en"); exit(1);
  137. }
  138. .fi
  139. .P
  140. .RE
  141. .SH "APPLICATION USAGE"
  142. Three names associated with the current process can be determined:
  143. .IR getpwuid (\c
  144. \fIgeteuid\fR())
  145. shall return the name associated with the effective user ID of the
  146. process;
  147. \fIgetlogin\fR()
  148. shall return the name associated with the current login activity; and
  149. .IR getpwuid (\c
  150. \fIgetuid\fR())
  151. shall return the name associated with the real user ID of the process.
  152. .P
  153. The
  154. \fIgetlogin_r\fR()
  155. function is thread-safe and returns values in a user-supplied buffer
  156. instead of possibly using a static data area that may be overwritten by
  157. each call.
  158. .SH RATIONALE
  159. The
  160. \fIgetlogin\fR()
  161. function returns a pointer to the user's login name. The same user ID
  162. may be shared by several login names. If it is desired to get the user
  163. database entry that is used during login, the result of
  164. \fIgetlogin\fR()
  165. should be used to provide the argument to the
  166. \fIgetpwnam\fR()
  167. function. (This might be used to determine the user's login shell,
  168. particularly where a single user has multiple login shells with
  169. distinct login names, but the same user ID.)
  170. .P
  171. The information provided by the
  172. .IR cuserid (\|)
  173. function, which was originally defined in the POSIX.1\(hy1988 standard and subsequently
  174. removed, can be obtained by the following:
  175. .sp
  176. .RS 4
  177. .nf
  178. getpwuid(geteuid())
  179. .fi
  180. .P
  181. .RE
  182. .P
  183. while the information provided by historical implementations of
  184. .IR cuserid (\|)
  185. can be obtained by:
  186. .sp
  187. .RS 4
  188. .nf
  189. getpwuid(getuid())
  190. .fi
  191. .P
  192. .RE
  193. .P
  194. The thread-safe version of this function places the user name in a
  195. user-supplied buffer and returns a non-zero value if it fails. The
  196. non-thread-safe version may return the name in a static data area that
  197. may be overwritten by each call.
  198. .SH "FUTURE DIRECTIONS"
  199. None.
  200. .SH "SEE ALSO"
  201. .IR "\fIgetpwnam\fR\^(\|)",
  202. .IR "\fIgetpwuid\fR\^(\|)",
  203. .IR "\fIgeteuid\fR\^(\|)",
  204. .IR "\fIgetuid\fR\^(\|)"
  205. .P
  206. The Base Definitions volume of POSIX.1\(hy2017,
  207. .IR "\fB<limits.h>\fP",
  208. .IR "\fB<unistd.h>\fP"
  209. .\"
  210. .SH COPYRIGHT
  211. Portions of this text are reprinted and reproduced in electronic form
  212. from IEEE Std 1003.1-2017, Standard for Information Technology
  213. -- Portable Operating System Interface (POSIX), The Open Group Base
  214. Specifications Issue 7, 2018 Edition,
  215. Copyright (C) 2018 by the Institute of
  216. Electrical and Electronics Engineers, Inc and The Open Group.
  217. In the event of any discrepancy between this version and the original IEEE and
  218. The Open Group Standard, the original IEEE and The Open Group Standard
  219. is the referee document. The original Standard can be obtained online at
  220. http://www.opengroup.org/unix/online.html .
  221. .PP
  222. Any typographical or formatting errors that appear
  223. in this page are most likely
  224. to have been introduced during the conversion of the source files to
  225. man page format. To report such errors, see
  226. https://www.kernel.org/doc/man-pages/reporting_bugs.html .