1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright 1995 James R. Van Zandt <jrv@vanzandt.mv.com>
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Changed Tue Sep 19 01:49:29 1995, aeb: moved from man2 to man3
26 .\" added ref to /etc/utmp, added BUGS section, etc.
27 .\" modified 2003 Walter Harms, aeb - added getlogin_r, note on stdin use
29 .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
30 .\" Translated 1998-03-01, NAKANO Takeo <nakano@apm.seikei.ac.jp>
31 .\" Updated & Modified 1999-08-21, NAKANO Takeo <nakano@apm.seikei.ac.jp>
32 .\" Updated & Modified 2005-03-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
34 .TH GETLOGIN 3 2008-06-29 "GNU" "Linux Programmer's Manual"
36 getlogin, getlogin_r, cuserid \- ユーザー名を取得する
38 .B #include <unistd.h>
40 .B "char *getlogin(void);"
42 .BI "int getlogin_r(char *" buf ", size_t " bufsize );
46 .BI "char *cuserid(char *" string );
50 .RB ( feature_test_macros (7)
55 _REENTRANT || _POSIX_C_SOURCE\ >=\ 199506L
61 は、現在のプロセスの制御端末にログインしているユーザー名の文字列への
62 ポインタを返す。ユーザー名が決定できない場合は NULL ポインタを返す。
63 文字列は静的領域に割り当てられており、この後でこの関数や
75 は、現在のプロセスの実効ユーザーID に対応するユーザー名の
77 \fIstring\fP が NULL ポインタ以外の場合、\fIstring\fP は少なくとも
78 \fBL_cuserid\fP 文字を保持できる配列でなければならない。
79 \fIstring\fP が NULL ポインタの場合には、静的領域に置かれた文字列への
80 ポインタが返される。この文字列は静的領域に割り当てられており、後で
85 マクロ \fBL_cuserid\fP は integer の定数で、ユーザー名を保持するために
86 必要な配列の長さを示す。 \fBL_cuserid\fP は \fBstdio.h\fP で宣言されて
89 これらの関数を使うと、プログラムを実行しているユーザー
95 (ただし set-user-ID プログラムでは、状況が違うこともある)。
97 たいていの目的では、ユーザーの特定には環境変数 \fBLOGNAME\fP を調べ
98 るほうが便利である。LOGNAME 変数はユーザーが自由に設定できるので
102 は成功した場合はユーザ名へのポインタを返し、失敗した場合は NULL を返す。
104 は成功すると 0 を返し、失敗すると 0 以外を返す。
106 POSIX では以下のエラーが規定されている:
109 呼び出し元プロセスがオープンしているファイル数がすでにプロセスあたりの
113 システム全体でオープンしているファイル数がすでに上限に達している。
120 (終端の NULL バイトも含めた) ユーザ名の長さが
124 Linux/glibc には以下のエラーもある。
127 utmp ファイルに対応するエントリがなかった。
130 passwd 構造体を割り当てるのに十分なメモリがない。
133 標準入力が端末を参照していない (「バグ」の節を参照)。
140 (伝統的には \fI/etc/utmp\fP が使われている;
141 libc の中には \fI/var/adm/utmp\fP を使うものもある)
146 は POSIX.1-2001 で規定されている。
151 これは実効ユーザー ID ではなく、実ユーザー ID を使用する。
153 関数は 1988 年版の POSIX には含まれていたが、
155 SUSv2 に存在したが、POSIX.1-2001 で削除された。
162 セッションに対応したユーザ名がある。制御端末がない
163 セッションの場合であっても、対応するユーザ名がある。
167 をだますのはそれほど難しいことではない。別のプログラムが utmp ファイルを
168 壊してしまうと、全く動作しないこともある。またログイン名の最初の 8 文字
169 しか返さないことも多い。またプログラムを制御している tty に
170 現在ログインしているユーザーは、プログラムを実行した
176 glibc は POSIX 仕様には従っておらず、
181 (SunOS 5.8 や HP-UX 11.11 や FreeBSD 4.8 といった他の最近のシステムはいずれも、
183 がリダイレクトされた場合でもログイン名を返す。)
186 が何を行っているのか、実際のところを知っている者は誰もいない;
190 というかどんなプログラムでも使うべきではない:
192 .I getpwuid(geteuid())