2 ldb database library - samba extensions
4 Copyright (C) Andrew Tridgell 2010
6 ** NOTE! The following LGPL license applies to the ldb
7 ** library. This does NOT imply that all of Samba is released
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 3 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #include "ldb_module.h"
27 #include "lib/cmdline/cmdline.h"
28 #include "auth/gensec/gensec.h"
29 #include "auth/auth.h"
30 #include "param/param.h"
31 #include "dsdb/samdb/samdb.h"
32 #include "dsdb/common/util.h"
37 static bool is_popt_table_end(const struct poptOption
*o
)
39 if (o
->longName
== NULL
&&
40 o
->shortName
=='\0' &&
49 work out the length of a popt array
51 static size_t calculate_popt_array_length(struct poptOption
*opts
)
55 for (i
= 0; i
< UINT32_MAX
; i
++) {
56 struct poptOption
*o
= &(opts
[i
]);
58 if (is_popt_table_end(o
)) {
67 called to register additional command line options
69 static int extensions_hook(struct ldb_context
*ldb
, enum ldb_module_hook_type t
)
72 case LDB_MODULE_HOOK_CMDLINE_OPTIONS
: {
74 struct poptOption
**popt_options
= ldb_module_popt_options(ldb
);
75 struct poptOption
*new_array
= NULL
;
78 struct poptOption cmdline_extensions
[] = {
80 POPT_COMMON_CONNECTION
81 POPT_COMMON_CREDENTIALS
87 ok
= samba_cmdline_init(ldb
,
88 SAMBA_CMDLINE_CONFIG_CLIENT
,
89 false /* require_smbconf */);
94 len1
= calculate_popt_array_length(*popt_options
);
95 len2
= calculate_popt_array_length(cmdline_extensions
);
96 new_array
= talloc_array(ldb
,
99 if (NULL
== new_array
) {
103 memcpy(new_array
, *popt_options
, len1
*sizeof(struct poptOption
));
104 memcpy(new_array
+len1
, cmdline_extensions
, (1+len2
)*sizeof(struct poptOption
));
107 ok
= samba_cmdline_sanity_check(new_array
);
109 talloc_free(new_array
);
110 return ldb_error(ldb
,
111 LDB_ERR_OPERATIONS_ERROR
,
112 "Duplicate cmdline options detected!");
116 (*popt_options
) = new_array
;
120 case LDB_MODULE_HOOK_CMDLINE_PRECONNECT
: {
121 struct loadparm_context
*lp_ctx
= NULL
;
122 struct cli_credentials
*creds
= NULL
;
124 int r
= ldb_register_samba_handlers(ldb
);
125 if (r
!= LDB_SUCCESS
) {
126 return ldb_operr(ldb
);
130 lp_ctx
= samba_cmdline_get_lp_ctx();
131 creds
= samba_cmdline_get_creds();
136 system_session(lp_ctx
))) {
138 return ldb_operr(ldb
);
140 if (ldb_set_opaque(ldb
, "credentials", creds
)) {
141 return ldb_operr(ldb
);
143 if (ldb_set_opaque(ldb
, "loadparm", lp_ctx
)) {
144 return ldb_operr(ldb
);
147 ldb_set_utf8_fns(ldb
, NULL
, wrap_casefold
);
151 case LDB_MODULE_HOOK_CMDLINE_POSTCONNECT
:
152 /* get the domain SID into the cache for SDDL processing */
153 samdb_domain_sid(ldb
);
162 initialise the module
164 _PUBLIC_
int ldb_samba_extensions_init(const char *ldb_version
)
166 ldb_register_hook(extensions_hook
);