waffle

user and group backend daemon
git clone git://git.2f30.org/waffle
Log | Files | Refs | LICENSE

commit 9e6de8d7ff57a66aad88d248571e1b32f5f1e193
parent ac983788ff8cf47de6e2379ec07eb03db6982a0d
Author: sin <sin@2f30.org>
Date:   Sat,  7 Mar 2015 18:21:35 +0000

Add GRBYGID suport

Diffstat:
Mbackend.c | 18+++++++++++++++++-
Mdummy.c | 15+++++++++++++++
Mproto.h | 2+-
Mreq.c | 5+++++
Mwaffle.h | 2++
5 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/backend.c b/backend.c @@ -41,7 +41,6 @@ backends_pwbyname(const char *key, struct passwd *pw) return -1; } - int backends_pwbyuid(const char *key, struct passwd *pw) { @@ -69,3 +68,20 @@ backends_grbyname(const char *key, struct group *gr) return 0; return -1; } + +int +backends_grbygid(const char *key, struct group *gr) +{ + char *end; + gid_t gid; + size_t i; + + errno = 0; + gid = strtol(key, &end, 10); + if (*end || errno) + return -1; + for (i = 0; i < LEN(backends); i++) + if (!backends[i].ops->grbygid(gid, gr)) + return 0; + return -1; +} diff --git a/dummy.c b/dummy.c @@ -56,10 +56,25 @@ dummy_grbyname(const char *name, struct group *gr) return 0; } +static int +dummy_grbygid(gid_t gid, struct group *gr) +{ + static char *mem[] = { "group1", "group2", NULL }; + + if (gid != 1337) + return -1; + gr->gr_name = "dummy"; + gr->gr_passwd = "passwd"; + gr->gr_gid = 1337; + gr->gr_mem = mem; + return 0; +} + struct backend_ops dummy_ops = { .init = dummy_init, .term = dummy_term, .pwbyname = dummy_pwbyname, .pwbyuid = dummy_pwbyuid, .grbyname = dummy_grbyname, + .grbygid = dummy_grbygid, }; diff --git a/proto.h b/proto.h @@ -17,7 +17,7 @@ enum { GETPWBYUID = 1, GETGRBYNAME = 2, - GETGRBYUID = 3, + GETGRBYGID = 3, INITGROUPS = 15, }; diff --git a/req.c b/req.c @@ -180,6 +180,11 @@ process_req(int clifd, struct nscdreq *req, char *key) return replygr(clifd, &gr); else return replygr(clifd, NULL); + case GETGRBYGID: + if (!backends_grbygid(key, &gr)) + return replygr(clifd, &gr); + else + return replygr(clifd, NULL); } if (debug) diff --git a/waffle.h b/waffle.h @@ -11,6 +11,7 @@ struct backend_ops { int (*pwbyname)(const char *, struct passwd *); int (*pwbyuid)(uid_t, struct passwd *); int (*grbyname)(const char *, struct group *); + int (*grbygid)(gid_t, struct group *); }; /* nscd.c */ @@ -28,3 +29,4 @@ void backends_term(void); int backends_pwbyname(const char *, struct passwd *); int backends_pwbyuid(const char *, struct passwd *); int backends_grbyname(const char *, struct group *); +int backends_grbygid(const char *, struct group *);