dir.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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.01 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_01.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: Thies C. Arntzen <thies@thieso.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* {{{ includes/startup/misc */
  19. #include "php.h"
  20. #include "fopen_wrappers.h"
  21. #include "file.h"
  22. #include "php_dir.h"
  23. #include "php_string.h"
  24. #include "php_scandir.h"
  25. #include "basic_functions.h"
  26. #ifdef HAVE_DIRENT_H
  27. #include <dirent.h>
  28. #endif
  29. #if HAVE_UNISTD_H
  30. #include <unistd.h>
  31. #endif
  32. #include <errno.h>
  33. #ifdef PHP_WIN32
  34. #include "win32/readdir.h"
  35. #endif
  36. #ifdef HAVE_GLOB
  37. #ifndef PHP_WIN32
  38. #include <glob.h>
  39. #else
  40. #include "win32/glob.h"
  41. #endif
  42. #endif
  43. typedef struct {
  44. zend_resource *default_dir;
  45. } php_dir_globals;
  46. #ifdef ZTS
  47. #define DIRG(v) ZEND_TSRMG(dir_globals_id, php_dir_globals *, v)
  48. int dir_globals_id;
  49. #else
  50. #define DIRG(v) (dir_globals.v)
  51. php_dir_globals dir_globals;
  52. #endif
  53. static zend_class_entry *dir_class_entry_ptr;
  54. #define FETCH_DIRP() \
  55. ZEND_PARSE_PARAMETERS_START(0, 1) \
  56. Z_PARAM_OPTIONAL \
  57. Z_PARAM_RESOURCE(id) \
  58. ZEND_PARSE_PARAMETERS_END(); \
  59. if (ZEND_NUM_ARGS() == 0) { \
  60. myself = getThis(); \
  61. if (myself) { \
  62. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \
  63. php_error_docref(NULL, E_WARNING, "Unable to find my handle property"); \
  64. RETURN_FALSE; \
  65. } \
  66. if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \
  67. RETURN_FALSE; \
  68. } \
  69. } else { \
  70. if (!DIRG(default_dir) || \
  71. (dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \
  72. RETURN_FALSE; \
  73. } \
  74. } \
  75. } else { \
  76. if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \
  77. RETURN_FALSE; \
  78. } \
  79. }
  80. /* {{{ arginfo */
  81. ZEND_BEGIN_ARG_INFO_EX(arginfo_dir, 0, 0, 0)
  82. ZEND_ARG_INFO(0, dir_handle)
  83. ZEND_END_ARG_INFO()
  84. /* }}} */
  85. static const zend_function_entry php_dir_class_functions[] = {
  86. PHP_FALIAS(close, closedir, arginfo_dir)
  87. PHP_FALIAS(rewind, rewinddir, arginfo_dir)
  88. PHP_NAMED_FE(read, php_if_readdir, arginfo_dir)
  89. PHP_FE_END
  90. };
  91. static void php_set_default_dir(zend_resource *res)
  92. {
  93. if (DIRG(default_dir)) {
  94. zend_list_delete(DIRG(default_dir));
  95. }
  96. if (res) {
  97. GC_ADDREF(res);
  98. }
  99. DIRG(default_dir) = res;
  100. }
  101. PHP_RINIT_FUNCTION(dir)
  102. {
  103. DIRG(default_dir) = NULL;
  104. return SUCCESS;
  105. }
  106. PHP_MINIT_FUNCTION(dir)
  107. {
  108. static char dirsep_str[2], pathsep_str[2];
  109. zend_class_entry dir_class_entry;
  110. INIT_CLASS_ENTRY(dir_class_entry, "Directory", php_dir_class_functions);
  111. dir_class_entry_ptr = zend_register_internal_class(&dir_class_entry);
  112. #ifdef ZTS
  113. ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
  114. #endif
  115. dirsep_str[0] = DEFAULT_SLASH;
  116. dirsep_str[1] = '\0';
  117. REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, CONST_CS|CONST_PERSISTENT);
  118. pathsep_str[0] = ZEND_PATHS_SEPARATOR;
  119. pathsep_str[1] = '\0';
  120. REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_CS|CONST_PERSISTENT);
  121. REGISTER_LONG_CONSTANT("SCANDIR_SORT_ASCENDING", PHP_SCANDIR_SORT_ASCENDING, CONST_CS | CONST_PERSISTENT);
  122. REGISTER_LONG_CONSTANT("SCANDIR_SORT_DESCENDING", PHP_SCANDIR_SORT_DESCENDING, CONST_CS | CONST_PERSISTENT);
  123. REGISTER_LONG_CONSTANT("SCANDIR_SORT_NONE", PHP_SCANDIR_SORT_NONE, CONST_CS | CONST_PERSISTENT);
  124. #ifdef HAVE_GLOB
  125. #ifdef GLOB_BRACE
  126. REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_CS | CONST_PERSISTENT);
  127. #else
  128. # define GLOB_BRACE 0
  129. #endif
  130. #ifdef GLOB_MARK
  131. REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_CS | CONST_PERSISTENT);
  132. #else
  133. # define GLOB_MARK 0
  134. #endif
  135. #ifdef GLOB_NOSORT
  136. REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_CS | CONST_PERSISTENT);
  137. #else
  138. # define GLOB_NOSORT 0
  139. #endif
  140. #ifdef GLOB_NOCHECK
  141. REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_CS | CONST_PERSISTENT);
  142. #else
  143. # define GLOB_NOCHECK 0
  144. #endif
  145. #ifdef GLOB_NOESCAPE
  146. REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT);
  147. #else
  148. # define GLOB_NOESCAPE 0
  149. #endif
  150. #ifdef GLOB_ERR
  151. REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_CS | CONST_PERSISTENT);
  152. #else
  153. # define GLOB_ERR 0
  154. #endif
  155. #ifndef GLOB_ONLYDIR
  156. # define GLOB_ONLYDIR (1<<30)
  157. # define GLOB_EMULATE_ONLYDIR
  158. # define GLOB_FLAGMASK (~GLOB_ONLYDIR)
  159. #else
  160. # define GLOB_FLAGMASK (~0)
  161. #endif
  162. /* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */
  163. #define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR)
  164. REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_CS | CONST_PERSISTENT);
  165. REGISTER_LONG_CONSTANT("GLOB_AVAILABLE_FLAGS", GLOB_AVAILABLE_FLAGS, CONST_CS | CONST_PERSISTENT);
  166. #endif /* HAVE_GLOB */
  167. return SUCCESS;
  168. }
  169. /* }}} */
  170. /* {{{ internal functions */
  171. static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject)
  172. {
  173. char *dirname;
  174. size_t dir_len;
  175. zval *zcontext = NULL;
  176. php_stream_context *context = NULL;
  177. php_stream *dirp;
  178. ZEND_PARSE_PARAMETERS_START(1, 2)
  179. Z_PARAM_PATH(dirname, dir_len)
  180. Z_PARAM_OPTIONAL
  181. Z_PARAM_RESOURCE(zcontext)
  182. ZEND_PARSE_PARAMETERS_END();
  183. context = php_stream_context_from_zval(zcontext, 0);
  184. dirp = php_stream_opendir(dirname, REPORT_ERRORS, context);
  185. if (dirp == NULL) {
  186. RETURN_FALSE;
  187. }
  188. dirp->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
  189. php_set_default_dir(dirp->res);
  190. if (createobject) {
  191. object_init_ex(return_value, dir_class_entry_ptr);
  192. add_property_stringl(return_value, "path", dirname, dir_len);
  193. add_property_resource(return_value, "handle", dirp->res);
  194. php_stream_auto_cleanup(dirp); /* so we don't get warnings under debug */
  195. } else {
  196. php_stream_to_zval(dirp, return_value);
  197. }
  198. }
  199. /* }}} */
  200. /* {{{ proto mixed opendir(string path[, resource context])
  201. Open a directory and return a dir_handle */
  202. PHP_FUNCTION(opendir)
  203. {
  204. _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  205. }
  206. /* }}} */
  207. /* {{{ proto object dir(string directory[, resource context])
  208. Directory class with properties, handle and class and methods read, rewind and close */
  209. PHP_FUNCTION(getdir)
  210. {
  211. _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  212. }
  213. /* }}} */
  214. /* {{{ proto void closedir([resource dir_handle])
  215. Close directory connection identified by the dir_handle */
  216. PHP_FUNCTION(closedir)
  217. {
  218. zval *id = NULL, *tmp, *myself;
  219. php_stream *dirp;
  220. zend_resource *res;
  221. FETCH_DIRP();
  222. if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
  223. php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
  224. RETURN_FALSE;
  225. }
  226. res = dirp->res;
  227. zend_list_close(dirp->res);
  228. if (res == DIRG(default_dir)) {
  229. php_set_default_dir(NULL);
  230. }
  231. }
  232. /* }}} */
  233. #if defined(HAVE_CHROOT) && !defined(ZTS) && ENABLE_CHROOT_FUNC
  234. /* {{{ proto bool chroot(string directory)
  235. Change root directory */
  236. PHP_FUNCTION(chroot)
  237. {
  238. char *str;
  239. int ret;
  240. size_t str_len;
  241. ZEND_PARSE_PARAMETERS_START(1, 1)
  242. Z_PARAM_PATH(str, str_len)
  243. ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
  244. ret = chroot(str);
  245. if (ret != 0) {
  246. php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno);
  247. RETURN_FALSE;
  248. }
  249. php_clear_stat_cache(1, NULL, 0);
  250. ret = chdir("/");
  251. if (ret != 0) {
  252. php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno);
  253. RETURN_FALSE;
  254. }
  255. RETURN_TRUE;
  256. }
  257. /* }}} */
  258. #endif
  259. /* {{{ proto bool chdir(string directory)
  260. Change the current directory */
  261. PHP_FUNCTION(chdir)
  262. {
  263. char *str;
  264. int ret;
  265. size_t str_len;
  266. ZEND_PARSE_PARAMETERS_START(1, 1)
  267. Z_PARAM_PATH(str, str_len)
  268. ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
  269. if (php_check_open_basedir(str)) {
  270. RETURN_FALSE;
  271. }
  272. ret = VCWD_CHDIR(str);
  273. if (ret != 0) {
  274. php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno);
  275. RETURN_FALSE;
  276. }
  277. if (BG(CurrentStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentStatFile), strlen(BG(CurrentStatFile)))) {
  278. efree(BG(CurrentStatFile));
  279. BG(CurrentStatFile) = NULL;
  280. }
  281. if (BG(CurrentLStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentLStatFile), strlen(BG(CurrentLStatFile)))) {
  282. efree(BG(CurrentLStatFile));
  283. BG(CurrentLStatFile) = NULL;
  284. }
  285. RETURN_TRUE;
  286. }
  287. /* }}} */
  288. /* {{{ proto mixed getcwd(void)
  289. Gets the current directory */
  290. PHP_FUNCTION(getcwd)
  291. {
  292. char path[MAXPATHLEN];
  293. char *ret=NULL;
  294. if (zend_parse_parameters_none() == FAILURE) {
  295. return;
  296. }
  297. #if HAVE_GETCWD
  298. ret = VCWD_GETCWD(path, MAXPATHLEN);
  299. #elif HAVE_GETWD
  300. ret = VCWD_GETWD(path);
  301. #endif
  302. if (ret) {
  303. RETURN_STRING(path);
  304. } else {
  305. RETURN_FALSE;
  306. }
  307. }
  308. /* }}} */
  309. /* {{{ proto void rewinddir([resource dir_handle])
  310. Rewind dir_handle back to the start */
  311. PHP_FUNCTION(rewinddir)
  312. {
  313. zval *id = NULL, *tmp, *myself;
  314. php_stream *dirp;
  315. FETCH_DIRP();
  316. if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
  317. php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
  318. RETURN_FALSE;
  319. }
  320. php_stream_rewinddir(dirp);
  321. }
  322. /* }}} */
  323. /* {{{ proto string readdir([resource dir_handle])
  324. Read directory entry from dir_handle */
  325. PHP_NAMED_FUNCTION(php_if_readdir)
  326. {
  327. zval *id = NULL, *tmp, *myself;
  328. php_stream *dirp;
  329. php_stream_dirent entry;
  330. FETCH_DIRP();
  331. if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
  332. php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
  333. RETURN_FALSE;
  334. }
  335. if (php_stream_readdir(dirp, &entry)) {
  336. RETURN_STRINGL(entry.d_name, strlen(entry.d_name));
  337. }
  338. RETURN_FALSE;
  339. }
  340. /* }}} */
  341. #ifdef HAVE_GLOB
  342. /* {{{ proto array glob(string pattern [, int flags])
  343. Find pathnames matching a pattern */
  344. PHP_FUNCTION(glob)
  345. {
  346. size_t cwd_skip = 0;
  347. #ifdef ZTS
  348. char cwd[MAXPATHLEN];
  349. char work_pattern[MAXPATHLEN];
  350. char *result;
  351. #endif
  352. char *pattern = NULL;
  353. size_t pattern_len;
  354. zend_long flags = 0;
  355. glob_t globbuf;
  356. size_t n;
  357. int ret;
  358. zend_bool basedir_limit = 0;
  359. ZEND_PARSE_PARAMETERS_START(1, 2)
  360. Z_PARAM_PATH(pattern, pattern_len)
  361. Z_PARAM_OPTIONAL
  362. Z_PARAM_LONG(flags)
  363. ZEND_PARSE_PARAMETERS_END();
  364. if (pattern_len >= MAXPATHLEN) {
  365. php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
  366. RETURN_FALSE;
  367. }
  368. if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {
  369. php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform");
  370. RETURN_FALSE;
  371. }
  372. #ifdef ZTS
  373. if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) {
  374. result = VCWD_GETCWD(cwd, MAXPATHLEN);
  375. if (!result) {
  376. cwd[0] = '\0';
  377. }
  378. #ifdef PHP_WIN32
  379. if (IS_SLASH(*pattern)) {
  380. cwd[2] = '\0';
  381. }
  382. #endif
  383. cwd_skip = strlen(cwd)+1;
  384. snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern);
  385. pattern = work_pattern;
  386. }
  387. #endif
  388. memset(&globbuf, 0, sizeof(glob_t));
  389. globbuf.gl_offs = 0;
  390. if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) {
  391. #ifdef GLOB_NOMATCH
  392. if (GLOB_NOMATCH == ret) {
  393. /* Some glob implementation simply return no data if no matches
  394. were found, others return the GLOB_NOMATCH error code.
  395. We don't want to treat GLOB_NOMATCH as an error condition
  396. so that PHP glob() behaves the same on both types of
  397. implementations and so that 'foreach (glob() as ...'
  398. can be used for simple glob() calls without further error
  399. checking.
  400. */
  401. goto no_results;
  402. }
  403. #endif
  404. RETURN_FALSE;
  405. }
  406. /* now catch the FreeBSD style of "no matches" */
  407. if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
  408. #ifdef GLOB_NOMATCH
  409. no_results:
  410. #endif
  411. #ifndef PHP_WIN32
  412. /* Paths containing '*', '?' and some other chars are
  413. illegal on Windows but legit on other platforms. For
  414. this reason the direct basedir check against the glob
  415. query is senseless on windows. For instance while *.txt
  416. is a pretty valid filename on EXT3, it's invalid on NTFS. */
  417. if (PG(open_basedir) && *PG(open_basedir)) {
  418. if (php_check_open_basedir_ex(pattern, 0)) {
  419. RETURN_FALSE;
  420. }
  421. }
  422. #endif
  423. array_init(return_value);
  424. return;
  425. }
  426. array_init(return_value);
  427. for (n = 0; n < (size_t)globbuf.gl_pathc; n++) {
  428. if (PG(open_basedir) && *PG(open_basedir)) {
  429. if (php_check_open_basedir_ex(globbuf.gl_pathv[n], 0)) {
  430. basedir_limit = 1;
  431. continue;
  432. }
  433. }
  434. /* we need to do this every time since GLOB_ONLYDIR does not guarantee that
  435. * all directories will be filtered. GNU libc documentation states the
  436. * following:
  437. * If the information about the type of the file is easily available
  438. * non-directories will be rejected but no extra work will be done to
  439. * determine the information for each file. I.e., the caller must still be
  440. * able to filter directories out.
  441. */
  442. if (flags & GLOB_ONLYDIR) {
  443. zend_stat_t s;
  444. if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
  445. continue;
  446. }
  447. if (S_IFDIR != (s.st_mode & S_IFMT)) {
  448. continue;
  449. }
  450. }
  451. add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip);
  452. }
  453. globfree(&globbuf);
  454. if (basedir_limit && !zend_hash_num_elements(Z_ARRVAL_P(return_value))) {
  455. zend_array_destroy(Z_ARR_P(return_value));
  456. RETURN_FALSE;
  457. }
  458. }
  459. /* }}} */
  460. #endif
  461. /* {{{ proto array scandir(string dir [, int sorting_order [, resource context]])
  462. List files & directories inside the specified path */
  463. PHP_FUNCTION(scandir)
  464. {
  465. char *dirn;
  466. size_t dirn_len;
  467. zend_long flags = 0;
  468. zend_string **namelist;
  469. int n, i;
  470. zval *zcontext = NULL;
  471. php_stream_context *context = NULL;
  472. ZEND_PARSE_PARAMETERS_START(1, 3)
  473. Z_PARAM_PATH(dirn, dirn_len)
  474. Z_PARAM_OPTIONAL
  475. Z_PARAM_LONG(flags)
  476. Z_PARAM_RESOURCE(zcontext)
  477. ZEND_PARSE_PARAMETERS_END();
  478. if (dirn_len < 1) {
  479. php_error_docref(NULL, E_WARNING, "Directory name cannot be empty");
  480. RETURN_FALSE;
  481. }
  482. if (zcontext) {
  483. context = php_stream_context_from_zval(zcontext, 0);
  484. }
  485. if (flags == PHP_SCANDIR_SORT_ASCENDING) {
  486. n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasort);
  487. } else if (flags == PHP_SCANDIR_SORT_NONE) {
  488. n = php_stream_scandir(dirn, &namelist, context, NULL);
  489. } else {
  490. n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr);
  491. }
  492. if (n < 0) {
  493. php_error_docref(NULL, E_WARNING, "(errno %d): %s", errno, strerror(errno));
  494. RETURN_FALSE;
  495. }
  496. array_init(return_value);
  497. for (i = 0; i < n; i++) {
  498. add_next_index_str(return_value, namelist[i]);
  499. }
  500. if (n) {
  501. efree(namelist);
  502. }
  503. }
  504. /* }}} */
  505. /*
  506. * Local variables:
  507. * tab-width: 4
  508. * c-basic-offset: 4
  509. * End:
  510. * vim600: sw=4 ts=4 fdm=marker
  511. * vim<600: sw=4 ts=4
  512. */