Skip to content

Commit

Permalink
Handle open_basedir checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdm committed Dec 4, 2013
1 parent fbabab8 commit 9a9bdb5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,30 @@ PHP_METHOD(Mosquitto_Client, setTlsCertificates)
zend_bool is_dir = 0;

PHP_MOSQUITTO_ERROR_HANDLING();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sss",
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!|s!s!s!",
&ca_path, &ca_path_len,
&cert_path, &cert_path_len,
&key_path, &key_path_len,
&key_pw, &key_pw_len) == FAILURE) {
PHP_MOSQUITTO_RESTORE_ERRORS();
return;
}

if ((php_check_open_basedir(ca_path TSRMLS_CC) < 0) ||
(php_check_open_basedir(cert_path TSRMLS_CC) < 0) ||
(php_check_open_basedir(key_path TSRMLS_CC) < 0))
{
PHP_MOSQUITTO_RESTORE_ERRORS();
return;
}

PHP_MOSQUITTO_RESTORE_ERRORS();

object = (mosquitto_client_object *) zend_object_store_get_object(getThis() TSRMLS_CC);

php_stat(ca_path, ca_path_len, FS_IS_DIR, stat TSRMLS_CC);
is_dir = Z_BVAL_P(stat);
zval_dtor(stat);
FREE_ZVAL(stat);

if (is_dir) {
retval = mosquitto_tls_set(object->client, NULL, ca_path, cert_path, key_path, NULL);
Expand Down

0 comments on commit 9a9bdb5

Please sign in to comment.