OSDN Git Service

(split) DP: release pages (catch up to 3.50).
[linuxjm/LDP_man-pages.git] / release / man3 / getlogin.3
1 .\" Copyright 1995  James R. Van Zandt <jrv@vanzandt.mv.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
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
28 .\"*******************************************************************
29 .\"
30 .\" This file was generated with po4a. Translate the source file.
31 .\"
32 .\"*******************************************************************
33 .TH GETLOGIN 3 2008\-06\-29 GNU "Linux Programmer's Manual"
34 .SH 名前
35 getlogin, getlogin_r, cuserid \- ユーザー名を取得する
36 .SH 書式
37 \fB#include <unistd.h>\fP
38 .sp
39 \fBchar *getlogin(void);\fP
40 .br
41 \fBint getlogin_r(char *\fP\fIbuf\fP\fB, size_t \fP\fIbufsize\fP\fB);\fP
42 .sp
43 \fB#include <stdio.h>\fP
44 .sp
45 \fBchar *cuserid(char *\fP\fIstring\fP\fB);\fP
46 .sp
47 .in -4n
48 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
49 .in
50 .sp
51 \fBgetlogin_r\fP(): _REENTRANT || _POSIX_C_SOURCE\ >=\ 199506L
52 .br
53 \fBcuserid\fP(): _XOPEN_SOURCE
54 .SH 説明
55 \fBgetlogin\fP()  は、現在のプロセスの制御端末にログインしているユーザー名の文字列への ポインタを返す。ユーザー名が決定できない場合は
56 NULL ポインタを返す。 文字列は静的領域に割り当てられており、この後でこの関数や \fBcuserid\fP()
57 が呼び出された際に上書きされることがある。
58 .PP
59 \fBgetlogin_r\fP()  は、上記の同じユーザ名を、大きさ \fIbufsize\fP の配列 \fIbuf\fP に入れて返す。
60 .PP
61 \fBcuserid\fP()  は、現在のプロセスの実効ユーザーID に対応するユーザー名の 文字列へのポインタを返す。 \fIstring\fP が NULL
62 ポインタ以外の場合、\fIstring\fP は少なくとも \fBL_cuserid\fP 文字を保持できる配列でなければならない。 \fIstring\fP が
63 NULL ポインタの場合には、静的領域に置かれた文字列への ポインタが返される。この文字列は静的領域に割り当てられており、後で この関数や
64 \fBgetlogin\fP()  が呼び出された際に上書きされることがある。
65 .PP
66 マクロ \fBL_cuserid\fP は integer の定数で、ユーザー名を保持するために 必要な配列の長さを示す。 \fBL_cuserid\fP は
67 \fBstdio.h\fP で宣言されて いる。
68 .PP
69 これらの関数を使うと、プログラムを実行しているユーザー (\fBcuserid\fP())  や このセッションにログインしているユーザー
70 (\fBgetlogin\fP())  を明確に特定することができる (ただし set\-user\-ID プログラムでは、状況が違うこともある)。
71 .PP
72 たいていの目的では、ユーザーの特定には環境変数 \fBLOGNAME\fP を調べ るほうが便利である。LOGNAME 変数はユーザーが自由に設定できるので
73 より柔軟な対応が可能になる。
74 .SH 返り値
75 \fBgetlogin\fP()  は成功した場合はユーザ名へのポインタを返し、失敗した場合は NULL を返す。 \fBgetlogin_r\fP()
76 は成功すると 0 を返し、失敗すると 0 以外を返す。
77 .SH エラー
78 POSIX では以下のエラーが規定されている:
79 .TP 
80 \fBEMFILE\fP
81 呼び出し元プロセスがオープンしているファイル数がすでにプロセスあたりの 上限に達している。
82 .TP 
83 \fBENFILE\fP
84 システム全体でオープンしているファイル数がすでに上限に達している。
85 .TP 
86 \fBENXIO\fP
87 The calling process has no controlling terminal.
88 .TP 
89 \fBERANGE\fP
90 (getlogin_r)  (終端の NULL バイトも含めた) ユーザ名の長さが \fIbufsize\fP よりも長い。
91 .LP
92 Linux/glibc には以下のエラーもある。
93 .TP 
94 \fBENOENT\fP
95 utmp ファイルに対応するエントリがなかった。
96 .TP 
97 \fBENOMEM\fP
98 passwd 構造体を割り当てるのに十分なメモリがない。
99 .TP 
100 \fBENOTTY\fP
101 標準入力が端末を参照していない (「バグ」の節を参照)。
102 .SH ファイル
103 .TP 
104 \fI/etc/passwd\fP
105 パスワードデータベースのファイル
106 .TP 
107 \fI/var/run/utmp\fP
108 (伝統的には \fI/etc/utmp\fP が使われている; libc の中には \fI/var/adm/utmp\fP を使うものもある)
109 .SH 準拠
110 \fBgetlogin\fP()  と \fBgetlogin_r\fP()  は POSIX.1\-2001 で規定されている。
111
112 System V にも \fBcuserid\fP()  があるが、 これは実効ユーザー ID ではなく、実ユーザー ID を使用する。
113 \fBcuserid\fP()  関数は 1988 年版の POSIX には含まれていたが、 1990 年版では削除された。 SUSv2
114 に存在したが、POSIX.1\-2001 で削除された。
115 .LP
116 OpenBSD has \fBgetlogin\fP()  and \fBsetlogin\fP(), and a username associated with
117 a session, even if it has no controlling terminal.
118 .SH バグ
119 Unfortunately, it is often rather easy to fool \fBgetlogin\fP().  Sometimes it
120 does not work at all, because some program messed up the utmp file.  Often,
121 it gives only the first 8 characters of the login name.  The user currently
122 logged in on the controlling terminal of our program need not be the user
123 who started it.  Avoid \fBgetlogin\fP()  for security\-related purposes.
124 .LP
125 glibc は POSIX 仕様には従っておらず、 \fI/dev/tty\fP ではなく \fI標準入力 (stdin)\fP を使う。これはバグである。
126 (SunOS 5.8 や HP\-UX 11.11 や FreeBSD 4.8 といった他の最近のシステムはいずれも、 \fI標準入力\fP
127 がリダイレクトされた場合でもログイン名を返す。)
128 .LP
129 \fBcuserid\fP()  が何を行っているのか、実際のところを知っている者は誰もいない; 移植性が求められるプログラムでは \fBcuserid\fP()
130 は使うべきではない。 というかどんなプログラムでも使うべきではない: 代わりに \fIgetpwuid(geteuid())\fP を用いるべきである
131 (これが意図していることならば、だが)。 \fBcuserid\fP()  は「使わない」こと。
132 .SH 関連項目
133 \fBgeteuid\fP(2), \fBgetuid\fP(2), \fButmp\fP(5)
134 .SH この文書について
135 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
136 である。プロジェクトの説明とバグ報告に関する情報は
137 http://www.kernel.org/doc/man\-pages/ に書かれている。