summaryrefslogtreecommitdiff
path: root/regress/bin/chmod/Makefile
blob: 703e5de37b6dc6b394a7cc80b452a6b3ca446939 (plain)
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# $OpenBSD: Makefile,v 1.5 2021/07/06 19:48:05 bluhm Exp $

REGRESS_TARGETS=	chmod_abs_0000 chmod_abs_0644
REGRESS_TARGETS+=	chmod_sym_0644 chmod_sym_0000
REGRESS_TARGETS+=	chmod_R_0755 chmod_RP_0755 chmod_RH_0755 chmod_RL_0755
REGRESS_TARGETS+=	chmod_h_abs_0000 chmod_h_abs_0644
REGRESS_TARGETS+=	chmod_h_sym_0000 chmod_h_sym_0644
REGRESS_TARGETS+=	chmod_h_go_minus_r chmod_h_go_minus_rx
REGRESS_TARGETS+=	chmod_h_go_plus_r chmod_h_go_plus_rx
REGRESS_TARGETS+=	chmod_via_link_abs_0000 chmod_via_link_abs_0644
REGRESS_TARGETS+=	chmod_via_link_sym_0000 chmod_via_link_sym_0644
REGRESS_TARGETS+=	chmod_via_link_go_minus_r chmod_via_link_go_minus_rx
REGRESS_TARGETS+=	chmod_via_link_go_plus_r chmod_via_link_go_plus_rx
REGRESS_TARGETS+=	chmod_error

REGRESS_TARGETS+=	chgrp_error

REGRESS_TARGETS+=	chown_error

REGRESS_TARGETS+=	chflags chflags_no
REGRESS_TARGETS+=	chflags_R chflags_RP chflags_RH chflags_RL
REGRESS_TARGETS+=	chflags_via_link
REGRESS_TARGETS+=	chflags_error

REGRESS_ROOT_TARGETS+=	chgrp_id
REGRESS_ROOT_TARGETS+=	chgrp_name
REGRESS_ROOT_TARGETS+=	chgrp_symlink
REGRESS_ROOT_TARGETS+=	chgrp_h_symlink
REGRESS_ROOT_TARGETS+=	chgrp_R
REGRESS_ROOT_TARGETS+=	chgrp_RP
REGRESS_ROOT_TARGETS+=	chgrp_RH
REGRESS_ROOT_TARGETS+=	chgrp_RL
REGRESS_ROOT_TARGETS+=	chown_id
REGRESS_ROOT_TARGETS+=	chown_name
REGRESS_ROOT_TARGETS+=	chown_symlink
REGRESS_ROOT_TARGETS+=	chown_h_symlink
REGRESS_ROOT_TARGETS+=	chown_R
REGRESS_ROOT_TARGETS+=	chown_RP
REGRESS_ROOT_TARGETS+=	chown_RH
REGRESS_ROOT_TARGETS+=	chown_RL

REGRESS_TARGETS+=	${REGRESS_ROOT_TARGETS}

MKDIR=			/bin/mkdir
TOUCH=			/usr/bin/touch
CHMOD=			/bin/chmod
LN=			/bin/ln
CHFLAGS=		/usr/bin/chflags
CHGRP=			${SUDO} /bin/chgrp
CHOWN=			${SUDO} /sbin/chown
STAT=			${SUDO} /usr/bin/stat
DIFF=			/usr/bin/diff -up
RM=			${SUDO} /bin/rm

prepfile: clean
	${MKDIR} -p regress
	${TOUCH} regress/file
	${CHMOD} 000 regress/file
	[ `${STAT} -f '%p' regress/file` == '100000' ]

chmod_prepsymlink: prepfile
	${LN} -s ${.OBJDIR}/regress/file regress/link
	${CHMOD} -h 755 regress/link
	[ `${STAT} -f '%p' regress/link` == '120755' ]

prepdir: clean
	${MKDIR} -p regress/dir
	${TOUCH} regress/dir/file1
	${TOUCH} regress/dir/file2
	${CHMOD} 000 regress/dir/file1
	${CHMOD} 000 regress/dir/file2
	${TOUCH} regress/link_target_file
	${CHMOD} 0600 regress/link_target_file
	[ `${STAT} -f '%p' regress/dir/file1` == '100000' ]
	[ `${STAT} -f '%p' regress/dir/file2` == '100000' ]
	${LN} -s ${.OBJDIR}/regress/link_target_file regress/dir/linked_file
	${LN} -s ${.OBJDIR}/regress/dir regress/linked_dir
	${CHMOD} 000 regress/dir
	[ `${STAT} -f '%p' regress/dir` == '40000' ]
	[ `${STAT} -f '%p' regress/link_target_file` == '100600' ]

chown_prepfile: prepfile
	${CHOWN} root:wheel regress/file
	[ `${STAT} -f '%Su' regress/file` == 'root' ]
	[ `${STAT} -f '%Sg' regress/file` == 'wheel' ]

chown_prepsymlink: chown_prepfile
	${LN} -s ${.OBJDIR}/regress/file regress/symlink
	${CHOWN} -h root:wheel regress/symlink
	[ `${STAT} -f '%Su' regress/symlink` == 'root' ]
	[ `${STAT} -f '%Sg' regress/symlink` == 'wheel' ]

chown_prepdir: prepdir
	${CHMOD} -R 0755 regress
	${CHOWN} -RL root:wheel regress

chflags_prepfile: prepfile
	${CHFLAGS} dump regress/file
	[ `${STAT} -f '%f' regress/file` == '0' ]

chflags_prepdir: prepdir
	${CHMOD} -R 0755 regress
	${CHFLAGS} -RL dump regress

chmod_abs_0000: prepfile
	${CHMOD} 0644 regress/file
	${CHMOD} 0000 regress/file
	[ `${STAT} -f '%p' regress/file` == '100000' ]

chmod_abs_0644: prepfile
	${CHMOD} 0644 regress/file
	[ `${STAT} -f '%p' regress/file` == '100644' ]

chmod_sym_0644: prepfile
	${CHMOD} u=rw,go=r regress/file
	[ `${STAT} -f '%p' regress/file` == '100644' ]

chmod_sym_0000: prepfile
	${CHMOD} 0644 regress/file
	${CHMOD} a-rwx regress/file
	[ `${STAT} -f '%p' regress/file` == '100000' ]

chmod_R_0755: prepdir
	${CHMOD} -R 0755 regress/dir
	[ `${STAT} -f '%p' regress/dir/file1` == '100755' ]
	[ `${STAT} -f '%p' regress/dir/file2` == '100755' ]
	[ `${STAT} -f '%p' regress/dir` == '40755' ]
	[ `${STAT} -f '%p' regress/link_target_file` == '100600' ]

chmod_RP_0755: prepdir
	${CHMOD} -RP 0755 regress/dir
	[ `${STAT} -f '%p' regress/dir/file1` == '100755' ]
	[ `${STAT} -f '%p' regress/dir/file2` == '100755' ]
	[ `${STAT} -f '%p' regress/dir` == '40755' ]
	[ `${STAT} -f '%p' regress/link_target_file` == '100600' ]

chmod_RH_0755: prepdir
	${CHMOD} -RH 0755 regress/linked_dir
	[ `${STAT} -f '%p' regress/dir/file1` == '100755' ]
	[ `${STAT} -f '%p' regress/dir/file2` == '100755' ]
	[ `${STAT} -f '%p' regress/dir` == '40755' ]
	[ `${STAT} -f '%p' regress/link_target_file` == '100600' ]

chmod_RL_0755: prepdir
	${CHMOD} -RL 0755 regress/linked_dir
	[ `${STAT} -f '%p' regress/dir/file1` == '100755' ]
	[ `${STAT} -f '%p' regress/dir/file2` == '100755' ]
	[ `${STAT} -f '%p' regress/dir` == '40755' ]
	[ `${STAT} -f '%p' regress/link_target_file` == '100755' ]

chmod_h_abs_0000: chmod_prepsymlink
	${CHMOD} -h 0000 regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120000' ]

chmod_h_abs_0644: chmod_prepsymlink
	${CHMOD} -h 0644 regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120644' ]

chmod_h_sym_0000: chmod_prepsymlink
	${CHMOD} -h a-rwx regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120000' ]

chmod_h_sym_0644: chmod_prepsymlink
	${CHMOD} -h u=rw,go=r regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120644' ]

chmod_h_go_minus_r: chmod_prepsymlink
	${CHMOD} -h go-r regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120711' ]

chmod_h_go_minus_rx: chmod_prepsymlink
	${CHMOD} -h go-rx regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120700' ]

chmod_h_go_plus_r: chmod_prepsymlink
	${CHMOD} -h go+r regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_h_go_plus_rx: chmod_prepsymlink
	${CHMOD} -h go+rx regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_via_link_abs_0000: chmod_prepsymlink
	${CHMOD} 0000 regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_via_link_abs_0644: chmod_prepsymlink
	${CHMOD} 0644 regress/link
	[ `${STAT} -f '%p' regress/file` == '100644' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_via_link_sym_0000: chmod_prepsymlink
	${CHMOD} a-rwx regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_via_link_sym_0644: chmod_prepsymlink
	${CHMOD} u=rw,go=r regress/link
	[ `${STAT} -f '%p' regress/file` == '100644' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_via_link_go_minus_r: chmod_prepsymlink
	${CHMOD} go-r regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_via_link_go_minus_rx: chmod_prepsymlink
	${CHMOD} go-rx regress/link
	[ `${STAT} -f '%p' regress/file` == '100000' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_via_link_go_plus_r: chmod_prepsymlink
	${CHMOD} go+r regress/link
	[ `${STAT} -f '%p' regress/file` == '100044' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_via_link_go_plus_rx: chmod_prepsymlink
	${CHMOD} go+rx regress/link
	[ `${STAT} -f '%p' regress/file` == '100055' ]
	[ `${STAT} -f '%p' regress/link` == '120755' ]

chmod_error:
	${CHMOD} foo bar 2>chmod.err || true
	${DIFF} ${.CURDIR}/chmod.error chmod.err

chgrp_id: chown_prepfile
	${CHGRP} 32767 regress/file
	[ `${STAT} -f '%g' regress/file` == 32767 ]

chgrp_name: chown_prepfile
	${CHGRP} nobody regress/file
	[ `${STAT} -f '%Sg' regress/file` == 'nobody' ]

chgrp_symlink: chown_prepsymlink
	${CHGRP} nobody regress/symlink
	[ `${STAT} -f '%Sg' regress/file` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/symlink` == 'wheel' ]

chgrp_h_symlink: chown_prepsymlink
	${CHGRP} -h nobody regress/symlink
	[ `${STAT} -f '%Sg' regress/file` == 'wheel' ]
	[ `${STAT} -f '%Sg' regress/symlink` == 'nobody' ]

chgrp_R: chown_prepdir
	${CHGRP} -R nobody regress/dir
	[ `${STAT} -f '%Sg' regress/dir/file1` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/dir/file2` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/dir` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/link_target_file` == 'wheel' ]

chgrp_RP: chown_prepdir
	${CHGRP} -RP nobody regress/dir
	[ `${STAT} -f '%Sg' regress/dir/file1` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/dir/file2` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/dir` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/link_target_file` == 'wheel' ]

chgrp_RH: chown_prepdir
	${CHGRP} -RH nobody regress/linked_dir
	[ `${STAT} -f '%Sg' regress/dir/file1` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/dir/file2` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/dir` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/link_target_file` == 'wheel' ]

chgrp_RL: chown_prepdir
	${CHGRP} -RL nobody regress/linked_dir
	[ `${STAT} -f '%Sg' regress/dir/file1` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/dir/file2` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/dir` == 'nobody' ]
	[ `${STAT} -f '%Sg' regress/link_target_file` == 'nobody' ]

chgrp_error:
	${CHGRP} __hopefully_not_existing_group bar 2>chgrp.err || true
	${DIFF} ${.CURDIR}/chgrp.error chgrp.err

chown_id: chown_prepfile
	${CHOWN} 32767 regress/file
	[ `${STAT} -f '%u' regress/file` == 32767 ]

chown_name: chown_prepfile
	${CHOWN} nobody regress/file
	[ `${STAT} -f '%Su' regress/file` == 'nobody' ]

chown_symlink: chown_prepsymlink
	${CHOWN} nobody regress/symlink
	[ `${STAT} -f '%Su' regress/file` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/symlink` == 'root' ]

chown_h_symlink: chown_prepsymlink
	${CHOWN} -h nobody regress/symlink
	[ `${STAT} -f '%Su' regress/file` == 'root' ]
	[ `${STAT} -f '%Su' regress/symlink` == 'nobody' ]

chown_R: chown_prepdir
	${CHOWN} -R nobody regress/dir
	[ `${STAT} -f '%Su' regress/dir/file1` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/dir/file2` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/dir` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/link_target_file` != 'nobody' ]

chown_RP: chown_prepdir
	${CHOWN} -RP nobody regress/dir
	[ `${STAT} -f '%Su' regress/dir/file1` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/dir/file2` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/dir` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/link_target_file` != 'nobody' ]

chown_RH: chown_prepdir
	${CHOWN} -RH nobody regress/linked_dir
	[ `${STAT} -f '%Su' regress/dir/file1` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/dir/file2` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/dir` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/link_target_file` != 'nobody' ]

chown_RL: chown_prepdir
	${CHOWN} -RL nobody regress/linked_dir
	[ `${STAT} -f '%Su' regress/dir/file1` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/dir/file2` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/dir` == 'nobody' ]
	[ `${STAT} -f '%Su' regress/link_target_file` == 'nobody' ]

chown_error:
	${CHOWN} __hopefully_not_existing_user bar 2>chown.err || true
	${DIFF} ${.CURDIR}/chown.error chown.err

chflags: chflags_prepfile
	${CHFLAGS} nodump regress/file
	[ `${STAT} -f '%f' regress/file` == '1' ]

chflags_no: chflags_prepfile
	${CHFLAGS} nodump regress/file
	[ `${STAT} -f '%f' regress/file` == '1' ]
	${CHFLAGS} dump regress/file
	[ `${STAT} -f '%f' regress/file` == '0' ]

chflags_R: chflags_prepdir
	${CHFLAGS} -R nodump regress/dir
	[ `${STAT} -f '%f' regress/dir/file1` == '1' ]
	[ `${STAT} -f '%f' regress/dir/file2` == '1' ]
	[ `${STAT} -f '%f' regress/dir` == '1' ]
	[ `${STAT} -f '%f' regress/link_target_file` == '0' ]

chflags_RP: chflags_prepdir
	${CHFLAGS} -RP nodump regress/dir
	[ `${STAT} -f '%f' regress/dir/file1` == '1' ]
	[ `${STAT} -f '%f' regress/dir/file2` == '1' ]
	[ `${STAT} -f '%f' regress/dir` == '1' ]
	[ `${STAT} -f '%f' regress/link_target_file` == '0' ]

chflags_RH: chflags_prepdir
	${CHFLAGS} -RH nodump regress/linked_dir
	[ `${STAT} -f '%f' regress/dir/file1` == '1' ]
	[ `${STAT} -f '%f' regress/dir/file2` == '1' ]
	[ `${STAT} -f '%f' regress/dir` == '1' ]
	[ `${STAT} -f '%f' regress/link_target_file` == '0' ]

chflags_RL: chflags_prepdir
	${CHFLAGS} -RL nodump regress/linked_dir
	[ `${STAT} -f '%f' regress/dir/file1` == '1' ]
	[ `${STAT} -f '%f' regress/dir/file2` == '1' ]
	[ `${STAT} -f '%f' regress/dir` == '1' ]
	[ `${STAT} -f '%f' regress/link_target_file` == '1' ]

chflags_via_link: chflags_prepfile
	${LN} -s ${.OBJDIR}/regress/file regress/link
	chflags -h uchg regress/link
	chflags nodump regress/link
	[ `${STAT} -f '%f' regress/link` == '2' ]
	[ `${STAT} -f '%f' regress/file` == '1' ]
	chflags -h nouchg regress/link
	chflags dump regress/link
	[ `${STAT} -f '%f' regress/link` == '0' ]
	[ `${STAT} -f '%f' regress/file` == '0' ]

chflags_error:
	${CHFLAGS} foo bar 2>chflags.err || true
	${DIFF} ${.CURDIR}/chflags.error chflags.err

clean:
	${RM} -f *.err
	${CHMOD} -R 0700 regress 2>/dev/null || true
	${RM} -rf regress

.PHONY: ${REGRESS_TARGETS} prepfile prepdir chown_prepfile chown_prepsymlink \
	    chown_prepdir chflags_prepfile chflags_prepdir

.include <bsd.regress.mk>