File: chown.2

package info (click to toggle)
manpages-ja 0.5.0.0.20080615-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 20,508 kB
  • ctags: 1
  • sloc: sh: 13,690; perl: 157; makefile: 114
file content (264 lines) | stat: -rw-r--r-- 7,674 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
.\" and Copyright (c) 1998 Andries Brouwer (aeb@cwi.nl)
.\" and Copyright (c) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" 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.
.\"
.\" Modified by Michael Haardt <michael@moria.de>
.\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
.\" Modified 1996-07-09 by Andries Brouwer <aeb@cwi.nl>
.\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
.\" Modified 1997-05-18 by Michael Haardt <michael@cantor.informatik.rwth-aachen.de>
.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
.\" 2007-07-08, mtk, added an example program; updated SYNOPSIS
.\"
.\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara
.\"         all rights reserved.
.\" Translated Mon Jun 24 14:29:55 JST 1996
.\"         by Yosiaki Yanagihara <yosiaki@bsd2.kbnes.nec.co.jp>
.\" Modified Mon May 11 15:26:34 JST 1998
.\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Modified Sun Feb 29 15:33:50 JST 2004
.\"         by Yuichi SATO <ysato444@yahoo.co.jp>
.\" Updated & Modified Wed Dec 29 06:48:16 JST 2004 by Yuichi SATO
.\" Updated 2007-09-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.64
.\"
.TH CHOWN 2 2007-07-26 "Linux" "Linux Programmer's Manual"
.SH ̾
chown, fchown, lchown \- եνͭԤѹ
.SH 
.B #include <unistd.h>
.sp
.BI "int chown(const char *" path ", uid_t " owner ", gid_t " group );
.br
.BI "int fchown(int " fd ", uid_t " owner ", gid_t " group );
.br
.BI "int lchown(const char *" path ", uid_t " owner ", gid_t " group );
.sp
.in -4n
glibc εǽޥ׷
.RB ( feature_test_macros (7)
):
.in
.sp
.BR fchown (),
.BR lchown ():
_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
.SH 
Υƥॳϡ
.I path
ޤ
.I fd
ǻꤵ줿եνͭ (owner) ȥ롼פѹ롣
øĥץ (Linux Ǥ
.B CAP_CHOWN
ѥӥƥ (capability) ĥץ) 
եνͭԤѹǤ롣
եνͭԤϡνͭԤ°Ƥ륰롼פΤ줫
եΥ롼פѹ뤳ȤǤ롣
ø (Linux Ǥ
.BR CAP_CHOWN )
ĥץϡǤդΥ롼פѹǤ롣

.I owner
ޤ
.I group
 \-1 ꤵ줿硢 ID ѹʤ

ѡ桼ʳˤäƼ¹ԥեνͭԤޤϥ롼פ
ѹ줿
.B S_ISUID

.B ISGID
⡼ɥӥåȤϥꥢ롣
POSIX Ϥư롼Ȥ
.BR chown ()
ԤʤäˤĤƤä˻ꤵƤʤ
Linux ˤưϥͥΥС˰¸롣
.\" Linux 2.0 ͥǤϡѡ桼Ǥư
.\" ¾Υ桼ξƱǤä
.\" 2.2 Ǥϡ2.2.12 ޤǤϡѡ桼ξˤ
.\" ΥӥåȤϥꥢʤʤä
.\" 2.2.13 ʹߤǤϡѡ桼Ǥư
.\" Ƥ¾Υ桼ξƱˤʤä
󥰥롼׼¹ԥե
.RB ( S_IXGRP
ӥåȤꤵƤʤե) ξˤ
.B S_ISGID
ӥåȤ϶å (mandatory locking) ̣Ƥ롣
Ƥ
.BR chown ()
ǤϥꥢǤʤ
.SH ֤
ȡ0 ֤
Ԥȡ\-1 ֤
.I errno
Ŭڤͤꤹ롣
.SH 顼
ե륷ƥˤäƤ¾Υ顼֤롣
.B chmod
ǰŪʥ顼ʲ˵󤲤롣
.TP
.B EACCES
.I path
ιǤ˸ (search permission) ʤ
.RB ( path_resolution (7)
⻲)
.TP
.B EFAULT
.I path
Ƥ줿ɥ쥹ֳؤƤ롣
.TP
.B ELOOP
.I path
褹ݤܥå󥯤¿᤮롣
.TP
.B ENAMETOOLONG
.I path
Ĺ᤮롣
.TP
.B ENOENT
ե뤬¸ߤʤ
.TP
.B ENOMEM
ͥ˽ʬʥ꤬ʤ
.TP
.B ENOTDIR
.I path
ιǤǥ쥯ȥǤʤ
.TP
.B EPERM
ƤӽФץ˽ͭԤޤϥ롼 (⤷Ϥξ) ѹ뤿
׵ᤵ (嵭򻲾) ʤ
.TP
.B EROFS
ꤷե뤬ɤ߹ (read-only) Υե롦ƥˤ롣
.PP
.BR fchown ()
ǰŪʥ顼ʲ˵󤲤:
.TP
.B EBADF
ǥץͭǤʤ
.TP
.B EIO
i Ρ (inode) ѹݤ٥ I/O 顼ȯ
.TP
.B ENOENT
嵭򻲾ȡ
.TP
.B EPERM
嵭򻲾ȡ
.TP
.B EROFS
嵭򻲾ȡ
.SH 
4.4BSD, SVr4, POSIX.1-2001.

4.4BSD ǤǤϥѡ桼ΤߤѤǤ
(Ĥޤꡢ̤Υ桼ϥեȤϤǤʤ)
.\" chown():
.\" SVr4 ˤ EINVAL, EINTR, ENOLINK, EMULTIHOP ֤ȵܤƤ뤬
.\" ENOMEM Ϥʤ
.\" POSIX.1 ˤ ENOMEM, ELOOP ˤĤƵܤϤʤ
.\" fchown():
.\" SVr4 ˤ¾ EINVAL, EIO, EINTR, ENOLINK 顼֤ˤĤƤεܤ롣
.SH 
.BR chown ()
 UID ޥåԥ󥰤Ѥ
NFS ե롦ƥ򿯳롣
˥եƤ˥ƤΥƥࡦ򿯳롣

.BR chown ()
˥ץ󤵤줿եФ
򤿤˼äȤˤ롣
饤¦Υåˤͭѹ
桼Υȡºݤ¾Υ饤Ȥǥ桼ˤä
ե˥ǤȤδ֤˻ֺ뤫⤷ʤ

Linux  2.1.81 ΥС (ä 2.1.46 ) Ǥϡ
.BR chown ()
ϥܥå󥯤פʤ
Linux 2.1.81 ʹߤǤ
.BR chown ()
ϥܥå󥯤פʥƥࡦ
.BR lchown ()
ϥܥå󥯤פʤ
Linux 2.1.86 ʹߤǤϤο (Ť
.BR chown ()
ƱưԤʤ) Ʊƥॳֹ
.BR chown ()
ϿƳ줿ֹġ
.SH 
.PP
ʲΥץϡ
ܤΥޥɥ饤ǻꤵ줿̾ΥեνͭԤ
ܤΥޥɥ饤ǻꤵ줿ͤѹ롣
ͭԤϡΥ桼 ID 桼̾Τ줫ǻǤ
(桼̾ǻꤷˤϡ
.BR getpwnam (3)
ȤäƥƥΥѥɥեθԤ졢
桼 ID ؤѴԤ)
.nf

#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
    uid_t uid;
    struct passwd *pwd;
    char *endptr;

    if (argc != 3 || argv[1][0] == '\\0') {
        fprintf(stderr, "%s <owner> <file>\\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    uid = strtol(argv[1], &endptr, 10);  /* Allow a numeric string */

    if (*endptr != '\\0') {         /* Was not pure numeric string */
        pwd = getpwnam(argv[1]);   /* Try getting UID for username */
        if (pwd == NULL) {
            perror("getpwnam");
            exit(EXIT_FAILURE);
        }

        uid = pwd\->pw_uid;
    }

    if (chown(argv[2], uid, \-1) == \-1) {
        perror("chown");
        exit(EXIT_FAILURE);
    } /* if */

    exit(EXIT_SUCCESS);
} /* main */
.fi
.SH Ϣ
.BR chmod (2),
.BR fchownat (2),
.BR flock (2),
.BR path_resolution (7)