negcache.c revision d338bb46b8c03c33e6182e725911af6d778bcf00
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder/*
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder SSSD
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski NSS Responder
2725abe920f91de62ae5c0b7230c1627cccf5fabChristian Maeder
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
3f69b6948966979163bdfe8331c38833d5d90ecdChristian Maeder This program is free software; you can redistribute it and/or modify
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder it under the terms of the GNU General Public License as published by
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder the Free Software Foundation; either version 3 of the License, or
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (at your option) any later version.
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder This program is distributed in the hope that it will be useful,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder GNU General Public License for more details.
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder You should have received a copy of the GNU General Public License
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder along with this program. If not, see <http://www.gnu.org/licenses/>.
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder*/
93603bd881e43d4ff5a57d7ca4e2b9fa619f25b4cmaeder
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder#include "util/util.h"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder#include "confdb/confdb.h"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder#include "responder/common/responder.h"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder#include "responder/common/negcache.h"
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist#include <fcntl.h>
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist#include <time.h>
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder#include "tdb.h"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder#define NC_ENTRY_PREFIX "NCE/"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder#define NC_USER_PREFIX NC_ENTRY_PREFIX"USER"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder#define NC_GROUP_PREFIX NC_ENTRY_PREFIX"GROUP"
85e1d54a475bfc30b3eac5ae6c5e42a2d7e93f10Christian Maeder#define NC_NETGROUP_PREFIX NC_ENTRY_PREFIX"NETGR"
85e1d54a475bfc30b3eac5ae6c5e42a2d7e93f10Christian Maeder#define NC_SERVICE_PREFIX NC_ENTRY_PREFIX"SERVICE"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder#define NC_UID_PREFIX NC_ENTRY_PREFIX"UID"
91e24fc45834b35f2a3830d72565640251149bf3Christian Maeder#define NC_GID_PREFIX NC_ENTRY_PREFIX"GID"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder#define NC_SID_PREFIX NC_ENTRY_PREFIX"SID"
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maederstruct sss_nc_ctx {
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder struct tdb_context *tdb;
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder};
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maedertypedef int (*ncache_set_byname_fn_t)(struct sss_nc_ctx *, bool,
0130083f314580170af1195037be3325f125fbceChristian Maeder const char *, const char *);
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder
0130083f314580170af1195037be3325f125fbceChristian Maederstatic int sss_ncache_set_ent(struct sss_nc_ctx *ctx, bool permanent,
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder struct sss_domain_info *dom, const char *name,
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder ncache_set_byname_fn_t setter);
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maederstatic int string_to_tdb_data(char *str, TDB_DATA *ret)
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder{
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder if (!str || !ret) return EINVAL;
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder ret->dptr = (uint8_t *)str;
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder ret->dsize = strlen(str)+1;
a461314c811f4187dff85c8be079a41b2f13f176Christian Maeder
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder return EOK;
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder}
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederint sss_ncache_init(TALLOC_CTX *memctx, struct sss_nc_ctx **_ctx)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder{
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder struct sss_nc_ctx *ctx;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder ctx = talloc_zero(memctx, struct sss_nc_ctx);
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder if (!ctx) return ENOMEM;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
7f7460e7095628f3437b116ee78d3043d11f8febChristian Maeder errno = 0;
3a9d784341454573b50b32fa1b494e7418df3086Christian Maeder /* open a memory only tdb with default hash size */
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder ctx->tdb = tdb_open("memcache", 0, TDB_INTERNAL, O_RDWR|O_CREAT, 0);
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (!ctx->tdb) return errno;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder *_ctx = ctx;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return EOK;
502483734c83d0bf1eadcc94113d0362f8713784Christian Maeder};
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maederstatic int sss_ncache_check_str(struct sss_nc_ctx *ctx, char *str, int ttl)
7f7460e7095628f3437b116ee78d3043d11f8febChristian Maeder{
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder TDB_DATA key;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder TDB_DATA data;
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder unsigned long long int timestamp;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder bool expired = false;
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder char *ep;
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder int ret;
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder DEBUG(SSSDBG_TRACE_INTERNAL, "Checking negative cache for [%s]\n", str);
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder data.dptr = NULL;
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder ret = string_to_tdb_data(str, &key);
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder if (ret != EOK) goto done;
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder data = tdb_fetch(ctx->tdb, key);
4eb859461f8fd904f40f57261cf23e5c73cf8ecaChristian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (!data.dptr) {
2353f65833a3da763392f771223250cd50b8d873Christian Maeder ret = ENOENT;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder goto done;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder if (ttl == -1) {
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder /* a negative ttl means: never expires */
8c8545dd3bf34fbcbc16904b65d249658f8f9efcChristian Maeder ret = EEXIST;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder goto done;
d81905a5b924415c524d702df26204683c82c12eChristian Maeder }
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder errno = 0;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder timestamp = strtoull((const char *)data.dptr, &ep, 10);
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (errno != 0 || *ep != '\0') {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder /* Malformed entry, remove it and return no entry */
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder expired = true;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder goto done;
cb2044812811d66efe038d914966e04290be93faChristian Maeder }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (timestamp == 0) {
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder /* a 0 timestamp means this is a permanent entry */
0ae7a79e865d4a6022d705d160530682b3c1f825Christian Maeder ret = EEXIST;
083bc1972a66d73749760eab3a90bf4eb9ca7951Christian Maeder goto done;
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu }
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu
b324cda6178c49ddeead3ce62b832ccf644cbcabRazvan Pascanu if (timestamp + ttl > time(NULL)) {
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu /* still valid */
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder ret = EEXIST;
966519955f5f7111abac20118563132b9dd41165Christian Maeder goto done;
8c8545dd3bf34fbcbc16904b65d249658f8f9efcChristian Maeder }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder expired = true;
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maederdone:
33fcc19ef2b59493b4e91eebf701df95fd230765Christian Maeder if (expired) {
33fcc19ef2b59493b4e91eebf701df95fd230765Christian Maeder /* expired, remove and return no entry */
33fcc19ef2b59493b4e91eebf701df95fd230765Christian Maeder tdb_delete(ctx->tdb, key);
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder ret = ENOENT;
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder }
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder
0d79ea4ed8512a802ecb6645edac141e0fbcee3fChristian Maeder free(data.dptr);
0d79ea4ed8512a802ecb6645edac141e0fbcee3fChristian Maeder return ret;
0d79ea4ed8512a802ecb6645edac141e0fbcee3fChristian Maeder}
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maederstatic int sss_ncache_set_str(struct sss_nc_ctx *ctx,
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder char *str, bool permanent)
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder{
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder TDB_DATA key;
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder TDB_DATA data;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder char *timest;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder int ret;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder ret = string_to_tdb_data(str, &key);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder if (ret != EOK) return ret;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder if (permanent) {
93603bd881e43d4ff5a57d7ca4e2b9fa619f25b4cmaeder timest = talloc_strdup(ctx, "0");
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder } else {
8865728716566f42fa73e7e0bc080ba3225df764Christian Maeder timest = talloc_asprintf(ctx, "%llu",
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (unsigned long long int)time(NULL));
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (!timest) return ENOMEM;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
1f2c732265a1292f0d7c51a4a7ca6be5dd370df6cmaeder ret = string_to_tdb_data(timest, &data);
1f2c732265a1292f0d7c51a4a7ca6be5dd370df6cmaeder if (ret != EOK) goto done;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder DEBUG(SSSDBG_TRACE_FUNC, "Adding [%s] to negative cache%s\n",
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder str, permanent?" permanently":"");
fdac680252d7347858bd67b4c2a2aaa52e623815Christian Maeder
fdac680252d7347858bd67b4c2a2aaa52e623815Christian Maeder ret = tdb_store(ctx->tdb, key, data, TDB_REPLACE);
a9e804dbec424ec36e34bab955cbe90edac5baa6Christian Maeder if (ret != 0) {
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulz DEBUG(SSSDBG_CRIT_FAILURE, "Negative cache failed to set entry: [%s]\n",
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder tdb_errorstr(ctx->tdb));
b76d27eba526ecac2a20400fa505ec5c642ae7d2Dominik Luecke ret = EFAULT;
b76d27eba526ecac2a20400fa505ec5c642ae7d2Dominik Luecke }
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettichdone:
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich talloc_free(timest);
2353f65833a3da763392f771223250cd50b8d873Christian Maeder return ret;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder}
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
2353f65833a3da763392f771223250cd50b8d873Christian Maederstatic int sss_ncache_check_user_int(struct sss_nc_ctx *ctx, int ttl,
2353f65833a3da763392f771223250cd50b8d873Christian Maeder const char *domain, const char *name)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder{
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder char *str;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder int ret;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!name || !*name) return EINVAL;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder str = talloc_asprintf(ctx, "%s/%s/%s", NC_USER_PREFIX, domain, name);
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder if (!str) return ENOMEM;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ret = sss_ncache_check_str(ctx, str, ttl);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
00df6fd583c19393fa141d5a0e21ac74c7bf5b19Christian Maeder talloc_free(str);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return ret;
cb2044812811d66efe038d914966e04290be93faChristian Maeder}
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maederstatic int sss_ncache_check_group_int(struct sss_nc_ctx *ctx, int ttl,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder const char *domain, const char *name)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
8d780c893d6df5dab3dcc7d8444b7517f6547f11Christian Maeder char *str;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder int ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!name || !*name) return EINVAL;
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder str = talloc_asprintf(ctx, "%s/%s/%s", NC_GROUP_PREFIX, domain, name);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!str) return ENOMEM;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ret = sss_ncache_check_str(ctx, str, ttl);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder talloc_free(str);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return ret;
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder}
966519955f5f7111abac20118563132b9dd41165Christian Maeder
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maederstatic int sss_ncache_check_netgr_int(struct sss_nc_ctx *ctx, int ttl,
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder const char *domain, const char *name)
d96bfd1d7a4595bfff87771b91797330fa939455Christian Maeder{
d96bfd1d7a4595bfff87771b91797330fa939455Christian Maeder char *str;
8c8545dd3bf34fbcbc16904b65d249658f8f9efcChristian Maeder int ret;
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
34d14197eb3dd643a8e6ef3ed8cba5629528e97fAivaras Jakubauskas if (!name || !*name) return EINVAL;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder str = talloc_asprintf(ctx, "%s/%s/%s", NC_NETGROUP_PREFIX, domain, name);
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder if (!str) return ENOMEM;
0d79ea4ed8512a802ecb6645edac141e0fbcee3fChristian Maeder
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder ret = sss_ncache_check_str(ctx, str, ttl);
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder talloc_free(str);
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder return ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder}
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maederstatic int sss_ncache_check_service_int(struct sss_nc_ctx *ctx,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder int ttl,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder const char *domain,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder const char *name)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder char *str;
2360728d4185c0c04279c999941c64d36626af79Christian Maeder int ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!name || !*name) return EINVAL;
00df6fd583c19393fa141d5a0e21ac74c7bf5b19Christian Maeder
2360728d4185c0c04279c999941c64d36626af79Christian Maeder str = talloc_asprintf(ctx, "%s/%s/%s",
2360728d4185c0c04279c999941c64d36626af79Christian Maeder NC_SERVICE_PREFIX,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder domain,
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder name);
2360728d4185c0c04279c999941c64d36626af79Christian Maeder if (!str) return ENOMEM;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
8d780c893d6df5dab3dcc7d8444b7517f6547f11Christian Maeder ret = sss_ncache_check_str(ctx, str, ttl);
2360728d4185c0c04279c999941c64d36626af79Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder talloc_free(str);
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder return ret;
2360728d4185c0c04279c999941c64d36626af79Christian Maeder}
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maedertypedef int (*ncache_check_byname_fn_t)(struct sss_nc_ctx *, int,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder const char *, const char *);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederstatic int sss_cache_check_ent(struct sss_nc_ctx *ctx, int ttl,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder struct sss_domain_info *dom, const char *name,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ncache_check_byname_fn_t checker)
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder{
966519955f5f7111abac20118563132b9dd41165Christian Maeder char *lower;
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder errno_t ret;
5a448e9be8c4482a978b174b744237757335140fChristian Maeder
d96bfd1d7a4595bfff87771b91797330fa939455Christian Maeder if (dom->case_sensitive == false) {
8c8545dd3bf34fbcbc16904b65d249658f8f9efcChristian Maeder lower = sss_tc_utf8_str_tolower(ctx, name);
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder if (!lower) return ENOMEM;
34d14197eb3dd643a8e6ef3ed8cba5629528e97fAivaras Jakubauskas ret = checker(ctx, ttl, dom->name, lower);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder talloc_free(lower);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder } else {
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder ret = checker(ctx, ttl, dom->name, name);
0d79ea4ed8512a802ecb6645edac141e0fbcee3fChristian Maeder }
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder return ret;
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder}
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederint sss_ncache_check_user(struct sss_nc_ctx *ctx, int ttl,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder struct sss_domain_info *dom, const char *name)
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder{
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder return sss_cache_check_ent(ctx, ttl, dom, name,
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder sss_ncache_check_user_int);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder}
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maederint sss_ncache_check_group(struct sss_nc_ctx *ctx, int ttl,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder struct sss_domain_info *dom, const char *name)
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder{
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder return sss_cache_check_ent(ctx, ttl, dom, name,
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder sss_ncache_check_group_int);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder}
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maederint sss_ncache_check_netgr(struct sss_nc_ctx *ctx, int ttl,
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder struct sss_domain_info *dom, const char *name)
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder{
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder return sss_cache_check_ent(ctx, ttl, dom, name,
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder sss_ncache_check_netgr_int);
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder}
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaederstatic int sss_ncache_set_service_int(struct sss_nc_ctx *ctx, bool permanent,
cb2044812811d66efe038d914966e04290be93faChristian Maeder const char *domain, const char *name)
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder{
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder char *str;
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder int ret;
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder if (!name || !*name) return EINVAL;
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder str = talloc_asprintf(ctx, "%s/%s/%s", NC_SERVICE_PREFIX, domain, name);
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder if (!str) return ENOMEM;
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder ret = sss_ncache_set_str(ctx, str, permanent);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder talloc_free(str);
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder return ret;
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder}
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maederint sss_ncache_set_service_name(struct sss_nc_ctx *ctx, bool permanent,
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder struct sss_domain_info *dom,
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder const char *name, const char *proto)
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder{
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder int ret;
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder char *service_and_protocol = talloc_asprintf(ctx, "%s:%s",
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder name,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder proto ? proto : "<ANY>");
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!service_and_protocol) return ENOMEM;
8bb80c9684e905de8dcfcfb1291542677e7d77b6Christian Maeder
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder ret = sss_ncache_set_ent(ctx, permanent, dom,
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder service_and_protocol,
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder sss_ncache_set_service_int);
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder talloc_free(service_and_protocol);
8bb80c9684e905de8dcfcfb1291542677e7d77b6Christian Maeder return ret;
00df6fd583c19393fa141d5a0e21ac74c7bf5b19Christian Maeder}
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederint sss_ncache_check_service(struct sss_nc_ctx *ctx, int ttl,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder struct sss_domain_info *dom,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder const char *name,
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder const char *proto)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder int ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder char *service_and_protocol = talloc_asprintf(ctx, "%s:%s",
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder name,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder proto ? proto : "<ANY>");
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!service_and_protocol) return ENOMEM;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ret = sss_cache_check_ent(ctx, ttl, dom, service_and_protocol,
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder sss_ncache_check_service_int);
966519955f5f7111abac20118563132b9dd41165Christian Maeder talloc_free(service_and_protocol);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder}
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederint sss_ncache_set_service_port(struct sss_nc_ctx *ctx, bool permanent,
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder struct sss_domain_info *dom,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder uint16_t port, const char *proto)
cb2044812811d66efe038d914966e04290be93faChristian Maeder{
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder int ret;
8d780c893d6df5dab3dcc7d8444b7517f6547f11Christian Maeder char *service_and_protocol = talloc_asprintf(ctx, "%ul:%s",
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder port,
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder proto ? proto : "<ANY>");
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!service_and_protocol) return ENOMEM;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ret = sss_ncache_set_ent(ctx, permanent, dom,
00df6fd583c19393fa141d5a0e21ac74c7bf5b19Christian Maeder service_and_protocol,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder sss_ncache_set_service_int);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder talloc_free(service_and_protocol);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder}
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maederint sss_ncache_check_service_port(struct sss_nc_ctx *ctx, int ttl,
8c8545dd3bf34fbcbc16904b65d249658f8f9efcChristian Maeder struct sss_domain_info *dom,
33fcc19ef2b59493b4e91eebf701df95fd230765Christian Maeder uint16_t port,
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder const char *proto)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder int ret;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder char *service_and_protocol = talloc_asprintf(ctx, "%ul:%s",
34d14197eb3dd643a8e6ef3ed8cba5629528e97fAivaras Jakubauskas port,
0d79ea4ed8512a802ecb6645edac141e0fbcee3fChristian Maeder proto ? proto : "<ANY>");
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder if (!service_and_protocol) return ENOMEM;
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder ret = sss_cache_check_ent(ctx, ttl, dom, service_and_protocol,
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder sss_ncache_check_service_int);
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder talloc_free(service_and_protocol);
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return ret;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder}
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maederint sss_ncache_check_uid(struct sss_nc_ctx *ctx, int ttl, uid_t uid)
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder{
2360728d4185c0c04279c999941c64d36626af79Christian Maeder char *str;
2360728d4185c0c04279c999941c64d36626af79Christian Maeder int ret;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder str = talloc_asprintf(ctx, "%s/%"SPRIuid, NC_UID_PREFIX, uid);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!str) return ENOMEM;
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder
2360728d4185c0c04279c999941c64d36626af79Christian Maeder ret = sss_ncache_check_str(ctx, str, ttl);
2360728d4185c0c04279c999941c64d36626af79Christian Maeder
0130083f314580170af1195037be3325f125fbceChristian Maeder talloc_free(str);
d81905a5b924415c524d702df26204683c82c12eChristian Maeder return ret;
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder}
2360728d4185c0c04279c999941c64d36626af79Christian Maeder
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maederint sss_ncache_check_gid(struct sss_nc_ctx *ctx, int ttl, gid_t gid)
8d780c893d6df5dab3dcc7d8444b7517f6547f11Christian Maeder{
2360728d4185c0c04279c999941c64d36626af79Christian Maeder char *str;
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder int ret;
966519955f5f7111abac20118563132b9dd41165Christian Maeder
2360728d4185c0c04279c999941c64d36626af79Christian Maeder str = talloc_asprintf(ctx, "%s/%"SPRIgid, NC_GID_PREFIX, gid);
2360728d4185c0c04279c999941c64d36626af79Christian Maeder if (!str) return ENOMEM;
00df6fd583c19393fa141d5a0e21ac74c7bf5b19Christian Maeder
2360728d4185c0c04279c999941c64d36626af79Christian Maeder ret = sss_ncache_check_str(ctx, str, ttl);
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder talloc_free(str);
2360728d4185c0c04279c999941c64d36626af79Christian Maeder return ret;
2360728d4185c0c04279c999941c64d36626af79Christian Maeder}
2360728d4185c0c04279c999941c64d36626af79Christian Maeder
2360728d4185c0c04279c999941c64d36626af79Christian Maederint sss_ncache_check_sid(struct sss_nc_ctx *ctx, int ttl, const char *sid)
2360728d4185c0c04279c999941c64d36626af79Christian Maeder{
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder char *str;
8994ef587ce7c7c39ddd20f0f7e4575838a6694aChristian Maeder int ret;
33fcc19ef2b59493b4e91eebf701df95fd230765Christian Maeder
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder str = talloc_asprintf(ctx, "%s/%s", NC_SID_PREFIX, sid);
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder if (!str) return ENOMEM;
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder ret = sss_ncache_check_str(ctx, str, ttl);
ce8a93047aaf0dc36fa221642292d47852a9862aChristian Maeder
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder talloc_free(str);
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder return ret;
2360728d4185c0c04279c999941c64d36626af79Christian Maeder}
2360728d4185c0c04279c999941c64d36626af79Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederstatic int sss_ncache_set_user_int(struct sss_nc_ctx *ctx, bool permanent,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder const char *domain, const char *name)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder{
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder char *str;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder int ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!name || !*name) return EINVAL;
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder str = talloc_asprintf(ctx, "%s/%s/%s", NC_USER_PREFIX, domain, name);
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (!str) return ENOMEM;
91e24fc45834b35f2a3830d72565640251149bf3Christian Maeder
91e24fc45834b35f2a3830d72565640251149bf3Christian Maeder ret = sss_ncache_set_str(ctx, str, permanent);
91e24fc45834b35f2a3830d72565640251149bf3Christian Maeder
91e24fc45834b35f2a3830d72565640251149bf3Christian Maeder talloc_free(str);
91e24fc45834b35f2a3830d72565640251149bf3Christian Maeder return ret;
91e24fc45834b35f2a3830d72565640251149bf3Christian Maeder}
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederstatic int sss_ncache_set_group_int(struct sss_nc_ctx *ctx, bool permanent,
d56ece59c372cb887355825901222b9f3377f7e6Thiemo Wiedemeyer const char *domain, const char *name)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder{
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder char *str;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder int ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
2360728d4185c0c04279c999941c64d36626af79Christian Maeder if (!name || !*name) return EINVAL;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder str = talloc_asprintf(ctx, "%s/%s/%s", NC_GROUP_PREFIX, domain, name);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!str) return ENOMEM;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ret = sss_ncache_set_str(ctx, str, permanent);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist talloc_free(str);
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist return ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder}
76d027be764e2ff61bef959efb3ac8f56499e646Christian Maeder
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakovastatic int sss_ncache_set_netgr_int(struct sss_nc_ctx *ctx, bool permanent,
a166da43d4e8f9dfa7a2651d033c6bea02627ca6Mihai Codescu const char *domain, const char *name)
22b772f8753f0cdb4508ba460356c238de2ee375Jonathan von Schroeder{
7bbfb15142ab4286dfc6fcde2fc94a5512297e41Jonathan von Schroeder char *str;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder int ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
63da71bfb4226f504944b293fb77177ebcaea7d4Ewaryst Schulz if (!name || !*name) return EINVAL;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder str = talloc_asprintf(ctx, "%s/%s/%s", NC_NETGROUP_PREFIX, domain, name);
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist if (!str) return ENOMEM;
af6e92e4a9ca308f928f9909acee115f801c5db5Ewaryst Schulz
b47b1ea8a412f6e4c731779f6a572384e7cf06d8Christian Maeder ret = sss_ncache_set_str(ctx, str, permanent);
26b1c101b72100b69045effdfaab3889de6c8c93Christian Maeder
a68ff26ddb1d300f7e16097edef615f130fcd5ceChristian Maeder talloc_free(str);
9f226cec9f978edaba67aee4c4e04e3d3b994b87Daniel Calegari return ret;
f730570f7c284b252ad2e24cf23cc594021f9e25Jonathan von Schroeder}
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder
897a04683fb30873e84dc3360dea770a4435971cChristian Maederstatic int sss_ncache_set_ent(struct sss_nc_ctx *ctx, bool permanent,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder struct sss_domain_info *dom, const char *name,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ncache_set_byname_fn_t setter)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder char *lower;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder errno_t ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist if (dom->case_sensitive == false) {
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist lower = sss_tc_utf8_str_tolower(ctx, name);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!lower) return ENOMEM;
63da71bfb4226f504944b293fb77177ebcaea7d4Ewaryst Schulz ret = setter(ctx, permanent, dom->name, lower);
76d027be764e2ff61bef959efb3ac8f56499e646Christian Maeder talloc_free(lower);
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakova } else {
a166da43d4e8f9dfa7a2651d033c6bea02627ca6Mihai Codescu ret = setter(ctx, permanent, dom->name, name);
22b772f8753f0cdb4508ba460356c238de2ee375Jonathan von Schroeder }
7bbfb15142ab4286dfc6fcde2fc94a5512297e41Jonathan von Schroeder
f730570f7c284b252ad2e24cf23cc594021f9e25Jonathan von Schroeder return ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder}
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederint sss_ncache_set_user(struct sss_nc_ctx *ctx, bool permanent,
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist struct sss_domain_info *dom, const char *name)
af6e92e4a9ca308f928f9909acee115f801c5db5Ewaryst Schulz{
b47b1ea8a412f6e4c731779f6a572384e7cf06d8Christian Maeder return sss_ncache_set_ent(ctx, permanent, dom, name, sss_ncache_set_user_int);
26b1c101b72100b69045effdfaab3889de6c8c93Christian Maeder}
a68ff26ddb1d300f7e16097edef615f130fcd5ceChristian Maeder
9f226cec9f978edaba67aee4c4e04e3d3b994b87Daniel Calegariint sss_ncache_set_group(struct sss_nc_ctx *ctx, bool permanent,
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder struct sss_domain_info *dom, const char *name)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder{
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return sss_ncache_set_ent(ctx, permanent, dom, name, sss_ncache_set_group_int);
2353f65833a3da763392f771223250cd50b8d873Christian Maeder}
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartistint sss_ncache_set_netgr(struct sss_nc_ctx *ctx, bool permanent,
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist struct sss_domain_info *dom, const char *name)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder{
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return sss_ncache_set_ent(ctx, permanent, dom, name, sss_ncache_set_netgr_int);
897a04683fb30873e84dc3360dea770a4435971cChristian Maeder}
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederint sss_ncache_set_uid(struct sss_nc_ctx *ctx, bool permanent, uid_t uid)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder char *str;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder int ret;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist str = talloc_asprintf(ctx, "%s/%"SPRIuid, NC_UID_PREFIX, uid);
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist if (!str) return ENOMEM;
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist ret = sss_ncache_set_str(ctx, str, permanent);
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist talloc_free(str);
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist return ret;
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist}
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartistint sss_ncache_set_gid(struct sss_nc_ctx *ctx, bool permanent, gid_t gid)
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist{
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist char *str;
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist int ret;
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist str = talloc_asprintf(ctx, "%s/%"SPRIgid, NC_GID_PREFIX, gid);
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist if (!str) return ENOMEM;
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist ret = sss_ncache_set_str(ctx, str, permanent);
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist talloc_free(str);
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist return ret;
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist}
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartistint sss_ncache_set_sid(struct sss_nc_ctx *ctx, bool permanent, const char *sid)
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist{
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist char *str;
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist int ret;
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist str = talloc_asprintf(ctx, "%s/%s", NC_SID_PREFIX, sid);
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist if (!str) return ENOMEM;
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist ret = sss_ncache_set_str(ctx, str, permanent);
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist
df87ff823273ae2969e9d29e833845b4c0a9ee77notanartist talloc_free(str);
c3b00d3435293c71ab4e750be084a2d8dcf6209fnotanartist return ret;
7ebcceae3d34771cae3bbb8c8060bef0b894376eChristian Maeder}
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettichstatic int delete_permanent(struct tdb_context *tdb,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder TDB_DATA key, TDB_DATA data, void *state)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
2360728d4185c0c04279c999941c64d36626af79Christian Maeder unsigned long long int timestamp;
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich bool remove_key = false;
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich char *ep;
7ebcceae3d34771cae3bbb8c8060bef0b894376eChristian Maeder
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich if (strncmp((char *)key.dptr,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder NC_ENTRY_PREFIX, sizeof(NC_ENTRY_PREFIX) - 1) != 0) {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder /* not interested in this key */
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return 0;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder errno = 0;
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist timestamp = strtoull((const char *)data.dptr, &ep, 10);
3ec3a22fe2b9c38a3575c98a82b4e3f988af64a6Eugen Kuksa if (errno != 0 || *ep != '\0') {
4c872eeb600fe8479dbda395405cf13c3d573c24Soeren D. Schulze /* Malformed entry, remove it */
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder remove_key = true;
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder goto done;
024703c9d1326c23e307c0b0d453ed3358e87fe4cmaeder }
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulz
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (timestamp == 0) {
53a3042e1da2253fd3f103bfef4deb47fc0bf6a6Ewaryst Schulz /* a 0 timestamp means this is a permanent entry */
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder remove_key = true;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederdone:
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist if (remove_key) {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return tdb_delete(tdb, key);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder }
c30231257d9116b514dce02703a515fe21cd427dTill Mossakowski
427ff3172ae2dfebe3c8fc972735158999997e8aChristian Maeder return 0;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder}
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederint sss_ncache_reset_permanent(struct sss_nc_ctx *ctx)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
1f2c732265a1292f0d7c51a4a7ca6be5dd370df6cmaeder int ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ret = tdb_traverse(ctx->tdb, delete_permanent, NULL);
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist if (ret < 0)
3ec3a22fe2b9c38a3575c98a82b4e3f988af64a6Eugen Kuksa return EIO;
4c872eeb600fe8479dbda395405cf13c3d573c24Soeren D. Schulze
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return EOK;
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder}
024703c9d1326c23e307c0b0d453ed3358e87fe4cmaeder
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulzerrno_t sss_ncache_prepopulate(struct sss_nc_ctx *ncache,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder struct confdb_ctx *cdb,
53a3042e1da2253fd3f103bfef4deb47fc0bf6a6Ewaryst Schulz struct resp_ctx *rctx)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder{
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder errno_t ret;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder bool filter_set = false;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder char **filter_list = NULL;
987bd66ac5bc367e2bbe50ce2b6355993fb335d9cmaeder char *name = NULL;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder struct sss_domain_info *dom = NULL;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder struct sss_domain_info *domain_list = rctx->domains;
c30231257d9116b514dce02703a515fe21cd427dTill Mossakowski char *domainname = NULL;
427ff3172ae2dfebe3c8fc972735158999997e8aChristian Maeder char *conf_path = NULL;
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder TALLOC_CTX *tmpctx = talloc_new(NULL);
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder int i;
59aa5703ac7f3b99e97cd5926e77088b256c5f40Christian Maeder
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist /* Populate domain-specific negative cache entries */
987bd66ac5bc367e2bbe50ce2b6355993fb335d9cmaeder for (dom = domain_list; dom; dom = get_next_domain(dom, false)) {
bbba10ee00dcf6bcbc9f22473b1acd0983b10512notanartist conf_path = talloc_asprintf(tmpctx, CONFDB_DOMAIN_PATH_TMPL,
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder dom->name);
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder if (!conf_path) {
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder ret = ENOMEM;
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder goto done;
78c294da55788b25e175180168371c9536a6d440Christian Maeder }
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder talloc_zfree(filter_list);
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich ret = confdb_get_string_as_list(cdb, tmpctx, conf_path,
b76d27eba526ecac2a20400fa505ec5c642ae7d2Dominik Luecke CONFDB_NSS_FILTER_USERS,
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder &filter_list);
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (ret == ENOENT) continue;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (ret != EOK) goto done;
1ebf8299efa3cdb39c73d40d15e1d1a8a2246e68notanartist filter_set = true;
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder for (i = 0; (filter_list && filter_list[i]); i++) {
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder ret = sss_parse_name_for_domains(tmpctx, domain_list,
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder rctx->default_domain,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder filter_list[i],
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder &domainname, &name);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (ret != EOK) {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder "Invalid name in filterUsers list: [%s] (%d)\n",
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder filter_list[i], ret);
78c294da55788b25e175180168371c9536a6d440Christian Maeder continue;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (domainname && strcmp(domainname, dom->name)) {
78c294da55788b25e175180168371c9536a6d440Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
78c294da55788b25e175180168371c9536a6d440Christian Maeder "Mismatch between domain name (%s) and name "
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder "set in FQN (%s), skipping user %s\n",
511284753313165e629cedf508752d6818ccc4d2Christian Maeder dom->name, domainname, name);
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder continue;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
78c294da55788b25e175180168371c9536a6d440Christian Maeder
78c294da55788b25e175180168371c9536a6d440Christian Maeder ret = sss_ncache_set_user(ncache, true, dom, name);
78c294da55788b25e175180168371c9536a6d440Christian Maeder if (ret != EOK) {
78c294da55788b25e175180168371c9536a6d440Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder "Failed to store permanent user filter for [%s]"
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder " (%d [%s])\n", filter_list[i],
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ret, strerror(ret));
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder continue;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ret = confdb_get_string_as_list(cdb, tmpctx, CONFDB_NSS_CONF_ENTRY,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder CONFDB_NSS_FILTER_USERS, &filter_list);
8865728716566f42fa73e7e0bc080ba3225df764Christian Maeder if (ret == ENOENT) {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if (!filter_set) {
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder filter_list = talloc_array(tmpctx, char *, 2);
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder if (!filter_list) {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ret = ENOMEM;
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder goto done;
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder filter_list[0] = talloc_strdup(tmpctx, "root");
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!filter_list[0]) {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ret = ENOMEM;
8bb80c9684e905de8dcfcfb1291542677e7d77b6Christian Maeder goto done;
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder }
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder filter_list[1] = NULL;
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder }
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder }
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder else if (ret != EOK) goto done;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder for (i = 0; (filter_list && filter_list[i]); i++) {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ret = sss_parse_name_for_domains(tmpctx, domain_list,
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder rctx->default_domain, filter_list[i],
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder &domainname, &name);
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder if (ret != EOK) {
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder "Invalid name in filterUsers list: [%s] (%d)\n",
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder filter_list[i], ret);
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder continue;
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder }
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder if (domainname) {
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder dom = responder_get_domain(rctx, domainname);
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder if (!dom) {
b6ff72be73dad3d1394cf2c71e29e67624ff030bChristian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder "Invalid domain name [%s]\n", domainname);
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder continue;
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder }
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder ret = sss_ncache_set_user(ncache, true, dom, name);
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder if (ret != EOK) {
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder "Failed to store permanent user filter for [%s]"
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder " (%d [%s])\n", filter_list[i],
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ret, strerror(ret));
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder continue;
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder }
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder } else {
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder for (dom = domain_list; dom; dom = get_next_domain(dom, false)) {
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder ret = sss_ncache_set_user(ncache, true, dom, name);
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder if (ret != EOK) {
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder "Failed to store permanent user filter for"
d81905a5b924415c524d702df26204683c82c12eChristian Maeder " [%s:%s] (%d [%s])\n",
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder dom->name, filter_list[i],
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder ret, strerror(ret));
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder continue;
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder }
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder }
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder }
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder }
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder filter_set = false;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder for (dom = domain_list; dom; dom = get_next_domain(dom, false)) {
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder conf_path = talloc_asprintf(tmpctx, CONFDB_DOMAIN_PATH_TMPL, dom->name);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder if (!conf_path) {
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder ret = ENOMEM;
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder goto done;
0b13f102310e03a20b38c870b5acb88712f316a4Christian Maeder }
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder talloc_zfree(filter_list);
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder ret = confdb_get_string_as_list(cdb, tmpctx, conf_path,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder CONFDB_NSS_FILTER_GROUPS, &filter_list);
818b228955ef40dd5a253bd942dd6ab8779ed713Christian Maeder if (ret == ENOENT) continue;
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder if (ret != EOK) goto done;
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder filter_set = true;
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder
353187efd08a2cb65226f414f192b59d312f27acChristian Maeder for (i = 0; (filter_list && filter_list[i]); i++) {
8c8545dd3bf34fbcbc16904b65d249658f8f9efcChristian Maeder ret = sss_parse_name(tmpctx, dom->names, filter_list[i],
33fcc19ef2b59493b4e91eebf701df95fd230765Christian Maeder &domainname, &name);
d4ebd9e5adc974cfa2bdf4bdd155e07be0e26f75Christian Maeder if (ret != EOK) {
0d79ea4ed8512a802ecb6645edac141e0fbcee3fChristian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder "Invalid name in filterGroups list: [%s] (%d)\n",
9ee80c455784287a8b5e1b6bac1f8efa6a2f4bb3cmaeder filter_list[i], ret);
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder continue;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder
4a2f7efdf67dfcda0946f1b6373f41976ddea7a4Christian Maeder if (domainname && strcmp(domainname, dom->name)) {
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder "Mismatch betwen domain name (%s) and name "
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder "set in FQN (%s), skipping group %s\n",
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder dom->name, domainname, name);
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder continue;
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder }
78c294da55788b25e175180168371c9536a6d440Christian Maeder
1f2c732265a1292f0d7c51a4a7ca6be5dd370df6cmaeder ret = sss_ncache_set_group(ncache, true, dom, name);
ab2f38d9cd1249f6bc9cc5b838dc2fcd76189c0fChristian Maeder if (ret != EOK) {
974b0baababf2878820de073b8fad8db68bef08aDominik Luecke DEBUG(SSSDBG_CRIT_FAILURE,
8d780c893d6df5dab3dcc7d8444b7517f6547f11Christian Maeder "Failed to store permanent group filter for [%s]"
8d780c893d6df5dab3dcc7d8444b7517f6547f11Christian Maeder " (%d [%s])\n", filter_list[i],
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder ret, strerror(ret));
083bc1972a66d73749760eab3a90bf4eb9ca7951Christian Maeder continue;
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder }
bc263f610d20a9cd3014ddfca903026127fa0d48Christian Maeder }
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder }
966519955f5f7111abac20118563132b9dd41165Christian Maeder
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder ret = confdb_get_string_as_list(cdb, tmpctx, CONFDB_NSS_CONF_ENTRY,
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder CONFDB_NSS_FILTER_GROUPS, &filter_list);
00df6fd583c19393fa141d5a0e21ac74c7bf5b19Christian Maeder if (ret == ENOENT) {
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder if (!filter_set) {
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder filter_list = talloc_array(tmpctx, char *, 2);
0ae7a79e865d4a6022d705d160530682b3c1f825Christian Maeder if (!filter_list) {
f03420e44d8204b2945edaab5c70a84e7c381892Christian Maeder ret = ENOMEM;
0ae7a79e865d4a6022d705d160530682b3c1f825Christian Maeder goto done;
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder }
dff1de7ad15d1582e25d636c3724dd202874897fChristian Maeder filter_list[0] = talloc_strdup(tmpctx, "root");
34d14197eb3dd643a8e6ef3ed8cba5629528e97fAivaras Jakubauskas if (!filter_list[0]) {
34d14197eb3dd643a8e6ef3ed8cba5629528e97fAivaras Jakubauskas ret = ENOMEM;
34d14197eb3dd643a8e6ef3ed8cba5629528e97fAivaras Jakubauskas goto done;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder filter_list[1] = NULL;
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder }
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder }
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder else if (ret != EOK) goto done;
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder for (i = 0; (filter_list && filter_list[i]); i++) {
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder ret = sss_parse_name_for_domains(tmpctx, domain_list,
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder rctx->default_domain, filter_list[i],
d590edc7ecb39262bd96ec70608cbb0cf4284ba5cmaeder &domainname, &name);
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder if (ret != EOK) {
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder DEBUG(SSSDBG_CRIT_FAILURE,
d1c667fd9445963d9d31e2cf5d0ead15e77082a4cmaeder "Invalid name in filterGroups list: [%s] (%d)\n",
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder filter_list[i], ret);
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder continue;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder }
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder if (domainname) {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dom = responder_get_domain(rctx, domainname);
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (!dom) {
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder "Invalid domain name [%s]\n", domainname);
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder continue;
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder }
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder ret = sss_ncache_set_group(ncache, true, dom, name);
96ae1a1d2197d0e0d5b80da2474b64c456feb1b0Christian Maeder if (ret != EOK) {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder "Failed to store permanent group filter for"
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder " [%s] (%d [%s])\n", filter_list[i],
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder ret, strerror(ret));
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder continue;
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder }
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder } else {
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu for (dom = domain_list; dom; dom = get_next_domain(dom, false)) {
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu ret = sss_ncache_set_group(ncache, true, dom, name);
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu if (ret != EOK) {
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu DEBUG(SSSDBG_CRIT_FAILURE,
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder "Failed to store permanent group filter for"
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu " [%s:%s] (%d [%s])\n",
9308cb2aebeae23f49713896e6d7028b0ac0f83enotanartist dom->name, filter_list[i],
2360728d4185c0c04279c999941c64d36626af79Christian Maeder ret, strerror(ret));
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu continue;
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu }
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu }
66a774f13272fde036481edd2298081ab3d04678Razvan Pascanu }
9308cb2aebeae23f49713896e6d7028b0ac0f83enotanartist }
2360728d4185c0c04279c999941c64d36626af79Christian Maeder
66a774f13272fde036481edd2298081ab3d04678Razvan Pascanu ret = EOK;
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maederdone:
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder talloc_free(tmpctx);
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder return ret;
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder}
16b71dad8d398af412d66a4f4763f1ada5b03d23Christian Maeder