8
Sumit Bose <sbose@redhat.com>
10
Copyright (C) 2010 Red Hat
12
This program is free software; you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
14
the Free Software Foundation; either version 3 of the License, or
15
(at your option) any later version.
17
This program is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
GNU General Public License for more details.
22
You should have received a copy of the GNU General Public License
23
along with this program. If not, see <http://www.gnu.org/licenses/>.
26
#include "providers/proxy/proxy.h"
27
#include "util/util.h"
31
static errno_t make_netgroup_attr(struct __netgrent netgrent,
32
struct sysdb_attrs *attrs)
37
if (netgrent.type == group_val) {
38
ret =sysdb_attrs_add_string(attrs, SYSDB_NETGROUP_MEMBER,
41
DEBUG(1, ("sysdb_attrs_add_string failed.\n"));
44
} else if (netgrent.type == triple_val) {
45
dummy = talloc_asprintf(attrs, "(%s,%s,%s)", netgrent.val.triple.host,
46
netgrent.val.triple.user,
47
netgrent.val.triple.domain);
49
DEBUG(1, ("talloc_asprintf failed.\n"));
53
ret = sysdb_attrs_add_string(attrs, SYSDB_NETGROUP_TRIPLE, dummy);
55
DEBUG(1, ("sysdb_attrs_add_string failed.\n"));
59
DEBUG(1, ("Unknown netgrent entry type [%d].\n", netgrent.type));
66
errno_t get_netgroup(struct proxy_id_ctx *ctx,
67
struct sysdb_ctx *sysdb,
68
struct sss_domain_info *dom,
71
struct __netgrent result;
72
enum nss_status status;
76
struct sysdb_attrs *attrs;
78
memset(&result, 0 ,sizeof(result));
79
status = ctx->ops.setnetgrent(name, &result);
80
if (status != NSS_STATUS_SUCCESS) {
81
DEBUG(5, ("setnetgrent failed for netgroup [%s].\n", name));
85
tmp_ctx = talloc_new(NULL);
86
if (tmp_ctx == NULL) {
87
DEBUG(1, ("talloc_new failed.\n"));
91
attrs = sysdb_new_attrs(tmp_ctx);
93
DEBUG(1, ("sysdb_new_attrs failed.\n"));
98
status = ctx->ops.getnetgrent_r(&result, buffer, BUFLEN, &ret);
99
if (status != NSS_STATUS_SUCCESS && status != NSS_STATUS_RETURN) {
100
DEBUG(1, ("getnetgrent_r failed for netgroup [%s]: [%d][%s].\n",
101
name, ret, strerror(ret)));
105
if (status == NSS_STATUS_SUCCESS) {
106
ret = make_netgroup_attr(result, attrs);
108
DEBUG(1, ("make_netgroup_attr failed.\n"));
112
} while (status != NSS_STATUS_RETURN);
114
status = ctx->ops.endnetgrent(&result);
115
if (status != NSS_STATUS_SUCCESS) {
116
DEBUG(1, ("endnetgrent failed.\n"));
121
ret = sysdb_add_netgroup(sysdb, dom, name, NULL, attrs,
122
ctx->entry_cache_timeout);
124
DEBUG(1, ("sysdb_add_netgroup failed.\n"));
131
talloc_free(tmp_ctx);