xref: /PHP-7.2/ext/fileinfo/fileinfo.c (revision 7a7ec01a)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2018 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.0 of the PHP license,       |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_0.txt.                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Author: Ilia Alshanetsky <ilia@php.net>                              |
16   +----------------------------------------------------------------------+
17 */
18 
19 /* $Id$ */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 #include "php.h"
25 
26 #include <magic.h>
27 /*
28  * HOWMANY specifies the maximum offset libmagic will look at
29  * this is currently hardcoded in the libmagic source but not exported
30  */
31 #ifndef HOWMANY
32 #define HOWMANY 65536
33 #endif
34 
35 #include "php_ini.h"
36 #include "ext/standard/info.h"
37 #include "ext/standard/file.h" /* needed for context stuff */
38 #include "php_fileinfo.h"
39 #include "fopen_wrappers.h" /* needed for is_url */
40 #include "Zend/zend_exceptions.h"
41 
42 /* {{{ macros and type definitions */
43 typedef struct _php_fileinfo {
44 	zend_long options;
45 	struct magic_set *magic;
46 } php_fileinfo;
47 
48 static zend_object_handlers finfo_object_handlers;
49 zend_class_entry *finfo_class_entry;
50 
51 typedef struct _finfo_object {
52 	php_fileinfo *ptr;
53 	zend_object zo;
54 } finfo_object;
55 
56 #define FILEINFO_DECLARE_INIT_OBJECT(object) \
57 	zval *object = ZEND_IS_METHOD_CALL() ? getThis() : NULL;
58 
php_finfo_fetch_object(zend_object * obj)59 static inline finfo_object *php_finfo_fetch_object(zend_object *obj) {
60 	return (finfo_object *)((char*)(obj) - XtOffsetOf(finfo_object, zo));
61 }
62 
63 #define Z_FINFO_P(zv) php_finfo_fetch_object(Z_OBJ_P((zv)))
64 
65 #define FILEINFO_REGISTER_OBJECT(_object, _ptr) \
66 { \
67 	finfo_object *obj; \
68     obj = Z_FINFO_P(_object); \
69     obj->ptr = _ptr; \
70 }
71 
72 #define FILEINFO_FROM_OBJECT(finfo, object) \
73 { \
74 	finfo_object *obj = Z_FINFO_P(object); \
75 	finfo = obj->ptr; \
76 	if (!finfo) { \
77         	php_error_docref(NULL, E_WARNING, "The invalid fileinfo object."); \
78 		RETURN_FALSE; \
79 	} \
80 }
81 
82 /* {{{ finfo_objects_free
83  */
finfo_objects_free(zend_object * object)84 static void finfo_objects_free(zend_object *object)
85 {
86 	finfo_object *intern = php_finfo_fetch_object(object);
87 
88 	if (intern->ptr) {
89 		magic_close(intern->ptr->magic);
90 		efree(intern->ptr);
91 	}
92 
93 	zend_object_std_dtor(&intern->zo);
94 }
95 /* }}} */
96 
97 /* {{{ finfo_objects_new
98  */
finfo_objects_new(zend_class_entry * class_type)99 PHP_FILEINFO_API zend_object *finfo_objects_new(zend_class_entry *class_type)
100 {
101 	finfo_object *intern;
102 
103 	intern = ecalloc(1, sizeof(finfo_object) + zend_object_properties_size(class_type));
104 
105 	zend_object_std_init(&intern->zo, class_type);
106 	object_properties_init(&intern->zo, class_type);
107 	intern->zo.handlers = &finfo_object_handlers;
108 
109 	return &intern->zo;
110 }
111 /* }}} */
112 
113 /* {{{ arginfo */
114 ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_open, 0, 0, 0)
115 	ZEND_ARG_INFO(0, options)
116 	ZEND_ARG_INFO(0, arg)
117 ZEND_END_ARG_INFO()
118 
119 ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_close, 0, 0, 1)
120 	ZEND_ARG_INFO(0, finfo)
121 ZEND_END_ARG_INFO()
122 
123 ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_set_flags, 0, 0, 2)
124 	ZEND_ARG_INFO(0, finfo)
125 	ZEND_ARG_INFO(0, options)
126 ZEND_END_ARG_INFO()
127 
128 ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_set_flags, 0, 0, 1)
129 	ZEND_ARG_INFO(0, options)
130 ZEND_END_ARG_INFO()
131 
132 ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_file, 0, 0, 2)
133 	ZEND_ARG_INFO(0, finfo)
134 	ZEND_ARG_INFO(0, filename)
135 	ZEND_ARG_INFO(0, options)
136 	ZEND_ARG_INFO(0, context)
137 ZEND_END_ARG_INFO()
138 
139 ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_file, 0, 0, 1)
140 	ZEND_ARG_INFO(0, filename)
141 	ZEND_ARG_INFO(0, options)
142 	ZEND_ARG_INFO(0, context)
143 ZEND_END_ARG_INFO()
144 
145 ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_buffer, 0, 0, 2)
146 	ZEND_ARG_INFO(0, finfo)
147 	ZEND_ARG_INFO(0, string)
148 	ZEND_ARG_INFO(0, options)
149 	ZEND_ARG_INFO(0, context)
150 ZEND_END_ARG_INFO()
151 
152 ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_buffer, 0, 0, 1)
153 	ZEND_ARG_INFO(0, string)
154 	ZEND_ARG_INFO(0, options)
155 	ZEND_ARG_INFO(0, context)
156 ZEND_END_ARG_INFO()
157 
158 ZEND_BEGIN_ARG_INFO_EX(arginfo_mime_content_type, 0, 0, 1)
159 	ZEND_ARG_INFO(0, string)
160 ZEND_END_ARG_INFO()
161 /* }}} */
162 
163 /* {{{ finfo_class_functions
164  */
165 zend_function_entry finfo_class_functions[] = {
166 	ZEND_ME_MAPPING(finfo,          finfo_open,     arginfo_finfo_open, ZEND_ACC_PUBLIC)
167 	ZEND_ME_MAPPING(set_flags,      finfo_set_flags,arginfo_finfo_method_set_flags, ZEND_ACC_PUBLIC)
168 	ZEND_ME_MAPPING(file,           finfo_file,     arginfo_finfo_method_file, ZEND_ACC_PUBLIC)
169 	ZEND_ME_MAPPING(buffer,         finfo_buffer,   arginfo_finfo_method_buffer, ZEND_ACC_PUBLIC)
170 	PHP_FE_END
171 };
172 /* }}} */
173 
174 #define FINFO_SET_OPTION(magic, options) \
175 	if (magic_setflags(magic, options) == -1) { \
176 		php_error_docref(NULL, E_WARNING, "Failed to set option '" ZEND_LONG_FMT "' %d:%s", \
177 				options, magic_errno(magic), magic_error(magic)); \
178 		RETURN_FALSE; \
179 	}
180 
181 /* True global resources - no need for thread safety here */
182 static int le_fileinfo;
183 /* }}} */
184 
finfo_resource_destructor(zend_resource * rsrc)185 void finfo_resource_destructor(zend_resource *rsrc) /* {{{ */
186 {
187 	if (rsrc->ptr) {
188 		php_fileinfo *finfo = (php_fileinfo *) rsrc->ptr;
189 		magic_close(finfo->magic);
190 		efree(rsrc->ptr);
191 		rsrc->ptr = NULL;
192 	}
193 }
194 /* }}} */
195 
196 
197 /* {{{ fileinfo_functions[]
198  */
199 zend_function_entry fileinfo_functions[] = {
200 	PHP_FE(finfo_open,		arginfo_finfo_open)
201 	PHP_FE(finfo_close,		arginfo_finfo_close)
202 	PHP_FE(finfo_set_flags,	arginfo_finfo_set_flags)
203 	PHP_FE(finfo_file,		arginfo_finfo_file)
204 	PHP_FE(finfo_buffer,	arginfo_finfo_buffer)
205 	PHP_FE(mime_content_type, arginfo_mime_content_type)
206 	PHP_FE_END
207 };
208 /* }}} */
209 
210 /* {{{ PHP_MINIT_FUNCTION
211  */
PHP_MINIT_FUNCTION(finfo)212 PHP_MINIT_FUNCTION(finfo)
213 {
214 	zend_class_entry _finfo_class_entry;
215 	INIT_CLASS_ENTRY(_finfo_class_entry, "finfo", finfo_class_functions);
216 	_finfo_class_entry.create_object = finfo_objects_new;
217 	finfo_class_entry = zend_register_internal_class(&_finfo_class_entry);
218 
219 	/* copy the standard object handlers to you handler table */
220 	memcpy(&finfo_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
221 	finfo_object_handlers.offset = XtOffsetOf(finfo_object, zo);
222 	finfo_object_handlers.free_obj = finfo_objects_free;
223 
224 	le_fileinfo = zend_register_list_destructors_ex(finfo_resource_destructor, NULL, "file_info", module_number);
225 
226 	REGISTER_LONG_CONSTANT("FILEINFO_NONE",			MAGIC_NONE, CONST_CS|CONST_PERSISTENT);
227 	REGISTER_LONG_CONSTANT("FILEINFO_SYMLINK",		MAGIC_SYMLINK, CONST_CS|CONST_PERSISTENT);
228 	REGISTER_LONG_CONSTANT("FILEINFO_MIME",			MAGIC_MIME, CONST_CS|CONST_PERSISTENT);
229 	REGISTER_LONG_CONSTANT("FILEINFO_MIME_TYPE",	MAGIC_MIME_TYPE, CONST_CS|CONST_PERSISTENT);
230 	REGISTER_LONG_CONSTANT("FILEINFO_MIME_ENCODING",MAGIC_MIME_ENCODING, CONST_CS|CONST_PERSISTENT);
231 /*	REGISTER_LONG_CONSTANT("FILEINFO_COMPRESS",		MAGIC_COMPRESS, CONST_CS|CONST_PERSISTENT); disabled, as it does fork now */
232 	REGISTER_LONG_CONSTANT("FILEINFO_DEVICES",		MAGIC_DEVICES, CONST_CS|CONST_PERSISTENT);
233 	REGISTER_LONG_CONSTANT("FILEINFO_CONTINUE",		MAGIC_CONTINUE, CONST_CS|CONST_PERSISTENT);
234 #ifdef MAGIC_PRESERVE_ATIME
235 	REGISTER_LONG_CONSTANT("FILEINFO_PRESERVE_ATIME",	MAGIC_PRESERVE_ATIME, CONST_CS|CONST_PERSISTENT);
236 #endif
237 #ifdef MAGIC_RAW
238 	REGISTER_LONG_CONSTANT("FILEINFO_RAW",			MAGIC_RAW, CONST_CS|CONST_PERSISTENT);
239 #endif
240 #if 0
241 	/* seems not usable yet. */
242 	REGISTER_LONG_CONSTANT("FILEINFO_APPLE",		MAGIC_APPLE, CONST_CS|CONST_PERSISTENT);
243 #endif
244 	REGISTER_LONG_CONSTANT("FILEINFO_EXTENSION",	MAGIC_EXTENSION, CONST_CS|CONST_PERSISTENT);
245 
246 	return SUCCESS;
247 }
248 /* }}} */
249 
250 /* {{{ fileinfo_module_entry
251  */
252 zend_module_entry fileinfo_module_entry = {
253 	STANDARD_MODULE_HEADER,
254 	"fileinfo",
255 	fileinfo_functions,
256 	PHP_MINIT(finfo),
257 	NULL,
258 	NULL,
259 	NULL,
260 	PHP_MINFO(fileinfo),
261 	PHP_FILEINFO_VERSION,
262 	STANDARD_MODULE_PROPERTIES
263 };
264 /* }}} */
265 
266 #ifdef COMPILE_DL_FILEINFO
267 ZEND_GET_MODULE(fileinfo)
268 #endif
269 
270 /* {{{ PHP_MINFO_FUNCTION
271  */
PHP_MINFO_FUNCTION(fileinfo)272 PHP_MINFO_FUNCTION(fileinfo)
273 {
274 	char magic_ver[5];
275 
276 	(void)snprintf(magic_ver, 4, "%d", magic_version());
277 	magic_ver[4] = '\0';
278 
279 	php_info_print_table_start();
280 	php_info_print_table_row(2, "fileinfo support", "enabled");
281 	php_info_print_table_row(2, "version", PHP_FILEINFO_VERSION);
282 	php_info_print_table_row(2, "libmagic", magic_ver);
283 	php_info_print_table_end();
284 }
285 /* }}} */
286 
287 /* {{{ proto resource finfo_open([int options [, string arg]])
288    Create a new fileinfo resource. */
PHP_FUNCTION(finfo_open)289 PHP_FUNCTION(finfo_open)
290 {
291 	zend_long options = MAGIC_NONE;
292 	char *file = NULL;
293 	size_t file_len = 0;
294 	php_fileinfo *finfo;
295 	FILEINFO_DECLARE_INIT_OBJECT(object)
296 	char resolved_path[MAXPATHLEN];
297 	zend_error_handling zeh;
298 	int flags = object ? ZEND_PARSE_PARAMS_THROW : 0;
299 
300 	if (zend_parse_parameters_ex(flags, ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
301 		RETURN_FALSE;
302 	}
303 
304 	if (object) {
305 		finfo_object *finfo_obj = Z_FINFO_P(object);
306 
307 		zend_replace_error_handling(EH_THROW, NULL, &zeh);
308 
309 		if (finfo_obj->ptr) {
310 			magic_close(finfo_obj->ptr->magic);
311 			efree(finfo_obj->ptr);
312 			finfo_obj->ptr = NULL;
313 		}
314 	}
315 
316 	if (file_len == 0) {
317 		file = NULL;
318 	} else if (file && *file) { /* user specified file, perform open_basedir checks */
319 
320 		if (php_check_open_basedir(file)) {
321 			if (object) {
322 				zend_restore_error_handling(&zeh);
323 				if (!EG(exception)) {
324 					zend_throw_exception(NULL, "Constructor failed", 0);
325 				}
326 			}
327 			RETURN_FALSE;
328 		}
329 		if (!expand_filepath_with_mode(file, resolved_path, NULL, 0, CWD_EXPAND)) {
330 			if (object) {
331 				zend_restore_error_handling(&zeh);
332 				if (!EG(exception)) {
333 					zend_throw_exception(NULL, "Constructor failed", 0);
334 				}
335 			}
336 			RETURN_FALSE;
337 		}
338 		file = resolved_path;
339 	}
340 
341 	finfo = emalloc(sizeof(php_fileinfo));
342 
343 	finfo->options = options;
344 	finfo->magic = magic_open(options);
345 
346 	if (finfo->magic == NULL) {
347 		efree(finfo);
348 		php_error_docref(NULL, E_WARNING, "Invalid mode '" ZEND_LONG_FMT "'.", options);
349 		if (object) {
350 			zend_restore_error_handling(&zeh);
351 			if (!EG(exception)) {
352 				zend_throw_exception(NULL, "Constructor failed", 0);
353 			}
354 		}
355 		RETURN_FALSE;
356 	}
357 
358 	if (magic_load(finfo->magic, file) == -1) {
359 		php_error_docref(NULL, E_WARNING, "Failed to load magic database at '%s'.", file);
360 		magic_close(finfo->magic);
361 		efree(finfo);
362 		if (object) {
363 			zend_restore_error_handling(&zeh);
364 			if (!EG(exception)) {
365 				zend_throw_exception(NULL, "Constructor failed", 0);
366 			}
367 		}
368 		RETURN_FALSE;
369 	}
370 
371 	if (object) {
372 		zend_restore_error_handling(&zeh);
373 		FILEINFO_REGISTER_OBJECT(object, finfo);
374 	} else {
375 		RETURN_RES(zend_register_resource(finfo, le_fileinfo));
376 	}
377 }
378 /* }}} */
379 
380 /* {{{ proto resource finfo_close(resource finfo)
381    Close fileinfo resource. */
PHP_FUNCTION(finfo_close)382 PHP_FUNCTION(finfo_close)
383 {
384 	php_fileinfo *finfo;
385 	zval *zfinfo;
386 
387 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zfinfo) == FAILURE) {
388 		RETURN_FALSE;
389 	}
390 
391 	if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) {
392 		RETURN_FALSE;
393 	}
394 
395 	zend_list_close(Z_RES_P(zfinfo));
396 
397 	RETURN_TRUE;
398 }
399 /* }}} */
400 
401 /* {{{ proto bool finfo_set_flags(resource finfo, int options)
402    Set libmagic configuration options. */
PHP_FUNCTION(finfo_set_flags)403 PHP_FUNCTION(finfo_set_flags)
404 {
405 	zend_long options;
406 	php_fileinfo *finfo;
407 	zval *zfinfo;
408 	FILEINFO_DECLARE_INIT_OBJECT(object)
409 
410 	if (object) {
411 		if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &options) == FAILURE) {
412 			RETURN_FALSE;
413 		}
414 		FILEINFO_FROM_OBJECT(finfo, object);
415 	} else {
416 		if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &zfinfo, &options) == FAILURE) {
417 			RETURN_FALSE;
418 		}
419 		if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) {
420 			RETURN_FALSE;
421 		}
422 	}
423 
424 	FINFO_SET_OPTION(finfo->magic, options)
425 	finfo->options = options;
426 
427 	RETURN_TRUE;
428 }
429 /* }}} */
430 
431 #define FILEINFO_MODE_BUFFER 0
432 #define FILEINFO_MODE_STREAM 1
433 #define FILEINFO_MODE_FILE 2
434 
_php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS,int mode,int mimetype_emu)435 static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mimetype_emu) /* {{{ */
436 {
437 	zend_long options = 0;
438 	char *ret_val = NULL, *buffer = NULL;
439 	size_t buffer_len;
440 	php_fileinfo *finfo = NULL;
441 	zval *zfinfo, *zcontext = NULL;
442 	zval *what;
443 	char mime_directory[] = "directory";
444 
445 	struct magic_set *magic = NULL;
446 	FILEINFO_DECLARE_INIT_OBJECT(object)
447 
448 	if (mimetype_emu) {
449 
450 		/* mime_content_type(..) emulation */
451 		if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &what) == FAILURE) {
452 			return;
453 		}
454 
455 		switch (Z_TYPE_P(what)) {
456 			case IS_STRING:
457 				buffer = Z_STRVAL_P(what);
458 				buffer_len = Z_STRLEN_P(what);
459 				mode = FILEINFO_MODE_FILE;
460 				break;
461 
462 			case IS_RESOURCE:
463 				mode = FILEINFO_MODE_STREAM;
464 				break;
465 
466 			default:
467 				php_error_docref(NULL, E_WARNING, "Can only process string or stream arguments");
468 				RETURN_FALSE;
469 		}
470 
471 		magic = magic_open(MAGIC_MIME_TYPE);
472 		if (magic_load(magic, NULL) == -1) {
473 			php_error_docref(NULL, E_WARNING, "Failed to load magic database.");
474 			goto common;
475 		}
476 	} else if (object) {
477 		if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lr", &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
478 			RETURN_FALSE;
479 		}
480 		FILEINFO_FROM_OBJECT(finfo, object);
481 		magic = finfo->magic;
482 	} else {
483 		if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lr", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
484 			RETURN_FALSE;
485 		}
486 		if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) {
487 			RETURN_FALSE;
488 		}
489 		magic = finfo->magic;
490 	}
491 
492 	/* Set options for the current file/buffer. */
493 	if (options) {
494 		FINFO_SET_OPTION(magic, options)
495 	}
496 
497 	switch (mode) {
498 		case FILEINFO_MODE_BUFFER:
499 		{
500 			ret_val = (char *) magic_buffer(magic, buffer, buffer_len);
501 			break;
502 		}
503 
504 		case FILEINFO_MODE_STREAM:
505 		{
506 				php_stream *stream;
507 				zend_off_t streampos;
508 
509 				php_stream_from_zval_no_verify(stream, what);
510 				if (!stream) {
511 					goto common;
512 				}
513 
514 				streampos = php_stream_tell(stream); /* remember stream position for restoration */
515 				php_stream_seek(stream, 0, SEEK_SET);
516 
517 				ret_val = (char *) magic_stream(magic, stream);
518 
519 				php_stream_seek(stream, streampos, SEEK_SET);
520 				break;
521 		}
522 
523 		case FILEINFO_MODE_FILE:
524 		{
525 			/* determine if the file is a local file or remote URL */
526 			const char *tmp2;
527 			php_stream_wrapper *wrap;
528 			php_stream_statbuf ssb;
529 
530 			if (buffer == NULL || !*buffer) {
531 				php_error_docref(NULL, E_WARNING, "Empty filename or path");
532 				RETVAL_FALSE;
533 				goto clean;
534 			}
535 			if (CHECK_NULL_PATH(buffer, buffer_len)) {
536 				php_error_docref(NULL, E_WARNING, "Invalid path");
537 				RETVAL_FALSE;
538 				goto clean;
539 			}
540 
541 			wrap = php_stream_locate_url_wrapper(buffer, &tmp2, 0);
542 
543 			if (wrap) {
544 				php_stream *stream;
545 				php_stream_context *context = php_stream_context_from_zval(zcontext, 0);
546 
547 #ifdef PHP_WIN32
548 				if (php_stream_stat_path_ex(buffer, 0, &ssb, context) == SUCCESS) {
549 					if (ssb.sb.st_mode & S_IFDIR) {
550 						ret_val = mime_directory;
551 						goto common;
552 					}
553 				}
554 #endif
555 
556 				stream = php_stream_open_wrapper_ex(buffer, "rb", REPORT_ERRORS, NULL, context);
557 
558 				if (!stream) {
559 					RETVAL_FALSE;
560 					goto clean;
561 				}
562 
563 				if (php_stream_stat(stream, &ssb) == SUCCESS) {
564 					if (ssb.sb.st_mode & S_IFDIR) {
565 						ret_val = mime_directory;
566 					} else {
567 						ret_val = (char *)magic_stream(magic, stream);
568 					}
569 				}
570 
571 				php_stream_close(stream);
572 			}
573 			break;
574 		}
575 
576 		default:
577 			php_error_docref(NULL, E_WARNING, "Can only process string or stream arguments");
578 	}
579 
580 common:
581 	if (ret_val) {
582 		RETVAL_STRING(ret_val);
583 	} else {
584 		php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic));
585 		RETVAL_FALSE;
586 	}
587 
588 clean:
589 	if (mimetype_emu) {
590 		magic_close(magic);
591 	}
592 
593 	/* Restore options */
594 	if (options) {
595 		FINFO_SET_OPTION(magic, finfo->options)
596 	}
597 	return;
598 }
599 /* }}} */
600 
601 /* {{{ proto string finfo_file(resource finfo, char *file_name [, int options [, resource context]])
602    Return information about a file. */
PHP_FUNCTION(finfo_file)603 PHP_FUNCTION(finfo_file)
604 {
605 	_php_finfo_get_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, FILEINFO_MODE_FILE, 0);
606 }
607 /* }}} */
608 
609 /* {{{ proto string finfo_buffer(resource finfo, char *string [, int options [, resource context]])
610    Return infromation about a string buffer. */
PHP_FUNCTION(finfo_buffer)611 PHP_FUNCTION(finfo_buffer)
612 {
613 	_php_finfo_get_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, FILEINFO_MODE_BUFFER, 0);
614 }
615 /* }}} */
616 
617 /* {{{ proto string mime_content_type(string filename|resource stream)
618    Return content-type for file */
PHP_FUNCTION(mime_content_type)619 PHP_FUNCTION(mime_content_type)
620 {
621 	_php_finfo_get_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, -1, 1);
622 }
623 /* }}} */
624 
625 
626 /*
627  * Local variables:
628  * tab-width: 4
629  * c-basic-offset: 4
630  * End:
631  * vim600: noet sw=4 ts=4 fdm=marker
632  * vim<600: noet sw=4 ts=4
633  */
634