wmi-1.3.16 from opsview.com

This commit is contained in:
Are Casilla
2019-02-16 00:16:52 +01:00
parent 163fdd3d1b
commit 17b3af2911
2146 changed files with 678824 additions and 0 deletions
+237
View File
@@ -0,0 +1,237 @@
/*
Unix SMB/CIFS mplementation.
LDAP protocol helper functions for SAMBA
Copyright (C) Stefan Metzmacher 2004
Copyright (C) Simo Sorce 2004
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 "includes.h"
#include "libcli/ldap/ldap_client.h"
#include "lib/cmdline/popt_common.h"
#include "torture/torture.h"
#include "torture/ldap/proto.h"
static BOOL test_bind_simple(struct ldap_connection *conn, const char *userdn, const char *password)
{
NTSTATUS status;
BOOL ret = True;
status = torture_ldap_bind(conn, userdn, password);
if (!NT_STATUS_IS_OK(status)) {
ret = False;
}
return ret;
}
static BOOL test_bind_sasl(struct ldap_connection *conn, struct cli_credentials *creds)
{
NTSTATUS status;
BOOL ret = True;
printf("Testing sasl bind as user\n");
status = torture_ldap_bind_sasl(conn, creds);
if (!NT_STATUS_IS_OK(status)) {
ret = False;
}
return ret;
}
static BOOL test_multibind(struct ldap_connection *conn, const char *userdn, const char *password)
{
BOOL ret = True;
printf("Testing multiple binds on a single connnection as anonymous and user\n");
ret = test_bind_simple(conn, NULL, NULL);
if (!ret) {
printf("1st bind as anonymous failed\n");
return ret;
}
ret = test_bind_simple(conn, userdn, password);
if (!ret) {
printf("2nd bind as authenticated user failed\n");
}
return ret;
}
static BOOL test_search_rootDSE(struct ldap_connection *conn, char **basedn)
{
BOOL ret = True;
struct ldap_message *msg, *result;
struct ldap_request *req;
int i;
struct ldap_SearchResEntry *r;
NTSTATUS status;
printf("Testing RootDSE Search\n");
*basedn = NULL;
msg = new_ldap_message(conn);
if (!msg) {
return False;
}
msg->type = LDAP_TAG_SearchRequest;
msg->r.SearchRequest.basedn = "";
msg->r.SearchRequest.scope = LDAP_SEARCH_SCOPE_BASE;
msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER;
msg->r.SearchRequest.timelimit = 0;
msg->r.SearchRequest.sizelimit = 0;
msg->r.SearchRequest.attributesonly = False;
msg->r.SearchRequest.tree = ldb_parse_tree(msg, "(objectclass=*)");
msg->r.SearchRequest.num_attributes = 0;
msg->r.SearchRequest.attributes = NULL;
req = ldap_request_send(conn, msg);
if (req == NULL) {
printf("Could not setup ldap search\n");
return False;
}
status = ldap_result_one(req, &result, LDAP_TAG_SearchResultEntry);
if (!NT_STATUS_IS_OK(status)) {
printf("search failed - %s\n", nt_errstr(status));
return False;
}
printf("received %d replies\n", req->num_replies);
r = &result->r.SearchResultEntry;
DEBUG(1,("\tdn: %s\n", r->dn));
for (i=0; i<r->num_attributes; i++) {
int j;
for (j=0; j<r->attributes[i].num_values; j++) {
DEBUG(1,("\t%s: %d %.*s\n", r->attributes[i].name,
(int)r->attributes[i].values[j].length,
(int)r->attributes[i].values[j].length,
(char *)r->attributes[i].values[j].data));
if (!(*basedn) &&
strcasecmp("defaultNamingContext",r->attributes[i].name)==0) {
*basedn = talloc_asprintf(conn, "%.*s",
(int)r->attributes[i].values[j].length,
(char *)r->attributes[i].values[j].data);
}
}
}
talloc_free(req);
return ret;
}
static BOOL test_compare_sasl(struct ldap_connection *conn, const char *basedn)
{
struct ldap_message *msg, *rep;
struct ldap_request *req;
const char *val;
NTSTATUS status;
printf("Testing SASL Compare: %s\n", basedn);
if (!basedn) {
return False;
}
msg = new_ldap_message(conn);
if (!msg) {
return False;
}
msg->type = LDAP_TAG_CompareRequest;
msg->r.CompareRequest.dn = basedn;
msg->r.CompareRequest.attribute = talloc_strdup(msg, "objectClass");
val = "domain";
msg->r.CompareRequest.value = data_blob_talloc(msg, val, strlen(val));
req = ldap_request_send(conn, msg);
if (!req) {
return False;
}
status = ldap_result_one(req, &rep, LDAP_TAG_CompareResponse);
if (!NT_STATUS_IS_OK(status)) {
printf("error in ldap compare request - %s\n", nt_errstr(status));
return False;
}
DEBUG(5,("Code: %d DN: [%s] ERROR:[%s] REFERRAL:[%s]\n",
rep->r.CompareResponse.resultcode,
rep->r.CompareResponse.dn,
rep->r.CompareResponse.errormessage,
rep->r.CompareResponse.referral));
return True;
}
BOOL torture_ldap_basic(struct torture_context *torture)
{
NTSTATUS status;
struct ldap_connection *conn;
TALLOC_CTX *mem_ctx;
BOOL ret = True;
const char *host = torture_setting_string(torture, "host", NULL);
const char *userdn = torture_setting_string(torture, "ldap_userdn", NULL);
const char *secret = torture_setting_string(torture, "ldap_secret", NULL);
char *url;
char *basedn;
mem_ctx = talloc_init("torture_ldap_basic");
url = talloc_asprintf(mem_ctx, "ldap://%s/", host);
status = torture_ldap_connection(mem_ctx, &conn, url);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
if (!test_search_rootDSE(conn, &basedn)) {
ret = False;
}
/* other basic tests here */
if (!test_multibind(conn, userdn, secret)) {
ret = False;
}
if (!test_bind_sasl(conn, cmdline_credentials)) {
ret = False;
}
if (!test_compare_sasl(conn, basedn)) {
ret = False;
}
/* no more test we are closing */
torture_ldap_close(conn);
talloc_free(mem_ctx);
return ret;
}
+289
View File
@@ -0,0 +1,289 @@
/*
Unix SMB/CIFS mplementation.
test CLDAP operations
Copyright (C) Andrew Tridgell 2005
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 "includes.h"
#include "libcli/cldap/cldap.h"
#include "libcli/ldap/ldap.h"
#include "librpc/gen_ndr/ndr_nbt.h"
#include "torture/torture.h"
#include "lib/ldb/include/ldb.h"
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
printf("(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
ret = False; \
goto done; \
} \
} while (0)
/*
test netlogon operations
*/
static BOOL test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
{
struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
NTSTATUS status;
struct cldap_netlogon search, empty_search;
union nbt_cldap_netlogon n1;
struct GUID guid;
int i;
BOOL ret = True;
ZERO_STRUCT(search);
search.in.dest_address = dest;
search.in.acct_control = -1;
search.in.version = 6;
empty_search = search;
printf("Trying without any attributes\n");
search = empty_search;
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
n1 = search.out.netlogon;
search.in.user = "Administrator";
search.in.realm = n1.logon5.dns_domain;
search.in.host = "__cldap_torture__";
printf("Scanning for netlogon levels\n");
for (i=0;i<256;i++) {
search.in.version = i;
printf("Trying netlogon level %d\n", i);
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
}
printf("Scanning for netlogon level bits\n");
for (i=0;i<31;i++) {
search.in.version = (1<<i);
printf("Trying netlogon level 0x%x\n", i);
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
}
search.in.version = 6;
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with User=NULL\n");
search.in.user = NULL;
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with User=Administrator\n");
search.in.user = "Administrator";
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with a GUID\n");
search.in.realm = NULL;
search.in.domain_guid = GUID_string(mem_ctx, &n1.logon5.domain_uuid);
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with a incorrect GUID\n");
guid = GUID_random();
search.in.user = NULL;
search.in.domain_guid = GUID_string(mem_ctx, &guid);
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
printf("Trying with a AAC\n");
search.in.acct_control = 0x180;
search.in.realm = n1.logon5.dns_domain;
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with a bad AAC\n");
search.in.acct_control = 0xFF00FF00;
search.in.realm = n1.logon5.dns_domain;
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with a user only\n");
search = empty_search;
search.in.user = "Administrator";
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with just a bad username\n");
search.in.user = "___no_such_user___";
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with just a bad domain\n");
search = empty_search;
search.in.realm = "___no_such_domain___";
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
printf("Trying with a incorrect domain and correct guid\n");
search.in.domain_guid = GUID_string(mem_ctx, &n1.logon5.domain_uuid);
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("Trying with a incorrect domain and incorrect guid\n");
search.in.domain_guid = GUID_string(mem_ctx, &guid);
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
printf("Trying with a incorrect GUID and correct domain\n");
search.in.domain_guid = GUID_string(mem_ctx, &guid);
search.in.realm = n1.logon5.dns_domain;
status = cldap_netlogon(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
done:
return ret;
}
/*
convert a ldap result message to a ldb message. This allows us to
use the convenient ldif dump routines in ldb to print out cldap
search results
*/
static struct ldb_message *ldap_msg_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struct ldap_SearchResEntry *res)
{
struct ldb_message *msg;
msg = ldb_msg_new(mem_ctx);
msg->dn = ldb_dn_new(msg, ldb, res->dn);
msg->num_elements = res->num_attributes;
msg->elements = talloc_steal(msg, res->attributes);
return msg;
}
/*
dump a set of cldap results
*/
static void cldap_dump_results(struct cldap_search *search)
{
struct ldb_ldif ldif;
struct ldb_context *ldb;
if (!search || !(search->out.response)) {
return;
}
/* we need a ldb context to use ldb_ldif_write_file() */
ldb = ldb_init(NULL);
ZERO_STRUCT(ldif);
ldif.msg = ldap_msg_to_ldb(ldb, ldb, search->out.response);
ldb_ldif_write_file(ldb, stdout, &ldif);
talloc_free(ldb);
}
/*
test generic cldap operations
*/
static BOOL test_cldap_generic(TALLOC_CTX *mem_ctx, const char *dest)
{
struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
NTSTATUS status;
struct cldap_search search;
BOOL ret = True;
const char *attrs1[] = { "currentTime", "highestCommittedUSN", NULL };
const char *attrs2[] = { "currentTime", "highestCommittedUSN", "netlogon", NULL };
const char *attrs3[] = { "netlogon", NULL };
ZERO_STRUCT(search);
search.in.dest_address = dest;
search.in.timeout = 10;
search.in.retries = 3;
status = cldap_search(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
printf("fetching whole rootDSE\n");
search.in.filter = "(objectclass=*)";
search.in.attributes = NULL;
status = cldap_search(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
if (DEBUGLVL(3)) cldap_dump_results(&search);
printf("fetching currentTime and USN\n");
search.in.filter = "(objectclass=*)";
search.in.attributes = attrs1;
status = cldap_search(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
if (DEBUGLVL(3)) cldap_dump_results(&search);
printf("Testing currentTime, USN and netlogon\n");
search.in.filter = "(objectclass=*)";
search.in.attributes = attrs2;
status = cldap_search(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
if (DEBUGLVL(3)) cldap_dump_results(&search);
printf("Testing objectClass=* and netlogon\n");
search.in.filter = "(objectclass2=*)";
search.in.attributes = attrs2;
status = cldap_search(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
if (DEBUGLVL(3)) cldap_dump_results(&search);
printf("Testing a false expression\n");
search.in.filter = "(&(objectclass=*)(highestCommittedUSN=2))";
search.in.attributes = attrs1;
status = cldap_search(cldap, mem_ctx, &search);
CHECK_STATUS(status, NT_STATUS_OK);
if (DEBUGLVL(3)) cldap_dump_results(&search);
done:
return ret;
}
BOOL torture_cldap(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx;
BOOL ret = True;
const char *host = torture_setting_string(torture, "host", NULL);
mem_ctx = talloc_init("torture_cldap");
ret &= test_cldap_netlogon(mem_ctx, host);
ret &= test_cldap_generic(mem_ctx, host);
talloc_free(mem_ctx);
return ret;
}
+129
View File
@@ -0,0 +1,129 @@
/*
Unix SMB/CIFS implementation.
CLDAP benchmark test
Copyright (C) Andrew Tridgell 2005
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 "includes.h"
#include "lib/events/events.h"
#include "libcli/cldap/cldap.h"
#include "libcli/resolve/resolve.h"
#include "torture/torture.h"
struct bench_state {
int pass_count, fail_count;
};
static void request_handler(struct cldap_request *req)
{
struct cldap_netlogon io;
struct bench_state *state = talloc_get_type(req->async.private, struct bench_state);
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
io.in.version = 6;
status = cldap_netlogon_recv(req, tmp_ctx, &io);
if (NT_STATUS_IS_OK(status)) {
state->pass_count++;
} else {
state->fail_count++;
}
talloc_free(tmp_ctx);
}
/*
benchmark cldap calls
*/
static BOOL bench_cldap(TALLOC_CTX *mem_ctx, const char *address)
{
struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
int num_sent=0;
struct timeval tv = timeval_current();
BOOL ret = True;
int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
struct cldap_netlogon search;
struct bench_state *state;
state = talloc_zero(mem_ctx, struct bench_state);
ZERO_STRUCT(search);
search.in.dest_address = address;
search.in.acct_control = -1;
search.in.version = 6;
printf("Running for %d seconds\n", timelimit);
while (timeval_elapsed(&tv) < timelimit) {
while (num_sent - (state->pass_count+state->fail_count) < 10) {
struct cldap_request *req;
req = cldap_netlogon_send(cldap, &search);
req->async.private = state;
req->async.fn = request_handler;
num_sent++;
if (num_sent % 50 == 0) {
printf("%.1f queries per second (%d failures) \r",
state->pass_count / timeval_elapsed(&tv),
state->fail_count);
}
}
event_loop_once(cldap->event_ctx);
}
while (num_sent != (state->pass_count + state->fail_count)) {
event_loop_once(cldap->event_ctx);
}
printf("%.1f queries per second (%d failures) \n",
state->pass_count / timeval_elapsed(&tv),
state->fail_count);
talloc_free(cldap);
return ret;
}
/*
benchmark how fast a CLDAP server can respond to a series of parallel
requests
*/
BOOL torture_bench_cldap(struct torture_context *torture)
{
const char *address;
struct nbt_name name;
TALLOC_CTX *mem_ctx = talloc_new(NULL);
NTSTATUS status;
BOOL ret = True;
make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL));
/* do an initial name resolution to find its IP */
status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to resolve %s - %s\n",
name.name, nt_errstr(status));
talloc_free(mem_ctx);
return False;
}
ret &= bench_cldap(mem_ctx, address);
talloc_free(mem_ctx);
return ret;
}
+119
View File
@@ -0,0 +1,119 @@
/*
Unix SMB/CIFS mplementation.
LDAP protocol helper functions for SAMBA
Copyright (C) Stefan Metzmacher 2004
Copyright (C) Simo Sorce 2004
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 "includes.h"
#include "libcli/ldap/ldap.h"
#include "torture/torture.h"
#include "torture/ldap/proto.h"
NTSTATUS torture_ldap_bind(struct ldap_connection *conn, const char *userdn, const char *password)
{
NTSTATUS status;
status = ldap_bind_simple(conn, userdn, password);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to bind with provided credentials - %s\n",
nt_errstr(status));
}
return status;
}
_PUBLIC_ NTSTATUS torture_ldap_bind_sasl(struct ldap_connection *conn,
struct cli_credentials *creds)
{
NTSTATUS status;
status = ldap_bind_sasl(conn, creds);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed sasl bind with provided credentials - %s\n",
nt_errstr(status));
}
return status;
}
/* open a ldap connection to a server */
_PUBLIC_ NTSTATUS torture_ldap_connection(TALLOC_CTX *mem_ctx, struct ldap_connection **conn,
const char *url)
{
NTSTATUS status;
if (!url) {
printf("You must specify a url string\n");
return NT_STATUS_INVALID_PARAMETER;
}
*conn = ldap4_new_connection(mem_ctx, NULL);
status = ldap_connect(*conn, url);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to connect to ldap server '%s' - %s\n",
url, nt_errstr(status));
}
return status;
}
/* open a ldap connection to a server */
NTSTATUS torture_ldap_connection2(TALLOC_CTX *mem_ctx, struct ldap_connection **conn,
const char *url, const char *userdn, const char *password)
{
NTSTATUS status;
status = torture_ldap_connection(mem_ctx, conn, url);
NT_STATUS_NOT_OK_RETURN(status);
status = ldap_bind_simple(*conn, userdn, password);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed a simple ldap bind - %s\n", ldap_errstr(*conn, status));
}
return status;
}
/* close an ldap connection to a server */
NTSTATUS torture_ldap_close(struct ldap_connection *conn)
{
talloc_free(conn);
return NT_STATUS_OK;
}
NTSTATUS torture_ldap_init(void)
{
struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"LDAP");
torture_suite_add_simple_test(suite, "BENCH-CLDAP",
torture_bench_cldap);
torture_suite_add_simple_test(suite, "BASIC", torture_ldap_basic);
torture_suite_add_simple_test(suite, "CLDAP", torture_cldap);
torture_suite_add_simple_test(suite, "SCHEMA", torture_ldap_schema);
suite->description = talloc_strdup(
suite, "LDAP and CLDAP tests");
torture_register_suite(suite);
return NT_STATUS_OK;
}
+519
View File
@@ -0,0 +1,519 @@
/*
Unix SMB/CIFS mplementation.
LDAP schema tests
Copyright (C) Stefan Metzmacher 2006
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 "includes.h"
#include "libcli/ldap/ldap_client.h"
#include "lib/cmdline/popt_common.h"
#include "db_wrap.h"
#include "lib/ldb/include/ldb.h"
#include "lib/ldb/include/ldb_errors.h"
#include "dsdb/samdb/samdb.h"
#include "lib/util/dlinklist.h"
#include "torture/torture.h"
#include "torture/ldap/proto.h"
struct dsdb_attribute {
struct dsdb_attribute *prev, *next;
const char *lDAPDisplayName;
const char *attributeID;
uint32_t attID;
struct GUID schemaIDGUID;
uint32_t searchFlags;
BOOL systemOnly;
uint32_t systemFlags;
BOOL isMemberOfPartialAttributeSet;
const char *attributeSyntax;
uint32_t oMSyntax;
BOOL isSingleValued;
uint32_t rangeLower;
uint32_t rangeUpper;
BOOL showInAdvancedViewOnly;
const char *adminDisplayName;
const char *adminDescription;
};
struct dsdb_objectClass {
struct dsdb_objectClass *prev, *next;
const char *subClassOf;
const char *governsID;
const char *rDNAttID;
BOOL showInAdvancedViewOnly;
const char *adminDisplayName;
const char *adminDescription;
uint32_t objectClassCategory;
const char *lDAPDisplayName;
struct GUID schemaIDGUID;
BOOL systemOnly;
const char **systemPossSuperiors;
const char **systemMayContain;
const char **possSuperiors;
const char **mayContain;
const char *defaultSecurityDescriptor;
uint32_t systemFlags;
BOOL defaultHidingValue;
const char *defaultObjectCategory;
};
struct dsdb_schema {
struct dsdb_attribute *attributes;
struct dsdb_objectClass *objectClasses;
};
struct test_rootDSE {
const char *defaultdn;
const char *rootdn;
const char *configdn;
const char *schemadn;
};
struct test_schema_ctx {
struct ldb_paged_control *ctrl;
uint32_t count;
BOOL pending;
int (*callback)(void *, struct ldb_context *ldb, struct ldb_message *);
void *private_data;
};
static BOOL test_search_rootDSE(struct ldb_context *ldb, struct test_rootDSE *root)
{
int ret;
struct ldb_message *msg;
struct ldb_result *r;
d_printf("Testing RootDSE Search\n");
ret = ldb_search(ldb, ldb_dn_new(ldb, ldb, NULL), LDB_SCOPE_BASE,
NULL, NULL, &r);
if (ret != LDB_SUCCESS) {
return False;
} else if (r->count != 1) {
talloc_free(r);
return False;
}
msg = r->msgs[0];
root->defaultdn = ldb_msg_find_attr_as_string(msg, "defaultNamingContext", NULL);
talloc_steal(ldb, root->defaultdn);
root->rootdn = ldb_msg_find_attr_as_string(msg, "rootDomainNamingContext", NULL);
talloc_steal(ldb, root->rootdn);
root->configdn = ldb_msg_find_attr_as_string(msg, "configurationNamingContext", NULL);
talloc_steal(ldb, root->configdn);
root->schemadn = ldb_msg_find_attr_as_string(msg, "schemaNamingContext", NULL);
talloc_steal(ldb, root->schemadn);
talloc_free(r);
return True;
}
static int test_schema_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
{
struct test_schema_ctx *actx = talloc_get_type(context, struct test_schema_ctx);
int ret = LDB_SUCCESS;
switch (ares->type) {
case LDB_REPLY_ENTRY:
actx->count++;
ret = actx->callback(actx->private_data, ldb, ares->message);
break;
case LDB_REPLY_REFERRAL:
break;
case LDB_REPLY_DONE:
if (ares->controls) {
struct ldb_paged_control *ctrl = NULL;
int i;
for (i=0; ares->controls[i]; i++) {
if (strcmp(LDB_CONTROL_PAGED_RESULTS_OID, ares->controls[i]->oid) == 0) {
ctrl = talloc_get_type(ares->controls[i]->data, struct ldb_paged_control);
break;
}
}
if (!ctrl) break;
talloc_free(actx->ctrl->cookie);
actx->ctrl->cookie = talloc_steal(actx->ctrl->cookie, ctrl->cookie);
actx->ctrl->cookie_len = ctrl->cookie_len;
if (actx->ctrl->cookie_len > 0) {
actx->pending = True;
}
}
break;
default:
d_printf("%s: unknown Reply Type %u\n", __location__, ares->type);
return LDB_ERR_OTHER;
}
if (talloc_free(ares) == -1) {
d_printf("talloc_free failed\n");
actx->pending = 0;
return LDB_ERR_OPERATIONS_ERROR;
}
if (ret) {
return LDB_ERR_OPERATIONS_ERROR;
}
return LDB_SUCCESS;
}
static BOOL test_create_schema_type(struct ldb_context *ldb, struct test_rootDSE *root,
const char *filter,
int (*callback)(void *, struct ldb_context *ldb, struct ldb_message *),
void *private_data)
{
struct ldb_control **ctrl;
struct ldb_paged_control *control;
struct ldb_request *req;
int ret;
struct test_schema_ctx *actx;
req = talloc(ldb, struct ldb_request);
actx = talloc(req, struct test_schema_ctx);
ctrl = talloc_array(req, struct ldb_control *, 2);
ctrl[0] = talloc(ctrl, struct ldb_control);
ctrl[0]->oid = LDB_CONTROL_PAGED_RESULTS_OID;
ctrl[0]->critical = True;
control = talloc(ctrl[0], struct ldb_paged_control);
control->size = 1000;
control->cookie = NULL;
control->cookie_len = 0;
ctrl[0]->data = control;
ctrl[1] = NULL;
req->operation = LDB_SEARCH;
req->op.search.base = ldb_dn_new(req, ldb, root->schemadn);
req->op.search.scope = LDB_SCOPE_SUBTREE;
req->op.search.tree = ldb_parse_tree(req, filter);
if (req->op.search.tree == NULL) return -1;
req->op.search.attrs = NULL;
req->controls = ctrl;
req->context = actx;
req->callback = test_schema_search_callback;
ldb_set_timeout(ldb, req, 0);
actx->count = 0;
actx->ctrl = control;
actx->callback = callback;
actx->private_data = private_data;
again:
actx->pending = False;
ret = ldb_request(ldb, req);
if (ret != LDB_SUCCESS) {
d_printf("search failed - %s\n", ldb_errstring(ldb));
return False;
}
ret = ldb_wait(req->handle, LDB_WAIT_ALL);
if (ret != LDB_SUCCESS) {
d_printf("search error - %s\n", ldb_errstring(ldb));
return False;
}
if (actx->pending)
goto again;
d_printf("filter[%s] count[%u]\n", filter, actx->count);
return True;
}
#define GET_STRING(p, elem, strict) do { \
(p)->elem = samdb_result_string(msg, #elem, NULL);\
if (strict && (p)->elem == NULL) { \
d_printf("%s: %s == NULL\n", __location__, #elem); \
goto failed; \
} \
(void)talloc_steal(p, (p)->elem); \
} while (0)
#define GET_BOOL(p, elem, strict) do { \
const char *str; \
str = samdb_result_string(msg, #elem, NULL);\
if (str == NULL) { \
if (strict) { \
d_printf("%s: %s == NULL\n", __location__, #elem); \
goto failed; \
} else { \
(p)->elem = False; \
} \
} else if (strcasecmp("TRUE", str) == 0) { \
(p)->elem = True; \
} else if (strcasecmp("FALSE", str) == 0) { \
(p)->elem = False; \
} else { \
d_printf("%s: %s == %s\n", __location__, #elem, str); \
goto failed; \
} \
} while (0)
#define GET_UINT32(p, elem) do { \
(p)->elem = samdb_result_uint(msg, #elem, 0);\
} while (0)
#define GET_GUID(p, elem) do { \
(p)->elem = samdb_result_guid(msg, #elem);\
} while (0)
static int test_add_attribute(void *ptr, struct ldb_context *ldb, struct ldb_message *msg)
{
struct dsdb_schema *schema = talloc_get_type(ptr, struct dsdb_schema);
struct dsdb_attribute *attr;
attr = talloc_zero(schema, struct dsdb_attribute);
GET_STRING(attr, lDAPDisplayName, True);
GET_STRING(attr, attributeID, True);
attr->attID = UINT32_MAX;
GET_GUID(attr, schemaIDGUID);
GET_UINT32(attr, searchFlags);
GET_BOOL(attr, systemOnly, False);
GET_UINT32(attr, systemFlags);
GET_BOOL(attr, isMemberOfPartialAttributeSet, False);
GET_STRING(attr, attributeSyntax, True);
GET_UINT32(attr, oMSyntax);
GET_BOOL(attr, isSingleValued, True);
GET_UINT32(attr, rangeLower);
GET_UINT32(attr, rangeUpper);
GET_BOOL(attr, showInAdvancedViewOnly, False);
GET_STRING(attr, adminDisplayName, True);
GET_STRING(attr, adminDescription, True);
DLIST_ADD_END(schema->attributes, attr, struct dsdb_attribute *);
return LDB_SUCCESS;
failed:
return LDB_ERR_OTHER;
}
static int test_add_class(void *ptr, struct ldb_context *ldb, struct ldb_message *msg)
{
struct dsdb_schema *schema = talloc_get_type(ptr, struct dsdb_schema);
struct dsdb_objectClass *obj;
obj = talloc_zero(schema, struct dsdb_objectClass);
GET_STRING(obj, subClassOf, True);
GET_STRING(obj, governsID, True);
GET_STRING(obj, rDNAttID, True);
GET_BOOL(obj, showInAdvancedViewOnly, False);
GET_STRING(obj, adminDisplayName, True);
GET_STRING(obj, adminDescription, True);
GET_UINT32(obj, objectClassCategory);
GET_STRING(obj, lDAPDisplayName, True);
GET_GUID(obj, schemaIDGUID);
GET_BOOL(obj, systemOnly, False);
obj->systemPossSuperiors= NULL;
obj->systemMayContain = NULL;
obj->possSuperiors = NULL;
obj->mayContain = NULL;
GET_STRING(obj, defaultSecurityDescriptor, False);
GET_UINT32(obj, systemFlags);
GET_BOOL(obj, defaultHidingValue, True);
GET_STRING(obj, defaultObjectCategory, True);
DLIST_ADD_END(schema->objectClasses, obj, struct dsdb_objectClass *);
return LDB_SUCCESS;
failed:
return LDB_ERR_OTHER;
}
static BOOL test_create_schema(struct ldb_context *ldb, struct test_rootDSE *root, struct dsdb_schema **_schema)
{
BOOL ret = True;
struct dsdb_schema *schema;
schema = talloc_zero(ldb, struct dsdb_schema);
d_printf("Fetching attributes...\n");
ret &= test_create_schema_type(ldb, root, "(objectClass=attributeSchema)",
test_add_attribute, schema);
d_printf("Fetching objectClasses...\n");
ret &= test_create_schema_type(ldb, root, "(objectClass=classSchema)",
test_add_class, schema);
if (ret == True) {
*_schema = schema;
}
return ret;
}
static BOOL test_dump_not_replicated(struct ldb_context *ldb, struct test_rootDSE *root, struct dsdb_schema *schema)
{
struct dsdb_attribute *a;
uint32_t a_i = 1;
d_printf("Dumping not replicated attributes\n");
for (a=schema->attributes; a; a = a->next) {
if (!(a->systemFlags & 0x00000001)) continue;
d_printf("attr[%4u]: '%s'\n", a_i++,
a->lDAPDisplayName);
}
return True;
}
static BOOL test_dump_partial(struct ldb_context *ldb, struct test_rootDSE *root, struct dsdb_schema *schema)
{
struct dsdb_attribute *a;
uint32_t a_i = 1;
d_printf("Dumping attributes which are provided by the global catalog\n");
for (a=schema->attributes; a; a = a->next) {
if (!(a->systemFlags & 0x00000002) && !a->isMemberOfPartialAttributeSet) continue;
d_printf("attr[%4u]: %u %u '%s'\n", a_i++,
a->systemFlags & 0x00000002, a->isMemberOfPartialAttributeSet,
a->lDAPDisplayName);
}
return True;
}
static BOOL test_dump_contructed(struct ldb_context *ldb, struct test_rootDSE *root, struct dsdb_schema *schema)
{
struct dsdb_attribute *a;
uint32_t a_i = 1;
d_printf("Dumping constructed attributes\n");
for (a=schema->attributes; a; a = a->next) {
if (!(a->systemFlags & 0x00000004)) continue;
d_printf("attr[%4u]: '%s'\n", a_i++,
a->lDAPDisplayName);
}
return True;
}
static BOOL test_dump_sorted_syntax(struct ldb_context *ldb, struct test_rootDSE *root, struct dsdb_schema *schema)
{
struct dsdb_attribute *a;
uint32_t a_i = 1;
uint32_t i;
const char *syntaxes[] = {
"2.5.5.0",
"2.5.5.1",
"2.5.5.2",
"2.5.5.3",
"2.5.5.4",
"2.5.5.5",
"2.5.5.6",
"2.5.5.7",
"2.5.5.8",
"2.5.5.9",
"2.5.5.10",
"2.5.5.11",
"2.5.5.12",
"2.5.5.13",
"2.5.5.14",
"2.5.5.15",
"2.5.5.16",
"2.5.5.17"
};
for (i=0; i < ARRAY_SIZE(syntaxes); i++) {
for (a=schema->attributes; a; a = a->next) {
if (strcmp(syntaxes[i], a->attributeSyntax) != 0) continue;
d_printf("attr[%4u]: %s %u '%s'\n", a_i++,
a->attributeSyntax, a->oMSyntax,
a->lDAPDisplayName);
}
}
return True;
}
BOOL torture_ldap_schema(struct torture_context *torture)
{
struct ldb_context *ldb;
TALLOC_CTX *mem_ctx;
BOOL ret = True;
const char *host = torture_setting_string(torture, "host", NULL);
char *url;
struct test_rootDSE rootDSE;
struct dsdb_schema *schema = NULL;
mem_ctx = talloc_init("torture_ldap_basic");
ZERO_STRUCT(rootDSE);
url = talloc_asprintf(mem_ctx, "ldap://%s/", host);
ldb = ldb_wrap_connect(mem_ctx, url,
NULL,
cmdline_credentials,
0, NULL);
if (!ldb) goto failed;
ret &= test_search_rootDSE(ldb, &rootDSE);
if (!ret) goto failed;
ret &= test_create_schema(ldb, &rootDSE, &schema);
if (!ret) goto failed;
ret &= test_dump_not_replicated(ldb, &rootDSE, schema);
ret &= test_dump_partial(ldb, &rootDSE, schema);
ret &= test_dump_contructed(ldb, &rootDSE, schema);
ret &= test_dump_sorted_syntax(ldb, &rootDSE, schema);
failed:
talloc_free(mem_ctx);
return ret;
}