|
cwist
Modern C web framework with libttak runtime
|
SQLite-to-socket bridge implementation. More...
#include <cwist/core/orm/orm_socket.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <fcntl.h>#include <pthread.h>#include <sys/socket.h>#include <sys/un.h>#include <arpa/inet.h>#include <stdint.h>#include <sqlite3.h>#include <cjson/cJSON.h>#include <cwist/core/mem/alloc.h>
Go to the source code of this file.
Macros | |
| #define | _GNU_SOURCE 1 |
| #define | ORM_PROTO_MAGIC 0x43574F52 /* "CWOR" in ASCII hex trickery */ |
| Magic value placed at the start of every response. | |
| #define | SOCK_CLOEXEC 0 |
Functions | |
| int | cwist_orm_socketpair_cloexec (int domain, int type, int protocol, int sv[2]) |
| int | cwist_db_transfer_sqlite_to_socket (const char *db_path) |
| Open a SQLite database behind an in-process SQL socket. | |
SQLite-to-socket bridge implementation.
This file is the only place in the ORM subsystem that directly links against SQLite3. It exposes the database as a byte stream over a local Unix socket pair so that cwist_orm_t remains fully decoupled from sqlite3.h.
Trust boundary: the worker executes whatever SQL text arrives on its end of the pair, verbatim. That is safe only because the pair is created with socketpair(AF_UNIX) in cwist_db_transfer_sqlite_to_socket(): it has no filesystem path or network address, so no other process can connect to it, and the only peer is the caller's end (normally a cwist_orm_t in the same process). Anyone holding that caller fd can run arbitrary SQL against the database, so it must never be handed to an untrusted party (SCM_RIGHTS, inheritance across fork() without exec, and so on). Escaping of untrusted values is the job of the layer that builds the SQL (orm.c), not of this bridge.
Definition in file orm_socket.c.
| #define _GNU_SOURCE 1 |
Definition at line 23 of file orm_socket.c.
Magic value placed at the start of every response.
Definition at line 48 of file orm_socket.c.
| #define SOCK_CLOEXEC 0 |
Definition at line 442 of file orm_socket.c.
Open a SQLite database behind an in-process SQL socket.
Creates an AF_UNIX socket pair and starts a detached worker thread that owns the SQLite connection on one end. The other end is returned to the caller, typically to be passed to cwist_orm_open_socket().
The worker executes every SQL request it receives on the returned fd as-is, with no escaping or filtering. Treat the fd as full access to the database: keep it inside the process and do not pass it to untrusted code or processes (for example over SCM_RIGHTS, or by fork() without exec). Both ends are close-on-exec.
| path | SQLite database path, or ":memory:". |
Definition at line 473 of file orm_socket.c.
References cap, and cwist_orm_socketpair_cloexec().
Definition at line 454 of file orm_socket.c.
References cap, and SOCK_CLOEXEC.
Referenced by cwist_db_transfer_sqlite_to_socket().