summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--ext/posix/config.m42
-rw-r--r--ext/posix/php_posix.h3
-rw-r--r--ext/posix/posix.c64
4 files changed, 69 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 1aa5c47d49..d48ae356bf 100644
--- a/NEWS
+++ b/NEWS
@@ -86,6 +86,7 @@ PHP NEWS
. inet_ntop() (Sara)
. mysqli::client_info property (Georg)
. posix_access() (Magnus)
+ . posix_mknod() (Magnus)
. SimpleXMLElement::registerXPathNamespace() (Christian)
. stream_context_get_default() (Wez)
. stream_socket_enable_crypto() (Wez)
diff --git a/ext/posix/config.m4 b/ext/posix/config.m4
index e687f73bf7..aa24907bc8 100644
--- a/ext/posix/config.m4
+++ b/ext/posix/config.m4
@@ -9,5 +9,5 @@ if test "$PHP_POSIX" = "yes"; then
AC_DEFINE(HAVE_POSIX, 1, [whether to include POSIX-like functions])
PHP_NEW_EXTENSION(posix, posix.c, $ext_shared)
- AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo getrlimit getlogin getgroups)
+ AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod getrlimit getlogin getgroups)
fi
diff --git a/ext/posix/php_posix.h b/ext/posix/php_posix.h
index eff5efcf30..bcc7874785 100644
--- a/ext/posix/php_posix.h
+++ b/ext/posix/php_posix.h
@@ -93,6 +93,9 @@ PHP_FUNCTION(posix_getcwd);
#ifdef HAVE_MKFIFO
PHP_FUNCTION(posix_mkfifo);
#endif
+#ifdef HAVE_MKNOD
+PHP_FUNCTION(posix_mknod);
+#endif
/* POSIX.1, 5.6 */
PHP_FUNCTION(posix_access);
diff --git a/ext/posix/posix.c b/ext/posix/posix.c
index 42c1164e91..7bee3d22e2 100644
--- a/ext/posix/posix.c
+++ b/ext/posix/posix.c
@@ -111,6 +111,9 @@ function_entry posix_functions[] = {
#ifdef HAVE_MKFIFO
PHP_FE(posix_mkfifo, NULL)
#endif
+#ifdef HAVE_MKNOD
+ PHP_FE(posix_mknod, NULL)
+#endif
/* POSIX.1, 5.6 */
PHP_FE(posix_access, NULL)
@@ -156,6 +159,22 @@ static PHP_MINIT_FUNCTION(posix)
REGISTER_LONG_CONSTANT("POSIX_X_OK", X_OK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("POSIX_W_OK", W_OK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("POSIX_R_OK", R_OK, CONST_CS | CONST_PERSISTENT);
+#ifdef S_IFREG
+ REGISTER_LONG_CONSTANT("POSIX_S_IFREG", S_IFREG, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef S_IFCHR
+ REGISTER_LONG_CONSTANT("POSIX_S_IFCHR", S_IFCHR, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef S_IFBLK
+ REGISTER_LONG_CONSTANT("POSIX_S_IFBLK", S_IFBLK, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef S_IFIFO
+ REGISTER_LONG_CONSTANT("POSIX_S_IFIFO", S_IFIFO, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef S_IFSOCK
+ REGISTER_LONG_CONSTANT("POSIX_S_IFSOCK", S_IFSOCK, CONST_CS | CONST_PERSISTENT);
+#endif
+
return SUCCESS;
}
/* }}} */
@@ -646,6 +665,51 @@ PHP_FUNCTION(posix_mkfifo)
#endif
/* }}} */
+/* {{{ proto bool posix_mknod(string pathname, int mode [, int major [, int minor]])
+ Make a special or ordinary file (POSIX.1) */
+#ifdef HAVE_MKNOD
+PHP_FUNCTION(posix_mknod)
+{
+ char *path;
+ int path_len;
+ long mode;
+ long major, minor = 0;
+ int result;
+ dev_t php_dev;
+
+ php_dev = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ll", &path, &path_len,
+ &mode, &major, &minor) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if (php_check_open_basedir_ex(path, 0 TSRMLS_CC) ||
+ (PG(safe_mode) && (!php_checkuid(path, NULL, CHECKUID_ALLOW_ONLY_DIR)))) {
+ RETURN_FALSE;
+ }
+
+ if ((mode & S_IFCHR) || (mode & S_IFBLK)) {
+ if (major == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "expects argument 4 to be non-zero for POSIX_S_IFCHR and POSIX_S_IFBLK");
+ RETURN_FALSE;
+ } else {
+ php_dev = makedev(major, minor);
+ }
+ }
+
+ result = mknod(path, mode, php_dev);
+ if (result < 0) {
+ POSIX_G(last_error) = errno;
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+#endif
+/* }}} */
+
/* Takes a pointer to posix group and a pointer to an already initialized ZVAL
* array container and fills the array with the posix group member data. */
int php_posix_group_to_array(struct group *g, zval *array_group) {