1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.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 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's "POSIX Programmer's Guide" (O'Reilly & Associates, 1991)
30 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified 1996-05-27 by Martin Schulze (joey@linux.de)
32 .\" Modified 2003-11-15 by aeb
33 .\" 2008-11-07, mtk, Added an example program for getpwnam_r().
35 .\" Japanese Version Copyright (c) 1997 HIROFUMI Nishizuka
36 .\" all rights reserved.
37 .\" Translated 1997-12-18, HIROFUMI Nishizuka <nishi@rpts.cl.nec.co.jp>
38 .\" Updated & Modified 2004-01-06, Yuichi SATO <ysato444@yahoo.co.jp>
39 .\" Updated & Modified 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
40 .\" Updated & Modified 2005-10-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
41 .\" Updated 2008-12-24, Akihiro MOTOKI, LDP v3.14
43 .TH GETPWNAM 3 2009-03-30 "GNU" "Linux Programmer's Manual"
45 getpwnam, getpwnam_r, getpwuid, getpwuid_r \- ¥Ñ¥¹¥ï¡¼¥É¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥È¥ê¤Î¼èÆÀ
48 .B #include <sys/types.h>
51 .BI "struct passwd *getpwnam(const char *" name );
53 .BI "struct passwd *getpwuid(uid_t " uid );
55 .BI "int getpwnam_r(const char *" name ", struct passwd *" pwd ,
57 .BI " char *" buf ", size_t " buflen ", struct passwd **" result );
59 .BI "int getpwuid_r(uid_t " uid ", struct passwd *" pwd ,
61 .BI " char *" buf ", size_t " buflen ", struct passwd **" result );
65 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
66 .RB ( feature_test_macros (7)
73 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
74 _SVID_SOURCE || _POSIX_SOURCE
80 ¤Ë¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥¨¥ó¥È¥ê¤ò
81 Í×ÁÇËè¤Ëʬ²ò¤·¡¢³ÆÍ×ÁǤò³ÊǼ¤·¤¿¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹
82 (¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÎã:
83 ¥í¡¼¥«¥ë¤Î¥Ñ¥¹¥ï¡¼¥É¥Õ¥¡¥¤¥ë
90 ¤Ë¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥¨¥ó¥È¥ê¤ò
91 Í×ÁÇËè¤Ëʬ²ò¤·¡¢³ÆÍ×ÁǤò³ÊǼ¤·¤¿¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
96 ´Ø¿ô¤Ï (¾åµ¤Î´Ø¿ô¤È) Ʊ¤¸¾ðÊó¤ò¼èÆÀ¤¹¤ë¤¬¡¢
101 ¤¬»Ø¤¹Îΰè¤Ë³ÊǼ¤¹¤ë¡£
104 ¹½Â¤ÂΤˤÏʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬´Þ¤Þ¤ì¡¢
105 ¤³¤ì¤é¤Îʸ»úÎó¤Ï¥µ¥¤¥º
112 ¤Ë¤Ï·ë²Ì¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬³ÊǼ¤µ¤ì¤ë¡£
113 ¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤ä¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¤Ï
117 \fIpasswd\fP ¹½Â¤ÂΤϡ¢\fI<pwd.h>\fP ¤Ç°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
122 char *pw_name; /* ¥æ¡¼¥¶Ì¾ */
123 char *pw_passwd; /* ¥æ¡¼¥¶¤Î¥Ñ¥¹¥ï¡¼¥É */
124 uid_t pw_uid; /* ¥æ¡¼¥¶ ID */
125 gid_t pw_gid; /* ¥°¥ë¡¼¥× ID */
126 char *pw_gecos; /* ¼Â̾ */
127 char *pw_dir; /* ¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê */
128 char *pw_shell; /* ¥·¥§¥ë¥×¥í¥°¥é¥à */
134 ¤ËºÇÂçɬÍפʥµ¥¤¥º¤Ï¡¢
137 .B _SC_GETPW_R_SIZE_MAX
138 ¤ò»ØÄꤷ¤Æ¼Â¹Ô¤¹¤ë¤³¤È¤Çʬ¤«¤ë¡£
145 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
146 °ìÃפ¹¤ë¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤ä¡¢¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ï NULL ¤òÊÖ¤¹¡£
147 ¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¾ì¹ç¡¢
152 ¤ò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢
153 ¸Æ¤Ó½Ð¤·¤ÎÁ°¤Ë (¤³¤ÎÃͤò) 0 ¤ËÀßÄꤷ¤Æ¤ª¤¯¤Ù¤¤Ç¤¢¤ë¡£
155 ÊÖ¤êÃͤÏÀÅŪ¤ÊÎΰè¤ò»Ø¤·¤Æ¤ª¤ê¡¢¤½¤Î¸å¤Î
159 ¤Î¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
173 ¥Þ¥Ã¥Á¤¹¤ë¥Ñ¥¹¥ï¡¼¥É¡¦¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢
177 ¥¨¥é¡¼¤Î¾ì¹ç¡¢¥¨¥é¡¼ÈÖ¹æ¤òÊÖ¤·¡¢
182 .BR 0 " ¤Þ¤¿¤Ï " ENOENT " ¤Þ¤¿¤Ï " ESRCH " ¤Þ¤¿¤Ï " EBADF " ¤Þ¤¿¤Ï " EPERM " ¤Þ¤¿¤Ï ... "
190 ¥·¥°¥Ê¥ë¤¬¥¥ã¥Ã¥Á¤µ¤ì¤¿¡£
196 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Ë¤ª¤¤¤Æ¡¢
197 ´û¤ËºÇÂç¿ô (OPEN_MAX) ¤Î¥Õ¥¡¥¤¥ë¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡£
200 ¥·¥¹¥Æ¥à¾å¤Ç´û¤ËºÇÂç¿ô¤Î¥Õ¥¡¥¤¥ë¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡£
206 ¹½Â¤ÂΤò³ä¤êÅö¤Æ¤ë¤¿¤á¤Î¥á¥â¥ê¤¬ÉÔ½½Ê¬¡£
207 .\" ¤³¤Î¹½Â¤ÂΤÏÀÅŪ¤Ç¤¢¤ê¡¢0 ²ó¤Þ¤¿¤Ï 1 ²ó³ä¤êÅö¤Æ¤é¤ì¤ë¡£
208 .\" ¥á¥â¥ê¥ê¡¼¥¯¤Ï̵¤¤¡£(libc45)
211 Í¿¤¨¤é¤ì¤¿¥Ð¥Ã¥Õ¥¡¶õ´Ö¤¬ÉÔ½½Ê¬¤Ç¤¢¤ë¡£
215 ¥í¡¼¥«¥ë¤Î¥Ñ¥¹¥ï¡¼¥É¡¦¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë
217 SVr4, 4.3BSD, POSIX.1-2001.
219 ¾åµ¤Î¡ÖÊÖ¤êÃ͡װʲ¼¤Îµ½Ò¤Ï POSIX.1-2001 ¤Ëµò¤ë¡£
220 ¤³¤Îɸ½à¤Ï¡Ö(¥¨¥ó¥È¥ê¤¬) ¸«¤Ä¤«¤é¤Ê¤¤¤³¤È¡×¤ò¥¨¥é¡¼¤È¤·¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢
223 ¤¬¤É¤Î¤è¤¦¤ÊÃͤˤʤ뤫¤òÄê¤á¤Æ¤¤¤Ê¤¤¡£
224 ¤½¤Î¤¿¤á¡¢¥¨¥é¡¼¤òǧ¼±¤¹¤ë¤³¤È¤ÏÉÔ²Äǽ¤Ç¤¢¤ë¡£
225 POSIX ¤Ë½àµò¤·¤Æ¡¢¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï
227 ¤òÊѹ¹¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤Ù¤¤Ç¤¢¤ë¡¢¤È¼çÄ¥¤¹¤ë¿Í¤â¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
228 ÍÍ¡¹¤Ê Unix ·Ï¤Î¥·¥¹¥Æ¥à¤Ç»î¤·¤Æ¤ß¤ë¤È¡¢¤½¤Î¤è¤¦¤Ê¾ì¹ç¤Ë¤Ï
229 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM ¤È¤¤¤Ã¤¿ÍÍ¡¹¤ÊÃͤ¬ÊÖ¤µ¤ì¤ë¡£
230 ¾¤ÎÃͤ¬ÊÖ¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
232 .\" AIX 5.1 ¤Ï ESRCH ¤òÊÖ¤¹¡£
233 .\" OSF1 4.0g ¤Ï EWOULDBLOCK ¤òÊÖ¤¹¡£
234 .\" libc, glibc (¥Ð¡¼¥¸¥ç¥ó 2.6 ¤Þ¤Ç), Irix 6.5 ¤Ï ENOENT ¤òÊÖ¤¹¡£
235 .\" glibc (¥Ð¡¼¥¸¥ç¥ó 2.7 °Ê¹ß) ¤Ï 0 ¤òÊÖ¤¹¡£
236 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 ¤Ï EPERM ¤òÊÖ¤¹¡£
237 .\" SunOS 5.8 ¤Ï EBADF ¤òÊÖ¤¹¡£
238 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 ¤Ï 0 ¤òÊÖ¤¹¡£
242 ¤Ë¤Ï¡¢¥æ¡¼¥¶¤Îºî¶È¥Ç¥£¥ì¥¯¥È¥ê̾¤Î½é´üÃͤ¬³ÊǼ¤µ¤ì¤ë¡£
243 ¥í¥°¥¤¥ó¥×¥í¥»¥¹¤Ï¡¢¤³¤Î¥Õ¥£¡¼¥ë¥É¤ÎÃͤò»È¤Ã¤Æ¡¢
246 ´Ä¶ÊÑ¿ô¤ò½é´ü²½¤¹¤ë¡£
247 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¡¢¥æ¡¼¥¶¤Î¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê¤ò·èÄꤹ¤ë¾ì¹ç¤Ë¤Ï¡¢
248 .RI ( getpwuid(getuid())\->pw_dir
251 ¤ÎÃͤò¸¡ºº¤¹¤ë¤è¤¦¤Ë¤¹¤Ù¤¤Ç¤¢¤ë¡£
252 ¤Ê¤¼¤Ê¤é¡¢¤³¤Î¤è¤¦¤Ë¤¹¤ë¤³¤È¤Ç¡¢¥æ¡¼¥¶¤¬¥í¥°¥¤¥ó¡¦¥»¥Ã¥·¥ç¥óÃæ¤Ç
253 ¡Ö¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê¡×¤Î°ÕÌ£¤òÊѹ¹¤Ç¤¤ë¤è¤¦¤Ë¤Ê¤ë¤«¤é¤Ç¤¢¤ë¡£
254 Ê̤Υ桼¥¶¤Î¥Û¡¼¥à¡¦¥Ç¥£¥ì¥¯¥È¥ê (¤Î½é´üÃÍ) ¤òÃΤë¤Ë¤Ï
255 .I getpwnam("username")\->pw_dir
256 ¤«Æ±ÍͤÎÊýË¡¤ò»È¤¦É¬Íפ¬¤¢¤ë¡£
260 ¤Î»ÈÍÑÎã¤ò¼¨¤·¤¿¤â¤Î¤Ç¡¢¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤¿ô¤ÇÅϤµ¤ì¤¿¥æ¡¼¥¶Ì¾¤ËÂФ¹¤ë
261 ´°Á´¤Ê¥æ¡¼¥¶Ì¾¤È¥æ¡¼¥¶ ID ¤òõ¤¹¤â¤Î¤Ç¤¢¤ë¡£
271 main(int argc, char *argv[])
274 struct passwd *result;
280 fprintf(stderr, "Usage: %s username\\n", argv[0]);
284 bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
285 if (bufsize == \-1) /* Ãͤò·èÄê¤Ç¤¤Ê¤«¤Ã¤¿ */
286 bufsize = 16384; /* ½½Ê¬Â礤ÊÃͤˤ¹¤Ù¤ */
288 buf = malloc(bufsize);
294 s = getpwnam_r(argv[1], &pwd, buf, bufsize, &result);
295 if (result == NULL) {
297 printf("Not found\\n");
300 perror("getpwnam_r");
305 printf("Name: %s; UID: %ld\\n", pwd.pw_gecos, (long) pwd.pw_uid);