ObjFW  Check-in [dec64f3a50]

Overview
Comment:ofarc: Use OFSandbox's new unveiling
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: dec64f3a50bdb0c04da05635daa06f835d6f1ef74cfc7b790d4babf2913f8094
User & Date: js on 2018-11-04 17:51:29
Other Links: manifest | tags
Context
2018-11-04
18:40
Sandbox ofdns check-in: 605634184d user: js tags: trunk
17:51
ofarc: Use OFSandbox's new unveiling check-in: dec64f3a50 user: js tags: trunk
16:24
OFSandbox: Add support for unveil() check-in: 648522a4e6 user: js tags: trunk
Changes

Modified src/OFFileManager.m from [cedacc51c1] to [1b81151f42].

37
38
39
40
41
42
43

44
45
46
47
48
49
50
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFURL.h"
#import "OFURLHandler.h"

#import "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFCopyItemFailedException.h"

#import "OFGetCurrentDirectoryPathFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFMoveItemFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFRemoveItemFailedException.h"







>







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFURL.h"
#import "OFURLHandler.h"

#import "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFCopyItemFailedException.h"
#import "OFCreateDirectoryFailedException.h"
#import "OFGetCurrentDirectoryPathFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFMoveItemFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFRemoveItemFailedException.h"
316
317
318
319
320
321
322






















323
324
325
326
327
328
329
	if (URL == nil)
		@throw [OFInvalidArgumentException exception];

	if (!createParents) {
		[self createDirectoryAtURL: URL];
		return;
	}























	components = [[URL URLEncodedPath] componentsSeparatedByString: @"/"];

	for (OFString *component in components) {
		if (currentPath != nil)
			currentPath = [currentPath
			    stringByAppendingFormat: @"/%@", component];







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
	if (URL == nil)
		@throw [OFInvalidArgumentException exception];

	if (!createParents) {
		[self createDirectoryAtURL: URL];
		return;
	}

	/*
	 * Try blindly creating the directory first.
	 *
	 * The reason for this is that we might be sandboxed, so attempting to
	 * create any of the parent directories will fail, while creating the
	 * directory itself will work.
	 */
	if ([self directoryExistsAtURL: URL])
		return;

	@try {
		[self createDirectoryAtURL: URL];
		return;
	} @catch (OFCreateDirectoryFailedException *e) {
		/*
		 * If we didn't fail because any of the parents is missing,
		 * there is no point in trying to create the parents.
		 */
		if ([e errNo] != ENOENT)
			@throw e;
	}

	components = [[URL URLEncodedPath] componentsSeparatedByString: @"/"];

	for (OFString *component in components) {
		if (currentPath != nil)
			currentPath = [currentPath
			    stringByAppendingFormat: @"/%@", component];

Modified src/OFString+PathAdditions.h from [4fb51bf901] to [cb842db825].

14
15
16
17
18
19
20






21
22
23
24
25
26
27
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN







#ifdef __cplusplus
extern "C" {
#endif
extern int _OFString_PathAdditions_reference;
#ifdef __cplusplus
}







>
>
>
>
>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

#ifdef OF_AMIGAOS
# define OF_PATH_CURRENT_DIRECTORY @""
#else
# define OF_PATH_CURRENT_DIRECTORY @"."
#endif

#ifdef __cplusplus
extern "C" {
#endif
extern int _OFString_PathAdditions_reference;
#ifdef __cplusplus
}

Modified src/OFURLHandler_file.m from [076074cb30] to [a72876bb53].

35
36
37
38
39
40
41

42
43
44
45
46
47
48
# include <grp.h>
#endif

#import "OFURLHandler_file.h"
#import "OFArray.h"
#import "OFDate.h"
#import "OFFile.h"

#import "OFLocale.h"
#import "OFNumber.h"
#import "OFURL.h"

#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif







>







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# include <grp.h>
#endif

#import "OFURLHandler_file.h"
#import "OFArray.h"
#import "OFDate.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFLocale.h"
#import "OFNumber.h"
#import "OFURL.h"

#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif

Modified utils/ofarc/OFArc.m from [6e1359d60a] to [b7dd938e02].

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
	OFOptionsParser *optionsParser;
	of_unichar_t option, mode = '\0';
	of_string_encoding_t encoding = OF_STRING_ENCODING_AUTODETECT;
	OFArray OF_GENERIC(OFString *) *remainingArguments, *files;
	id <Archive> archive;

#ifdef OF_HAVE_SANDBOX
	OFSandbox *sandbox = [[OFSandbox alloc] init];
	@try {
		[sandbox setAllowsStdIO: true];
		[sandbox setAllowsReadingFiles: true];
		[sandbox setAllowsWritingFiles: true];
		[sandbox setAllowsCreatingFiles: true];
		[sandbox setAllowsChangingFileAttributes: true];
		[sandbox setAllowsUserDatabaseReading: true];



		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#ifndef OF_AMIGAOS
	[OFLocale addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"];
#endif







|
|
|
|
|
|
|
|
>
>

|
<
<
<







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
	OFOptionsParser *optionsParser;
	of_unichar_t option, mode = '\0';
	of_string_encoding_t encoding = OF_STRING_ENCODING_AUTODETECT;
	OFArray OF_GENERIC(OFString *) *remainingArguments, *files;
	id <Archive> archive;

#ifdef OF_HAVE_SANDBOX
	OFSandbox *sandbox = [OFSandbox sandbox];

	[sandbox setAllowsStdIO: true];
	[sandbox setAllowsReadingFiles: true];
	[sandbox setAllowsWritingFiles: true];
	[sandbox setAllowsCreatingFiles: true];
	[sandbox setAllowsChangingFileAttributes: true];
	[sandbox setAllowsUserDatabaseReading: true];
	/* Dropped after parsing options */
	[sandbox setAllowsUnveil: true];

	[OFApplication activateSandbox: sandbox];



#endif

#ifndef OF_AMIGAOS
	[OFLocale addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"];
#endif
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
		    @"prog", [OFApplication programName],
		    @"encoding", encodingString)];

		[OFApplication terminateWithStatus: 1];
	}

	remainingArguments = [optionsParser remainingArguments];
	archive = [self openArchiveWithPath: [remainingArguments firstObject]
				       type: type
				       mode: mode
				   encoding: encoding];

	if (outputDir != nil)
		[[OFFileManager defaultManager]
		    changeCurrentDirectoryPath: outputDir];

	switch (mode) {
	case 'a':
	case 'c':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];



















		[archive addFiles: files];
		break;
	case 'l':
		if ([remainingArguments count] != 1)
			help(of_stderr, false, 1);














		[archive listFiles];
		break;
	case 'p':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);








		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];







		[archive printFiles: files];
		break;
	case 'x':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];































		@try {
			[archive extractFiles: files];
		} @catch (OFCreateDirectoryFailedException *e) {
			OFString *error = [OFString
			    stringWithCString: strerror([e errNo])
				     encoding: [OFLocale encoding]];
			[of_stderr writeString: @"\r"];







<
<
<
<
<
<
<
<










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>




>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
		    @"prog", [OFApplication programName],
		    @"encoding", encodingString)];

		[OFApplication terminateWithStatus: 1];
	}

	remainingArguments = [optionsParser remainingArguments];









	switch (mode) {
	case 'a':
	case 'c':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];

#ifdef OF_HAVE_SANDBOX
		[sandbox unveilPath: [remainingArguments firstObject]
			permissions: (mode == 'a' ? @"rwc" : @"wc")];

		for (OFString *path in files)
			[sandbox unveilPath: path
				permissions: @"r"];

		[sandbox setAllowsUnveil: false];
		[OFApplication activateSandbox: sandbox];
#endif

		archive = [self
		    openArchiveWithPath: [remainingArguments firstObject]
				   type: type
				   mode: mode
			       encoding: encoding];

		[archive addFiles: files];
		break;
	case 'l':
		if ([remainingArguments count] != 1)
			help(of_stderr, false, 1);

#ifdef OF_HAVE_SANDBOX
		[sandbox unveilPath: [remainingArguments firstObject]
			permissions: @"r"];
		[sandbox setAllowsUnveil: false];
		[OFApplication activateSandbox: sandbox];
#endif

		archive = [self
		    openArchiveWithPath: [remainingArguments firstObject]
				   type: type
				   mode: mode
			       encoding: encoding];

		[archive listFiles];
		break;
	case 'p':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

#ifdef OF_HAVE_SANDBOX
		[sandbox unveilPath: [remainingArguments firstObject]
			permissions: @"r"];
		[sandbox setAllowsUnveil: false];
		[OFApplication activateSandbox: sandbox];
#endif

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];

		archive = [self
		    openArchiveWithPath: [remainingArguments firstObject]
				   type: type
				   mode: mode
			       encoding: encoding];

		[archive printFiles: files];
		break;
	case 'x':
		if ([remainingArguments count] < 1)
			help(of_stderr, false, 1);

		files = [remainingArguments objectsInRange:
		    of_range(1, [remainingArguments count] - 1)];

#ifdef OF_HAVE_SANDBOX
		[sandbox unveilPath: [remainingArguments firstObject]
			permissions: @"r"];

		if ([files count] > 0)
			for (OFString *path in files)
				[sandbox unveilPath: path
					permissions: @"wc"];
		else {
			OFString *path = (outputDir != nil
			    ? outputDir : OF_PATH_CURRENT_DIRECTORY);
			/* We need 'r' to change the directory to it. */
			[sandbox unveilPath: path
				permissions: @"rwc"];
		}

		[sandbox setAllowsUnveil: false];
		[OFApplication activateSandbox: sandbox];
#endif

		archive = [self
		    openArchiveWithPath: [remainingArguments firstObject]
				   type: type
				   mode: mode
			       encoding: encoding];

		if (outputDir != nil)
			[[OFFileManager defaultManager]
			    changeCurrentDirectoryPath: outputDir];

		@try {
			[archive extractFiles: files];
		} @catch (OFCreateDirectoryFailedException *e) {
			OFString *error = [OFString
			    stringWithCString: strerror([e errNo])
				     encoding: [OFLocale encoding]];
			[of_stderr writeString: @"\r"];