mirror of
https://github.com/samba-team/samba.git
synced 2024-12-29 11:21:54 +03:00
r7714: enable samba credentials handling in ldb tools. So you can now do a
encrypted ldbedit against w2k3
This commit is contained in:
parent
abc9f4bd89
commit
6277c3923e
@ -34,6 +34,7 @@
|
|||||||
#include "ldb/include/ldb_private.h"
|
#include "ldb/include/ldb_private.h"
|
||||||
#include "libcli/ldap/ldap.h"
|
#include "libcli/ldap/ldap.h"
|
||||||
#include "libcli/ldap/ldap_client.h"
|
#include "libcli/ldap/ldap_client.h"
|
||||||
|
#include "lib/cmdline/popt_common.h"
|
||||||
|
|
||||||
struct ildb_private {
|
struct ildb_private {
|
||||||
const char *basedn;
|
const char *basedn;
|
||||||
@ -110,6 +111,10 @@ static int ildb_search(struct ldb_module *module, const char *base,
|
|||||||
int count, i;
|
int count, i;
|
||||||
struct ldap_message **ldapres, *msg;
|
struct ldap_message **ldapres, *msg;
|
||||||
|
|
||||||
|
if (scope == LDB_SCOPE_DEFAULT) {
|
||||||
|
scope = LDB_SCOPE_SUBTREE;
|
||||||
|
}
|
||||||
|
|
||||||
if (base == NULL) {
|
if (base == NULL) {
|
||||||
base = "";
|
base = "";
|
||||||
}
|
}
|
||||||
@ -384,6 +389,15 @@ int ildb_connect(struct ldb_context *ldb, const char *url,
|
|||||||
ldb->modules->private_data = ildb;
|
ldb->modules->private_data = ildb;
|
||||||
ldb->modules->ops = &ildb_ops;
|
ldb->modules->ops = &ildb_ops;
|
||||||
|
|
||||||
|
if (cmdline_credentials->username_obtained > CRED_GUESSED) {
|
||||||
|
status = ldap_bind_sasl(ildb->ldap, cmdline_credentials);
|
||||||
|
if (!NT_STATUS_IS_OK(status)) {
|
||||||
|
ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n",
|
||||||
|
ldap_errstr(ildb->ldap, status));
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
#include "ldb/include/ldb.h"
|
#include "ldb/include/ldb.h"
|
||||||
#include "ldb/include/ldb_private.h"
|
#include "ldb/include/ldb_private.h"
|
||||||
#include "ldb/tools/cmdline.h"
|
#include "ldb/tools/cmdline.h"
|
||||||
|
#ifdef _SAMBA_BUILD_
|
||||||
|
#include "lib/cmdline/popt_common.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
process command line options
|
process command line options
|
||||||
@ -50,10 +53,20 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
|
|||||||
{ "num-records", 0, POPT_ARG_INT, &options.num_records, 0, "number of test records", NULL },
|
{ "num-records", 0, POPT_ARG_INT, &options.num_records, 0, "number of test records", NULL },
|
||||||
{ "all", 'a', POPT_ARG_NONE, &options.all_records, 0, "dn=*", NULL },
|
{ "all", 'a', POPT_ARG_NONE, &options.all_records, 0, "dn=*", NULL },
|
||||||
{ "sorted", 'S', POPT_ARG_NONE, &options.sorted, 0, "sort attributes", NULL },
|
{ "sorted", 'S', POPT_ARG_NONE, &options.sorted, 0, "sort attributes", NULL },
|
||||||
|
{ "sasl-mechanism", 0, POPT_ARG_STRING, &options.sasl_mechanism, 0, "choose SASL mechanism", "MECHANISM" },
|
||||||
{ NULL, 'o', POPT_ARG_STRING, NULL, 'o', "ldb_connect option", "OPTION" },
|
{ NULL, 'o', POPT_ARG_STRING, NULL, 'o', "ldb_connect option", "OPTION" },
|
||||||
|
#ifdef _SAMBA_BUILD_
|
||||||
|
POPT_COMMON_SAMBA
|
||||||
|
POPT_COMMON_CREDENTIALS
|
||||||
|
POPT_COMMON_VERSION
|
||||||
|
#endif
|
||||||
POPT_TABLEEND
|
POPT_TABLEEND
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef _SAMBA_BUILD_
|
||||||
|
ldbsearch_init_subsystems;
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = talloc_zero(ldb, struct ldb_cmdline);
|
ret = talloc_zero(ldb, struct ldb_cmdline);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
ldb_oom(ldb);
|
ldb_oom(ldb);
|
||||||
@ -74,6 +87,8 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
|
|||||||
options.editor = "vi";
|
options.editor = "vi";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.scope = LDB_SCOPE_DEFAULT;
|
||||||
|
|
||||||
pc = poptGetContext(argv[0], argc, argv, popt_options,
|
pc = poptGetContext(argv[0], argc, argv, popt_options,
|
||||||
POPT_CONTEXT_KEEP_FIRST);
|
POPT_CONTEXT_KEEP_FIRST);
|
||||||
|
|
||||||
@ -133,6 +148,12 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ldb_connect(ldb, ret->url, 0, ret->options) != 0) {
|
||||||
|
fprintf(stderr, "Failed to connect to %s - %s\n",
|
||||||
|
ret->url, ldb_errstring(ldb));
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
|
@ -39,6 +39,7 @@ struct ldb_cmdline {
|
|||||||
const char **argv;
|
const char **argv;
|
||||||
int num_records;
|
int num_records;
|
||||||
int num_searches;
|
int num_searches;
|
||||||
|
const char *sasl_mechanism;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const char **argv,
|
struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const char **argv,
|
||||||
|
@ -90,21 +90,13 @@ static int process_file(struct ldb_context *ldb, FILE *f)
|
|||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
struct ldb_context *ldb;
|
struct ldb_context *ldb;
|
||||||
int i, ret, count=0;
|
int i, count=0;
|
||||||
struct ldb_cmdline *options;
|
struct ldb_cmdline *options;
|
||||||
|
|
||||||
ldb = ldb_init(NULL);
|
ldb = ldb_init(NULL);
|
||||||
|
|
||||||
options = ldb_cmdline_process(ldb, argc, argv, usage);
|
options = ldb_cmdline_process(ldb, argc, argv, usage);
|
||||||
|
|
||||||
ret = ldb_connect(ldb, options->url, 0, options->options);
|
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "Failed to connect to %s - %s\n",
|
|
||||||
options->url, ldb_errstring(ldb));
|
|
||||||
talloc_free(ldb);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->argc == 0) {
|
if (options->argc == 0) {
|
||||||
count += process_file(ldb, stdin);
|
count += process_file(ldb, stdin);
|
||||||
} else {
|
} else {
|
||||||
|
@ -93,14 +93,6 @@ static void usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ldb_connect(ldb, options->url, 0, options->options);
|
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "Failed to connect to %s - %s\n",
|
|
||||||
options->url, ldb_errstring(ldb));
|
|
||||||
talloc_free(ldb);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i=0;i<options->argc;i++) {
|
for (i=0;i<options->argc;i++) {
|
||||||
const char *dn = options->argv[i];
|
const char *dn = options->argv[i];
|
||||||
if (options->recursive) {
|
if (options->recursive) {
|
||||||
|
@ -303,14 +303,6 @@ static void usage(void)
|
|||||||
attrs = (const char * const *)options->argv;
|
attrs = (const char * const *)options->argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ldb_connect(ldb, options->url, LDB_FLG_RDONLY, options->options);
|
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "Failed to connect to %s - %s\n",
|
|
||||||
options->url, ldb_errstring(ldb));
|
|
||||||
talloc_free(ldb);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = ldb_search(ldb, options->basedn, options->scope, expression, attrs, &msgs);
|
ret = ldb_search(ldb, options->basedn, options->scope, expression, attrs, &msgs);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
printf("search failed - %s\n", ldb_errstring(ldb));
|
printf("search failed - %s\n", ldb_errstring(ldb));
|
||||||
|
@ -100,14 +100,6 @@ static int process_file(struct ldb_context *ldb, FILE *f)
|
|||||||
|
|
||||||
options = ldb_cmdline_process(ldb, argc, argv, usage);
|
options = ldb_cmdline_process(ldb, argc, argv, usage);
|
||||||
|
|
||||||
ret = ldb_connect(ldb, options->url, 0, options->options);
|
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "Failed to connect to %s - %s\n",
|
|
||||||
options->url, ldb_errstring(ldb));
|
|
||||||
talloc_free(ldb);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->argc == 0) {
|
if (options->argc == 0) {
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -67,14 +67,6 @@ static void usage(void)
|
|||||||
|
|
||||||
options = ldb_cmdline_process(ldb, argc, argv, usage);
|
options = ldb_cmdline_process(ldb, argc, argv, usage);
|
||||||
|
|
||||||
ret = ldb_connect(ldb, options->url, 0, options->options);
|
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "Failed to connect to %s - %s\n",
|
|
||||||
options->url, ldb_errstring(ldb));
|
|
||||||
talloc_free(ldb);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->argc < 2) {
|
if (options->argc < 2) {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ static int do_search(struct ldb_context *ldb,
|
|||||||
struct ldb_context *ldb;
|
struct ldb_context *ldb;
|
||||||
const char * const * attrs = NULL;
|
const char * const * attrs = NULL;
|
||||||
struct ldb_cmdline *options;
|
struct ldb_cmdline *options;
|
||||||
int ret;
|
int ret = -1;
|
||||||
|
|
||||||
ldb = ldb_init(NULL);
|
ldb = ldb_init(NULL);
|
||||||
|
|
||||||
@ -134,14 +134,6 @@ static int do_search(struct ldb_context *ldb,
|
|||||||
attrs = (const char * const *)(options->argv+1);
|
attrs = (const char * const *)(options->argv+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ldb_connect(ldb, options->url, LDB_FLG_RDONLY, options->options);
|
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "Failed to connect to %s - %s\n",
|
|
||||||
options->url, ldb_errstring(ldb));
|
|
||||||
talloc_free(ldb);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->interactive) {
|
if (options->interactive) {
|
||||||
char line[1024];
|
char line[1024];
|
||||||
while (fgets(line, sizeof(line), stdin)) {
|
while (fgets(line, sizeof(line), stdin)) {
|
||||||
|
@ -365,14 +365,6 @@ static void usage(void)
|
|||||||
options->basedn = "ou=Ldb Test,ou=People,o=University of Michigan,c=US";
|
options->basedn = "ou=Ldb Test,ou=People,o=University of Michigan,c=US";
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ldb_connect(ldb, options->url, 0, options->options);
|
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "Failed to connect to %s - %s\n",
|
|
||||||
options->url, ldb_errstring(ldb));
|
|
||||||
talloc_free(ldb);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
srandom(1);
|
srandom(1);
|
||||||
|
|
||||||
start_test(ldb, options->num_records, options->num_searches);
|
start_test(ldb, options->num_records, options->num_searches);
|
||||||
|
Loading…
Reference in New Issue
Block a user