#include <syslog.h>
#endif
-#ifdef HAVE_GLOB_H
-#include <glob.h>
-#endif
-
#include <math.h>
struct rspamd_rcl_default_handler_data {
{
struct stat st;
struct script_module *cur_mod;
- glob_t globbuf;
- gchar *pattern, *ext_pos;
- size_t len;
+ GPtrArray *paths;
+ gchar *fname, *ext_pos;
guint i;
if (stat (path, &st) == -1) {
/* Handle directory */
if (S_ISDIR (st.st_mode)) {
- globbuf.gl_offs = 0;
- len = strlen (path) + sizeof ("*.lua");
- pattern = g_malloc (len);
- rspamd_snprintf (pattern, len, "%s%s", path, "*.lua");
-
- if (glob (pattern, GLOB_DOOFFS, NULL, &globbuf) == 0) {
- for (i = 0; i < globbuf.gl_pathc; i++) {
- cur_mod =
+ paths = rspamd_glob_path (path, "*.lua", TRUE, err);
+
+ if (!paths) {
+ return FALSE;
+ }
+
+ PTR_ARRAY_FOREACH (paths, i, fname) {
+ cur_mod =
rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (struct script_module));
- cur_mod->path = rspamd_mempool_strdup (cfg->cfg_pool,
- globbuf.gl_pathv[i]);
- cur_mod->name = g_path_get_basename (cur_mod->path);
- rspamd_mempool_add_destructor (cfg->cfg_pool, g_free,
- cur_mod->name);
- ext_pos = strstr (cur_mod->name, ".lua");
-
- if (ext_pos != NULL) {
- *ext_pos = '\0';
- }
+ sizeof (struct script_module));
+ cur_mod->path = rspamd_mempool_strdup (cfg->cfg_pool, fname);
+ cur_mod->name = g_path_get_basename (cur_mod->path);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, g_free,
+ cur_mod->name);
+ ext_pos = strstr (cur_mod->name, ".lua");
+
+ if (ext_pos != NULL) {
+ *ext_pos = '\0';
+ }
- if (cfg->script_modules == NULL) {
- cfg->script_modules = g_list_append (cfg->script_modules,
- cur_mod);
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)g_list_free,
- cfg->script_modules);
- }
- else {
- cfg->script_modules = g_list_append (cfg->script_modules,
- cur_mod);
- }
+ if (cfg->script_modules == NULL) {
+ cfg->script_modules = g_list_append (cfg->script_modules,
+ cur_mod);
+ rspamd_mempool_add_destructor (cfg->cfg_pool,
+ (rspamd_mempool_destruct_t) g_list_free,
+ cfg->script_modules);
+ } else {
+ cfg->script_modules = g_list_append (cfg->script_modules,
+ cur_mod);
}
- globfree (&globbuf);
- g_free (pattern);
- }
- else {
- g_set_error (err,
- CFG_RCL_ERROR,
- errno,
- "glob failed for %s, %s",
- pattern,
- strerror (errno));
- g_free (pattern);
- return FALSE;
}
+
+ g_ptr_array_free (paths, TRUE);
}
else {
/* Handle single file */
#endif
#endif
#include <math.h> /* for pow */
-#include <glob.h>
+#include <glob.h> /* in fact, we require this file ultimately */
#include "cryptobox.h"
#include "zlib.h"
const gchar *path;
static gchar pathbuf[PATH_MAX]; /* Static to help recursion */
guint i;
+ gint rc;
static const guint rec_lim = 16;
struct stat st;
memset (&globbuf, 0, sizeof (globbuf));
- if (glob (full_path, 0, NULL, &globbuf) != 0) {
- g_set_error (err, g_quark_from_static_string ("glob"), errno,
- "glob %s failed: %s", full_path, strerror (errno));
- globfree (&globbuf);
+ if ((rc = glob (full_path, 0, NULL, &globbuf)) != 0) {
- return FALSE;
+ if (rc != GLOB_NOMATCH) {
+ g_set_error (err, g_quark_from_static_string ("glob"), errno,
+ "glob %s failed: %s", full_path, strerror (errno));
+ globfree (&globbuf);
+
+ return FALSE;
+ }
+ else {
+ globfree (&globbuf);
+
+ return TRUE;
+ }
}
for (i = 0; i < globbuf.gl_pathc; i ++) {