| 324 | } |
| 325 | |
| 326 | static int sqlite_authorize(void *dbq_, int code, |
| 327 | const char *a, |
| 328 | const char *b, |
| 329 | const char *c, |
| 330 | const char *d) |
| 331 | { |
| 332 | struct db_query *dbq = dbq_; |
| 333 | |
| 334 | /* You can do select statements */ |
| 335 | if (code == SQLITE_SELECT) |
| 336 | return SQLITE_OK; |
| 337 | |
| 338 | /* You can do a column read: takes a table name, column name */ |
| 339 | if (code == SQLITE_READ) { |
| 340 | struct sql *sql = sql_of(dbq->cmd->plugin); |
| 341 | struct table_desc *td = strmap_get(&sql->tablemap, a); |
| 342 | struct column *col; |
| 343 | if (!td) { |
| 344 | dbq->authfail = tal_fmt(dbq, "Unknown table %s", a); |
| 345 | return SQLITE_DENY; |
| 346 | } |
| 347 | /* If it has a parent, we refresh that instead */ |
| 348 | while (td->parent) |
| 349 | td = td->parent; |
| 350 | if (!has_table_desc(dbq->tables, td)) |
| 351 | tal_arr_expand(&dbq->tables, td); |
| 352 | |
| 353 | /* Check column name, to control access to deprecated ones. */ |
| 354 | col = find_column(td, b); |
| 355 | if (!col) { |
| 356 | /* Magic column names like id, __id__ etc. */ |
| 357 | return SQLITE_OK; |
| 358 | } |
| 359 | |
| 360 | /* Don't do tal if we are not deprecated at all */ |
| 361 | if (!col->depr_start) |
| 362 | return SQLITE_OK; |
| 363 | |
| 364 | /* Can this command see this? We have to allow this |
| 365 | * (as null) with "SELECT *" though! */ |
| 366 | if (!command_deprecated_in_named_ok(dbq->cmd, td->cmdname, |
| 367 | col->jsonname, |
| 368 | col->depr_start, |
| 369 | col->depr_end)) { |
| 370 | if (dbq->has_wildcard) |
| 371 | return SQLITE_IGNORE; |
| 372 | dbq->authfail = tal_fmt(dbq, "Deprecated column table %s.%s", a, b); |
| 373 | return SQLITE_DENY; |
| 374 | } |
| 375 | |
| 376 | return SQLITE_OK; |
| 377 | } |
| 378 | |
| 379 | /* Some functions are fairly necessary: */ |
| 380 | if (code == SQLITE_FUNCTION) { |
| 381 | if (streq(b, "abs")) |
| 382 | return SQLITE_OK; |
| 383 | if (streq(b, "avg")) |
nothing calls this directly
no test coverage detected