nsssrv_cmd.c revision b8f07efe5d98071777e3a2863688c8269a7912e4
/*
SSSD
NSS Responder
Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "util/btreemap.h"
#include <time.h>
struct nss_cmd_ctx {
const char *name;
bool immediate;
bool done;
int nr;
};
struct getent_ctx {
struct ldb_result *pwds;
struct ldb_result *grps;
int pwd_cur;
int grp_cur;
};
struct nss_dom_ctx {
struct nss_cmd_ctx *cmdctx;
const char *domain;
bool check_provider;
bool legacy;
};
struct nss_cmd_table {
enum sss_nss_command cmd;
};
{
/* now that the packet is in place, unlock queue
* making the event writable */
/* free all request related data through the talloc hierarchy */
}
{
int ret;
/* create response packet */
return ret;
}
return EOK;
}
#define NSS_CMD_FATAL_ERROR(cctx) do { \
talloc_free(cctx); \
return; \
} while(0)
{
struct nss_domain_info *info;
struct btreemap *domain_map;
char *delim;
char *domain;
} else {
}
/* Check for registered domain */
if (!info) {
/* No such domain was registered. Return EINVAL.
* TODO: alternative approach?
* Alternatively, we could simply fail down to
* below, treating the entire construct as the
* full name if the domain is unspecified.
*/
return EINVAL;
}
if (delim) {
} else {
}
return EOK;
}
{
struct nss_cmd_ctx *cmdctx;
int ret;
if (!cmdctx) {
return ENOMEM;
}
/* create response packet */
return ret;
}
return EOK;
}
/****************************************************************************
* PASSWD db related functions
***************************************************************************/
struct ldb_message **msgs,
int count)
{
struct ldb_message *msg;
const char *name;
const char *fullname;
const char *homedir;
const char *shell;
/* first 2 fields (len and reserved), filled up later */
num = 0;
for (i = 0; i < count; i++) {
continue;
}
num = 0;
goto done;
}
rp += 2;
num++;
}
done:
return EOK;
}
struct ldb_result *res)
{
int timeout;
bool call_provider = false;
int ret;
if (status != LDB_SUCCESS) {
}
goto done;
}
if (dctx->check_provider) {
case 0:
call_provider = true;
break;
case 1:
SYSDB_LAST_UPDATE, 0);
call_provider = true;
}
break;
default:
}
goto done;
}
}
if (call_provider) {
/* dont loop forever :-) */
dctx->check_provider = false;
}
goto done;
}
return;
}
case 0:
}
break;
case 1:
/* create response packet */
}
break;
default:
}
}
done:
}
{
int ret;
if (err_maj) {
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
}
}
}
}
{
struct nss_cmd_ctx *cmdctx;
struct nss_dom_ctx *dctx;
int ret;
if (!cmdctx) {
return ENOMEM;
}
/* get user name to query */
/* if not terminated fail */
return EINVAL;
}
return ret;
}
}
return ret;
}
return EOK;
}
struct ldb_result *res)
{
int timeout;
bool call_provider = false;
int ret;
/* one less to go */
/* check if another callback already replied */
/* now check if this is the last callback */
/* ok we are really done with this request */
goto done;
}
}
if (status != LDB_SUCCESS) {
}
goto done;
}
if (dctx->check_provider) {
case 0:
call_provider = true;
break;
case 1:
SYSDB_LAST_UPDATE, 0);
call_provider = true;
}
break;
default:
}
goto done;
}
}
if (call_provider) {
/* yet one more call to go */
/* dont loop forever :-) */
dctx->check_provider = false;
}
goto done;
}
return;
}
case 0:
/* nothing to do */
return;
}
}
break;
case 1:
/* create response packet */
}
break;
default:
}
}
done:
return;
}
}
{
int ret;
if (err_maj) {
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
}
}
return;
}
}
}
{
struct nss_cmd_ctx *cmdctx;
struct nss_dom_ctx *dctx;
struct nss_domain_info *info;
const char **domains;
if (!cmdctx) {
return ENOMEM;
}
/* get uid to query */
return EINVAL;
}
/* FIXME: Just ask all backends for now, until we check for ranges */
num = 0;
/* get domains list */
for (i = 0; i < num; i++) {
/* shutdown ? */
}
return ret;
}
}
return EOK;
}
/* to keep it simple at this stage we are retrieving the
* full enumeration again for each request for each process
* and we also block on setpwent() for the full time needed
* to retrieve the data. And endpwent() frees all the data.
* Next steps are:
* - use an nsssrv wide cache with data already structured
* so that it can be immediately returned (see nscd way)
* - use mutexes so that setpwent() can return immediately
* even if the data is still being fetched
* - make getpwent() wait on the mutex
*/
struct ldb_result *res);
struct ldb_result *res)
{
int i, j, c, ret;
/* do not reply until all domain searches are done */
else goto done;
}
if (status != LDB_SUCCESS) {
/* create response packet */
}
return;
}
if (store) {
struct ldb_message *, c);
}
} else {
}
/* do not reply until all domain searches are done */
/* this was a getpwent call w/o setpwent,
* return immediately one result */
return;
}
/* create response packet */
}
done:
}
{
int ret;
if (err_maj) {
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
}
}
}
}
{
struct nss_domain_info *info;
struct nss_cmd_ctx *cmdctx;
struct nss_dom_ctx *dctx;
struct getent_ctx *gctx;
const char **domains;
int timeout;
if (!cmdctx) {
return ENOMEM;
}
if (!gctx) {
return ENOMEM;
}
}
}
num = 0;
/* get domains list */
/* check if enumeration is enabled in any domain */
for (i = 0; i < num; i++) {
continue;
}
/* TODO: enabled, check if we have a recent cached enumeration */
/* ok no cache, go and ask the backend to enumerate */
if (dctx->check_provider) {
NULL, 0);
} else {
}
/* FIXME: shutdown ? */
domains[i]));
continue;
}
/* number of replies to wait for before setpwent is done */
}
/* create response packet */
return ret;
}
return EOK;
}
return ret;
}
{
return nss_cmd_setpwent_ext(cctx, false);
}
{
int n, ret;
return ret;
}
/* used only if a process calls getpwent() without first calling setpwent()
*/
struct ldb_result *res)
{
int ret;
/* get max num of entries to return in one call */
}
/* create response packet */
}
if (status != LDB_SUCCESS) {
goto done;
}
done:
}
{
struct nss_cmd_ctx *cmdctx;
struct getent_ctx *gctx;
int ret;
/* get max num of entries to return in one call */
return EINVAL;
}
/* see if we need to trigger an implicit setpwent() */
if (!gctx) {
return ENOMEM;
}
}
return ret;
}
}
if (!cmdctx) {
return ENOMEM;
}
/* create response packet */
return ret;
}
return EOK;
}
{
struct nss_cmd_ctx *cmdctx;
int ret;
if (!cmdctx) {
return ENOMEM;
}
/* create response packet */
/* free results and reset */
done:
return EOK;
}
/****************************************************************************
* GROUP db related functions
***************************************************************************/
struct ldb_message **msgs,
int count)
{
struct ldb_message_element *el;
struct ldb_message *msg;
const char *name;
bool get_group = true;
bool memnum_set = false;
/* first 2 fields (len and reserved), filled up later */
num = 0;
mnump = 0;
for (i = 0; i < count; i++) {
if (get_group) {
num = 0;
goto done;
}
/* fill in gid and name and set pointer for number of members */
memnum_set = false;
memnum = 0;
num++;
/* legacy style group, members are in SYSDB_LEGACY_MEMBER */
if (el) {
/* legacy */
for (j = 0; j < memnum; j++) {
num = 0;
goto done;
}
}
memnum_set = true;
} else {
get_group = false;
}
continue;
}
if (!name) {
/* last member of previous group found, or error.
* set next element to be a group, and eventually
* fail there if here start bogus entries */
get_group = true;
i--;
memnum_set = true;
continue;
}
num = 0;
goto done;
}
memnum++;
}
if (!memnum_set) {
/* fill in the last group member count */
if (mnump != 0) {
}
}
done:
return EOK;
}
struct ldb_result *res)
{
int timeout;
bool call_provider = false;
int ret;
if (status != LDB_SUCCESS) {
}
return;
}
if (dctx->check_provider) {
case 0:
call_provider = true;
break;
default:
SYSDB_LAST_UPDATE, 0);
call_provider = true;
}
}
}
if (call_provider) {
/* dont loop forever :-) */
dctx->check_provider = false;
}
goto done;
}
return;
}
case 0:
}
break;
default:
/* create response packet */
}
}
done:
}
{
int ret;
if (err_maj) {
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
}
}
}
}
{
struct nss_cmd_ctx *cmdctx;
struct nss_dom_ctx *dctx;
int ret;
if (!cmdctx) {
return ENOMEM;
}
/* get user name to query */
/* if not terminated fail */
return EINVAL;
}
return ret;
}
}
return ret;
}
return EOK;
}
struct ldb_result *res)
{
int timeout;
bool call_provider = false;
int ret;
/* one less to go */
/* check if another callback already replied */
/* now check if this is the last callback */
/* ok we are really done with this request */
goto done;
}
}
if (status != LDB_SUCCESS) {
}
goto done;
}
if (dctx->check_provider) {
case 0:
call_provider = true;
break;
default:
SYSDB_LAST_UPDATE, 0);
call_provider = true;
}
}
}
if (call_provider) {
/* yet one more call to go */
/* dont loop forever :-) */
dctx->check_provider = false;
}
goto done;
}
return;
}
case 0:
/* nothing to do */
return;
}
}
break;
default:
/* create response packet */
}
}
done:
return;
}
}
{
int ret;
if (err_maj) {
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
}
}
}
}
{
struct nss_cmd_ctx *cmdctx;
struct nss_dom_ctx *dctx;
struct nss_domain_info *info;
const char **domains;
if (!cmdctx) {
return ENOMEM;
}
/* get uid to query */
return EINVAL;
}
/* FIXME: Just ask all backends for now, until we check for ranges */
num = 0;
/* get domains list */
for (i = 0; i < num; i++) {
/* shutdown ? */
}
return ret;
}
}
return EOK;
}
/* to keep it simple at this stage we are retrieving the
* full enumeration again for each request for each process
* and we also block on setgrent() for the full time needed
* to retrieve the data. And endgrent() frees all the data.
* Next steps are:
* - use and nsssrv wide cache with data already structured
* so that it can be immediately returned (see nscd way)
* - use mutexes so that setgrent() can return immediately
* even if the data is still being fetched
* - make getgrent() wait on the mutex
*/
struct ldb_result *res);
struct ldb_result *res)
{
int i, j, c, ret;
/* do not reply until all domain searches are done */
else goto done;
}
if (status != LDB_SUCCESS) {
/* create response packet */
}
return;
}
if (store) {
struct ldb_message *, c);
}
} else {
}
/* do not reply until all domain searches are done */
/* this was a getgrent call w/o setgrent,
* return immediately one result */
return;
}
/* create response packet */
}
done:
}
{
int ret;
if (err_maj) {
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
}
}
}
}
{
struct nss_domain_info *info;
struct nss_cmd_ctx *cmdctx;
struct nss_dom_ctx *dctx;
struct getent_ctx *gctx;
const char **domains;
int timeout;
if (!cmdctx) {
return ENOMEM;
}
if (!gctx) {
return ENOMEM;
}
}
}
num = 0;
/* get domains list */
/* check if enumeration is enabled in any domain */
for (i = 0; i < num; i++) {
continue;
}
/* TODO: enabled, check if we have a recent cached enumeration */
/* ok no cache, go and ask the backend to enumerate */
if (dctx->check_provider) {
NULL, 0);
} else {
}
/* FIXME: shutdown ? */
domains[i]));
continue;
}
}
/* create response packet */
return ret;
}
return EOK;
}
return ret;
}
{
return nss_cmd_setgrent_ext(cctx, false);
}
{
int n, ret;
return ret;
}
/* used only if a process calls getpwent() without first calling setpwent()
* in this case we basically trigger an implicit setpwent() */
struct ldb_result *res)
{
int ret;
/* get max num of entries to return in one call */
}
}
/* create response packet */
}
if (status != LDB_SUCCESS) {
goto done;
}
done:
}
{
struct nss_cmd_ctx *cmdctx;
struct getent_ctx *gctx;
int ret;
/* get max num of entries to return in one call */
return EINVAL;
}
/* see if we need to trigger an implicit setpwent() */
if (!gctx) {
return ENOMEM;
}
}
return ret;
}
}
if (!cmdctx) {
return ENOMEM;
}
/* create response packet */
return ret;
}
return EOK;
}
{
struct nss_cmd_ctx *cmdctx;
int ret;
if (!cmdctx) {
return ENOMEM;
}
/* create response packet */
/* free results and reset */
done:
return EOK;
}
struct ldb_result *res)
{
int ret, i;
/* create response packet */
}
if (status != LDB_SUCCESS) {
goto done;
}
/* the first 64 bit uint is really 2 32 units used to hold the number of
* results */
goto done;
}
for (i = 0; i < num; i++) {
if (!gid) {
num = 0;
goto done;
}
}
done:
}
{
int ret;
if (err_maj) {
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
}
}
}
}
struct ldb_result *res);
{
int ret;
if (err_maj) {
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
}
}
}
}
struct ldb_result *res)
{
int timeout;
bool call_provider = false;
int ret;
if (status != LDB_SUCCESS) {
}
goto done;
}
if (dctx->check_provider) {
case 0:
call_provider = true;
break;
default:
SYSDB_LAST_UPDATE, 0);
call_provider = true;
}
}
}
if (call_provider) {
/* dont loop forever :-) */
dctx->check_provider = false;
}
goto done;
}
return;
}
case 0:
}
break;
case 1:
}
goto done;
}
return;
default:
}
}
done:
}
/* for now, if we are online, try to always query the backend */
{
struct nss_cmd_ctx *cmdctx;
struct nss_dom_ctx *dctx;
int ret;
if (!cmdctx) {
return ENOMEM;
}
/* get user name to query */
/* if not terminated fail */
return EINVAL;
}
return ret;
}
}
return ret;
}
return EOK;
}
struct nss_cmd_table nss_cmds[] = {
{SSS_NSS_NULL, NULL}
};
{
enum sss_nss_command cmd;
int i;
}
}
return EINVAL;
}