aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-cred.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-05-05 18:59:57 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-05-05 18:59:57 +0200
commit9952955d440866fa061d78fe923cb8282f778667 (patch)
treead0764b00d6a3bfec7a7154d9d9525d6e4d1a56b /src/afb-cred.c
parentfebbd43b65c6b0d480b076ead8a078979b8b3603 (diff)
Add user to context
At this time, user is the string representation of the uid. Change-Id: I65fbb4112f209fdb948d24e9c47fa73dacdf571f Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-cred.c')
-rw-r--r--src/afb-cred.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/afb-cred.c b/src/afb-cred.c
index 8a777009..763c9265 100644
--- a/src/afb-cred.c
+++ b/src/afb-cred.c
@@ -34,9 +34,18 @@ static struct afb_cred *current;
static struct afb_cred *mkcred(uid_t uid, gid_t gid, pid_t pid, const char *label, size_t size)
{
struct afb_cred *cred;
- char *dest;
-
- cred = malloc(1 + size + sizeof *cred);
+ char *dest, user[64];
+ size_t i;
+ uid_t u;
+
+ i = 0;
+ u = uid;
+ do {
+ user[i++] = (char)('0' + u % 10);
+ u = u / 10;
+ } while(u && i < sizeof user);
+
+ cred = malloc(2 + i + size + sizeof *cred);
if (!cred)
errno = ENOMEM;
else {
@@ -45,12 +54,16 @@ static struct afb_cred *mkcred(uid_t uid, gid_t gid, pid_t pid, const char *labe
cred->gid = gid;
cred->pid = pid;
dest = (char*)(&cred[1]);
- memcpy(dest, label, size);
- dest[size] = 0;
+ cred->user = dest;
+ while(i)
+ *dest++ = user[--i];
+ *dest++ = 0;
cred->label = dest;
cred->id = dest;
+ memcpy(dest, label, size);
+ dest[size] = 0;
dest = strrchr(dest, ':');
- if (dest && dest[1])
+ if (dest)
cred->id = &dest[1];
}
return cred;