summaryrefslogtreecommitdiffstats
path: root/server/nss/nsssrv_cmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/nss/nsssrv_cmd.c')
-rw-r--r--server/nss/nsssrv_cmd.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/server/nss/nsssrv_cmd.c b/server/nss/nsssrv_cmd.c
index 0e1cd8ceb..74fdb2278 100644
--- a/server/nss/nsssrv_cmd.c
+++ b/server/nss/nsssrv_cmd.c
@@ -83,6 +83,7 @@ static int nss_cmd_get_version(struct cli_ctx *cctx)
***************************************************************************/
static int fill_pwent(struct nss_packet *packet,
+ struct nss_ldb_ctx *lctx,
struct ldb_message **msgs,
int count)
{
@@ -106,12 +107,12 @@ static int fill_pwent(struct nss_packet *packet,
for (i = 0; i < count; i++) {
msg = msgs[i];
- name = ldb_msg_find_attr_as_string(msg, NSS_PW_NAME, NULL);
- fullname = ldb_msg_find_attr_as_string(msg, NSS_PW_FULLNAME, NULL);
- homedir = ldb_msg_find_attr_as_string(msg, NSS_PW_HOMEDIR, NULL);
- shell = ldb_msg_find_attr_as_string(msg, NSS_PW_SHELL, NULL);
- uid = ldb_msg_find_attr_as_uint64(msg, NSS_PW_UIDNUM, 0);
- gid = ldb_msg_find_attr_as_uint64(msg, NSS_PW_GIDNUM, 0);
+ name = ldb_msg_find_attr_as_string(msg, lctx->pw_name, NULL);
+ fullname = ldb_msg_find_attr_as_string(msg, lctx->pw_fullname, NULL);
+ homedir = ldb_msg_find_attr_as_string(msg, lctx->pw_homedir, NULL);
+ shell = ldb_msg_find_attr_as_string(msg, lctx->pw_shell, NULL);
+ uid = ldb_msg_find_attr_as_uint64(msg, lctx->pw_uidnum, 0);
+ gid = ldb_msg_find_attr_as_uint64(msg, lctx->pw_gidnum, 0);
if (!name || !fullname || !homedir || !shell || !uid || !gid) {
DEBUG(1, ("Incomplete user object for %s[%llu]! Skipping\n",
@@ -198,7 +199,7 @@ static int nss_cmd_getpw_callback(void *ptr, int status,
goto done;
}
- ret = fill_pwent(cctx->creq->out, res->msgs, res->count);
+ ret = fill_pwent(cctx->creq->out, cctx->lctx, res->msgs, res->count);
nss_packet_set_error(cctx->creq->out, ret);
done:
@@ -228,7 +229,7 @@ static int nss_cmd_getpwnam(struct cli_ctx *cctx)
}
nctx->cctx = cctx;
- ret = nss_ldb_getpwnam(nctx, cctx->ev, cctx->ldb, name,
+ ret = nss_ldb_getpwnam(nctx, cctx->ev, cctx->lctx, name,
nss_cmd_getpw_callback, nctx);
return ret;
@@ -257,7 +258,7 @@ static int nss_cmd_getpwuid(struct cli_ctx *cctx)
}
nctx->cctx = cctx;
- ret = nss_ldb_getpwuid(nctx, cctx->ev, cctx->ldb, uid,
+ ret = nss_ldb_getpwuid(nctx, cctx->ev, cctx->lctx, uid,
nss_cmd_getpw_callback, nctx);
return ret;
@@ -328,7 +329,7 @@ static int nss_cmd_setpwent(struct cli_ctx *cctx)
cctx->gctx->pwd_cur = 0;
}
- ret = nss_ldb_enumpwent(nctx, cctx->ev, cctx->ldb,
+ ret = nss_ldb_enumpwent(nctx, cctx->ev, cctx->lctx,
nss_cmd_setpwent_callback, nctx);
return ret;
@@ -342,7 +343,8 @@ static int nss_cmd_retpwent(struct cli_ctx *cctx, int num)
n = gctx->pwds->count - gctx->pwd_cur;
if (n > num) n = num;
- ret = fill_pwent(cctx->creq->out, &(gctx->pwds->msgs[gctx->pwd_cur]), n);
+ ret = fill_pwent(cctx->creq->out, cctx->lctx,
+ &(gctx->pwds->msgs[gctx->pwd_cur]), n);
gctx->pwd_cur += n;
return ret;
@@ -424,7 +426,7 @@ static int nss_cmd_getpwent(struct cli_ctx *cctx)
cctx->gctx = gctx;
}
if (cctx->gctx->pwds == NULL) {
- ret = nss_ldb_enumpwent(nctx, cctx->ev, cctx->ldb,
+ ret = nss_ldb_enumpwent(nctx, cctx->ev, cctx->lctx,
nss_cmd_getpwent_callback, nctx);
return ret;
}
@@ -478,6 +480,7 @@ done:
***************************************************************************/
static int fill_grent(struct nss_packet *packet,
+ struct nss_ldb_ctx *lctx,
struct ldb_message **msgs,
int count)
{
@@ -500,8 +503,8 @@ static int fill_grent(struct nss_packet *packet,
if (get_group) {
/* find group name/gid */
- name = ldb_msg_find_attr_as_string(msg, NSS_GR_NAME, NULL);
- gid = ldb_msg_find_attr_as_uint64(msg, NSS_GR_GIDNUM, 0);
+ name = ldb_msg_find_attr_as_string(msg, lctx->gr_name, NULL);
+ gid = ldb_msg_find_attr_as_uint64(msg, lctx->gr_gidnum, 0);
if (!name || !gid) {
DEBUG(1, ("Incomplete group object for %s[%llu]! Aborting\n",
name?name:"<NULL>", (unsigned long long int)gid));
@@ -529,7 +532,7 @@ static int fill_grent(struct nss_packet *packet,
continue;
}
- name = ldb_msg_find_attr_as_string(msg, NSS_PW_NAME, NULL);
+ name = ldb_msg_find_attr_as_string(msg, lctx->pw_name, NULL);
if (!name) {
/* last member of previous group found, or error.
@@ -607,7 +610,7 @@ static int nss_cmd_getgr_callback(void *ptr, int status,
goto done;
}
- ret = fill_grent(cctx->creq->out, res->msgs, res->count);
+ ret = fill_grent(cctx->creq->out, cctx->lctx, res->msgs, res->count);
nss_packet_set_error(cctx->creq->out, ret);
done:
@@ -637,7 +640,7 @@ static int nss_cmd_getgrnam(struct cli_ctx *cctx)
}
nctx->cctx = cctx;
- ret = nss_ldb_getgrnam(nctx, cctx->ev, cctx->ldb, name,
+ ret = nss_ldb_getgrnam(nctx, cctx->ev, cctx->lctx, name,
nss_cmd_getgr_callback, nctx);
return ret;
@@ -666,7 +669,7 @@ static int nss_cmd_getgrgid(struct cli_ctx *cctx)
}
nctx->cctx = cctx;
- ret = nss_ldb_getgrgid(nctx, cctx->ev, cctx->ldb, gid,
+ ret = nss_ldb_getgrgid(nctx, cctx->ev, cctx->lctx, gid,
nss_cmd_getgr_callback, nctx);
return ret;
@@ -737,7 +740,7 @@ static int nss_cmd_setgrent(struct cli_ctx *cctx)
cctx->gctx->grp_cur = 0;
}
- ret = nss_ldb_enumgrent(nctx, cctx->ev, cctx->ldb,
+ ret = nss_ldb_enumgrent(nctx, cctx->ev, cctx->lctx,
nss_cmd_setgrent_callback, nctx);
return ret;
@@ -751,7 +754,8 @@ static int nss_cmd_retgrent(struct cli_ctx *cctx, int num)
n = gctx->grps->count - gctx->grp_cur;
if (n > num) n = num;
- ret = fill_grent(cctx->creq->out, &(gctx->grps->msgs[gctx->grp_cur]), n);
+ ret = fill_grent(cctx->creq->out, cctx->lctx,
+ &(gctx->grps->msgs[gctx->grp_cur]), n);
gctx->grp_cur += n;
return ret;
@@ -833,7 +837,7 @@ static int nss_cmd_getgrent(struct cli_ctx *cctx)
cctx->gctx = gctx;
}
if (cctx->gctx->grps == NULL) {
- ret = nss_ldb_enumgrent(nctx, cctx->ev, cctx->ldb,
+ ret = nss_ldb_enumgrent(nctx, cctx->ev, cctx->lctx,
nss_cmd_getgrent_callback, nctx);
return ret;
}
@@ -887,6 +891,7 @@ static int nss_cmd_initgr_callback(void *ptr, int status,
{
struct nss_cmd_ctx *nctx = talloc_get_type(ptr, struct nss_cmd_ctx);
struct cli_ctx *cctx = nctx->cctx;
+ struct nss_ldb_ctx *lctx = cctx->lctx;
uint8_t *body;
size_t blen;
uint64_t gid;
@@ -917,7 +922,7 @@ static int nss_cmd_initgr_callback(void *ptr, int status,
nss_packet_get_body(cctx->creq->out, &body, &blen);
for (i = 0; i < num; i++) {
- gid = ldb_msg_find_attr_as_uint64(res->msgs[i], NSS_GR_GIDNUM, 0);
+ gid = ldb_msg_find_attr_as_uint64(res->msgs[i], lctx->gr_gidnum, 0);
if (!gid) {
DEBUG(1, ("Incomplete group object for initgroups! Aborting\n"));
nss_packet_set_error(cctx->creq->out, EIO);
@@ -957,7 +962,7 @@ static int nss_cmd_initgroups(struct cli_ctx *cctx)
}
nctx->cctx = cctx;
- ret = nss_ldb_initgroups(nctx, cctx->ev, cctx->ldb, name,
+ ret = nss_ldb_initgroups(nctx, cctx->ev, cctx->lctx, name,
nss_cmd_initgr_callback, nctx);
return ret;