Use configurable path to IANA PEN registry

Add support for IANADIR and IANAUSERDIR variables to configure
to allow for customizable locations of system and user-supplied
IANA PEN registry.

Also make path building code portable to Windows.

Partially resolves ipmitool/ipmitool#11

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
Alexander Amelkin 2019-06-13 16:41:35 +03:00 committed by Alexander Amelkin
parent bd0475ce4a
commit 54abbaf0e8
2 changed files with 42 additions and 6 deletions

View File

@ -691,6 +691,32 @@ if test "x${!xdefault_intf_is_enabled}" != "xyes"; then
AC_MSG_ERROR([** Cannot set ${DEFAULT_INTF} as default; ${DEFAULT_INTF} is not enabled. :${!xdefault_intf_is_enabled}:])
fi
AC_ARG_VAR(IANADIR, [Configure the path to IANA PEN dictionary (default=DATAROOTDIR/misc)])
AC_ARG_VAR(IANAUSERDIR, [Configure the path to IANA PEN dictionary wihtin the user's HOME directory (default=.local/usr/share/misc)])
if test "x${IANADIR}" == "x"; then
echo Set IANA PEN dictionary search path to ${datarootdir}/misc
IANADIR="${datarootdir}/misc"
fi
if test "x${IANAUSERDIR}" == "x"; then
IANAUSERDIR=".local/usr/share/misc"
echo Set user\'s IANA PEN dictionary search path to ${IANAUSERDIR}
fi
AH_TEMPLATE([IANADIR],[The path to system IANA PEN dictionary])
AC_DEFINE_UNQUOTED(IANADIR, "`eval "echo ${IANADIR}"`", [])
AH_TEMPLATE([IANAUSERDIR],[The subpath to user IANA PEN dictionary within the user's HOME])
AC_DEFINE_UNQUOTED(IANAUSERDIR, "`eval "echo ${IANAUSERDIR}"`", [])
AH_TEMPLATE([PATH_SEPARATOR], [The path separator string])
#if defined _WIN32 || defined __CYGWIN__
AC_DEFINE(PATH_SEPARATOR, "\\")
#else
AC_DEFINE(PATH_SEPARATOR, "/")
#endif
dnl Generate files for build
AC_CONFIG_FILES([Makefile
doc/Makefile

View File

@ -812,7 +812,7 @@ size_t count_bytes(const char *s, unsigned char c)
* That is, IANA PEN at position 0, enterprise name at position 2.
*/
#define IANA_NAME_OFFSET 2
#define IANA_PEN_REGISTRY "/usr/share/misc/enterprise-numbers"
#define IANA_PEN_REGISTRY "enterprise-numbers"
static
int oem_info_list_load(oem_valstr_list_t **list)
{
@ -826,8 +826,9 @@ int oem_info_list_load(oem_valstr_list_t **list)
*/
if ((home = getenv("HOME"))) {
char path[PATH_MAX + 1] = { 0 };
strncpy(path, home, sizeof(path));
strncat(path, "/.local" IANA_PEN_REGISTRY, PATH_MAX);
snprintf(path, PATH_MAX, "%s%s",
home,
PATH_SEPARATOR IANAUSERDIR PATH_SEPARATOR IANA_PEN_REGISTRY);
in = fopen(path, "r");
}
@ -835,7 +836,7 @@ int oem_info_list_load(oem_valstr_list_t **list)
/*
* Now open the system default file
*/
in = fopen(IANA_PEN_REGISTRY, "r");
in = fopen(IANADIR PATH_SEPARATOR IANA_PEN_REGISTRY, "r");
if (!in) {
lperror(LOG_ERR, "IANA PEN registry open failed");
return -1;
@ -923,8 +924,17 @@ int oem_info_list_load(oem_valstr_list_t **list)
/* Just stop reading, and process what has already been read */
break;
}
strncpy((void *)item->valstr.str, line + IANA_NAME_OFFSET, len);
((char *)(item->valstr.str))[len] = 0;
/*
* Most other valstr arrays are constant and all of them aren't meant
* for modification, so the string inside 'struct valstr' is const.
* Here we're loading the strings dynamically so we intentionally
* cast to a non-const type to be able to modify data here and
* keep the compiler silent about it. Restrictions still apply to
* other places where these strings are used.
*/
snprintf((void *)item->valstr.str, len + 1,
"%s", line + IANA_NAME_OFFSET);
free_n(&line);
item->next = oemlist;
oemlist = item;