ISPATHSEP and ISTILDE macros; Windows portability
Windows treats '\\' and '/' equivalently but we cannot control the form that will be used by end users. Introduce ISPATHSEP() macro which tests only for '/' on UNIX and both on Windows. Introduce ISTILDE() macro to test for '~'. When testing for '/' with strchr() or strrchr() add conditional checks for '\\' on Windows. Change-Id: Ia85e698fc88f15a6a71db649db5417f02ef7e5fe
This commit is contained in:
@@ -979,7 +979,7 @@ krb5_cc_get_prefix_ops(krb5_context context, const char *prefix)
|
||||
|
||||
if (prefix == NULL)
|
||||
return KRB5_DEFAULT_CCTYPE;
|
||||
if (prefix[0] == '/')
|
||||
if (ISPATHSEP(prefix[0]))
|
||||
return &krb5_fcc_ops;
|
||||
|
||||
p = strdup(prefix);
|
||||
|
@@ -425,7 +425,7 @@ krb5_config_parse_file_multi (krb5_context context,
|
||||
* current users home directory. The behavior can be disabled and
|
||||
* enabled by calling krb5_set_home_dir_access().
|
||||
*/
|
||||
if (fname[0] == '~' && fname[1] == '/') {
|
||||
if (ISTILDE(fname[0]) && ISPATHSEP(fname[1])) {
|
||||
#ifndef KRB5_USE_PATH_TOKENS
|
||||
const char *home = NULL;
|
||||
|
||||
|
@@ -256,8 +256,8 @@ dcc_resolve(krb5_context context, krb5_ccache *id, const char *res)
|
||||
|
||||
p = res;
|
||||
do {
|
||||
p = strstr(p, "/..");
|
||||
if (p && (p[3] == '/' || p[3] == '\0')) {
|
||||
p = strstr(p, "..");
|
||||
if (p && (p == res || ISPATHSEP(p[-1])) && (ISPATHSEP(p[2]) || p[2] == '\0')) {
|
||||
krb5_set_error_message(context, KRB5_CC_FORMAT,
|
||||
N_("Path contains a .. component", ""));
|
||||
return KRB5_CC_FORMAT;
|
||||
@@ -278,6 +278,10 @@ dcc_resolve(krb5_context context, krb5_ccache *id, const char *res)
|
||||
char *q;
|
||||
|
||||
dc->dir = strdup(&res[1]);
|
||||
#ifdef _WIN32
|
||||
q = strrchr(dc->dir, '\\');
|
||||
if (q == NULL)
|
||||
#endif
|
||||
q = strrchr(dc->dir, '/');
|
||||
if (q) {
|
||||
*q++ = '\0';
|
||||
@@ -318,7 +322,7 @@ dcc_resolve(krb5_context context, krb5_ccache *id, const char *res)
|
||||
|
||||
len = strlen(dc->dir);
|
||||
|
||||
if (dc->dir[len - 1] == '/')
|
||||
if (ISPATHSEP(dc->dir[len - 1]))
|
||||
dc->dir[len - 1] = '\0';
|
||||
|
||||
ret = verify_directory(context, dc->dir);
|
||||
|
@@ -170,7 +170,7 @@ keytab_name(const char *name, const char **type, size_t *type_len)
|
||||
residual = strchr(name, ':');
|
||||
|
||||
if (residual == NULL ||
|
||||
name[0] == '/'
|
||||
ISPATHSEP(name[0])
|
||||
#ifdef _WIN32
|
||||
/* Avoid treating <drive>:<path> as a keytab type
|
||||
* specification */
|
||||
|
@@ -375,4 +375,11 @@ enum krb5_pk_type {
|
||||
|
||||
#endif /* PKINIT */
|
||||
|
||||
#define ISTILDE(x) (x == '~')
|
||||
#ifdef _WIN32
|
||||
# define ISPATHSEP(x) (x == '/' || x =='\\')
|
||||
#else
|
||||
# define ISPATHSEP(x) (x == '/')
|
||||
#endif
|
||||
|
||||
#endif /* __KRB5_LOCL_H__ */
|
||||
|
@@ -271,10 +271,13 @@ krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig)
|
||||
int min = 0, max = -1, n;
|
||||
char c;
|
||||
const char *p = orig;
|
||||
#ifdef _WIN32
|
||||
const char *q;
|
||||
#endif
|
||||
|
||||
n = sscanf(p, "%d%c%d/", &min, &c, &max);
|
||||
if(n == 2){
|
||||
if(c == '/') {
|
||||
if(ISPATHSEP(c)) {
|
||||
if(min < 0){
|
||||
max = -min;
|
||||
min = 0;
|
||||
@@ -284,6 +287,12 @@ krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig)
|
||||
}
|
||||
}
|
||||
if(n){
|
||||
#ifdef _WIN32
|
||||
q = strrchr(p, '\\');
|
||||
if (q != NULL)
|
||||
p = q;
|
||||
else
|
||||
#endif
|
||||
p = strchr(p, '/');
|
||||
if(p == NULL) {
|
||||
krb5_set_error_message(context, HEIM_ERR_LOG_PARSE,
|
||||
|
@@ -241,6 +241,10 @@ resolve_origin(const char *di)
|
||||
return strdup(LIBDIR "/plugin/krb5");
|
||||
|
||||
dname = dl_info.dli_fname;
|
||||
#ifdef _WIN32
|
||||
p = strrchr(dname, '\\');
|
||||
if (p == NULL)
|
||||
#endif
|
||||
p = strrchr(dname, '/');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
|
@@ -289,10 +289,13 @@ check_log(krb5_context context, const char *path, char *data)
|
||||
int min = 0, max = -1, n;
|
||||
char c;
|
||||
const char *p = data;
|
||||
#ifdef _WIN32
|
||||
const char *q;
|
||||
#endif
|
||||
|
||||
n = sscanf(p, "%d%c%d/", &min, &c, &max);
|
||||
if(n == 2){
|
||||
if(c == '/') {
|
||||
if(ISPATHSEP(c)) {
|
||||
if(min < 0){
|
||||
max = -min;
|
||||
min = 0;
|
||||
@@ -302,6 +305,12 @@ check_log(krb5_context context, const char *path, char *data)
|
||||
}
|
||||
}
|
||||
if(n){
|
||||
#ifdef _WIN32
|
||||
q = strrchr(p, '\\');
|
||||
if (q != NULL)
|
||||
p = q;
|
||||
else
|
||||
#endif
|
||||
p = strchr(p, '/');
|
||||
if(p == NULL) {
|
||||
krb5_warnx(context, "%s: failed to parse \"%s\"", path, data);
|
||||
|
Reference in New Issue
Block a user