nsssrv_cmd.c revision 9f26cae5ae716a0542261167b5a91d7d2e1763e7
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maeder NSS Responder
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maeder Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maeder This program is free software; you can redistribute it and/or modify
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maeder it under the terms of the GNU General Public License as published by
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maeder the Free Software Foundation; either version 3 of the License, or
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maeder (at your option) any later version.
486db0a875bcdd0b80cf0d447d14c9c00a92ae94Simon Ulbricht This program is distributed in the hope that it will be useful,
486db0a875bcdd0b80cf0d447d14c9c00a92ae94Simon Ulbricht but WITHOUT ANY WARRANTY; without even the implied warranty of
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c208973c890b8f993297720fd0247bc7481d4304Christian Maeder GNU General Public License for more details.
863c98ae89e37c21c0c04b9b130b5136688976eeChristian Maeder You should have received a copy of the GNU General Public License
486db0a875bcdd0b80cf0d447d14c9c00a92ae94Simon Ulbricht along with this program. If not, see <http://www.gnu.org/licenses/>.
df0e8744a2befcba003ea6d93214601c743bde74Christian Maeder#include "responder/nss/nsssrv_mmap_cache.h"
bea536c79193020edac8fc6ebdd51b11f885b5afChristian Maederstatic int nss_cmd_send_error(struct nss_cmd_ctx *cmdctx, int err)
863c98ae89e37c21c0c04b9b130b5136688976eeChristian Maeder return sss_cmd_send_error(cmdctx->cctx, err);
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maederstatic int nss_cmd_send_empty(struct nss_cmd_ctx *cmdctx)
e46d78f7c6324ed9f1a191d46b6e5732e61e1835Simon Ulbrichtint nss_cmd_done(struct nss_cmd_ctx *cmdctx, int ret)
3ddbdc6f84dbf9a59e178575db8359d3aab1dd2fChristian Maeder /* all fine, just return here */
46b207daf66b64930a59f3615c8b127aac0b8e43Christian Maeder /* async processing, just return here */
f0d823af5e37881b77328bbcff8c96b58b92c89fChristian Maeder /* very bad error */
081deee1bac477ab8db717646baba47f0fe95479Christian Maeder/***************************
081deee1bac477ab8db717646baba47f0fe95479Christian Maeder * Enumeration procedures *
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder ***************************/
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maedererrno_t nss_setent_add_ref(TALLOC_CTX *memctx,
5b68f1141555736e0b7ddbe14218bcabcc44636fChristian Maeder return setent_add_ref(memctx, getent_ctx, &getent_ctx->reqs, req);
5b68f1141555736e0b7ddbe14218bcabcc44636fChristian Maedervoid nss_setent_notify_error(struct getent_ctx *getent_ctx, errno_t ret)
595bf3e172e12ef62c72b9a87ff7aedbfed416ffSimon Ulbricht return setent_notify(&getent_ctx->reqs, ret);
595bf3e172e12ef62c72b9a87ff7aedbfed416ffSimon Ulbrichtvoid nss_setent_notify_done(struct getent_ctx *getent_ctx)
4e1239f8b5fa139bd9be8d0431d711c7b88a58c2Christian Maeder return setent_notify_done(&getent_ctx->reqs);
deb58cca57a0ec5eacf69ec6770d70b4701fa8b4Christian Maeder/****************************************************************************
e3d7fd1b63d824960b1c17b6c7009d52d7528c1eChristian Maeder * PASSWD db related functions
e46d78f7c6324ed9f1a191d46b6e5732e61e1835Simon Ulbricht ***************************************************************************/
e46d78f7c6324ed9f1a191d46b6e5732e61e1835Simon Ulbrichtstatic gid_t get_gid_override(struct ldb_message *msg,
863c98ae89e37c21c0c04b9b130b5136688976eeChristian Maeder ldb_msg_find_attr_as_uint64(msg, SYSDB_GIDNUM, 0);
62631c8934cb171853a6c3d7910d1cd335007bf5Christian Maederstatic const char *get_homedir_override(TALLOC_CTX *mem_ctx,
34db68bf7b0a0cb624373cc364a56442c1b3f0f7Christian Maeder /* Check whether we are unconditionally overriding the server
34db68bf7b0a0cb624373cc364a56442c1b3f0f7Christian Maeder * for home directory locations.
0607966fab6924a9fda8b55a9dccb28236a856deSimon Ulbricht return expand_homedir_template(mem_ctx, dom->override_homedir,
863c98ae89e37c21c0c04b9b130b5136688976eeChristian Maeder return expand_homedir_template(mem_ctx, nctx->override_homedir,
c62c1b82e3316ff978475d6e61a5ed172fe60b0bChristian Maeder homedir = ldb_msg_find_attr_as_string(msg, SYSDB_HOMEDIR, NULL);
eccd7c7446e270bda674c07248d04fccc41cba0bSimon Ulbricht /* In the case of a NULL or empty homedir, check to see if
dd8d2aeeb3648de87bd70d261a9e0a49b8239f4bSimon Ulbricht * we have a fallback homedir to use.
eccd7c7446e270bda674c07248d04fccc41cba0bSimon Ulbricht return expand_homedir_template(mem_ctx, dom->fallback_homedir,
bea536c79193020edac8fc6ebdd51b11f885b5afChristian Maeder return expand_homedir_template(mem_ctx, nctx->fallback_homedir,
bea536c79193020edac8fc6ebdd51b11f885b5afChristian Maeder /* Return the value we got from the provider */
c62c1b82e3316ff978475d6e61a5ed172fe60b0bChristian Maederstatic const char *get_shell_override(TALLOC_CTX *mem_ctx,
54233d1f5ebf82ebb341a0f481e8ae657fc90e91Christian Maeder user_shell = ldb_msg_find_attr_as_string(msg, SYSDB_SHELL, NULL);
54233d1f5ebf82ebb341a0f481e8ae657fc90e91Christian Maeder /* Check whether there is a default shell specified */
54233d1f5ebf82ebb341a0f481e8ae657fc90e91Christian Maeder return talloc_strdup(mem_ctx, nctx->default_shell);
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder if (!nctx->allowed_shells && !nctx->vetoed_shells) return talloc_strdup(mem_ctx, user_shell);
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder if (strcmp(nctx->vetoed_shells[i], user_shell) == 0) {
486db0a875bcdd0b80cf0d447d14c9c00a92ae94Simon Ulbricht return talloc_strdup(mem_ctx, nctx->shell_fallback);
c30231257d9116b514dce02703a515fe21cd427dTill Mossakowski if (strcmp(user_shell, nctx->etc_shells[i]) == 0) {
62631c8934cb171853a6c3d7910d1cd335007bf5Christian Maeder DEBUG(9, ("Using original shell '%s'\n", user_shell));
62631c8934cb171853a6c3d7910d1cd335007bf5Christian Maeder if (strcmp(nctx->allowed_shells[i], user_shell) == 0) {
62631c8934cb171853a6c3d7910d1cd335007bf5Christian Maeder DEBUG(5, ("The shell '%s' is allowed but does not exist. "
62631c8934cb171853a6c3d7910d1cd335007bf5Christian Maeder return talloc_strdup(mem_ctx, nctx->shell_fallback);
62631c8934cb171853a6c3d7910d1cd335007bf5Christian Maeder DEBUG(5, ("The shell '%s' is not allowed and does not exist.\n",
fbb98c3714200d240ae693dc673cc36198cff2f5Till Mossakowski return talloc_strdup(mem_ctx, NOLOGIN_SHELL);
9dd36c71632e08a1bf73b7bf4a61380e3474758aChristian Maederstatic int fill_pwent(struct sss_packet *packet,
int *count)
const char *tmpstr;
const char *orig_name;
bool packet_initialized = false;
int ncret;
num = 0;
for (i = 0; i < *count; i++) {
if (filter_users) {
if (!packet_initialized) {
packet_initialized = true;
if (!tmpstr) {
if (!tmpstr) {
if (!tmpstr) {
num = 0;
goto done;
if (add_domain) {
num = 0;
goto done;
delim += t;
num++;
done:
*count = i;
return EOK;
int ret;
return EFAULT;
if (ret) {
return ret;
return EOK;
int req_type,
const char *opt_name,
void *pvt)
return ENOENT;
if (cacheExpire == 0) {
SYSDB_CACHE_EXPIRE, 0);
return EOK;
goto error;
if (!req) {
if (!req) {
goto error;
if(!cb_ctx) {
goto error;
return EAGAIN;
return EOK;
return EOK;
char *err_msg;
&err_msg);
int ret;
while (dom) {
if (!dom) break;
return ENOENT;
return EIO;
return EIO;
return ENOENT;
return ret;
if (dom) continue;
return ENOENT;
dctx);
return ret;
return EOK;
return ENOENT;
int ret;
if (err_maj) {
goto done;
goto done;
done:
if (ret) {
const char *rawname;
char *domname;
int ret;
if (!cmdctx) {
return ENOMEM;
if (!dctx) {
goto done;
goto done;
goto done;
goto done;
if (domname) {
goto done;
goto done;
done:
goto done;
goto done;
done:
int ret;
while (dom) {
return ENOENT;
return EIO;
return EIO;
return ENOENT;
return ret;
return ENOENT;
dctx);
return ret;
return EOK;
return ENOENT;
int ret;
if (err_maj) {
goto done;
goto done;
done:
if (ret) {
int ret;
if (!cmdctx) {
return ENOMEM;
if (!dctx) {
goto done;
goto done;
goto done;
done:
if (!cmdctx) {
return ENOMEM;
if (!req) {
goto done;
done:
if (!req) {
return NULL;
goto error;
goto error;
return NULL;
return req;
goto error;
if (!step_ctx) {
goto error;
return req;
return req;
void *pvt);
while (dom) {
if (!dom) break;
return EIO;
if (!dpreq) {
if(!cb_ctx) {
return ENOMEM;
return EAGAIN;
return ENOMEM;
if (!te) {
return EAGAIN;
return EOK;
void *pvt)
int ret;
if (err_maj) {
return EOK;
if (!cmdctx) {
return ENOMEM;
if (!req) {
return EIO;
return EOK;
int ret;
return EINVAL;
return ret;
return EOK;
true, false, msgs, &n);
none:
return ret;
int ret;
return ret;
done:
return EOK;
#define GID_ROFFSET 0
int *_memnum)
char *tmpstr;
if (add_domain) {
delim = 0;
dom_len = 0;
return ENOMEM;
if (add_domain) {
goto done;
if (add_domain) {
goto done;
delim += t;
goto done;
if (add_domain) {
memnum++;
done:
return ret;
int *count)
const char *tmpstr;
const char *orig_name;
if (add_domain) {
delim = 0;
dom_len = 0;
num = 0;
goto done;
rsize = 0;
for (i = 0; i < *count; i++) {
rsize = 0;
if (filter_groups) {
num = 0;
goto done;
if (add_domain) {
num = 0;
goto done;
rsize += t;
delim += t;
num = 0;
goto done;
rsize = 0;
memnum = 0;
if (el) {
num = 0;
goto done;
if (el) {
num = 0;
goto done;
if (memnum) {
num++;
done:
*count = i;
if (num == 0) {
return ENOENT;
return EOK;
int ret;
return EFAULT;
if (ret) {
return ret;
return EOK;
int ret;
while (dom) {
if (!dom) break;
return ENOENT;
return EIO;
return EIO;
return ENOENT;
return ret;
if (dom) continue;
return ENOENT;
dctx);
return ret;
return EOK;
return ENOENT;
int ret;
if (err_maj) {
goto done;
goto done;
done:
if (ret) {
const char *rawname;
char *domname;
int ret;
if (!cmdctx) {
return ENOMEM;
if (!dctx) {
goto done;
goto done;
goto done;
goto done;
if (domname) {
goto done;
goto done;
done:
goto done;
goto done;
done:
int ret;
while (dom) {
return ENOENT;
return EIO;
return EIO;
return ENOENT;
return ret;
return ENOENT;
dctx);
return ret;
return EOK;
return ENOENT;
int ret;
if (err_maj) {
goto done;
goto done;
done:
if (ret) {
int ret;
if (!cmdctx) {
return ENOMEM;
if (!dctx) {
goto done;
goto done;
goto done;
done:
if (!cmdctx) {
return ENOMEM;
if (!req) {
goto done;
done:
if (!req) {
return NULL;
goto error;
goto error;
return NULL;
return req;
goto error;
if (!step_ctx) {
goto error;
return req;
return req;
void *pvt);
while (dom) {
if (!dom) break;
return EIO;
if (!dpreq) {
if(!cb_ctx) {
return ENOMEM;
return EAGAIN;
return ENOMEM;
if (!te) {
return EAGAIN;
return EOK;
void *pvt)
int ret;
if (err_maj) {
return EOK;
none:
return ret;
int ret;
return EINVAL;
return ret;
return EOK;
if (!cmdctx) {
return ENOMEM;
if (!req) {
return EIO;
return EOK;
int ret;
return ret;
done:
return EOK;
int skipped = 0;
const char *posix;
return ENOENT;
return ret;
bindex = 0;
for (i = 0; i < num; i++) {
if (!gid) {
skipped++;
return EFAULT;
bindex++;
return EOK;
int ret;
return EFAULT;
if (ret) {
return ret;
return EOK;
int ret;
while (dom) {
if (!dom) break;
return ENOENT;
return EIO;
return EIO;
return ret;
if (dom) continue;
return ENOENT;
dctx);
return ret;
return EOK;
return ENOENT;
int ret;
if (err_maj) {
goto done;
goto done;
done:
if (ret) {
const char *rawname;
char *domname;
int ret;
if (!cmdctx) {
return ENOMEM;
if (!dctx) {
goto done;
goto done;
goto done;
goto done;
if (domname) {
goto done;
goto done;
done:
goto done;
goto done;
done:
return nss_cli_protocol_version;
return nss_cmds;
return EINVAL;