static int authorizer(void *autharg, int access_type, const char *arg3, const char *arg4, const char *arg5, const char *arg6) { char *filename; switch (access_type) { case SQLITE_COPY: { filename = make_filename_safe(arg4); if (!filename) { return SQLITE_DENY; } efree(filename); return SQLITE_OK; } case SQLITE_ATTACH: { filename = make_filename_safe(arg3); if (!filename) { return SQLITE_DENY; } efree(filename); return SQLITE_OK; } default: /* access allowed */ return SQLITE_OK; } }
static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ */ { pdo_sqlite_db_handle *H; int i, ret = 0; zend_long timeout = 60, flags; char *filename; H = pecalloc(1, sizeof(pdo_sqlite_db_handle), dbh->is_persistent); H->einfo.errcode = 0; H->einfo.errmsg = NULL; dbh->driver_data = H; filename = make_filename_safe(dbh->data_source); if (!filename) { zend_throw_exception_ex(php_pdo_get_exception(), 0, "open_basedir prohibits opening %s", dbh->data_source); goto cleanup; } flags = pdo_attr_lval(driver_options, PDO_SQLITE_ATTR_OPEN_FLAGS, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); #if SQLITE_VERSION_NUMBER >= 3005000 i = sqlite3_open_v2(filename, &H->db, flags, NULL); #else i = sqlite3_open(filename, &H->db); #endif efree(filename); if (i != SQLITE_OK) { pdo_sqlite_error(dbh); goto cleanup; } if (PG(open_basedir) && *PG(open_basedir)) { sqlite3_set_authorizer(H->db, authorizer, NULL); } if (driver_options) { timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, timeout); } sqlite3_busy_timeout(H->db, timeout * 1000); dbh->alloc_own_columns = 1; dbh->max_escaped_char_length = 2; ret = 1; cleanup: dbh->methods = &sqlite_methods; return ret; }