diff options
Diffstat (limited to 'proxy/src')
-rw-r--r-- | proxy/src/gp_common.h | 5 | ||||
-rw-r--r-- | proxy/src/gp_creds.c | 51 |
2 files changed, 42 insertions, 14 deletions
diff --git a/proxy/src/gp_common.h b/proxy/src/gp_common.h index ad68e55..13a4c9b 100644 --- a/proxy/src/gp_common.h +++ b/proxy/src/gp_common.h @@ -57,6 +57,11 @@ elem->next = NULL; \ } while (0) +#define safefree(ptr) do { \ + free(ptr); \ + ptr = NULL; \ +} while(0) + /* max out at 1MB for now */ #define MAX_RPC_SIZE 1024*1024 diff --git a/proxy/src/gp_creds.c b/proxy/src/gp_creds.c index 6ac5776..9baa126 100644 --- a/proxy/src/gp_creds.c +++ b/proxy/src/gp_creds.c @@ -115,6 +115,7 @@ static char *gp_get_ccache_name(struct gp_service *svc, char *ccache; char *tmp; char *p; + int len, left, right; int ret; if (svc->krb5.ccache == NULL) { @@ -125,7 +126,8 @@ static char *gp_get_ccache_name(struct gp_service *svc, ret = asprintf(&ccache, "%s/krb5cc_%s", CCACHE_PATH, pwd.pw_name); if (ret == -1) { - return NULL; + ccache = NULL; + goto done; } return ccache; @@ -133,40 +135,61 @@ static char *gp_get_ccache_name(struct gp_service *svc, ccache = strdup(svc->krb5.ccache); if (!ccache) { - return NULL; + goto done; } + len = strlen(ccache); p = ccache; while ((p = strchr(p, '%')) != NULL) { p++; switch (*p) { case '%': - p++; + left = p - ccache; + memmove(p, p + 1, left - 1); + len--; continue; + case 'U': + p++; + left = p - ccache; + right = len - left; + len = asprintf(&tmp, "%.*s%d%s", left - 2, ccache, svc->euid, p); + safefree(ccache); + if (len == -1) { + goto done; + } + ccache = tmp; + p = ccache + (len - right); + break; case 'u': if (!res) { ret = getpwuid_r(svc->euid, &pwd, buffer, 2048, &res); if (ret || !res) { - free(ccache); - return NULL; + safefree(ccache); + goto done; } } - ret = asprintf(&tmp, "%.*s%s%s", - (int)(p - ccache - 1), ccache, pwd.pw_name, p + 1); - if (ret == -1) { - free(ccache); - return NULL; + p++; + left = p - ccache; + right = len - left; + len = asprintf(&tmp, "%.*s%s%s", left - 2, ccache, pwd.pw_name, p); + safefree(ccache); + if (len == -1) { + goto done; } - p = p - ccache + tmp; - free(ccache); ccache = tmp; + p = ccache + (len - right); break; default: - p++; - continue; + GPDEBUG("Invalid format code '%%%c'\n", *p); + safefree(ccache); + goto done; } } +done: + if (!ccache) { + GPDEBUG("Failed to construct ccache string.\n"); + } return ccache; } |