Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dynamic_cfg.c 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * Copyright 2023 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "config.h"
  17. #include "rspamd.h"
  18. #include "libserver/maps/map.h"
  19. #include "scan_result.h"
  20. #include "dynamic_cfg.h"
  21. #include "unix-std.h"
  22. #include "lua/lua_common.h"
  23. #include <math.h>
  24. struct config_json_buf {
  25. GString *buf;
  26. struct rspamd_config *cfg;
  27. };
  28. /**
  29. * Apply configuration to the specified configuration
  30. * @param conf_metrics
  31. * @param cfg
  32. */
  33. static void
  34. apply_dynamic_conf(const ucl_object_t *top, struct rspamd_config *cfg)
  35. {
  36. enum rspamd_action_type test_act;
  37. const ucl_object_t *cur_elt, *cur_nm, *it_val;
  38. ucl_object_iter_t it = NULL;
  39. const char *name;
  40. double nscore;
  41. static const unsigned int priority = 3;
  42. while ((cur_elt = ucl_object_iterate(top, &it, true))) {
  43. if (ucl_object_type(cur_elt) != UCL_OBJECT) {
  44. msg_err("loaded json array element is not an object");
  45. continue;
  46. }
  47. cur_nm = ucl_object_lookup(cur_elt, "metric");
  48. if (!cur_nm || ucl_object_type(cur_nm) != UCL_STRING) {
  49. msg_err(
  50. "loaded json metric object element has no 'metric' attribute");
  51. continue;
  52. }
  53. cur_nm = ucl_object_lookup(cur_elt, "symbols");
  54. /* Parse symbols */
  55. if (cur_nm && ucl_object_type(cur_nm) == UCL_ARRAY) {
  56. ucl_object_iter_t nit = NULL;
  57. while ((it_val = ucl_object_iterate(cur_nm, &nit, true))) {
  58. if (ucl_object_lookup(it_val, "name") &&
  59. ucl_object_lookup(it_val, "value")) {
  60. const ucl_object_t *n =
  61. ucl_object_lookup(it_val, "name");
  62. const ucl_object_t *v =
  63. ucl_object_lookup(it_val, "value");
  64. nscore = ucl_object_todouble(v);
  65. /*
  66. * We use priority = 3 here
  67. */
  68. rspamd_config_add_symbol(cfg,
  69. ucl_object_tostring(n), nscore, NULL, NULL,
  70. 0, priority, cfg->default_max_shots);
  71. }
  72. else {
  73. msg_info(
  74. "json symbol object has no mandatory 'name' and 'value' attributes");
  75. }
  76. }
  77. }
  78. else {
  79. ucl_object_t *arr;
  80. arr = ucl_object_typed_new(UCL_ARRAY);
  81. ucl_object_insert_key((ucl_object_t *) cur_elt, arr, "symbols",
  82. sizeof("symbols") - 1, false);
  83. }
  84. cur_nm = ucl_object_lookup(cur_elt, "actions");
  85. /* Parse actions */
  86. if (cur_nm && ucl_object_type(cur_nm) == UCL_ARRAY) {
  87. ucl_object_iter_t nit = NULL;
  88. while ((it_val = ucl_object_iterate(cur_nm, &nit, true))) {
  89. const ucl_object_t *n = ucl_object_lookup(it_val, "name");
  90. const ucl_object_t *v = ucl_object_lookup(it_val, "value");
  91. if (n != NULL && v != NULL) {
  92. name = ucl_object_tostring(n);
  93. if (!name || !rspamd_action_from_str(name, &test_act)) {
  94. msg_err("unknown action: %s",
  95. ucl_object_tostring(ucl_object_lookup(it_val,
  96. "name")));
  97. continue;
  98. }
  99. if (ucl_object_type(v) == UCL_NULL) {
  100. nscore = NAN;
  101. }
  102. else {
  103. nscore = ucl_object_todouble(v);
  104. }
  105. ucl_object_t *obj_tbl = ucl_object_typed_new(UCL_OBJECT);
  106. ucl_object_insert_key(obj_tbl, ucl_object_fromdouble(nscore),
  107. "score", 0, false);
  108. ucl_object_insert_key(obj_tbl, ucl_object_fromdouble(priority),
  109. "priority", 0, false);
  110. rspamd_config_set_action_score(cfg, name, obj_tbl);
  111. ucl_object_unref(obj_tbl);
  112. }
  113. else {
  114. msg_info(
  115. "json action object has no mandatory 'name' and 'value' attributes");
  116. }
  117. }
  118. }
  119. else {
  120. ucl_object_t *arr;
  121. arr = ucl_object_typed_new(UCL_ARRAY);
  122. ucl_object_insert_key((ucl_object_t *) cur_elt, arr, "actions",
  123. sizeof("actions") - 1, false);
  124. }
  125. }
  126. }
  127. /* Callbacks for reading json dynamic rules */
  128. static char *
  129. json_config_read_cb(char *chunk,
  130. int len,
  131. struct map_cb_data *data,
  132. gboolean final)
  133. {
  134. struct config_json_buf *jb, *pd;
  135. pd = data->prev_data;
  136. g_assert(pd != NULL);
  137. if (data->cur_data == NULL) {
  138. jb = g_malloc0(sizeof(*jb));
  139. jb->cfg = pd->cfg;
  140. data->cur_data = jb;
  141. }
  142. else {
  143. jb = data->cur_data;
  144. }
  145. if (jb->buf == NULL) {
  146. /* Allocate memory for buffer */
  147. jb->buf = g_string_sized_new(MAX(len, BUFSIZ));
  148. }
  149. g_string_append_len(jb->buf, chunk, len);
  150. return NULL;
  151. }
  152. static void
  153. json_config_fin_cb(struct map_cb_data *data, void **target)
  154. {
  155. struct config_json_buf *jb;
  156. ucl_object_t *top;
  157. struct ucl_parser *parser;
  158. /* Now parse json */
  159. if (data->cur_data) {
  160. jb = data->cur_data;
  161. }
  162. else {
  163. return;
  164. }
  165. if (jb->buf == NULL) {
  166. msg_err("no data read");
  167. return;
  168. }
  169. parser = ucl_parser_new(0);
  170. if (!ucl_parser_add_chunk(parser, jb->buf->str, jb->buf->len)) {
  171. msg_err("cannot load json data: parse error %s",
  172. ucl_parser_get_error(parser));
  173. ucl_parser_free(parser);
  174. return;
  175. }
  176. top = ucl_parser_get_object(parser);
  177. ucl_parser_free(parser);
  178. if (ucl_object_type(top) != UCL_ARRAY) {
  179. ucl_object_unref(top);
  180. msg_err("loaded json is not an array");
  181. return;
  182. }
  183. ucl_object_unref(jb->cfg->current_dynamic_conf);
  184. apply_dynamic_conf(top, jb->cfg);
  185. jb->cfg->current_dynamic_conf = top;
  186. if (target) {
  187. *target = data->cur_data;
  188. }
  189. if (data->prev_data) {
  190. jb = data->prev_data;
  191. /* Clean prev data */
  192. if (jb->buf) {
  193. g_string_free(jb->buf, TRUE);
  194. }
  195. g_free(jb);
  196. }
  197. }
  198. static void
  199. json_config_dtor_cb(struct map_cb_data *data)
  200. {
  201. struct config_json_buf *jb;
  202. if (data->cur_data) {
  203. jb = data->cur_data;
  204. /* Clean prev data */
  205. if (jb->buf) {
  206. g_string_free(jb->buf, TRUE);
  207. }
  208. if (jb->cfg && jb->cfg->current_dynamic_conf) {
  209. ucl_object_unref(jb->cfg->current_dynamic_conf);
  210. }
  211. g_free(jb);
  212. }
  213. }
  214. /**
  215. * Init dynamic configuration using map logic and specific configuration
  216. * @param cfg config file
  217. */
  218. void init_dynamic_config(struct rspamd_config *cfg)
  219. {
  220. struct config_json_buf *jb, **pjb;
  221. if (cfg->dynamic_conf == NULL) {
  222. /* No dynamic conf has been specified, so do not try to load it */
  223. return;
  224. }
  225. /* Now try to add map with json data */
  226. jb = g_malloc(sizeof(struct config_json_buf));
  227. pjb = g_malloc(sizeof(struct config_json_buf *));
  228. jb->buf = NULL;
  229. jb->cfg = cfg;
  230. *pjb = jb;
  231. cfg->current_dynamic_conf = ucl_object_typed_new(UCL_ARRAY);
  232. rspamd_mempool_add_destructor(cfg->cfg_pool,
  233. (rspamd_mempool_destruct_t) g_free,
  234. pjb);
  235. if (!rspamd_map_add(cfg,
  236. cfg->dynamic_conf,
  237. "Dynamic configuration map",
  238. json_config_read_cb,
  239. json_config_fin_cb,
  240. json_config_dtor_cb,
  241. (void **) pjb, NULL, RSPAMD_MAP_DEFAULT)) {
  242. msg_err("cannot add map for configuration %s", cfg->dynamic_conf);
  243. }
  244. }
  245. /**
  246. * Dump dynamic configuration to the disk
  247. * @param cfg
  248. * @return
  249. */
  250. gboolean
  251. dump_dynamic_config(struct rspamd_config *cfg)
  252. {
  253. struct stat st;
  254. char *dir, pathbuf[PATH_MAX];
  255. int fd;
  256. if (cfg->dynamic_conf == NULL || cfg->current_dynamic_conf == NULL) {
  257. /* No dynamic conf has been specified, so do not try to dump it */
  258. msg_err("cannot save dynamic conf as it is not specified");
  259. return FALSE;
  260. }
  261. dir = g_path_get_dirname(cfg->dynamic_conf);
  262. if (dir == NULL) {
  263. msg_err("invalid path: %s", cfg->dynamic_conf);
  264. return FALSE;
  265. }
  266. if (stat(cfg->dynamic_conf, &st) == -1) {
  267. msg_debug("%s is unavailable: %s", cfg->dynamic_conf,
  268. strerror(errno));
  269. st.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  270. }
  271. if (access(dir, W_OK | R_OK) == -1) {
  272. msg_warn("%s is inaccessible: %s", dir, strerror(errno));
  273. g_free(dir);
  274. return FALSE;
  275. }
  276. rspamd_snprintf(pathbuf,
  277. sizeof(pathbuf),
  278. "%s%crconf-XXXXXX",
  279. dir,
  280. G_DIR_SEPARATOR);
  281. g_free(dir);
  282. #ifdef HAVE_MKSTEMP
  283. /* Umask is set before */
  284. fd = mkstemp(pathbuf);
  285. #else
  286. fd = g_mkstemp_full(pathbuf, O_RDWR, S_IWUSR | S_IRUSR);
  287. #endif
  288. if (fd == -1) {
  289. msg_err("mkstemp error: %s", strerror(errno));
  290. return FALSE;
  291. }
  292. struct ucl_emitter_functions *emitter_functions;
  293. FILE *fp;
  294. fp = fdopen(fd, "w");
  295. emitter_functions = ucl_object_emit_file_funcs(fp);
  296. if (!ucl_object_emit_full(cfg->current_dynamic_conf, UCL_EMIT_JSON,
  297. emitter_functions, NULL)) {
  298. msg_err("cannot emit ucl object: %s", strerror(errno));
  299. ucl_object_emit_funcs_free(emitter_functions);
  300. fclose(fp);
  301. return FALSE;
  302. }
  303. (void) unlink(cfg->dynamic_conf);
  304. /* Rename old config */
  305. if (rename(pathbuf, cfg->dynamic_conf) == -1) {
  306. msg_err("rename error: %s", strerror(errno));
  307. fclose(fp);
  308. ucl_object_emit_funcs_free(emitter_functions);
  309. unlink(pathbuf);
  310. return FALSE;
  311. }
  312. /* Set permissions */
  313. if (chmod(cfg->dynamic_conf, st.st_mode) == -1) {
  314. msg_warn("chmod failed: %s", strerror(errno));
  315. }
  316. fclose(fp);
  317. ucl_object_emit_funcs_free(emitter_functions);
  318. return TRUE;
  319. }
  320. static ucl_object_t *
  321. new_dynamic_metric(const char *metric_name, ucl_object_t *top)
  322. {
  323. ucl_object_t *metric;
  324. metric = ucl_object_typed_new(UCL_OBJECT);
  325. ucl_object_insert_key(metric, ucl_object_fromstring(metric_name),
  326. "metric", sizeof("metric") - 1, true);
  327. ucl_object_insert_key(metric, ucl_object_typed_new(UCL_ARRAY),
  328. "actions", sizeof("actions") - 1, false);
  329. ucl_object_insert_key(metric, ucl_object_typed_new(UCL_ARRAY),
  330. "symbols", sizeof("symbols") - 1, false);
  331. ucl_array_append(top, metric);
  332. return metric;
  333. }
  334. static ucl_object_t *
  335. dynamic_metric_find_elt(const ucl_object_t *arr, const char *name)
  336. {
  337. ucl_object_iter_t it = NULL;
  338. const ucl_object_t *cur, *n;
  339. it = ucl_object_iterate_new(arr);
  340. while ((cur = ucl_object_iterate_safe(it, true)) != NULL) {
  341. if (cur->type == UCL_OBJECT) {
  342. n = ucl_object_lookup(cur, "name");
  343. if (n && n->type == UCL_STRING &&
  344. strcmp(name, ucl_object_tostring(n)) == 0) {
  345. ucl_object_iterate_free(it);
  346. return (ucl_object_t *) ucl_object_lookup(cur, "value");
  347. }
  348. }
  349. }
  350. ucl_object_iterate_free(it);
  351. return NULL;
  352. }
  353. static ucl_object_t *
  354. dynamic_metric_find_metric(const ucl_object_t *arr, const char *metric)
  355. {
  356. ucl_object_iter_t it = NULL;
  357. const ucl_object_t *cur, *n;
  358. it = ucl_object_iterate_new(arr);
  359. while ((cur = ucl_object_iterate_safe(it, true)) != NULL) {
  360. if (cur->type == UCL_OBJECT) {
  361. n = ucl_object_lookup(cur, "metric");
  362. if (n && n->type == UCL_STRING &&
  363. strcmp(metric, ucl_object_tostring(n)) == 0) {
  364. ucl_object_iterate_free(it);
  365. return (ucl_object_t *) cur;
  366. }
  367. }
  368. }
  369. ucl_object_iterate_free(it);
  370. return NULL;
  371. }
  372. static ucl_object_t *
  373. new_dynamic_elt(ucl_object_t *arr, const char *name, double value)
  374. {
  375. ucl_object_t *n;
  376. n = ucl_object_typed_new(UCL_OBJECT);
  377. ucl_object_insert_key(n, ucl_object_fromstring(name), "name",
  378. sizeof("name") - 1, false);
  379. ucl_object_insert_key(n, ucl_object_fromdouble(value), "value",
  380. sizeof("value") - 1, false);
  381. ucl_array_append(arr, n);
  382. return n;
  383. }
  384. static int
  385. rspamd_maybe_add_lua_dynsym(struct rspamd_config *cfg,
  386. const char *sym,
  387. double score)
  388. {
  389. lua_State *L = cfg->lua_state;
  390. int ret = -1;
  391. struct rspamd_config **pcfg;
  392. lua_getglobal(L, "rspamd_plugins");
  393. if (lua_type(L, -1) == LUA_TTABLE) {
  394. lua_pushstring(L, "dynamic_conf");
  395. lua_gettable(L, -2);
  396. if (lua_type(L, -1) == LUA_TTABLE) {
  397. lua_pushstring(L, "add_symbol");
  398. lua_gettable(L, -2);
  399. if (lua_type(L, -1) == LUA_TFUNCTION) {
  400. pcfg = lua_newuserdata(L, sizeof(*pcfg));
  401. *pcfg = cfg;
  402. rspamd_lua_setclass(L, rspamd_config_classname, -1);
  403. lua_pushstring(L, sym);
  404. lua_pushnumber(L, score);
  405. if (lua_pcall(L, 3, 1, 0) != 0) {
  406. msg_err_config("cannot execute add_symbol script: %s",
  407. lua_tostring(L, -1));
  408. }
  409. else {
  410. ret = lua_toboolean(L, -1);
  411. }
  412. lua_pop(L, 1);
  413. }
  414. else {
  415. lua_pop(L, 1);
  416. }
  417. }
  418. lua_pop(L, 1);
  419. }
  420. lua_pop(L, 1);
  421. return ret;
  422. }
  423. static int
  424. rspamd_maybe_add_lua_dynact(struct rspamd_config *cfg,
  425. const char *action,
  426. double score)
  427. {
  428. lua_State *L = cfg->lua_state;
  429. int ret = -1;
  430. struct rspamd_config **pcfg;
  431. lua_getglobal(L, "rspamd_plugins");
  432. if (lua_type(L, -1) == LUA_TTABLE) {
  433. lua_pushstring(L, "dynamic_conf");
  434. lua_gettable(L, -2);
  435. if (lua_type(L, -1) == LUA_TTABLE) {
  436. lua_pushstring(L, "add_action");
  437. lua_gettable(L, -2);
  438. if (lua_type(L, -1) == LUA_TFUNCTION) {
  439. pcfg = lua_newuserdata(L, sizeof(*pcfg));
  440. *pcfg = cfg;
  441. rspamd_lua_setclass(L, rspamd_config_classname, -1);
  442. lua_pushstring(L, action);
  443. lua_pushnumber(L, score);
  444. if (lua_pcall(L, 3, 1, 0) != 0) {
  445. msg_err_config("cannot execute add_action script: %s",
  446. lua_tostring(L, -1));
  447. }
  448. else {
  449. ret = lua_toboolean(L, -1);
  450. }
  451. lua_pop(L, 1);
  452. }
  453. else {
  454. lua_pop(L, 1);
  455. }
  456. }
  457. lua_pop(L, 1);
  458. }
  459. lua_pop(L, 1);
  460. return ret;
  461. }
  462. /**
  463. * Add symbol for specified metric
  464. * @param cfg config file object
  465. * @param metric metric's name
  466. * @param symbol symbol's name
  467. * @param value value of symbol
  468. * @return
  469. */
  470. gboolean
  471. add_dynamic_symbol(struct rspamd_config *cfg,
  472. const char *metric_name,
  473. const char *symbol,
  474. double value)
  475. {
  476. ucl_object_t *metric, *syms;
  477. int ret;
  478. if ((ret = rspamd_maybe_add_lua_dynsym(cfg, symbol, value)) != -1) {
  479. return ret == 0 ? FALSE : TRUE;
  480. }
  481. if (cfg->dynamic_conf == NULL) {
  482. msg_info("dynamic conf is disabled");
  483. return FALSE;
  484. }
  485. metric = dynamic_metric_find_metric(cfg->current_dynamic_conf,
  486. metric_name);
  487. if (metric == NULL) {
  488. metric = new_dynamic_metric(metric_name, cfg->current_dynamic_conf);
  489. }
  490. syms = (ucl_object_t *) ucl_object_lookup(metric, "symbols");
  491. if (syms != NULL) {
  492. ucl_object_t *sym;
  493. sym = dynamic_metric_find_elt(syms, symbol);
  494. if (sym) {
  495. sym->value.dv = value;
  496. }
  497. else {
  498. new_dynamic_elt(syms, symbol, value);
  499. }
  500. }
  501. apply_dynamic_conf(cfg->current_dynamic_conf, cfg);
  502. return TRUE;
  503. }
  504. gboolean
  505. remove_dynamic_symbol(struct rspamd_config *cfg,
  506. const char *metric_name,
  507. const char *symbol)
  508. {
  509. ucl_object_t *metric, *syms;
  510. gboolean ret = FALSE;
  511. if (cfg->dynamic_conf == NULL) {
  512. msg_info("dynamic conf is disabled");
  513. return FALSE;
  514. }
  515. metric = dynamic_metric_find_metric(cfg->current_dynamic_conf,
  516. metric_name);
  517. if (metric == NULL) {
  518. return FALSE;
  519. }
  520. syms = (ucl_object_t *) ucl_object_lookup(metric, "symbols");
  521. if (syms != NULL) {
  522. ucl_object_t *sym;
  523. sym = dynamic_metric_find_elt(syms, symbol);
  524. if (sym) {
  525. ret = ucl_array_delete((ucl_object_t *) syms, sym) != NULL;
  526. if (ret) {
  527. ucl_object_unref(sym);
  528. }
  529. }
  530. }
  531. if (ret) {
  532. apply_dynamic_conf(cfg->current_dynamic_conf, cfg);
  533. }
  534. return ret;
  535. }
  536. /**
  537. * Add action for specified metric
  538. * @param cfg config file object
  539. * @param metric metric's name
  540. * @param action action's name
  541. * @param value value of symbol
  542. * @return
  543. */
  544. gboolean
  545. add_dynamic_action(struct rspamd_config *cfg,
  546. const char *metric_name,
  547. unsigned int action,
  548. double value)
  549. {
  550. ucl_object_t *metric, *acts;
  551. const char *action_name = rspamd_action_to_str(action);
  552. int ret;
  553. if ((ret = rspamd_maybe_add_lua_dynact(cfg, action_name, value)) != -1) {
  554. return ret == 0 ? FALSE : TRUE;
  555. }
  556. if (cfg->dynamic_conf == NULL) {
  557. msg_info("dynamic conf is disabled");
  558. return FALSE;
  559. }
  560. metric = dynamic_metric_find_metric(cfg->current_dynamic_conf,
  561. metric_name);
  562. if (metric == NULL) {
  563. metric = new_dynamic_metric(metric_name, cfg->current_dynamic_conf);
  564. }
  565. acts = (ucl_object_t *) ucl_object_lookup(metric, "actions");
  566. if (acts != NULL) {
  567. ucl_object_t *act;
  568. act = dynamic_metric_find_elt(acts, action_name);
  569. if (act) {
  570. act->value.dv = value;
  571. }
  572. else {
  573. new_dynamic_elt(acts, action_name, value);
  574. }
  575. }
  576. apply_dynamic_conf(cfg->current_dynamic_conf, cfg);
  577. return TRUE;
  578. }
  579. gboolean
  580. remove_dynamic_action(struct rspamd_config *cfg,
  581. const char *metric_name,
  582. unsigned int action)
  583. {
  584. ucl_object_t *metric, *acts;
  585. const char *action_name = rspamd_action_to_str(action);
  586. gboolean ret = FALSE;
  587. if (cfg->dynamic_conf == NULL) {
  588. msg_info("dynamic conf is disabled");
  589. return FALSE;
  590. }
  591. metric = dynamic_metric_find_metric(cfg->current_dynamic_conf,
  592. metric_name);
  593. if (metric == NULL) {
  594. return FALSE;
  595. }
  596. acts = (ucl_object_t *) ucl_object_lookup(metric, "actions");
  597. if (acts != NULL) {
  598. ucl_object_t *act;
  599. act = dynamic_metric_find_elt(acts, action_name);
  600. if (act) {
  601. ret = ucl_array_delete(acts, act) != NULL;
  602. }
  603. if (ret) {
  604. ucl_object_unref(act);
  605. }
  606. }
  607. if (ret) {
  608. apply_dynamic_conf(cfg->current_dynamic_conf, cfg);
  609. }
  610. return ret;
  611. }