kopia lustrzana https://gitlab.com/sane-project/backends
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
rodzic
2ede166550
commit
093fff631c
|
@ -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>
|
||||
* doc/descriptions-external/epkowa.desc: update for iScan 2.26.0,
|
||||
from Alesh Slovak <alesh.slovak@avasys.jp>.
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
/* Please increase version number with every change
|
||||
(don't forget to update dll.desc) */
|
||||
#define DLL_VERSION "1.0.12"
|
||||
#define DLL_VERSION "1.0.13"
|
||||
|
||||
#ifdef _AIX
|
||||
# include "lalloca.h" /* MUST come first for AIX! */
|
||||
|
@ -773,14 +773,37 @@ read_dlld (void)
|
|||
DIR *dlld;
|
||||
struct dirent *dllconf;
|
||||
struct stat st;
|
||||
char conffile[PATH_MAX];
|
||||
char conffile[PATH_MAX], dlldir[PATH_MAX];
|
||||
size_t len, plen;
|
||||
const char *dir_list;
|
||||
char *copy, *next, *dir;
|
||||
|
||||
DBG (5, "sane_init/read_dlld: processing %s ...\n",
|
||||
STRINGIFY(PATH_SANE_CONFIG_DIR) "/dll.d");
|
||||
dir_list = sanei_config_get_paths ();
|
||||
if (!dir_list)
|
||||
{
|
||||
DBG(2, "sane_init/read_dlld: Unable to detect configuration directories\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read files under $sysconfdir/sane.d/dll.d */
|
||||
dlld = opendir (STRINGIFY(PATH_SANE_CONFIG_DIR) "/dll.d");
|
||||
copy = strdup (dir_list);
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -789,8 +812,6 @@ read_dlld (void)
|
|||
return;
|
||||
}
|
||||
|
||||
plen = strlen (STRINGIFY(PATH_SANE_CONFIG_DIR)) + 1;
|
||||
|
||||
while ((dllconf = readdir (dlld)) != NULL)
|
||||
{
|
||||
/* dotfile (or directory) */
|
||||
|
@ -804,8 +825,7 @@ read_dlld (void)
|
|||
|| (dllconf->d_name[len-1] == '#'))
|
||||
continue;
|
||||
|
||||
snprintf (conffile, PATH_MAX, "%s/dll.d/%s",
|
||||
STRINGIFY (PATH_SANE_CONFIG_DIR), dllconf->d_name);
|
||||
snprintf (conffile, PATH_MAX, "%s/%s", dlldir, dllconf->d_name);
|
||||
|
||||
DBG (5, "sane_init/read_dlld: considering %s\n", conffile);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
:backend "dll" ; name of backend
|
||||
:version "1.0.12"
|
||||
:version "1.0.13"
|
||||
:manpage "sane-dll"
|
||||
:url "mailto:henning@meier-geinitz.de"
|
||||
|
||||
|
|
|
@ -164,4 +164,12 @@ extern SANE_Status sanei_configure_attach (
|
|||
SANEI_Config *config,
|
||||
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 */
|
||||
|
|
|
@ -76,21 +76,25 @@
|
|||
#include <FindDirectory.h>
|
||||
#endif
|
||||
|
||||
static const char *dir_list;
|
||||
static char *dir_list;
|
||||
|
||||
FILE *
|
||||
sanei_config_open (const char *filename)
|
||||
const char *
|
||||
sanei_config_get_paths ()
|
||||
{
|
||||
char *copy, *next, *dir, result[PATH_MAX];
|
||||
FILE *fp = 0;
|
||||
#ifdef __BEOS__
|
||||
char result[PATH_MAX];
|
||||
#endif
|
||||
void *mem;
|
||||
char *dlist;
|
||||
size_t len;
|
||||
void *mem = 0;
|
||||
|
||||
if (!dir_list)
|
||||
{
|
||||
DBG_INIT();
|
||||
|
||||
dir_list = getenv ("SANE_CONFIG_DIR");
|
||||
dlist = getenv ("SANE_CONFIG_DIR");
|
||||
if (dlist)
|
||||
dir_list = strdup (dlist);
|
||||
#ifdef __BEOS__
|
||||
/* ~/config/settings/SANE takes precedence over /etc/sane.d/ */
|
||||
if (!dir_list)
|
||||
|
@ -99,7 +103,7 @@ sanei_config_open (const char *filename)
|
|||
{
|
||||
strcat(result,"/SANE");
|
||||
strcat(result,DIR_SEP); /* do append the default ones */
|
||||
dir_list = result;
|
||||
dir_list = strdup (result);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -110,20 +114,39 @@ sanei_config_open (const char *filename)
|
|||
{
|
||||
/* append default search directories: */
|
||||
mem = malloc (len + sizeof (DEFAULT_DIRS));
|
||||
|
||||
memcpy (mem, dir_list, len);
|
||||
memcpy ((char *) mem + len, DEFAULT_DIRS, sizeof (DEFAULT_DIRS));
|
||||
free (dir_list);
|
||||
dir_list = mem;
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
if (mem)
|
||||
free(mem);
|
||||
copy = strdup (cfg_dir_list);
|
||||
|
||||
for (next = copy; (dir = strsep (&next, DIR_SEP)) != 0; )
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue