2008-12-18 11:08:35 +00:00
|
|
|
/*
|
|
|
|
* OpenVPN-GUI -- A Windows GUI for OpenVPN.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Mathias Sundman <mathias@nilings.se>
|
2010-03-21 20:28:35 +00:00
|
|
|
* 2010 Heiko Hund <heikoh@users.sf.net>
|
2016-07-09 19:14:36 +00:00
|
|
|
* 2016 Selva Nair <selva.nair@gmail.com>
|
2008-12-18 11:08:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program (see the file COPYING included with this
|
|
|
|
* distribution); if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2012-03-28 10:34:47 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2008-12-18 11:08:35 +00:00
|
|
|
#include <windows.h>
|
2010-03-11 21:58:45 +00:00
|
|
|
|
2008-12-18 11:08:35 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "openvpn-gui-res.h"
|
|
|
|
#include "options.h"
|
2009-01-19 12:28:26 +00:00
|
|
|
#include "localization.h"
|
2016-03-21 12:43:41 +00:00
|
|
|
#include "save_pass.h"
|
2016-07-06 17:38:27 +00:00
|
|
|
#include "misc.h"
|
|
|
|
#include "passphrase.h"
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
match_false,
|
|
|
|
match_file,
|
|
|
|
match_dir
|
|
|
|
} match_t;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-04-09 04:01:30 +00:00
|
|
|
extern options_t o;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
static match_t
|
|
|
|
match(const WIN32_FIND_DATA *find, const TCHAR *ext)
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2010-03-21 20:28:35 +00:00
|
|
|
size_t ext_len = _tcslen(ext);
|
|
|
|
int i;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
if (find->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
return match_dir;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
if (ext_len == 0)
|
|
|
|
return match_file;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
i = _tcslen(find->cFileName) - ext_len - 1;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
if (i > 0 && find->cFileName[i] == '.'
|
|
|
|
&& _tcsicmp(find->cFileName + i + 1, ext) == 0)
|
|
|
|
return match_file;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
return match_false;
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2016-02-14 03:44:52 +00:00
|
|
|
static bool
|
2016-05-14 03:34:53 +00:00
|
|
|
CheckReadAccess (const TCHAR *dir, const TCHAR *file)
|
2016-02-14 03:44:52 +00:00
|
|
|
{
|
2016-05-14 03:34:53 +00:00
|
|
|
TCHAR path[MAX_PATH];
|
|
|
|
|
2021-10-24 01:57:11 +00:00
|
|
|
_sntprintf_0 (path, _T("%ls\\%ls"), dir, file);
|
2016-02-14 03:44:52 +00:00
|
|
|
|
2016-07-06 17:38:27 +00:00
|
|
|
return CheckFileAccess (path, GENERIC_READ);
|
2016-02-14 03:44:52 +00:00
|
|
|
}
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
static int
|
|
|
|
ConfigAlreadyExists(TCHAR *newconfig)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < o.num_configs; ++i)
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2010-04-09 04:01:30 +00:00
|
|
|
if (_tcsicmp(o.conn[i].config_file, newconfig) == 0)
|
2010-03-21 20:28:35 +00:00
|
|
|
return true;
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|
2010-03-21 20:28:35 +00:00
|
|
|
return false;
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
static void
|
2016-02-17 21:02:40 +00:00
|
|
|
AddConfigFileToList(int config, const TCHAR *filename, const TCHAR *config_dir)
|
2010-03-21 20:28:35 +00:00
|
|
|
{
|
2012-05-08 14:50:26 +00:00
|
|
|
connection_t *c = &o.conn[config];
|
2010-03-21 20:28:35 +00:00
|
|
|
int i;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2017-01-09 02:54:00 +00:00
|
|
|
memset(c, 0, sizeof(*c));
|
|
|
|
|
2012-05-08 14:50:26 +00:00
|
|
|
_tcsncpy(c->config_file, filename, _countof(c->config_file) - 1);
|
|
|
|
_tcsncpy(c->config_dir, config_dir, _countof(c->config_dir) - 1);
|
|
|
|
_tcsncpy(c->config_name, c->config_file, _countof(c->config_name) - 1);
|
|
|
|
c->config_name[_tcslen(c->config_name) - _tcslen(o.ext_string) - 1] = _T('\0');
|
2021-10-24 01:57:11 +00:00
|
|
|
_sntprintf_0(c->log_path, _T("%ls\\%ls.log"), o.log_dir, c->config_name);
|
2012-05-08 14:50:26 +00:00
|
|
|
|
|
|
|
c->manage.sk = INVALID_SOCKET;
|
|
|
|
c->manage.skaddr.sin_family = AF_INET;
|
2012-10-15 13:49:41 +00:00
|
|
|
c->manage.skaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
2021-01-01 00:38:02 +00:00
|
|
|
c->manage.skaddr.sin_port = htons(o.mgmt_port_offset + config);
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2016-08-23 18:37:57 +00:00
|
|
|
#ifndef DISABLE_CHANGE_PASSWORD
|
2016-07-06 17:38:27 +00:00
|
|
|
if (CheckKeyFileWriteAccess (c))
|
2016-02-29 03:10:14 +00:00
|
|
|
c->flags |= FLAG_ALLOW_CHANGE_PASSPHRASE;
|
2016-08-23 18:37:57 +00:00
|
|
|
#endif
|
2016-07-06 17:38:27 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
/* Check if connection should be autostarted */
|
2018-04-20 02:19:10 +00:00
|
|
|
for (i = 0; i < o.num_auto_connect; ++i)
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2017-06-11 20:29:46 +00:00
|
|
|
if (_tcsicmp(c->config_file, o.auto_connect[i]) == 0
|
|
|
|
|| _tcsicmp(c->config_name, o.auto_connect[i]) == 0)
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2012-05-08 14:50:26 +00:00
|
|
|
c->auto_connect = true;
|
2010-03-21 20:28:35 +00:00
|
|
|
break;
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-21 12:43:41 +00:00
|
|
|
/* check whether passwords are saved */
|
2017-01-09 02:54:00 +00:00
|
|
|
if (o.disable_save_passwords)
|
|
|
|
{
|
|
|
|
DisableSavePasswords(c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IsAuthPassSaved(c->config_name))
|
|
|
|
c->flags |= FLAG_SAVE_AUTH_PASS;
|
|
|
|
if (IsKeyPassSaved(c->config_name))
|
|
|
|
c->flags |= FLAG_SAVE_KEY_PASS;
|
|
|
|
}
|
2017-12-17 19:46:06 +00:00
|
|
|
if (o.disable_popup_messages)
|
|
|
|
{
|
|
|
|
DisablePopupMessages(c);
|
|
|
|
}
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 01:43:17 +00:00
|
|
|
#define FLAG_WARN_DUPLICATES (0x1)
|
|
|
|
#define FLAG_WARN_MAX_CONFIGS (0x2)
|
|
|
|
#define FLAG_ADD_CONFIG_GROUPS (0x4)
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2018-04-20 01:43:17 +00:00
|
|
|
/*
|
|
|
|
* Create a new group with the given name as a child of the
|
2018-11-27 17:49:50 +00:00
|
|
|
* specified parent group id and returns the id of the new group.
|
2018-04-20 01:43:17 +00:00
|
|
|
* If FLAG_ADD_CONFIG_GROUPS is not enabled, returns the
|
|
|
|
* parent itself.
|
|
|
|
*/
|
2018-11-27 17:49:50 +00:00
|
|
|
static int
|
|
|
|
NewConfigGroup(const wchar_t *name, int parent, int flags)
|
2018-04-20 01:43:17 +00:00
|
|
|
{
|
|
|
|
if (!(flags & FLAG_ADD_CONFIG_GROUPS))
|
2018-11-27 17:49:50 +00:00
|
|
|
{
|
2018-04-20 01:43:17 +00:00
|
|
|
return parent;
|
2018-11-27 17:49:50 +00:00
|
|
|
}
|
2018-04-20 01:43:17 +00:00
|
|
|
|
|
|
|
if (!o.groups || o.num_groups == o.max_groups)
|
|
|
|
{
|
|
|
|
o.max_groups += 10;
|
|
|
|
void *tmp = realloc(o.groups, sizeof(*o.groups)*o.max_groups);
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
o.max_groups -= 10;
|
|
|
|
ErrorExit(1, L"Out of memory while grouping configs");
|
|
|
|
}
|
|
|
|
o.groups = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_group_t *cg = &o.groups[o.num_groups];
|
|
|
|
memset(cg, 0, sizeof(*cg));
|
|
|
|
|
2021-10-24 01:57:11 +00:00
|
|
|
_sntprintf_0(cg->name, L"%ls", name);
|
2018-04-20 01:43:17 +00:00
|
|
|
cg->id = o.num_groups++;
|
|
|
|
cg->parent = parent;
|
|
|
|
cg->active = false; /* activated later if not empty */
|
|
|
|
|
2018-11-27 17:49:50 +00:00
|
|
|
return cg->id;
|
2018-04-20 01:43:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All groups that link at least one config to the root are
|
|
|
|
* enabled. Dangling entries with no terminal configs will stay
|
|
|
|
* disabled and are not displayed in the menu tree.
|
2018-04-21 14:22:13 +00:00
|
|
|
* Also groups with single configs are squashed if the group
|
|
|
|
* and config names match --- this improves the display.
|
2018-04-20 01:43:17 +00:00
|
|
|
*/
|
2016-02-17 21:02:40 +00:00
|
|
|
static void
|
2018-04-20 01:43:17 +00:00
|
|
|
ActivateConfigGroups(void)
|
|
|
|
{
|
|
|
|
/* the root group is always active */
|
|
|
|
o.groups[0].active = true;
|
|
|
|
|
2018-11-27 17:49:50 +00:00
|
|
|
/* children is a counter re-used for activation, menu indexing etc. -- reset before use */
|
|
|
|
for (int i = 0; i < o.num_groups; i++)
|
|
|
|
o.groups[i].children = 0;
|
|
|
|
|
2018-04-21 14:22:13 +00:00
|
|
|
/* count children of each group -- this includes groups
|
|
|
|
* and configs which have it as parent
|
|
|
|
*/
|
|
|
|
for (int i = 0; i < o.num_configs; i++)
|
|
|
|
{
|
2018-11-27 17:49:50 +00:00
|
|
|
CONFIG_GROUP(&o.conn[i])->children++;
|
2018-04-21 14:22:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i < o.num_groups; i++)
|
|
|
|
{
|
|
|
|
config_group_t *this = &o.groups[i];
|
2018-11-27 17:49:50 +00:00
|
|
|
config_group_t *parent = PARENT_GROUP(this);
|
|
|
|
if (parent) /* should be true as i = 0 is omitted */
|
|
|
|
parent->children++;
|
2018-04-21 14:22:13 +00:00
|
|
|
|
|
|
|
/* unless activated below the group stays inactive */
|
|
|
|
this->active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Squash single config directories with name matching the config
|
|
|
|
* one depth up. This is done so that automatically imported configs
|
|
|
|
* which are added as a single config per directory are handled
|
|
|
|
* as if its in the parent directory. This encourages the
|
|
|
|
* practice of keeping each config and its dependencies (certs,
|
|
|
|
* script etc.) in a separate directory, without making the menu structure
|
|
|
|
* too deeply nested.
|
|
|
|
*/
|
|
|
|
for (int i = 0; i < o.num_configs; i++)
|
|
|
|
{
|
2018-11-27 17:49:50 +00:00
|
|
|
config_group_t *cg = CONFIG_GROUP(&o.conn[i]);
|
2018-04-21 14:22:13 +00:00
|
|
|
|
|
|
|
/* if not root and has only this config as child -- squash it */
|
2018-11-27 17:49:50 +00:00
|
|
|
if (PARENT_GROUP(cg) && cg->children == 1
|
2018-04-21 14:22:13 +00:00
|
|
|
&& !wcscmp(cg->name, o.conn[i].config_name))
|
|
|
|
{
|
|
|
|
cg->children--;
|
|
|
|
o.conn[i].group = cg->parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 01:43:17 +00:00
|
|
|
/* activate all groups that connect a config to the root */
|
|
|
|
for (int i = 0; i < o.num_configs; i++)
|
|
|
|
{
|
2018-11-27 17:49:50 +00:00
|
|
|
config_group_t *cg = CONFIG_GROUP(&o.conn[i]);
|
2018-04-20 01:43:17 +00:00
|
|
|
|
|
|
|
while (cg)
|
|
|
|
{
|
|
|
|
cg->active = true;
|
2018-11-27 17:49:50 +00:00
|
|
|
cg = PARENT_GROUP(cg);
|
2018-04-20 01:43:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scan for configs in config_dir recursing down up to recurse_depth.
|
|
|
|
* Input: config_dir -- root of the directory to scan from
|
|
|
|
* group -- the group into which add the configs to
|
|
|
|
* flags -- enable warnings, use directory based
|
|
|
|
* grouping of configs etc.
|
|
|
|
* Currently configs in a directory are grouped together and group is
|
2018-11-27 17:49:50 +00:00
|
|
|
* the id of the current group in the global group array |o.groups|
|
2018-04-20 01:43:17 +00:00
|
|
|
* This may be recursively called until depth becomes 1 and each time
|
|
|
|
* the group is changed to that of the directory being recursed into.
|
|
|
|
*/
|
|
|
|
static void
|
2018-11-27 17:49:50 +00:00
|
|
|
BuildFileList0(const TCHAR *config_dir, int recurse_depth, int group, int flags)
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2010-03-21 20:28:35 +00:00
|
|
|
WIN32_FIND_DATA find_obj;
|
|
|
|
HANDLE find_handle;
|
|
|
|
TCHAR find_string[MAX_PATH];
|
2018-04-12 02:39:44 +00:00
|
|
|
TCHAR subdir_name[MAX_PATH];
|
2010-03-21 20:28:35 +00:00
|
|
|
|
2021-10-24 01:57:11 +00:00
|
|
|
_sntprintf_0(find_string, _T("%ls\\*"), config_dir);
|
2010-03-21 20:28:35 +00:00
|
|
|
find_handle = FindFirstFile(find_string, &find_obj);
|
|
|
|
if (find_handle == INVALID_HANDLE_VALUE)
|
|
|
|
return;
|
|
|
|
|
2018-04-12 02:39:44 +00:00
|
|
|
/* Loop over each config file in config dir */
|
2010-03-21 20:28:35 +00:00
|
|
|
do
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2018-04-20 02:19:10 +00:00
|
|
|
if (!o.conn || o.num_configs == o.max_configs)
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2018-04-20 02:19:10 +00:00
|
|
|
o.max_configs += 50;
|
|
|
|
void *tmp = realloc(o.conn, sizeof(*o.conn)*o.max_configs);
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
o.max_configs -= 50;
|
|
|
|
FindClose(find_handle);
|
|
|
|
ErrorExit(1, L"Out of memory while scanning configs");
|
|
|
|
}
|
|
|
|
o.conn = tmp;
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
match_t match_type = match(&find_obj, o.ext_string);
|
|
|
|
if (match_type == match_file)
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2016-02-17 21:02:40 +00:00
|
|
|
if (ConfigAlreadyExists(find_obj.cFileName))
|
|
|
|
{
|
2018-04-20 01:43:17 +00:00
|
|
|
if (flags & FLAG_WARN_DUPLICATES)
|
2016-02-17 21:02:40 +00:00
|
|
|
ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-05-14 03:34:53 +00:00
|
|
|
if (CheckReadAccess (config_dir, find_obj.cFileName))
|
2018-04-20 01:43:17 +00:00
|
|
|
{
|
|
|
|
AddConfigFileToList(o.num_configs, find_obj.cFileName, config_dir);
|
|
|
|
o.conn[o.num_configs++].group = group;
|
|
|
|
}
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|
2010-03-21 20:28:35 +00:00
|
|
|
} while (FindNextFile(find_handle, &find_obj));
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2010-03-21 20:28:35 +00:00
|
|
|
FindClose(find_handle);
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2018-04-12 02:39:44 +00:00
|
|
|
/* optionally loop over each subdir */
|
2020-09-08 16:49:30 +00:00
|
|
|
if (recurse_depth < 1)
|
2018-04-12 02:39:44 +00:00
|
|
|
return;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2018-04-12 02:39:44 +00:00
|
|
|
find_handle = FindFirstFile (find_string, &find_obj);
|
|
|
|
if (find_handle == INVALID_HANDLE_VALUE)
|
|
|
|
return;
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2018-04-12 02:39:44 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
match_t match_type = match(&find_obj, o.ext_string);
|
|
|
|
if (match_type == match_dir)
|
2010-03-21 20:28:35 +00:00
|
|
|
{
|
2018-04-12 02:39:44 +00:00
|
|
|
if (wcscmp(find_obj.cFileName, _T("."))
|
|
|
|
&& wcscmp(find_obj.cFileName, _T("..")))
|
2008-12-18 11:08:35 +00:00
|
|
|
{
|
2018-04-12 02:39:44 +00:00
|
|
|
/* recurse into subdirectory */
|
2021-10-24 01:57:11 +00:00
|
|
|
_sntprintf_0(subdir_name, _T("%ls\\%ls"), config_dir, find_obj.cFileName);
|
2018-11-27 17:49:50 +00:00
|
|
|
int sub_group = NewConfigGroup(find_obj.cFileName, group, flags);
|
2018-04-20 01:43:17 +00:00
|
|
|
|
|
|
|
BuildFileList0(subdir_name, recurse_depth - 1, sub_group, flags);
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|
2018-04-12 02:39:44 +00:00
|
|
|
}
|
|
|
|
} while (FindNextFile(find_handle, &find_obj));
|
2008-12-18 11:08:35 +00:00
|
|
|
|
2018-04-12 02:39:44 +00:00
|
|
|
FindClose(find_handle);
|
2016-02-17 21:02:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 03:52:37 +00:00
|
|
|
/*
|
|
|
|
* Open a path and get its file information structure.
|
|
|
|
* Returns true on success, false on error.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
GetFileInfo(const wchar_t *path, BY_HANDLE_FILE_INFORMATION *info)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
/* FILE_FLAG_BACKUP_SEMANTICS required to open directories */
|
|
|
|
HANDLE fd = CreateFileW(path, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
|
|
|
|
|
|
|
if (fd == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
MsgToEventLog(EVENTLOG_ERROR_TYPE, L"GetFileInfo: Error opening path <%ls> (status = %lu)", path, GetLastError());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GetFileInformationByHandle(fd, info);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
MsgToEventLog(EVENTLOG_ERROR_TYPE, L"GetFileInfo: Error accessing file information for path <%ls> (status = %lu)", path, GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintDebug(L"path = <%ls> volumeid = %lu file index = (%lu,%lu)", path, info->dwVolumeSerialNumber, info->nFileIndexLow, info->nFileIndexHigh);
|
|
|
|
}
|
|
|
|
CloseHandle(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare two paths by checking whether they point to the
|
|
|
|
* same object in the file system. Returns true if the paths
|
|
|
|
* are same, false otherwise.
|
|
|
|
* If the two paths are identical strings return true early.
|
|
|
|
* If any of the paths do not exist, are not accessible or
|
|
|
|
* fail to provide file information, we return false.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
IsSamePath(const wchar_t *path1, const wchar_t *path2)
|
|
|
|
{
|
|
|
|
BOOL ret = false;
|
|
|
|
BY_HANDLE_FILE_INFORMATION info1, info2;
|
|
|
|
|
|
|
|
if (_wcsicmp(path1, path2) == 0) return true;
|
|
|
|
|
|
|
|
if (GetFileInfo(path1, &info1) && GetFileInfo(path2, &info2))
|
|
|
|
{
|
|
|
|
ret = (info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
|
|
|
|
&& info1.nFileIndexLow == info2.nFileIndexLow
|
|
|
|
&& info1.nFileIndexHigh == info2.nFileIndexHigh);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-17 21:02:40 +00:00
|
|
|
void
|
|
|
|
BuildFileList()
|
|
|
|
{
|
|
|
|
static bool issue_warnings = true;
|
2020-09-08 16:49:30 +00:00
|
|
|
int recurse_depth = 20; /* maximum number of levels below config_dir to recurse into */
|
2018-04-20 01:43:17 +00:00
|
|
|
int flags = 0;
|
2018-11-27 17:49:50 +00:00
|
|
|
int root = 0;
|
2021-02-27 19:40:15 +00:00
|
|
|
int max_configs = (1<<16) - o.mgmt_port_offset;
|
2016-02-17 21:02:40 +00:00
|
|
|
|
2017-01-02 19:29:19 +00:00
|
|
|
if (o.silent_connection)
|
|
|
|
issue_warnings = false;
|
|
|
|
|
2016-05-14 03:35:09 +00:00
|
|
|
/*
|
|
|
|
* If no connections are active reset num_configs and rescan
|
|
|
|
* to make a new list. Else we keep all current configs and
|
|
|
|
* rescan to add any new one's found
|
|
|
|
*/
|
2018-11-27 17:49:50 +00:00
|
|
|
if (!o.num_groups || CountConnState(disconnected) == o.num_configs)
|
2018-04-20 01:43:17 +00:00
|
|
|
{
|
2016-05-14 03:35:09 +00:00
|
|
|
o.num_configs = 0;
|
2018-04-20 01:43:17 +00:00
|
|
|
o.num_groups = 0;
|
|
|
|
flags |= FLAG_ADD_CONFIG_GROUPS;
|
2018-11-27 17:49:50 +00:00
|
|
|
root = NewConfigGroup(L"ROOT", -1, flags); /* -1 indicates no parent */
|
2018-04-20 01:43:17 +00:00
|
|
|
}
|
|
|
|
else
|
2018-11-27 17:49:50 +00:00
|
|
|
root = 0;
|
2016-02-17 21:02:40 +00:00
|
|
|
|
2018-04-20 01:43:17 +00:00
|
|
|
if (issue_warnings)
|
|
|
|
{
|
|
|
|
flags |= FLAG_WARN_DUPLICATES | FLAG_WARN_MAX_CONFIGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildFileList0 (o.config_dir, recurse_depth, root, flags);
|
|
|
|
|
|
|
|
root = NewConfigGroup(L"System Profiles", root, flags);
|
2016-02-17 21:02:40 +00:00
|
|
|
|
2021-02-26 03:52:37 +00:00
|
|
|
if (!IsSamePath(o.global_config_dir, o.config_dir))
|
2018-04-20 01:43:17 +00:00
|
|
|
BuildFileList0 (o.global_config_dir, recurse_depth, root, flags);
|
2016-02-17 21:02:40 +00:00
|
|
|
|
|
|
|
if (o.num_configs == 0 && issue_warnings)
|
2016-09-18 18:32:50 +00:00
|
|
|
ShowLocalizedMsg(IDS_NFO_NO_CONFIGS, o.config_dir, o.global_config_dir);
|
2016-02-17 21:02:40 +00:00
|
|
|
|
2021-02-27 19:40:15 +00:00
|
|
|
/* More than max_configs are ignored in the menu listing */
|
|
|
|
if (o.num_configs > max_configs)
|
2018-04-20 02:19:10 +00:00
|
|
|
{
|
|
|
|
if (issue_warnings)
|
2021-02-27 19:40:15 +00:00
|
|
|
ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, max_configs);
|
|
|
|
o.num_configs = max_configs; /* management-port cant handle more -- ignore the rest */
|
2018-04-20 02:19:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 17:49:50 +00:00
|
|
|
/* if adding groups, activate non-empty ones */
|
|
|
|
if (flags &FLAG_ADD_CONFIG_GROUPS)
|
|
|
|
{
|
|
|
|
ActivateConfigGroups();
|
|
|
|
}
|
2018-04-20 01:43:17 +00:00
|
|
|
|
2016-02-17 21:02:40 +00:00
|
|
|
issue_warnings = false;
|
2008-12-18 11:08:35 +00:00
|
|
|
}
|