summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2008-10-13 07:01:13 -0400
committerSimo Sorce <idra@samba.org>2008-10-13 07:01:13 -0400
commit56ae64b3f5116004a0023abdbd9163ba7c97c746 (patch)
tree9af8c937538588895f8bb5692640758ae06aca85
parent6389867a6038c8ae3b8bd1ea88726f3b650d067b (diff)
downloadsssd-56ae64b3f5116004a0023abdbd9163ba7c97c746.tar.gz
sssd-56ae64b3f5116004a0023abdbd9163ba7c97c746.tar.bz2
sssd-56ae64b3f5116004a0023abdbd9163ba7c97c746.zip
Implement getgrgid()
-rw-r--r--server/nss/nss_ldb.h2
-rw-r--r--server/nss/nsssrv_cmd.c32
-rw-r--r--server/nss/nsssrv_ldb.c24
-rw-r--r--server/nss/nsssrv_ldb.h6
4 files changed, 62 insertions, 2 deletions
diff --git a/server/nss/nss_ldb.h b/server/nss/nss_ldb.h
index 3dbe70d9..13e5a672 100644
--- a/server/nss/nss_ldb.h
+++ b/server/nss/nss_ldb.h
@@ -11,7 +11,7 @@
#define NSS_GRNAM_FILTER "(&(objectclass=group)(gid=%s))"
#define NSS_GRNA2_FILTER "(&(objectclass=user)(memberof=%s))"
-#define NSS_GRUID_FILTER "(&(objectclass=group)(gidNumber=%llu))"
+#define NSS_GRGID_FILTER "(&(objectclass=group)(gidNumber=%llu))"
#define NSS_GRENT_FILTER "(objectclass=group)"
#define NSS_PW_ATTRS {NSS_PW_NAME, NSS_PW_UIDNUM, NSS_PW_GIDNUM, \
diff --git a/server/nss/nsssrv_cmd.c b/server/nss/nsssrv_cmd.c
index b8183e00..6252ab4a 100644
--- a/server/nss/nsssrv_cmd.c
+++ b/server/nss/nsssrv_cmd.c
@@ -619,7 +619,7 @@ static int nss_cmd_getgrnam(struct cli_ctx *cctx)
int ret;
const char *name;
- /* get user name to query */
+ /* get group name to query */
nss_packet_get_body(cctx->creq->in, &body, &blen);
name = (const char *)body;
/* if not terminated fail */
@@ -639,6 +639,35 @@ static int nss_cmd_getgrnam(struct cli_ctx *cctx)
return ret;
}
+static int nss_cmd_getgrgid(struct cli_ctx *cctx)
+{
+ struct nss_cmd_ctx *nctx;
+ uint8_t *body;
+ size_t blen;
+ int ret;
+ uint64_t gid;
+
+ /* get gid to query */
+ nss_packet_get_body(cctx->creq->in, &body, &blen);
+
+ if (blen != sizeof(uint64_t)) {
+ return EINVAL;
+ }
+
+ gid = *((uint64_t *)body);
+
+ nctx = talloc(cctx, struct nss_cmd_ctx);
+ if (!nctx) {
+ return ENOMEM;
+ }
+ nctx->cctx = cctx;
+
+ ret = nss_ldb_getgrgid(nctx, cctx->ev, cctx->ldb, gid,
+ nss_cmd_getgr_callback, nctx);
+
+ return ret;
+}
+
struct nss_cmd_table nss_cmds[] = {
{SSS_NSS_GET_VERSION, nss_cmd_get_version},
{SSS_NSS_GETPWNAM, nss_cmd_getpwnam},
@@ -647,6 +676,7 @@ struct nss_cmd_table nss_cmds[] = {
{SSS_NSS_GETPWENT, nss_cmd_getpwent},
{SSS_NSS_ENDPWENT, nss_cmd_endpwent},
{SSS_NSS_GETGRNAM, nss_cmd_getgrnam},
+ {SSS_NSS_GETGRGID, nss_cmd_getgrgid},
{SSS_NSS_NULL, NULL}
};
diff --git a/server/nss/nsssrv_ldb.c b/server/nss/nsssrv_ldb.c
index 04225e00..dce8d48b 100644
--- a/server/nss/nsssrv_ldb.c
+++ b/server/nss/nsssrv_ldb.c
@@ -364,6 +364,30 @@ int nss_ldb_getgrnam(TALLOC_CTX *mem_ctx,
return grp_search(sctx, ldb, expression);
}
+int nss_ldb_getgrgid(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct ldb_context *ldb,
+ uint64_t gid,
+ nss_ldb_callback_t fn, void *ptr)
+{
+ struct nss_ldb_search_ctx *sctx;
+ unsigned long long int filter_gid = gid;
+ char *expression;
+
+ sctx = init_sctx(mem_ctx, ldb, fn, ptr);
+ if (!sctx) {
+ return ENOMEM;
+ }
+
+ expression = talloc_asprintf(sctx, NSS_GRGID_FILTER, filter_gid);
+ if (!expression) {
+ talloc_free(sctx);
+ return ENOMEM;
+ }
+
+ return grp_search(sctx, ldb, expression);
+}
+
int nss_ldb_init(TALLOC_CTX *mem_ctx,
struct event_context *ev,
diff --git a/server/nss/nsssrv_ldb.h b/server/nss/nsssrv_ldb.h
index 9998714a..ebb97255 100644
--- a/server/nss/nsssrv_ldb.h
+++ b/server/nss/nsssrv_ldb.h
@@ -39,3 +39,9 @@ int nss_ldb_getgrnam(TALLOC_CTX *mem_ctx,
const char *name,
nss_ldb_callback_t fn, void *ptr);
+int nss_ldb_getgrgid(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct ldb_context *ldb,
+ uint64_t gid,
+ nss_ldb_callback_t fn, void *ptr);
+