.\" Copyright 1995 James R. Van Zandt .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Changed Tue Sep 19 01:49:29 1995, aeb: moved from man2 to man3 .\" added ref to /etc/utmp, added BUGS section, etc. .\" modified 2003 Walter Harms, aeb - added getlogin_r, note on stdin use .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH GETLOGIN 3 2008\-06\-29 GNU "Linux Programmer's Manual" .SH 名前 getlogin, getlogin_r, cuserid \- ユーザー名を取得する .SH 書式 \fB#include \fP .sp \fBchar *getlogin(void);\fP .br \fBint getlogin_r(char *\fP\fIbuf\fP\fB, size_t \fP\fIbufsize\fP\fB);\fP .sp \fB#include \fP .sp \fBchar *cuserid(char *\fP\fIstring\fP\fB);\fP .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fBgetlogin_r\fP(): _REENTRANT || _POSIX_C_SOURCE\ >=\ 199506L .br \fBcuserid\fP(): _XOPEN_SOURCE .SH 説明 \fBgetlogin\fP() は、現在のプロセスの制御端末にログインしているユーザー名の文字列への ポインタを返す。ユーザー名が決定できない場合は NULL ポインタを返す。 文字列は静的領域に割り当てられており、この後でこの関数や \fBcuserid\fP() が呼び出された際に上書きされることがある。 .PP \fBgetlogin_r\fP() は、上記の同じユーザ名を、大きさ \fIbufsize\fP の配列 \fIbuf\fP に入れて返す。 .PP \fBcuserid\fP() は、現在のプロセスの実効ユーザーID に対応するユーザー名の 文字列へのポインタを返す。 \fIstring\fP が NULL ポインタ以外の場合、\fIstring\fP は少なくとも \fBL_cuserid\fP 文字を保持できる配列でなければならない。 \fIstring\fP が NULL ポインタの場合には、静的領域に置かれた文字列への ポインタが返される。この文字列は静的領域に割り当てられており、後で この関数や \fBgetlogin\fP() が呼び出された際に上書きされることがある。 .PP マクロ \fBL_cuserid\fP は integer の定数で、ユーザー名を保持するために 必要な配列の長さを示す。 \fBL_cuserid\fP は \fBstdio.h\fP で宣言されて いる。 .PP これらの関数を使うと、プログラムを実行しているユーザー (\fBcuserid\fP()) や このセッションにログインしているユーザー (\fBgetlogin\fP()) を明確に特定することができる (ただし set\-user\-ID プログラムでは、状況が違うこともある)。 .PP たいていの目的では、ユーザーの特定には環境変数 \fBLOGNAME\fP を調べ るほうが便利である。LOGNAME 変数はユーザーが自由に設定できるので より柔軟な対応が可能になる。 .SH 返り値 \fBgetlogin\fP() は成功した場合はユーザ名へのポインタを返し、失敗した場合は NULL を返す。 \fBgetlogin_r\fP() は成功すると 0 を返し、失敗すると 0 以外を返す。 .SH エラー POSIX では以下のエラーが規定されている: .TP \fBEMFILE\fP 呼び出し元プロセスがオープンしているファイル数がすでにプロセスあたりの 上限に達している。 .TP \fBENFILE\fP システム全体でオープンしているファイル数がすでに上限に達している。 .TP \fBENXIO\fP The calling process has no controlling terminal. .TP \fBERANGE\fP (getlogin_r) (終端の NULL バイトも含めた) ユーザ名の長さが \fIbufsize\fP よりも長い。 .LP Linux/glibc には以下のエラーもある。 .TP \fBENOENT\fP utmp ファイルに対応するエントリがなかった。 .TP \fBENOMEM\fP passwd 構造体を割り当てるのに十分なメモリがない。 .TP \fBENOTTY\fP 標準入力が端末を参照していない (「バグ」の節を参照)。 .SH ファイル .TP \fI/etc/passwd\fP パスワードデータベースのファイル .TP \fI/var/run/utmp\fP (伝統的には \fI/etc/utmp\fP が使われている; libc の中には \fI/var/adm/utmp\fP を使うものもある) .SH 準拠 \fBgetlogin\fP() と \fBgetlogin_r\fP() は POSIX.1\-2001 で規定されている。 System V にも \fBcuserid\fP() があるが、 これは実効ユーザー ID ではなく、実ユーザー ID を使用する。 \fBcuserid\fP() 関数は 1988 年版の POSIX には含まれていたが、 1990 年版では削除された。 SUSv2 に存在したが、POSIX.1\-2001 で削除された。 .LP OpenBSD has \fBgetlogin\fP() and \fBsetlogin\fP(), and a username associated with a session, even if it has no controlling terminal. .SH バグ Unfortunately, it is often rather easy to fool \fBgetlogin\fP(). Sometimes it does not work at all, because some program messed up the utmp file. Often, it gives only the first 8 characters of the login name. The user currently logged in on the controlling terminal of our program need not be the user who started it. Avoid \fBgetlogin\fP() for security\-related purposes. .LP glibc は POSIX 仕様には従っておらず、 \fI/dev/tty\fP ではなく \fI標準入力 (stdin)\fP を使う。これはバグである。 (SunOS 5.8 や HP\-UX 11.11 や FreeBSD 4.8 といった他の最近のシステムはいずれも、 \fI標準入力\fP がリダイレクトされた場合でもログイン名を返す。) .LP \fBcuserid\fP() が何を行っているのか、実際のところを知っている者は誰もいない; 移植性が求められるプログラムでは \fBcuserid\fP() は使うべきではない。 というかどんなプログラムでも使うべきではない: 代わりに \fIgetpwuid(geteuid())\fP を用いるべきである (これが意図していることならば、だが)。 \fBcuserid\fP() は「使わない」こと。 .SH 関連項目 \fBgeteuid\fP(2), \fBgetuid\fP(2), \fButmp\fP(5) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。