Skip to content

Commit 286e3da

Browse files
committed
Escape principal name to remove the path separator
The principla name is used as a file name, any embedded path separators are going to cause trouble if used in the file name, so we need to escape them away. Usee ~ as the escape chracter (~~ to escape ~ itself) Fixes #14
1 parent 457872c commit 286e3da

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

src/mod_auth_gssapi.c

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,48 @@ static bool mag_conn_is_https(conn_rec *c)
119119
return false;
120120
}
121121

122+
static char *escape(apr_pool_t *pool, const char *name,
123+
char find, const char *replace)
124+
{
125+
char *escaped = NULL;
126+
char *namecopy;
127+
char *n;
128+
char *p;
129+
130+
namecopy = apr_pstrdup(pool, name);
131+
if (!namecopy) goto done;
132+
133+
p = strchr(namecopy, find);
134+
if (!p) return namecopy;
135+
136+
/* first segment */
137+
n = namecopy;
138+
while (p) {
139+
/* terminate previous segment */
140+
*p = '\0';
141+
if (escaped) {
142+
escaped = apr_pstrcat(pool, escaped, n, replace, NULL);
143+
} else {
144+
escaped = apr_pstrcat(pool, n, replace, NULL);
145+
}
146+
if (!escaped) goto done;
147+
/* move to next segment */
148+
n = p + 1;
149+
p = strchr(n, find);
150+
}
151+
/* append last segment if any */
152+
if (*n) {
153+
escaped = apr_pstrcat(pool, escaped, n, NULL);
154+
}
155+
156+
done:
157+
if (!escaped) {
158+
ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
159+
"OOM escaping name");
160+
}
161+
return escaped;
162+
}
163+
122164
static void mag_store_deleg_creds(request_rec *req,
123165
char *dir, char *clientname,
124166
gss_cred_id_t delegated_cred,
@@ -128,8 +170,18 @@ static void mag_store_deleg_creds(request_rec *req,
128170
gss_key_value_set_desc store;
129171
char *value;
130172
uint32_t maj, min;
131-
132-
value = apr_psprintf(req->pool, "FILE:%s/%s", dir, clientname);
173+
char *escaped;
174+
175+
/* We need to escape away '/', we can't have path separators in
176+
* a ccache file name */
177+
/* first double escape the esacping char (~) if any */
178+
escaped = escape(req->pool, clientname, '~', "~~");
179+
if (!escaped) return;
180+
/* then escape away the separator (/) if any */
181+
escaped = escape(req->pool, escaped, '/', "~");
182+
if (!escaped) return;
183+
184+
value = apr_psprintf(req->pool, "FILE:%s/%s", dir, escaped);
133185
if (!value) {
134186
ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
135187
"OOM storing delegated credentials");

0 commit comments

Comments
 (0)