summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2010-10-13 21:52:26 +0200
committerStephen Gallagher <sgallagh@redhat.com>2010-10-25 07:06:43 -0400
commit04feeade1f6259368a6b23c6b3ecbad261161659 (patch)
treeba97f63b25b3b599f1ad160275824ba97f63f703
parentd7dc57bcc2468bee756bcd568daee0644e5b888d (diff)
downloadsssd-04feeade1f6259368a6b23c6b3ecbad261161659.tar.gz
sssd-04feeade1f6259368a6b23c6b3ecbad261161659.tar.xz
sssd-04feeade1f6259368a6b23c6b3ecbad261161659.zip
Implement netgroups for proxy provider
-rw-r--r--Makefile.am1
-rw-r--r--src/providers/proxy/proxy.h7
-rw-r--r--src/providers/proxy/proxy_id.c4
-rw-r--r--src/providers/proxy/proxy_netgroup.c134
4 files changed, 144 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 65860b634..294b17416 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -795,6 +795,7 @@ libsss_proxy_la_SOURCES = \
src/providers/proxy/proxy_common.c \
src/providers/proxy/proxy_init.c \
src/providers/proxy/proxy_id.c \
+ src/providers/proxy/proxy_netgroup.c \
src/providers/proxy/proxy_auth.c
libsss_proxy_la_CFLAGS = \
$(AM_CFLAGS)
diff --git a/src/providers/proxy/proxy.h b/src/providers/proxy/proxy.h
index e35e91ce3..9faa967cb 100644
--- a/src/providers/proxy/proxy.h
+++ b/src/providers/proxy/proxy.h
@@ -138,4 +138,11 @@ void proxy_get_account_info(struct be_req *breq);
/* From proxy_auth.c */
void proxy_pam_handler(struct be_req *req);
+/* From proxy_netgroup.c */
+errno_t get_netgroup(struct proxy_id_ctx *ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *dom,
+ const char *name);
+
+
#endif /* __PROXY_H__ */
diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c
index ead6ce080..ff3ddf803 100644
--- a/src/providers/proxy/proxy_id.c
+++ b/src/providers/proxy/proxy_id.c
@@ -1149,8 +1149,8 @@ void proxy_get_account_info(struct be_req *breq)
ENODEV, "Netgroups are not supported");
}
- return proxy_reply(breq, DP_ERR_FATAL,
- ENOSYS, "Netgroups not implemented");
+ ret = get_netgroup(ctx, sysdb, domain, ar->filter_value);
+ break;
default: /*fail*/
return proxy_reply(breq, DP_ERR_FATAL,
diff --git a/src/providers/proxy/proxy_netgroup.c b/src/providers/proxy/proxy_netgroup.c
new file mode 100644
index 000000000..cdcb2a857
--- /dev/null
+++ b/src/providers/proxy/proxy_netgroup.c
@@ -0,0 +1,134 @@
+/*
+ SSSD
+
+ Proxy netgroup handler
+
+ Authors:
+
+ Sumit Bose <sbose@redhat.com>
+
+ Copyright (C) 2010 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 "providers/proxy/proxy.h"
+#include "util/util.h"
+
+#define BUFLEN 1024
+
+static errno_t make_netgroup_attr(struct __netgrent netgrent,
+ struct sysdb_attrs *attrs)
+{
+ int ret;
+ char *dummy;
+
+ if (netgrent.type == group_val) {
+ ret =sysdb_attrs_add_string(attrs, SYSDB_NETGROUP_MEMBER,
+ netgrent.val.group);
+ if (ret != EOK) {
+ DEBUG(1, ("sysdb_attrs_add_string failed.\n"));
+ return ret;
+ }
+ } else if (netgrent.type == triple_val) {
+ dummy = talloc_asprintf(attrs, "(%s,%s,%s)", netgrent.val.triple.host,
+ netgrent.val.triple.user,
+ netgrent.val.triple.domain);
+ if (dummy == NULL) {
+ DEBUG(1, ("talloc_asprintf failed.\n"));
+ return ENOMEM;
+ }
+
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NETGROUP_TRIPLE, dummy);
+ if (ret != EOK) {
+ DEBUG(1, ("sysdb_attrs_add_string failed.\n"));
+ return ret;
+ }
+ } else {
+ DEBUG(1, ("Unknown netgrent entry type [%d].\n", netgrent.type));
+ return EINVAL;
+ }
+
+ return EOK;
+}
+
+errno_t get_netgroup(struct proxy_id_ctx *ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *dom,
+ const char *name)
+{
+ struct __netgrent result;
+ enum nss_status status;
+ char buffer[BUFLEN];
+ int ret;
+ TALLOC_CTX *tmp_ctx;
+ struct sysdb_attrs *attrs;
+
+ memset(&result, 0 ,sizeof(result));
+ status = ctx->ops.setnetgrent(name, &result);
+ if (status != NSS_STATUS_SUCCESS) {
+ DEBUG(5, ("setnetgrent failed for netgroup [%s].\n", name));
+ return EIO;
+ }
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ DEBUG(1, ("talloc_new failed.\n"));
+ return ENOMEM;
+ }
+
+ attrs = sysdb_new_attrs(tmp_ctx);
+ if (attrs == NULL) {
+ DEBUG(1, ("sysdb_new_attrs failed.\n"));
+ return ENOMEM;
+ }
+
+ do {
+ status = ctx->ops.getnetgrent_r(&result, buffer, BUFLEN, &ret);
+ if (status != NSS_STATUS_SUCCESS && status != NSS_STATUS_RETURN) {
+ DEBUG(1, ("getnetgrent_r failed for netgroup [%s]: [%d][%s].\n",
+ name, ret, strerror(ret)));
+ goto done;
+ }
+
+ if (status == NSS_STATUS_SUCCESS) {
+ ret = make_netgroup_attr(result, attrs);
+ if (ret != EOK) {
+ DEBUG(1, ("make_netgroup_attr failed.\n"));
+ goto done;
+ }
+ }
+ } while (status != NSS_STATUS_RETURN);
+
+ status = ctx->ops.endnetgrent(&result);
+ if (status != NSS_STATUS_SUCCESS) {
+ DEBUG(1, ("endnetgrent failed.\n"));
+ ret = EIO;
+ goto done;
+ }
+
+ ret = sysdb_add_netgroup(sysdb, dom, name, NULL, attrs,
+ ctx->entry_cache_timeout);
+ if (ret != EOK) {
+ DEBUG(1, ("sysdb_add_netgroup failed.\n"));
+ goto done;
+ }
+
+ ret = EOK;
+
+done:
+ talloc_free(tmp_ctx);
+
+ return ret;
+}