.\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" Copyright 1995 James R. Van Zandt .\" .\" 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. .\" .\" 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 .\" .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved. .\" Translated 1998-03-01, NAKANO Takeo .\" Updated & Modified 1999-08-21, NAKANO Takeo .\" Updated & Modified 2005-03-18, Akihiro MOTOKI .\" .TH GETLOGIN 3 2008-06-29 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .\"O getlogin, getlogin_r, cuserid \- get username .SH 名前 getlogin, getlogin_r, cuserid \- ユーザー名を取得する .\"O .SH SYNOPSIS .SH 書式 .B #include .sp .B "char *getlogin(void);" .br .BI "int getlogin_r(char *" buf ", size_t " bufsize ); .sp .B #include .sp .BI "char *cuserid(char *" string ); .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR getlogin_r (): _REENTRANT || _POSIX_C_SOURCE\ >=\ 199506L .br .BR cuserid (): _XOPEN_SOURCE .\"O .SH DESCRIPTION .SH 説明 .\"O .BR getlogin () .\"O returns a pointer to a string containing the name of .\"O the user logged in on the controlling terminal of the process, or a .\"O null pointer if this information cannot be determined. .\"O The string is .\"O statically allocated and might be overwritten on subsequent calls to .\"O this function or to .\"O .BR cuserid (). .BR getlogin () は、現在のプロセスの制御端末にログインしているユーザー名の文字列への ポインタを返す。ユーザー名が決定できない場合は null ポインタを返す。 文字列は静的領域に割り当てられており、この後でこの関数や .BR cuserid () が呼び出された際に上書きされることがある。 .PP .\"O .BR getlogin_r () .\"O returns this same username in the array .\"O .I buf .\"O of size .\"O .IR bufsize . .BR getlogin_r () は、上記の同じユーザ名を、大きさ .I bufsize の配列 .I buf に入れて返す。 .PP .\"O .BR cuserid () .\"O returns a pointer to a string containing a username .\"O associated with the effective user ID of the process. .\"O If \fIstring\fP .\"O is not a null pointer, it should be an array that can hold at least .\"O \fBL_cuserid\fP characters; the string is returned in this array. .\"O Otherwise, a pointer to a string in a static area is returned. .\"O This .\"O string is statically allocated and might be overwritten on subsequent .\"O calls to this function or to .\"O .BR getlogin (). .BR cuserid () は、現在のプロセスの実効ユーザーID に対応するユーザー名の 文字列へのポインタを返す。 \fIstring\fP が null ポインタ以外の場合、\fIstring\fP は少なくとも \fBL_cuserid\fP 文字を保持できる配列でなければならない。 \fIstring\fP が null ポインタの場合には、静的領域に置かれた文字列への ポインタが返される。この文字列は静的領域に割り当てられており、後で この関数や .BR getlogin () が呼び出された際に上書きされることがある。 .PP .\"O The macro \fBL_cuserid\fP is an integer constant that indicates how .\"O long an array you might need to store a username. \fBL_cuserid\fP is .\"O declared in \fBstdio.h\fP. マクロ \fBL_cuserid\fP は integer の定数で、ユーザー名を保持するために 必要な配列の長さを示す。 \fBL_cuserid\fP は \fBstdio.h\fP で宣言されて いる。 .PP .\"O These functions let your program identify positively the user who is .\"O running .\"O .RB ( cuserid ()) .\"O or the user who logged in this session .\"O .RB ( getlogin ()). .\"O (These can differ when set-user-ID programs are .\"O involved.) これらの関数を使うと、プログラムを実行しているユーザー .RB ( cuserid ()) や このセッションにログインしているユーザー .RB ( getlogin ()) を明確に特定することができる (ただし set-user-ID プログラムでは、状況が違うこともある)。 .PP .\"O For most purposes, it is more useful to use the environment variable .\"O \fBLOGNAME\fP to find out who the user is. .\"O This is more flexible .\"O precisely because the user can set \fBLOGNAME\fP arbitrarily. たいていの目的では、ユーザーの特定には環境変数 \fBLOGNAME\fP を調べ るほうが便利である。LOGNAME 変数はユーザーが自由に設定できるので より柔軟な対応が可能になる。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O .BR getlogin () .\"O returns a pointer to the username when successful, .\"O and NULL on failure. .\"O .BR getlogin_r () .\"O returns 0 when successful, and nonzero on failure. .BR getlogin () は成功した場合はユーザ名へのポインタを返し、失敗した場合は NULL を返す。 .BR getlogin_r () は成功すると 0 を返し、失敗すると 0 以外を返す。 .\"O .SH ERRORS .SH エラー .\"O POSIX specifies POSIX では以下のエラーが規定されている: .TP .B EMFILE .\"O The calling process already has the maximum allowed number of open files. 呼び出し元プロセスがオープンしているファイル数がすでにプロセスあたりの 上限に達している。 .TP .B ENFILE .\"O The system already has the maximum allowed number of open files. システム全体でオープンしているファイル数がすでに上限に達している。 .TP .B ENXIO .\"O The calling process has no controlling tty. 呼び出し元プロセスには制御端末がない。 .TP .B ERANGE (getlogin_r) .\"O The length of the username, including the terminating null byte, .\"O is larger than .\"O .IR bufsize . (終端の NULL バイトも含めた) ユーザ名の長さが .I bufsize よりも長い。 .LP .\"O Linux/glibc also has Linux/glibc には以下のエラーもある。 .TP .B ENOENT .\"O There was no corresponding entry in the utmp-file. utmp ファイルに対応するエントリがなかった。 .TP .B ENOMEM .\"O Insufficient memory to allocate passwd structure. passwd 構造体を割り当てるのに十分なメモリがない。 .TP .B ENOTTY .\"O Standard input didn't refer to a terminal. .\"O (See BUGS.) 標準入力が端末を参照していない (「バグ」の節を参照)。 .\"O .SH FILES .SH ファイル .TP \fI/etc/passwd\fP .\"O password database file パスワードデータベースのファイル .TP \fI/var/run/utmp\fP .\"O (traditionally \fI/etc/utmp\fP; .\"O some libc versions used \fI/var/adm/utmp\fP) (伝統的には \fI/etc/utmp\fP が使われている; libc の中には \fI/var/adm/utmp\fP を使うものもある) .\"O .SH "CONFORMING TO" .SH 準拠 .\"O .BR getlogin () .\"O and .\"O .BR getlogin_r () .\"O specified in POSIX.1-2001. .BR getlogin () と .BR getlogin_r () は POSIX.1-2001 で規定されている。 .\"O System V has a .\"O .BR cuserid () .\"O function which uses the real .\"O user ID rather than the effective user ID. .\"O The .\"O .BR cuserid () .\"O function .\"O was included in the 1988 version of POSIX, .\"O but removed from the 1990 version. .\"O It was present in SUSv2, but removed in POSIX.1-2001. System V にも .BR cuserid () があるが、 これは実効ユーザー ID ではなく、実ユーザー ID を使用する。 .BR cuserid () 関数は 1988 年版の POSIX には含まれていたが、 1990 年版では削除された。 SUSv2 に存在したが、POSIX.1-2001 で削除された。 .LP .\"O OpenBSD has .\"O .BR getlogin () .\"O and .\"O .BR setlogin (), .\"O and a username .\"O associated with a session, even if it has no controlling tty. OpenBSD には .BR getlogin () と .BR setlogin () があり、 セッションに対応したユーザ名がある。制御端末がない セッションの場合であっても、対応するユーザ名がある。 .\"O .SH BUGS .SH バグ .\"O Unfortunately, it is often rather easy to fool .\"O .BR getlogin (). .\"O Sometimes it does not work at all, because some program messed up .\"O the utmp file. .\"O Often, it gives only the first 8 characters of .\"O the login name. .\"O The user currently logged in on the controlling tty .\"O of our program need not be the user who started it. .\"O Avoid .\"O .BR getlogin () .\"O for security-related purposes. 残念ながら、 .BR getlogin () をだますのはそれほど難しいことではない。別のプログラムが utmp ファイルを 壊してしまうと、全く動作しないこともある。またログイン名の最初の 8 文字 しか返さないことも多い。またプログラムを制御している tty に 現在ログインしているユーザーは、プログラムを実行した ユーザーでない場合もある。 セキュリティの絡む用途には .BR getlogin () を用いるべきではない。 .LP .\"O Note that glibc does not follow the POSIX specification and uses .\"O .I stdin .\"O instead of .\"O .IR /dev/tty . .\"O A bug. .\"O (Other recent systems, like SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8 .\"O all return the login name also when .\"O .I stdin .\"O is redirected.) glibc は POSIX 仕様には従っておらず、 .I /dev/tty ではなく .I "標準入力 (stdin)" を使う。これはバグである。 (SunOS 5.8 や HP-UX 11.11 や FreeBSD 4.8 といった他の最近のシステムはいずれも、 .I 標準入力 がリダイレクトされた場合でもログイン名を返す。) .LP .\"O Nobody knows precisely what .\"O .BR cuserid () .\"O does; avoid it in portable programs. .\"O Or avoid it altogether: use .\"O .I getpwuid(geteuid()) .\"O instead, if that is .\"O what you meant. .\"O .B Do not use .\"O .BR cuserid (). .BR cuserid () が何を行っているのか、実際のところを知っている者は誰もいない; 移植性が求められるプログラムでは .BR cuserid () は使うべきではない。 というかどんなプログラムでも使うべきではない: 代わりに .I getpwuid(geteuid()) を用いるべきである (これが意図していることならば、だが)。 .BR cuserid () は「使わない」こと。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR geteuid (2), .BR getuid (2), .BR utmp (5)