summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/cmdline/popt_common.c6
-rw-r--r--source4/lib/cmdline/popt_common.h16
-rw-r--r--source4/lib/cmdline/popt_credentials.c2
-rw-r--r--source4/lib/events/events.h2
-rw-r--r--source4/lib/ldb-samba/ldb_wrap.c15
-rw-r--r--source4/lib/ldb-samba/ldb_wrap.h6
-rw-r--r--source4/lib/ldb-samba/samba_extensions.c2
-rw-r--r--source4/lib/ldb-samba/wscript_build2
-rw-r--r--source4/lib/ldb/common/ldb_controls.c8
-rw-r--r--source4/lib/ldb/common/ldb_msg.c3
-rw-r--r--source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c5
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c3
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c12
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_pack.c4
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c7
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c19
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.h13
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c76
-rw-r--r--source4/lib/ldb/pyldb.c165
-rwxr-xr-xsource4/lib/ldb/tests/python/api.py5
-rw-r--r--source4/lib/ldb/tools/cmdline.c4
-rw-r--r--source4/lib/ldb/tools/ldbtest.c12
-rwxr-xr-xsource4/lib/ldb/wscript17
-rw-r--r--source4/lib/messaging/irpc.h14
-rw-r--r--source4/lib/messaging/messaging.c178
-rw-r--r--source4/lib/messaging/messaging.h22
-rw-r--r--source4/lib/messaging/pymessaging.c114
-rw-r--r--source4/lib/messaging/tests/irpc.c10
-rw-r--r--source4/lib/messaging/tests/messaging.c34
-rw-r--r--source4/lib/registry/rpc.c2
-rw-r--r--source4/lib/registry/wscript_build2
-rw-r--r--source4/lib/socket/access.c8
-rw-r--r--source4/lib/socket/connect_multi.c4
-rw-r--r--source4/lib/socket/interface.c389
-rw-r--r--source4/lib/socket/netif.c127
-rw-r--r--source4/lib/socket/netif.h14
-rw-r--r--source4/lib/socket/socket.c169
-rw-r--r--source4/lib/socket/socket.h10
-rw-r--r--source4/lib/socket/socket_ip.c86
-rw-r--r--source4/lib/socket/socket_unix.c16
-rw-r--r--source4/lib/socket/testsuite.c14
-rw-r--r--source4/lib/socket/wscript_build10
-rw-r--r--source4/lib/tdb_wrap.c117
-rw-r--r--source4/lib/tdb_wrap.h45
-rw-r--r--source4/lib/wscript_build9
45 files changed, 893 insertions, 905 deletions
diff --git a/source4/lib/cmdline/popt_common.c b/source4/lib/cmdline/popt_common.c
index 16c6a1b81b..af1e900092 100644
--- a/source4/lib/cmdline/popt_common.c
+++ b/source4/lib/cmdline/popt_common.c
@@ -186,7 +186,7 @@ static void popt_common_callback(poptContext con,
}
}
-struct poptOption popt_common_connection[] = {
+struct poptOption popt_common_connection4[] = {
{ NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback },
{ "name-resolve", 'R', POPT_ARG_STRING, NULL, 'R', "Use these name resolution services only", "NAME-RESOLVE-ORDER" },
{ "socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use", "SOCKETOPTIONS" },
@@ -199,7 +199,7 @@ struct poptOption popt_common_connection[] = {
{ NULL }
};
-struct poptOption popt_common_samba[] = {
+struct poptOption popt_common_samba4[] = {
{ NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_samba_callback },
{ "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" },
{ "debug-stderr", 0, POPT_ARG_NONE, NULL, OPT_DEBUG_STDERR, "Send debug output to STDERR", NULL },
@@ -211,7 +211,7 @@ struct poptOption popt_common_samba[] = {
{ NULL }
};
-struct poptOption popt_common_version[] = {
+struct poptOption popt_common_version4[] = {
{ NULL, 0, POPT_ARG_CALLBACK, (void *)popt_version_callback },
{ "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" },
{ NULL }
diff --git a/source4/lib/cmdline/popt_common.h b/source4/lib/cmdline/popt_common.h
index 2f4ab2c178..8aed4d0496 100644
--- a/source4/lib/cmdline/popt_common.h
+++ b/source4/lib/cmdline/popt_common.h
@@ -23,19 +23,19 @@
#include <popt.h>
/* Common popt structures */
-extern struct poptOption popt_common_samba[];
-extern struct poptOption popt_common_connection[];
-extern struct poptOption popt_common_version[];
-extern struct poptOption popt_common_credentials[];
+extern struct poptOption popt_common_samba4[];
+extern struct poptOption popt_common_connection4[];
+extern struct poptOption popt_common_version4[];
+extern struct poptOption popt_common_credentials4[];
#ifndef POPT_TABLEEND
#define POPT_TABLEEND { NULL, '\0', 0, 0, 0, NULL, NULL }
#endif
-#define POPT_COMMON_SAMBA { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_samba, 0, "Common samba options:", NULL },
-#define POPT_COMMON_CONNECTION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_connection, 0, "Connection options:", NULL },
-#define POPT_COMMON_VERSION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version, 0, "Common samba options:", NULL },
-#define POPT_COMMON_CREDENTIALS { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_credentials, 0, "Authentication options:", NULL },
+#define POPT_COMMON_SAMBA { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_samba4, 0, "Common samba options:", NULL },
+#define POPT_COMMON_CONNECTION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_connection4, 0, "Connection options:", NULL },
+#define POPT_COMMON_VERSION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version4, 0, "Common samba options:", NULL },
+#define POPT_COMMON_CREDENTIALS { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_credentials4, 0, "Authentication options:", NULL },
extern struct cli_credentials *cmdline_credentials;
extern struct loadparm_context *cmdline_lp_ctx;
diff --git a/source4/lib/cmdline/popt_credentials.c b/source4/lib/cmdline/popt_credentials.c
index 6dcef3f22b..497d2a7228 100644
--- a/source4/lib/cmdline/popt_credentials.c
+++ b/source4/lib/cmdline/popt_credentials.c
@@ -168,7 +168,7 @@ static void popt_common_credentials_callback(poptContext con,
-struct poptOption popt_common_credentials[] = {
+struct poptOption popt_common_credentials4[] = {
{ NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_credentials_callback },
{ "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
{ "no-pass", 'N', POPT_ARG_NONE, &dont_ask, 'N', "Don't ask for a password" },
diff --git a/source4/lib/events/events.h b/source4/lib/events/events.h
index f66698838d..546a5e5158 100644
--- a/source4/lib/events/events.h
+++ b/source4/lib/events/events.h
@@ -1,6 +1,8 @@
#ifndef __LIB_EVENTS_H__
#define __LIB_EVENTS_H__
+#ifndef TEVENT_COMPAT_DEFINES
#define TEVENT_COMPAT_DEFINES 1
+#endif
#include <tevent.h>
struct tevent_context *s4_event_context_init(TALLOC_CTX *mem_ctx);
struct tevent_context *event_context_find(TALLOC_CTX *mem_ctx) _DEPRECATED_;
diff --git a/source4/lib/ldb-samba/ldb_wrap.c b/source4/lib/ldb-samba/ldb_wrap.c
index 7dcf514e23..66213bf288 100644
--- a/source4/lib/ldb-samba/ldb_wrap.c
+++ b/source4/lib/ldb-samba/ldb_wrap.c
@@ -35,7 +35,7 @@
#include "dsdb/samdb/samdb.h"
#include "param/param.h"
#include "../lib/util/dlinklist.h"
-#include <tdb.h>
+#include "../lib/tdb_compat/tdb_compat.h"
/*
this is used to catch debug messages from ldb
@@ -126,10 +126,7 @@ char *wrap_casefold(void *context, void *mem_ctx, const char *s, size_t n)
return NULL;
}
- ldb_set_modules_dir(ldb,
- talloc_asprintf(ldb,
- "%s/ldb",
- lpcfg_modulesdir(lp_ctx)));
+ ldb_set_modules_dir(ldb, modules_path(ldb, "ldb"));
ldb_set_debug(ldb, ldb_wrap_debug, NULL);
@@ -177,7 +174,7 @@ char *wrap_casefold(void *context, void *mem_ctx, const char *s, size_t n)
struct loadparm_context *lp_ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
- int flags)
+ unsigned int flags)
{
struct ldb_wrap *w;
/* see if we can re-use an existing ldb */
@@ -195,7 +192,7 @@ char *wrap_casefold(void *context, void *mem_ctx, const char *s, size_t n)
}
int samba_ldb_connect(struct ldb_context *ldb, struct loadparm_context *lp_ctx,
- const char *url, int flags)
+ const char *url, unsigned int flags)
{
int ret;
char *real_url = NULL;
@@ -209,7 +206,7 @@ int samba_ldb_connect(struct ldb_context *ldb, struct loadparm_context *lp_ctx,
flags |= LDB_FLG_ENABLE_TRACING;
}
- real_url = private_path(ldb, lp_ctx, url);
+ real_url = lpcfg_private_path(ldb, lp_ctx, url);
if (real_url == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -230,7 +227,7 @@ int samba_ldb_connect(struct ldb_context *ldb, struct loadparm_context *lp_ctx,
struct loadparm_context *lp_ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
- int flags,
+ unsigned int flags,
struct ldb_context *ldb)
{
struct ldb_wrap *w;
diff --git a/source4/lib/ldb-samba/ldb_wrap.h b/source4/lib/ldb-samba/ldb_wrap.h
index 4d2539fff5..aa7ccb3a23 100644
--- a/source4/lib/ldb-samba/ldb_wrap.h
+++ b/source4/lib/ldb-samba/ldb_wrap.h
@@ -53,18 +53,18 @@ struct ldb_context *ldb_wrap_find(const char *url,
struct loadparm_context *lp_ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
- int flags);
+ unsigned int flags);
bool ldb_wrap_add(const char *url, struct tevent_context *ev,
struct loadparm_context *lp_ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
- int flags,
+ unsigned int flags,
struct ldb_context *ldb);
char *ldb_relative_path(struct ldb_context *ldb,
TALLOC_CTX *mem_ctx,
const char *name);
int samba_ldb_connect(struct ldb_context *ldb, struct loadparm_context *lp_ctx,
- const char *url, int flags);
+ const char *url, unsigned int flags);
#endif /* _LDB_WRAP_H_ */
diff --git a/source4/lib/ldb-samba/samba_extensions.c b/source4/lib/ldb-samba/samba_extensions.c
index 63b0f3df91..be9f36a5a7 100644
--- a/source4/lib/ldb-samba/samba_extensions.c
+++ b/source4/lib/ldb-samba/samba_extensions.c
@@ -82,7 +82,7 @@ static int extensions_hook(struct ldb_context *ldb, enum ldb_module_hook_type t)
if (r != LDB_SUCCESS) {
return ldb_operr(ldb);
}
- gensec_init(cmdline_lp_ctx);
+ gensec_init();
if (ldb_set_opaque(ldb, "sessionInfo", system_session(cmdline_lp_ctx))) {
return ldb_operr(ldb);
diff --git a/source4/lib/ldb-samba/wscript_build b/source4/lib/ldb-samba/wscript_build
index a8d4df2ce0..2e1cacba64 100644
--- a/source4/lib/ldb-samba/wscript_build
+++ b/source4/lib/ldb-samba/wscript_build
@@ -8,7 +8,7 @@ bld.SAMBA_LIBRARY('ldbsamba',
source='ldif_handlers.c',
autoproto='ldif_handlers_proto.h',
public_deps='ldb',
- deps='security ndr NDR_DRSBLOBS NDR_DNSP ldbwrap samdb-common SAMDB_SCHEMA tdb pyldb-util',
+ deps='security ndr NDR_DRSBLOBS NDR_DNSP ldbwrap samdb-common SAMDB_SCHEMA tdb_compat pyldb-util errors',
private_library=True
)
diff --git a/source4/lib/ldb/common/ldb_controls.c b/source4/lib/ldb/common/ldb_controls.c
index 5048b6deac..b3ef243493 100644
--- a/source4/lib/ldb/common/ldb_controls.c
+++ b/source4/lib/ldb/common/ldb_controls.c
@@ -482,10 +482,10 @@ struct ldb_control *ldb_parse_control_from_string(struct ldb_context *ldb, TALLO
}
/* w2k3 seems to ignore the parameter,
- * but w2k sends a wrong cookie when this value is to small
- * this would cause looping forever, while getting
- * the same data and same cookie forever
- */
+ * but w2k sends a wrong cookie when this value is to small
+ * this would cause looping forever, while getting
+ * the same data and same cookie forever
+ */
if (max_attrs == 0) max_attrs = 0x0FFFFFFF;
ctrl->oid = LDB_CONTROL_DIRSYNC_OID;
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 9c5a279b8a..28c414e6b2 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -130,7 +130,6 @@ static int _ldb_msg_add_el(struct ldb_message *msg,
els = talloc_realloc(msg, msg->elements,
struct ldb_message_element, msg->num_elements + 1);
if (!els) {
- errno = ENOMEM;
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -164,7 +163,6 @@ int ldb_msg_add_empty(struct ldb_message *msg,
el->flags = flags;
el->name = talloc_strdup(msg->elements, attr_name);
if (!el->name) {
- errno = ENOMEM;
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -229,7 +227,6 @@ int ldb_msg_add_value(struct ldb_message *msg,
vals = talloc_realloc(msg->elements, el->values, struct ldb_val,
el->num_values+1);
if (!vals) {
- errno = ENOMEM;
return LDB_ERR_OPERATIONS_ERROR;
}
el->values = vals;
diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
index e5b43fd0c9..223868a6c0 100644
--- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
+++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
@@ -1136,7 +1136,7 @@ static int lsql_modify(struct lsql_context *ctx)
for (i = 0; i < msg->num_elements; i++) {
const struct ldb_message_element *el = &msg->elements[i];
const struct ldb_schema_attribute *a;
- int flags = el->flags & LDB_FLAG_MOD_MASK;
+ unsigned int flags = el->flags & LDB_FLAG_MOD_MASK;
char *attr;
char *mod;
unsigned int j;
@@ -1596,7 +1596,8 @@ static const struct ldb_module_ops lsqlite3_ops = {
*/
static int initialize(struct lsqlite3_private *lsqlite3,
- struct ldb_context *ldb, const char *url, int flags)
+ struct ldb_context *ldb, const char *url,
+ unsigned int flags)
{
TALLOC_CTX *local_ctx;
long long queryInt;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index 697f7427a4..e54ceaaa98 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -345,9 +345,6 @@ int ltdb_cache_load(struct ldb_module *module)
ltdb->check_base = false;
}
- talloc_free(ltdb->cache->last_attribute.name);
- memset(&ltdb->cache->last_attribute, 0, sizeof(ltdb->cache->last_attribute));
-
talloc_free(ltdb->cache->indexlist);
ltdb_attributes_unload(module); /* calls internally "talloc_free" */
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 02e4acbbde..24cc93feb9 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -155,7 +155,7 @@ static int ltdb_dn_list_load(struct ldb_module *module,
key.dptr = discard_const_p(unsigned char, ldb_dn_get_linearized(dn));
key.dsize = strlen((char *)key.dptr);
- rec = tdb_fetch(ltdb->idxptr->itdb, key);
+ rec = tdb_fetch_compat(ltdb->idxptr->itdb, key);
if (rec.dptr == NULL) {
goto normal_index;
}
@@ -261,7 +261,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
}
if (ltdb->idxptr->itdb == NULL) {
- ltdb->idxptr->itdb = tdb_open(NULL, 1000, TDB_INTERNAL, O_RDWR, 0);
+ ltdb->idxptr->itdb = tdb_open_compat(NULL, 1000, TDB_INTERNAL, O_RDWR, 0, NULL, NULL);
if (ltdb->idxptr->itdb == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -270,7 +270,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
key.dptr = discard_const_p(unsigned char, ldb_dn_get_linearized(dn));
key.dsize = strlen((char *)key.dptr);
- rec = tdb_fetch(ltdb->idxptr->itdb, key);
+ rec = tdb_fetch_compat(ltdb->idxptr->itdb, key);
if (rec.dptr != NULL) {
list2 = ltdb_index_idxptr(module, rec, false);
if (list2 == NULL) {
@@ -294,7 +294,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
rec.dsize = sizeof(void *);
ret = tdb_store(ltdb->idxptr->itdb, key, rec, TDB_INSERT);
- if (ret == -1) {
+ if (ret != 0) {
return ltdb_err_map(tdb_error(ltdb->idxptr->itdb));
}
return LDB_SUCCESS;
@@ -1569,7 +1569,7 @@ int ltdb_reindex(struct ldb_module *module)
* putting NULL entries in the in-memory tdb
*/
ret = tdb_traverse(ltdb->tdb, delete_index, module);
- if (ret == -1) {
+ if (ret < 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -1583,7 +1583,7 @@ int ltdb_reindex(struct ldb_module *module)
/* now traverse adding any indexes for normal LDB records */
ret = tdb_traverse(ltdb->tdb, re_index, &ctx);
- if (ret == -1) {
+ if (ret < 0) {
struct ldb_context *ldb = ldb_module_get_ctx(module);
ldb_asprintf_errstring(ldb, "reindexing traverse failed: %s", ldb_errstring(ldb));
return LDB_ERR_OPERATIONS_ERROR;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c
index 8ab07cd347..7c13065aee 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_pack.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c
@@ -74,7 +74,7 @@ static int attribute_storable_values(const struct ldb_message_element *el)
*/
int ltdb_pack_data(struct ldb_module *module,
const struct ldb_message *message,
- struct TDB_DATA *data)
+ TDB_DATA *data)
{
struct ldb_context *ldb;
unsigned int i, j, real_elements=0;
@@ -155,7 +155,7 @@ int ltdb_pack_data(struct ldb_module *module,
Free with ltdb_unpack_data_free()
*/
int ltdb_unpack_data(struct ldb_module *module,
- const struct TDB_DATA *data,
+ const TDB_DATA *data,
struct ldb_message *message)
{
struct ldb_context *ldb;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index a49751de15..46e2d74998 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -32,6 +32,7 @@
*/
#include "ldb_tdb.h"
+#include <lib/tdb_compat/tdb_compat.h>
/*
add one element to a message
@@ -223,7 +224,7 @@ static int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn)
return LDB_ERR_OPERATIONS_ERROR;
}
- tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
+ tdb_data = tdb_fetch_compat(ltdb->tdb, tdb_key);
talloc_free(tdb_key.dptr);
if (!tdb_data.dptr) {
return LDB_ERR_NO_SUCH_OBJECT;
@@ -255,7 +256,7 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes
return LDB_ERR_OPERATIONS_ERROR;
}
- tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
+ tdb_data = tdb_fetch_compat(ltdb->tdb, tdb_key);
talloc_free(tdb_key.dptr);
if (!tdb_data.dptr) {
return LDB_ERR_NO_SUCH_OBJECT;
@@ -479,7 +480,7 @@ static int ltdb_search_full(struct ltdb_context *ctx)
ret = tdb_traverse_read(ltdb->tdb, search_func, ctx);
}
- if (ret == -1) {
+ if (ret < 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 2f7f222086..0d4be49123 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -50,6 +50,7 @@
*/
#include "ldb_tdb.h"
+#include <lib/tdb_compat/tdb_compat.h>
/*
@@ -67,9 +68,13 @@ int ltdb_err_map(enum TDB_ERROR tdb_code)
case TDB_ERR_IO:
return LDB_ERR_PROTOCOL_ERROR;
case TDB_ERR_LOCK:
+#ifndef BUILD_TDB2
case TDB_ERR_NOLOCK:
+#endif
return LDB_ERR_BUSY;
+#ifndef BUILD_TDB2
case TDB_ERR_LOCK_TIMEOUT:
+#endif
return LDB_ERR_TIME_LIMIT_EXCEEDED;
case TDB_ERR_EXISTS:
return LDB_ERR_ENTRY_ALREADY_EXISTS;
@@ -110,7 +115,8 @@ int ltdb_unlock_read(struct ldb_module *module)
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
if (ltdb->in_transaction == 0 && ltdb->read_lock_count == 1) {
- return tdb_unlockall_read(ltdb->tdb);
+ tdb_unlockall_read(ltdb->tdb);
+ return 0;
}
ltdb->read_lock_count--;
return 0;
@@ -124,7 +130,7 @@ int ltdb_unlock_read(struct ldb_module *module)
note that the key for a record can depend on whether the
dn refers to a case sensitive index record or not
*/
-struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn)
+TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn)
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
TDB_DATA key;
@@ -263,7 +269,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg
}
ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs);
- if (ret == -1) {
+ if (ret != 0) {
ret = ltdb_err_map(tdb_error(ltdb->tdb));
goto done;
}
@@ -653,7 +659,7 @@ int ltdb_modify_internal(struct ldb_module *module,
return LDB_ERR_OTHER;
}
- tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
+ tdb_data = tdb_fetch_compat(ltdb->tdb, tdb_key);
if (!tdb_data.dptr) {
talloc_free(tdb_key.dptr);
return ltdb_err_map(tdb_error(ltdb->tdb));
@@ -1072,10 +1078,7 @@ static int ltdb_del_trans(struct ldb_module *module)
return ltdb_err_map(tdb_error(ltdb->tdb));
}
- if (tdb_transaction_cancel(ltdb->tdb) != 0) {
- return ltdb_err_map(tdb_error(ltdb->tdb));
- }
-
+ tdb_transaction_cancel(ltdb->tdb);
return LDB_SUCCESS;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
index 33313b00da..96ad43fbd6 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
@@ -1,7 +1,7 @@
#include "replace.h"
#include "system/filesys.h"
#include "system/time.h"
-#include "tdb.h"
+#include "tdb_compat.h"
#include "ldb_module.h"
/* this private structure is used by the ltdb backend in the
@@ -21,11 +21,6 @@ struct ltdb_private {
struct ldb_message *attributes;
bool one_level_indexes;
bool attribute_indexes;
-
- struct {
- char *name;
- int flags;
- } last_attribute;
} *cache;
int in_transaction;
@@ -107,11 +102,11 @@ int ltdb_index_transaction_cancel(struct ldb_module *module);
int ltdb_pack_data(struct ldb_module *module,
const struct ldb_message *message,
- struct TDB_DATA *data);
+ TDB_DATA *data);
void ltdb_unpack_data_free(struct ldb_module *module,
struct ldb_message *message);
int ltdb_unpack_data(struct ldb_module *module,
- const struct TDB_DATA *data,
+ const TDB_DATA *data,
struct ldb_message *message);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c */
@@ -132,7 +127,7 @@ int ltdb_search(struct ltdb_context *ctx);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
int ltdb_lock_read(struct ldb_module *module);
int ltdb_unlock_read(struct ldb_module *module);
-struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
+TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn);
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
index b9f3e79f20..16a037a6c3 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
@@ -24,29 +24,30 @@
#include "ldb_tdb.h"
#include "dlinklist.h"
-/*
- the purpose of this code is to work around the braindead posix locking
- rules, to allow us to have a ldb open more than once while allowing
- locking to work
-*/
-
-struct ltdb_wrap {
- struct ltdb_wrap *next, *prev;
- struct tdb_context *tdb;
- dev_t device;
- ino_t inode;
-};
-
-static struct ltdb_wrap *tdb_list;
-
-/* destroy the last connection to a tdb */
-static int ltdb_wrap_destructor(struct ltdb_wrap *w)
+/* FIXME: TDB2 does this internally, so no need to wrap multiple opens! */
+#if BUILD_TDB2
+static void ltdb_log_fn(struct tdb_context *tdb,
+ enum tdb_log_level level,
+ const char *message,
+ struct ldb_context *ldb)
{
- tdb_close(w->tdb);
- DLIST_REMOVE(tdb_list, w);
- return 0;
-}
+ enum ldb_debug_level ldb_level;
+ const char *name = tdb_name(tdb);
+
+ switch (level) {
+ case TDB_LOG_WARNING:
+ ldb_level = LDB_DEBUG_WARNING;
+ case TDB_LOG_USE_ERROR:
+ case TDB_LOG_ERROR:
+ ldb_level = LDB_DEBUG_FATAL;
+ break;
+ default:
+ ldb_level = LDB_DEBUG_FATAL;
+ }
+ ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message);
+}
+#else /* !TDB2 */
static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
{
@@ -83,6 +84,32 @@ static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, con
ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message);
talloc_free(message);
}
+#endif
+
+/*
+ the purpose of this code is to work around the braindead posix locking
+ rules, to allow us to have a ldb open more than once while allowing
+ locking to work
+
+ TDB2 handles multiple opens, so we don't have this problem there.
+*/
+
+struct ltdb_wrap {
+ struct ltdb_wrap *next, *prev;
+ struct tdb_context *tdb;
+ dev_t device;
+ ino_t inode;
+};
+
+static struct ltdb_wrap *tdb_list;
+
+/* destroy the last connection to a tdb */
+static int ltdb_wrap_destructor(struct ltdb_wrap *w)
+{
+ tdb_close(w->tdb);
+ DLIST_REMOVE(tdb_list, w);
+ return 0;
+}
/*
wrapped connection to a tdb database. The caller should _not_ free
@@ -98,10 +125,6 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
{
struct ltdb_wrap *w;
struct stat st;
- struct tdb_logging_context log_ctx;
-
- log_ctx.log_fn = ltdb_log_fn;
- log_ctx.log_private = ldb;
if (stat(path, &st) == 0) {
for (w=tdb_list;w;w=w->next) {
@@ -119,7 +142,7 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
return NULL;
}
- w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL);
+ w->tdb = tdb_open_compat(path, hash_size, tdb_flags, open_flags, mode, ltdb_log_fn, ldb);
if (w->tdb == NULL) {
talloc_free(w);
return NULL;
@@ -140,4 +163,3 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
return w->tdb;
}
-
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 5fcc5a64b6..e2a2e7180e 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -7,6 +7,8 @@
Copyright (C) 2006 Simo Sorce <idra@samba.org>
Copyright (C) 2007-2010 Jelmer Vernooij <jelmer@samba.org>
Copyright (C) 2009-2010 Matthias Dieter Wallnöfer
+ Copyright (C) 2009-2011 Andrew Tridgell
+ Copyright (C) 2009-2011 Andrew Bartlett
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
@@ -48,7 +50,7 @@ static PyObject *PyLdbModule_FromModule(struct ldb_module *mod);
static struct ldb_message_element *PyObject_AsMessageElement(
TALLOC_CTX *mem_ctx,
PyObject *set_obj,
- int flags,
+ unsigned int flags,
const char *attr_name);
/* There's no Py_ssize_t in 2.4, apparently */
@@ -384,6 +386,62 @@ static PyObject *py_ldb_dn_canonical_ex_str(PyLdbDnObject *self)
return PyString_FromString(ldb_dn_canonical_ex_string(self->dn, self->dn));
}
+static PyObject *py_ldb_dn_extended_str(PyLdbDnObject *self, PyObject *args, PyObject *kwargs)
+{
+ const char * const kwnames[] = { "mode", NULL };
+ int mode = 1;
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i",
+ discard_const_p(char *, kwnames),
+ &mode))
+ return NULL;
+ return PyString_FromString(ldb_dn_get_extended_linearized(self->dn, self->dn, mode));
+}
+
+static PyObject *py_ldb_dn_get_extended_component(PyLdbDnObject *self, PyObject *args)
+{
+ char *name;
+ const struct ldb_val *val;
+
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+ val = ldb_dn_get_extended_component(self->dn, name);
+ if (val == NULL) {
+ Py_RETURN_NONE;
+ }
+
+ return PyString_FromStringAndSize((const char *)val->data, val->length);
+}
+
+static PyObject *py_ldb_dn_set_extended_component(PyLdbDnObject *self, PyObject *args)
+{
+ char *name;
+ PyObject *value;
+ int err;
+
+ if (!PyArg_ParseTuple(args, "sO", &name, &value))
+ return NULL;
+
+ if (value == Py_None) {
+ err = ldb_dn_set_extended_component(self->dn, name, NULL);
+ } else {
+ struct ldb_val val;
+ if (!PyString_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "Expected a string argument");
+ return NULL;
+ }
+ val.data = (uint8_t *)PyString_AsString(value);
+ val.length = PyString_Size(value);
+ err = ldb_dn_set_extended_component(self->dn, name, &val);
+ }
+
+ if (err != LDB_SUCCESS) {
+ PyErr_SetString(PyExc_TypeError, "Failed to set extended component");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
static PyObject *py_ldb_dn_repr(PyLdbDnObject *self)
{
return PyString_FromFormat("Dn(%s)", PyObject_REPR(PyString_FromString(ldb_dn_get_linearized(self->dn))));
@@ -485,6 +543,9 @@ static PyMethodDef py_ldb_dn_methods[] = {
{ "canonical_ex_str", (PyCFunction)py_ldb_dn_canonical_ex_str, METH_NOARGS,
"S.canonical_ex_str() -> string\n"
"Canonical version of this DN (like a posix path, with terminating newline)." },
+ { "extended_str", (PyCFunction)py_ldb_dn_extended_str, METH_VARARGS | METH_KEYWORDS,
+ "S.extended_str(mode=1) -> string\n"
+ "Extended version of this DN" },
{ "parent", (PyCFunction)py_ldb_dn_get_parent, METH_NOARGS,
"S.parent() -> dn\n"
"Get the parent for this DN." },
@@ -497,6 +558,12 @@ static PyMethodDef py_ldb_dn_methods[] = {
{ "check_special", (PyCFunction)py_ldb_dn_check_special, METH_VARARGS,
"S.check_special(name) -> bool\n\n"
"Check if name is a special DN name"},
+ { "get_extended_component", (PyCFunction)py_ldb_dn_get_extended_component, METH_VARARGS,
+ "S.get_extended_component(name) -> string\n\n"
+ "returns a DN extended component as a binary string"},
+ { "set_extended_component", (PyCFunction)py_ldb_dn_set_extended_component, METH_VARARGS,
+ "S.set_extended_component(name, value) -> string\n\n"
+ "set a DN extended component as a binary string"},
{ NULL }
};
@@ -737,11 +804,11 @@ static int py_ldb_init(PyLdbObject *self, PyObject *args, PyObject *kwargs)
char *url = NULL;
PyObject *py_options = Py_None;
const char **options;
- int flags = 0;
+ unsigned int flags = 0;
int ret;
struct ldb_context *ldb;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ziO:Ldb.__init__",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|zIO:Ldb.__init__",
discard_const_p(char *, kwnames),
&url, &flags, &py_options))
return -1;
@@ -792,13 +859,13 @@ static PyObject *py_ldb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
static PyObject *py_ldb_connect(PyLdbObject *self, PyObject *args, PyObject *kwargs)
{
char *url;
- int flags = 0;
+ unsigned int flags = 0;
PyObject *py_options = Py_None;
int ret;
const char **options;
const char * const kwnames[] = { "url", "flags", "options", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ziO",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|zIO",
discard_const_p(char *, kwnames),
&url, &flags, &py_options))
return NULL;
@@ -819,7 +886,7 @@ static PyObject *py_ldb_connect(PyLdbObject *self, PyObject *args, PyObject *kwa
Py_RETURN_NONE;
}
-static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args)
+static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *py_msg;
PyObject *py_controls = Py_None;
@@ -829,8 +896,12 @@ static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args)
struct ldb_message *msg;
int ret;
TALLOC_CTX *mem_ctx;
+ bool validate=true;
+ const char * const kwnames[] = { "message", "controls", "validate", NULL };
- if (!PyArg_ParseTuple(args, "O|O", &py_msg, &py_controls))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Ob",
+ discard_const_p(char *, kwnames),
+ &py_msg, &py_controls, &validate))
return NULL;
mem_ctx = talloc_new(NULL);
@@ -855,11 +926,13 @@ static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args)
}
msg = PyLdbMessage_AsMessage(py_msg);
- ret = ldb_msg_sanity_check(ldb_ctx, msg);
- if (ret != LDB_SUCCESS) {
- PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx);
- talloc_free(mem_ctx);
- return NULL;
+ if (validate) {
+ ret = ldb_msg_sanity_check(ldb_ctx, msg);
+ if (ret != LDB_SUCCESS) {
+ PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx);
+ talloc_free(mem_ctx);
+ return NULL;
+ }
}
ret = ldb_build_mod_req(&req, ldb_ctx, mem_ctx, msg, parsed_controls,
@@ -958,7 +1031,7 @@ static struct ldb_message *PyDict_AsMessage(TALLOC_CTX *mem_ctx,
return msg;
}
-static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args)
+static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *py_obj;
int ret;
@@ -968,8 +1041,11 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args)
PyObject *py_controls = Py_None;
TALLOC_CTX *mem_ctx;
struct ldb_control **parsed_controls;
+ const char * const kwnames[] = { "message", "controls", NULL };
- if (!PyArg_ParseTuple(args, "O|O", &py_obj, &py_controls ))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
+ discard_const_p(char *, kwnames),
+ &py_obj, &py_controls))
return NULL;
mem_ctx = talloc_new(NULL);
@@ -1047,7 +1123,7 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args)
Py_RETURN_NONE;
}
-static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args)
+static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *py_dn;
struct ldb_dn *dn;
@@ -1057,8 +1133,11 @@ static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args)
PyObject *py_controls = Py_None;
TALLOC_CTX *mem_ctx;
struct ldb_control **parsed_controls;
+ const char * const kwnames[] = { "dn", "controls", NULL };
- if (!PyArg_ParseTuple(args, "O|O", &py_dn, &py_controls))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
+ discard_const_p(char *, kwnames),
+ &py_dn, &py_controls))
return NULL;
mem_ctx = talloc_new(NULL);
@@ -1119,7 +1198,7 @@ static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args)
Py_RETURN_NONE;
}
-static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args)
+static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *py_dn1, *py_dn2;
struct ldb_dn *dn1, *dn2;
@@ -1130,10 +1209,13 @@ static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args)
struct ldb_control **parsed_controls;
struct ldb_context *ldb_ctx;
struct ldb_request *req;
+ const char * const kwnames[] = { "dn1", "dn2", "controls", NULL };
ldb_ctx = PyLdb_AsLdbContext(self);
- if (!PyArg_ParseTuple(args, "OO|O", &py_dn1, &py_dn2, &py_controls))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O",
+ discard_const_p(char *, kwnames),
+ &py_dn1, &py_dn2, &py_controls))
return NULL;
@@ -1586,17 +1668,17 @@ static PyMethodDef py_ldb_methods[] = {
{ "connect", (PyCFunction)py_ldb_connect, METH_VARARGS|METH_KEYWORDS,
"S.connect(url, flags=0, options=None) -> None\n"
"Connect to a LDB URL." },
- { "modify", (PyCFunction)py_ldb_modify, METH_VARARGS,
- "S.modify(message) -> None\n"
+ { "modify", (PyCFunction)py_ldb_modify, METH_VARARGS|METH_KEYWORDS,
+ "S.modify(message, controls=None, validate=False) -> None\n"
"Modify an entry." },
- { "add", (PyCFunction)py_ldb_add, METH_VARARGS,
- "S.add(message) -> None\n"
+ { "add", (PyCFunction)py_ldb_add, METH_VARARGS|METH_KEYWORDS,
+ "S.add(message, controls=None) -> None\n"
"Add an entry." },
- { "delete", (PyCFunction)py_ldb_delete, METH_VARARGS,
- "S.delete(dn) -> None\n"
+ { "delete", (PyCFunction)py_ldb_delete, METH_VARARGS|METH_KEYWORDS,
+ "S.delete(dn, controls=None) -> None\n"
"Remove an entry." },
- { "rename", (PyCFunction)py_ldb_rename, METH_VARARGS,
- "S.rename(old_dn, new_dn) -> None\n"
+ { "rename", (PyCFunction)py_ldb_rename, METH_VARARGS|METH_KEYWORDS,
+ "S.rename(old_dn, new_dn, controls=None) -> None\n"
"Rename an entry." },
{ "search", (PyCFunction)py_ldb_search, METH_VARARGS|METH_KEYWORDS,
"S.search(base=None, scope=None, expression=None, attrs=None, controls=None) -> msgs\n"
@@ -2031,7 +2113,7 @@ static PyTypeObject PyLdbModule = {
static struct ldb_message_element *PyObject_AsMessageElement(
TALLOC_CTX *mem_ctx,
PyObject *set_obj,
- int flags,
+ unsigned int flags,
const char *attr_name)
{
struct ldb_message_element *me;
@@ -2122,9 +2204,9 @@ static PyObject *py_ldb_msg_element_flags(PyLdbMessageElementObject *self, PyObj
static PyObject *py_ldb_msg_element_set_flags(PyLdbMessageElementObject *self, PyObject *args)
{
- int flags;
+ unsigned int flags;
struct ldb_message_element *el;
- if (!PyArg_ParseTuple(args, "i", &flags))
+ if (!PyArg_ParseTuple(args, "I", &flags))
return NULL;
el = PyLdbMessageElement_AsMessageElement(self);
@@ -2192,13 +2274,13 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
{
PyObject *py_elements = NULL;
struct ldb_message_element *el;
- int flags = 0;
+ unsigned int flags = 0;
char *name = NULL;
const char * const kwnames[] = { "elements", "flags", "name", NULL };
PyLdbMessageElementObject *ret;
TALLOC_CTX *mem_ctx;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Ois",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OIs",
discard_const_p(char *, kwnames),
&py_elements, &flags, &name))
return NULL;
@@ -2427,15 +2509,20 @@ static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
static PyObject *py_ldb_msg_get(PyLdbMessageObject *self, PyObject *args)
{
- PyObject *name, *ret;
- if (!PyArg_ParseTuple(args, "O", &name))
+ PyObject *name, *ret, *retobj;
+ retobj = NULL;
+ if (!PyArg_ParseTuple(args, "O|O", &name, &retobj))
return NULL;
ret = py_ldb_msg_getitem_helper(self, name);
if (ret == NULL) {
if (PyErr_Occurred())
return NULL;
- Py_RETURN_NONE;
+ if (retobj != NULL) {
+ return retobj;
+ } else {
+ Py_RETURN_NONE;
+ }
}
return ret;
}
@@ -3202,4 +3289,14 @@ void initldb(void)
PyModule_AddObject(m, "Control", (PyObject *)&PyLdbControl);
PyModule_AddObject(m, "__version__", PyString_FromString(PACKAGE_VERSION));
+
+#define ADD_LDB_STRING(val) PyModule_AddObject(m, #val, PyString_FromString(val))
+
+ ADD_LDB_STRING(LDB_SYNTAX_DN);
+ ADD_LDB_STRING(LDB_SYNTAX_DN);
+ ADD_LDB_STRING(LDB_SYNTAX_DIRECTORY_STRING);
+ ADD_LDB_STRING(LDB_SYNTAX_INTEGER);
+ ADD_LDB_STRING(LDB_SYNTAX_BOOLEAN);
+ ADD_LDB_STRING(LDB_SYNTAX_OCTET_STRING);
+ ADD_LDB_STRING(LDB_SYNTAX_UTC_TIME);
}
diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py
index a9f68cbd71..e7658d51ab 100755
--- a/source4/lib/ldb/tests/python/api.py
+++ b/source4/lib/ldb/tests/python/api.py
@@ -516,6 +516,11 @@ class LdbMsgTests(unittest.TestCase):
self.msg["foo"] = ["bar"]
self.assertEquals("bar", self.msg.get("foo")[0])
+ def test_get_default(self):
+ self.assertEquals(None, self.msg.get("tatayoyo"))
+
+ self.assertEquals("anniecordie", self.msg.get("tatayoyo", "anniecordie"))
+
def test_get_unknown(self):
self.assertEquals(None, self.msg.get("lalalala"))
diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c
index b2be54ebf9..a06445fc0f 100644
--- a/source4/lib/ldb/tools/cmdline.c
+++ b/source4/lib/ldb/tools/cmdline.c
@@ -101,7 +101,7 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
poptContext pc;
int num_options = 0;
int opt;
- int flags = 0;
+ unsigned int flags = 0;
int rc;
struct poptOption **popt_options;
@@ -297,7 +297,7 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
}
/* now connect to the ldb */
- if (ldb_connect(ldb, ret->url, flags, ret->options) != 0) {
+ if (ldb_connect(ldb, ret->url, flags, ret->options) != LDB_SUCCESS) {
fprintf(stderr, "Failed to connect to %s - %s\n",
ret->url, ldb_errstring(ldb));
goto failed;
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index a9d8fafe81..4e181af9d5 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -126,7 +126,7 @@ static void add_records(struct ldb_context *ldb,
ldb_delete(ldb, msg.dn);
- if (ldb_add(ldb, &msg) != 0) {
+ if (ldb_add(ldb, &msg) != LDB_SUCCESS) {
printf("Add of %s failed - %s\n", name, ldb_errstring(ldb));
exit(LDB_ERR_OPERATIONS_ERROR);
}
@@ -183,7 +183,7 @@ static void modify_records(struct ldb_context *ldb,
vals[2].data = (uint8_t *)talloc_asprintf(tmp_ctx, "%s@other2.example.com", name);
vals[2].length = strlen((char *)vals[2].data);
- if (ldb_modify(ldb, &msg) != 0) {
+ if (ldb_modify(ldb, &msg) != LDB_SUCCESS) {
printf("Modify of %s failed - %s\n", name, ldb_errstring(ldb));
exit(LDB_ERR_OPERATIONS_ERROR);
}
@@ -213,7 +213,7 @@ static void delete_records(struct ldb_context *ldb,
printf("Deleting uid Test%d\r", i);
fflush(stdout);
- if (ldb_delete(ldb, dn) != 0) {
+ if (ldb_delete(ldb, dn) != LDB_SUCCESS) {
printf("Delete of %s failed - %s\n", ldb_dn_get_linearized(dn), ldb_errstring(ldb));
exit(LDB_ERR_OPERATIONS_ERROR);
}
@@ -304,7 +304,7 @@ static void start_test_index(struct ldb_context **ldb)
struct ldb_dn *indexlist;
struct ldb_dn *basedn;
int ret;
- int flags = 0;
+ unsigned int flags = 0;
const char *specials;
specials = getenv("LDB_SPECIALS");
@@ -343,7 +343,7 @@ static void start_test_index(struct ldb_context **ldb)
ldb_msg_add_string(msg, "uid", strdup("test"));
ldb_msg_add_string(msg, "objectClass", strdup("OpenLDAPperson"));
- if (ldb_add(*ldb, msg) != 0) {
+ if (ldb_add(*ldb, msg) != LDB_SUCCESS) {
printf("Add of %s failed - %s\n", ldb_dn_get_linearized(msg->dn), ldb_errstring(*ldb));
exit(LDB_ERR_OPERATIONS_ERROR);
}
@@ -356,7 +356,7 @@ static void start_test_index(struct ldb_context **ldb)
(*ldb) = ldb_init(options, NULL);
ret = ldb_connect(*ldb, options->url, flags, NULL);
- if (ret != 0) {
+ if (ret != LDB_SUCCESS) {
printf("failed to connect to %s\n", options->url);
exit(LDB_ERR_OPERATIONS_ERROR);
}
diff --git a/source4/lib/ldb/wscript b/source4/lib/ldb/wscript
index b59e782e45..7de95494c7 100755
--- a/source4/lib/ldb/wscript
+++ b/source4/lib/ldb/wscript
@@ -16,29 +16,33 @@ sys.path.insert(0, srcdir + '/buildtools/wafsamba')
import wafsamba, samba_dist, Options
samba_dist.DIST_DIRS('''source4/lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
- lib/tdb:lib/tdb lib/tevent:lib/tevent lib/popt:lib/popt
+ lib/tdb:lib/tdb lib/tdb2:lib/tdb2 lib/tdb_compat:lib/tdb_compat lib/ccan:lib/ccan lib/tevent:lib/tevent lib/popt:lib/popt
buildtools:buildtools''')
def set_options(opt):
opt.BUILTIN_DEFAULT('replace')
opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
- opt.RECURSE('lib/tdb')
+ opt.RECURSE('lib/tdb_compat')
opt.RECURSE('lib/tevent')
opt.RECURSE('lib/replace')
opt.tool_options('python') # options for disabling pyc or pyo compilation
def configure(conf):
- conf.RECURSE('lib/tdb')
+ conf.RECURSE('lib/tdb_compat')
conf.RECURSE('lib/tevent')
conf.RECURSE('lib/popt')
conf.RECURSE('lib/replace')
+ conf.RECURSE('lib/tdb_compat')
conf.find_program('python', var='PYTHON')
conf.find_program('xsltproc', var='XSLTPROC')
conf.check_tool('python')
conf.check_python_version((2,4,2))
conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True)
+ # This make #include <ccan/...> work.
+ conf.ADD_EXTRA_INCLUDES('''#lib''')
+
# where does the default LIBDIR end up? in conf.env somewhere?
#
conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
@@ -72,10 +76,11 @@ def configure(conf):
conf.SAMBA_CONFIG_H()
def build(bld):
- bld.RECURSE('lib/tdb')
+ bld.RECURSE('lib/tdb_compat')
bld.RECURSE('lib/tevent')
bld.RECURSE('lib/popt')
bld.RECURSE('lib/replace')
+ bld.RECURSE('lib/tdb_compat')
if bld.env.standalone_ldb:
private_library = False
@@ -233,14 +238,14 @@ def build(bld):
init_function='ldb_tdb_init',
module_init_name='ldb_init_module',
internal_module=False,
- deps='tdb ldb',
+ deps='tdb_compat ldb',
subsystem='ldb')
# have a separate subsystem for common/ldb.c, so it can rebuild
# for install with a different -DLDB_MODULESDIR=
bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
'common/ldb.c',
- deps='tevent',
+ deps='tevent tdb_compat',
includes='include',
cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
diff --git a/source4/lib/messaging/irpc.h b/source4/lib/messaging/irpc.h
index bdb1b8fedb..15f8259e51 100644
--- a/source4/lib/messaging/irpc.h
+++ b/source4/lib/messaging/irpc.h
@@ -35,7 +35,7 @@ struct irpc_message {
struct ndr_pull *ndr;
bool defer_reply;
bool no_reply;
- struct messaging_context *msg_ctx;
+ struct imessaging_context *msg_ctx;
struct irpc_list *irpc;
void *data;
struct tevent_context *ev;
@@ -58,24 +58,24 @@ typedef NTSTATUS (*irpc_function_t)(struct irpc_message *, void *r);
struct ndr_interface_table;
-NTSTATUS irpc_register(struct messaging_context *msg_ctx,
+NTSTATUS irpc_register(struct imessaging_context *msg_ctx,
const struct ndr_interface_table *table,
int call, irpc_function_t fn, void *private_data);
struct dcerpc_binding_handle *irpc_binding_handle(TALLOC_CTX *mem_ctx,
- struct messaging_context *msg_ctx,
+ struct imessaging_context *msg_ctx,
struct server_id server_id,
const struct ndr_interface_table *table);
struct dcerpc_binding_handle *irpc_binding_handle_by_name(TALLOC_CTX *mem_ctx,
- struct messaging_context *msg_ctx,
+ struct imessaging_context *msg_ctx,
const char *dest_task,
const struct ndr_interface_table *table);
void irpc_binding_handle_add_security_token(struct dcerpc_binding_handle *h,
struct security_token *token);
-NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name);
-struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx, TALLOC_CTX *mem_ctx, const char *name);
-void irpc_remove_name(struct messaging_context *msg_ctx, const char *name);
+NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name);
+struct server_id *irpc_servers_byname(struct imessaging_context *msg_ctx, TALLOC_CTX *mem_ctx, const char *name);
+void irpc_remove_name(struct imessaging_context *msg_ctx, const char *name);
NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status);
#endif
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index f9d63203f2..484f22b2ee 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -27,22 +27,22 @@
#include "lib/socket/socket.h"
#include "librpc/gen_ndr/ndr_irpc.h"
#include "lib/messaging/irpc.h"
-#include "tdb_wrap.h"
+#include "lib/util/tdb_wrap.h"
#include "../lib/util/unix_privs.h"
#include "librpc/rpc/dcerpc.h"
-#include <tdb.h>
+#include "../lib/tdb_compat/tdb_compat.h"
#include "../lib/util/util_tdb.h"
#include "cluster/cluster.h"
#include "../lib/util/tevent_ntstatus.h"
/* change the message version with any incompatible changes in the protocol */
-#define MESSAGING_VERSION 1
+#define IMESSAGING_VERSION 1
/*
a pending irpc call
*/
struct irpc_request {
- struct messaging_context *msg_ctx;
+ struct imessaging_context *msg_ctx;
int callid;
struct {
void (*handler)(struct irpc_request *irpc, struct irpc_message *m);
@@ -50,7 +50,7 @@ struct irpc_request {
} incoming;
};
-struct messaging_context {
+struct imessaging_context {
struct server_id server_id;
struct socket_context *sock;
const char *base_path;
@@ -58,8 +58,8 @@ struct messaging_context {
struct dispatch_fn **dispatch;
uint32_t num_types;
struct idr_context *dispatch_tree;
- struct messaging_rec *pending;
- struct messaging_rec *retry_queue;
+ struct imessaging_rec *pending;
+ struct imessaging_rec *retry_queue;
struct irpc_list *irpc;
struct idr_context *idr;
const char **names;
@@ -81,12 +81,12 @@ struct dispatch_fn {
};
/* an individual message */
-struct messaging_rec {
- struct messaging_rec *next, *prev;
- struct messaging_context *msg;
+struct imessaging_rec {
+ struct imessaging_rec *next, *prev;
+ struct imessaging_context *msg;
const char *path;
- struct messaging_header {
+ struct imessaging_header {
uint32_t version;
uint32_t msg_type;
struct server_id from;
@@ -99,20 +99,22 @@ struct messaging_rec {
};
-static void irpc_handler(struct messaging_context *, void *,
+static void irpc_handler(struct imessaging_context *, void *,
uint32_t, struct server_id, DATA_BLOB *);
/*
A useful function for testing the message system.
*/
-static void ping_message(struct messaging_context *msg, void *private_data,
+static void ping_message(struct imessaging_context *msg, void *private_data,
uint32_t msg_type, struct server_id src, DATA_BLOB *data)
{
- DEBUG(1,("INFO: Received PING message from server %u.%u [%.*s]\n",
- (unsigned int)src.node, (unsigned int)src.id, (int)data->length,
+ char *task_id = server_id_str(NULL, &src);
+ DEBUG(1,("INFO: Received PING message from server %s [%.*s]\n",
+ task_id, (int)data->length,
data->data?(const char *)data->data:""));
- messaging_send(msg, src, MSG_PONG, data);
+ talloc_free(task_id);
+ imessaging_send(msg, src, MSG_PONG, data);
}
/*
@@ -121,7 +123,7 @@ static void ping_message(struct messaging_context *msg, void *private_data,
static NTSTATUS irpc_uptime(struct irpc_message *msg,
struct irpc_uptime *r)
{
- struct messaging_context *ctx = talloc_get_type(msg->private_data, struct messaging_context);
+ struct imessaging_context *ctx = talloc_get_type(msg->private_data, struct imessaging_context);
*r->out.start_time = timeval_to_nttime(&ctx->start_time);
return NT_STATUS_OK;
}
@@ -129,10 +131,10 @@ static NTSTATUS irpc_uptime(struct irpc_message *msg,
/*
return the path to a messaging socket
*/
-static char *messaging_path(struct messaging_context *msg, struct server_id server_id)
+static char *imessaging_path(struct imessaging_context *msg, struct server_id server_id)
{
TALLOC_CTX *tmp_ctx = talloc_new(msg);
- const char *id = cluster_id_string(tmp_ctx, server_id);
+ const char *id = server_id_str(tmp_ctx, &server_id);
char *s;
if (id == NULL) {
return NULL;
@@ -149,7 +151,7 @@ static char *messaging_path(struct messaging_context *msg, struct server_id serv
per message. That allows a single messasging context to register
(for example) a debug handler for more than one piece of code
*/
-static void messaging_dispatch(struct messaging_context *msg, struct messaging_rec *rec)
+static void imessaging_dispatch(struct imessaging_context *msg, struct imessaging_rec *rec)
{
struct dispatch_fn *d, *next;
@@ -176,18 +178,18 @@ static void messaging_dispatch(struct messaging_context *msg, struct messaging_r
/*
handler for messages that arrive from other nodes in the cluster
*/
-static void cluster_message_handler(struct messaging_context *msg, DATA_BLOB packet)
+static void cluster_message_handler(struct imessaging_context *msg, DATA_BLOB packet)
{
- struct messaging_rec *rec;
+ struct imessaging_rec *rec;
- rec = talloc(msg, struct messaging_rec);
+ rec = talloc(msg, struct imessaging_rec);
if (rec == NULL) {
- smb_panic("Unable to allocate messaging_rec");
+ smb_panic("Unable to allocate imessaging_rec");
}
rec->msg = msg;
rec->path = msg->path;
- rec->header = (struct messaging_header *)packet.data;
+ rec->header = (struct imessaging_header *)packet.data;
rec->packet = packet;
rec->retries = 0;
@@ -198,7 +200,7 @@ static void cluster_message_handler(struct messaging_context *msg, DATA_BLOB pac
return;
}
- messaging_dispatch(msg, rec);
+ imessaging_dispatch(msg, rec);
talloc_free(rec);
}
@@ -207,9 +209,9 @@ static void cluster_message_handler(struct messaging_context *msg, DATA_BLOB pac
/*
try to send the message
*/
-static NTSTATUS try_send(struct messaging_rec *rec)
+static NTSTATUS try_send(struct imessaging_rec *rec)
{
- struct messaging_context *msg = rec->msg;
+ struct imessaging_context *msg = rec->msg;
size_t nsent;
void *priv;
NTSTATUS status;
@@ -238,15 +240,15 @@ static NTSTATUS try_send(struct messaging_rec *rec)
static void msg_retry_timer(struct tevent_context *ev, struct tevent_timer *te,
struct timeval t, void *private_data)
{
- struct messaging_context *msg = talloc_get_type(private_data,
- struct messaging_context);
+ struct imessaging_context *msg = talloc_get_type(private_data,
+ struct imessaging_context);
msg->retry_te = NULL;
/* put the messages back on the main queue */
while (msg->retry_queue) {
- struct messaging_rec *rec = msg->retry_queue;
+ struct imessaging_rec *rec = msg->retry_queue;
DLIST_REMOVE(msg->retry_queue, rec);
- DLIST_ADD_END(msg->pending, rec, struct messaging_rec *);
+ DLIST_ADD_END(msg->pending, rec, struct imessaging_rec *);
}
EVENT_FD_WRITEABLE(msg->event.fde);
@@ -255,10 +257,10 @@ static void msg_retry_timer(struct tevent_context *ev, struct tevent_timer *te,
/*
handle a socket write event
*/
-static void messaging_send_handler(struct messaging_context *msg)
+static void imessaging_send_handler(struct imessaging_context *msg)
{
while (msg->pending) {
- struct messaging_rec *rec = msg->pending;
+ struct imessaging_rec *rec = msg->pending;
NTSTATUS status;
status = try_send(rec);
if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
@@ -268,7 +270,7 @@ static void messaging_send_handler(struct messaging_context *msg)
backoff this record */
DLIST_REMOVE(msg->pending, rec);
DLIST_ADD_END(msg->retry_queue, rec,
- struct messaging_rec *);
+ struct imessaging_rec *);
if (msg->retry_te == NULL) {
msg->retry_te =
event_add_timed(msg->event.ev, msg,
@@ -282,8 +284,8 @@ static void messaging_send_handler(struct messaging_context *msg)
if (!NT_STATUS_IS_OK(status)) {
TALLOC_CTX *tmp_ctx = talloc_new(msg);
DEBUG(1,("messaging: Lost message from %s to %s of type %u - %s\n",
- cluster_id_string(tmp_ctx, rec->header->from),
- cluster_id_string(tmp_ctx, rec->header->to),
+ server_id_str(tmp_ctx, &rec->header->from),
+ server_id_str(tmp_ctx, &rec->header->to),
rec->header->msg_type,
nt_errstr(status)));
talloc_free(tmp_ctx);
@@ -299,9 +301,9 @@ static void messaging_send_handler(struct messaging_context *msg)
/*
handle a new incoming packet
*/
-static void messaging_recv_handler(struct messaging_context *msg)
+static void imessaging_recv_handler(struct imessaging_context *msg)
{
- struct messaging_rec *rec;
+ struct imessaging_rec *rec;
NTSTATUS status;
DATA_BLOB packet;
size_t msize;
@@ -332,15 +334,15 @@ static void messaging_recv_handler(struct messaging_context *msg)
return;
}
- rec = talloc(msg, struct messaging_rec);
+ rec = talloc(msg, struct imessaging_rec);
if (rec == NULL) {
- smb_panic("Unable to allocate messaging_rec");
+ smb_panic("Unable to allocate imessaging_rec");
}
talloc_steal(rec, packet.data);
rec->msg = msg;
rec->path = msg->path;
- rec->header = (struct messaging_header *)packet.data;
+ rec->header = (struct imessaging_header *)packet.data;
rec->packet = packet;
rec->retries = 0;
@@ -351,7 +353,7 @@ static void messaging_recv_handler(struct messaging_context *msg)
return;
}
- messaging_dispatch(msg, rec);
+ imessaging_dispatch(msg, rec);
talloc_free(rec);
}
@@ -359,16 +361,16 @@ static void messaging_recv_handler(struct messaging_context *msg)
/*
handle a socket event
*/
-static void messaging_handler(struct tevent_context *ev, struct tevent_fd *fde,
+static void imessaging_handler(struct tevent_context *ev, struct tevent_fd *fde,
uint16_t flags, void *private_data)
{
- struct messaging_context *msg = talloc_get_type(private_data,
- struct messaging_context);
+ struct imessaging_context *msg = talloc_get_type(private_data,
+ struct imessaging_context);
if (flags & EVENT_FD_WRITE) {
- messaging_send_handler(msg);
+ imessaging_send_handler(msg);
}
if (flags & EVENT_FD_READ) {
- messaging_recv_handler(msg);
+ imessaging_recv_handler(msg);
}
}
@@ -376,7 +378,7 @@ static void messaging_handler(struct tevent_context *ev, struct tevent_fd *fde,
/*
Register a dispatch function for a particular message type.
*/
-NTSTATUS messaging_register(struct messaging_context *msg, void *private_data,
+NTSTATUS imessaging_register(struct imessaging_context *msg, void *private_data,
uint32_t msg_type, msg_callback_t fn)
{
struct dispatch_fn *d;
@@ -409,7 +411,7 @@ NTSTATUS messaging_register(struct messaging_context *msg, void *private_data,
register a temporary message handler. The msg_type is allocated
above MSG_TMP_BASE
*/
-NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private_data,
+NTSTATUS imessaging_register_tmp(struct imessaging_context *msg, void *private_data,
msg_callback_t fn, uint32_t *msg_type)
{
struct dispatch_fn *d;
@@ -435,7 +437,7 @@ NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private_dat
/*
De-register the function for a particular message type.
*/
-void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private_data)
+void imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, void *private_data)
{
struct dispatch_fn *d, *next;
@@ -460,14 +462,14 @@ void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void
/*
Send a message to a particular server
*/
-NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server,
+NTSTATUS imessaging_send(struct imessaging_context *msg, struct server_id server,
uint32_t msg_type, const DATA_BLOB *data)
{
- struct messaging_rec *rec;
+ struct imessaging_rec *rec;
NTSTATUS status;
size_t dlength = data?data->length:0;
- rec = talloc(msg, struct messaging_rec);
+ rec = talloc(msg, struct imessaging_rec);
if (rec == NULL) {
return NT_STATUS_NO_MEMORY;
}
@@ -480,10 +482,10 @@ NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server,
rec->retries = 0;
rec->msg = msg;
- rec->header = (struct messaging_header *)rec->packet.data;
+ rec->header = (struct imessaging_header *)rec->packet.data;
/* zero padding */
ZERO_STRUCTP(rec->header);
- rec->header->version = MESSAGING_VERSION;
+ rec->header->version = IMESSAGING_VERSION;
rec->header->msg_type = msg_type;
rec->header->from = msg->server_id;
rec->header->to = server;
@@ -501,7 +503,7 @@ NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server,
return status;
}
- rec->path = messaging_path(msg, server);
+ rec->path = imessaging_path(msg, server);
talloc_steal(rec, rec->path);
if (msg->pending != NULL) {
@@ -514,7 +516,7 @@ NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server,
if (msg->pending == NULL) {
EVENT_FD_WRITEABLE(msg->event.fde);
}
- DLIST_ADD_END(msg->pending, rec, struct messaging_rec *);
+ DLIST_ADD_END(msg->pending, rec, struct imessaging_rec *);
return NT_STATUS_OK;
}
@@ -526,7 +528,7 @@ NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server,
/*
Send a message to a particular server, with the message containing a single pointer
*/
-NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id server,
+NTSTATUS imessaging_send_ptr(struct imessaging_context *msg, struct server_id server,
uint32_t msg_type, void *ptr)
{
DATA_BLOB blob;
@@ -534,14 +536,14 @@ NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id serv
blob.data = (uint8_t *)&ptr;
blob.length = sizeof(void *);
- return messaging_send(msg, server, msg_type, &blob);
+ return imessaging_send(msg, server, msg_type, &blob);
}
/*
destroy the messaging context
*/
-static int messaging_destructor(struct messaging_context *msg)
+static int imessaging_destructor(struct imessaging_context *msg)
{
unlink(msg->path);
while (msg->names && msg->names[0]) {
@@ -553,12 +555,12 @@ static int messaging_destructor(struct messaging_context *msg)
/*
create the listening socket and setup the dispatcher
*/
-struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
+struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
const char *dir,
struct server_id server_id,
struct tevent_context *ev)
{
- struct messaging_context *msg;
+ struct imessaging_context *msg;
NTSTATUS status;
struct socket_address *path;
@@ -566,7 +568,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
return NULL;
}
- msg = talloc_zero(mem_ctx, struct messaging_context);
+ msg = talloc_zero(mem_ctx, struct imessaging_context);
if (msg == NULL) {
return NULL;
}
@@ -582,7 +584,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
mkdir(dir, 0700);
msg->base_path = talloc_reference(msg, dir);
- msg->path = messaging_path(msg, server_id);
+ msg->path = imessaging_path(msg, server_id);
msg->server_id = server_id;
msg->idr = idr_init(msg);
msg->dispatch_tree = idr_init(msg);
@@ -617,13 +619,13 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
msg->event.ev = ev;
msg->event.fde = event_add_fd(ev, msg, socket_get_fd(msg->sock),
- EVENT_FD_READ, messaging_handler, msg);
+ EVENT_FD_READ, imessaging_handler, msg);
tevent_fd_set_auto_close(msg->event.fde);
- talloc_set_destructor(msg, messaging_destructor);
+ talloc_set_destructor(msg, imessaging_destructor);
- messaging_register(msg, NULL, MSG_PING, ping_message);
- messaging_register(msg, NULL, MSG_IRPC, irpc_handler);
+ imessaging_register(msg, NULL, MSG_PING, ping_message);
+ imessaging_register(msg, NULL, MSG_IRPC, irpc_handler);
IRPC_REGISTER(msg, irpc, IRPC_UPTIME, irpc_uptime, msg);
return msg;
@@ -632,14 +634,14 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
/*
A hack, for the short term until we get 'client only' messaging in place
*/
-struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx,
+struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx,
const char *dir,
struct tevent_context *ev)
{
struct server_id id;
ZERO_STRUCT(id);
- id.id = random() % 0x10000000;
- return messaging_init(mem_ctx, dir, id, ev);
+ id.pid = random() % 0x10000000;
+ return imessaging_init(mem_ctx, dir, id, ev);
}
/*
a list of registered irpc server functions
@@ -657,7 +659,7 @@ struct irpc_list {
/*
register a irpc server function
*/
-NTSTATUS irpc_register(struct messaging_context *msg_ctx,
+NTSTATUS irpc_register(struct imessaging_context *msg_ctx,
const struct ndr_interface_table *table,
int callnum, irpc_function_t fn, void *private_data)
{
@@ -688,7 +690,7 @@ NTSTATUS irpc_register(struct messaging_context *msg_ctx,
/*
handle an incoming irpc reply message
*/
-static void irpc_handler_reply(struct messaging_context *msg_ctx, struct irpc_message *m)
+static void irpc_handler_reply(struct imessaging_context *msg_ctx, struct irpc_message *m)
{
struct irpc_request *irpc;
@@ -734,7 +736,7 @@ NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status)
/* send the reply message */
packet = ndr_push_blob(push);
- status = messaging_send(m->msg_ctx, m->from, MSG_IRPC, &packet);
+ status = imessaging_send(m->msg_ctx, m->from, MSG_IRPC, &packet);
if (!NT_STATUS_IS_OK(status)) goto failed;
failed:
@@ -745,7 +747,7 @@ failed:
/*
handle an incoming irpc request message
*/
-static void irpc_handler_request(struct messaging_context *msg_ctx,
+static void irpc_handler_request(struct imessaging_context *msg_ctx,
struct irpc_message *m)
{
struct irpc_list *i;
@@ -809,7 +811,7 @@ failed:
/*
handle an incoming irpc message
*/
-static void irpc_handler(struct messaging_context *msg_ctx, void *private_data,
+static void irpc_handler(struct imessaging_context *msg_ctx, void *private_data,
uint32_t msg_type, struct server_id src, DATA_BLOB *packet)
{
struct irpc_message *m;
@@ -856,7 +858,7 @@ static int irpc_destructor(struct irpc_request *irpc)
/*
open the naming database
*/
-static struct tdb_wrap *irpc_namedb_open(struct messaging_context *msg_ctx)
+static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx)
{
struct tdb_wrap *t;
char *path = talloc_asprintf(msg_ctx, "%s/names.tdb", msg_ctx->base_path);
@@ -872,7 +874,7 @@ static struct tdb_wrap *irpc_namedb_open(struct messaging_context *msg_ctx)
/*
add a string name that this irpc server can be called on
*/
-NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name)
+NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name)
{
struct tdb_wrap *t;
TDB_DATA rec;
@@ -912,7 +914,7 @@ NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name)
/*
return a list of server ids for a server name
*/
-struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx,
+struct server_id *irpc_servers_byname(struct imessaging_context *msg_ctx,
TALLOC_CTX *mem_ctx,
const char *name)
{
@@ -957,7 +959,7 @@ struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx,
/*
remove a name from a messaging context
*/
-void irpc_remove_name(struct messaging_context *msg_ctx, const char *name)
+void irpc_remove_name(struct imessaging_context *msg_ctx, const char *name)
{
struct tdb_wrap *t;
TDB_DATA rec;
@@ -1005,13 +1007,13 @@ void irpc_remove_name(struct messaging_context *msg_ctx, const char *name)
talloc_free(t);
}
-struct server_id messaging_get_server_id(struct messaging_context *msg_ctx)
+struct server_id imessaging_get_server_id(struct imessaging_context *msg_ctx)
{
return msg_ctx->server_id;
}
struct irpc_bh_state {
- struct messaging_context *msg_ctx;
+ struct imessaging_context *msg_ctx;
struct server_id server_id;
const struct ndr_interface_table *table;
uint32_t timeout;
@@ -1137,7 +1139,7 @@ static struct tevent_req *irpc_bh_raw_call_send(TALLOC_CTX *mem_ctx,
/* and send it */
state->in_packet = ndr_push_blob(ndr);
- status = messaging_send(hs->msg_ctx, hs->server_id,
+ status = imessaging_send(hs->msg_ctx, hs->server_id,
MSG_IRPC, &state->in_packet);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(req, status);
@@ -1176,7 +1178,7 @@ static void irpc_bh_raw_call_incoming_handler(struct irpc_request *irpc,
m->ndr->data + m->ndr->offset,
m->ndr->data_size - m->ndr->offset);
if ((m->ndr->data_size - m->ndr->offset) > 0 && !state->out_data.data) {
- tevent_req_nomem(NULL, req);
+ tevent_req_oom(req);
return;
}
@@ -1270,7 +1272,7 @@ static const struct dcerpc_binding_handle_ops irpc_bh_ops = {
/* initialise a irpc binding handle */
struct dcerpc_binding_handle *irpc_binding_handle(TALLOC_CTX *mem_ctx,
- struct messaging_context *msg_ctx,
+ struct imessaging_context *msg_ctx,
struct server_id server_id,
const struct ndr_interface_table *table)
{
@@ -1298,7 +1300,7 @@ struct dcerpc_binding_handle *irpc_binding_handle(TALLOC_CTX *mem_ctx,
}
struct dcerpc_binding_handle *irpc_binding_handle_by_name(TALLOC_CTX *mem_ctx,
- struct messaging_context *msg_ctx,
+ struct imessaging_context *msg_ctx,
const char *dest_task,
const struct ndr_interface_table *table)
{
@@ -1312,7 +1314,7 @@ struct dcerpc_binding_handle *irpc_binding_handle_by_name(TALLOC_CTX *mem_ctx,
errno = EADDRNOTAVAIL;
return NULL;
}
- if (sids[0].id == 0) {
+ if (sids[0].pid == 0) {
talloc_free(sids);
errno = EADDRNOTAVAIL;
return NULL;
diff --git a/source4/lib/messaging/messaging.h b/source4/lib/messaging/messaging.h
index 4bc6d8c509..eb8a8abc79 100644
--- a/source4/lib/messaging/messaging.h
+++ b/source4/lib/messaging/messaging.h
@@ -21,9 +21,9 @@
#ifndef _MESSAGES_H_
#define _MESSAGES_H_
-#include "librpc/gen_ndr/server_id4.h"
+#include "librpc/gen_ndr/server_id.h"
-struct messaging_context;
+struct imessaging_context;
/* general messages */
#define MSG_DEBUG 1
@@ -42,27 +42,27 @@ struct messaging_context;
/* taskid for messaging of parent process */
#define SAMBA_PARENT_TASKID 0
-typedef void (*msg_callback_t)(struct messaging_context *msg, void *private_data,
+typedef void (*msg_callback_t)(struct imessaging_context *msg, void *private_data,
uint32_t msg_type,
struct server_id server_id, DATA_BLOB *data);
-NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server,
+NTSTATUS imessaging_send(struct imessaging_context *msg, struct server_id server,
uint32_t msg_type, const DATA_BLOB *data);
-NTSTATUS messaging_register(struct messaging_context *msg, void *private_data,
+NTSTATUS imessaging_register(struct imessaging_context *msg, void *private_data,
uint32_t msg_type,
msg_callback_t fn);
-NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private_data,
+NTSTATUS imessaging_register_tmp(struct imessaging_context *msg, void *private_data,
msg_callback_t fn, uint32_t *msg_type);
-struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
+struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
const char *dir,
struct server_id server_id,
struct tevent_context *ev);
-struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx,
+struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx,
const char *dir,
struct tevent_context *ev);
-NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id server,
+NTSTATUS imessaging_send_ptr(struct imessaging_context *msg, struct server_id server,
uint32_t msg_type, void *ptr);
-void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private_data);
-struct server_id messaging_get_server_id(struct messaging_context *msg_ctx);
+void imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, void *private_data);
+struct server_id imessaging_get_server_id(struct imessaging_context *msg_ctx);
#endif
diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c
index 358d205b53..cafd45beae 100644
--- a/source4/lib/messaging/pymessaging.c
+++ b/source4/lib/messaging/pymessaging.c
@@ -31,11 +31,11 @@
#include "param/param.h"
#include "param/pyparam.h"
#include "librpc/rpc/dcerpc.h"
-#include "librpc/gen_ndr/server_id4.h"
+#include "librpc/gen_ndr/server_id.h"
void initmessaging(void);
-extern PyTypeObject messaging_Type;
+extern PyTypeObject imessaging_Type;
static bool server_id_from_py(PyObject *object, struct server_id *server_id)
{
@@ -45,12 +45,12 @@ static bool server_id_from_py(PyObject *object, struct server_id *server_id)
}
if (PyTuple_Size(object) == 3) {
- return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node);
+ return PyArg_ParseTuple(object, "iii", &server_id->pid, &server_id->task_id, &server_id->vnn);
} else {
- int id, id2;
- if (!PyArg_ParseTuple(object, "ii", &id, &id2))
+ int pid, task_id;
+ if (!PyArg_ParseTuple(object, "ii", &pid, &task_id))
return false;
- *server_id = cluster_id(id, id2);
+ *server_id = cluster_id(pid, task_id);
return true;
}
}
@@ -58,23 +58,23 @@ static bool server_id_from_py(PyObject *object, struct server_id *server_id)
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
- struct messaging_context *msg_ctx;
-} messaging_Object;
+ struct imessaging_context *msg_ctx;
+} imessaging_Object;
-static PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
+static PyObject *py_imessaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
{
struct tevent_context *ev;
const char *kwnames[] = { "own_id", "messaging_path", NULL };
PyObject *own_id = Py_None;
- const char *messaging_path = NULL;
- messaging_Object *ret;
+ const char *imessaging_path = NULL;
+ imessaging_Object *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oz:connect",
- discard_const_p(char *, kwnames), &own_id, &messaging_path)) {
+ discard_const_p(char *, kwnames), &own_id, &imessaging_path)) {
return NULL;
}
- ret = PyObject_New(messaging_Object, &messaging_Type);
+ ret = PyObject_New(imessaging_Object, &imessaging_Type);
if (ret == NULL)
return NULL;
@@ -82,11 +82,11 @@ static PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObje
ev = s4_event_context_init(ret->mem_ctx);
- if (messaging_path == NULL) {
- messaging_path = lpcfg_messaging_path(ret->mem_ctx,
+ if (imessaging_path == NULL) {
+ imessaging_path = lpcfg_imessaging_path(ret->mem_ctx,
py_default_loadparm_context(ret->mem_ctx));
} else {
- messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);
+ imessaging_path = talloc_strdup(ret->mem_ctx, imessaging_path);
}
if (own_id != Py_None) {
@@ -95,18 +95,18 @@ static PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObje
if (!server_id_from_py(own_id, &server_id))
return NULL;
- ret->msg_ctx = messaging_init(ret->mem_ctx,
- messaging_path,
+ ret->msg_ctx = imessaging_init(ret->mem_ctx,
+ imessaging_path,
server_id,
ev);
} else {
- ret->msg_ctx = messaging_client_init(ret->mem_ctx,
- messaging_path,
+ ret->msg_ctx = imessaging_client_init(ret->mem_ctx,
+ imessaging_path,
ev);
}
if (ret->msg_ctx == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "messaging_connect unable to create a messaging context");
+ PyErr_SetString(PyExc_RuntimeError, "imessaging_connect unable to create a messaging context");
talloc_free(ret->mem_ctx);
return NULL;
}
@@ -114,16 +114,16 @@ static PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObje
return (PyObject *)ret;
}
-static void py_messaging_dealloc(PyObject *self)
+static void py_imessaging_dealloc(PyObject *self)
{
- messaging_Object *iface = (messaging_Object *)self;
+ imessaging_Object *iface = (imessaging_Object *)self;
talloc_free(iface->msg_ctx);
self->ob_type->tp_free(self);
}
-static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwargs)
+static PyObject *py_imessaging_send(PyObject *self, PyObject *args, PyObject *kwargs)
{
- messaging_Object *iface = (messaging_Object *)self;
+ imessaging_Object *iface = (imessaging_Object *)self;
uint32_t msg_type;
DATA_BLOB data;
PyObject *target;
@@ -143,7 +143,7 @@ static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwa
if (!server_id_from_py(target, &server))
return NULL;
- status = messaging_send(iface->msg_ctx, server, msg_type, &data);
+ status = imessaging_send(iface->msg_ctx, server, msg_type, &data);
if (NT_STATUS_IS_ERR(status)) {
PyErr_SetNTSTATUS(status);
return NULL;
@@ -152,20 +152,20 @@ static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwa
Py_RETURN_NONE;
}
-static void py_msg_callback_wrapper(struct messaging_context *msg, void *private_data,
+static void py_msg_callback_wrapper(struct imessaging_context *msg, void *private_data,
uint32_t msg_type,
struct server_id server_id, DATA_BLOB *data)
{
PyObject *callback = (PyObject *)private_data;
- PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type,
- server_id.id, server_id.id2, server_id.node,
+ PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type,
+ server_id.pid, server_id.task_id, server_id.vnn,
data->data, data->length);
}
-static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject *kwargs)
+static PyObject *py_imessaging_register(PyObject *self, PyObject *args, PyObject *kwargs)
{
- messaging_Object *iface = (messaging_Object *)self;
+ imessaging_Object *iface = (imessaging_Object *)self;
int msg_type = -1;
PyObject *callback;
NTSTATUS status;
@@ -180,11 +180,11 @@ static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject
if (msg_type == -1) {
uint32_t msg_type32 = msg_type;
- status = messaging_register_tmp(iface->msg_ctx, callback,
+ status = imessaging_register_tmp(iface->msg_ctx, callback,
py_msg_callback_wrapper, &msg_type32);
msg_type = msg_type32;
} else {
- status = messaging_register(iface->msg_ctx, callback,
+ status = imessaging_register(iface->msg_ctx, callback,
msg_type, py_msg_callback_wrapper);
}
if (NT_STATUS_IS_ERR(status)) {
@@ -195,9 +195,9 @@ static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject
return PyLong_FromLong(msg_type);
}
-static PyObject *py_messaging_deregister(PyObject *self, PyObject *args, PyObject *kwargs)
+static PyObject *py_imessaging_deregister(PyObject *self, PyObject *args, PyObject *kwargs)
{
- messaging_Object *iface = (messaging_Object *)self;
+ imessaging_Object *iface = (imessaging_Object *)self;
int msg_type = -1;
PyObject *callback;
const char *kwnames[] = { "callback", "msg_type", NULL };
@@ -207,49 +207,49 @@ static PyObject *py_messaging_deregister(PyObject *self, PyObject *args, PyObjec
return NULL;
}
- messaging_deregister(iface->msg_ctx, msg_type, callback);
+ imessaging_deregister(iface->msg_ctx, msg_type, callback);
Py_DECREF(callback);
Py_RETURN_NONE;
}
-static PyMethodDef py_messaging_methods[] = {
- { "send", (PyCFunction)py_messaging_send, METH_VARARGS|METH_KEYWORDS,
+static PyMethodDef py_imessaging_methods[] = {
+ { "send", (PyCFunction)py_imessaging_send, METH_VARARGS|METH_KEYWORDS,
"S.send(target, msg_type, data) -> None\nSend a message" },
- { "register", (PyCFunction)py_messaging_register, METH_VARARGS|METH_KEYWORDS,
+ { "register", (PyCFunction)py_imessaging_register, METH_VARARGS|METH_KEYWORDS,
"S.register(callback, msg_type=None) -> msg_type\nRegister a message handler" },
- { "deregister", (PyCFunction)py_messaging_deregister, METH_VARARGS|METH_KEYWORDS,
+ { "deregister", (PyCFunction)py_imessaging_deregister, METH_VARARGS|METH_KEYWORDS,
"S.deregister(callback, msg_type) -> None\nDeregister a message handler" },
{ NULL, NULL, 0, NULL }
};
-static PyObject *py_messaging_server_id(PyObject *obj, void *closure)
+static PyObject *py_imessaging_server_id(PyObject *obj, void *closure)
{
- messaging_Object *iface = (messaging_Object *)obj;
- struct server_id server_id = messaging_get_server_id(iface->msg_ctx);
+ imessaging_Object *iface = (imessaging_Object *)obj;
+ struct server_id server_id = imessaging_get_server_id(iface->msg_ctx);
- return Py_BuildValue("(iii)", server_id.id, server_id.id2,
- server_id.node);
+ return Py_BuildValue("(iii)", server_id.pid, server_id.task_id,
+ server_id.vnn);
}
-static PyGetSetDef py_messaging_getset[] = {
- { discard_const_p(char, "server_id"), py_messaging_server_id, NULL,
+static PyGetSetDef py_imessaging_getset[] = {
+ { discard_const_p(char, "server_id"), py_imessaging_server_id, NULL,
discard_const_p(char, "local server id") },
{ NULL },
};
-PyTypeObject messaging_Type = {
+PyTypeObject imessaging_Type = {
PyObject_HEAD_INIT(NULL) 0,
.tp_name = "messaging.Messaging",
- .tp_basicsize = sizeof(messaging_Object),
+ .tp_basicsize = sizeof(imessaging_Object),
.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
- .tp_new = py_messaging_connect,
- .tp_dealloc = py_messaging_dealloc,
- .tp_methods = py_messaging_methods,
- .tp_getset = py_messaging_getset,
- .tp_doc = "Messaging(own_id=None, messaging_path=None)\n" \
+ .tp_new = py_imessaging_connect,
+ .tp_dealloc = py_imessaging_dealloc,
+ .tp_methods = py_imessaging_methods,
+ .tp_getset = py_imessaging_getset,
+ .tp_doc = "Messaging(own_id=None, imessaging_path=None)\n" \
"Create a new object that can be used to communicate with the peers in the specified messaging path.\n" \
"If no path is specified, the default path from smb.conf will be used."
};
@@ -258,13 +258,13 @@ void initmessaging(void)
{
PyObject *mod;
- if (PyType_Ready(&messaging_Type) < 0)
+ if (PyType_Ready(&imessaging_Type) < 0)
return;
mod = Py_InitModule3("messaging", NULL, "Internal RPC");
if (mod == NULL)
return;
- Py_INCREF((PyObject *)&messaging_Type);
- PyModule_AddObject(mod, "Messaging", (PyObject *)&messaging_Type);
+ Py_INCREF((PyObject *)&imessaging_Type);
+ PyModule_AddObject(mod, "Messaging", (PyObject *)&imessaging_Type);
}
diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c
index 4d0b6b4378..cfa2bcb91e 100644
--- a/source4/lib/messaging/tests/irpc.c
+++ b/source4/lib/messaging/tests/irpc.c
@@ -34,7 +34,7 @@ static bool test_debug;
struct irpc_test_data
{
- struct messaging_context *msg_ctx1, *msg_ctx2;
+ struct imessaging_context *msg_ctx1, *msg_ctx2;
struct tevent_context *ev;
};
@@ -246,15 +246,15 @@ static bool irpc_setup(struct torture_context *tctx, void **_data)
data->ev = tctx->ev;
torture_assert(tctx, data->msg_ctx1 =
- messaging_init(tctx,
- lpcfg_messaging_path(tctx, tctx->lp_ctx),
+ imessaging_init(tctx,
+ lpcfg_imessaging_path(tctx, tctx->lp_ctx),
cluster_id(0, MSG_ID1),
data->ev),
"Failed to init first messaging context");
torture_assert(tctx, data->msg_ctx2 =
- messaging_init(tctx,
- lpcfg_messaging_path(tctx, tctx->lp_ctx),
+ imessaging_init(tctx,
+ lpcfg_imessaging_path(tctx, tctx->lp_ctx),
cluster_id(0, MSG_ID2),
data->ev),
"Failed to init second messaging context");
diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c
index 82fdf2f73e..38c34fc52e 100644
--- a/source4/lib/messaging/tests/messaging.c
+++ b/source4/lib/messaging/tests/messaging.c
@@ -29,24 +29,24 @@
static uint32_t msg_pong;
-static void ping_message(struct messaging_context *msg, void *private_data,
+static void ping_message(struct imessaging_context *msg, void *private_data,
uint32_t msg_type, struct server_id src, DATA_BLOB *data)
{
NTSTATUS status;
- status = messaging_send(msg, src, msg_pong, data);
+ status = imessaging_send(msg, src, msg_pong, data);
if (!NT_STATUS_IS_OK(status)) {
printf("pong failed - %s\n", nt_errstr(status));
}
}
-static void pong_message(struct messaging_context *msg, void *private_data,
+static void pong_message(struct imessaging_context *msg, void *private_data,
uint32_t msg_type, struct server_id src, DATA_BLOB *data)
{
int *count = (int *)private_data;
(*count)++;
}
-static void exit_message(struct messaging_context *msg, void *private_data,
+static void exit_message(struct imessaging_context *msg, void *private_data,
uint32_t msg_type, struct server_id src, DATA_BLOB *data)
{
talloc_free(private_data);
@@ -59,8 +59,8 @@ static void exit_message(struct messaging_context *msg, void *private_data,
static bool test_ping_speed(struct torture_context *tctx)
{
struct tevent_context *ev;
- struct messaging_context *msg_client_ctx;
- struct messaging_context *msg_server_ctx;
+ struct imessaging_context *msg_client_ctx;
+ struct imessaging_context *msg_server_ctx;
int ping_count = 0;
int pong_count = 0;
struct timeval tv;
@@ -71,24 +71,24 @@ static bool test_ping_speed(struct torture_context *tctx)
ev = tctx->ev;
- msg_server_ctx = messaging_init(tctx,
- lpcfg_messaging_path(tctx, tctx->lp_ctx), cluster_id(0, 1),
+ msg_server_ctx = imessaging_init(tctx,
+ lpcfg_imessaging_path(tctx, tctx->lp_ctx), cluster_id(0, 1),
ev);
torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context");
- messaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping);
- messaging_register_tmp(msg_server_ctx, tctx, exit_message, &msg_exit);
+ imessaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping);
+ imessaging_register_tmp(msg_server_ctx, tctx, exit_message, &msg_exit);
- msg_client_ctx = messaging_init(tctx,
- lpcfg_messaging_path(tctx, tctx->lp_ctx),
+ msg_client_ctx = imessaging_init(tctx,
+ lpcfg_imessaging_path(tctx, tctx->lp_ctx),
cluster_id(0, 2),
ev);
torture_assert(tctx, msg_client_ctx != NULL,
- "msg_client_ctx messaging_init() failed");
+ "msg_client_ctx imessaging_init() failed");
- messaging_register_tmp(msg_client_ctx, &pong_count, pong_message, &msg_pong);
+ imessaging_register_tmp(msg_client_ctx, &pong_count, pong_message, &msg_pong);
tv = timeval_current();
@@ -100,8 +100,8 @@ static bool test_ping_speed(struct torture_context *tctx)
data.data = discard_const_p(uint8_t, "testing");
data.length = strlen((const char *)data.data);
- status1 = messaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, &data);
- status2 = messaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, NULL);
+ status1 = imessaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, &data);
+ status2 = imessaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, NULL);
torture_assert_ntstatus_ok(tctx, status1, "msg1 failed");
ping_count++;
@@ -121,7 +121,7 @@ static bool test_ping_speed(struct torture_context *tctx)
}
torture_comment(tctx, "sending exit\n");
- messaging_send(msg_client_ctx, cluster_id(0, 1), msg_exit, NULL);
+ imessaging_send(msg_client_ctx, cluster_id(0, 1), msg_exit, NULL);
torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed");
diff --git a/source4/lib/registry/rpc.c b/source4/lib/registry/rpc.c
index f1e14c1b86..42b7374f7a 100644
--- a/source4/lib/registry/rpc.c
+++ b/source4/lib/registry/rpc.c
@@ -485,7 +485,7 @@ _PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx,
struct dcerpc_pipe *p;
struct rpc_registry_context *rctx;
- dcerpc_init(lp_ctx);
+ dcerpc_init();
rctx = talloc(NULL, struct rpc_registry_context);
W_ERROR_HAVE_NO_MEMORY(rctx);
diff --git a/source4/lib/registry/wscript_build b/source4/lib/registry/wscript_build
index 2f0372a933..5adc941718 100644
--- a/source4/lib/registry/wscript_build
+++ b/source4/lib/registry/wscript_build
@@ -13,7 +13,7 @@ bld.SAMBA_SUBSYSTEM('TDR_REGF',
bld.SAMBA_LIBRARY('registry',
source='interface.c util.c samba.c patchfile_dotreg.c patchfile_preg.c patchfile.c regf.c hive.c local.c ldb.c dir.c rpc.c',
pc_files='registry.pc',
- public_deps='samba-util TDR_REGF ldb RPC_NDR_WINREG ldbsamba util_reg',
+ public_deps='dcerpc samba-util TDR_REGF ldb RPC_NDR_WINREG ldbsamba util_reg',
public_headers='registry.h',
vnum='0.0.1'
)
diff --git a/source4/lib/socket/access.c b/source4/lib/socket/access.c
index ab39d63ef5..589797763f 100644
--- a/source4/lib/socket/access.c
+++ b/source4/lib/socket/access.c
@@ -249,9 +249,9 @@ static bool allow_access_internal(TALLOC_CTX *mem_ctx,
}
/* return true if access should be allowed */
-bool allow_access(TALLOC_CTX *mem_ctx,
- const char **deny_list, const char **allow_list,
- const char *cname, const char *caddr)
+bool socket_allow_access(TALLOC_CTX *mem_ctx,
+ const char **deny_list, const char **allow_list,
+ const char *cname, const char *caddr)
{
bool ret;
char *nc_cname = talloc_strdup(mem_ctx, cname);
@@ -346,7 +346,7 @@ bool socket_check_access(struct socket_context *sock,
return false;
}
- ret = allow_access(mem_ctx, deny_list, allow_list, name, addr->addr);
+ ret = socket_allow_access(mem_ctx, deny_list, allow_list, name, addr->addr);
if (ret) {
DEBUG(2,("socket_check_access: Allowed connection to '%s' from %s (%s)\n",
diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c
index 300e5fb1e5..4ce5115e97 100644
--- a/source4/lib/socket/connect_multi.c
+++ b/source4/lib/socket/connect_multi.c
@@ -136,7 +136,7 @@ static void connect_multi_next_socket(struct composite_context *result)
if (composite_nomem(state, result)) return;
state->result = result;
- result->status = socket_create("ipv4", SOCKET_TYPE_STREAM, &state->sock, 0);
+ result->status = socket_create(multi->server_address->family, SOCKET_TYPE_STREAM, &state->sock, 0);
if (!composite_is_ok(result)) return;
state->addr = socket_address_copy(state, multi->server_address);
@@ -162,7 +162,7 @@ static void connect_multi_next_socket(struct composite_context *result)
connect attempt state, so it will go away when this
request completes */
event_add_timed(result->event_ctx, state,
- timeval_current_ofs(0, MULTI_PORT_DELAY),
+ timeval_current_ofs_usec(MULTI_PORT_DELAY),
connect_multi_timer, result);
}
}
diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c
index c4411b623c..d5b610fea7 100644
--- a/source4/lib/socket/interface.c
+++ b/source4/lib/socket/interface.c
@@ -21,15 +21,19 @@
#include "includes.h"
#include "system/network.h"
+#include "param/param.h"
#include "lib/socket/netif.h"
#include "../lib/util/util_net.h"
#include "../lib/util/dlinklist.h"
-/** used for network interfaces */
+/* used for network interfaces */
struct interface {
struct interface *next, *prev;
- struct in_addr ip;
- struct in_addr nmask;
+ char *name;
+ int flags;
+ struct sockaddr_storage ip;
+ struct sockaddr_storage netmask;
+ struct sockaddr_storage bcast;
const char *ip_s;
const char *bcast_s;
const char *nmask_s;
@@ -45,31 +49,51 @@ struct interface {
/****************************************************************************
Try and find an interface that matches an ip. If we cannot, return NULL
**************************************************************************/
-static struct interface *iface_find(struct interface *interfaces,
- struct in_addr ip, bool CheckMask)
+static struct interface *iface_list_find(struct interface *interfaces,
+ const struct sockaddr *ip,
+ bool check_mask)
{
struct interface *i;
- if (is_zero_ip_v4(ip)) return interfaces;
- for (i=interfaces;i;i=i->next)
- if (CheckMask) {
- if (same_net_v4(i->ip,ip,i->nmask)) return i;
- } else if (i->ip.s_addr == ip.s_addr) return i;
+ if (is_address_any(ip)) {
+ return interfaces;
+ }
+
+ for (i=interfaces;i;i=i->next) {
+ if (check_mask) {
+ if (same_net(ip, (struct sockaddr *)&i->ip, (struct sockaddr *)&i->netmask)) {
+ return i;
+ }
+ } else if (sockaddr_equal((struct sockaddr *)&i->ip, ip)) {
+ return i;
+ }
+ }
return NULL;
}
-
/****************************************************************************
add an interface to the linked list of interfaces
****************************************************************************/
-static void add_interface(TALLOC_CTX *mem_ctx, struct in_addr ip, struct in_addr nmask, struct interface **interfaces)
+static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, struct interface **interfaces,
+ bool enable_ipv6)
{
+ char addr[INET6_ADDRSTRLEN];
struct interface *iface;
- struct in_addr bcast;
- if (iface_find(*interfaces, ip, false)) {
- DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip)));
+ if (iface_list_find(*interfaces, (const struct sockaddr *)&ifs->ip, false)) {
+ DEBUG(3,("add_interface: not adding duplicate interface %s\n",
+ print_sockaddr(addr, sizeof(addr), &ifs->ip) ));
+ return;
+ }
+
+ if (!(ifs->flags & (IFF_BROADCAST|IFF_LOOPBACK))) {
+ DEBUG(3,("not adding non-broadcast interface %s\n",
+ ifs->name ));
+ return;
+ }
+
+ if (!enable_ipv6 && ifs->ip.ss_family != AF_INET) {
return;
}
@@ -79,26 +103,40 @@ static void add_interface(TALLOC_CTX *mem_ctx, struct in_addr ip, struct in_addr
ZERO_STRUCTPN(iface);
- iface->ip = ip;
- iface->nmask = nmask;
- bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr);
+ iface->name = talloc_strdup(iface, ifs->name);
+ if (!iface->name) {
+ SAFE_FREE(iface);
+ return;
+ }
+ iface->flags = ifs->flags;
+ iface->ip = ifs->ip;
+ iface->netmask = ifs->netmask;
+ iface->bcast = ifs->bcast;
/* keep string versions too, to avoid people tripping over the implied
static in inet_ntoa() */
- iface->ip_s = talloc_strdup(iface, inet_ntoa(iface->ip));
- iface->nmask_s = talloc_strdup(iface, inet_ntoa(iface->nmask));
-
- if (nmask.s_addr != ~0) {
- iface->bcast_s = talloc_strdup(iface, inet_ntoa(bcast));
- }
-
- DLIST_ADD_END(*interfaces, iface, struct interface *);
-
- DEBUG(3,("added interface ip=%s nmask=%s\n", iface->ip_s, iface->nmask_s));
+ print_sockaddr(addr, sizeof(addr), &iface->ip);
+ DEBUG(4,("added interface %s ip=%s ",
+ iface->name, addr));
+ iface->ip_s = talloc_strdup(iface, addr);
+
+ print_sockaddr(addr, sizeof(addr),
+ &iface->bcast);
+ DEBUG(4,("bcast=%s ", addr));
+ iface->bcast_s = talloc_strdup(iface, addr);
+
+ print_sockaddr(addr, sizeof(addr),
+ &iface->netmask);
+ DEBUG(4,("netmask=%s\n", addr));
+ iface->nmask_s = talloc_strdup(iface, addr);
+
+ /*
+ this needs to be a ADD_END, as some tests (such as the
+ spoolss notify test) depend on the interfaces ordering
+ */
+ DLIST_ADD_END(*interfaces, iface, NULL);
}
-
-
/**
interpret a single element from a interfaces= config line
@@ -114,99 +152,155 @@ static void interpret_interface(TALLOC_CTX *mem_ctx,
const char *token,
struct iface_struct *probed_ifaces,
int total_probed,
- struct interface **local_interfaces)
+ struct interface **local_interfaces,
+ bool enable_ipv6)
{
- struct in_addr ip, nmask;
+ struct sockaddr_storage ss;
+ struct sockaddr_storage ss_mask;
+ struct sockaddr_storage ss_net;
+ struct sockaddr_storage ss_bcast;
+ struct iface_struct ifs;
char *p;
- char *address;
- int i, added=0;
+ int i;
+ bool added=false;
+ bool goodaddr = false;
- ip.s_addr = 0;
- nmask.s_addr = 0;
-
/* first check if it is an interface name */
for (i=0;i<total_probed;i++) {
if (gen_fnmatch(token, probed_ifaces[i].name) == 0) {
- add_interface(mem_ctx, probed_ifaces[i].ip,
- probed_ifaces[i].netmask,
- local_interfaces);
- added = 1;
+ add_interface(mem_ctx, &probed_ifaces[i],
+ local_interfaces, enable_ipv6);
+ added = true;
}
}
- if (added) return;
+ if (added) {
+ return;
+ }
/* maybe it is a DNS name */
p = strchr_m(token,'/');
- if (!p) {
- /* don't try to do dns lookups on wildcard names */
- if (strpbrk(token, "*?") != NULL) {
+ if (p == NULL) {
+ if (!interpret_string_addr(&ss, token, 0)) {
+ DEBUG(2, ("interpret_interface: Can't find address "
+ "for %s\n", token));
return;
}
- ip.s_addr = interpret_addr2(token).s_addr;
+
for (i=0;i<total_probed;i++) {
- if (ip.s_addr == probed_ifaces[i].ip.s_addr) {
- add_interface(mem_ctx, probed_ifaces[i].ip,
- probed_ifaces[i].netmask,
- local_interfaces);
+ if (sockaddr_equal((struct sockaddr *)&ss, (struct sockaddr *)&probed_ifaces[i].ip)) {
+ add_interface(mem_ctx, &probed_ifaces[i],
+ local_interfaces, enable_ipv6);
return;
}
}
- DEBUG(2,("can't determine netmask for %s\n", token));
+ DEBUG(2,("interpret_interface: "
+ "can't determine interface for %s\n",
+ token));
return;
}
- address = talloc_strdup(mem_ctx, token);
- p = strchr_m(address,'/');
-
/* parse it into an IP address/netmasklength pair */
- *p++ = 0;
-
- ip.s_addr = interpret_addr2(address).s_addr;
+ *p = 0;
+ goodaddr = interpret_string_addr(&ss, token, 0);
+ *p++ = '/';
+
+ if (!goodaddr) {
+ DEBUG(2,("interpret_interface: "
+ "can't determine interface for %s\n",
+ token));
+ return;
+ }
if (strlen(p) > 2) {
- nmask.s_addr = interpret_addr2(p).s_addr;
+ goodaddr = interpret_string_addr(&ss_mask, p, 0);
+ if (!goodaddr) {
+ DEBUG(2,("interpret_interface: "
+ "can't determine netmask from %s\n",
+ p));
+ return;
+ }
} else {
- nmask.s_addr = htonl(((ALLONES >> atoi(p)) ^ ALLONES));
+ char *endp = NULL;
+ unsigned long val = strtoul(p, &endp, 0);
+ if (p == endp || (endp && *endp != '\0')) {
+ DEBUG(2,("interpret_interface: "
+ "can't determine netmask value from %s\n",
+ p));
+ return;
+ }
+ if (!make_netmask(&ss_mask, &ss, val)) {
+ DEBUG(2,("interpret_interface: "
+ "can't apply netmask value %lu from %s\n",
+ val,
+ p));
+ return;
+ }
}
- /* maybe the first component was a broadcast address */
- if (ip.s_addr == MKBCADDR(ip.s_addr, nmask.s_addr) ||
- ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) {
+ make_bcast(&ss_bcast, &ss, &ss_mask);
+ make_net(&ss_net, &ss, &ss_mask);
+
+ /* Maybe the first component was a broadcast address. */
+ if (sockaddr_equal((struct sockaddr *)&ss_bcast, (struct sockaddr *)&ss) ||
+ sockaddr_equal((struct sockaddr *)&ss_net, (struct sockaddr *)&ss)) {
for (i=0;i<total_probed;i++) {
- if (same_net_v4(ip, probed_ifaces[i].ip, nmask)) {
- add_interface(mem_ctx, probed_ifaces[i].ip, nmask,
- local_interfaces);
- talloc_free(address);
+ if (same_net((struct sockaddr *)&ss,
+ (struct sockaddr *)&probed_ifaces[i].ip,
+ (struct sockaddr *)&ss_mask)) {
+ /* Temporarily replace netmask on
+ * the detected interface - user knows
+ * best.... */
+ struct sockaddr_storage saved_mask =
+ probed_ifaces[i].netmask;
+ probed_ifaces[i].netmask = ss_mask;
+ DEBUG(2,("interpret_interface: "
+ "using netmask value %s from "
+ "config file on interface %s\n",
+ p,
+ probed_ifaces[i].name));
+ add_interface(mem_ctx, &probed_ifaces[i],
+ local_interfaces, enable_ipv6);
+ probed_ifaces[i].netmask = saved_mask;
return;
}
}
- DEBUG(2,("Can't determine ip for broadcast address %s\n", address));
- talloc_free(address);
+ DEBUG(2,("interpret_interface: Can't determine ip for "
+ "broadcast address %s\n",
+ token));
return;
}
- add_interface(mem_ctx, ip, nmask, local_interfaces);
- talloc_free(address);
+ /* Just fake up the interface definition. User knows best. */
+
+ DEBUG(2,("interpret_interface: Adding interface %s\n",
+ token));
+
+ ZERO_STRUCT(ifs);
+ (void)strlcpy(ifs.name, token, sizeof(ifs.name));
+ ifs.flags = IFF_BROADCAST;
+ ifs.ip = ss;
+ ifs.netmask = ss_mask;
+ ifs.bcast = ss_bcast;
+ add_interface(mem_ctx, &ifs,
+ local_interfaces, enable_ipv6);
}
/**
load the list of network interfaces
**/
-void load_interfaces(TALLOC_CTX *mem_ctx, const char **interfaces, struct interface **local_interfaces)
+void load_interface_list(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, struct interface **local_interfaces)
{
- const char **ptr = interfaces;
+ const char **ptr = lpcfg_interfaces(lp_ctx);
int i;
- struct iface_struct ifaces[MAX_INTERFACES];
- struct in_addr loopback_ip;
+ struct iface_struct *ifaces;
int total_probed;
+ bool enable_ipv6 = lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", true);
*local_interfaces = NULL;
- loopback_ip = interpret_addr2("127.0.0.1");
-
/* probe the kernel for interfaces */
- total_probed = get_interfaces(ifaces, MAX_INTERFACES);
+ total_probed = get_interfaces(mem_ctx, &ifaces);
/* if we don't have a interfaces line then use all interfaces
except loopback */
@@ -215,27 +309,27 @@ void load_interfaces(TALLOC_CTX *mem_ctx, const char **interfaces, struct interf
DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n"));
}
for (i=0;i<total_probed;i++) {
- if (ifaces[i].ip.s_addr != loopback_ip.s_addr) {
- add_interface(mem_ctx, ifaces[i].ip,
- ifaces[i].netmask, local_interfaces);
+ if (!is_loopback_addr((struct sockaddr *)&ifaces[i].ip)) {
+ add_interface(mem_ctx, &ifaces[i], local_interfaces, enable_ipv6);
}
}
}
while (ptr && *ptr) {
- interpret_interface(mem_ctx, *ptr, ifaces, total_probed, local_interfaces);
+ interpret_interface(mem_ctx, *ptr, ifaces, total_probed, local_interfaces, enable_ipv6);
ptr++;
}
if (!*local_interfaces) {
DEBUG(0,("WARNING: no network interfaces found\n"));
}
+ talloc_free(ifaces);
}
/**
how many interfaces do we have
**/
-int iface_count(struct interface *ifaces)
+int iface_list_count(struct interface *ifaces)
{
int ret = 0;
struct interface *i;
@@ -248,7 +342,7 @@ int iface_count(struct interface *ifaces)
/**
return IP of the Nth interface
**/
-const char *iface_n_ip(struct interface *ifaces, int n)
+const char *iface_list_n_ip(struct interface *ifaces, int n)
{
struct interface *i;
@@ -261,10 +355,59 @@ const char *iface_n_ip(struct interface *ifaces, int n)
return NULL;
}
+
+/**
+ return the first IPv4 interface address we have registered
+ **/
+const char *iface_list_first_v4(struct interface *ifaces)
+{
+ struct interface *i;
+
+ for (i=ifaces; i; i=i->next) {
+ if (i->ip.ss_family == AF_INET) {
+ return i->ip_s;
+ }
+ }
+ return NULL;
+}
+
+/**
+ return the first IPv6 interface address we have registered
+ **/
+static const char *iface_list_first_v6(struct interface *ifaces)
+{
+ struct interface *i;
+
+#ifdef HAVE_IPV6
+ for (i=ifaces; i; i=i->next) {
+ if (i->ip.ss_family == AF_INET6) {
+ return i->ip_s;
+ }
+ }
+#endif
+ return NULL;
+}
+
+/**
+ check if an interface is IPv4
+ **/
+bool iface_list_n_is_v4(struct interface *ifaces, int n)
+{
+ struct interface *i;
+
+ for (i=ifaces;i && n;i=i->next)
+ n--;
+
+ if (i) {
+ return i->ip.ss_family == AF_INET;
+ }
+ return false;
+}
+
/**
return bcast of the Nth interface
**/
-const char *iface_n_bcast(struct interface *ifaces, int n)
+const char *iface_list_n_bcast(struct interface *ifaces, int n)
{
struct interface *i;
@@ -280,7 +423,7 @@ const char *iface_n_bcast(struct interface *ifaces, int n)
/**
return netmask of the Nth interface
**/
-const char *iface_n_netmask(struct interface *ifaces, int n)
+const char *iface_list_n_netmask(struct interface *ifaces, int n)
{
struct interface *i;
@@ -297,28 +440,37 @@ const char *iface_n_netmask(struct interface *ifaces, int n)
return the local IP address that best matches a destination IP, or
our first interface if none match
*/
-const char *iface_best_ip(struct interface *ifaces, const char *dest)
+const char *iface_list_best_ip(struct interface *ifaces, const char *dest)
{
struct interface *iface;
- struct in_addr ip;
+ struct sockaddr_storage ss;
- ip.s_addr = interpret_addr(dest);
- iface = iface_find(ifaces, ip, true);
+ if (!interpret_string_addr(&ss, dest, AI_NUMERICHOST)) {
+ return iface_list_n_ip(ifaces, 0);
+ }
+ iface = iface_list_find(ifaces, (const struct sockaddr *)&ss, true);
if (iface) {
return iface->ip_s;
}
- return iface_n_ip(ifaces, 0);
+#ifdef HAVE_IPV6
+ if (ss.ss_family == AF_INET6) {
+ return iface_list_first_v6(ifaces);
+ }
+#endif
+ return iface_list_first_v4(ifaces);
}
/**
return true if an IP is one one of our local networks
*/
-bool iface_is_local(struct interface *ifaces, const char *dest)
+bool iface_list_is_local(struct interface *ifaces, const char *dest)
{
- struct in_addr ip;
+ struct sockaddr_storage ss;
- ip.s_addr = interpret_addr(dest);
- if (iface_find(ifaces, ip, true)) {
+ if (!interpret_string_addr(&ss, dest, AI_NUMERICHOST)) {
+ return false;
+ }
+ if (iface_list_find(ifaces, (const struct sockaddr *)&ss, true)) {
return true;
}
return false;
@@ -327,9 +479,50 @@ bool iface_is_local(struct interface *ifaces, const char *dest)
/**
return true if a IP matches a IP/netmask pair
*/
-bool iface_same_net(const char *ip1, const char *ip2, const char *netmask)
+bool iface_list_same_net(const char *ip1, const char *ip2, const char *netmask)
{
- return same_net_v4(interpret_addr2(ip1),
- interpret_addr2(ip2),
- interpret_addr2(netmask));
+ struct sockaddr_storage ip1_ss, ip2_ss, nm_ss;
+
+ if (!interpret_string_addr(&ip1_ss, ip1, AI_NUMERICHOST)) {
+ return false;
+ }
+ if (!interpret_string_addr(&ip2_ss, ip2, AI_NUMERICHOST)) {
+ return false;
+ }
+ if (!interpret_string_addr(&nm_ss, netmask, AI_NUMERICHOST)) {
+ return false;
+ }
+
+ return same_net((struct sockaddr *)&ip1_ss,
+ (struct sockaddr *)&ip2_ss,
+ (struct sockaddr *)&nm_ss);
+}
+
+/**
+ return the list of wildcard interfaces
+ this will include the IPv4 0.0.0.0, and may include IPv6 ::
+ it is overridden by the 'socket address' option in smb.conf
+*/
+const char **iface_list_wildcard(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
+{
+ const char **ret;
+ const char *socket_address;
+
+ /* the user may have configured a specific address */
+ socket_address = lpcfg_socket_address(lp_ctx);
+ if (strcmp(socket_address, "") != 0) {
+ ret = (const char **)str_list_make(mem_ctx, socket_address, NULL);
+ return ret;
+ }
+
+ ret = (const char **)str_list_make(mem_ctx, "0.0.0.0", NULL);
+ if (ret == NULL) return NULL;
+
+#ifdef HAVE_IPV6
+ if (lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", true)) {
+ return str_list_add(ret, "::");
+ }
+#endif
+
+ return ret;
}
diff --git a/source4/lib/socket/netif.c b/source4/lib/socket/netif.c
deleted file mode 100644
index e36f268bde..0000000000
--- a/source4/lib/socket/netif.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- return a list of network interfaces
- Copyright (C) Andrew Tridgell 1998
- Copyright (C) Jeremy Allison 2007
- Copyright (C) Jelmer Vernooij 2007
-
- 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-
-/* working out the interfaces for a OS is an incredibly non-portable
- thing. We have several possible implementations below, and autoconf
- tries each of them to see what works
-
- Note that this file does _not_ include includes.h. That is so this code
- can be called directly from the autoconf tests. That also means
- this code cannot use any of the normal Samba debug stuff or defines.
- This is standalone code.
-
-*/
-
-#include "includes.h"
-#include "system/network.h"
-#include "netif.h"
-#include "lib/util/tsort.h"
-
-/****************************************************************************
- Try the "standard" getifaddrs/freeifaddrs interfaces.
- Also gets IPv6 interfaces.
-****************************************************************************/
-
-/****************************************************************************
- Get the netmask address for a local interface.
-****************************************************************************/
-
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- struct ifaddrs *iflist = NULL;
- struct ifaddrs *ifptr = NULL;
- int total = 0;
-
- if (getifaddrs(&iflist) < 0) {
- return -1;
- }
-
- /* Loop through interfaces, looking for given IP address */
- for (ifptr = iflist, total = 0;
- ifptr != NULL && total < max_interfaces;
- ifptr = ifptr->ifa_next) {
-
- memset(&ifaces[total], '\0', sizeof(ifaces[total]));
-
- if (!ifptr->ifa_addr || !ifptr->ifa_netmask) {
- continue;
- }
-
- /* Check the interface is up. */
- if (!(ifptr->ifa_flags & IFF_UP)) {
- continue;
- }
-
- /* We don't support IPv6 *yet* */
- if (ifptr->ifa_addr->sa_family != AF_INET) {
- continue;
- }
-
- ifaces[total].ip = ((struct sockaddr_in *)ifptr->ifa_addr)->sin_addr;
- ifaces[total].netmask = ((struct sockaddr_in *)ifptr->ifa_netmask)->sin_addr;
-
- strlcpy(ifaces[total].name, ifptr->ifa_name,
- sizeof(ifaces[total].name));
- total++;
- }
-
- freeifaddrs(iflist);
-
- return total;
-}
-
-static int iface_comp(struct iface_struct *i1, struct iface_struct *i2)
-{
- int r;
- r = strcmp(i1->name, i2->name);
- if (r) return r;
- r = ntohl(i1->ip.s_addr) - ntohl(i2->ip.s_addr);
- if (r) return r;
- r = ntohl(i1->netmask.s_addr) - ntohl(i2->netmask.s_addr);
- return r;
-}
-
-/* this wrapper is used to remove duplicates from the interface list generated
- above */
-int get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- int total, i, j;
-
- total = _get_interfaces(ifaces, max_interfaces);
- if (total <= 0) return total;
-
- /* now we need to remove duplicates */
- TYPESAFE_QSORT(ifaces, total, iface_comp);
-
- for (i=1;i<total;) {
- if (iface_comp(&ifaces[i-1], &ifaces[i]) == 0) {
- for (j=i-1;j<total-1;j++) {
- ifaces[j] = ifaces[j+1];
- }
- total--;
- } else {
- i++;
- }
- }
-
- return total;
-}
diff --git a/source4/lib/socket/netif.h b/source4/lib/socket/netif.h
index 417c6e074f..1d90a4fd13 100644
--- a/source4/lib/socket/netif.h
+++ b/source4/lib/socket/netif.h
@@ -20,17 +20,5 @@
*/
#include "system/network.h"
-
-struct iface_struct {
- char name[16];
- struct in_addr ip;
- struct in_addr netmask;
-};
-
-struct interface;
-
-#define MAX_INTERFACES 128
-
-#ifndef AUTOCONF_TEST
+#include "lib/socket/interfaces.h"
#include "lib/socket/netif_proto.h"
-#endif
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index 4b5cecab34..2dbdaad11d 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -451,7 +451,7 @@ _PUBLIC_ NTSTATUS socket_dup(struct socket_context *sock)
}
fd = dup(sock->fd);
if (fd == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
close(sock->fd);
sock->fd = fd;
@@ -473,6 +473,11 @@ _PUBLIC_ struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx,
return NULL;
}
+ if (strcmp(family, "ip") == 0 && is_ipaddress_v6(host)) {
+ /* leaving as "ip" would force IPv4 */
+ family = "ipv6";
+ }
+
addr->family = family;
addr->addr = talloc_strdup(addr, host);
if (!addr->addr) {
@@ -498,7 +503,19 @@ _PUBLIC_ struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx
if (!addr) {
return NULL;
}
- addr->family = NULL;
+ switch (sockaddr->sa_family) {
+ case AF_INET:
+ addr->family = "ipv4";
+ break;
+#ifdef HAVE_IPV6
+ case AF_INET6:
+ addr->family = "ipv6";
+ break;
+#endif
+ case AF_UNIX:
+ addr->family = "unix";
+ break;
+ }
addr->addr = NULL;
addr->port = 0;
addr->sockaddr = (struct sockaddr *)talloc_memdup(addr, sockaddr, sockaddrlen);
@@ -510,6 +527,50 @@ _PUBLIC_ struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx
return addr;
}
+
+/*
+ Create a new socket_address from sockaddr_storage
+ */
+_PUBLIC_ struct socket_address *socket_address_from_sockaddr_storage(TALLOC_CTX *mem_ctx,
+ const struct sockaddr_storage *sockaddr,
+ uint16_t port)
+{
+ struct socket_address *addr = talloc_zero(mem_ctx, struct socket_address);
+ char addr_str[INET6_ADDRSTRLEN+1];
+ const char *str;
+
+ if (!addr) {
+ return NULL;
+ }
+ addr->port = port;
+ switch (sockaddr->ss_family) {
+ case AF_INET:
+ addr->family = "ipv4";
+ break;
+#ifdef HAVE_IPV6
+ case AF_INET6:
+ addr->family = "ipv6";
+ break;
+#endif
+ default:
+ talloc_free(addr);
+ return NULL;
+ }
+
+ str = print_sockaddr(addr_str, sizeof(addr_str), sockaddr);
+ if (str == NULL) {
+ talloc_free(addr);
+ return NULL;
+ }
+ addr->addr = talloc_strdup(addr, str);
+ if (addr->addr == NULL) {
+ talloc_free(addr);
+ return NULL;
+ }
+
+ return addr;
+}
+
/* Copy a socket_address structure */
struct socket_address *socket_address_copy(TALLOC_CTX *mem_ctx,
const struct socket_address *oaddr)
@@ -567,110 +628,6 @@ _PUBLIC_ const struct socket_ops *socket_getops_byname(const char *family, enum
return NULL;
}
-enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON};
-
-static const struct {
- const char *name;
- int level;
- int option;
- int value;
- int opttype;
-} socket_options[] = {
- {"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL},
- {"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL},
- {"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL},
-#ifdef TCP_NODELAY
- {"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL},
-#endif
-#ifdef IPTOS_LOWDELAY
- {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON},
-#endif
-#ifdef IPTOS_THROUGHPUT
- {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON},
-#endif
-#ifdef SO_REUSEPORT
- {"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, 0, OPT_BOOL},
-#endif
-#ifdef SO_SNDBUF
- {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT},
-#endif
-#ifdef SO_RCVBUF
- {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT},
-#endif
-#ifdef SO_SNDLOWAT
- {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT},
-#endif
-#ifdef SO_RCVLOWAT
- {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT},
-#endif
-#ifdef SO_SNDTIMEO
- {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT},
-#endif
-#ifdef SO_RCVTIMEO
- {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT},
-#endif
- {NULL,0,0,0,0}};
-
-
-/**
- Set user socket options.
-**/
-_PUBLIC_ void set_socket_options(int fd, const char *options)
-{
- const char **options_list = (const char **)str_list_make(NULL, options, " \t,");
- int j;
-
- if (!options_list)
- return;
-
- for (j = 0; options_list[j]; j++) {
- const char *tok = options_list[j];
- int ret=0,i;
- int value = 1;
- char *p;
- bool got_value = false;
-
- if ((p = strchr(tok,'='))) {
- *p = 0;
- value = atoi(p+1);
- got_value = true;
- }
-
- for (i=0;socket_options[i].name;i++)
- if (strequal(socket_options[i].name,tok))
- break;
-
- if (!socket_options[i].name) {
- DEBUG(0,("Unknown socket option %s\n",tok));
- continue;
- }
-
- switch (socket_options[i].opttype) {
- case OPT_BOOL:
- case OPT_INT:
- ret = setsockopt(fd,socket_options[i].level,
- socket_options[i].option,(char *)&value,sizeof(int));
- break;
-
- case OPT_ON:
- if (got_value)
- DEBUG(0,("syntax error - %s does not take a value\n",tok));
-
- {
- int on = socket_options[i].value;
- ret = setsockopt(fd,socket_options[i].level,
- socket_options[i].option,(char *)&on,sizeof(int));
- }
- break;
- }
-
- if (ret != 0)
- DEBUG(0,("Failed to set socket option %s (Error %s)\n",tok, strerror(errno) ));
- }
-
- talloc_free(options_list);
-}
-
/*
set some flags on a socket
*/
diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h
index 4a744797b3..e00b61ba6c 100644
--- a/source4/lib/socket/socket.h
+++ b/source4/lib/socket/socket.h
@@ -174,14 +174,18 @@ struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx,
struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx,
struct sockaddr *sockaddr,
size_t addrlen);
+struct sockaddr_storage;
+struct socket_address *socket_address_from_sockaddr_storage(TALLOC_CTX *mem_ctx,
+ const struct sockaddr_storage *sockaddr,
+ uint16_t port);
_PUBLIC_ void socket_address_set_port(struct socket_address *a,
uint16_t port);
struct socket_address *socket_address_copy(TALLOC_CTX *mem_ctx,
const struct socket_address *oaddr);
const struct socket_ops *socket_getops_byname(const char *name, enum socket_type type);
-bool allow_access(TALLOC_CTX *mem_ctx,
- const char **deny_list, const char **allow_list,
- const char *cname, const char *caddr);
+bool socket_allow_access(TALLOC_CTX *mem_ctx,
+ const char **deny_list, const char **allow_list,
+ const char *cname, const char *caddr);
bool socket_check_access(struct socket_context *sock,
const char *service_name,
const char **allow_list, const char **deny_list);
diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c
index 4e66653252..80f7d333f3 100644
--- a/source4/lib/socket/socket_ip.c
+++ b/source4/lib/socket/socket_ip.c
@@ -47,7 +47,7 @@ static NTSTATUS ipv4_init(struct socket_context *sock)
sock->fd = socket(PF_INET, type, 0);
if (sock->fd == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
sock->backend_name = "ipv4";
@@ -70,16 +70,16 @@ static NTSTATUS ip_connect_complete(struct socket_context *sock, uint32_t flags)
for non-blocking connect */
ret = getsockopt(sock->fd, SOL_SOCKET, SO_ERROR, &error, &len);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
if (error != 0) {
- return map_nt_error_from_unix(error);
+ return map_nt_error_from_unix_common(error);
}
if (!(flags & SOCKET_FLAG_BLOCK)) {
ret = set_blocking(sock->fd, false);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
@@ -102,7 +102,7 @@ static NTSTATUS ipv4_connect(struct socket_context *sock,
if (my_address && my_address->sockaddr) {
ret = bind(sock->fd, my_address->sockaddr, my_address->sockaddrlen);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
} else if (my_address) {
my_ip = interpret_addr2(my_address->addr);
@@ -119,7 +119,7 @@ static NTSTATUS ipv4_connect(struct socket_context *sock,
ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
}
@@ -127,7 +127,7 @@ static NTSTATUS ipv4_connect(struct socket_context *sock,
if (srv_address->sockaddr) {
ret = connect(sock->fd, srv_address->sockaddr, srv_address->sockaddrlen);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
} else {
srv_ip = interpret_addr2(srv_address->addr);
@@ -147,7 +147,7 @@ static NTSTATUS ipv4_connect(struct socket_context *sock,
ret = connect(sock->fd, (const struct sockaddr *)&srv_addr, sizeof(srv_addr));
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
@@ -186,20 +186,20 @@ static NTSTATUS ipv4_listen(struct socket_context *sock,
}
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
if (sock->type == SOCKET_TYPE_STREAM) {
ret = listen(sock->fd, queue_size);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
if (!(flags & SOCKET_FLAG_BLOCK)) {
ret = set_blocking(sock->fd, false);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
@@ -220,14 +220,14 @@ static NTSTATUS ipv4_accept(struct socket_context *sock, struct socket_context *
new_fd = accept(sock->fd, (struct sockaddr *)&cli_addr, &cli_addr_len);
if (new_fd == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
if (!(sock->flags & SOCKET_FLAG_BLOCK)) {
int ret = set_blocking(new_fd, false);
if (ret == -1) {
close(new_fd);
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
@@ -268,7 +268,7 @@ static NTSTATUS ip_recv(struct socket_context *sock, void *buf,
if (gotlen == 0) {
return NT_STATUS_END_OF_FILE;
} else if (gotlen == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
*nread = gotlen;
@@ -311,7 +311,7 @@ static NTSTATUS ipv4_recvfrom(struct socket_context *sock, void *buf,
return NT_STATUS_END_OF_FILE;
} else if (gotlen == -1) {
talloc_free(src);
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
src->sockaddrlen = from_len;
@@ -342,7 +342,7 @@ static NTSTATUS ip_send(struct socket_context *sock,
len = send(sock->fd, blob->data, blob->length, 0);
if (len == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
*sendlen = len;
@@ -383,7 +383,7 @@ static NTSTATUS ipv4_sendto(struct socket_context *sock,
(struct sockaddr *)&srv_addr, sizeof(srv_addr));
}
if (len == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
*sendlen = len;
@@ -518,7 +518,7 @@ static NTSTATUS ip_pending(struct socket_context *sock, size_t *npending)
*npending = value;
return NT_STATUS_OK;
}
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
static const struct socket_ops ipv4_ops = {
@@ -604,7 +604,7 @@ static NTSTATUS ipv6_init(struct socket_context *sock)
sock->fd = socket(PF_INET6, type, 0);
if (sock->fd == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
sock->backend_name = "ipv6";
@@ -623,7 +623,7 @@ static NTSTATUS ipv6_tcp_connect(struct socket_context *sock,
if (my_address && my_address->sockaddr) {
ret = bind(sock->fd, my_address->sockaddr, my_address->sockaddrlen);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
} else if (my_address) {
struct in6_addr my_ip;
@@ -638,7 +638,7 @@ static NTSTATUS ipv6_tcp_connect(struct socket_context *sock,
ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
}
@@ -661,15 +661,28 @@ static NTSTATUS ipv6_tcp_connect(struct socket_context *sock,
ret = connect(sock->fd, (const struct sockaddr *)&srv_addr, sizeof(srv_addr));
}
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
return ip_connect_complete(sock, flags);
}
+/*
+ fix the sin6_scope_id based on the address interface
+ */
+static void fix_scope_id(struct sockaddr_in6 *in6,
+ const char *address)
+{
+ const char *p = strchr(address, '%');
+ if (p != NULL) {
+ in6->sin6_scope_id = if_nametoindex(p+1);
+ }
+}
+
+
static NTSTATUS ipv6_listen(struct socket_context *sock,
- const struct socket_address *my_address,
- int queue_size, uint32_t flags)
+ const struct socket_address *my_address,
+ int queue_size, uint32_t flags)
{
struct sockaddr_in6 my_addr;
struct in6_addr ip_addr;
@@ -680,31 +693,38 @@ static NTSTATUS ipv6_listen(struct socket_context *sock,
if (my_address->sockaddr) {
ret = bind(sock->fd, my_address->sockaddr, my_address->sockaddrlen);
} else {
+ int one = 1;
ip_addr = interpret_addr6(my_address->addr);
ZERO_STRUCT(my_addr);
my_addr.sin6_addr = ip_addr;
my_addr.sin6_port = htons(my_address->port);
my_addr.sin6_family = PF_INET6;
-
- ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
+ fix_scope_id(&my_addr, my_address->addr);
+
+ /* when binding on ipv6 we always want to only bind on v6 */
+ ret = setsockopt(sock->fd, IPPROTO_IPV6, IPV6_V6ONLY,
+ (const void *)&one, sizeof(one));
+ if (ret != -1) {
+ ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
+ }
}
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
if (sock->type == SOCKET_TYPE_STREAM) {
ret = listen(sock->fd, queue_size);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
if (!(flags & SOCKET_FLAG_BLOCK)) {
ret = set_blocking(sock->fd, false);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
@@ -725,14 +745,14 @@ static NTSTATUS ipv6_tcp_accept(struct socket_context *sock, struct socket_conte
new_fd = accept(sock->fd, (struct sockaddr *)&cli_addr, &cli_addr_len);
if (new_fd == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
if (!(sock->flags & SOCKET_FLAG_BLOCK)) {
int ret = set_blocking(new_fd, false);
if (ret == -1) {
close(new_fd);
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
@@ -796,7 +816,7 @@ static NTSTATUS ipv6_recvfrom(struct socket_context *sock, void *buf,
return NT_STATUS_END_OF_FILE;
} else if (gotlen == -1) {
talloc_free(src);
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
src->sockaddrlen = from_len;
@@ -847,7 +867,7 @@ static NTSTATUS ipv6_sendto(struct socket_context *sock,
(struct sockaddr *)&srv_addr, sizeof(srv_addr));
}
if (len == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
*sendlen = len;
diff --git a/source4/lib/socket/socket_unix.c b/source4/lib/socket/socket_unix.c
index f1fa0a3a30..d492f01268 100644
--- a/source4/lib/socket/socket_unix.c
+++ b/source4/lib/socket/socket_unix.c
@@ -33,7 +33,7 @@ _PUBLIC_ const struct socket_ops *socket_unixdom_ops(enum socket_type type);
*/
static NTSTATUS unixdom_error(int ernum)
{
- return map_nt_error_from_unix(ernum);
+ return map_nt_error_from_unix_common(ernum);
}
static NTSTATUS unixdom_init(struct socket_context *sock)
@@ -53,7 +53,7 @@ static NTSTATUS unixdom_init(struct socket_context *sock)
sock->fd = socket(PF_UNIX, type, 0);
if (sock->fd == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
sock->private_data = NULL;
@@ -76,16 +76,16 @@ static NTSTATUS unixdom_connect_complete(struct socket_context *sock, uint32_t f
for non-blocking connect */
ret = getsockopt(sock->fd, SOL_SOCKET, SO_ERROR, &error, &len);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
if (error != 0) {
- return map_nt_error_from_unix(error);
+ return map_nt_error_from_unix_common(error);
}
if (!(flags & SOCKET_FLAG_BLOCK)) {
ret = set_blocking(sock->fd, false);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
@@ -194,7 +194,7 @@ static NTSTATUS unixdom_accept(struct socket_context *sock,
int ret = set_blocking(new_fd, false);
if (ret == -1) {
close(new_fd);
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
}
@@ -280,7 +280,7 @@ static NTSTATUS unixdom_sendto(struct socket_context *sock,
(struct sockaddr *)&srv_addr, sizeof(srv_addr));
}
if (len == -1) {
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
*sendlen = len;
@@ -390,7 +390,7 @@ static NTSTATUS unixdom_pending(struct socket_context *sock, size_t *npending)
*npending = value;
return NT_STATUS_OK;
}
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
static const struct socket_ops unixdom_ops = {
diff --git a/source4/lib/socket/testsuite.c b/source4/lib/socket/testsuite.c
index 2489277433..357e4ae5df 100644
--- a/source4/lib/socket/testsuite.c
+++ b/source4/lib/socket/testsuite.c
@@ -42,7 +42,7 @@ static bool test_udp(struct torture_context *tctx)
TALLOC_CTX *mem_ctx = tctx;
struct interface *ifaces;
- load_interfaces(tctx, lpcfg_interfaces(tctx->lp_ctx), &ifaces);
+ load_interface_list(tctx, tctx->lp_ctx, &ifaces);
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0);
torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
@@ -53,7 +53,7 @@ static bool test_udp(struct torture_context *tctx)
talloc_steal(mem_ctx, sock2);
localhost = socket_address_from_strings(sock1, sock1->backend_name,
- iface_best_ip(ifaces, "127.0.0.1"), 0);
+ iface_list_best_ip(ifaces, "127.0.0.1"), 0);
torture_assert(tctx, localhost, "Localhost not found");
@@ -62,10 +62,10 @@ static bool test_udp(struct torture_context *tctx)
srv_addr = socket_get_my_addr(sock1, mem_ctx);
torture_assert(tctx, srv_addr != NULL &&
- strcmp(srv_addr->addr, iface_best_ip(ifaces, "127.0.0.1")) == 0,
+ strcmp(srv_addr->addr, iface_list_best_ip(ifaces, "127.0.0.1")) == 0,
talloc_asprintf(tctx,
"Expected server address of %s but got %s",
- iface_best_ip(ifaces, "127.0.0.1"), srv_addr ? srv_addr->addr : NULL));
+ iface_list_best_ip(ifaces, "127.0.0.1"), srv_addr ? srv_addr->addr : NULL));
torture_comment(tctx, "server port is %d\n", srv_addr->port);
@@ -135,9 +135,9 @@ static bool test_tcp(struct torture_context *tctx)
torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
talloc_steal(mem_ctx, sock2);
- load_interfaces(tctx, lpcfg_interfaces(tctx->lp_ctx), &ifaces);
+ load_interface_list(tctx, tctx->lp_ctx, &ifaces);
localhost = socket_address_from_strings(sock1, sock1->backend_name,
- iface_best_ip(ifaces, "127.0.0.1"), 0);
+ iface_list_best_ip(ifaces, "127.0.0.1"), 0);
torture_assert(tctx, localhost, "Localhost not found");
status = socket_listen(sock1, localhost, 0, 0);
@@ -147,7 +147,7 @@ static bool test_tcp(struct torture_context *tctx)
torture_assert(tctx, srv_addr && srv_addr->addr,
"Unexpected socket_get_my_addr NULL\n");
- torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip(ifaces, "127.0.0.1"),
+ torture_assert_str_equal(tctx, srv_addr->addr, iface_list_best_ip(ifaces, "127.0.0.1"),
"Unexpected server address");
torture_comment(tctx, "server port is %d\n", srv_addr->port);
diff --git a/source4/lib/socket/wscript_build b/source4/lib/socket/wscript_build
index e2ff9b078a..c10970d17a 100644
--- a/source4/lib/socket/wscript_build
+++ b/source4/lib/socket/wscript_build
@@ -1,11 +1,11 @@
#!/usr/bin/env python
bld.SAMBA_LIBRARY('netif',
- source='interface.c netif.c',
- autoproto='netif_proto.h',
- deps='samba-util',
- private_library=True
- )
+ source='interface.c',
+ deps='samba-util interfaces samba-hostconfig',
+ private_library=True,
+ autoproto='netif_proto.h'
+ )
bld.SAMBA_MODULE('socket_ip',
source='socket_ip.c',
diff --git a/source4/lib/tdb_wrap.c b/source4/lib/tdb_wrap.c
deleted file mode 100644
index 97294e13d3..0000000000
--- a/source4/lib/tdb_wrap.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- TDB wrap functions
-
- Copyright (C) Andrew Tridgell 2004
- Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
-
- 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include <tdb.h>
-#include "../lib/util/dlinklist.h"
-#include "tdb_wrap.h"
-#include <tdb.h>
-
-static struct tdb_wrap *tdb_list;
-
-/* destroy the last connection to a tdb */
-static int tdb_wrap_destructor(struct tdb_wrap *w)
-{
- tdb_close(w->tdb);
- DLIST_REMOVE(tdb_list, w);
- return 0;
-}
-
-/*
- Log tdb messages via DEBUG().
-*/
-static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
- const char *format, ...) PRINTF_ATTRIBUTE(3,4);
-
-static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
- const char *format, ...)
-{
- va_list ap;
- char *ptr = NULL;
- int dl;
-
- va_start(ap, format);
- vasprintf(&ptr, format, ap);
- va_end(ap);
-
- switch (level) {
- case TDB_DEBUG_FATAL:
- dl = 0;
- break;
- case TDB_DEBUG_ERROR:
- dl = 1;
- break;
- case TDB_DEBUG_WARNING:
- dl = 2;
- break;
- case TDB_DEBUG_TRACE:
- dl = 5;
- break;
- default:
- dl = 0;
- }
-
- if (ptr != NULL) {
- const char *name = tdb_name(tdb);
- DEBUG(dl, ("tdb(%s): %s", name ? name : "unnamed", ptr));
- free(ptr);
- }
-}
-
-
-/*
- wrapped connection to a tdb database
- to close just talloc_free() the tdb_wrap pointer
- */
-struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx,
- const char *name, int hash_size, int tdb_flags,
- int open_flags, mode_t mode)
-{
- struct tdb_wrap *w;
- struct tdb_logging_context log_ctx;
- log_ctx.log_fn = tdb_wrap_log;
-
- for (w=tdb_list;w;w=w->next) {
- if (strcmp(name, w->name) == 0) {
- return talloc_reference(mem_ctx, w);
- }
- }
-
- w = talloc(mem_ctx, struct tdb_wrap);
- if (w == NULL) {
- return NULL;
- }
-
- w->name = talloc_strdup(w, name);
-
- w->tdb = tdb_open_ex(name, hash_size, tdb_flags,
- open_flags, mode, &log_ctx, NULL);
- if (w->tdb == NULL) {
- talloc_free(w);
- return NULL;
- }
-
- talloc_set_destructor(w, tdb_wrap_destructor);
-
- DLIST_ADD(tdb_list, w);
-
- return w;
-}
diff --git a/source4/lib/tdb_wrap.h b/source4/lib/tdb_wrap.h
deleted file mode 100644
index 94035c1bea..0000000000
--- a/source4/lib/tdb_wrap.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- database wrap headers
-
- Copyright (C) Andrew Tridgell 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-/* IMPORTANT: tdb_wrap should be always preferred over tdb_context for end consumer functions
- it's because if the code will be running inside smbd, then we must use the linked list
- of open tdb files, to determine if the tdb we desire is already open
- as otherwise, when you close the tdb (even on a different file descriptor),
- ALL LOCKS are lost (due to a real screwup in the POSIX specification that nobody has been able to get fixed)
-*/
-
-#ifndef _TDB_WRAP_H_
-#define _TDB_WRAP_H_
-
-#include <tdb.h>
-
-struct tdb_wrap {
- struct tdb_context *tdb;
-
- const char *name;
- struct tdb_wrap *next, *prev;
-};
-
-struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx,
- const char *name, int hash_size, int tdb_flags,
- int open_flags, mode_t mode);
-
-#endif /* _TDB_WRAP_H_ */
diff --git a/source4/lib/wscript_build b/source4/lib/wscript_build
index 872259d670..cf60820da7 100644
--- a/source4/lib/wscript_build
+++ b/source4/lib/wscript_build
@@ -5,12 +5,3 @@ bld.SAMBA_SUBSYSTEM('GENCACHE',
enabled=False,
deps='tdb-wrap'
)
-
-
-bld.SAMBA_LIBRARY('tdb-wrap',
- source='tdb_wrap.c',
- deps='tdb talloc samba-util',
- public_headers='tdb_wrap.h',
- private_library=True
- )
-