summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2016-11-07 13:05:31 +0100
committerLukas Slebodnik <lslebodn@redhat.com>2016-12-19 23:23:23 +0100
commitc2fc9459c31cb1192ab3c15ce4df1c150e99bf95 (patch)
tree86ea8169fb1c9acb43f35d5f3ee130a914e76d1b
parent2e13817e64ff1e0e47dc844be501f2d3ab299f34 (diff)
downloadsssd-c2fc9459c31cb1192ab3c15ce4df1c150e99bf95.tar.gz
sssd-c2fc9459c31cb1192ab3c15ce4df1c150e99bf95.tar.xz
sssd-c2fc9459c31cb1192ab3c15ce4df1c150e99bf95.zip
cache_req: add support for service by port
Resolves: https://fedorahosted.org/sssd/ticket/3151 Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
-rw-r--r--Makefile.am1
-rw-r--r--src/responder/common/cache_req/cache_req.c1
-rw-r--r--src/responder/common/cache_req/cache_req.h14
-rw-r--r--src/responder/common/cache_req/cache_req_data.c20
-rw-r--r--src/responder/common/cache_req/cache_req_plugin.h1
-rw-r--r--src/responder/common/cache_req/plugins/cache_req_svc_by_port.c154
-rw-r--r--src/tests/cwrap/Makefile.am1
7 files changed, 192 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 6323c9181..431ca811d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -496,6 +496,7 @@ SSSD_CACHE_REQ_OBJ = \
src/responder/common/cache_req/plugins/cache_req_initgroups_by_upn.c \
src/responder/common/cache_req/plugins/cache_req_object_by_sid.c \
src/responder/common/cache_req/plugins/cache_req_svc_by_name.c \
+ src/responder/common/cache_req/plugins/cache_req_svc_by_port.c \
$(NULL)
SSSD_RESPONDER_OBJ = \
diff --git a/src/responder/common/cache_req/cache_req.c b/src/responder/common/cache_req/cache_req.c
index 2f69f95d9..9bf63b191 100644
--- a/src/responder/common/cache_req/cache_req.c
+++ b/src/responder/common/cache_req/cache_req.c
@@ -49,6 +49,7 @@ cache_req_get_plugin(enum cache_req_type type)
&cache_req_enum_groups,
&cache_req_svc_by_name,
+ &cache_req_svc_by_port,
};
if (type >= CACHE_REQ_SENTINEL) {
diff --git a/src/responder/common/cache_req/cache_req.h b/src/responder/common/cache_req/cache_req.h
index 926deb0c2..c91d88c83 100644
--- a/src/responder/common/cache_req/cache_req.h
+++ b/src/responder/common/cache_req/cache_req.h
@@ -45,6 +45,7 @@ enum cache_req_type {
CACHE_REQ_ENUM_GROUPS,
CACHE_REQ_SVC_BY_NAME,
+ CACHE_REQ_SVC_BY_PORT,
CACHE_REQ_SENTINEL
};
@@ -272,4 +273,17 @@ cache_req_svc_by_name_send(TALLOC_CTX *mem_ctx,
#define cache_req_svc_by_name_recv(mem_ctx, req, _result) \
cache_req_single_domain_recv(mem_ctx, req, _result)
+struct tevent_req *
+cache_req_svc_by_port_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct resp_ctx *rctx,
+ struct sss_nc_ctx *ncache,
+ int cache_refresh_percent,
+ const char *domain,
+ uint16_t port,
+ const char *protocol);
+
+#define cache_req_svc_by_port_recv(mem_ctx, req, _result) \
+ cache_req_single_domain_recv(mem_ctx, req, _result)
+
#endif /* _CACHE_REQ_H_ */
diff --git a/src/responder/common/cache_req/cache_req_data.c b/src/responder/common/cache_req/cache_req_data.c
index 3760c8c70..fcbeef82c 100644
--- a/src/responder/common/cache_req/cache_req_data.c
+++ b/src/responder/common/cache_req/cache_req_data.c
@@ -122,6 +122,26 @@ cache_req_data_create(TALLOC_CTX *mem_ctx,
}
break;
+ case CACHE_REQ_SVC_BY_PORT:
+ if (input->svc.port == 0) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Bug: port cannot be 0!\n");
+ ret = ERR_INTERNAL;
+ goto done;
+ }
+
+ data->svc.port = input->svc.port;
+
+ if (input->svc.protocol.name == NULL) {
+ break;
+ }
+
+ data->svc.protocol.name = talloc_strdup(data, input->svc.protocol.name);
+ if (data->svc.protocol.name == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ break;
case CACHE_REQ_SENTINEL:
DEBUG(SSSDBG_CRIT_FAILURE, "Invalid cache request type!\n");
ret = ERR_INTERNAL;
diff --git a/src/responder/common/cache_req/cache_req_plugin.h b/src/responder/common/cache_req/cache_req_plugin.h
index 99caa791e..6b461fa45 100644
--- a/src/responder/common/cache_req/cache_req_plugin.h
+++ b/src/responder/common/cache_req/cache_req_plugin.h
@@ -197,5 +197,6 @@ extern struct cache_req_plugin cache_req_object_by_sid;
extern struct cache_req_plugin cache_req_enum_users;
extern struct cache_req_plugin cache_req_enum_groups;
extern struct cache_req_plugin cache_req_svc_by_name;
+extern struct cache_req_plugin cache_req_svc_by_port;
#endif /* _CACHE_REQ_PLUGIN_H_ */
diff --git a/src/responder/common/cache_req/plugins/cache_req_svc_by_port.c b/src/responder/common/cache_req/plugins/cache_req_svc_by_port.c
new file mode 100644
index 000000000..521849992
--- /dev/null
+++ b/src/responder/common/cache_req/plugins/cache_req_svc_by_port.c
@@ -0,0 +1,154 @@
+/*
+ Authors:
+ Pavel Březina <pbrezina@redhat.com>
+
+ Copyright (C) 2016 Red Hat
+
+ This program is free software; you can redistribute it and/or modify
+ 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 <talloc.h>
+#include <ldb.h>
+
+#include "db/sysdb.h"
+#include "db/sysdb_services.h"
+#include "util/util.h"
+#include "providers/data_provider.h"
+#include "responder/common/cache_req/cache_req_plugin.h"
+
+static errno_t
+cache_req_svc_by_port_prepare_domain_data(struct cache_req *cr,
+ struct cache_req_data *data,
+ struct sss_domain_info *domain)
+{
+ const char *protocol;
+
+ if (data->svc.protocol.name == NULL) {
+ return EOK;
+ }
+
+ protocol = sss_get_cased_name(NULL, data->svc.protocol.name,
+ domain->case_sensitive);
+ if (protocol == NULL) {
+ return ENOMEM;
+ }
+
+ talloc_zfree(data->svc.protocol.lookup);
+ data->svc.protocol.lookup = talloc_steal(data, protocol);
+
+ return EOK;
+}
+
+static const char *
+cache_req_svc_by_port_create_debug_name(TALLOC_CTX *mem_ctx,
+ struct cache_req_data *data,
+ struct sss_domain_info *domain)
+{
+ const char *protocol = data->svc.protocol.lookup;
+
+ protocol = protocol == NULL ? "<ANY>" : protocol;
+
+ return talloc_asprintf(mem_ctx, "%s %u@%s", protocol,
+ data->svc.port, domain->name);
+}
+
+static errno_t
+cache_req_svc_by_port_ncache_check(struct sss_nc_ctx *ncache,
+ struct sss_domain_info *domain,
+ struct cache_req_data *data)
+{
+ return sss_ncache_check_service_port(ncache, domain, data->svc.port,
+ data->svc.protocol.lookup);
+}
+
+static errno_t
+cache_req_svc_by_port_ncache_add(struct sss_nc_ctx *ncache,
+ struct sss_domain_info *domain,
+ struct cache_req_data *data)
+{
+ return sss_ncache_set_service_port(ncache, false, domain,
+ data->svc.port,
+ data->svc.protocol.lookup);
+}
+
+static errno_t
+cache_req_svc_by_port_lookup(TALLOC_CTX *mem_ctx,
+ struct cache_req *cr,
+ struct cache_req_data *data,
+ struct sss_domain_info *domain,
+ struct ldb_result **_result)
+{
+ return sysdb_getservbyport(mem_ctx, domain, data->svc.port,
+ data->svc.protocol.lookup, _result);
+}
+
+static errno_t
+cache_req_svc_by_port_dpreq_params(TALLOC_CTX *mem_ctx,
+ struct cache_req *cr,
+ struct ldb_result *result,
+ const char **_string,
+ uint32_t *_id,
+ const char **_flag)
+{
+ *_id = cr->data->svc.port;
+ *_string = NULL;
+ *_flag = cr->data->svc.protocol.lookup;
+
+ return EOK;
+}
+
+struct cache_req_plugin cache_req_svc_by_port = {
+ .name = "Service by port",
+ .dp_type = SSS_DP_SERVICES,
+ .attr_expiration = SYSDB_CACHE_EXPIRE,
+ .parse_name = false,
+ .bypass_cache = false,
+ .only_one_result = false,
+ .search_all_domains = false,
+ .require_enumeration = false,
+ .allow_missing_fqn = false,
+ .allow_switch_to_upn = false,
+ .upn_equivalent = CACHE_REQ_SENTINEL,
+ .get_next_domain_flags = 0,
+
+ .prepare_domain_data_fn = cache_req_svc_by_port_prepare_domain_data,
+ .create_debug_name_fn = cache_req_svc_by_port_create_debug_name,
+ .global_ncache_add_fn = NULL,
+ .ncache_check_fn = cache_req_svc_by_port_ncache_check,
+ .ncache_add_fn = cache_req_svc_by_port_ncache_add,
+ .lookup_fn = cache_req_svc_by_port_lookup,
+ .dpreq_params_fn = cache_req_svc_by_port_dpreq_params
+};
+
+struct tevent_req *
+cache_req_svc_by_port_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct resp_ctx *rctx,
+ struct sss_nc_ctx *ncache,
+ int cache_refresh_percent,
+ const char *domain,
+ uint16_t port,
+ const char *protocol)
+{
+ struct cache_req_data *data;
+
+ data = cache_req_data_svc(mem_ctx, CACHE_REQ_SVC_BY_PORT,
+ NULL, protocol, port);
+ if (data == NULL) {
+ return NULL;
+ }
+
+ return cache_req_steal_data_and_send(mem_ctx, ev, rctx, ncache,
+ cache_refresh_percent, domain, data);
+}
diff --git a/src/tests/cwrap/Makefile.am b/src/tests/cwrap/Makefile.am
index 1a2881b1c..2a9983d84 100644
--- a/src/tests/cwrap/Makefile.am
+++ b/src/tests/cwrap/Makefile.am
@@ -54,6 +54,7 @@ SSSD_CACHE_REQ_OBJ = \
../../../src/responder/common/cache_req/plugins/cache_req_initgroups_by_upn.c \
../../../src/responder/common/cache_req/plugins/cache_req_object_by_sid.c \
../../../src/responder/common/cache_req/plugins/cache_req_svc_by_name.c \
+ ../../../src/responder/common/cache_req/plugins/cache_req_svc_by_port.c \
$(NULL)
SSSD_RESPONDER_OBJ = \