#include <arpa/inet.h>#include <errno.h>#include <net/if.h>#include <netdb.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <stdlib.h>#include <sys/param.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/uio.h>#include <sys/un.h>#include <time.h>#include <errmsg.h>#include <mysql.h>#include <mysqld_error.h>#include <atalk/adouble.h>#include <atalk/cnid_bdb_private.h>#include <atalk/cnid_mysql_private.h>#include <atalk/errchk.h>#include <atalk/globals.h>#include <atalk/logger.h>#include <atalk/unix.h>#include <atalk/util.h>#include <atalk/volume.h>Macros | |
| #define | CNID_MYSQL_HINT_RESERVE (1u << 28) |
| #define | CNID_MYSQL_MAX_HINT (UINT32_MAX - CNID_MYSQL_HINT_RESERVE) |
| #define | CNID_MYSQL_ADD_ATTEMPTS 16 |
| #define | CNID_MYSQL_RECONNECT_ATTEMPTS 2 |
Functions | |
| static bool | cnid_mysql_hint_usable (cnid_t hint) |
| Whether a CNID hint from AppleDouble/EA metadata is safe to bind. | |
| static int | init_prepared_stmt_lookup (CNID_mysql_private *db) |
| static int | init_prepared_stmt_add (CNID_mysql_private *db) |
| static int | init_prepared_stmt_put (CNID_mysql_private *db) |
| static int | init_prepared_stmt_get (CNID_mysql_private *db) |
| static int | init_prepared_stmt_delete (CNID_mysql_private *db) |
| static int | init_prepared_stmt_resolve (CNID_mysql_private *db) |
| static int | init_prepared_stmt_purge (CNID_mysql_private *db) |
| static int | init_prepared_stmt (CNID_mysql_private *db) |
| static void | close_prepared_stmt (CNID_mysql_private *db) |
| static void | cnid_mysql_set_errno (unsigned int mysql_error_code) |
| static int | cnid_mysql_drain_results (MYSQL *con) |
| Drain the remaining results of a multi-statement batch. | |
| static int | cnid_mysql_stmt_execute (CNID_mysql_private *db, MYSQL_STMT **stmtp) |
| static int | cnid_mysql_execute (MYSQL *con, const char *sql) |
| int | cnid_mysql_delete (struct _cnid_db *cdb, const cnid_t id) |
| void | cnid_mysql_close (struct _cnid_db *cdb) |
| int | cnid_mysql_update (struct _cnid_db *cdb, cnid_t id, const struct stat *st, cnid_t did, const char *name, size_t len) |
| cnid_t | cnid_mysql_lookup (struct _cnid_db *cdb, const struct stat *st, cnid_t did, const char *name, size_t len) |
| cnid_t | cnid_mysql_add (struct _cnid_db *cdb, const struct stat *st, cnid_t did, const char *name, size_t len, cnid_t hint) |
| cnid_t | cnid_mysql_get (struct _cnid_db *cdb, cnid_t did, const char *name, size_t len) |
| char * | cnid_mysql_resolve (struct _cnid_db *cdb, cnid_t *id, void *buffer, size_t len) |
| int | cnid_mysql_getstamp (struct _cnid_db *cdb, void *buffer, const size_t len) |
| int | cnid_mysql_find (struct _cnid_db *cdb, const char *name, size_t namelen, cnid_t scope_did, void *buffer, size_t buflen, bool *more_available) |
| Backend implementation of cnid_find() for the mysql backend. | |
| cnid_t | cnid_mysql_rebuild_add (struct _cnid_db *cdb, const struct stat *st, cnid_t did, const char *name, size_t len, cnid_t hint) |
| int | cnid_mysql_wipe (struct _cnid_db *cdb) |
| static struct _cnid_db * | cnid_mysql_new (struct vol *vol) |
| struct _cnid_db * | cnid_mysql_open (struct cnid_open_args *args) |
Variables | |
| static MYSQL_BIND | lookup_param [4] |
| static MYSQL_BIND | lookup_result [5] |
| static MYSQL_BIND | add_param [4] |
| static MYSQL_BIND | put_param [5] |
| static MYSQL_BIND | get_param [2] |
| static MYSQL_BIND | get_result [1] |
| static MYSQL_BIND | delete_param [1] |
| static MYSQL_BIND | resolve_param [1] |
| static MYSQL_BIND | resolve_result [2] |
| static MYSQL_BIND | purge_param [5] |
| static char | stmt_param_name [MAXPATHLEN] |
| static unsigned long | stmt_param_name_len |
| static unsigned long long | stmt_param_id |
| static unsigned long long | stmt_param_did |
| static unsigned long long | stmt_param_dev |
| static unsigned long long | stmt_param_ino |
| static unsigned long long | lookup_result_id |
| static unsigned long long | lookup_result_did |
| static char | lookup_result_name [MAXPATHLEN] |
| static unsigned long | lookup_result_name_len |
| static unsigned long long | lookup_result_dev |
| static unsigned long long | lookup_result_ino |
| static unsigned long long | get_result_id |
| static unsigned long long | resolve_result_did |
| static char | resolve_result_name [MAXPATHLEN] |
| static unsigned long | resolve_result_name_len |
| struct _cnid_module | cnid_mysql_module |
| #define CNID_MYSQL_ADD_ATTEMPTS 16 |
| #define CNID_MYSQL_HINT_RESERVE (1u << 28) |
| #define CNID_MYSQL_MAX_HINT (UINT32_MAX - CNID_MYSQL_HINT_RESERVE) |
| #define CNID_MYSQL_RECONNECT_ATTEMPTS 2 |
|
static |
NULL-safe and NULLs each handle: a failed recovery leaves a mix of closed and live handles, and a later close or re-init must neither double-close nor leak the survivors.
| cnid_t cnid_mysql_add | ( | struct _cnid_db * | cdb, |
| const struct stat * | st, | ||
| cnid_t | did, | ||
| const char * | name, | ||
| size_t | len, | ||
| cnid_t | hint ) |
| void cnid_mysql_close | ( | struct _cnid_db * | cdb | ) |
|
static |
Drain the remaining results of a multi-statement batch.
cnid_mysql_execute() reports only the batch's first statement. mysql_next_result() returns >0 when a later one failed, which a plain "== 0" loop reads as the end of the batch — so a wipe whose TRUNCATE or ALTER failed would be taken for a completed one.
|
static |
| int cnid_mysql_find | ( | struct _cnid_db * | cdb, |
| const char * | name, | ||
| size_t | namelen, | ||
| cnid_t | scope_did, | ||
| void * | buffer, | ||
| size_t | buflen, | ||
| bool * | more_available ) |
Backend implementation of cnid_find() for the mysql backend.
Parameters are pre-validated by the libatalk/cnid/cnid.c wrapper, so cdb, name, namelen and buflen are all sane on entry. Detects truncation by building "LIMIT max_results + 1" into the SQL and observing whether the extra row was produced; reports it via more_available.
The Name LIKE parameter is bound via mysql_stmt_bind_param, never inlined into the SQL string, to prevent a filename SQL-injection vector. The LIMIT literal is not user-controlled (derived from caller's buflen) and is safely interpolated into the SQL string.
| int cnid_mysql_getstamp | ( | struct _cnid_db * | cdb, |
| void * | buffer, | ||
| const size_t | len ) |
Caller passes buffer where we will store the db stamp
|
static |
Whether a CNID hint from AppleDouble/EA metadata is safe to bind.
Rejects the reserved range below CNID_START and anything above CNID_MYSQL_MAX_HINT, which as an explicit Id would raise the AUTO_INCREMENT high-water mark towards the depletion reset.
| cnid_t cnid_mysql_lookup | ( | struct _cnid_db * | cdb, |
| const struct stat * | st, | ||
| cnid_t | did, | ||
| const char * | name, | ||
| size_t | len ) |
| struct _cnid_db * cnid_mysql_open | ( | struct cnid_open_args * | args | ) |
| cnid_t cnid_mysql_rebuild_add | ( | struct _cnid_db * | cdb, |
| const struct stat * | st, | ||
| cnid_t | did, | ||
| const char * | name, | ||
| size_t | len, | ||
| cnid_t | hint ) |
|
static |
|
static |
stmtp must point at the handle field in CNID_mysql_private: CR_SERVER_LOST recovery reallocates every handle, and the retry must execute the fresh one. Recovery also invalidates any other statement's in-flight stored result.
| int cnid_mysql_update | ( | struct _cnid_db * | cdb, |
| cnid_t | id, | ||
| const struct stat * | st, | ||
| cnid_t | did, | ||
| const char * | name, | ||
| size_t | len ) |
| int cnid_mysql_wipe | ( | struct _cnid_db * | cdb | ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| struct _cnid_module cnid_mysql_module |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
lookup result parameters
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Prepared statement parameters
|
static |