diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-05-05 18:59:57 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-05-05 18:59:57 +0200 |
commit | 9952955d440866fa061d78fe923cb8282f778667 (patch) | |
tree | ad0764b00d6a3bfec7a7154d9d9525d6e4d1a56b | |
parent | febbd43b65c6b0d480b076ead8a078979b8b3603 (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>
-rw-r--r-- | src/afb-cred.c | 25 | ||||
-rw-r--r-- | src/afb-cred.h | 1 | ||||
-rw-r--r-- | src/afb-hook.c | 3 |
3 files changed, 22 insertions, 7 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; diff --git a/src/afb-cred.h b/src/afb-cred.h index 5bd54233..6f8173f6 100644 --- a/src/afb-cred.h +++ b/src/afb-cred.h @@ -25,6 +25,7 @@ struct afb_cred uid_t uid; gid_t gid; pid_t pid; + const char *user; const char *label; const char *id; }; diff --git a/src/afb-hook.c b/src/afb-hook.c index efd2e652..c1f93fab 100644 --- a/src/afb-hook.c +++ b/src/afb-hook.c @@ -99,8 +99,9 @@ static void hook_xreq_begin_default_cb(void * closure, const struct afb_xreq *xr if (!xreq->cred) _hook_xreq_(xreq, "BEGIN"); else - _hook_xreq_(xreq, "BEGIN uid=%d gid=%d pid=%d label=%s id=%s", + _hook_xreq_(xreq, "BEGIN uid=%d=%s gid=%d pid=%d label=%s id=%s", (int)xreq->cred->uid, + xreq->cred->user, (int)xreq->cred->gid, (int)xreq->cred->pid, xreq->cred->label?:"(null)", |