mirror of https://github.com/OpenVPN/openvpn-gui
Remove the limit on number of config subdirectories
Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/298/head
parent
4cb55f1e58
commit
0702acf70c
|
@ -137,21 +137,19 @@ AddConfigFileToList(int config, const TCHAR *filename, const TCHAR *config_dir)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
BuildFileList0(const TCHAR *config_dir, bool warn_duplicates)
|
BuildFileList0(const TCHAR *config_dir, int recurse_depth, bool warn_duplicates)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA find_obj;
|
WIN32_FIND_DATA find_obj;
|
||||||
HANDLE find_handle;
|
HANDLE find_handle;
|
||||||
TCHAR find_string[MAX_PATH];
|
TCHAR find_string[MAX_PATH];
|
||||||
TCHAR subdir_table[MAX_CONFIG_SUBDIRS][MAX_PATH];
|
TCHAR subdir_name[MAX_PATH];
|
||||||
int subdirs = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
_sntprintf_0(find_string, _T("%s\\*"), config_dir);
|
_sntprintf_0(find_string, _T("%s\\*"), config_dir);
|
||||||
find_handle = FindFirstFile(find_string, &find_obj);
|
find_handle = FindFirstFile(find_string, &find_obj);
|
||||||
if (find_handle == INVALID_HANDLE_VALUE)
|
if (find_handle == INVALID_HANDLE_VALUE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Loop over each config file in main config dir */
|
/* Loop over each config file in config dir */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (o.num_configs >= MAX_CONFIGS)
|
if (o.num_configs >= MAX_CONFIGS)
|
||||||
|
@ -173,62 +171,41 @@ BuildFileList0(const TCHAR *config_dir, bool warn_duplicates)
|
||||||
if (CheckReadAccess (config_dir, find_obj.cFileName))
|
if (CheckReadAccess (config_dir, find_obj.cFileName))
|
||||||
AddConfigFileToList(o.num_configs++, find_obj.cFileName, config_dir);
|
AddConfigFileToList(o.num_configs++, find_obj.cFileName, config_dir);
|
||||||
}
|
}
|
||||||
else if (match_type == match_dir)
|
} while (FindNextFile(find_handle, &find_obj));
|
||||||
|
|
||||||
|
FindClose(find_handle);
|
||||||
|
|
||||||
|
/* optionally loop over each subdir */
|
||||||
|
if (recurse_depth <= 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
find_handle = FindFirstFile (find_string, &find_obj);
|
||||||
|
if (find_handle == INVALID_HANDLE_VALUE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
match_t match_type = match(&find_obj, o.ext_string);
|
||||||
|
if (match_type == match_dir)
|
||||||
{
|
{
|
||||||
if (_tcsncmp(find_obj.cFileName, _T("."), _tcslen(find_obj.cFileName)) != 0
|
if (wcscmp(find_obj.cFileName, _T("."))
|
||||||
&& _tcsncmp(find_obj.cFileName, _T(".."), _tcslen(find_obj.cFileName)) != 0
|
&& wcscmp(find_obj.cFileName, _T("..")))
|
||||||
&& subdirs < MAX_CONFIG_SUBDIRS)
|
|
||||||
{
|
{
|
||||||
/* Add dir to dir_table */
|
/* recurse into subdirectory */
|
||||||
_sntprintf_0(subdir_table[subdirs], _T("%s\\%s"), config_dir, find_obj.cFileName);
|
_sntprintf_0(subdir_name, _T("%s\\%s"), config_dir, find_obj.cFileName);
|
||||||
subdirs++;
|
BuildFileList0(subdir_name, recurse_depth - 1, warn_duplicates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (FindNextFile(find_handle, &find_obj));
|
} while (FindNextFile(find_handle, &find_obj));
|
||||||
|
|
||||||
FindClose(find_handle);
|
FindClose(find_handle);
|
||||||
|
|
||||||
/* Loop over each config file in every subdir */
|
|
||||||
for (i = 0; i < subdirs; ++i)
|
|
||||||
{
|
|
||||||
_sntprintf_0(find_string, _T("%s\\*"), subdir_table[i]);
|
|
||||||
|
|
||||||
find_handle = FindFirstFile (find_string, &find_obj);
|
|
||||||
if (find_handle == INVALID_HANDLE_VALUE)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (o.num_configs >= MAX_CONFIGS)
|
|
||||||
{
|
|
||||||
ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS);
|
|
||||||
FindClose(find_handle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* does file have the correct type and extension? */
|
|
||||||
if (match(&find_obj, o.ext_string) != match_file)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (ConfigAlreadyExists(find_obj.cFileName))
|
|
||||||
{
|
|
||||||
if (warn_duplicates)
|
|
||||||
ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckReadAccess (subdir_table[i], find_obj.cFileName))
|
|
||||||
AddConfigFileToList(o.num_configs++, find_obj.cFileName, subdir_table[i]);
|
|
||||||
} while (FindNextFile(find_handle, &find_obj));
|
|
||||||
|
|
||||||
FindClose(find_handle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BuildFileList()
|
BuildFileList()
|
||||||
{
|
{
|
||||||
static bool issue_warnings = true;
|
static bool issue_warnings = true;
|
||||||
|
int recurse_depth = 2; /* read config_dir and sub-directories */
|
||||||
|
|
||||||
if (o.silent_connection)
|
if (o.silent_connection)
|
||||||
issue_warnings = false;
|
issue_warnings = false;
|
||||||
|
@ -241,10 +218,10 @@ BuildFileList()
|
||||||
if (CountConnState(disconnected) == o.num_configs)
|
if (CountConnState(disconnected) == o.num_configs)
|
||||||
o.num_configs = 0;
|
o.num_configs = 0;
|
||||||
|
|
||||||
BuildFileList0 (o.config_dir, issue_warnings);
|
BuildFileList0 (o.config_dir, recurse_depth, issue_warnings);
|
||||||
|
|
||||||
if (_tcscmp (o.global_config_dir, o.config_dir))
|
if (_tcscmp (o.global_config_dir, o.config_dir))
|
||||||
BuildFileList0 (o.global_config_dir, issue_warnings);
|
BuildFileList0 (o.global_config_dir, recurse_depth, issue_warnings);
|
||||||
|
|
||||||
if (o.num_configs == 0 && issue_warnings)
|
if (o.num_configs == 0 && issue_warnings)
|
||||||
ShowLocalizedMsg(IDS_NFO_NO_CONFIGS, o.config_dir, o.global_config_dir);
|
ShowLocalizedMsg(IDS_NFO_NO_CONFIGS, o.config_dir, o.global_config_dir);
|
||||||
|
|
|
@ -40,8 +40,7 @@ typedef struct connection connection_t;
|
||||||
* Maximum number of parameters associated with an option,
|
* Maximum number of parameters associated with an option,
|
||||||
* including the option name itself.
|
* including the option name itself.
|
||||||
*/
|
*/
|
||||||
#define MAX_PARMS 5 /* May number of parameters per option */
|
#define MAX_PARMS 5 /* Max number of parameters per option */
|
||||||
#define MAX_CONFIG_SUBDIRS 50 /* Max number of subdirs to scan for configs */
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
Loading…
Reference in New Issue