From 67905b41a97fb7c0a7f4c7070e837f1fcb8bfbb4 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 29 Apr 2011 12:47:11 +1000 Subject: s4-param Rename private_path() -> lpcfg_private_path() This is consistent with lock_path() Andrew Bartlett --- source4/lib/ldb-samba/ldb_wrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb-samba/ldb_wrap.c b/source4/lib/ldb-samba/ldb_wrap.c index 7dcf514e23..6d92f60d62 100644 --- a/source4/lib/ldb-samba/ldb_wrap.c +++ b/source4/lib/ldb-samba/ldb_wrap.c @@ -209,7 +209,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; } -- cgit From d4a06d5dac813951cff3f76704199ec5b6dc834c Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Sun, 10 Apr 2011 19:24:16 +0200 Subject: ldb:ldb_controls.c - fix comment indentation Reviewed-by: abartlet --- source4/lib/ldb/common/ldb_controls.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib') 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; -- cgit From aec1bc7febfb8d3b18018e7b5b653210a0d94e93 Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Sun, 10 Apr 2011 19:35:22 +0200 Subject: ldb:tools/cmdline.c + tools/ldbtest.c - make use of LDB result constants Reviewed-by: abartlet --- source4/lib/ldb/tools/cmdline.c | 2 +- source4/lib/ldb/tools/ldbtest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c index b2be54ebf9..c2599414b0 100644 --- a/source4/lib/ldb/tools/cmdline.c +++ b/source4/lib/ldb/tools/cmdline.c @@ -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..5270357bad 100644 --- a/source4/lib/ldb/tools/ldbtest.c +++ b/source4/lib/ldb/tools/ldbtest.c @@ -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); } -- cgit From e64ffee1c212b6956a993ebb2032f664c0ac5802 Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Sun, 10 Apr 2011 19:41:34 +0200 Subject: ldb:tdb backend - cache - remove unused "last_attribute" structure member MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: abartlet Autobuild-User: Matthias Dieter Wallnöfer Autobuild-Date: Fri Apr 29 20:07:27 CEST 2011 on sn-devel-104 --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 3 --- source4/lib/ldb/ldb_tdb/ldb_tdb.h | 5 ----- 2 files changed, 8 deletions(-) (limited to 'source4/lib') 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(<db->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_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index 33313b00da..3d793d27df 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -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; -- cgit From 85eb4377dbc9e2d25e0ee2e358e785347b09f0a7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 10:05:46 +1000 Subject: s4:cluster Rename .id to .pid in server_id This also changes some DEBUG messages to use cluster_id_string() rather than .id, to isolate them from this and other changes. Andrew Bartlett --- source4/lib/messaging/messaging.c | 10 ++++++---- source4/lib/messaging/pymessaging.c | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index f9d63203f2..48c9c16fb9 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -109,9 +109,11 @@ static void irpc_handler(struct messaging_context *, void *, static void ping_message(struct messaging_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 = cluster_id_string(NULL, src); + DEBUG(1,("INFO: Received PING message from server %s [%.*s]\n", + task_id, (int)data->length, data->data?(const char *)data->data:"")); + talloc_free(task_id); messaging_send(msg, src, MSG_PONG, data); } @@ -638,7 +640,7 @@ struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, { struct server_id id; ZERO_STRUCT(id); - id.id = random() % 0x10000000; + id.pid = random() % 0x10000000; return messaging_init(mem_ctx, dir, id, ev); } /* @@ -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/pymessaging.c b/source4/lib/messaging/pymessaging.c index 358d205b53..017b6f91a2 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -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->id2, &server_id->node); } else { - int id, id2; - if (!PyArg_ParseTuple(object, "ii", &id, &id2)) + int pid, id2; + if (!PyArg_ParseTuple(object, "ii", &pid, &id2)) return false; - *server_id = cluster_id(id, id2); + *server_id = cluster_id(pid, id2); return true; } } @@ -159,7 +159,7 @@ static void py_msg_callback_wrapper(struct messaging_context *msg, void *private 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, + server_id.pid, server_id.id2, server_id.node, data->data, data->length); } @@ -229,7 +229,7 @@ static PyObject *py_messaging_server_id(PyObject *obj, void *closure) messaging_Object *iface = (messaging_Object *)obj; struct server_id server_id = messaging_get_server_id(iface->msg_ctx); - return Py_BuildValue("(iii)", server_id.id, server_id.id2, + return Py_BuildValue("(iii)", server_id.pid, server_id.id2, server_id.node); } -- cgit From 4c8de5ab135d7d8462e264f616225122945c7682 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 10:53:18 +1000 Subject: s4-cluster Rename server_id.node -> vnn to match Samba3 --- source4/lib/messaging/pymessaging.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index 017b6f91a2..a58176dc07 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -45,7 +45,7 @@ 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->pid, &server_id->id2, &server_id->node); + return PyArg_ParseTuple(object, "iii", &server_id->pid, &server_id->id2, &server_id->vnn); } else { int pid, id2; if (!PyArg_ParseTuple(object, "ii", &pid, &id2)) @@ -158,8 +158,8 @@ static void py_msg_callback_wrapper(struct messaging_context *msg, void *private { PyObject *callback = (PyObject *)private_data; - PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type, - server_id.pid, server_id.id2, server_id.node, + PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type, + server_id.pid, server_id.id2, server_id.vnn, data->data, data->length); } @@ -230,7 +230,7 @@ static PyObject *py_messaging_server_id(PyObject *obj, void *closure) struct server_id server_id = messaging_get_server_id(iface->msg_ctx); return Py_BuildValue("(iii)", server_id.pid, server_id.id2, - server_id.node); + server_id.vnn); } static PyGetSetDef py_messaging_getset[] = { -- cgit From 4d0268dce4eb5210ee73efdb6c82aa899b27008f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 16:15:50 +1000 Subject: s4-lib/socket Merge updated set_socket_options from Samba3 -> Samba4 --- source4/lib/socket/socket.c | 124 ++++++++++++++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 34 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c index 4b5cecab34..a627fbe2a6 100644 --- a/source4/lib/socket/socket.c +++ b/source4/lib/socket/socket.c @@ -569,68 +569,115 @@ _PUBLIC_ const struct socket_ops *socket_getops_byname(const char *family, enum enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON}; -static const struct { +typedef struct smb_socket_option { 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}, +} smb_socket_option; + +static const smb_socket_option 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}, + {"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL}, +#endif +#ifdef TCP_KEEPCNT + {"TCP_KEEPCNT", IPPROTO_TCP, TCP_KEEPCNT, 0, OPT_INT}, +#endif +#ifdef TCP_KEEPIDLE + {"TCP_KEEPIDLE", IPPROTO_TCP, TCP_KEEPIDLE, 0, OPT_INT}, +#endif +#ifdef TCP_KEEPINTVL + {"TCP_KEEPINTVL", IPPROTO_TCP, TCP_KEEPINTVL, 0, OPT_INT}, #endif #ifdef IPTOS_LOWDELAY - {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON}, + {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON}, #endif #ifdef IPTOS_THROUGHPUT - {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON}, + {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON}, #endif #ifdef SO_REUSEPORT - {"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, 0, OPT_BOOL}, + {"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, 0, OPT_BOOL}, #endif #ifdef SO_SNDBUF - {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT}, + {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT}, #endif #ifdef SO_RCVBUF - {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT}, + {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT}, #endif #ifdef SO_SNDLOWAT - {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT}, + {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT}, #endif #ifdef SO_RCVLOWAT - {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT}, + {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT}, #endif #ifdef SO_SNDTIMEO - {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT}, + {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT}, #endif #ifdef SO_RCVTIMEO - {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT}, + {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT}, +#endif +#ifdef TCP_FASTACK + {"TCP_FASTACK", IPPROTO_TCP, TCP_FASTACK, 0, OPT_INT}, +#endif +#ifdef TCP_QUICKACK + {"TCP_QUICKACK", IPPROTO_TCP, TCP_QUICKACK, 0, OPT_BOOL}, +#endif +#ifdef TCP_KEEPALIVE_THRESHOLD + {"TCP_KEEPALIVE_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, 0, OPT_INT}, +#endif +#ifdef TCP_KEEPALIVE_ABORT_THRESHOLD + {"TCP_KEEPALIVE_ABORT_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, 0, OPT_INT}, #endif {NULL,0,0,0,0}}; +/**************************************************************************** + Print socket options. +****************************************************************************/ -/** - Set user socket options. -**/ -_PUBLIC_ void set_socket_options(int fd, const char *options) +static void print_socket_options(int s) { - const char **options_list = (const char **)str_list_make(NULL, options, " \t,"); - int j; + int value; + socklen_t vlen = 4; + const smb_socket_option *p = &socket_options[0]; + + /* wrapped in if statement to prevent streams + * leak in SCO Openserver 5.0 */ + /* reported on samba-technical --jerry */ + if ( DEBUGLEVEL >= 5 ) { + DEBUG(5,("Socket options:\n")); + for (; p->name != NULL; p++) { + if (getsockopt(s, p->level, p->option, + (void *)&value, &vlen) == -1) { + DEBUGADD(5,("\tCould not test socket option %s.\n", + p->name)); + } else { + DEBUGADD(5,("\t%s = %d\n", + p->name,value)); + } + } + } + } - if (!options_list) - return; +/**************************************************************************** + Set user socket options. +****************************************************************************/ - for (j = 0; options_list[j]; j++) { - const char *tok = options_list[j]; +void set_socket_options(int fd, const char *options) +{ + TALLOC_CTX *ctx = talloc_new(NULL); + char *tok; + + while (next_token_talloc(ctx, &options, &tok," \t,")) { int ret=0,i; int value = 1; char *p; bool got_value = false; - if ((p = strchr(tok,'='))) { + if ((p = strchr_m(tok,'='))) { *p = 0; value = atoi(p+1); got_value = true; @@ -649,26 +696,35 @@ _PUBLIC_ void set_socket_options(int fd, const char *options) case OPT_BOOL: case OPT_INT: ret = setsockopt(fd,socket_options[i].level, - socket_options[i].option,(char *)&value,sizeof(int)); + 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)); + 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)); + socket_options[i].option, + (char *)&on,sizeof(int)); } - break; + break; + } + + if (ret != 0) { + /* be aware that some systems like Solaris return + * EINVAL to a setsockopt() call when the client + * sent a RST previously - no need to worry */ + DEBUG(2,("Failed to set socket option %s (Error %s)\n", + tok, strerror(errno) )); } - - if (ret != 0) - DEBUG(0,("Failed to set socket option %s (Error %s)\n",tok, strerror(errno) )); } - talloc_free(options_list); + TALLOC_FREE(ctx); + print_socket_options(fd); } /* -- cgit From eea783e04cca45b1d3d9e5bb10556a2c8dc79b86 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 16:23:40 +1000 Subject: lib/util Move set_socket_options() into common code. --- source4/lib/socket/socket.c | 160 -------------------------------------------- 1 file changed, 160 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c index a627fbe2a6..cecd1026d5 100644 --- a/source4/lib/socket/socket.c +++ b/source4/lib/socket/socket.c @@ -567,166 +567,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}; - -typedef struct smb_socket_option { - const char *name; - int level; - int option; - int value; - int opttype; -} smb_socket_option; - -static const smb_socket_option 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 TCP_KEEPCNT - {"TCP_KEEPCNT", IPPROTO_TCP, TCP_KEEPCNT, 0, OPT_INT}, -#endif -#ifdef TCP_KEEPIDLE - {"TCP_KEEPIDLE", IPPROTO_TCP, TCP_KEEPIDLE, 0, OPT_INT}, -#endif -#ifdef TCP_KEEPINTVL - {"TCP_KEEPINTVL", IPPROTO_TCP, TCP_KEEPINTVL, 0, OPT_INT}, -#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 -#ifdef TCP_FASTACK - {"TCP_FASTACK", IPPROTO_TCP, TCP_FASTACK, 0, OPT_INT}, -#endif -#ifdef TCP_QUICKACK - {"TCP_QUICKACK", IPPROTO_TCP, TCP_QUICKACK, 0, OPT_BOOL}, -#endif -#ifdef TCP_KEEPALIVE_THRESHOLD - {"TCP_KEEPALIVE_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, 0, OPT_INT}, -#endif -#ifdef TCP_KEEPALIVE_ABORT_THRESHOLD - {"TCP_KEEPALIVE_ABORT_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, 0, OPT_INT}, -#endif - {NULL,0,0,0,0}}; - -/**************************************************************************** - Print socket options. -****************************************************************************/ - -static void print_socket_options(int s) -{ - int value; - socklen_t vlen = 4; - const smb_socket_option *p = &socket_options[0]; - - /* wrapped in if statement to prevent streams - * leak in SCO Openserver 5.0 */ - /* reported on samba-technical --jerry */ - if ( DEBUGLEVEL >= 5 ) { - DEBUG(5,("Socket options:\n")); - for (; p->name != NULL; p++) { - if (getsockopt(s, p->level, p->option, - (void *)&value, &vlen) == -1) { - DEBUGADD(5,("\tCould not test socket option %s.\n", - p->name)); - } else { - DEBUGADD(5,("\t%s = %d\n", - p->name,value)); - } - } - } - } - -/**************************************************************************** - Set user socket options. -****************************************************************************/ - -void set_socket_options(int fd, const char *options) -{ - TALLOC_CTX *ctx = talloc_new(NULL); - char *tok; - - while (next_token_talloc(ctx, &options, &tok," \t,")) { - int ret=0,i; - int value = 1; - char *p; - bool got_value = false; - - if ((p = strchr_m(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) { - /* be aware that some systems like Solaris return - * EINVAL to a setsockopt() call when the client - * sent a RST previously - no need to worry */ - DEBUG(2,("Failed to set socket option %s (Error %s)\n", - tok, strerror(errno) )); - } - } - - TALLOC_FREE(ctx); - print_socket_options(fd); -} - /* set some flags on a socket */ -- cgit From cdd802af8319e0b0744d8e727cef75526269ece2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 3 May 2011 10:40:33 +1000 Subject: s4-messaging Rename messaging -> imessaging This avoid symbol and structure conflicts between Samba3 and Samba4, and chooses a less generic name. Andrew Bartlett --- source4/lib/messaging/irpc.h | 14 +-- source4/lib/messaging/messaging.c | 156 ++++++++++++++++---------------- source4/lib/messaging/messaging.h | 20 ++-- source4/lib/messaging/pymessaging.c | 96 ++++++++++---------- source4/lib/messaging/tests/irpc.c | 10 +- source4/lib/messaging/tests/messaging.c | 34 +++---- 6 files changed, 165 insertions(+), 165 deletions(-) (limited to 'source4/lib') 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 48c9c16fb9..1b0fc1291c 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -36,13 +36,13 @@ #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,14 +99,14 @@ 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) { char *task_id = cluster_id_string(NULL, src); @@ -114,7 +114,7 @@ static void ping_message(struct messaging_context *msg, void *private_data, task_id, (int)data->length, data->data?(const char *)data->data:"")); talloc_free(task_id); - messaging_send(msg, src, MSG_PONG, data); + imessaging_send(msg, src, MSG_PONG, data); } /* @@ -123,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; } @@ -131,7 +131,7 @@ 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); @@ -151,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; @@ -178,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; @@ -200,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); } @@ -209,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; @@ -240,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); @@ -257,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)) { @@ -270,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, @@ -301,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; @@ -334,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; @@ -353,7 +353,7 @@ static void messaging_recv_handler(struct messaging_context *msg) return; } - messaging_dispatch(msg, rec); + imessaging_dispatch(msg, rec); talloc_free(rec); } @@ -361,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); } } @@ -378,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; @@ -411,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; @@ -437,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; @@ -462,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; } @@ -482,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; @@ -503,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) { @@ -516,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; } @@ -528,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; @@ -536,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]) { @@ -555,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; @@ -568,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; } @@ -584,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); @@ -619,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; @@ -634,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.pid = random() % 0x10000000; - return messaging_init(mem_ctx, dir, id, ev); + return imessaging_init(mem_ctx, dir, id, ev); } /* a list of registered irpc server functions @@ -659,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) { @@ -690,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; @@ -736,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: @@ -747,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; @@ -811,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; @@ -858,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); @@ -874,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; @@ -914,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) { @@ -959,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; @@ -1007,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; @@ -1139,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); @@ -1272,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) { @@ -1300,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) { diff --git a/source4/lib/messaging/messaging.h b/source4/lib/messaging/messaging.h index 4bc6d8c509..14a112f878 100644 --- a/source4/lib/messaging/messaging.h +++ b/source4/lib/messaging/messaging.h @@ -23,7 +23,7 @@ #include "librpc/gen_ndr/server_id4.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 a58176dc07..f295f42d5f 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -35,7 +35,7 @@ void initmessaging(void); -extern PyTypeObject messaging_Type; +extern PyTypeObject imessaging_Type; static bool server_id_from_py(PyObject *object, struct server_id *server_id) { @@ -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,7 +152,7 @@ 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) { @@ -163,9 +163,9 @@ static void py_msg_callback_wrapper(struct messaging_context *msg, void *private 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.pid, server_id.id2, 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"); -- cgit From b96389d3e17013fd22a64b6ce54478bd912d06b3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 3 May 2011 09:34:06 +1000 Subject: s4-socket: rename allow_access() to socket_allow_access() this prevents a symbol collision with s3 Pair-Programmed-With: Andrew Bartlett --- source4/lib/socket/access.c | 8 ++++---- source4/lib/socket/socket.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/lib') 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/socket.h b/source4/lib/socket/socket.h index 4a744797b3..88360ac8f3 100644 --- a/source4/lib/socket/socket.h +++ b/source4/lib/socket/socket.h @@ -179,9 +179,9 @@ _PUBLIC_ void socket_address_set_port(struct socket_address *a, 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); -- cgit From 14750139639b3531e57a3ca3f9e481d6e458dc06 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 4 May 2011 10:28:15 +1000 Subject: lib/util Move source3 tdb_wrap_open() into the common code. This #if _SAMBA_BUILD == 3 is very unfortunate, as it means that in the top level build, these options are not available for these databases. However, having two different tdb_wrap lists is a worse fate, so this will do for now. Andrew Bartlett --- source4/lib/messaging/messaging.c | 2 +- source4/lib/tdb_wrap.c | 117 -------------------------------------- source4/lib/tdb_wrap.h | 45 --------------- source4/lib/wscript_build | 9 --- 4 files changed, 1 insertion(+), 172 deletions(-) delete mode 100644 source4/lib/tdb_wrap.c delete mode 100644 source4/lib/tdb_wrap.h (limited to 'source4/lib') diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 1b0fc1291c..3a330d5794 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -27,7 +27,7 @@ #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 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 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 . -*/ - -#include "includes.h" -#include -#include "../lib/util/dlinklist.h" -#include "tdb_wrap.h" -#include - -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 . -*/ - -/* 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 - -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 - ) - -- cgit From ea0ac9cdfceae96b0e0be2531d9dea3b079bcd7f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 7 May 2011 08:14:06 +0200 Subject: s4-auth Rename auth -> auth4 to avoid conflict with s3 auth --- source4/lib/events/events.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib') 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 struct tevent_context *s4_event_context_init(TALLOC_CTX *mem_ctx); struct tevent_context *event_context_find(TALLOC_CTX *mem_ctx) _DEPRECATED_; -- cgit From 5a8b6ac4c0ea88bdab12349830985560c69cbf8c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 12:09:19 +1000 Subject: s4-lib merge get_interfaces() from Samba3 to Samba4 --- source4/lib/socket/interface.c | 244 ++++++++++++++++++++++++++++------------- source4/lib/socket/netif.c | 225 +++++++++++++++++++++++++++++++++---- source4/lib/socket/netif.h | 6 +- 3 files changed, 375 insertions(+), 100 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index c4411b623c..abeca8ba1e 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -25,11 +25,14 @@ #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; @@ -46,30 +49,45 @@ 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) + 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) { + 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_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; } @@ -79,26 +97,36 @@ 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(2,("added interface %s ip=%s ", + iface->name, addr)); + iface->ip_s = talloc_strdup(iface, addr); + + print_sockaddr(addr, sizeof(addr), + &iface->bcast); + DEBUG(2,("bcast=%s ", addr)); + iface->bcast_s = talloc_strdup(iface, addr); + + print_sockaddr(addr, sizeof(addr), + &iface->netmask); + DEBUG(2,("netmask=%s\n", addr)); + iface->nmask_s = talloc_strdup(iface, addr); + + DLIST_ADD(*interfaces, iface); } - - /** interpret a single element from a interfaces= config line @@ -116,77 +144,134 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, int total_probed, struct interface **local_interfaces) { - 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 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;iip_s; } @@ -315,10 +399,12 @@ const char *iface_best_ip(struct interface *ifaces, const char *dest) */ bool iface_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_find(ifaces, (const struct sockaddr *)&ss, true)) { return true; } return false; diff --git a/source4/lib/socket/netif.c b/source4/lib/socket/netif.c index e36f268bde..2846813d3f 100644 --- a/source4/lib/socket/netif.c +++ b/source4/lib/socket/netif.c @@ -36,6 +36,101 @@ #include "netif.h" #include "lib/util/tsort.h" +/**************************************************************************** + Create a struct sockaddr_storage with the netmask bits set to 1. +****************************************************************************/ + +bool make_netmask(struct sockaddr_storage *pss_out, + const struct sockaddr_storage *pss_in, + unsigned long masklen) +{ + *pss_out = *pss_in; + /* Now apply masklen bits of mask. */ +#if defined(HAVE_IPV6) + if (pss_in->ss_family == AF_INET6) { + char *p = (char *)&((struct sockaddr_in6 *)pss_out)->sin6_addr; + unsigned int i; + + if (masklen > 128) { + return false; + } + for (i = 0; masklen >= 8; masklen -= 8, i++) { + *p++ = 0xff; + } + /* Deal with the partial byte. */ + *p++ &= (0xff & ~(0xff>>masklen)); + i++; + for (;i < sizeof(struct in6_addr); i++) { + *p++ = '\0'; + } + return true; + } +#endif + if (pss_in->ss_family == AF_INET) { + if (masklen > 32) { + return false; + } + ((struct sockaddr_in *)pss_out)->sin_addr.s_addr = + htonl(((0xFFFFFFFFL >> masklen) ^ 0xFFFFFFFFL)); + return true; + } + return false; +} + +/**************************************************************************** + Create a struct sockaddr_storage set to the broadcast or network adress from + an incoming sockaddr_storage. +****************************************************************************/ + +static void make_bcast_or_net(struct sockaddr_storage *pss_out, + const struct sockaddr_storage *pss_in, + const struct sockaddr_storage *nmask, + bool make_bcast_p) +{ + unsigned int i = 0, len = 0; + char *pmask = NULL; + char *p = NULL; + *pss_out = *pss_in; + + /* Set all zero netmask bits to 1. */ +#if defined(HAVE_IPV6) + if (pss_in->ss_family == AF_INET6) { + p = (char *)&((struct sockaddr_in6 *)pss_out)->sin6_addr; + pmask = discard_const_p(char, &((struct sockaddr_in6 *)nmask)->sin6_addr); + len = 16; + } +#endif + if (pss_in->ss_family == AF_INET) { + p = (char *)&((struct sockaddr_in *)pss_out)->sin_addr; + pmask = discard_const_p(char, &((struct sockaddr_in *)nmask)->sin_addr); + len = 4; + } + + for (i = 0; i < len; i++, p++, pmask++) { + if (make_bcast_p) { + *p = (*p & *pmask) | (*pmask ^ 0xff); + } else { + /* make_net */ + *p = (*p & *pmask); + } + } +} + +void make_bcast(struct sockaddr_storage *pss_out, + const struct sockaddr_storage *pss_in, + const struct sockaddr_storage *nmask) +{ + make_bcast_or_net(pss_out, pss_in, nmask, true); +} + +void make_net(struct sockaddr_storage *pss_out, + const struct sockaddr_storage *pss_in, + const struct sockaddr_storage *nmask) +{ + make_bcast_or_net(pss_out, pss_in, nmask, false); +} + + /**************************************************************************** Try the "standard" getifaddrs/freeifaddrs interfaces. Also gets IPv6 interfaces. @@ -45,22 +140,38 @@ Get the netmask address for a local interface. ****************************************************************************/ -static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) +static int _get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces) { + struct iface_struct *ifaces; struct ifaddrs *iflist = NULL; struct ifaddrs *ifptr = NULL; + int count; int total = 0; + size_t copy_size; 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) { + count = 0; + for (ifptr = iflist; ifptr != NULL; ifptr = ifptr->ifa_next) { + if (!ifptr->ifa_addr || !ifptr->ifa_netmask) { + continue; + } + if (!(ifptr->ifa_flags & IFF_UP)) { + continue; + } + count += 1; + } - memset(&ifaces[total], '\0', sizeof(ifaces[total])); + ifaces = talloc_array(mem_ctx, struct iface_struct, count); + if (ifaces == NULL) { + errno = ENOMEM; + return -1; + } + + /* Loop through interfaces, looking for given IP address */ + for (ifptr = iflist; ifptr != NULL; ifptr = ifptr->ifa_next) { if (!ifptr->ifa_addr || !ifptr->ifa_netmask) { continue; @@ -71,13 +182,33 @@ static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) continue; } - /* We don't support IPv6 *yet* */ - if (ifptr->ifa_addr->sa_family != AF_INET) { - continue; + memset(&ifaces[total], '\0', sizeof(ifaces[total])); + + copy_size = sizeof(struct sockaddr_in); + + ifaces[total].flags = ifptr->ifa_flags; + +#if defined(HAVE_IPV6) + if (ifptr->ifa_addr->sa_family == AF_INET6) { + copy_size = sizeof(struct sockaddr_in6); } +#endif + + memcpy(&ifaces[total].ip, ifptr->ifa_addr, copy_size); + memcpy(&ifaces[total].netmask, ifptr->ifa_netmask, copy_size); - ifaces[total].ip = ((struct sockaddr_in *)ifptr->ifa_addr)->sin_addr; - ifaces[total].netmask = ((struct sockaddr_in *)ifptr->ifa_netmask)->sin_addr; + if (ifaces[total].flags & (IFF_BROADCAST|IFF_LOOPBACK)) { + make_bcast(&ifaces[total].bcast, + &ifaces[total].ip, + &ifaces[total].netmask); + } else if ((ifaces[total].flags & IFF_POINTOPOINT) && + ifptr->ifa_dstaddr ) { + memcpy(&ifaces[total].bcast, + ifptr->ifa_dstaddr, + copy_size); + } else { + continue; + } strlcpy(ifaces[total].name, ifptr->ifa_name, sizeof(ifaces[total].name)); @@ -86,27 +217,82 @@ static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) freeifaddrs(iflist); + *pifaces = ifaces; 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; + +#if defined(HAVE_IPV6) + /* + * If we have IPv6 - sort these interfaces lower + * than any IPv4 ones. + */ + if (i1->ip.ss_family == AF_INET6 && + i2->ip.ss_family == AF_INET) { + return -1; + } else if (i1->ip.ss_family == AF_INET && + i2->ip.ss_family == AF_INET6) { + return 1; + } + + if (i1->ip.ss_family == AF_INET6) { + struct sockaddr_in6 *s1 = (struct sockaddr_in6 *)&i1->ip; + struct sockaddr_in6 *s2 = (struct sockaddr_in6 *)&i2->ip; + + r = memcmp(&s1->sin6_addr, + &s2->sin6_addr, + sizeof(struct in6_addr)); + if (r) { + return r; + } + + s1 = (struct sockaddr_in6 *)&i1->netmask; + s2 = (struct sockaddr_in6 *)&i2->netmask; + + r = memcmp(&s1->sin6_addr, + &s2->sin6_addr, + sizeof(struct in6_addr)); + if (r) { + return r; + } + } +#endif + + /* AIX uses __ss_family instead of ss_family inside of + sockaddr_storage. Instead of trying to figure out which field to + use, we can just cast it to a sockaddr. + */ + + if (((struct sockaddr *)&i1->ip)->sa_family == AF_INET) { + struct sockaddr_in *s1 = (struct sockaddr_in *)&i1->ip; + struct sockaddr_in *s2 = (struct sockaddr_in *)&i2->ip; + + r = ntohl(s1->sin_addr.s_addr) - + ntohl(s2->sin_addr.s_addr); + if (r) { + return r; + } + + s1 = (struct sockaddr_in *)&i1->netmask; + s2 = (struct sockaddr_in *)&i2->netmask; + + return ntohl(s1->sin_addr.s_addr) - + ntohl(s2->sin_addr.s_addr); + } + return 0; } /* this wrapper is used to remove duplicates from the interface list generated above */ -int get_interfaces(struct iface_struct *ifaces, int max_interfaces) +int get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces) { + struct iface_struct *ifaces; int total, i, j; - total = _get_interfaces(ifaces, max_interfaces); + total = _get_interfaces(mem_ctx, &ifaces); if (total <= 0) return total; /* now we need to remove duplicates */ @@ -123,5 +309,6 @@ int get_interfaces(struct iface_struct *ifaces, int max_interfaces) } } + *pifaces = ifaces; return total; } diff --git a/source4/lib/socket/netif.h b/source4/lib/socket/netif.h index 417c6e074f..6a06c4bf15 100644 --- a/source4/lib/socket/netif.h +++ b/source4/lib/socket/netif.h @@ -23,8 +23,10 @@ struct iface_struct { char name[16]; - struct in_addr ip; - struct in_addr netmask; + int flags; + struct sockaddr_storage ip; + struct sockaddr_storage netmask; + struct sockaddr_storage bcast; }; struct interface; -- cgit From 879498b3622102630a5ade8d7d5421720f6fd7c6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 3 May 2011 19:41:41 +1000 Subject: s4-lib/socket Samba4 is not IPv6 compatible Don't add IPv6 interfaces until we actually support them. I'll soon have IPv6 service at home, and then I'll make it my buisness to sort this out once and for all. Andrew Bartlett --- source4/lib/socket/interface.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index abeca8ba1e..69b7ec1d49 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -91,6 +91,11 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s return; } + if (ifs->ip.ss_family != AF_INET) { + DEBUG(5, ("not adding IPv6 interface %s\n", ifs->name)); + return; + } + iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); if (iface == NULL) return; -- cgit From f346a737855bb5018978f0fcf1dcafbf5dc7e603 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 13:02:17 +1000 Subject: lib/socket move interfaces code to the top level --- source4/lib/socket/netif.c | 314 --------------------------------------- source4/lib/socket/netif.h | 16 +- source4/lib/socket/wscript_build | 10 +- 3 files changed, 6 insertions(+), 334 deletions(-) delete mode 100644 source4/lib/socket/netif.c (limited to 'source4/lib') diff --git a/source4/lib/socket/netif.c b/source4/lib/socket/netif.c deleted file mode 100644 index 2846813d3f..0000000000 --- a/source4/lib/socket/netif.c +++ /dev/null @@ -1,314 +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 . -*/ - - -/* 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" - -/**************************************************************************** - Create a struct sockaddr_storage with the netmask bits set to 1. -****************************************************************************/ - -bool make_netmask(struct sockaddr_storage *pss_out, - const struct sockaddr_storage *pss_in, - unsigned long masklen) -{ - *pss_out = *pss_in; - /* Now apply masklen bits of mask. */ -#if defined(HAVE_IPV6) - if (pss_in->ss_family == AF_INET6) { - char *p = (char *)&((struct sockaddr_in6 *)pss_out)->sin6_addr; - unsigned int i; - - if (masklen > 128) { - return false; - } - for (i = 0; masklen >= 8; masklen -= 8, i++) { - *p++ = 0xff; - } - /* Deal with the partial byte. */ - *p++ &= (0xff & ~(0xff>>masklen)); - i++; - for (;i < sizeof(struct in6_addr); i++) { - *p++ = '\0'; - } - return true; - } -#endif - if (pss_in->ss_family == AF_INET) { - if (masklen > 32) { - return false; - } - ((struct sockaddr_in *)pss_out)->sin_addr.s_addr = - htonl(((0xFFFFFFFFL >> masklen) ^ 0xFFFFFFFFL)); - return true; - } - return false; -} - -/**************************************************************************** - Create a struct sockaddr_storage set to the broadcast or network adress from - an incoming sockaddr_storage. -****************************************************************************/ - -static void make_bcast_or_net(struct sockaddr_storage *pss_out, - const struct sockaddr_storage *pss_in, - const struct sockaddr_storage *nmask, - bool make_bcast_p) -{ - unsigned int i = 0, len = 0; - char *pmask = NULL; - char *p = NULL; - *pss_out = *pss_in; - - /* Set all zero netmask bits to 1. */ -#if defined(HAVE_IPV6) - if (pss_in->ss_family == AF_INET6) { - p = (char *)&((struct sockaddr_in6 *)pss_out)->sin6_addr; - pmask = discard_const_p(char, &((struct sockaddr_in6 *)nmask)->sin6_addr); - len = 16; - } -#endif - if (pss_in->ss_family == AF_INET) { - p = (char *)&((struct sockaddr_in *)pss_out)->sin_addr; - pmask = discard_const_p(char, &((struct sockaddr_in *)nmask)->sin_addr); - len = 4; - } - - for (i = 0; i < len; i++, p++, pmask++) { - if (make_bcast_p) { - *p = (*p & *pmask) | (*pmask ^ 0xff); - } else { - /* make_net */ - *p = (*p & *pmask); - } - } -} - -void make_bcast(struct sockaddr_storage *pss_out, - const struct sockaddr_storage *pss_in, - const struct sockaddr_storage *nmask) -{ - make_bcast_or_net(pss_out, pss_in, nmask, true); -} - -void make_net(struct sockaddr_storage *pss_out, - const struct sockaddr_storage *pss_in, - const struct sockaddr_storage *nmask) -{ - make_bcast_or_net(pss_out, pss_in, nmask, false); -} - - -/**************************************************************************** - Try the "standard" getifaddrs/freeifaddrs interfaces. - Also gets IPv6 interfaces. -****************************************************************************/ - -/**************************************************************************** - Get the netmask address for a local interface. -****************************************************************************/ - -static int _get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces) -{ - struct iface_struct *ifaces; - struct ifaddrs *iflist = NULL; - struct ifaddrs *ifptr = NULL; - int count; - int total = 0; - size_t copy_size; - - if (getifaddrs(&iflist) < 0) { - return -1; - } - - count = 0; - for (ifptr = iflist; ifptr != NULL; ifptr = ifptr->ifa_next) { - if (!ifptr->ifa_addr || !ifptr->ifa_netmask) { - continue; - } - if (!(ifptr->ifa_flags & IFF_UP)) { - continue; - } - count += 1; - } - - ifaces = talloc_array(mem_ctx, struct iface_struct, count); - if (ifaces == NULL) { - errno = ENOMEM; - return -1; - } - - /* Loop through interfaces, looking for given IP address */ - for (ifptr = iflist; ifptr != NULL; ifptr = ifptr->ifa_next) { - - if (!ifptr->ifa_addr || !ifptr->ifa_netmask) { - continue; - } - - /* Check the interface is up. */ - if (!(ifptr->ifa_flags & IFF_UP)) { - continue; - } - - memset(&ifaces[total], '\0', sizeof(ifaces[total])); - - copy_size = sizeof(struct sockaddr_in); - - ifaces[total].flags = ifptr->ifa_flags; - -#if defined(HAVE_IPV6) - if (ifptr->ifa_addr->sa_family == AF_INET6) { - copy_size = sizeof(struct sockaddr_in6); - } -#endif - - memcpy(&ifaces[total].ip, ifptr->ifa_addr, copy_size); - memcpy(&ifaces[total].netmask, ifptr->ifa_netmask, copy_size); - - if (ifaces[total].flags & (IFF_BROADCAST|IFF_LOOPBACK)) { - make_bcast(&ifaces[total].bcast, - &ifaces[total].ip, - &ifaces[total].netmask); - } else if ((ifaces[total].flags & IFF_POINTOPOINT) && - ifptr->ifa_dstaddr ) { - memcpy(&ifaces[total].bcast, - ifptr->ifa_dstaddr, - copy_size); - } else { - continue; - } - - strlcpy(ifaces[total].name, ifptr->ifa_name, - sizeof(ifaces[total].name)); - total++; - } - - freeifaddrs(iflist); - - *pifaces = ifaces; - return total; -} - -static int iface_comp(struct iface_struct *i1, struct iface_struct *i2) -{ - int r; - -#if defined(HAVE_IPV6) - /* - * If we have IPv6 - sort these interfaces lower - * than any IPv4 ones. - */ - if (i1->ip.ss_family == AF_INET6 && - i2->ip.ss_family == AF_INET) { - return -1; - } else if (i1->ip.ss_family == AF_INET && - i2->ip.ss_family == AF_INET6) { - return 1; - } - - if (i1->ip.ss_family == AF_INET6) { - struct sockaddr_in6 *s1 = (struct sockaddr_in6 *)&i1->ip; - struct sockaddr_in6 *s2 = (struct sockaddr_in6 *)&i2->ip; - - r = memcmp(&s1->sin6_addr, - &s2->sin6_addr, - sizeof(struct in6_addr)); - if (r) { - return r; - } - - s1 = (struct sockaddr_in6 *)&i1->netmask; - s2 = (struct sockaddr_in6 *)&i2->netmask; - - r = memcmp(&s1->sin6_addr, - &s2->sin6_addr, - sizeof(struct in6_addr)); - if (r) { - return r; - } - } -#endif - - /* AIX uses __ss_family instead of ss_family inside of - sockaddr_storage. Instead of trying to figure out which field to - use, we can just cast it to a sockaddr. - */ - - if (((struct sockaddr *)&i1->ip)->sa_family == AF_INET) { - struct sockaddr_in *s1 = (struct sockaddr_in *)&i1->ip; - struct sockaddr_in *s2 = (struct sockaddr_in *)&i2->ip; - - r = ntohl(s1->sin_addr.s_addr) - - ntohl(s2->sin_addr.s_addr); - if (r) { - return r; - } - - s1 = (struct sockaddr_in *)&i1->netmask; - s2 = (struct sockaddr_in *)&i2->netmask; - - return ntohl(s1->sin_addr.s_addr) - - ntohl(s2->sin_addr.s_addr); - } - return 0; -} - -/* this wrapper is used to remove duplicates from the interface list generated - above */ -int get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces) -{ - struct iface_struct *ifaces; - int total, i, j; - - total = _get_interfaces(mem_ctx, &ifaces); - if (total <= 0) return total; - - /* now we need to remove duplicates */ - TYPESAFE_QSORT(ifaces, total, iface_comp); - - for (i=1;i Date: Mon, 2 May 2011 15:57:19 +1000 Subject: s4-interfaces Rename interfaces code so not to conflict with source3/ The iface_count, iface_n_bcast, and load_interfaces functions conflicted with functions of the same name in source3, so the source4 functions were renamed. Hopefully we can actually wrap one around the other in future. Andrew Bartlett --- source4/lib/socket/interface.c | 32 ++++++++++++++++---------------- source4/lib/socket/testsuite.c | 14 +++++++------- 2 files changed, 23 insertions(+), 23 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 69b7ec1d49..4eb4f3a517 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -48,9 +48,9 @@ struct interface { /**************************************************************************** Try and find an interface that matches an ip. If we cannot, return NULL **************************************************************************/ -static struct interface *iface_find(struct interface *interfaces, - const struct sockaddr *ip, - bool check_mask) +static struct interface *iface_list_find(struct interface *interfaces, + const struct sockaddr *ip, + bool check_mask) { struct interface *i; @@ -79,7 +79,7 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s char addr[INET6_ADDRSTRLEN]; struct interface *iface; - if (iface_find(*interfaces, (const struct sockaddr *)&ifs->ip, false)) { + 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; @@ -283,7 +283,7 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, /** 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, const char **interfaces, struct interface **local_interfaces) { const char **ptr = interfaces; int i; @@ -322,7 +322,7 @@ void load_interfaces(TALLOC_CTX *mem_ctx, const char **interfaces, struct interf /** 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; @@ -335,7 +335,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; @@ -351,7 +351,7 @@ const char *iface_n_ip(struct interface *ifaces, int n) /** 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; @@ -367,7 +367,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; @@ -384,32 +384,32 @@ 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 sockaddr_storage ss; if (!interpret_string_addr(&ss, dest, AI_NUMERICHOST)) { - return iface_n_ip(ifaces, 0); + return iface_list_n_ip(ifaces, 0); } - iface = iface_find(ifaces, (const struct sockaddr *)&ss, true); + iface = iface_list_find(ifaces, (const struct sockaddr *)&ss, true); if (iface) { return iface->ip_s; } - return iface_n_ip(ifaces, 0); + return iface_list_n_ip(ifaces, 0); } /** 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 sockaddr_storage ss; if (!interpret_string_addr(&ss, dest, AI_NUMERICHOST)) { return false; } - if (iface_find(ifaces, (const struct sockaddr *)&ss, true)) { + if (iface_list_find(ifaces, (const struct sockaddr *)&ss, true)) { return true; } return false; @@ -418,7 +418,7 @@ 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), diff --git a/source4/lib/socket/testsuite.c b/source4/lib/socket/testsuite.c index 2489277433..518bc72501 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, lpcfg_interfaces(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, lpcfg_interfaces(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); -- cgit From c596d85afd41c2512ef77a10a9d6b40f4836c386 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 8 May 2011 12:55:41 +0200 Subject: s4-interfaces: keep interfaces in the order they were declared the spoolss notify test depends on the interfaces order Pair-Programmed-With: Andrew Bartlett Autobuild-User: Andrew Tridgell Autobuild-Date: Sun May 8 13:57:58 CEST 2011 on sn-devel-104 --- source4/lib/socket/interface.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 4eb4f3a517..b762f5573a 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -129,7 +129,11 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s DEBUG(2,("netmask=%s\n", addr)); iface->nmask_s = talloc_strdup(iface, addr); - DLIST_ADD(*interfaces, iface); + /* + 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); } /** -- cgit From 30979f3ea1df7f81c44fb1d8b6a1a61777c8c72d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 14 May 2011 19:55:57 +0200 Subject: build: Expand dcerpc-samba grouping library This is possible in common now because the generated RPC code does not rely on a particular dcerpc layer. Andrew Bartlett --- source4/lib/registry/wscript_build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib') 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' ) -- cgit From e6c5e11116afb8e6f5c16267c62e90084ac7d4da Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Wed, 11 May 2011 14:25:11 +0200 Subject: ldb:ldbtest.c - make more use of LDB constants Signed-off-by: Metze --- source4/lib/ldb/tools/ldbtest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c index 5270357bad..47b78364fa 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); } @@ -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); } -- cgit From 3956e6840d1619519bf9848574baf60efa926b42 Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Sun, 10 Apr 2011 19:44:53 +0200 Subject: ldb:tools/cmdline.c + tools/ldbtest.c - the connection flags are typed as "unsigned" Signed-off-by: Metze --- source4/lib/ldb/tools/cmdline.c | 2 +- source4/lib/ldb/tools/ldbtest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c index c2599414b0..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; diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c index 47b78364fa..4e181af9d5 100644 --- a/source4/lib/ldb/tools/ldbtest.c +++ b/source4/lib/ldb/tools/ldbtest.c @@ -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"); -- cgit From 74b50b47e962ae7a7e90b054f4bab7527397b7de Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Wed, 13 Apr 2011 09:05:34 +0200 Subject: ldb:ldb_sqlite3.c - all LDB flags should be handled as "unsigned" Signed-off-by: Metze --- source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/lib') 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; -- cgit From 4618a7f3a188e938070e1aa70a9209cdc8045f81 Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Sun, 10 Apr 2011 19:48:07 +0200 Subject: ldb:pyldb.c - all flags should be unsigned Adapt it to the previous commits Reviewed-by: Jelmer + Metze --- source4/lib/ldb/pyldb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 5fcc5a64b6..68f909858d 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -48,7 +48,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 */ @@ -737,11 +737,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 +792,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; @@ -2031,7 +2031,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 +2122,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 +2192,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; -- cgit From d34205add33c028dfd8ca1f8c364013b71f5b3a1 Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Sun, 10 Apr 2011 19:54:31 +0200 Subject: s4:ldb-samba/ldb_wrap.*-dsdb/samdb/samdb.c - handle LDB connection flags as unsigned The LDB API ("ldb_connect") prescribes that they should be "unsigned". Signed-off-by: Metze --- source4/lib/ldb-samba/ldb_wrap.c | 6 +++--- source4/lib/ldb-samba/ldb_wrap.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb-samba/ldb_wrap.c b/source4/lib/ldb-samba/ldb_wrap.c index 6d92f60d62..f7d562377a 100644 --- a/source4/lib/ldb-samba/ldb_wrap.c +++ b/source4/lib/ldb-samba/ldb_wrap.c @@ -177,7 +177,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 +195,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; @@ -230,7 +230,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_ */ -- cgit From 0204ae6229bae3573b3194c3f657c8f385c0b940 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 1 Jun 2011 11:24:51 +0930 Subject: lib/util/time.c: timeval_current_ofs_usec Several places want "microseconds from current time", and several were simply handing "usecs" values which could be over a million. Using a helper to do this is safer and more readable. I didn't replace any obviously correct callers (ie. constants). I also renamed wait_nsec in source3/lib/util_sock.c; it's actually microseconds not nanoseconds (introduced with this code in Volker's 19b783cc Async wrapper for open_socket_out_send/recv). Signed-off-by: Rusty Russell --- source4/lib/socket/connect_multi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c index 300e5fb1e5..e3b58456c4 100644 --- a/source4/lib/socket/connect_multi.c +++ b/source4/lib/socket/connect_multi.c @@ -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); } } -- cgit From 2fc11518b7573bce3cdf2f2acf7dec024f22e9c6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 May 2011 12:23:35 +0200 Subject: s4-ipv6: added iface_list_wildcard() this returns a list of wildcard address to listen on, when we don't have 'bind interfaces only' set. It is a list, not a single address, we need to listen separately for the IPv6 "::" address from the IPv4 0.0.0.0 address. This also takes account of the loadparm "socket address" option --- source4/lib/socket/interface.c | 28 ++++++++++++++++++++++++++++ source4/lib/socket/wscript_build | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index b762f5573a..83d8e4c129 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -21,6 +21,7 @@ #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" @@ -428,3 +429,30 @@ bool iface_list_same_net(const char *ip1, const char *ip2, const char *netmask) interpret_addr2(ip2), interpret_addr2(netmask)); } + +/** + 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 + return str_list_add(ret, "::"); +#endif + + return ret; +} diff --git a/source4/lib/socket/wscript_build b/source4/lib/socket/wscript_build index fa497335fb..c10970d17a 100644 --- a/source4/lib/socket/wscript_build +++ b/source4/lib/socket/wscript_build @@ -2,7 +2,7 @@ bld.SAMBA_LIBRARY('netif', source='interface.c', - deps='samba-util interfaces', + deps='samba-util interfaces samba-hostconfig', private_library=True, autoproto='netif_proto.h' ) -- cgit From 62af4a3798995b0368625c0322bc9d5373bb0348 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 May 2011 12:26:18 +0200 Subject: s4-ipv6: allow IPv6 addresses in our interfaces list --- source4/lib/socket/interface.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 83d8e4c129..9ae658da3e 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -92,11 +92,6 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s return; } - if (ifs->ip.ss_family != AF_INET) { - DEBUG(5, ("not adding IPv6 interface %s\n", ifs->name)); - return; - } - iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); if (iface == NULL) return; -- cgit From a527b96c968037db2d699493a9017709d053f95a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 May 2011 12:27:01 +0200 Subject: s4-ipv6: fixed a warning --- source4/lib/socket/interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 9ae658da3e..0de44c1517 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -302,7 +302,7 @@ void load_interface_list(TALLOC_CTX *mem_ctx, const char **interfaces, struct in DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n")); } for (i=0;i Date: Thu, 12 May 2011 12:27:37 +0200 Subject: s4-ipv6: added ipv4 functions to interface code this adds iface_list_first_v4() and iface_list_n_is_v4(). The NBT server will use these to allow it to listen only for IPv4 addresses. --- source4/lib/socket/interface.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 0de44c1517..3737f57f9b 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -348,6 +348,38 @@ const char *iface_list_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; +} + +/** + 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 **/ -- cgit From 244137b10d511dedb1798b90aa2f4c354c50a44e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 May 2011 12:29:21 +0200 Subject: s4-ipv6: added socket_address_from_sockaddr_storage() this converts a struct sockaddr_storage to a struct socket_address --- source4/lib/socket/socket.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ source4/lib/socket/socket.h | 4 ++++ 2 files changed, 48 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c index cecd1026d5..41638b3d72 100644 --- a/source4/lib/socket/socket.c +++ b/source4/lib/socket/socket.c @@ -510,6 +510,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) diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h index 88360ac8f3..e00b61ba6c 100644 --- a/source4/lib/socket/socket.h +++ b/source4/lib/socket/socket.h @@ -174,6 +174,10 @@ 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, -- cgit From df632483f18923430a6da595d07c9f241438e766 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 May 2011 12:30:16 +0200 Subject: s4-ipv6: fixed ipv6_listen() to use IPV6_V6ONLY this changes ipv6_listen() to use IPV6_V6ONLY, and to setup the right scope id for link local IPv6 addresses --- source4/lib/socket/socket_ip.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c index 4e66653252..bf0aff74ec 100644 --- a/source4/lib/socket/socket_ip.c +++ b/source4/lib/socket/socket_ip.c @@ -667,9 +667,22 @@ static NTSTATUS ipv6_tcp_connect(struct socket_context *sock, 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,14 +693,21 @@ 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) { -- cgit From 44d47e85157209f5aec1a6e0cd507c1084716816 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Jun 2011 15:39:54 +1000 Subject: s4-ipv6: allow ipv6 to be enabled/disabled in smb.conf this adds the parametric option ipv6:enable=true/false It defaults to false for now, until the remaining issues with testing of ipv6 are resolved --- source4/lib/socket/interface.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 3737f57f9b..00550a9ed4 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -75,7 +75,8 @@ static struct interface *iface_list_find(struct interface *interfaces, /**************************************************************************** add an interface to the linked list of interfaces ****************************************************************************/ -static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, 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; @@ -92,6 +93,10 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s return; } + if (!enable_ipv6 && ifs->ip.ss_family != AF_INET) { + return; + } + iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); if (iface == NULL) return; @@ -147,7 +152,8 @@ 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 sockaddr_storage ss; struct sockaddr_storage ss_mask; @@ -163,7 +169,7 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, for (i=0;i Date: Thu, 2 Jun 2011 15:40:28 +1000 Subject: s4-ipv6: update callers to load_interface_list() --- source4/lib/socket/testsuite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/testsuite.c b/source4/lib/socket/testsuite.c index 518bc72501..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_interface_list(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"); @@ -135,7 +135,7 @@ 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_interface_list(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_list_best_ip(ifaces, "127.0.0.1"), 0); torture_assert(tctx, localhost, "Localhost not found"); -- cgit From dc1e6109c8bcc21831defd443fcf42427706c642 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 4 Jun 2011 07:59:54 +1000 Subject: s4-ipv6: enable IPv6 by default it now passes all tests --- source4/lib/socket/interface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 00550a9ed4..96cee2fbe6 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -295,7 +295,7 @@ void load_interface_list(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, s int i; struct iface_struct *ifaces; int total_probed; - bool enable_ipv6 = lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", false); + bool enable_ipv6 = lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", true); *local_interfaces = NULL; @@ -485,7 +485,7 @@ const char **iface_list_wildcard(TALLOC_CTX *mem_ctx, struct loadparm_context *l if (ret == NULL) return NULL; #ifdef HAVE_IPV6 - if (lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", false)) { + if (lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", true)) { return str_list_add(ret, "::"); } #endif -- cgit From 3736f29696288f908aac4189aedfc7149c431caa Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Jun 2011 10:11:53 +1000 Subject: s4-ipv6: use the server address family don't force v4 in connect_multi --- source4/lib/socket/connect_multi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c index e3b58456c4..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); -- cgit From 25ac58dccef5d1da9946aeb191d6b6c4ee8782cf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Jun 2011 10:42:28 +1000 Subject: s4-ipv6: fix the address family for IPv6 string addresses --- source4/lib/socket/socket.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c index 41638b3d72..369cf5ff36 100644 --- a/source4/lib/socket/socket.c +++ b/source4/lib/socket/socket.c @@ -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) { -- cgit From d168a5e703288a5fba3f35a6e44d3f5d5733e6c5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Jun 2011 11:31:23 +1000 Subject: s4-ipv6: fill in family when initialising from sockaddr Autobuild-User: Andrew Tridgell Autobuild-Date: Mon Jun 6 05:35:36 CEST 2011 on sn-devel-104 --- source4/lib/socket/socket.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c index 369cf5ff36..b16e38c372 100644 --- a/source4/lib/socket/socket.c +++ b/source4/lib/socket/socket.c @@ -503,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); -- cgit From de46ad9084aff4384f33660acf91da3b81554a88 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 6 Jun 2011 14:37:06 +1000 Subject: lib/util use modules_path(), data_path() and shlib_ext() from source3 This brings these helpful utility functions in common, as they are not based on either loadparm system. (The 'modules dir' parameter from Samba4 will shortly be removed, so there is no loss in functionality) Andrew Bartlett --- source4/lib/ldb-samba/ldb_wrap.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb-samba/ldb_wrap.c b/source4/lib/ldb-samba/ldb_wrap.c index f7d562377a..d713dfffbf 100644 --- a/source4/lib/ldb-samba/ldb_wrap.c +++ b/source4/lib/ldb-samba/ldb_wrap.c @@ -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); -- cgit From 907cdb5de7f16a2540299aeba211bf2a5ae6fafe Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 6 Jun 2011 14:58:28 +1000 Subject: s4-modules Remove lp_ctx from init functions that no longer need it Now that we don't allow the smb.conf to change the modules dir, many functions that simply load modules or initialise a subsytem that may load modules no longer need an lp_ctx. Andrew Bartlett --- source4/lib/ldb-samba/samba_extensions.c | 2 +- source4/lib/registry/rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib') 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/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); -- cgit From 6a6d4d8884788c1e860bda886d168301623e1ea3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Jun 2011 15:18:12 +1000 Subject: s4-ipv6: fix iface_list_best_ip() for IPv6 return an interface with the same address family as the target --- source4/lib/socket/interface.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 96cee2fbe6..1bf1e4f62b 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -371,6 +371,23 @@ const char *iface_list_first_v4(struct interface *ifaces) 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 **/ @@ -435,7 +452,12 @@ const char *iface_list_best_ip(struct interface *ifaces, const char *dest) if (iface) { return iface->ip_s; } - return iface_list_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); } /** -- cgit From 3ccb72d7496aadbdf35b0aee3b2384466d9dd3b8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 7 Jun 2011 12:55:09 +1000 Subject: s4-ipv6: fixed iface_list_same_net() for IPv6 --- source4/lib/socket/interface.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 1bf1e4f62b..9cb8f5e611 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -481,9 +481,21 @@ bool iface_list_is_local(struct interface *ifaces, const char *dest) */ 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); } /** -- cgit From 79ef434b900288f23f352dcce083c37308baef2d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 8 Jun 2011 10:41:38 +1000 Subject: s4-interface: raise the debug level for interface discovery --- source4/lib/socket/interface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 9cb8f5e611..d5b610fea7 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -116,18 +116,18 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s /* keep string versions too, to avoid people tripping over the implied static in inet_ntoa() */ print_sockaddr(addr, sizeof(addr), &iface->ip); - DEBUG(2,("added interface %s ip=%s ", + 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(2,("bcast=%s ", addr)); + DEBUG(4,("bcast=%s ", addr)); iface->bcast_s = talloc_strdup(iface, addr); print_sockaddr(addr, sizeof(addr), &iface->netmask); - DEBUG(2,("netmask=%s\n", addr)); + DEBUG(4,("netmask=%s\n", addr)); iface->nmask_s = talloc_strdup(iface, addr); /* -- cgit From ba5cec58049fd9ca8cb9d0d1706ed2e34328335f Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Thu, 26 May 2011 09:25:16 +0200 Subject: ldb:ldb_msg.c - move away from "errno" Reviewed-by: Tridge --- source4/lib/ldb/common/ldb_msg.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source4/lib') 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; -- cgit From 8d803d5a0a9a7815c4e6fcbd9b7c652fb85e94dd Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 8 May 2011 18:28:17 +0200 Subject: s4-cluster Use task_id instead of id2 to clarify server_id structure This seems a clearer and more acceptable name. Andrew Bartlett Signed-off-by: Andrew Tridgell --- source4/lib/messaging/pymessaging.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index f295f42d5f..63312da5d0 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -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->pid, &server_id->id2, &server_id->vnn); + return PyArg_ParseTuple(object, "iii", &server_id->pid, &server_id->task_id, &server_id->vnn); } else { - int pid, id2; - if (!PyArg_ParseTuple(object, "ii", &pid, &id2)) + int pid, task_id; + if (!PyArg_ParseTuple(object, "ii", &pid, &task_id)) return false; - *server_id = cluster_id(pid, id2); + *server_id = cluster_id(pid, task_id); return true; } } @@ -159,7 +159,7 @@ static void py_msg_callback_wrapper(struct imessaging_context *msg, void *privat PyObject *callback = (PyObject *)private_data; PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type, - server_id.pid, server_id.id2, server_id.vnn, + server_id.pid, server_id.task_id, server_id.vnn, data->data, data->length); } @@ -229,7 +229,7 @@ static PyObject *py_imessaging_server_id(PyObject *obj, void *closure) imessaging_Object *iface = (imessaging_Object *)obj; struct server_id server_id = imessaging_get_server_id(iface->msg_ctx); - return Py_BuildValue("(iii)", server_id.pid, server_id.id2, + return Py_BuildValue("(iii)", server_id.pid, server_id.task_id, server_id.vnn); } -- cgit From d057116cc2e454ba097d0dcb22e16108a05a4a1b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 10:55:20 +1000 Subject: server_id.idl: Bring server_id.idl in common Andrew Bartlett Signed-off-by: Andrew Tridgell --- source4/lib/messaging/messaging.h | 2 +- source4/lib/messaging/pymessaging.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/messaging/messaging.h b/source4/lib/messaging/messaging.h index 14a112f878..eb8a8abc79 100644 --- a/source4/lib/messaging/messaging.h +++ b/source4/lib/messaging/messaging.h @@ -21,7 +21,7 @@ #ifndef _MESSAGES_H_ #define _MESSAGES_H_ -#include "librpc/gen_ndr/server_id4.h" +#include "librpc/gen_ndr/server_id.h" struct imessaging_context; diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index 63312da5d0..cafd45beae 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -31,7 +31,7 @@ #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); -- cgit From 16b1c77644217796f70a3a0bf1d95c245f9ee2d9 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 8 Jun 2011 14:05:55 +1000 Subject: lib/util Bring procid_str() into lib/util as server_id_string() This is needed for OpenChange, which prints Samba struct server_id values in debug messages. Andrew Bartlett --- source4/lib/messaging/messaging.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 3a330d5794..aa1b43308f 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -109,7 +109,7 @@ static void irpc_handler(struct imessaging_context *, void *, static void ping_message(struct imessaging_context *msg, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data) { - char *task_id = cluster_id_string(NULL, src); + 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:"")); @@ -134,7 +134,7 @@ static NTSTATUS irpc_uptime(struct irpc_message *msg, 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; @@ -284,8 +284,8 @@ static void imessaging_send_handler(struct imessaging_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); -- cgit From 8741f039955853c092c45cc7f2cedca2384b4c57 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 14 Jun 2011 16:39:49 +1000 Subject: pyldb: added validate option to ldb.modify() This allows validation of ldb messages in a ldb modify operation to be bypassed, by setting validate=False. This is useful in the dbcheck tool to allow for removing invalid empty attributes from the database --- source4/lib/ldb/pyldb.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 68f909858d..58a63950b1 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -819,7 +819,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 +829,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 +859,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, @@ -1586,8 +1592,8 @@ 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" -- cgit From 23202211050b3b3d41632d2bf2795249644d7e8a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 14 Jun 2011 16:41:35 +1000 Subject: pyldb: make ldb operations more consistent This changes the controls option on ldb operations to be a keyword argument, which is more consistent with general python conventions. This also fixes the pydoc output to include the controls option. --- source4/lib/ldb/pyldb.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 58a63950b1..61662f6763 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -964,7 +964,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; @@ -974,8 +974,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); @@ -1053,7 +1056,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; @@ -1063,8 +1066,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); @@ -1125,7 +1131,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; @@ -1136,10 +1142,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; @@ -1595,14 +1604,14 @@ static PyMethodDef py_ldb_methods[] = { { "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" -- cgit From 02970f41a27bd4614d6aedf0fe337619b34310db Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Sat, 11 Jun 2011 16:57:02 +0400 Subject: py-ldb: allow dictionnary like usage (ie. e.get("myattribute", defVal) --- source4/lib/ldb/pyldb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 61662f6763..b568bc2ccd 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -2442,15 +2442,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; } -- cgit From 018f4a5889743f742a59e9ad72056b2ea09adfe9 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 20 Jun 2011 14:03:26 +1000 Subject: libcli/util Bring samba4 unix -> nt_status code in common. Due to library link orders, this is already the function that is being used. However we still need to sort out the duplicate symbol issues, probably by renaming things. Andrew Bartlett --- source4/lib/ldb-samba/wscript_build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb-samba/wscript_build b/source4/lib/ldb-samba/wscript_build index a8d4df2ce0..e6a13f3933 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 pyldb-util errors', private_library=True ) -- cgit From a1f04e8abc761ef1ba211420ff1dbda50fcf527d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 20 Jun 2011 14:55:32 +1000 Subject: libcli/util Rename common map_nt_error_from_unix to avoid duplicate symbol The two error tables need to be combined, but for now seperate the names. (As the common parts of the tree now use the _common function, errmap_unix.c must be included in the s3 autoconf build). Andrew Bartlett Autobuild-User: Andrew Bartlett Autobuild-Date: Mon Jun 20 08:12:03 CEST 2011 on sn-devel-104 --- source4/lib/socket/socket.c | 2 +- source4/lib/socket/socket_ip.c | 58 ++++++++++++++++++++-------------------- source4/lib/socket/socket_unix.c | 16 +++++------ 3 files changed, 38 insertions(+), 38 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c index b16e38c372..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; diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c index bf0aff74ec..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,7 +661,7 @@ 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); @@ -711,20 +711,20 @@ static NTSTATUS ipv6_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); } } @@ -745,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); } } @@ -816,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; @@ -867,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 = { -- cgit From 29e043a2080143ea8ed19e5aa7880690b4ec4644 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Sat, 11 Jun 2011 18:09:40 +0400 Subject: pyldb: add unit test for get(myattribute, defVal) Autobuild-User: Matthieu Patou Autobuild-Date: Mon Jun 20 09:23:15 CEST 2011 on sn-devel-104 --- source4/lib/ldb/tests/python/api.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib') 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")) -- cgit From 0e4c358e2710580d5aeb439d767c87aaf4c0f2f3 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:25 +0930 Subject: tdb_compat.h: divert every tdb build and includes to tdb_compat We change all the headers and wscript files to use tdb_compat; this means we have one place to decide whether to use TDB1 or TDB2. Signed-off-by: Rusty Russell --- source4/lib/ldb-samba/ldb_wrap.c | 2 +- source4/lib/ldb-samba/wscript_build | 2 +- source4/lib/ldb/ldb_tdb/ldb_tdb.h | 2 +- source4/lib/ldb/wscript | 17 +++++++++++------ source4/lib/messaging/messaging.c | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb-samba/ldb_wrap.c b/source4/lib/ldb-samba/ldb_wrap.c index d713dfffbf..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 +#include "../lib/tdb_compat/tdb_compat.h" /* this is used to catch debug messages from ldb diff --git a/source4/lib/ldb-samba/wscript_build b/source4/lib/ldb-samba/wscript_build index e6a13f3933..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 errors', + 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/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index 3d793d27df..82127a1f56 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 diff --git a/source4/lib/ldb/wscript b/source4/lib/ldb/wscript index b59e782e45..393f99f630 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/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 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/messaging.c b/source4/lib/messaging/messaging.c index aa1b43308f..13fc188155 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -30,7 +30,7 @@ #include "lib/util/tdb_wrap.h" #include "../lib/util/unix_privs.h" #include "librpc/rpc/dcerpc.h" -#include +#include "../lib/tdb_compat/tdb_compat.h" #include "../lib/util/util_tdb.h" #include "cluster/cluster.h" #include "../lib/util/tevent_ntstatus.h" -- cgit From 058c4f84924c07b88ccaf3d617f3abff797a7cc8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_fetch_compat: use instead of tdb_fetch. This is a noop for tdb1. Signed-off-by: Rusty Russell --- source4/lib/ldb/ldb_tdb/ldb_index.c | 4 ++-- source4/lib/ldb/ldb_tdb/ldb_search.c | 5 +++-- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 02e4acbbde..45e747379f 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; } @@ -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) { diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index a49751de15..30364897d9 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 /* 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; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 2f7f222086..77a75a4504 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 /* @@ -653,7 +654,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)); -- cgit From 6bc59d77b64d1ecbe5c906ed2fa80a7b8ca5d420 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_store: check returns for 0, not -1. TDB2 returns a negative error number on failure. This is compatible if we always check for != 0 instead of == -1. Signed-off-by: Rusty Russell --- source4/lib/ldb/ldb_tdb/ldb_index.c | 2 +- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 45e747379f..0e9f1e75dd 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -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; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 77a75a4504..436ef46b33 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -264,7 +264,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; } -- cgit From d6251996fa5b8371c0f7449825b5d1788da95dd0 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_transaction_cancel: ignore return value. TDB2 returns void here. tdb_transaction_cancel will *always* return with the transaction cancelled, but it will complain via the log function if a transaction wasn't in progress. Signed-off-by: Rusty Russell --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 436ef46b33..77b4b24a2e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1073,10 +1073,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; } -- cgit From 5a7874e119acbc80410b2f2c1847371236c22a56 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_traverse/tdb_traverse_read: check returns for negative, not -1. TDB2 returns a negative error number on failure. This is compatible if we always check for < 0 instead of == -1. Also, there's no tdb_traverse_read in TDB2: we don't try to make traverse reliable any more, so there are no write locks anyway. Signed-off-by: Rusty Russell --- source4/lib/ldb/ldb_tdb/ldb_index.c | 4 ++-- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 0e9f1e75dd..45c36f09c9 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -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_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 30364897d9..46e2d74998 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -480,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; } -- cgit From 2c71e8596b295e7080eb936db705f452e1d7b9d9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:32 +0930 Subject: tdb_unlockall/tdb_unlockall_read: ignore return value. TDB2 returns void here. tdb_unlockall will *always* return with the database unlocked, but it will complain via the log function if it wasn't locked. Signed-off-by: Rusty Russell --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 77b4b24a2e..16e556d78d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -111,7 +111,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; -- cgit From a4993f647cfc5b8e0cf4405cc1d8815770837310 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:32 +0930 Subject: ldb: replace 'struct TDB_DATA' with 'TDB_DATA' The typedef is TDB2 compatible, the struct isn't. Signed-off-by: Rusty Russell --- source4/lib/ldb/ldb_tdb/ldb_pack.c | 4 ++-- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- source4/lib/ldb/ldb_tdb/ldb_tdb.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib') 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_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 16e556d78d..6033f84ef3 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -126,7 +126,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; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index 82127a1f56..96ad43fbd6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -102,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 */ @@ -127,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); -- cgit From 4823262439bc6c1ce9fcce97ed472ad44e85cb77 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:32 +0930 Subject: tdb2: #ifdef out TDB_ERR_NOLOCK and TDB_ERR_LOCK_TIMEOUT. These don't exist in tdb2. The former is used in one weird place in tdb1, and the latter not at all. Signed-off-by: Rusty Russell --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 6033f84ef3..0d4be49123 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -68,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; -- cgit From ca1936fbb26af0ee8d0421ae6a4e07a0f62311d9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:32 +0930 Subject: tdb_compat: use tdb_open_compat. This is a helper for the common case of opening a tdb with a logging function, but it doesn't do all the work, since TDB1 and TDB2's log functions are different types. Signed-off-by: Rusty Russell --- source4/lib/ldb/ldb_tdb/ldb_index.c | 2 +- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 76 ++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 28 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 45c36f09c9..24cc93feb9 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -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; } 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; } - -- cgit From 985e83ef520da68a60899f0ad977cb28a77b8cbe Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:34 +0930 Subject: tdb2: tie it into build process if --enable-tdb2-breaks-compat This is simplistic. We need to support making TDB2 a standalone library, but for now, we simply built it in-tree. Once we have tdb1 compatibility in tdb2, we can rename this option to --enable-tdb2. Signed-off-by: Rusty Russell --- source4/lib/ldb/wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/wscript b/source4/lib/ldb/wscript index 393f99f630..7de95494c7 100755 --- a/source4/lib/ldb/wscript +++ b/source4/lib/ldb/wscript @@ -16,7 +16,7 @@ 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/tdb_compat:lib/tdb_compat lib/ccan:lib/ccan 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''') -- cgit From f0ff6f390a14b0da8466096c0886f5c4860b977f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Jun 2011 21:10:01 +0200 Subject: Use tevent_req_oom This fixes a few Coverity errors --- source4/lib/messaging/messaging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 13fc188155..484f22b2ee 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -1178,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; } -- cgit From 179a3530d7aace977c6847f165033d9c6b6adba8 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 20 Jun 2011 20:57:41 +1000 Subject: s4-cmdline: Rename popt tables to avoid symbol conflicts These same names are use in the source3 popt code, which is called from in libsmbclient and libnet. These are then included in the smbtorture binary for testing Andrew Bartlett --- source4/lib/cmdline/popt_common.c | 6 +++--- source4/lib/cmdline/popt_common.h | 16 ++++++++-------- source4/lib/cmdline/popt_credentials.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'source4/lib') 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 /* 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" }, -- cgit From dd5350b0a87c82be7d0b0d124885ecfd73bb1b5b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Jun 2011 12:34:32 +1000 Subject: ldb: expose syntax oids to python Pair-Programmed-With: Andrew Bartlett --- source4/lib/ldb/pyldb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index b568bc2ccd..1bcdaabe13 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -3222,4 +3222,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); } -- cgit From 341884c835b9c5785794cba562c2a21939eb4bce Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Jun 2011 13:49:37 +1000 Subject: ldb: added extended_str() method to pyldb this gives access to ldb_dn_get_extended_linearized() from python Pair-Programmed-With: Andrew Bartlett --- source4/lib/ldb/pyldb.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 1bcdaabe13..842da633bb 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -7,6 +7,8 @@ Copyright (C) 2006 Simo Sorce Copyright (C) 2007-2010 Jelmer Vernooij 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 @@ -384,6 +386,17 @@ 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_repr(PyLdbDnObject *self) { return PyString_FromFormat("Dn(%s)", PyObject_REPR(PyString_FromString(ldb_dn_get_linearized(self->dn)))); @@ -485,6 +498,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." }, -- cgit From 505dce2d3aa95d475e12c4e5e4e2b3f1907bdd84 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Jun 2011 14:44:12 +1000 Subject: pyldb: added methods to get/set extended components on DNs this will be used by the dbcheck code Pair-Programmed-With: Andrew Bartlett --- source4/lib/ldb/pyldb.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 842da633bb..e2a2e7180e 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -397,6 +397,51 @@ static PyObject *py_ldb_dn_extended_str(PyLdbDnObject *self, PyObject *args, PyO 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)))); @@ -513,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 } }; -- cgit