diff options
author | Alexander Amelkin <alexander@amelkin.msk.ru> | 2019-06-13 16:41:35 +0300 |
---|---|---|
committer | Alexander Amelkin <mocbuhtig@amelkin.msk.ru> | 2019-06-18 16:43:41 +0300 |
commit | 54abbaf0e8b24a7389d6883d282691b9d0cfb2e5 (patch) | |
tree | e9e56bf6211827a090d6321cd2886c80d67d4c0b /lib | |
parent | bd0475ce4ad85645f893010423b265ada1514cc5 (diff) | |
download | ipmitool-54abbaf0e8b24a7389d6883d282691b9d0cfb2e5.tar.gz |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ipmi_strings.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/ipmi_strings.c b/lib/ipmi_strings.c index 30376c3..b8b8300 100644 --- a/lib/ipmi_strings.c +++ b/lib/ipmi_strings.c @@ -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; |