Fix SANE_CONFIG_DIR handling, use it for dll.d/; Add sanei_config_get_paths

* include/sane/sanei_config.h sanei/sanei_config.c: Add function
        sanei_config_get_paths to obtain all configuration pathes (from env var
        SANE_CONFIG_DIR and default paths); fix pointers to invalid/freed
        strings when SANE_CONFIG_DIR is set

* backend/dll.c: When searching for the dll.d/ directory, also use
        the SANE_CONFIG_DIR env variable.
merge-requests/1/head
Reinhold Kainhofer 2010-09-18 10:35:35 +02:00 zatwierdzone przez Julien BLACHE
rodzic 2ede166550
commit 093fff631c
5 zmienionych plików z 84 dodań i 25 usunięć

Wyświetl plik

@ -1,3 +1,11 @@
2010-09-18 Reinhold Kainhofer <reinhold@kainhofer.com>
* include/sane/sanei_config.h sanei/sanei_config.c: Add
function sanei_config_get_paths to obtain all configuration pathes
(from env var SANE_CONFIG_DIR and default paths); fix pointers to
invalid/freed strings when SANE_CONFIG_DIR is set.
* backend/dll.c: When searching for the dll.d/ directory,
also use the SANE_CONFIG_DIR env variable.
2010-07-12 Julien Blache <jb@jblache.org> 2010-07-12 Julien Blache <jb@jblache.org>
* doc/descriptions-external/epkowa.desc: update for iScan 2.26.0, * doc/descriptions-external/epkowa.desc: update for iScan 2.26.0,
from Alesh Slovak <alesh.slovak@avasys.jp>. from Alesh Slovak <alesh.slovak@avasys.jp>.

Wyświetl plik

@ -44,7 +44,7 @@
/* Please increase version number with every change /* Please increase version number with every change
(don't forget to update dll.desc) */ (don't forget to update dll.desc) */
#define DLL_VERSION "1.0.12" #define DLL_VERSION "1.0.13"
#ifdef _AIX #ifdef _AIX
# include "lalloca.h" /* MUST come first for AIX! */ # include "lalloca.h" /* MUST come first for AIX! */
@ -773,14 +773,37 @@ read_dlld (void)
DIR *dlld; DIR *dlld;
struct dirent *dllconf; struct dirent *dllconf;
struct stat st; struct stat st;
char conffile[PATH_MAX]; char conffile[PATH_MAX], dlldir[PATH_MAX];
size_t len, plen; size_t len, plen;
const char *dir_list;
char *copy, *next, *dir;
DBG (5, "sane_init/read_dlld: processing %s ...\n", dir_list = sanei_config_get_paths ();
STRINGIFY(PATH_SANE_CONFIG_DIR) "/dll.d"); if (!dir_list)
{
DBG(2, "sane_init/read_dlld: Unable to detect configuration directories\n");
return;
}
/* Read files under $sysconfdir/sane.d/dll.d */ copy = strdup (dir_list);
dlld = opendir (STRINGIFY(PATH_SANE_CONFIG_DIR) "/dll.d");
for (next = copy; (dir = strsep (&next, DIR_SEP)) != NULL;)
{
snprintf (dlldir, sizeof (dlldir), "%s%s", dir, "/dll.d");
DBG(4, "sane_init/read_dlld: attempting to open directory `%s'\n", dlldir);
dlld = opendir (dlldir);
if (dlld)
{
/* length of path to parent dir of dll.d/ */
plen = strlen (dir) + 1;
DBG(3, "sane_init/read_dlld: using config directory `%s'\n", dlldir);
break;
}
}
free (copy);
if (dlld == NULL) if (dlld == NULL)
{ {
@ -789,8 +812,6 @@ read_dlld (void)
return; return;
} }
plen = strlen (STRINGIFY(PATH_SANE_CONFIG_DIR)) + 1;
while ((dllconf = readdir (dlld)) != NULL) while ((dllconf = readdir (dlld)) != NULL)
{ {
/* dotfile (or directory) */ /* dotfile (or directory) */
@ -804,8 +825,7 @@ read_dlld (void)
|| (dllconf->d_name[len-1] == '#')) || (dllconf->d_name[len-1] == '#'))
continue; continue;
snprintf (conffile, PATH_MAX, "%s/dll.d/%s", snprintf (conffile, PATH_MAX, "%s/%s", dlldir, dllconf->d_name);
STRINGIFY (PATH_SANE_CONFIG_DIR), dllconf->d_name);
DBG (5, "sane_init/read_dlld: considering %s\n", conffile); DBG (5, "sane_init/read_dlld: considering %s\n", conffile);

Wyświetl plik

@ -1,5 +1,5 @@
:backend "dll" ; name of backend :backend "dll" ; name of backend
:version "1.0.12" :version "1.0.13"
:manpage "sane-dll" :manpage "sane-dll"
:url "mailto:henning@meier-geinitz.de" :url "mailto:henning@meier-geinitz.de"

Wyświetl plik

@ -164,4 +164,12 @@ extern SANE_Status sanei_configure_attach (
SANEI_Config *config, SANEI_Config *config,
SANE_Status (*config_attach)(SANEI_Config *config, const char *devname) SANE_Status (*config_attach)(SANEI_Config *config, const char *devname)
); );
/** Return the list of config directories, extracted from the SANE_CONFIG_DIR
* environment variable and the default paths.
* @return a string containing the configuration paths, separated by the
* operating system's path separator
*/
extern const char *sanei_config_get_paths (void);
#endif /* sanei_config_h */ #endif /* sanei_config_h */

Wyświetl plik

@ -76,21 +76,25 @@
#include <FindDirectory.h> #include <FindDirectory.h>
#endif #endif
static const char *dir_list; static char *dir_list;
FILE * const char *
sanei_config_open (const char *filename) sanei_config_get_paths ()
{ {
char *copy, *next, *dir, result[PATH_MAX]; #ifdef __BEOS__
FILE *fp = 0; char result[PATH_MAX];
#endif
void *mem;
char *dlist;
size_t len; size_t len;
void *mem = 0;
if (!dir_list) if (!dir_list)
{ {
DBG_INIT(); DBG_INIT();
dir_list = getenv ("SANE_CONFIG_DIR"); dlist = getenv ("SANE_CONFIG_DIR");
if (dlist)
dir_list = strdup (dlist);
#ifdef __BEOS__ #ifdef __BEOS__
/* ~/config/settings/SANE takes precedence over /etc/sane.d/ */ /* ~/config/settings/SANE takes precedence over /etc/sane.d/ */
if (!dir_list) if (!dir_list)
@ -99,7 +103,7 @@ sanei_config_open (const char *filename)
{ {
strcat(result,"/SANE"); strcat(result,"/SANE");
strcat(result,DIR_SEP); /* do append the default ones */ strcat(result,DIR_SEP); /* do append the default ones */
dir_list = result; dir_list = strdup (result);
} }
} }
#endif #endif
@ -110,20 +114,39 @@ sanei_config_open (const char *filename)
{ {
/* append default search directories: */ /* append default search directories: */
mem = malloc (len + sizeof (DEFAULT_DIRS)); mem = malloc (len + sizeof (DEFAULT_DIRS));
memcpy (mem, dir_list, len); memcpy (mem, dir_list, len);
memcpy ((char *) mem + len, DEFAULT_DIRS, sizeof (DEFAULT_DIRS)); memcpy ((char *) mem + len, DEFAULT_DIRS, sizeof (DEFAULT_DIRS));
free (dir_list);
dir_list = mem; dir_list = mem;
} }
} }
else else
dir_list = DEFAULT_DIRS; {
/* Create a copy, since we might call free on it */
dir_list = strdup (DEFAULT_DIRS);
}
}
DBG (5, "sanei_config_get_paths: using config directories %s\n", dir_list);
return dir_list;
}
FILE *
sanei_config_open (const char *filename)
{
char *next, *dir, result[PATH_MAX];
const char *cfg_dir_list;
FILE *fp;
char *copy;
cfg_dir_list = sanei_config_get_paths ();
if (!cfg_dir_list)
{
DBG(2, "sanei_config_open: could not find config file `%s'\n", filename);
return NULL;
} }
copy = strdup (dir_list); copy = strdup (cfg_dir_list);
if (mem)
free(mem);
for (next = copy; (dir = strsep (&next, DIR_SEP)) != 0; ) for (next = copy; (dir = strsep (&next, DIR_SEP)) != 0; )
{ {