summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-03-05 12:24:35 +1100
committerAndrew Bartlett <abartlet@samba.org>2009-03-05 12:24:35 +1100
commit41760c18bdab20d526d32568531bdf7c88272879 (patch)
treeb2f421919501a3061afe40f0cb0980f86f448ea8 /source3/lib
parent8249383efb2037bb234dd040ebe151329cc4feb9 (diff)
parentc8ea9d1f13096cd7f51e5972915a61ca65b56ac3 (diff)
downloadsamba-41760c18bdab20d526d32568531bdf7c88272879.tar.gz
samba-41760c18bdab20d526d32568531bdf7c88272879.tar.bz2
samba-41760c18bdab20d526d32568531bdf7c88272879.zip
Merge branch 'master' of ssh://git.samba.org/data/git/samba into wspp-schema
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/charcnv.c2
-rw-r--r--source3/lib/dbwrap.c26
-rw-r--r--source3/lib/dbwrap_ctdb.c12
-rw-r--r--source3/lib/dbwrap_rbt.c8
-rw-r--r--source3/lib/dbwrap_tdb.c12
-rw-r--r--source3/lib/display_sec.c8
-rw-r--r--source3/lib/events.c7
-rw-r--r--source3/lib/fault.c173
-rw-r--r--source3/lib/iconv.c4
-rw-r--r--source3/lib/secace.c293
-rw-r--r--source3/lib/secacl.c118
-rw-r--r--source3/lib/smbconf/smbconf_reg.c174
-rw-r--r--source3/lib/util.c7
-rw-r--r--source3/lib/util_nttoken.c16
-rw-r--r--source3/lib/util_reg_api.c2
-rw-r--r--source3/lib/util_sock.c92
-rw-r--r--source3/lib/util_str.c112
-rw-r--r--source3/lib/wb_reqtrans.c30
-rw-r--r--source3/lib/wbclient.c7
19 files changed, 330 insertions, 773 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index c3b345142f..81cb9a5094 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -763,7 +763,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
* converted.
*/
bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
- void const *src, size_t srclen, void *dst,
+ void const *src, size_t srclen, void **dst,
size_t *converted_size, bool allow_bad_conv)
{
void **dest = (void **)dst;
diff --git a/source3/lib/dbwrap.c b/source3/lib/dbwrap.c
index a57b7c97a5..5e7ce6099f 100644
--- a/source3/lib/dbwrap.c
+++ b/source3/lib/dbwrap.c
@@ -42,6 +42,29 @@ static int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
return 0;
}
+/*
+ * Fall back using fetch if no genuine parse operation is provided
+ */
+
+static int dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key,
+ int (*parser)(TDB_DATA key,
+ TDB_DATA data,
+ void *private_data),
+ void *private_data)
+{
+ TDB_DATA data;
+ int res;
+
+ res = db->fetch(db, talloc_tos(), key, &data);
+ if (res != 0) {
+ return res;
+ }
+
+ res = parser(key, data, private_data);
+ TALLOC_FREE(data.dptr);
+ return res;
+}
+
/**
* open a database
*/
@@ -101,6 +124,9 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
if ((result != NULL) && (result->fetch == NULL)) {
result->fetch = dbwrap_fallback_fetch;
}
+ if ((result != NULL) && (result->parse_record == NULL)) {
+ result->parse_record = dbwrap_fallback_parse_record;
+ }
return result;
}
diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c
index 03667ff355..4a5bf6d81a 100644
--- a/source3/lib/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap_ctdb.c
@@ -121,9 +121,9 @@ static struct ctdb_marshall_buffer *db_ctdb_marshall_add(TALLOC_CTX *mem_ctx,
{
struct ctdb_rec_data *r;
size_t m_size, r_size;
- struct ctdb_marshall_buffer *m2;
+ struct ctdb_marshall_buffer *m2 = NULL;
- r = db_ctdb_marshall_record(mem_ctx, reqid, key, header, data);
+ r = db_ctdb_marshall_record(talloc_tos(), reqid, key, header, data);
if (r == NULL) {
talloc_free(m);
return NULL;
@@ -133,7 +133,7 @@ static struct ctdb_marshall_buffer *db_ctdb_marshall_add(TALLOC_CTX *mem_ctx,
m = (struct ctdb_marshall_buffer *)talloc_zero_size(
mem_ctx, offsetof(struct ctdb_marshall_buffer, data));
if (m == NULL) {
- return NULL;
+ goto done;
}
m->db_id = db_id;
}
@@ -145,15 +145,15 @@ static struct ctdb_marshall_buffer *db_ctdb_marshall_add(TALLOC_CTX *mem_ctx,
mem_ctx, m, m_size + r_size);
if (m2 == NULL) {
talloc_free(m);
- return NULL;
+ goto done;
}
memcpy(m_size + (uint8_t *)m2, r, r_size);
- talloc_free(r);
-
m2->count++;
+done:
+ talloc_free(r);
return m2;
}
diff --git a/source3/lib/dbwrap_rbt.c b/source3/lib/dbwrap_rbt.c
index 6e09627223..cf4faa25b9 100644
--- a/source3/lib/dbwrap_rbt.c
+++ b/source3/lib/dbwrap_rbt.c
@@ -131,12 +131,12 @@ static NTSTATUS db_rbt_store(struct db_record *rec, TDB_DATA data, int flag)
*/
}
- node = (struct db_rbt_node *)SMB_MALLOC(
+ node = (struct db_rbt_node *)talloc_size(rec_priv->db_ctx,
offsetof(struct db_rbt_node, data) + rec->key.dsize
+ data.dsize);
if (node == NULL) {
- SAFE_FREE(rec_priv->node);
+ TALLOC_FREE(rec_priv->node);
return NT_STATUS_NO_MEMORY;
}
@@ -148,7 +148,7 @@ static NTSTATUS db_rbt_store(struct db_record *rec, TDB_DATA data, int flag)
db_rbt_parse_node(node, &this_key, &this_val);
memcpy(this_key.dptr, rec->key.dptr, node->keysize);
- SAFE_FREE(rec_priv->node);
+ TALLOC_FREE(rec_priv->node);
memcpy(this_val.dptr, data.dptr, node->valuesize);
@@ -194,7 +194,7 @@ static NTSTATUS db_rbt_delete(struct db_record *rec)
}
rb_erase(&rec_priv->node->rb_node, &rec_priv->db_ctx->tree);
- SAFE_FREE(rec_priv->node);
+ TALLOC_FREE(rec_priv->node);
return NT_STATUS_OK;
}
diff --git a/source3/lib/dbwrap_tdb.c b/source3/lib/dbwrap_tdb.c
index b5eb1881d4..c71e073b41 100644
--- a/source3/lib/dbwrap_tdb.c
+++ b/source3/lib/dbwrap_tdb.c
@@ -176,6 +176,17 @@ static int db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
return 0;
}
+static int db_tdb_parse(struct db_context *db, TDB_DATA key,
+ int (*parser)(TDB_DATA key, TDB_DATA data,
+ void *private_data),
+ void *private_data)
+{
+ struct db_tdb_ctx *ctx = talloc_get_type_abort(
+ db->private_data, struct db_tdb_ctx);
+
+ return tdb_parse_record(ctx->wtdb->tdb, key, parser, private_data);
+}
+
static NTSTATUS db_tdb_store(struct db_record *rec, TDB_DATA data, int flag)
{
struct db_tdb_ctx *ctx = talloc_get_type_abort(rec->private_data,
@@ -351,6 +362,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
result->fetch = db_tdb_fetch;
result->traverse = db_tdb_traverse;
result->traverse_read = db_tdb_traverse_read;
+ result->parse_record = db_tdb_parse;
result->get_seqnum = db_tdb_get_seqnum;
result->get_flags = db_tdb_get_flags;
result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0);
diff --git a/source3/lib/display_sec.c b/source3/lib/display_sec.c
index 636639c11d..fe1ae77edd 100644
--- a/source3/lib/display_sec.c
+++ b/source3/lib/display_sec.c
@@ -155,13 +155,13 @@ void display_sec_ace_flags(uint8_t flags)
****************************************************************************/
static void disp_sec_ace_object(struct security_ace_object *object)
{
- if (object->flags & SEC_ACE_OBJECT_PRESENT) {
- printf("Object type: SEC_ACE_OBJECT_PRESENT\n");
+ if (object->flags & SEC_ACE_OBJECT_TYPE_PRESENT) {
+ printf("Object type: SEC_ACE_OBJECT_TYPE_PRESENT\n");
printf("Object GUID: %s\n", GUID_string(talloc_tos(),
&object->type.type));
}
- if (object->flags & SEC_ACE_OBJECT_INHERITED_PRESENT) {
- printf("Object type: SEC_ACE_OBJECT_INHERITED_PRESENT\n");
+ if (object->flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT) {
+ printf("Object type: SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT\n");
printf("Object GUID: %s\n", GUID_string(talloc_tos(),
&object->inherited_type.inherited_type));
}
diff --git a/source3/lib/events.c b/source3/lib/events.c
index 44b4562757..f875e0dc0c 100644
--- a/source3/lib/events.c
+++ b/source3/lib/events.c
@@ -282,12 +282,13 @@ static void s3_event_debug(void *context, enum tevent_debug_level level,
samba_level = 2;
break;
case TEVENT_DEBUG_TRACE:
- samba_level = 5;
+ samba_level = 10;
break;
};
- vasprintf(&s, fmt, ap);
- if (!s) return;
+ if (vasprintf(&s, fmt, ap) == -1) {
+ return;
+ }
DEBUG(samba_level, ("s3_event: %s", s));
free(s);
}
diff --git a/source3/lib/fault.c b/source3/lib/fault.c
index 8c4a45bbc9..efd1dddfd4 100644
--- a/source3/lib/fault.c
+++ b/source3/lib/fault.c
@@ -2,6 +2,7 @@
Unix SMB/CIFS implementation.
Critical Fault handling
Copyright (C) Andrew Tridgell 1992-1998
+ Copyright (C) Tim Prouty 2009
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
@@ -87,6 +88,128 @@ void fault_setup(void (*fn)(void *))
#endif
}
+/**
+ * Build up the default corepath as "<logbase>/cores/<progname>"
+ */
+static char *get_default_corepath(const char *logbase, const char *progname)
+{
+ char *tmp_corepath;
+
+ /* Setup core dir in logbase. */
+ tmp_corepath = talloc_asprintf(NULL, "%s/cores", logbase);
+ if (!tmp_corepath)
+ return NULL;
+
+ if ((mkdir(tmp_corepath, 0700) == -1) && errno != EEXIST)
+ goto err_out;
+
+ if (chmod(tmp_corepath, 0700) == -1)
+ goto err_out;
+
+ talloc_free(tmp_corepath);
+
+ /* Setup progname-specific core subdir */
+ tmp_corepath = talloc_asprintf(NULL, "%s/cores/%s", logbase, progname);
+ if (!tmp_corepath)
+ return NULL;
+
+ if (mkdir(tmp_corepath, 0700) == -1 && errno != EEXIST)
+ goto err_out;
+
+ if (chown(tmp_corepath, getuid(), getgid()) == -1)
+ goto err_out;
+
+ if (chmod(tmp_corepath, 0700) == -1)
+ goto err_out;
+
+ return tmp_corepath;
+
+ err_out:
+ talloc_free(tmp_corepath);
+ return NULL;
+}
+
+/**
+ * Get the FreeBSD corepath.
+ *
+ * On FreeBSD the current working directory is ignored when creating a core
+ * file. Instead the core directory is controlled via sysctl. This consults
+ * the value of "kern.corefile" so the correct corepath can be printed out
+ * before dump_core() calls abort.
+ */
+#if (defined(FREEBSD) && defined(HAVE_SYSCTLBYNAME))
+static char *get_freebsd_corepath(void)
+{
+ char *tmp_corepath = NULL;
+ char *end = NULL;
+ size_t len = 128;
+ int ret;
+
+ /* Loop with increasing sizes so we don't allocate too much. */
+ do {
+ if (len > 1024) {
+ goto err_out;
+ }
+
+ tmp_corepath = (char *)talloc_realloc(NULL, tmp_corepath,
+ char, len);
+ if (!tmp_corepath) {
+ return NULL;
+ }
+
+ ret = sysctlbyname("kern.corefile", tmp_corepath, &len, NULL,
+ 0);
+ if (ret == -1) {
+ if (errno != ENOMEM) {
+ DEBUG(0, ("sysctlbyname failed getting "
+ "kern.corefile %s\n",
+ strerror(errno)));
+ goto err_out;
+ }
+
+ /* Not a large enough array, try a bigger one. */
+ len = len << 1;
+ }
+ } while (ret == -1);
+
+ /* Strip off the common filename expansion */
+ if ((end = strrchr_m(tmp_corepath, '/'))) {
+ *end = '\0';
+ }
+
+ return tmp_corepath;
+
+ err_out:
+ if (tmp_corepath) {
+ talloc_free(tmp_corepath);
+ }
+ return NULL;
+}
+#endif
+
+/**
+ * Try getting system-specific corepath if one exists.
+ *
+ * If the system doesn't define a corepath, then the default is used.
+ */
+static char *get_corepath(const char *logbase, const char *progname)
+{
+ char *tmp_corepath = NULL;
+
+ /* @todo: Add support for the linux corepath. */
+#if (defined(FREEBSD) && defined(HAVE_SYSCTLBYNAME))
+ tmp_corepath = get_freebsd_corepath();
+#endif
+
+ /* If this has been set correctly, we're done. */
+ if (tmp_corepath) {
+ return tmp_corepath;
+ }
+
+ /* Fall back to the default. */
+ return get_default_corepath(logbase, progname);
+}
+
/*******************************************************************
make all the preparations to safely dump a core file
********************************************************************/
@@ -104,7 +227,7 @@ void dump_core_setup(const char *progname)
*end = '\0';
}
} else {
- /* We will end up here is the log file is given on the command
+ /* We will end up here if the log file is given on the command
* line by the -l option but the "log file" option is not set
* in smb.conf.
*/
@@ -115,49 +238,13 @@ void dump_core_setup(const char *progname)
SMB_ASSERT(progname != NULL);
- if (asprintf(&corepath, "%s/cores", logbase) < 0) {
- SAFE_FREE(logbase);
- return;
- }
- if (mkdir(corepath,0700) == -1) {
- if (errno != EEXIST) {
- SAFE_FREE(corepath);
- SAFE_FREE(logbase);
- return;
- }
- }
- if (chmod(corepath,0700) == -1) {
- SAFE_FREE(corepath);
- SAFE_FREE(logbase);
- return;
- }
-
- SAFE_FREE(corepath);
- if (asprintf(&corepath, "%s/cores/%s",
- logbase, progname) < 0) {
- SAFE_FREE(logbase);
- return;
- }
- if (mkdir(corepath,0700) == -1) {
- if (errno != EEXIST) {
- SAFE_FREE(corepath);
- SAFE_FREE(logbase);
- return;
- }
- }
-
- if (chown(corepath,getuid(),getgid()) == -1) {
- SAFE_FREE(corepath);
- SAFE_FREE(logbase);
- return;
- }
- if (chmod(corepath,0700) == -1) {
- SAFE_FREE(corepath);
- SAFE_FREE(logbase);
- return;
+ corepath = get_corepath(logbase, progname);
+ if (!corepath) {
+ DEBUG(0, ("Unable to setup corepath for %s: %s\n", progname,
+ strerror(errno)));
+ goto out;
}
- SAFE_FREE(logbase);
#ifdef HAVE_GETRLIMIT
#ifdef RLIMIT_CORE
@@ -184,6 +271,8 @@ void dump_core_setup(const char *progname)
/* FIXME: if we have a core-plus-pid facility, configurably set
* this up here.
*/
+ out:
+ SAFE_FREE(logbase);
}
void dump_core(void)
diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c
index 3ceb637b8e..44500542f2 100644
--- a/source3/lib/iconv.c
+++ b/source3/lib/iconv.c
@@ -207,12 +207,12 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
from = charsets;
to = charsets;
- ret = SMB_MALLOC_P(struct _smb_iconv_t);
+ ret = SMB_MALLOC_P(struct smb_iconv_s);
if (!ret) {
errno = ENOMEM;
return (smb_iconv_t)-1;
}
- memset(ret, 0, sizeof(struct _smb_iconv_t));
+ memset(ret, 0, sizeof(struct smb_iconv_s));
ret->from_name = SMB_STRDUP(fromcode);
ret->to_name = SMB_STRDUP(tocode);
diff --git a/source3/lib/secace.c b/source3/lib/secace.c
deleted file mode 100644
index 878fac252b..0000000000
--- a/source3/lib/secace.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Unix SMB/Netbios implementation.
- * SEC_ACE handling functions
- * Copyright (C) Andrew Tridgell 1992-1998,
- * Copyright (C) Jeremy R. Allison 1995-2003.
- * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
- * Copyright (C) Paul Ashton 1997-1998.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "includes.h"
-
-/*******************************************************************
- Check if ACE has OBJECT type.
-********************************************************************/
-
-bool sec_ace_object(uint8 type)
-{
- if (type == SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT ||
- type == SEC_ACE_TYPE_ACCESS_DENIED_OBJECT ||
- type == SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT ||
- type == SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT) {
- return True;
- }
- return False;
-}
-
-/*******************************************************************
- copy a SEC_ACE structure.
-********************************************************************/
-void sec_ace_copy(SEC_ACE *ace_dest, SEC_ACE *ace_src)
-{
- ace_dest->type = ace_src->type;
- ace_dest->flags = ace_src->flags;
- ace_dest->size = ace_src->size;
- ace_dest->access_mask = ace_src->access_mask;
- ace_dest->object = ace_src->object;
- sid_copy(&ace_dest->trustee, &ace_src->trustee);
-}
-
-/*******************************************************************
- Sets up a SEC_ACE structure.
-********************************************************************/
-
-void init_sec_ace(SEC_ACE *t, const DOM_SID *sid, enum security_ace_type type,
- uint32_t mask, uint8 flag)
-{
- t->type = type;
- t->flags = flag;
- t->size = ndr_size_dom_sid(sid, NULL, 0) + 8;
- t->access_mask = mask;
-
- ZERO_STRUCTP(&t->trustee);
- sid_copy(&t->trustee, sid);
-}
-
-/*******************************************************************
- adds new SID with its permissions to ACE list
-********************************************************************/
-
-NTSTATUS sec_ace_add_sid(TALLOC_CTX *ctx, SEC_ACE **pp_new, SEC_ACE *old, unsigned *num, DOM_SID *sid, uint32 mask)
-{
- unsigned int i = 0;
-
- if (!ctx || !pp_new || !old || !sid || !num) return NT_STATUS_INVALID_PARAMETER;
-
- *num += 1;
-
- if((pp_new[0] = TALLOC_ZERO_ARRAY(ctx, SEC_ACE, *num )) == 0)
- return NT_STATUS_NO_MEMORY;
-
- for (i = 0; i < *num - 1; i ++)
- sec_ace_copy(&(*pp_new)[i], &old[i]);
-
- (*pp_new)[i].type = SEC_ACE_TYPE_ACCESS_ALLOWED;
- (*pp_new)[i].flags = 0;
- (*pp_new)[i].size = SEC_ACE_HEADER_SIZE + ndr_size_dom_sid(sid, NULL, 0);
- (*pp_new)[i].access_mask = mask;
- sid_copy(&(*pp_new)[i].trustee, sid);
- return NT_STATUS_OK;
-}
-
-/*******************************************************************
- modify SID's permissions at ACL
-********************************************************************/
-
-NTSTATUS sec_ace_mod_sid(SEC_ACE *ace, size_t num, DOM_SID *sid, uint32 mask)
-{
- unsigned int i = 0;
-
- if (!ace || !sid) return NT_STATUS_INVALID_PARAMETER;
-
- for (i = 0; i < num; i ++) {
- if (sid_compare(&ace[i].trustee, sid) == 0) {
- ace[i].access_mask = mask;
- return NT_STATUS_OK;
- }
- }
- return NT_STATUS_NOT_FOUND;
-}
-
-/*******************************************************************
- delete SID from ACL
-********************************************************************/
-
-NTSTATUS sec_ace_del_sid(TALLOC_CTX *ctx, SEC_ACE **pp_new, SEC_ACE *old, uint32 *num, DOM_SID *sid)
-{
- unsigned int i = 0;
- unsigned int n_del = 0;
-
- if (!ctx || !pp_new || !old || !sid || !num) return NT_STATUS_INVALID_PARAMETER;
-
- if (*num) {
- if((pp_new[0] = TALLOC_ZERO_ARRAY(ctx, SEC_ACE, *num )) == 0)
- return NT_STATUS_NO_MEMORY;
- } else {
- pp_new[0] = NULL;
- }
-
- for (i = 0; i < *num; i ++) {
- if (sid_compare(&old[i].trustee, sid) != 0)
- sec_ace_copy(&(*pp_new)[i], &old[i]);
- else
- n_del ++;
- }
- if (n_del == 0)
- return NT_STATUS_NOT_FOUND;
- else {
- *num -= n_del;
- return NT_STATUS_OK;
- }
-}
-
-/*******************************************************************
- Compares two SEC_ACE structures
-********************************************************************/
-
-bool sec_ace_equal(SEC_ACE *s1, SEC_ACE *s2)
-{
- /* Trivial case */
-
- if (!s1 && !s2) {
- return True;
- }
-
- if (!s1 || !s2) {
- return False;
- }
-
- /* Check top level stuff */
-
- if (s1->type != s2->type || s1->flags != s2->flags ||
- s1->access_mask != s2->access_mask) {
- return False;
- }
-
- /* Check SID */
-
- if (!sid_equal(&s1->trustee, &s2->trustee)) {
- return False;
- }
-
- return True;
-}
-
-int nt_ace_inherit_comp( SEC_ACE *a1, SEC_ACE *a2)
-{
- int a1_inh = a1->flags & SEC_ACE_FLAG_INHERITED_ACE;
- int a2_inh = a2->flags & SEC_ACE_FLAG_INHERITED_ACE;
-
- if (a1_inh == a2_inh)
- return 0;
-
- if (!a1_inh && a2_inh)
- return -1;
- return 1;
-}
-
-/*******************************************************************
- Comparison function to apply the order explained below in a group.
-*******************************************************************/
-
-int nt_ace_canon_comp( SEC_ACE *a1, SEC_ACE *a2)
-{
- if ((a1->type == SEC_ACE_TYPE_ACCESS_DENIED) &&
- (a2->type != SEC_ACE_TYPE_ACCESS_DENIED))
- return -1;
-
- if ((a2->type == SEC_ACE_TYPE_ACCESS_DENIED) &&
- (a1->type != SEC_ACE_TYPE_ACCESS_DENIED))
- return 1;
-
- /* Both access denied or access allowed. */
-
- /* 1. ACEs that apply to the object itself */
-
- if (!(a1->flags & SEC_ACE_FLAG_INHERIT_ONLY) &&
- (a2->flags & SEC_ACE_FLAG_INHERIT_ONLY))
- return -1;
- else if (!(a2->flags & SEC_ACE_FLAG_INHERIT_ONLY) &&
- (a1->flags & SEC_ACE_FLAG_INHERIT_ONLY))
- return 1;
-
- /* 2. ACEs that apply to a subobject of the object, such as
- * a property set or property. */
-
- if (a1->flags & (SEC_ACE_FLAG_CONTAINER_INHERIT|SEC_ACE_FLAG_OBJECT_INHERIT) &&
- !(a2->flags & (SEC_ACE_FLAG_CONTAINER_INHERIT|SEC_ACE_FLAG_OBJECT_INHERIT)))
- return -1;
- else if (a2->flags & (SEC_ACE_FLAG_CONTAINER_INHERIT|SEC_ACE_FLAG_OBJECT_INHERIT) &&
- !(a1->flags & (SEC_ACE_FLAG_CONTAINER_INHERIT|SEC_ACE_FLAG_OBJECT_INHERIT)))
- return 1;
-
- return 0;
-}
-
-/*******************************************************************
- Functions to convert a SEC_DESC ACE DACL list into canonical order.
- JRA.
-
---- from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/security/order_of_aces_in_a_dacl.asp
-
-The following describes the preferred order:
-
- To ensure that noninherited ACEs have precedence over inherited ACEs,
- place all noninherited ACEs in a group before any inherited ACEs.
- This ordering ensures, for example, that a noninherited access-denied ACE
- is enforced regardless of any inherited ACE that allows access.
-
- Within the groups of noninherited ACEs and inherited ACEs, order ACEs according to ACE type, as the following shows:
- 1. Access-denied ACEs that apply to the object itself
- 2. Access-denied ACEs that apply to a subobject of the object, such as a property set or property
- 3. Access-allowed ACEs that apply to the object itself
- 4. Access-allowed ACEs that apply to a subobject of the object"
-
-********************************************************************/
-
-void dacl_sort_into_canonical_order(SEC_ACE *srclist, unsigned int num_aces)
-{
- unsigned int i;
-
- if (!srclist || num_aces == 0)
- return;
-
- /* Sort so that non-inherited ACE's come first. */
- qsort( srclist, num_aces, sizeof(srclist[0]), QSORT_CAST nt_ace_inherit_comp);
-
- /* Find the boundary between non-inherited ACEs. */
- for (i = 0; i < num_aces; i++ ) {
- SEC_ACE *curr_ace = &srclist[i];
-
- if (curr_ace->flags & SEC_ACE_FLAG_INHERITED_ACE)
- break;
- }
-
- /* i now points at entry number of the first inherited ACE. */
-
- /* Sort the non-inherited ACEs. */
- if (i)
- qsort( srclist, i, sizeof(srclist[0]), QSORT_CAST nt_ace_canon_comp);
-
- /* Now sort the inherited ACEs. */
- if (num_aces - i)
- qsort( &srclist[i], num_aces - i, sizeof(srclist[0]), QSORT_CAST nt_ace_canon_comp);
-}
-
-/*******************************************************************
- Check if this ACE has a SID in common with the token.
-********************************************************************/
-
-bool token_sid_in_ace(const NT_USER_TOKEN *token, const SEC_ACE *ace)
-{
- size_t i;
-
- for (i = 0; i < token->num_sids; i++) {
- if (sid_equal(&ace->trustee, &token->user_sids[i]))
- return True;
- }
-
- return False;
-}
diff --git a/source3/lib/secacl.c b/source3/lib/secacl.c
deleted file mode 100644
index 5e82242e1b..0000000000
--- a/source3/lib/secacl.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Unix SMB/Netbios implementation.
- * SEC_ACL handling routines
- * Copyright (C) Andrew Tridgell 1992-1998,
- * Copyright (C) Jeremy R. Allison 1995-2003.
- * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
- * Copyright (C) Paul Ashton 1997-1998.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "includes.h"
-
-/*******************************************************************
- Create a SEC_ACL structure.
-********************************************************************/
-
-SEC_ACL *make_sec_acl(TALLOC_CTX *ctx, enum security_acl_revision revision,
- int num_aces, SEC_ACE *ace_list)
-{
- SEC_ACL *dst;
- int i;
-
- if((dst = TALLOC_ZERO_P(ctx,SEC_ACL)) == NULL)
- return NULL;
-
- dst->revision = revision;
- dst->num_aces = num_aces;
- dst->size = SEC_ACL_HEADER_SIZE;
-
- /* Now we need to return a non-NULL address for the ace list even
- if the number of aces required is zero. This is because there
- is a distinct difference between a NULL ace and an ace with zero
- entries in it. This is achieved by checking that num_aces is a
- positive number. */
-
- if ((num_aces) &&
- ((dst->aces = TALLOC_ARRAY(ctx, SEC_ACE, num_aces))
- == NULL)) {
- return NULL;
- }
-
- for (i = 0; i < num_aces; i++) {
- dst->aces[i] = ace_list[i]; /* Structure copy. */
- dst->size += ace_list[i].size;
- }
-
- return dst;
-}
-
-/*******************************************************************
- Duplicate a SEC_ACL structure.
-********************************************************************/
-
-SEC_ACL *dup_sec_acl(TALLOC_CTX *ctx, SEC_ACL *src)
-{
- if(src == NULL)
- return NULL;
-
- return make_sec_acl(ctx, src->revision, src->num_aces, src->aces);
-}
-
-/*******************************************************************
- Compares two SEC_ACL structures
-********************************************************************/
-
-bool sec_acl_equal(SEC_ACL *s1, SEC_ACL *s2)
-{
- unsigned int i, j;
-
- /* Trivial cases */
-
- if (!s1 && !s2) return True;
- if (!s1 || !s2) return False;
-
- /* Check top level stuff */
-
- if (s1->revision != s2->revision) {
- DEBUG(10, ("sec_acl_equal(): revision differs (%d != %d)\n",
- s1->revision, s2->revision));
- return False;
- }
-
- if (s1->num_aces != s2->num_aces) {
- DEBUG(10, ("sec_acl_equal(): num_aces differs (%d != %d)\n",
- s1->revision, s2->revision));
- return False;
- }
-
- /* The ACEs could be in any order so check each ACE in s1 against
- each ACE in s2. */
-
- for (i = 0; i < s1->num_aces; i++) {
- bool found = False;
-
- for (j = 0; j < s2->num_aces; j++) {
- if (sec_ace_equal(&s1->aces[i], &s2->aces[j])) {
- found = True;
- break;
- }
- }
-
- if (!found) return False;
- }
-
- return True;
-}
diff --git a/source3/lib/smbconf/smbconf_reg.c b/source3/lib/smbconf/smbconf_reg.c
index e36fa8a2a1..ae6a41151d 100644
--- a/source3/lib/smbconf/smbconf_reg.c
+++ b/source3/lib/smbconf/smbconf_reg.c
@@ -23,7 +23,7 @@
#define INCLUDES_VALNAME "includes"
struct reg_private_data {
- NT_USER_TOKEN *token;
+ struct registry_key *base_key;
bool open; /* did _we_ open the registry? */
};
@@ -72,54 +72,6 @@ static bool smbconf_reg_valname_valid(const char *valname)
}
/**
- * Open a registry key specified by "path"
- */
-static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx,
- struct smbconf_ctx *ctx,
- const char *path,
- uint32 desired_access,
- struct registry_key **key)
-{
- WERROR werr = WERR_OK;
-
- if (ctx == NULL) {
- DEBUG(1, ("Error: configuration is not open!\n"));
- werr = WERR_INVALID_PARAM;
- goto done;
- }
-
- if (rpd(ctx)->token == NULL) {
- DEBUG(1, ("Error: token missing from smbconf_ctx. "
- "was smbconf_init() called?\n"));
- werr = WERR_INVALID_PARAM;
- goto done;
- }
-
- werr = ctx->ops->open_conf(ctx);
- if (!W_ERROR_IS_OK(werr)) {
- DEBUG(1, ("Error opening the registry.\n"));
- goto done;
- }
-
- if (path == NULL) {
- DEBUG(1, ("Error: NULL path string given\n"));
- werr = WERR_INVALID_PARAM;
- goto done;
- }
-
- werr = reg_open_path(mem_ctx, path, desired_access, rpd(ctx)->token,
- key);
-
- if (!W_ERROR_IS_OK(werr)) {
- DEBUG(5, ("Error opening registry path '%s': %s\n",
- path, win_errstr(werr)));
- }
-
-done:
- return werr;
-}
-
-/**
* Open a subkey of the base key (i.e a service)
*/
static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
@@ -128,40 +80,23 @@ static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
uint32 desired_access,
struct registry_key **key)
{
- WERROR werr = WERR_OK;
- char *path = NULL;
+ WERROR werr;
if (servicename == NULL) {
- path = talloc_strdup(mem_ctx, ctx->path);
- } else {
- path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path,
- servicename);
- }
- if (path == NULL) {
- werr = WERR_NOMEM;
- goto done;
+ *key = rpd(ctx)->base_key;
+ return WERR_OK;
}
+ werr = reg_openkey(mem_ctx, rpd(ctx)->base_key, servicename,
+ desired_access, key);
- werr = smbconf_reg_open_path(mem_ctx, ctx, path, desired_access, key);
+ if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
+ werr = WERR_NO_SUCH_SERVICE;
+ }
-done:
- talloc_free(path);
return werr;
}
/**
- * open the base key
- */
-static WERROR smbconf_reg_open_base_key(TALLOC_CTX *mem_ctx,
- struct smbconf_ctx *ctx,
- uint32 desired_access,
- struct registry_key **key)
-{
- return smbconf_reg_open_path(mem_ctx, ctx, ctx->path, desired_access,
- key);
-}
-
-/**
* check if a value exists in a given registry key
*/
static bool smbconf_value_exists(struct registry_key *key, const char *param)
@@ -189,7 +124,6 @@ static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
struct registry_key **newkey)
{
WERROR werr = WERR_OK;
- struct registry_key *create_parent = NULL;
TALLOC_CTX *create_ctx;
enum winreg_CreateAction action = REG_ACTION_NONE;
@@ -198,13 +132,7 @@ static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
* and will be destroyed when leaving this function... */
create_ctx = talloc_stackframe();
- werr = smbconf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE,
- &create_parent);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- werr = reg_createkey(mem_ctx, create_parent, subkeyname,
+ werr = reg_createkey(mem_ctx, rpd(ctx)->base_key, subkeyname,
REG_KEY_WRITE, newkey, &action);
if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
DEBUG(10, ("Key '%s' already exists.\n", subkeyname));
@@ -215,7 +143,6 @@ static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
subkeyname, win_errstr(werr)));
}
-done:
talloc_free(create_ctx);
return werr;
}
@@ -608,6 +535,7 @@ done:
static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
{
WERROR werr = WERR_OK;
+ struct nt_user_token *token;
if (path == NULL) {
path = KEY_SMBCONF;
@@ -620,8 +548,7 @@ static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
ctx->data = TALLOC_ZERO_P(ctx, struct reg_private_data);
- werr = ntstatus_to_werror(registry_create_admin_token(ctx,
- &(rpd(ctx)->token)));
+ werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
if (!W_ERROR_IS_OK(werr)) {
DEBUG(1, ("Error creating admin token\n"));
goto done;
@@ -633,6 +560,19 @@ static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
goto done;
}
+ werr = ctx->ops->open_conf(ctx);
+ if (!W_ERROR_IS_OK(werr)) {
+ DEBUG(1, ("Error opening the registry.\n"));
+ goto done;
+ }
+
+ werr = reg_open_path(ctx, ctx->path,
+ SEC_RIGHTS_ENUM_SUBKEYS | REG_KEY_WRITE,
+ token, &rpd(ctx)->base_key);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+
done:
return werr;
}
@@ -723,6 +663,13 @@ static WERROR smbconf_reg_drop(struct smbconf_ctx *ctx)
struct registry_key *new_key = NULL;
TALLOC_CTX* mem_ctx = talloc_stackframe();
enum winreg_CreateAction action;
+ struct nt_user_token *token;
+
+ werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
+ if (!W_ERROR_IS_OK(werr)) {
+ DEBUG(1, ("Error creating admin token\n"));
+ goto done;
+ }
path = talloc_strdup(mem_ctx, ctx->path);
if (path == NULL) {
@@ -731,8 +678,8 @@ static WERROR smbconf_reg_drop(struct smbconf_ctx *ctx)
}
p = strrchr(path, '\\');
*p = '\0';
- werr = smbconf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE,
- &parent_key);
+ werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token,
+ &parent_key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
@@ -765,7 +712,6 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
uint32_t added_count = 0;
TALLOC_CTX *tmp_ctx = NULL;
WERROR werr = WERR_OK;
- struct registry_key *key = NULL;
char *subkey_name = NULL;
char **tmp_share_names = NULL;
@@ -777,13 +723,8 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
tmp_ctx = talloc_stackframe();
/* if there are values in the base key, return NULL as share name */
- werr = smbconf_reg_open_base_key(tmp_ctx, ctx,
- SEC_RIGHTS_ENUM_SUBKEYS, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
- if (smbconf_reg_key_has_values(key)) {
+ if (smbconf_reg_key_has_values(rpd(ctx)->base_key)) {
werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
0, NULL);
if (!W_ERROR_IS_OK(werr)) {
@@ -803,7 +744,8 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
}
for (count = 0;
- werr = reg_enumkey(tmp_ctx, key, count, &subkey_name, NULL),
+ werr = reg_enumkey(tmp_ctx, rpd(ctx)->base_key, count,
+ &subkey_name, NULL),
W_ERROR_IS_OK(werr);
count++)
{
@@ -865,18 +807,16 @@ static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx,
const char *servicename)
{
WERROR werr;
- TALLOC_CTX *mem_ctx = talloc_stackframe();
struct registry_key *key = NULL;
if (servicename == NULL) {
- werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE,
- &key);
- } else {
- werr = smbconf_reg_create_service_key(mem_ctx, ctx,
- servicename, &key);
+ return WERR_OK;
}
- talloc_free(mem_ctx);
+ werr = smbconf_reg_create_service_key(talloc_tos(), ctx,
+ servicename, &key);
+
+ talloc_free(key);
return werr;
}
@@ -934,21 +874,15 @@ static WERROR smbconf_reg_delete_share(struct smbconf_ctx *ctx,
const char *servicename)
{
WERROR werr = WERR_OK;
- struct registry_key *key = NULL;
TALLOC_CTX *mem_ctx = talloc_stackframe();
- werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
if (servicename != NULL) {
- werr = reg_deletekey_recursive(key, key, servicename);
+ werr = reg_deletekey_recursive(mem_ctx, rpd(ctx)->base_key,
+ servicename);
} else {
- werr = smbconf_reg_delete_values(key);
+ werr = smbconf_reg_delete_values(rpd(ctx)->base_key);
}
-done:
talloc_free(mem_ctx);
return werr;
}
@@ -1137,6 +1071,21 @@ done:
return werr;
}
+static WERROR smbconf_reg_transaction_start(struct smbconf_ctx *ctx)
+{
+ return regdb_transaction_start();
+}
+
+static WERROR smbconf_reg_transaction_commit(struct smbconf_ctx *ctx)
+{
+ return regdb_transaction_commit();
+}
+
+static WERROR smbconf_reg_transaction_cancel(struct smbconf_ctx *ctx)
+{
+ return regdb_transaction_cancel();
+}
+
struct smbconf_ops smbconf_ops_reg = {
.init = smbconf_reg_init,
.shutdown = smbconf_reg_shutdown,
@@ -1157,6 +1106,9 @@ struct smbconf_ops smbconf_ops_reg = {
.get_includes = smbconf_reg_get_includes,
.set_includes = smbconf_reg_set_includes,
.delete_includes = smbconf_reg_delete_includes,
+ .transaction_start = smbconf_reg_transaction_start,
+ .transaction_commit = smbconf_reg_transaction_commit,
+ .transaction_cancel = smbconf_reg_transaction_cancel,
};
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 89f7be8e6c..ec794ca74e 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -899,13 +899,6 @@ bool reinit_after_fork(struct messaging_context *msg_ctx,
* numbers as each other */
set_need_random_reseed();
-#ifdef WITH_MADVISE_PROTECTED
- /* Protect parent process from being killed by kernel when system
- * memory is low. Child processes can still be killed */
- if(!parent_longlived)
- madvise(NULL,0,MADV_PROTECT);
-#endif
-
/* tdb needs special fork handling */
if (tdb_reopen_all(parent_longlived ? 1 : 0) == -1) {
DEBUG(0,("tdb_reopen_all failed.\n"));
diff --git a/source3/lib/util_nttoken.c b/source3/lib/util_nttoken.c
index 774ef498b7..76e7402422 100644
--- a/source3/lib/util_nttoken.c
+++ b/source3/lib/util_nttoken.c
@@ -115,3 +115,19 @@ NTSTATUS merge_nt_token(TALLOC_CTX *mem_ctx,
return NT_STATUS_OK;
}
+
+/*******************************************************************
+ Check if this ACE has a SID in common with the token.
+********************************************************************/
+
+bool token_sid_in_ace(const NT_USER_TOKEN *token, const struct security_ace *ace)
+{
+ size_t i;
+
+ for (i = 0; i < token->num_sids; i++) {
+ if (sid_equal(&ace->trustee, &token->user_sids[i]))
+ return true;
+ }
+
+ return false;
+}
diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c
index 8f28e9c282..9313193f10 100644
--- a/source3/lib/util_reg_api.c
+++ b/source3/lib/util_reg_api.c
@@ -92,7 +92,7 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx,
}
if (!convert_string_talloc(value, CH_UTF16LE, CH_UNIX, tmp,
- length+2, &value->v.sz.str,
+ length+2, (void **)&value->v.sz.str,
&value->v.sz.len, False)) {
SAFE_FREE(tmp);
err = WERR_INVALID_PARAM;
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 83e8a9d355..3604be369f 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -967,20 +967,20 @@ static int open_socket_out_state_destructor(struct open_socket_out_state *s)
Create an outgoing socket. timeout is in milliseconds.
**************************************************************************/
-struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
- const struct sockaddr_storage *pss,
- uint16_t port,
- int timeout)
+struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ const struct sockaddr_storage *pss,
+ uint16_t port,
+ int timeout)
{
char addr[INET6_ADDRSTRLEN];
- struct async_req *result;
- struct tevent_req *subreq;
+ struct tevent_req *result, *subreq;
struct open_socket_out_state *state;
NTSTATUS status;
- if (!async_req_setup(mem_ctx, &result, &state,
- struct open_socket_out_state)) {
+ result = tevent_req_create(mem_ctx, &state,
+ struct open_socket_out_state);
+ if (result == NULL) {
return NULL;
}
state->ev = ev;
@@ -996,7 +996,8 @@ struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
}
talloc_set_destructor(state, open_socket_out_state_destructor);
- if (!async_req_set_timeout(result, ev, timeval_set(0, timeout*1000))) {
+ if (!tevent_req_set_endtime(
+ result, ev, timeval_current_ofs(0, timeout*1000))) {
goto fail;
}
@@ -1030,18 +1031,14 @@ struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
|| !tevent_req_set_endtime(
subreq, state->ev,
timeval_current_ofs(0, state->wait_nsec))) {
- status = NT_STATUS_NO_MEMORY;
- goto post_status;
+ goto fail;
}
- subreq->async.fn = open_socket_out_connected;
- subreq->async.private_data = result;
+ tevent_req_set_callback(subreq, open_socket_out_connected, result);
return result;
post_status:
- if (!async_post_ntstatus(result, ev, status)) {
- goto fail;
- }
- return result;
+ tevent_req_nterror(result, status);
+ return tevent_req_post(result, ev);
fail:
TALLOC_FREE(result);
return NULL;
@@ -1049,17 +1046,17 @@ struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
static void open_socket_out_connected(struct tevent_req *subreq)
{
- struct async_req *req = talloc_get_type_abort(
- subreq->async.private_data, struct async_req);
- struct open_socket_out_state *state = talloc_get_type_abort(
- req->private_data, struct open_socket_out_state);
+ struct tevent_req *req =
+ tevent_req_callback_data(subreq, struct tevent_req);
+ struct open_socket_out_state *state =
+ tevent_req_data(req, struct open_socket_out_state);
int ret;
int sys_errno;
ret = async_connect_recv(subreq, &sys_errno);
TALLOC_FREE(subreq);
if (ret == 0) {
- async_req_done(req);
+ tevent_req_done(req);
return;
}
@@ -1082,39 +1079,38 @@ static void open_socket_out_connected(struct tevent_req *subreq)
subreq = async_connect_send(state, state->ev, state->fd,
(struct sockaddr *)&state->ss,
state->salen);
- if (async_req_nomem(subreq, req)) {
+ if (tevent_req_nomem(subreq, req)) {
return;
}
if (!tevent_req_set_endtime(
subreq, state->ev,
timeval_current_ofs(0, state->wait_nsec))) {
- async_req_error(req, ENOMEM);
+ tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
return;
}
- subreq->async.fn = open_socket_out_connected;
- subreq->async.private_data = req;
+ tevent_req_set_callback(subreq, open_socket_out_connected, req);
return;
}
#ifdef EISCONN
if (sys_errno == EISCONN) {
- async_req_done(req);
+ tevent_req_done(req);
return;
}
#endif
/* real error */
- async_req_error(req, sys_errno);
+ tevent_req_nterror(req, map_nt_error_from_unix(sys_errno));
}
-NTSTATUS open_socket_out_recv(struct async_req *req, int *pfd)
+NTSTATUS open_socket_out_recv(struct tevent_req *req, int *pfd)
{
- struct open_socket_out_state *state = talloc_get_type_abort(
- req->private_data, struct open_socket_out_state);
- int err;
+ struct open_socket_out_state *state =
+ tevent_req_data(req, struct open_socket_out_state);
+ NTSTATUS status;
- if (async_req_is_errno(req, &err)) {
- return map_nt_error_from_unix(err);
+ if (tevent_req_is_nterror(req, &status)) {
+ return status;
}
*pfd = state->fd;
state->fd = -1;
@@ -1126,7 +1122,7 @@ NTSTATUS open_socket_out(const struct sockaddr_storage *pss, uint16_t port,
{
TALLOC_CTX *frame = talloc_stackframe();
struct event_context *ev;
- struct async_req *req;
+ struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
ev = event_context_init(frame);
@@ -1138,10 +1134,10 @@ NTSTATUS open_socket_out(const struct sockaddr_storage *pss, uint16_t port,
if (req == NULL) {
goto fail;
}
- while (req->state < ASYNC_REQ_DONE) {
- event_loop_once(ev);
+ if (!tevent_req_poll(req, ev)) {
+ status = NT_STATUS_INTERNAL_ERROR;
+ goto fail;
}
-
status = open_socket_out_recv(req, pfd);
fail:
TALLOC_FREE(frame);
@@ -1157,7 +1153,7 @@ struct open_socket_out_defer_state {
};
static void open_socket_out_defer_waited(struct async_req *subreq);
-static void open_socket_out_defer_connected(struct async_req *subreq);
+static void open_socket_out_defer_connected(struct tevent_req *subreq);
struct async_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx,
struct event_context *ev,
@@ -1204,6 +1200,7 @@ static void open_socket_out_defer_waited(struct async_req *subreq)
subreq->async.priv, struct async_req);
struct open_socket_out_defer_state *state = talloc_get_type_abort(
req->private_data, struct open_socket_out_defer_state);
+ struct tevent_req *subreq2;
bool ret;
ret = async_wait_recv(subreq);
@@ -1213,19 +1210,18 @@ static void open_socket_out_defer_waited(struct async_req *subreq)
return;
}
- subreq = open_socket_out_send(state, state->ev, &state->ss,
- state->port, state->timeout);
- if (async_req_nomem(subreq, req)) {
+ subreq2 = open_socket_out_send(state, state->ev, &state->ss,
+ state->port, state->timeout);
+ if (async_req_nomem(subreq2, req)) {
return;
}
- subreq->async.fn = open_socket_out_defer_connected;
- subreq->async.priv = req;
+ tevent_req_set_callback(subreq2, open_socket_out_defer_connected, req);
}
-static void open_socket_out_defer_connected(struct async_req *subreq)
+static void open_socket_out_defer_connected(struct tevent_req *subreq)
{
- struct async_req *req = talloc_get_type_abort(
- subreq->async.priv, struct async_req);
+ struct async_req *req =
+ tevent_req_callback_data(subreq, struct async_req);
struct open_socket_out_defer_state *state = talloc_get_type_abort(
req->private_data, struct open_socket_out_defer_state);
NTSTATUS status;
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 9358061797..b9ccb83e55 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -36,118 +36,6 @@ const char toupper_ascii_fast_table[128] = {
};
/**
- * @file
- * @brief String utilities.
- **/
-
-static bool next_token_internal_talloc(TALLOC_CTX *ctx,
- const char **ptr,
- char **pp_buff,
- const char *sep,
- bool ltrim)
-{
- char *s;
- char *saved_s;
- char *pbuf;
- bool quoted;
- size_t len=1;
-
- *pp_buff = NULL;
- if (!ptr) {
- return(false);
- }
-
- s = (char *)*ptr;
-
- /* default to simple separators */
- if (!sep) {
- sep = " \t\n\r";
- }
-
- /* find the first non sep char, if left-trimming is requested */
- if (ltrim) {
- while (*s && strchr_m(sep,*s)) {
- s++;
- }
- }
-
- /* nothing left? */
- if (!*s) {
- return false;
- }
-
- /* When restarting we need to go from here. */
- saved_s = s;
-
- /* Work out the length needed. */
- for (quoted = false; *s &&
- (quoted || !strchr_m(sep,*s)); s++) {
- if (*s == '\"') {
- quoted = !quoted;
- } else {
- len++;
- }
- }
-
- /* We started with len = 1 so we have space for the nul. */
- *pp_buff = TALLOC_ARRAY(ctx, char, len);
- if (!*pp_buff) {
- return false;
- }
-
- /* copy over the token */
- pbuf = *pp_buff;
- s = saved_s;
- for (quoted = false; *s &&
- (quoted || !strchr_m(sep,*s)); s++) {
- if ( *s == '\"' ) {
- quoted = !quoted;
- } else {
- *pbuf++ = *s;
- }
- }
-
- *ptr = (*s) ? s+1 : s;
- *pbuf = 0;
-
- return true;
-}
-
-#if 0
-/*
- * Get the next token from a string, return false if none found. Handles
- * double-quotes. This version trims leading separator characters before
- * looking for a token.
- */
-bool next_token(const char **ptr, char *buff, const char *sep, size_t bufsize)
-{
- return next_token_internal(ptr, buff, sep, bufsize, true);
-}
-#endif
-
-bool next_token_talloc(TALLOC_CTX *ctx,
- const char **ptr,
- char **pp_buff,
- const char *sep)
-{
- return next_token_internal_talloc(ctx, ptr, pp_buff, sep, true);
-}
-
-/*
- * Get the next token from a string, return false if none found. Handles
- * double-quotes. This version does not trim leading separator characters
- * before looking for a token.
- */
-
-bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx,
- const char **ptr,
- char **pp_buff,
- const char *sep)
-{
- return next_token_internal_talloc(ctx, ptr, pp_buff, sep, false);
-}
-
-/**
* Case insensitive string compararison.
*
* iconv does not directly give us a way to compare strings in
diff --git a/source3/lib/wb_reqtrans.c b/source3/lib/wb_reqtrans.c
index a5adf8f108..222b64667c 100644
--- a/source3/lib/wb_reqtrans.c
+++ b/source3/lib/wb_reqtrans.c
@@ -103,8 +103,7 @@ struct async_req *wb_req_read_send(TALLOC_CTX *mem_ctx,
goto nomem;
}
- subreq->async.fn = wb_req_read_done;
- subreq->async.private_data = result;
+ tevent_req_set_callback(subreq, wb_req_read_done, result);
return result;
nomem:
TALLOC_FREE(result);
@@ -140,8 +139,8 @@ static ssize_t wb_req_more(uint8_t *buf, size_t buflen, void *private_data)
static void wb_req_read_done(struct tevent_req *subreq)
{
- struct async_req *req = talloc_get_type_abort(
- subreq->async.private_data, struct async_req);
+ struct async_req *req =
+ tevent_req_callback_data(subreq, struct async_req);
struct req_read_state *state = talloc_get_type_abort(
req->private_data, struct req_read_state);
int err;
@@ -213,8 +212,7 @@ struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx,
if (subreq == NULL) {
goto fail;
}
- subreq->async.fn = wb_req_write_done;
- subreq->async.private_data = result;
+ tevent_req_set_callback(subreq, wb_req_write_done, result);
return result;
fail:
@@ -224,8 +222,8 @@ struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx,
static void wb_req_write_done(struct tevent_req *subreq)
{
- struct async_req *req = talloc_get_type_abort(
- subreq->async.private_data, struct async_req);
+ struct async_req *req =
+ tevent_req_callback_data(subreq, struct async_req);
int err;
ssize_t ret;
@@ -266,8 +264,7 @@ struct async_req *wb_resp_read_send(TALLOC_CTX *mem_ctx,
if (subreq == NULL) {
goto nomem;
}
- subreq->async.fn = wb_resp_read_done;
- subreq->async.private_data = result;
+ tevent_req_set_callback(subreq, wb_resp_read_done, result);
return result;
nomem:
@@ -288,13 +285,13 @@ static ssize_t wb_resp_more(uint8_t *buf, size_t buflen, void *private_data)
return -1;
}
}
- return resp->length - 4;
+ return resp->length - buflen;
}
static void wb_resp_read_done(struct tevent_req *subreq)
{
- struct async_req *req = talloc_get_type_abort(
- subreq->async.private_data, struct async_req);
+ struct async_req *req =
+ tevent_req_callback_data(subreq, struct async_req);
struct resp_read_state *state = talloc_get_type_abort(
req->private_data, struct resp_read_state);
uint8_t *buf;
@@ -367,8 +364,7 @@ struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx,
if (subreq == NULL) {
goto fail;
}
- subreq->async.fn = wb_resp_write_done;
- subreq->async.private_data = result;
+ tevent_req_set_callback(subreq, wb_resp_write_done, result);
return result;
fail:
@@ -378,8 +374,8 @@ struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx,
static void wb_resp_write_done(struct tevent_req *subreq)
{
- struct async_req *req = talloc_get_type_abort(
- subreq->async.private_data, struct async_req);
+ struct async_req *req =
+ tevent_req_callback_data(subreq, struct async_req);
int err;
ssize_t ret;
diff --git a/source3/lib/wbclient.c b/source3/lib/wbclient.c
index b8d55a944a..7034e668ed 100644
--- a/source3/lib/wbclient.c
+++ b/source3/lib/wbclient.c
@@ -224,8 +224,7 @@ static struct async_req *wb_connect_send(TALLOC_CTX *mem_ctx,
if (subreq == NULL) {
goto nomem;
}
- subreq->async.fn = wbc_connect_connected;
- subreq->async.private_data = result;
+ tevent_req_set_callback(subreq, wbc_connect_connected, result);
if (!tevent_req_set_endtime(subreq, ev, timeval_current_ofs(30, 0))) {
goto nomem;
@@ -245,8 +244,8 @@ static struct async_req *wb_connect_send(TALLOC_CTX *mem_ctx,
static void wbc_connect_connected(struct tevent_req *subreq)
{
- struct async_req *req = talloc_get_type_abort(
- subreq->async.private_data, struct async_req);
+ struct async_req *req =
+ tevent_req_callback_data(subreq, struct async_req);
int res, err;
res = async_connect_recv(subreq, &err);