lib/base: introduce HEIM_BASE_USE_PATH_TOKENS

KRB5_USE_PATH_TOKENS cannot be used within lib/base as its value
is declared in lib/krb5/krb5.h.  Declare HEIM_BASE_USE_PATH_TOKENS
in lib/base/baselocl.h and test for it in
heim_config_parse_file_multi().

By conditionalizing heim_config_parse_file_multi() behavior on
KRB5_USE_PATH_TOKENS heim_expand_path_tokens() is not executed
and open() is called on a path without token substitution.  As a
result open() always fails with ENOENT.

Change-Id: I29dc018bc560519b76314232b2d51f53bde6313c
This commit is contained in:
Jeffrey Altman
2020-05-25 14:16:35 -04:00
committed by Nicolas Williams
parent f77618ef15
commit 3074561796
3 changed files with 8 additions and 13 deletions

View File

@@ -40,6 +40,7 @@
#define ISTILDE(x) (x == '~')
#ifdef _WIN32
# define ISPATHSEP(x) (x == '/' || x =='\\')
# define HEIM_BASE_USE_PATH_TOKENS 1
#else
# define ISPATHSEP(x) (x == '/')
#endif

View File

@@ -572,7 +572,7 @@ heim_config_parse_file_multi(heim_context context,
* enabled by calling heim_set_home_dir_access().
*/
if (ISTILDE(fname[0]) && ISPATHSEP(fname[1])) {
#ifndef KRB5_USE_PATH_TOKENS
#ifndef HEIM_BASE_USE_PATH_TOKENS
const char *home = NULL;
char homebuf[MAX_PATH];
@@ -594,7 +594,7 @@ heim_config_parse_file_multi(heim_context context,
}
fname = newfname;
}
#else /* KRB5_USE_PATH_TOKENS */
#else /* HEIM_BASE_USE_PATH_TOKENS */
/*
* Really, this is Windows, and on Windows we'd want to allow homedir
* access. We could refactor this a bit though.
@@ -605,7 +605,7 @@ heim_config_parse_file_multi(heim_context context,
return heim_enomem(context);
}
fname = newfname;
#endif
#endif /* HEIM_BASE_USE_PATH_TOKENS */
}
if (is_plist_file(fname)) {
@@ -624,15 +624,8 @@ heim_config_parse_file_multi(heim_context context,
return ENOENT;
#endif
} else {
#ifdef KRB5_USE_PATH_TOKENS
char * exp_fname = NULL;
/*
* Note that heim_config_parse_dir_multi() doesn't want tokens
* expanded here, but it happens to limit the names of files to
* include such that there can be no tokens to expand. Don't
* add token expansion for tokens using _, say.
*/
#ifdef HEIM_BASE_USE_PATH_TOKENS
char *exp_fname; /* newfname might be non-NULL */
ret = heim_expand_path_tokens(context, fname, 1, &exp_fname, NULL);
if (ret) {
config_include_depth--;
@@ -642,7 +635,7 @@ heim_config_parse_file_multi(heim_context context,
free(newfname);
fname = newfname = exp_fname;
#endif
#endif /* HEIM_BASE_USE_PATH_TOKENS */
f.context = context;
f.f = fopen(fname, "r");

View File

@@ -35,6 +35,7 @@
#include "baselocl.h"
#include "heim_threads.h"
#include "heimbase.h"
#include "heimbase-svc.h"
#include <assert.h>
#include <stdarg.h>