diff options
author | Simo Sorce <simo@redhat.com> | 2013-03-25 22:27:57 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2013-03-27 10:30:35 -0400 |
commit | cc2a2e800995b587c88776a76de096d38eb82229 (patch) | |
tree | cc9973b624e3d448331fda01b092acc02683afb7 | |
parent | c3a36be0184c4abdd22e3fc01dc29861678c80ec (diff) | |
download | gss-proxy-cc2a2e800995b587c88776a76de096d38eb82229.tar.gz gss-proxy-cc2a2e800995b587c88776a76de096d38eb82229.tar.xz gss-proxy-cc2a2e800995b587c88776a76de096d38eb82229.zip |
Improve ccache formatting.
Add %U support which will insert the user uid number instead of name.
Fix %% support by actually removing one of the % charcters
Fix %<invalid> sequence by actually bailing out if one is found.
Add GPDEBUG statements to indicate what went wrong.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Günther Deschner <gdeschner@redhat.com>
-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; } |