OSDN Git Service

1a5870d04ba4b090972529a34d475a19c9fdb39f
[linuxjm/LDP_man-pages.git] / draft / 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 2013\-04\-19 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()  returns a pointer to the username when successful, and NULL
76 on failure, with \fIerrno\fP set to indicate the cause of the error.
77 \fBgetlogin_r\fP()  returns 0 when successful, and nonzero on failure.
78 .SH エラー
79 POSIX では以下のエラーが規定されている:
80 .TP 
81 \fBEMFILE\fP
82 呼び出し元プロセスがオープンしているファイル数がすでにプロセスあたりの 上限に達している。
83 .TP 
84 \fBENFILE\fP
85 システム全体でオープンしているファイル数がすでに上限に達している。
86 .TP 
87 \fBENXIO\fP
88 呼び出し元プロセスには制御端末がない。
89 .TP 
90 \fBERANGE\fP
91 (getlogin_r)  The length of the username, including the terminating null
92 byte (\(aq\e0\(aq), is larger than \fIbufsize\fP.
93 .LP
94 Linux/glibc には以下のエラーもある。
95 .TP 
96 \fBENOENT\fP
97 utmp ファイルに対応するエントリがなかった。
98 .TP 
99 \fBENOMEM\fP
100 passwd 構造体を割り当てるのに十分なメモリがない。
101 .TP 
102 \fBENOTTY\fP
103 標準入力が端末を参照していない (「バグ」の節を参照)。
104 .SH ファイル
105 .TP 
106 \fI/etc/passwd\fP
107 パスワードデータベースのファイル
108 .TP 
109 \fI/var/run/utmp\fP
110 (伝統的には \fI/etc/utmp\fP が使われている; libc の中には \fI/var/adm/utmp\fP を使うものもある)
111 .SH ATTRIBUTES
112 .SS "Multithreading (see pthreads(7))"
113 The \fBgetlogin\fP()  function is not thread\-safe.
114 .LP
115 The \fBgetlogin_r\fP()  function is thread\-safe.
116 .LP
117 The \fBcuserid\fP()  function is thread\-safe with exceptions.  It is not
118 thread\-safe if called with a NULL parameter.
119 .SH 準拠
120 \fBgetlogin\fP()  と \fBgetlogin_r\fP()  は POSIX.1\-2001 で規定されている。
121
122 System V にも \fBcuserid\fP()  があるが、 これは実効ユーザー ID ではなく、実ユーザー ID を使用する。
123 \fBcuserid\fP()  関数は 1988 年版の POSIX には含まれていたが、 1990 年版では削除された。 SUSv2
124 に存在したが、POSIX.1\-2001 で削除された。
125 .LP
126 OpenBSD には \fBgetlogin\fP()  と \fBsetlogin\fP()  があり、 セッションに対応したユーザ名がある。制御端末がない
127 セッションの場合であっても、対応するユーザ名がある。
128 .SH バグ
129 残念ながら、 \fBgetlogin\fP() をだますのはそれほど難しいことではない。別のプログラムが utmp ファイルを
130 壊してしまうと、全く動作しないこともある。またログイン名の最初の 8 文字
131 しか返さないことも多い。また、プログラムの制御端末に現在ログインしているユーザーは、プログラムを実行したユーザーでない場合もある。
132 セキュリティの絡む用途には \fBgetlogin\fP() を用いるべきではない。
133 .LP
134 glibc は POSIX 仕様には従っておらず、 \fI/dev/tty\fP ではなく \fI標準入力 (stdin)\fP を使う。これはバグである。
135 (SunOS 5.8 や HP\-UX 11.11 や FreeBSD 4.8 といった他の最近のシステムはいずれも、 \fI標準入力\fP
136 がリダイレクトされた場合でもログイン名を返す。)
137 .LP
138 \fBcuserid\fP()  が何を行っているのか、実際のところを知っている者は誰もいない; 移植性が求められるプログラムでは \fBcuserid\fP()
139 は使うべきではない。 というかどんなプログラムでも使うべきではない: 代わりに \fIgetpwuid(geteuid())\fP を用いるべきである
140 (これが意図していることならば、だが)。 \fBcuserid\fP()  は「使わない」こと。
141 .SH 関連項目
142 \fBgeteuid\fP(2), \fBgetuid\fP(2), \fButmp\fP(5)
143 .SH この文書について
144 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
145 である。プロジェクトの説明とバグ報告に関する情報は
146 http://www.kernel.org/doc/man\-pages/ に書かれている。