summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2013-08-20 20:29:13 -0400
committerGünther Deschner <gdeschner@redhat.com>2013-10-23 19:51:49 +0200
commit485a2eb71d3a22c50a5be35318d421b451713ccb (patch)
tree47a03ecaa886b1b3663baa8ac60d1fa4d1bed3f7
parentee2a1573a41e4a08dd00e9b37523656ae3ef4146 (diff)
downloadgss-proxy-485a2eb71d3a22c50a5be35318d421b451713ccb.tar.gz
gss-proxy-485a2eb71d3a22c50a5be35318d421b451713ccb.tar.xz
gss-proxy-485a2eb71d3a22c50a5be35318d421b451713ccb.zip
Move uid to name resolution in its own function.
Reviewed-by: Günther Deschner <gdeschner@redhat.com>
-rw-r--r--proxy/src/gp_creds.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/proxy/src/gp_creds.c b/proxy/src/gp_creds.c
index 28a3d45..5800a51 100644
--- a/proxy/src/gp_creds.c
+++ b/proxy/src/gp_creds.c
@@ -123,12 +123,24 @@ struct gp_service *gp_creds_match_conn(struct gssproxy_ctx *gpctx,
return NULL;
}
-#define PWBUFLEN 2048
-static char *get_formatted_string(const char *orig, uid_t target_uid)
+static char *uid_to_name(uid_t uid)
{
struct passwd pwd, *res = NULL;
char buffer[PWBUFLEN];
+ int ret;
+
+ ret = getpwuid_r(uid, &pwd, buffer, PWBUFLEN, &res);
+ if (ret || !res) {
+ return NULL;
+ }
+ return strdup(pwd.pw_name);
+}
+
+#define PWBUFLEN 2048
+static char *get_formatted_string(const char *orig, uid_t target_uid)
+{
int len, left, right;
+ char *user = NULL;
char *str;
char *tmp;
char *p;
@@ -162,9 +174,9 @@ static char *get_formatted_string(const char *orig, uid_t target_uid)
p = str + (len - right);
break;
case 'u':
- if (!res) {
- ret = getpwuid_r(target_uid, &pwd, buffer, 2048, &res);
- if (ret || !res) {
+ if (!user) {
+ user = uid_to_name(target_uid);
+ if (!user) {
safefree(str);
goto done;
}
@@ -172,7 +184,7 @@ static char *get_formatted_string(const char *orig, uid_t target_uid)
p++;
left = p - str;
right = len - left;
- len = asprintf(&tmp, "%.*s%s%s", left - 2, str, pwd.pw_name, p);
+ len = asprintf(&tmp, "%.*s%s%s", left - 2, str, user, p);
safefree(str);
if (len == -1) {
goto done;
@@ -188,6 +200,7 @@ static char *get_formatted_string(const char *orig, uid_t target_uid)
}
done:
+ safefree(user);
return str;
}