summaryrefslogtreecommitdiff
path: root/source3/nsswitch
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-12-03 06:04:18 +0000
committerAndrew Tridgell <tridge@samba.org>2001-12-03 06:04:18 +0000
commit2285b99cb1047ea85589ef23d4ca73278a15ee08 (patch)
tree4075ad18c9d81dba881b23b4a8d263b1ab9078fb /source3/nsswitch
parentfeb4f52f134d463c9871cd1709897a4b9ccfc6d2 (diff)
downloadsamba-2285b99cb1047ea85589ef23d4ca73278a15ee08.tar.gz
samba-2285b99cb1047ea85589ef23d4ca73278a15ee08.tar.bz2
samba-2285b99cb1047ea85589ef23d4ca73278a15ee08.zip
added a basic ADS backend to winbind. More work needed, but at
least basic operations work (This used to be commit 88241cab983b2c7db7d477c6c4654694a7a56cd3)
Diffstat (limited to 'source3/nsswitch')
-rw-r--r--source3/nsswitch/winbindd_ads.c207
-rw-r--r--source3/nsswitch/winbindd_rpc.c20
-rw-r--r--source3/nsswitch/winbindd_util.c18
3 files changed, 233 insertions, 12 deletions
diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c
new file mode 100644
index 0000000000..c728f9659c
--- /dev/null
+++ b/source3/nsswitch/winbindd_ads.c
@@ -0,0 +1,207 @@
+/*
+ Unix SMB/Netbios implementation.
+
+ Winbind ADS backend functions
+
+ Copyright (C) Andrew Tridgell 2001
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "winbindd.h"
+
+#ifdef HAVE_ADS
+
+/* Query display info for a realm. This is the basic user list fn */
+static NTSTATUS query_dispinfo(struct winbindd_domain *domain,
+ TALLOC_CTX *mem_ctx,
+ uint32 *start_ndx, uint32 *num_entries,
+ WINBIND_DISPINFO **info)
+{
+ ADS_STRUCT *ads;
+ const char *attrs[] = {"sAMAccountName", "name", "objectSid", "primaryGroupID",
+ "userAccountControl", NULL};
+ int rc, i, count;
+ void *res;
+ void *msg;
+
+ DEBUG(3,("ads: query_dispinfo\n"));
+
+ if ((*start_ndx) != 0) {
+ DEBUG(1,("ads backend start_ndx not implemented\n"));
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+
+ ads = ads_init(NULL, NULL, NULL);
+ if (!ads) {
+ DEBUG(1,("ads_init failed\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ rc = ads_connect(ads);
+ if (rc) {
+ DEBUG(1,("query_dispinfo ads_connect: %s\n", ads_errstr(rc)));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ rc = ads_search(ads, &res, "(objectclass=user)", attrs);
+ if (rc) {
+ DEBUG(1,("query_dispinfo ads_search: %s\n", ads_errstr(rc)));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ count = ads_count_replies(ads, res);
+ if (count == 0) {
+ DEBUG(1,("query_dispinfo: No users found\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ (*info) = talloc(mem_ctx, count * sizeof(**info));
+ if (!*info) return NT_STATUS_NO_MEMORY;
+
+ i = 0;
+
+ for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) {
+ char *name, *gecos;
+ DOM_SID sid;
+ uint32 rid, group;
+ uint32 account_control;
+
+ if (!ads_pull_uint32(ads, msg, "userAccountControl",
+ &account_control) ||
+ !(account_control & UF_NORMAL_ACCOUNT)) continue;
+
+ name = ads_pull_string(ads, mem_ctx, msg, "sAMAccountName");
+ gecos = ads_pull_string(ads, mem_ctx, msg, "name");
+ if (!ads_pull_sid(ads, msg, "objectSid", &sid)) {
+ DEBUG(1,("No sid for %s !?\n", name));
+ continue;
+ }
+ if (!ads_pull_uint32(ads, msg, "primaryGroupID", &group)) {
+ DEBUG(1,("No primary group for %s !?\n", name));
+ continue;
+ }
+
+ if (!sid_peek_rid(&sid, &rid)) {
+ DEBUG(1,("No rid for %s !?\n", name));
+ continue;
+ }
+
+ (*info)[i].acct_name = name;
+ (*info)[i].full_name = gecos;
+ (*info)[i].user_rid = rid;
+ (*info)[i].group_rid = group;
+ i++;
+ }
+
+ (*num_entries) = i;
+
+ ads_destroy(&ads);
+
+ return NT_STATUS_OK;
+}
+
+/* list all domain groups */
+static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
+ TALLOC_CTX *mem_ctx,
+ uint32 *start_ndx, uint32 *num_entries,
+ struct acct_info **info)
+{
+ ADS_STRUCT *ads;
+ const char *attrs[] = {"sAMAccountName", "name", "objectSid",
+ "sAMAccountType", NULL};
+ int rc, i, count;
+ void *res;
+ void *msg;
+
+ DEBUG(3,("ads: enum_dom_groups\n"));
+
+ if ((*start_ndx) != 0) {
+ DEBUG(1,("ads backend start_ndx not implemented\n"));
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+
+ ads = ads_init(NULL, NULL, NULL);
+ if (!ads) {
+ DEBUG(1,("ads_init failed\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ rc = ads_connect(ads);
+ if (rc) {
+ DEBUG(1,("query_dispinfo ads_connect: %s\n", ads_errstr(rc)));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ rc = ads_search(ads, &res, "(objectclass=group)", attrs);
+ if (rc) {
+ DEBUG(1,("query_dispinfo ads_search: %s\n", ads_errstr(rc)));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ count = ads_count_replies(ads, res);
+ if (count == 0) {
+ DEBUG(1,("query_dispinfo: No users found\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ (*info) = talloc(mem_ctx, count * sizeof(**info));
+ if (!*info) return NT_STATUS_NO_MEMORY;
+
+ i = 0;
+
+ for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) {
+ char *name, *gecos;
+ DOM_SID sid;
+ uint32 rid;
+ uint32 account_type;
+
+ if (!ads_pull_uint32(ads, msg, "sAMAccountType",
+ &account_type) ||
+ !(account_type & ATYPE_NORMAL_GROUP)) continue;
+
+ name = ads_pull_string(ads, mem_ctx, msg, "sAMAccountName");
+ gecos = ads_pull_string(ads, mem_ctx, msg, "name");
+ if (!ads_pull_sid(ads, msg, "objectSid", &sid)) {
+ DEBUG(1,("No sid for %s !?\n", name));
+ continue;
+ }
+
+ if (!sid_peek_rid(&sid, &rid)) {
+ DEBUG(1,("No rid for %s !?\n", name));
+ continue;
+ }
+
+ fstrcpy((*info)[i].acct_name, name);
+ fstrcpy((*info)[i].acct_desc, gecos);
+ (*info)[i].rid = rid;
+ i++;
+ }
+
+ (*num_entries) = i;
+
+ ads_destroy(&ads);
+
+ return NT_STATUS_OK;
+}
+
+
+/* the rpc backend methods are exposed via this structure */
+struct winbindd_methods ads_methods = {
+ query_dispinfo,
+ enum_dom_groups
+};
+
+#endif
diff --git a/source3/nsswitch/winbindd_rpc.c b/source3/nsswitch/winbindd_rpc.c
index 6b86ebd2da..ba428c5aed 100644
--- a/source3/nsswitch/winbindd_rpc.c
+++ b/source3/nsswitch/winbindd_rpc.c
@@ -26,10 +26,10 @@
/* Query display info for a domain. This returns enough information plus a
bit extra to give an overview of domain users for the User Manager
application. */
-static NTSTATUS winbindd_query_dispinfo(struct winbindd_domain *domain,
- TALLOC_CTX *mem_ctx,
- uint32 *start_ndx, uint32 *num_entries,
- WINBIND_DISPINFO **info)
+static NTSTATUS query_dispinfo(struct winbindd_domain *domain,
+ TALLOC_CTX *mem_ctx,
+ uint32 *start_ndx, uint32 *num_entries,
+ WINBIND_DISPINFO **info)
{
CLI_POLICY_HND *hnd;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
@@ -89,10 +89,10 @@ static NTSTATUS winbindd_query_dispinfo(struct winbindd_domain *domain,
}
/* list all domain groups */
-static NTSTATUS winbindd_enum_dom_groups(struct winbindd_domain *domain,
- TALLOC_CTX *mem_ctx,
- uint32 *start_ndx, uint32 *num_entries,
- struct acct_info **info)
+static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
+ TALLOC_CTX *mem_ctx,
+ uint32 *start_ndx, uint32 *num_entries,
+ struct acct_info **info)
{
uint32 des_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
CLI_POLICY_HND *hnd;
@@ -124,7 +124,7 @@ static NTSTATUS winbindd_enum_dom_groups(struct winbindd_domain *domain,
/* the rpc backend methods are exposed via this structure */
struct winbindd_methods msrpc_methods = {
- winbindd_query_dispinfo,
- winbindd_enum_dom_groups
+ query_dispinfo,
+ enum_dom_groups
};
diff --git a/source3/nsswitch/winbindd_util.c b/source3/nsswitch/winbindd_util.c
index 258a940225..50cc76f1e9 100644
--- a/source3/nsswitch/winbindd_util.c
+++ b/source3/nsswitch/winbindd_util.c
@@ -135,6 +135,20 @@ BOOL get_domain_info(void)
BOOL rv = False;
TALLOC_CTX *mem_ctx;
extern struct winbindd_methods msrpc_methods;
+ struct winbindd_methods *methods;
+
+ switch (lp_security()) {
+#ifdef HAVE_ADS
+ case SEC_ADS:
+ {
+ extern struct winbindd_methods ads_methods;
+ methods = &ads_methods;
+ break;
+ }
+#endif
+ default:
+ methods = &msrpc_methods;
+ }
DEBUG(1, ("getting trusted domain list\n"));
@@ -152,7 +166,7 @@ BOOL get_domain_info(void)
if (!NT_STATUS_IS_OK(result))
goto done;
- add_trusted_domain(lp_workgroup(), &domain_sid, &msrpc_methods);
+ add_trusted_domain(lp_workgroup(), &domain_sid, methods);
/* Enumerate list of trusted domains */
@@ -168,7 +182,7 @@ BOOL get_domain_info(void)
/* Add each domain to the trusted domain list */
for(i = 0; i < num_doms; i++)
- add_trusted_domain(domains[i], &sids[i], &msrpc_methods);
+ add_trusted_domain(domains[i], &sids[i], methods);
rv = True;