summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/access.c6
-rw-r--r--source3/lib/arc4.c79
-rw-r--r--source3/lib/charcnv.c58
-rw-r--r--source3/lib/ctdbd_conn.c8
-rw-r--r--source3/lib/data_blob.c180
-rw-r--r--source3/lib/dbwrap_ctdb.c4
-rw-r--r--source3/lib/dbwrap_file.c2
-rw-r--r--source3/lib/dbwrap_rbt.c2
-rw-r--r--source3/lib/dbwrap_tdb.c6
-rw-r--r--source3/lib/debug.c12
-rw-r--r--source3/lib/display_sec.c8
-rw-r--r--source3/lib/dprintf.c2
-rw-r--r--source3/lib/events.c2
-rw-r--r--source3/lib/fsusage.c157
-rw-r--r--source3/lib/genrand.c17
-rw-r--r--source3/lib/ldb/libldb.m432
-rw-r--r--source3/lib/memcache.c2
-rw-r--r--source3/lib/netapi/group.c2
-rw-r--r--source3/lib/netapi/localgroup.c4
-rw-r--r--source3/lib/packet.c12
-rw-r--r--source3/lib/rbtree.c422
-rw-r--r--source3/lib/select.c4
-rw-r--r--source3/lib/signal.c138
-rw-r--r--source3/lib/smbconf/smbconf_txt.c2
-rw-r--r--source3/lib/smbldap.c2
-rw-r--r--source3/lib/sysquotas.c6
-rw-r--r--source3/lib/sysquotas_4A.c16
-rw-r--r--source3/lib/sysquotas_linux.c48
-rw-r--r--source3/lib/sysquotas_xfs.c16
-rw-r--r--source3/lib/time.c558
-rw-r--r--source3/lib/util.c306
-rw-r--r--source3/lib/util_file.c352
-rw-r--r--source3/lib/util_pw.c4
-rw-r--r--source3/lib/util_sock.c12
-rw-r--r--source3/lib/util_str.c142
-rw-r--r--source3/lib/util_tdb.c297
-rw-r--r--source3/lib/util_uuid.c78
-rw-r--r--source3/lib/xfile.c417
38 files changed, 163 insertions, 3252 deletions
diff --git a/source3/lib/access.c b/source3/lib/access.c
index 6a445f8139..966d8ce87c 100644
--- a/source3/lib/access.c
+++ b/source3/lib/access.c
@@ -104,7 +104,7 @@ static bool string_match(const char *tok,const char *s)
if (memcache_lookup(
NULL, SINGLETON_CACHE,
- data_blob_string_const("yp_default_domain"),
+ data_blob_string_const_null("yp_default_domain"),
&tmp)) {
SMB_ASSERT(tmp.length > 0);
@@ -116,8 +116,8 @@ static bool string_match(const char *tok,const char *s)
memcache_add(
NULL, SINGLETON_CACHE,
- data_blob_string_const("yp_default_domain"),
- data_blob_string_const(mydomain?mydomain:""));
+ data_blob_string_const_null("yp_default_domain"),
+ data_blob_string_const_null(mydomain?mydomain:""));
}
if (!mydomain) {
diff --git a/source3/lib/arc4.c b/source3/lib/arc4.c
deleted file mode 100644
index af2564b6c0..0000000000
--- a/source3/lib/arc4.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- An implementation of arc4.
-
- Copyright (C) Jeremy Allison 2005.
-
- 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"
-
-/*****************************************************************
- Initialize state for an arc4 crypt/decrpyt.
- arc4 state is 258 bytes - last 2 bytes are the index bytes.
-*****************************************************************/
-
-void smb_arc4_init(unsigned char arc4_state_out[258], const unsigned char *key, size_t keylen)
-{
- size_t ind;
- unsigned char j = 0;
-
- for (ind = 0; ind < 256; ind++) {
- arc4_state_out[ind] = (unsigned char)ind;
- }
-
- for( ind = 0; ind < 256; ind++) {
- unsigned char tc;
-
- j += (arc4_state_out[ind] + key[ind%keylen]);
-
- tc = arc4_state_out[ind];
- arc4_state_out[ind] = arc4_state_out[j];
- arc4_state_out[j] = tc;
- }
- arc4_state_out[256] = 0;
- arc4_state_out[257] = 0;
-}
-
-/*****************************************************************
- Do the arc4 crypt/decrpyt.
- arc4 state is 258 bytes - last 2 bytes are the index bytes.
-*****************************************************************/
-
-void smb_arc4_crypt(unsigned char arc4_state_inout[258], unsigned char *data, size_t len)
-{
- unsigned char index_i = arc4_state_inout[256];
- unsigned char index_j = arc4_state_inout[257];
- size_t ind;
-
- for( ind = 0; ind < len; ind++) {
- unsigned char tc;
- unsigned char t;
-
- index_i++;
- index_j += arc4_state_inout[index_i];
-
- tc = arc4_state_inout[index_i];
- arc4_state_inout[index_i] = arc4_state_inout[index_j];
- arc4_state_inout[index_j] = tc;
-
- t = arc4_state_inout[index_i] + arc4_state_inout[index_j];
- data[ind] = data[ind] ^ arc4_state_inout[t];
- }
-
- arc4_state_inout[256] = index_i;
- arc4_state_inout[257] = index_j;
-}
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 485212b100..3ec3220900 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -1166,7 +1166,7 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx,
int flags)
{
char *dest = NULL;
- size_t converted_size;
+ size_t dest_len;
#ifdef DEVELOPER
/* Ensure we never use the braindead "malloc" varient. */
@@ -1177,6 +1177,10 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx,
*ppdest = NULL;
+ if (!src_len) {
+ return 0;
+ }
+
if (flags & STR_TERMINATE) {
if (src_len == (size_t)-1) {
src_len = strlen((const char *)src) + 1;
@@ -1194,18 +1198,41 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx,
(unsigned int)src_len);
smb_panic(msg);
}
+ } else {
+ /* Can't have an unlimited length
+ * non STR_TERMINATE'd.
+ */
+ if (src_len == (size_t)-1) {
+ errno = EINVAL;
+ return 0;
+ }
}
+ /* src_len != -1 here. */
+
if (!convert_string_allocate(ctx, CH_DOS, CH_UNIX, src, src_len, &dest,
- &converted_size, True))
- {
- converted_size = 0;
+ &dest_len, True)) {
+ dest_len = 0;
}
- if (converted_size && dest) {
+ if (dest_len && dest) {
/* Did we already process the terminating zero ? */
- if (dest[converted_size - 1] != 0) {
- dest[converted_size - 1] = 0;
+ if (dest[dest_len-1] != 0) {
+ size_t size = talloc_get_size(dest);
+ /* Have we got space to append the '\0' ? */
+ if (size <= dest_len) {
+ /* No, realloc. */
+ dest = TALLOC_REALLOC_ARRAY(ctx, dest, char,
+ dest_len+1);
+ if (!dest) {
+ /* talloc fail. */
+ dest_len = (size_t)-1;
+ return 0;
+ }
+ }
+ /* Yay - space ! */
+ dest[dest_len] = '\0';
+ dest_len++;
}
} else if (dest) {
dest[0] = 0;
@@ -1562,21 +1589,26 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx,
if (src_len >= 1024*1024) {
smb_panic("Bad src length in pull_ucs2_base_talloc\n");
}
+ } else {
+ /* Can't have an unlimited length
+ * non STR_TERMINATE'd.
+ */
+ if (src_len == (size_t)-1) {
+ errno = EINVAL;
+ return 0;
+ }
}
+ /* src_len != -1 here. */
+
/* ucs2 is always a multiple of 2 bytes */
- if (src_len != (size_t)-1) {
- src_len &= ~1;
- }
+ src_len &= ~1;
if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len,
(void *)&dest, &dest_len, True)) {
dest_len = 0;
}
- if (src_len == (size_t)-1)
- src_len = dest_len*2;
-
if (dest_len) {
/* Did we already process the terminating zero ? */
if (dest[dest_len-1] != 0) {
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 5075476e94..10a65c5bcc 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -155,7 +155,7 @@ static NTSTATUS ctdbd_connect(TALLOC_CTX *mem_ctx,
* Do we have a complete ctdb packet in the queue?
*/
-static bool ctdb_req_complete(const struct data_blob *data,
+static bool ctdb_req_complete(const DATA_BLOB *data,
size_t *length,
void *private_data)
{
@@ -220,7 +220,7 @@ struct req_pull_state {
* Pull a ctdb request out of the incoming packet queue
*/
-static NTSTATUS ctdb_req_pull(const struct data_blob *data,
+static NTSTATUS ctdb_req_pull(const DATA_BLOB *data,
void *private_data)
{
struct req_pull_state *state = (struct req_pull_state *)private_data;
@@ -497,7 +497,7 @@ NTSTATUS ctdbd_messaging_connection(TALLOC_CTX *mem_ctx,
/*
* Packet handler to receive and handle a ctdb message
*/
-static NTSTATUS ctdb_handle_message(const struct data_blob *data,
+static NTSTATUS ctdb_handle_message(const DATA_BLOB *data,
void *private_data)
{
struct ctdbd_connection *conn = talloc_get_type_abort(
@@ -1025,7 +1025,7 @@ struct ctdbd_traverse_state {
* Handle a traverse record coming in on the ctdbd connection
*/
-static NTSTATUS ctdb_traverse_handler(const struct data_blob *blob,
+static NTSTATUS ctdb_traverse_handler(const DATA_BLOB *blob,
void *private_data)
{
struct ctdbd_traverse_state *state =
diff --git a/source3/lib/data_blob.c b/source3/lib/data_blob.c
deleted file mode 100644
index 66c5daf363..0000000000
--- a/source3/lib/data_blob.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Easy management of byte-length data
- Copyright (C) Andrew Tridgell 2001
- Copyright (C) Andrew Bartlett 2001
-
- 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"
-
-const DATA_BLOB data_blob_null = { NULL, 0, NULL };
-
-/*******************************************************************
- Free() a data blob.
-*******************************************************************/
-
-static void free_data_blob(DATA_BLOB *d)
-{
- if ((d) && (d->free)) {
- SAFE_FREE(d->data);
- }
-}
-
-/*******************************************************************
- Construct a data blob, must be freed with data_blob_free().
- You can pass NULL for p and get a blank data blob
-*******************************************************************/
-
-DATA_BLOB data_blob(const void *p, size_t length)
-{
- DATA_BLOB ret;
-
- if (!length) {
- ZERO_STRUCT(ret);
- return ret;
- }
-
- if (p) {
- ret.data = (uint8 *)smb_xmemdup(p, length);
- } else {
- ret.data = SMB_XMALLOC_ARRAY(uint8, length);
- }
- ret.length = length;
- ret.free = free_data_blob;
- return ret;
-}
-
-/*******************************************************************
- Construct a data blob, using supplied TALLOC_CTX.
-*******************************************************************/
-
-DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length)
-{
- DATA_BLOB ret;
-
- if (!length) {
- ZERO_STRUCT(ret);
- return ret;
- }
-
- if (p) {
- ret.data = (uint8 *)TALLOC_MEMDUP(mem_ctx, p, length);
- if (ret.data == NULL)
- smb_panic("data_blob_talloc: TALLOC_MEMDUP failed");
- } else {
- ret.data = (uint8 *)TALLOC(mem_ctx, length);
- if (ret.data == NULL)
- smb_panic("data_blob_talloc: TALLOC failed");
- }
-
- ret.length = length;
- ret.free = NULL;
- return ret;
-}
-
-/*******************************************************************
- Free a data blob.
-*******************************************************************/
-
-void data_blob_free(DATA_BLOB *d)
-{
- if (d) {
- if (d->free) {
- (d->free)(d);
- }
- d->length = 0;
- }
-}
-
-/*******************************************************************
- Clear a DATA_BLOB's contents
-*******************************************************************/
-
-void data_blob_clear(DATA_BLOB *d)
-{
- if (d->data) {
- memset(d->data, 0, d->length);
- }
-}
-
-/*******************************************************************
- Free a data blob and clear its contents
-*******************************************************************/
-
-void data_blob_clear_free(DATA_BLOB *d)
-{
- data_blob_clear(d);
- data_blob_free(d);
-}
-
-/**
- useful for constructing data blobs in test suites, while
- avoiding const warnings
-**/
-DATA_BLOB data_blob_string_const(const char *str)
-{
- DATA_BLOB blob;
- blob.data = CONST_DISCARD(uint8 *, str);
- blob.length = strlen(str) + 1;
- blob.free = NULL;
- return blob;
-}
-
-/**
- * Create a new data blob from const data
- */
-DATA_BLOB data_blob_const(const void *p, size_t length)
-{
- DATA_BLOB blob;
- blob.data = CONST_DISCARD(uint8 *, p);
- blob.length = length;
- blob.free = NULL;
- return blob;
-}
-
-/**
- construct a zero data blob, using supplied TALLOC_CTX.
- use this sparingly as it initialises data - better to initialise
- yourself if you want specific data in the blob
-**/
-DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length)
-{
- DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, length);
- data_blob_clear(&blob);
- return blob;
-}
-
-/**
-print the data_blob as hex string
-**/
-_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
-{
- int i;
- char *hex_string;
-
- hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1);
- if (!hex_string) {
- return NULL;
- }
-
- for (i = 0; i < blob->length; i++)
- slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]);
-
- hex_string[(blob->length*2)] = '\0';
- return hex_string;
-}
-
-
diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c
index 2818634b14..38daa61b33 100644
--- a/source3/lib/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap_ctdb.c
@@ -821,7 +821,7 @@ static int db_ctdb_record_destr(struct db_record* data)
? "Unlocking db %u key %s\n"
: "Unlocking db %u key %.20s\n",
(int)crec->ctdb_ctx->db_id,
- hex_encode(data, (unsigned char *)data->key.dptr,
+ hex_encode_talloc(data, (unsigned char *)data->key.dptr,
data->key.dsize)));
if (tdb_chainunlock(crec->ctdb_ctx->wtdb->tdb, data->key) != 0) {
@@ -871,7 +871,7 @@ static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx,
again:
if (DEBUGLEVEL >= 10) {
- char *keystr = hex_encode(result, key.dptr, key.dsize);
+ char *keystr = hex_encode_talloc(result, key.dptr, key.dsize);
DEBUG(10, (DEBUGLEVEL > 10
? "Locking db %u key %s\n"
: "Locking db %u key %.20s\n",
diff --git a/source3/lib/dbwrap_file.c b/source3/lib/dbwrap_file.c
index e3779de1e4..69ad8e4b20 100644
--- a/source3/lib/dbwrap_file.c
+++ b/source3/lib/dbwrap_file.c
@@ -105,7 +105,7 @@ static struct db_record *db_file_fetch_locked(struct db_context *db,
/* Cut to 8 bits */
file->hash = fsh(key.dptr, key.dsize);
- file->name = hex_encode(file, (unsigned char *)key.dptr, key.dsize);
+ file->name = hex_encode_talloc(file, (unsigned char *)key.dptr, key.dsize);
if (file->name == NULL) {
DEBUG(0, ("hex_encode failed\n"));
TALLOC_FREE(result);
diff --git a/source3/lib/dbwrap_rbt.c b/source3/lib/dbwrap_rbt.c
index b70ce3dfa0..6e09627223 100644
--- a/source3/lib/dbwrap_rbt.c
+++ b/source3/lib/dbwrap_rbt.c
@@ -18,7 +18,7 @@
*/
#include "includes.h"
-#include "rbtree.h"
+#include "../lib/util/rbtree.h"
#define DBWRAP_RBT_ALIGN(_size_) (((_size_)+15)&~15)
diff --git a/source3/lib/dbwrap_tdb.c b/source3/lib/dbwrap_tdb.c
index 7bdadd3770..4860c61ab0 100644
--- a/source3/lib/dbwrap_tdb.c
+++ b/source3/lib/dbwrap_tdb.c
@@ -31,14 +31,14 @@ static int db_tdb_record_destr(struct db_record* data)
struct db_tdb_ctx *ctx =
talloc_get_type_abort(data->private_data, struct db_tdb_ctx);
- /* This hex_encode() call allocates memory on data context. By way how current
+ /* This hex_encode_talloc() call allocates memory on data context. By way how current
__talloc_free() code works, it is OK to allocate in the destructor as
the children of data will be freed after call to the destructor and this
new 'child' will be caught and freed correctly.
*/
DEBUG(10, (DEBUGLEVEL > 10
? "Unlocking key %s\n" : "Unlocking key %.20s\n",
- hex_encode(data, (unsigned char *)data->key.dptr,
+ hex_encode_talloc(data, (unsigned char *)data->key.dptr,
data->key.dsize)));
if (tdb_chainunlock(ctx->wtdb->tdb, data->key) != 0) {
@@ -94,7 +94,7 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db,
/* Do not accidently allocate/deallocate w/o need when debug level is lower than needed */
if(DEBUGLEVEL >= 10) {
- char *keystr = hex_encode(NULL, (unsigned char*)key.dptr, key.dsize);
+ char *keystr = hex_encode_talloc(NULL, (unsigned char*)key.dptr, key.dsize);
DEBUG(10, (DEBUGLEVEL > 10
? "Locking key %s\n" : "Locking key %.20s\n",
keystr));
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index d91b55dd23..be2707b595 100644
--- a/source3/lib/debug.c
+++ b/source3/lib/debug.c
@@ -984,7 +984,7 @@ void dbgflush( void )
****************************************************************************/
-bool dbghdr(int level, int cls, const char *file, const char *func, int line)
+bool dbghdrclass(int level, int cls, const char *location, const char *func)
{
/* Ensure we don't lose any real errno value. */
int old_errno = errno;
@@ -1046,10 +1046,10 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line)
lp_debug_hires_timestamp()),
level, header_str);
} else {
- (void)Debug1( "[%s, %2d%s] %s:%s(%d)\n",
+ (void)Debug1( "[%s, %2d%s] %s(%s)\n",
current_timestring(debug_ctx(),
lp_debug_hires_timestamp()),
- level, header_str, file, func, line );
+ level, header_str, location, func );
}
}
@@ -1057,6 +1057,12 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line)
return( True );
}
+bool dbghdr(int level, const char *location, const char *func)
+{
+ /* For compatibility with Samba 4, which doesn't have debug classes */
+ return dbghdrclass(level, 0, location, func);
+}
+
/***************************************************************************
Add text to the body of the "current" debug message via the format buffer.
diff --git a/source3/lib/display_sec.c b/source3/lib/display_sec.c
index 5427a8173e..a0d93d6fe7 100644
--- a/source3/lib/display_sec.c
+++ b/source3/lib/display_sec.c
@@ -157,13 +157,13 @@ 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");
- printf("Object GUID: %s\n", smb_uuid_string(talloc_tos(),
- object->type.type));
+ 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");
- printf("Object GUID: %s\n", smb_uuid_string(talloc_tos(),
- object->inherited_type.inherited_type));
+ printf("Object GUID: %s\n", GUID_string(talloc_tos(),
+ &object->inherited_type.inherited_type));
}
}
diff --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c
index a3bb5be43a..b3c830dd5b 100644
--- a/source3/lib/dprintf.c
+++ b/source3/lib/dprintf.c
@@ -41,7 +41,7 @@
msgstr = lang_msg(format);
if (!msgstr) return -1;
- VA_COPY(ap2, ap);
+ va_copy(ap2, ap);
ret = vasprintf(&p, msgstr, ap2);
diff --git a/source3/lib/events.c b/source3/lib/events.c
index f03138708b..8bbc9497ac 100644
--- a/source3/lib/events.c
+++ b/source3/lib/events.c
@@ -436,7 +436,7 @@ void dump_event_list(struct event_context *event_ctx)
te->event_name,
(unsigned long)te,
(int)evt.tv_sec,
- http_timestring(te->when.tv_sec)));
+ http_timestring(talloc_tos(), te->when.tv_sec)));
}
for (fe = event_ctx->fd_events; fe; fe = fe->next) {
diff --git a/source3/lib/fsusage.c b/source3/lib/fsusage.c
deleted file mode 100644
index 66ffb9f442..0000000000
--- a/source3/lib/fsusage.c
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- functions to calculate the free disk space
- Copyright (C) Andrew Tridgell 1998-2000
-
- 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"
-
-
-/* Return the number of TOSIZE-byte blocks used by
- BLOCKS FROMSIZE-byte blocks, rounding away from zero.
-*/
-static SMB_BIG_UINT adjust_blocks(SMB_BIG_UINT blocks, SMB_BIG_UINT fromsize, SMB_BIG_UINT tosize)
-{
- if (fromsize == tosize) { /* e.g., from 512 to 512 */
- return blocks;
- } else if (fromsize > tosize) { /* e.g., from 2048 to 512 */
- return blocks * (fromsize / tosize);
- } else { /* e.g., from 256 to 512 */
- /* Protect against broken filesystems... */
- if (fromsize == 0) {
- fromsize = tosize;
- }
- return (blocks + 1) / (tosize / fromsize);
- }
-}
-
-/* this does all of the system specific guff to get the free disk space.
- It is derived from code in the GNU fileutils package, but has been
- considerably mangled for use here
-
- results are returned in *dfree and *dsize, in 512 byte units
-*/
-int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
-{
-#ifdef STAT_STATFS3_OSF1
-#define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_fsize, (SMB_BIG_UINT)512)
- struct statfs fsd;
-
- if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
- return -1;
-#endif /* STAT_STATFS3_OSF1 */
-
-#ifdef STAT_STATFS2_FS_DATA /* Ultrix */
-#define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)1024, (SMB_BIG_UINT)512)
- struct fs_data fsd;
-
- if (statfs (path, &fsd) != 1)
- return -1;
-
- (*dsize) = CONVERT_BLOCKS (fsd.fd_req.btot);
- (*dfree) = CONVERT_BLOCKS (fsd.fd_req.bfreen);
-#endif /* STAT_STATFS2_FS_DATA */
-
-#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
-#define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
- struct statfs fsd;
-
- if (statfs (path, &fsd) < 0)
- return -1;
-
-#ifdef STATFS_TRUNCATES_BLOCK_COUNTS
- /* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the
- struct statfs are truncated to 2GB. These conditions detect that
- truncation, presumably without botching the 4.1.1 case, in which
- the values are not truncated. The correct counts are stored in
- undocumented spare fields. */
- if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0) {
- fsd.f_blocks = fsd.f_spare[0];
- fsd.f_bfree = fsd.f_spare[1];
- fsd.f_bavail = fsd.f_spare[2];
- }
-#endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
-#endif /* STAT_STATFS2_BSIZE */
-
-
-#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */
-#define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_fsize, (SMB_BIG_UINT)512)
-
- struct statfs fsd;
-
- if (statfs (path, &fsd) < 0)
- return -1;
-#endif /* STAT_STATFS2_FSIZE */
-
-#ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */
-# if _AIX || defined(_CRAY)
-# define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
-# ifdef _CRAY
-# define f_bavail f_bfree
-# endif
-# else
-# define CONVERT_BLOCKS(B) ((SMB_BIG_UINT)B)
-# ifndef _SEQUENT_ /* _SEQUENT_ is DYNIX/ptx */
-# ifndef DOLPHIN /* DOLPHIN 3.8.alfa/7.18 has f_bavail */
-# define f_bavail f_bfree
-# endif
-# endif
-# endif
-
- struct statfs fsd;
-
- if (statfs (path, &fsd, sizeof fsd, 0) < 0)
- return -1;
- /* Empirically, the block counts on most SVR3 and SVR3-derived
- systems seem to always be in terms of 512-byte blocks,
- no matter what value f_bsize has. */
-
-#endif /* STAT_STATFS4 */
-
-#if defined(STAT_STATVFS) || defined(STAT_STATVFS64) /* SVR4 */
-#if defined HAVE_FRSIZE
-# define CONVERT_BLOCKS(B) \
- adjust_blocks ((SMB_BIG_UINT)(B), fsd.f_frsize ? (SMB_BIG_UINT)fsd.f_frsize : (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
-#else
-# define CONVERT_BLOCKS(B) \
- adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
-#endif
-
-#ifdef STAT_STATVFS64
- struct statvfs64 fsd;
- if (statvfs64(path, &fsd) < 0) return -1;
-#else
- struct statvfs fsd;
- if (statvfs(path, &fsd) < 0) return -1;
-#endif
-
- /* f_frsize isn't guaranteed to be supported. */
-
-#endif /* STAT_STATVFS */
-
-#ifndef CONVERT_BLOCKS
- /* we don't have any dfree code! */
- return -1;
-#else
-#if !defined(STAT_STATFS2_FS_DATA)
- /* !Ultrix */
- (*dsize) = CONVERT_BLOCKS (fsd.f_blocks);
- (*dfree) = CONVERT_BLOCKS (fsd.f_bavail);
-#endif /* not STAT_STATFS2_FS_DATA */
-#endif
-
- return 0;
-}
diff --git a/source3/lib/genrand.c b/source3/lib/genrand.c
index 4590b812c5..076a2fd518 100644
--- a/source3/lib/genrand.c
+++ b/source3/lib/genrand.c
@@ -21,7 +21,7 @@
#include "includes.h"
-static unsigned char smb_arc4_state[258];
+static struct arcfour_state smb_arc4_state;
static uint32 counter;
static bool done_reseed = False;
@@ -89,6 +89,7 @@ static void do_filehash(const char *fname, unsigned char *the_hash)
static int do_reseed(bool use_fd, int fd)
{
unsigned char seed_inbuf[40];
+ DATA_BLOB seed_blob = { seed_inbuf, 40 };
uint32 v1, v2; struct timeval tval; pid_t mypid;
struct passwd *pw;
int reseed_data = 0;
@@ -146,7 +147,7 @@ static int do_reseed(bool use_fd, int fd)
seed_inbuf[i] ^= ((char *)(&reseed_data))[i % sizeof(reseed_data)];
}
- smb_arc4_init(smb_arc4_state, seed_inbuf, sizeof(seed_inbuf));
+ arcfour_init(&smb_arc4_state, &seed_blob);
return -1;
}
@@ -155,7 +156,7 @@ static int do_reseed(bool use_fd, int fd)
Interface to the (hopefully) good crypto random number generator.
********************************************************************/
-void generate_random_buffer( unsigned char *out, int len)
+void generate_random_buffer(uint8_t *out, int len)
{
static int urand_fd = -1;
unsigned char md4_buf[64];
@@ -190,7 +191,7 @@ void generate_random_buffer( unsigned char *out, int len)
while(len > 0) {
int copy_len = len > 16 ? 16 : len;
- smb_arc4_crypt(smb_arc4_state, md4_buf, sizeof(md4_buf));
+ arcfour_crypt_sbox(&smb_arc4_state, md4_buf, sizeof(md4_buf));
mdfour(tmp_buf, md4_buf, sizeof(md4_buf));
memcpy(p, tmp_buf, copy_len);
p += copy_len;
@@ -204,15 +205,11 @@ void generate_random_buffer( unsigned char *out, int len)
static char c_list[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,";
-char *generate_random_str(size_t len)
+char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len)
{
- static unsigned char retstr[256];
+ unsigned char *retstr = talloc_zero_array(mem_ctx, unsigned char, len);
size_t i;
- memset(retstr, '\0', sizeof(retstr));
-
- if (len > sizeof(retstr)-1)
- len = sizeof(retstr) -1;
generate_random_buffer( retstr, len);
for (i = 0; i < len; i++)
retstr[i] = c_list[ retstr[i] % (sizeof(c_list)-1) ];
diff --git a/source3/lib/ldb/libldb.m4 b/source3/lib/ldb/libldb.m4
index 845563b4a1..df2075d4e3 100644
--- a/source3/lib/ldb/libldb.m4
+++ b/source3/lib/ldb/libldb.m4
@@ -1,33 +1 @@
SMB_ENABLE(ldb_sqlite3,$with_sqlite3_support)
-
-AC_MSG_CHECKING([for Python])
-
-PYTHON=
-
-AC_ARG_WITH(python,
-[ --with-python=PYTHONNAME build Python libraries],
-[ case "${withval-python}" in
- yes)
- PYTHON=python
- ;;
- no)
- PYTHON=
- ;;
- *)
- PYTHON=${withval-python}
- ;;
- esac ])
-
-if test x"$PYTHON" != "x"; then
- incdir=`python -c 'import sys; print "%s/include/python%d.%d" % (sys.prefix, sys.version_info[[0]], sys.version_info[[1]])'`
- CPPFLAGS="$CPPFLAGS -I $incdir"
-fi
-
-if test x"$PYTHON" != "x"; then
- AC_MSG_RESULT([${withval-python}])
-else
- AC_MSG_RESULT(no)
- SMB_ENABLE(swig_ldb, NO)
-fi
-
-AC_SUBST(PYTHON)
diff --git a/source3/lib/memcache.c b/source3/lib/memcache.c
index e1426bc811..9c892fedfa 100644
--- a/source3/lib/memcache.c
+++ b/source3/lib/memcache.c
@@ -18,7 +18,7 @@
*/
#include "memcache.h"
-#include "rbtree.h"
+#include "../lib/util/rbtree.h"
static struct memcache *global_cache;
diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c
index c3fccb4840..8dba4b8838 100644
--- a/source3/lib/netapi/group.c
+++ b/source3/lib/netapi/group.c
@@ -1224,7 +1224,7 @@ WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx,
}
if (r->out.total_entries) {
- *r->out.total_entries = domain_info->info2.num_groups;
+ *r->out.total_entries = domain_info->general.num_groups;
}
status = rpccli_samr_QueryDisplayInfo2(pipe_cli,
diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c
index 25a3427bc1..5e738e1262 100644
--- a/source3/lib/netapi/localgroup.c
+++ b/source3/lib/netapi/localgroup.c
@@ -822,7 +822,7 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx,
}
if (r->out.total_entries) {
- *r->out.total_entries += builtin_info->info2.num_aliases;
+ *r->out.total_entries += builtin_info->general.num_aliases;
}
status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx,
@@ -835,7 +835,7 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx,
}
if (r->out.total_entries) {
- *r->out.total_entries += domain_info->info2.num_aliases;
+ *r->out.total_entries += domain_info->general.num_aliases;
}
status = rpccli_samr_EnumDomainAliases(pipe_cli, ctx,
diff --git a/source3/lib/packet.c b/source3/lib/packet.c
index e0486165f3..e4cab6ba87 100644
--- a/source3/lib/packet.c
+++ b/source3/lib/packet.c
@@ -21,7 +21,7 @@
struct packet_context {
int fd;
- struct data_blob in, out;
+ DATA_BLOB in, out;
};
/*
@@ -120,16 +120,16 @@ NTSTATUS packet_fd_read_sync(struct packet_context *ctx)
}
bool packet_handler(struct packet_context *ctx,
- bool (*full_req)(const struct data_blob *data,
+ bool (*full_req)(const DATA_BLOB *data,
size_t *length,
void *private_data),
- NTSTATUS (*callback)(const struct data_blob *data,
+ NTSTATUS (*callback)(const DATA_BLOB *data,
void *private_data),
void *private_data,
NTSTATUS *status)
{
size_t length;
- struct data_blob data;
+ DATA_BLOB data;
if (!full_req(&ctx->in, &length, private_data)) {
return False;
@@ -211,7 +211,7 @@ NTSTATUS packet_send(struct packet_context *ctx, int num_blobs, ...)
va_start(ap, num_blobs);
for (i=0; i<num_blobs; i++) {
size_t tmp;
- struct data_blob blob = va_arg(ap, struct data_blob);
+ DATA_BLOB blob = va_arg(ap, DATA_BLOB);
tmp = len + blob.length;
if (tmp < len) {
@@ -236,7 +236,7 @@ NTSTATUS packet_send(struct packet_context *ctx, int num_blobs, ...)
va_start(ap, num_blobs);
for (i=0; i<num_blobs; i++) {
- struct data_blob blob = va_arg(ap, struct data_blob);
+ DATA_BLOB blob = va_arg(ap, DATA_BLOB);
memcpy(ctx->out.data+ctx->out.length, blob.data, blob.length);
ctx->out.length += blob.length;
diff --git a/source3/lib/rbtree.c b/source3/lib/rbtree.c
deleted file mode 100644
index f6868cab5d..0000000000
--- a/source3/lib/rbtree.c
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- Red Black Trees
- (C) 1999 Andrea Arcangeli <andrea@suse.de>
- (C) 2002 David Woodhouse <dwmw2@infradead.org>
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- linux/lib/rbtree.c
-*/
-
-#include "includes.h"
-#include "rbtree.h"
-
-#define RB_RED 0
-#define RB_BLACK 1
-
-#define rb_parent(r) ((struct rb_node *)((r)->rb_parent_color & ~3))
-#define rb_color(r) ((r)->rb_parent_color & 1)
-#define rb_is_red(r) (!rb_color(r))
-#define rb_is_black(r) rb_color(r)
-#define rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0)
-#define rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0)
-
-static void rb_set_parent(struct rb_node *rb, struct rb_node *p)
-{
- rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p;
-}
-static void rb_set_color(struct rb_node *rb, int color)
-{
- rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
-}
-
-#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
-#define RB_EMPTY_NODE(node) (rb_parent(node) == node)
-#define RB_CLEAR_NODE(node) (rb_set_parent(node, node))
-
-static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)
-{
- struct rb_node *right = node->rb_right;
- struct rb_node *parent = rb_parent(node);
-
- if ((node->rb_right = right->rb_left))
- rb_set_parent(right->rb_left, node);
- right->rb_left = node;
-
- rb_set_parent(right, parent);
-
- if (parent)
- {
- if (node == parent->rb_left)
- parent->rb_left = right;
- else
- parent->rb_right = right;
- }
- else
- root->rb_node = right;
- rb_set_parent(node, right);
-}
-
-static void __rb_rotate_right(struct rb_node *node, struct rb_root *root)
-{
- struct rb_node *left = node->rb_left;
- struct rb_node *parent = rb_parent(node);
-
- if ((node->rb_left = left->rb_right))
- rb_set_parent(left->rb_right, node);
- left->rb_right = node;
-
- rb_set_parent(left, parent);
-
- if (parent)
- {
- if (node == parent->rb_right)
- parent->rb_right = left;
- else
- parent->rb_left = left;
- }
- else
- root->rb_node = left;
- rb_set_parent(node, left);
-}
-
-void rb_insert_color(struct rb_node *node, struct rb_root *root)
-{
- struct rb_node *parent, *gparent;
-
- while ((parent = rb_parent(node)) && rb_is_red(parent))
- {
- gparent = rb_parent(parent);
-
- if (parent == gparent->rb_left)
- {
- {
- register struct rb_node *uncle = gparent->rb_right;
- if (uncle && rb_is_red(uncle))
- {
- rb_set_black(uncle);
- rb_set_black(parent);
- rb_set_red(gparent);
- node = gparent;
- continue;
- }
- }
-
- if (parent->rb_right == node)
- {
- register struct rb_node *tmp;
- __rb_rotate_left(parent, root);
- tmp = parent;
- parent = node;
- node = tmp;
- }
-
- rb_set_black(parent);
- rb_set_red(gparent);
- __rb_rotate_right(gparent, root);
- } else {
- {
- register struct rb_node *uncle = gparent->rb_left;
- if (uncle && rb_is_red(uncle))
- {
- rb_set_black(uncle);
- rb_set_black(parent);
- rb_set_red(gparent);
- node = gparent;
- continue;
- }
- }
-
- if (parent->rb_left == node)
- {
- register struct rb_node *tmp;
- __rb_rotate_right(parent, root);
- tmp = parent;
- parent = node;
- node = tmp;
- }
-
- rb_set_black(parent);
- rb_set_red(gparent);
- __rb_rotate_left(gparent, root);
- }
- }
-
- rb_set_black(root->rb_node);
-}
-
-static void __rb_erase_color(struct rb_node *node, struct rb_node *parent,
- struct rb_root *root)
-{
- struct rb_node *other;
-
- while ((!node || rb_is_black(node)) && node != root->rb_node)
- {
- if (parent->rb_left == node)
- {
- other = parent->rb_right;
- if (rb_is_red(other))
- {
- rb_set_black(other);
- rb_set_red(parent);
- __rb_rotate_left(parent, root);
- other = parent->rb_right;
- }
- if ((!other->rb_left || rb_is_black(other->rb_left)) &&
- (!other->rb_right || rb_is_black(other->rb_right)))
- {
- rb_set_red(other);
- node = parent;
- parent = rb_parent(node);
- }
- else
- {
- if (!other->rb_right || rb_is_black(other->rb_right))
- {
- struct rb_node *o_left;
- if ((o_left = other->rb_left))
- rb_set_black(o_left);
- rb_set_red(other);
- __rb_rotate_right(other, root);
- other = parent->rb_right;
- }
- rb_set_color(other, rb_color(parent));
- rb_set_black(parent);
- if (other->rb_right)
- rb_set_black(other->rb_right);
- __rb_rotate_left(parent, root);
- node = root->rb_node;
- break;
- }
- }
- else
- {
- other = parent->rb_left;
- if (rb_is_red(other))
- {
- rb_set_black(other);
- rb_set_red(parent);
- __rb_rotate_right(parent, root);
- other = parent->rb_left;
- }
- if ((!other->rb_left || rb_is_black(other->rb_left)) &&
- (!other->rb_right || rb_is_black(other->rb_right)))
- {
- rb_set_red(other);
- node = parent;
- parent = rb_parent(node);
- }
- else
- {
- if (!other->rb_left || rb_is_black(other->rb_left))
- {
- register struct rb_node *o_right;
- if ((o_right = other->rb_right))
- rb_set_black(o_right);
- rb_set_red(other);
- __rb_rotate_left(other, root);
- other = parent->rb_left;
- }
- rb_set_color(other, rb_color(parent));
- rb_set_black(parent);
- if (other->rb_left)
- rb_set_black(other->rb_left);
- __rb_rotate_right(parent, root);
- node = root->rb_node;
- break;
- }
- }
- }
- if (node)
- rb_set_black(node);
-}
-
-void rb_erase(struct rb_node *node, struct rb_root *root)
-{
- struct rb_node *child, *parent;
- int color;
-
- if (!node->rb_left)
- child = node->rb_right;
- else if (!node->rb_right)
- child = node->rb_left;
- else
- {
- struct rb_node *old = node, *left;
-
- node = node->rb_right;
- while ((left = node->rb_left) != NULL)
- node = left;
- child = node->rb_right;
- parent = rb_parent(node);
- color = rb_color(node);
-
- if (child)
- rb_set_parent(child, parent);
- if (parent == old) {
- parent->rb_right = child;
- parent = node;
- } else
- parent->rb_left = child;
-
- node->rb_parent_color = old->rb_parent_color;
- node->rb_right = old->rb_right;
- node->rb_left = old->rb_left;
-
- if (rb_parent(old))
- {
- if (rb_parent(old)->rb_left == old)
- rb_parent(old)->rb_left = node;
- else
- rb_parent(old)->rb_right = node;
- } else
- root->rb_node = node;
-
- rb_set_parent(old->rb_left, node);
- if (old->rb_right)
- rb_set_parent(old->rb_right, node);
- goto color;
- }
-
- parent = rb_parent(node);
- color = rb_color(node);
-
- if (child)
- rb_set_parent(child, parent);
- if (parent)
- {
- if (parent->rb_left == node)
- parent->rb_left = child;
- else
- parent->rb_right = child;
- }
- else
- root->rb_node = child;
-
- color:
- if (color == RB_BLACK)
- __rb_erase_color(child, parent, root);
-}
-
-/*
- * This function returns the first node (in sort order) of the tree.
- */
-struct rb_node *rb_first(struct rb_root *root)
-{
- struct rb_node *n;
-
- n = root->rb_node;
- if (!n)
- return NULL;
- while (n->rb_left)
- n = n->rb_left;
- return n;
-}
-
-struct rb_node *rb_last(struct rb_root *root)
-{
- struct rb_node *n;
-
- n = root->rb_node;
- if (!n)
- return NULL;
- while (n->rb_right)
- n = n->rb_right;
- return n;
-}
-
-struct rb_node *rb_next(struct rb_node *node)
-{
- struct rb_node *parent;
-
- if (rb_parent(node) == node)
- return NULL;
-
- /* If we have a right-hand child, go down and then left as far
- as we can. */
- if (node->rb_right) {
- node = node->rb_right;
- while (node->rb_left)
- node=node->rb_left;
- return node;
- }
-
- /* No right-hand children. Everything down and left is
- smaller than us, so any 'next' node must be in the general
- direction of our parent. Go up the tree; any time the
- ancestor is a right-hand child of its parent, keep going
- up. First time it's a left-hand child of its parent, said
- parent is our 'next' node. */
- while ((parent = rb_parent(node)) && node == parent->rb_right)
- node = parent;
-
- return parent;
-}
-
-struct rb_node *rb_prev(struct rb_node *node)
-{
- struct rb_node *parent;
-
- if (rb_parent(node) == node)
- return NULL;
-
- /* If we have a left-hand child, go down and then right as far
- as we can. */
- if (node->rb_left) {
- node = node->rb_left;
- while (node->rb_right)
- node=node->rb_right;
- return node;
- }
-
- /* No left-hand children. Go up till we find an ancestor which
- is a right-hand child of its parent */
- while ((parent = rb_parent(node)) && node == parent->rb_left)
- node = parent;
-
- return parent;
-}
-
-void rb_replace_node(struct rb_node *victim, struct rb_node *new_node,
- struct rb_root *root)
-{
- struct rb_node *parent = rb_parent(victim);
-
- /* Set the surrounding nodes to point to the replacement */
- if (parent) {
- if (victim == parent->rb_left)
- parent->rb_left = new_node;
- else
- parent->rb_right = new_node;
- } else {
- root->rb_node = new_node;
- }
- if (victim->rb_left)
- rb_set_parent(victim->rb_left, new_node);
- if (victim->rb_right)
- rb_set_parent(victim->rb_right, new_node);
-
- /* Copy the pointers/colour from the victim to the replacement */
- *new_node = *victim;
-}
-
-void rb_link_node(struct rb_node * node, struct rb_node * parent,
- struct rb_node ** rb_link)
-{
- node->rb_parent_color = (unsigned long )parent;
- node->rb_left = node->rb_right = NULL;
-
- *rb_link = node;
-}
diff --git a/source3/lib/select.c b/source3/lib/select.c
index c3da6a9bba..14e59257ba 100644
--- a/source3/lib/select.c
+++ b/source3/lib/select.c
@@ -30,7 +30,7 @@
static pid_t initialised;
static int select_pipe[2];
-static VOLATILE unsigned pipe_written, pipe_read;
+static volatile unsigned pipe_written, pipe_read;
/*******************************************************************
Call this from all Samba signal handlers if you want to avoid a
@@ -161,7 +161,7 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf
errorfds_buf = *errorfds;
if (ptval && (errno == EINTR)) {
struct timeval now_time;
- SMB_BIG_INT tdif;
+ int64_t tdif;
GetTimeOfDay(&now_time);
tdif = usec_time_diff(&end_time, &now_time);
diff --git a/source3/lib/signal.c b/source3/lib/signal.c
deleted file mode 100644
index 4b1c95eb77..0000000000
--- a/source3/lib/signal.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- signal handling functions
-
- Copyright (C) Andrew Tridgell 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"
-
-/****************************************************************************
- Catch child exits and reap the child zombie status.
-****************************************************************************/
-
-static void sig_cld(int signum)
-{
- while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0)
- ;
-
- /*
- * Turns out it's *really* important not to
- * restore the signal handler here if we have real POSIX
- * signal handling. If we do, then we get the signal re-delivered
- * immediately - hey presto - instant loop ! JRA.
- */
-
-#if !defined(HAVE_SIGACTION)
- CatchSignal(SIGCLD, sig_cld);
-#endif
-}
-
-/****************************************************************************
-catch child exits - leave status;
-****************************************************************************/
-
-static void sig_cld_leave_status(int signum)
-{
- /*
- * Turns out it's *really* important not to
- * restore the signal handler here if we have real POSIX
- * signal handling. If we do, then we get the signal re-delivered
- * immediately - hey presto - instant loop ! JRA.
- */
-
-#if !defined(HAVE_SIGACTION)
- CatchSignal(SIGCLD, sig_cld_leave_status);
-#endif
-}
-
-/*******************************************************************
- Block sigs.
-********************************************************************/
-
-void BlockSignals(bool block,int signum)
-{
-#ifdef HAVE_SIGPROCMASK
- sigset_t set;
- sigemptyset(&set);
- sigaddset(&set,signum);
- sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL);
-#elif defined(HAVE_SIGBLOCK)
- if (block) {
- sigblock(sigmask(signum));
- } else {
- sigsetmask(siggetmask() & ~sigmask(signum));
- }
-#else
- /* yikes! This platform can't block signals? */
- static int done;
- if (!done) {
- DEBUG(0,("WARNING: No signal blocking available\n"));
- done=1;
- }
-#endif
-}
-
-/*******************************************************************
- Catch a signal. This should implement the following semantics:
-
- 1) The handler remains installed after being called.
- 2) The signal should be blocked during handler execution.
-********************************************************************/
-
-void (*CatchSignal(int signum,void (*handler)(int )))(int)
-{
-#ifdef HAVE_SIGACTION
- struct sigaction act;
- struct sigaction oldact;
-
- ZERO_STRUCT(act);
-
- act.sa_handler = handler;
-#ifdef SA_RESTART
- /*
- * We *want* SIGALRM to interrupt a system call.
- */
- if(signum != SIGALRM)
- act.sa_flags = SA_RESTART;
-#endif
- sigemptyset(&act.sa_mask);
- sigaddset(&act.sa_mask,signum);
- sigaction(signum,&act,&oldact);
- return oldact.sa_handler;
-#else /* !HAVE_SIGACTION */
- /* FIXME: need to handle sigvec and systems with broken signal() */
- return signal(signum, handler);
-#endif
-}
-
-/*******************************************************************
- Ignore SIGCLD via whatever means is necessary for this OS.
-********************************************************************/
-
-void CatchChild(void)
-{
- CatchSignal(SIGCLD, sig_cld);
-}
-
-/*******************************************************************
- Catch SIGCLD but leave the child around so it's status can be reaped.
-********************************************************************/
-
-void CatchChildLeaveStatus(void)
-{
- CatchSignal(SIGCLD, sig_cld_leave_status);
-}
diff --git a/source3/lib/smbconf/smbconf_txt.c b/source3/lib/smbconf/smbconf_txt.c
index 1a29f40164..1393a098d5 100644
--- a/source3/lib/smbconf/smbconf_txt.c
+++ b/source3/lib/smbconf/smbconf_txt.c
@@ -183,7 +183,7 @@ static WERROR smbconf_txt_load_file(struct smbconf_ctx *ctx)
WERROR werr;
uint64_t new_csn;
- if (!file_exist(ctx->path, NULL)) {
+ if (!file_exist(ctx->path)) {
return WERR_BADFILE;
}
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 93494d6dad..f5e152bb95 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -1211,7 +1211,7 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state,
if (ldap_state->last_rebind.tv_sec > 0) {
struct timeval tval;
- SMB_BIG_INT tdiff = 0;
+ int64_t tdiff = 0;
int sleep_time = 0;
ZERO_STRUCT(tval);
diff --git a/source3/lib/sysquotas.c b/source3/lib/sysquotas.c
index 4a2d88abdf..5ee199de22 100644
--- a/source3/lib/sysquotas.c
+++ b/source3/lib/sysquotas.c
@@ -295,7 +295,7 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
dp->bsize = 1024;
}
- file_lines_free(lines);
+ TALLOC_FREE(lines);
lines = NULL;
DEBUG (3, ("Parsed output of get_quota, ...\n"));
@@ -331,7 +331,7 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
invalid_param:
- file_lines_free(lines);
+ TALLOC_FREE(lines);
DEBUG(0,("The output of get_quota_command is invalid!\n"));
return -1;
}
@@ -392,7 +392,7 @@ static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
DEBUG (3, ("Read output from set_quota, \"%s\"\n", line));
- file_lines_free(lines);
+ TALLOC_FREE(lines);
return 0;
}
diff --git a/source3/lib/sysquotas_4A.c b/source3/lib/sysquotas_4A.c
index f185bba6df..8a1b12238c 100644
--- a/source3/lib/sysquotas_4A.c
+++ b/source3/lib/sysquotas_4A.c
@@ -89,7 +89,7 @@ int sys_get_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qt
int ret = -1;
uint32 qflags = 0;
struct dqblk D;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+ uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
ZERO_STRUCT(D);
ZERO_STRUCT(*dp);
@@ -162,12 +162,12 @@ int sys_get_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qt
}
dp->bsize = bsize;
- dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit;
- dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit;
- dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit;
- dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit;
- dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes;
- dp->curblocks = (SMB_BIG_UINT)D.dqb_curblocks;
+ dp->softlimit = (uint64_t)D.dqb_bsoftlimit;
+ dp->hardlimit = (uint64_t)D.dqb_bhardlimit;
+ dp->ihardlimit = (uint64_t)D.dqb_ihardlimit;
+ dp->isoftlimit = (uint64_t)D.dqb_isoftlimit;
+ dp->curinodes = (uint64_t)D.dqb_curinodes;
+ dp->curblocks = (uint64_t)D.dqb_curblocks;
dp->qflags = qflags;
@@ -184,7 +184,7 @@ int sys_set_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qt
uint32 qflags = 0;
uint32 oldqflags = 0;
struct dqblk D;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+ uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
ZERO_STRUCT(D);
diff --git a/source3/lib/sysquotas_linux.c b/source3/lib/sysquotas_linux.c
index f9a0464086..5720328764 100644
--- a/source3/lib/sysquotas_linux.c
+++ b/source3/lib/sysquotas_linux.c
@@ -41,7 +41,7 @@ static int sys_get_linux_v1_quota(const char *path, const char *bdev, enum SMB_Q
int ret = -1;
uint32 qflags = 0;
struct v1_kern_dqblk D;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+ uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
ZERO_STRUCT(D);
@@ -88,12 +88,12 @@ static int sys_get_linux_v1_quota(const char *path, const char *bdev, enum SMB_Q
}
dp->bsize = bsize;
- dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit;
- dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit;
- dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit;
- dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit;
- dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes;
- dp->curblocks = (SMB_BIG_UINT)D.dqb_curblocks;
+ dp->softlimit = (uint64_t)D.dqb_bsoftlimit;
+ dp->hardlimit = (uint64_t)D.dqb_bhardlimit;
+ dp->ihardlimit = (uint64_t)D.dqb_ihardlimit;
+ dp->isoftlimit = (uint64_t)D.dqb_isoftlimit;
+ dp->curinodes = (uint64_t)D.dqb_curinodes;
+ dp->curblocks = (uint64_t)D.dqb_curblocks;
dp->qflags = qflags;
@@ -110,7 +110,7 @@ static int sys_set_linux_v1_quota(const char *path, const char *bdev, enum SMB_Q
uint32 qflags = 0;
uint32 oldqflags = 0;
struct v1_kern_dqblk D;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+ uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
ZERO_STRUCT(D);
@@ -175,7 +175,7 @@ static int sys_get_linux_v2_quota(const char *path, const char *bdev, enum SMB_Q
int ret = -1;
uint32 qflags = 0;
struct v2_kern_dqblk D;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+ uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
ZERO_STRUCT(D);
@@ -222,12 +222,12 @@ static int sys_get_linux_v2_quota(const char *path, const char *bdev, enum SMB_Q
}
dp->bsize = bsize;
- dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit;
- dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit;
- dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit;
- dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit;
- dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes;
- dp->curblocks = (SMB_BIG_UINT)D.dqb_curspace/bsize;
+ dp->softlimit = (uint64_t)D.dqb_bsoftlimit;
+ dp->hardlimit = (uint64_t)D.dqb_bhardlimit;
+ dp->ihardlimit = (uint64_t)D.dqb_ihardlimit;
+ dp->isoftlimit = (uint64_t)D.dqb_isoftlimit;
+ dp->curinodes = (uint64_t)D.dqb_curinodes;
+ dp->curblocks = (uint64_t)D.dqb_curspace/bsize;
dp->qflags = qflags;
@@ -244,7 +244,7 @@ static int sys_set_linux_v2_quota(const char *path, const char *bdev, enum SMB_Q
uint32 qflags = 0;
uint32 oldqflags = 0;
struct v2_kern_dqblk D;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+ uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
ZERO_STRUCT(D);
@@ -309,7 +309,7 @@ static int sys_get_linux_gen_quota(const char *path, const char *bdev, enum SMB_
int ret = -1;
uint32 qflags = 0;
struct if_dqblk D;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+ uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
ZERO_STRUCT(D);
@@ -356,12 +356,12 @@ static int sys_get_linux_gen_quota(const char *path, const char *bdev, enum SMB_
}
dp->bsize = bsize;
- dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit;
- dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit;
- dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit;
- dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit;
- dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes;
- dp->curblocks = (SMB_BIG_UINT)D.dqb_curspace/bsize;
+ dp->softlimit = (uint64_t)D.dqb_bsoftlimit;
+ dp->hardlimit = (uint64_t)D.dqb_bhardlimit;
+ dp->ihardlimit = (uint64_t)D.dqb_ihardlimit;
+ dp->isoftlimit = (uint64_t)D.dqb_isoftlimit;
+ dp->curinodes = (uint64_t)D.dqb_curinodes;
+ dp->curblocks = (uint64_t)D.dqb_curspace/bsize;
dp->qflags = qflags;
@@ -378,7 +378,7 @@ static int sys_set_linux_gen_quota(const char *path, const char *bdev, enum SMB_
uint32 qflags = 0;
uint32 oldqflags = 0;
struct if_dqblk D;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE;
+ uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
ZERO_STRUCT(D);
diff --git a/source3/lib/sysquotas_xfs.c b/source3/lib/sysquotas_xfs.c
index 30538c167b..1e438e9a6d 100644
--- a/source3/lib/sysquotas_xfs.c
+++ b/source3/lib/sysquotas_xfs.c
@@ -76,7 +76,7 @@ int sys_get_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qt
{
int ret = -1;
uint32 qflags = 0;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)BBSIZE;
+ uint64_t bsize = (uint64_t)BBSIZE;
struct fs_disk_quota D;
struct fs_quota_stat F;
ZERO_STRUCT(D);
@@ -145,12 +145,12 @@ int sys_get_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qt
}
dp->bsize = bsize;
- dp->softlimit = (SMB_BIG_UINT)D.d_blk_softlimit;
- dp->hardlimit = (SMB_BIG_UINT)D.d_blk_hardlimit;
- dp->ihardlimit = (SMB_BIG_UINT)D.d_ino_hardlimit;
- dp->isoftlimit = (SMB_BIG_UINT)D.d_ino_softlimit;
- dp->curinodes = (SMB_BIG_UINT)D.d_icount;
- dp->curblocks = (SMB_BIG_UINT)D.d_bcount;
+ dp->softlimit = (uint64_t)D.d_blk_softlimit;
+ dp->hardlimit = (uint64_t)D.d_blk_hardlimit;
+ dp->ihardlimit = (uint64_t)D.d_ino_hardlimit;
+ dp->isoftlimit = (uint64_t)D.d_ino_softlimit;
+ dp->curinodes = (uint64_t)D.d_icount;
+ dp->curblocks = (uint64_t)D.d_bcount;
dp->qflags = qflags;
return ret;
@@ -163,7 +163,7 @@ int sys_set_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qt
{
int ret = -1;
uint32 qflags = 0;
- SMB_BIG_UINT bsize = (SMB_BIG_UINT)BBSIZE;
+ uint64_t bsize = (uint64_t)BBSIZE;
struct fs_disk_quota D;
struct fs_quota_stat F;
int q_on = 0;
diff --git a/source3/lib/time.c b/source3/lib/time.c
index 8cefef6e23..c4aa7d01b3 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -38,112 +38,12 @@
#define NTTIME_INFINITY (NTTIME)0x8000000000000000LL
-/***************************************************************************
- External access to time_t_min and time_t_max.
-****************************************************************************/
-
-time_t get_time_t_max(void)
-{
- return TIME_T_MAX;
-}
-
-/***************************************************************************
- A gettimeofday wrapper.
-****************************************************************************/
-
-void GetTimeOfDay(struct timeval *tval)
-{
-#ifdef HAVE_GETTIMEOFDAY_TZ
- gettimeofday(tval,NULL);
-#else
- gettimeofday(tval);
-#endif
-}
-
#if (SIZEOF_LONG == 8)
#define TIME_FIXUP_CONSTANT_INT 11644473600L
#elif (SIZEOF_LONG_LONG == 8)
#define TIME_FIXUP_CONSTANT_INT 11644473600LL
#endif
-/****************************************************************************
- Interpret an 8 byte "filetime" structure to a time_t
- It's originally in "100ns units since jan 1st 1601"
-
- An 8 byte value of 0xffffffffffffffff will be returned as a timespec of
-
- tv_sec = 0
- tv_nsec = 0;
-
- Returns GMT.
-****************************************************************************/
-
-time_t nt_time_to_unix(NTTIME nt)
-{
- return convert_timespec_to_time_t(nt_time_to_unix_timespec(&nt));
-}
-
-/****************************************************************************
- Put a 8 byte filetime from a time_t. Uses GMT.
-****************************************************************************/
-
-void unix_to_nt_time(NTTIME *nt, time_t t)
-{
- uint64_t t2;
-
- if (t == (time_t)-1) {
- *nt = (NTTIME)-1LL;
- return;
- }
-
- if (t == TIME_T_MAX) {
- *nt = 0x7fffffffffffffffLL;
- return;
- }
-
- if (t == 0) {
- *nt = 0;
- return;
- }
-
- t2 = t;
- t2 += TIME_FIXUP_CONSTANT_INT;
- t2 *= 1000*1000*10;
-
- *nt = t2;
-}
-
-/****************************************************************************
- Check if it's a null unix time.
-****************************************************************************/
-
-bool null_time(time_t t)
-{
- return t == 0 ||
- t == (time_t)0xFFFFFFFF ||
- t == (time_t)-1;
-}
-
-/****************************************************************************
- Check if it's a null NTTIME.
-****************************************************************************/
-
-bool null_nttime(NTTIME t)
-{
- return t == 0 || t == (NTTIME)-1;
-}
-
-/****************************************************************************
- Check if it's a null timespec.
-****************************************************************************/
-
-bool null_timespec(struct timespec ts)
-{
- return ts.tv_sec == 0 ||
- ts.tv_sec == (time_t)0xFFFFFFFF ||
- ts.tv_sec == (time_t)-1;
-}
-
/*******************************************************************
create a 16 bit dos packed date
********************************************************************/
@@ -193,183 +93,6 @@ static uint32_t make_dos_date(time_t unixdate, int zone_offset)
}
/**
-put a dos date into a buffer (time/date format)
-This takes GMT time and puts local time in the buffer
-**/
-void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset)
-{
- uint32_t x = make_dos_date(unixdate, zone_offset);
- SIVAL(buf,offset,x);
-}
-
-/**
-put a dos date into a buffer (date/time format)
-This takes GMT time and puts local time in the buffer
-**/
-void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset)
-{
- uint32_t x;
- x = make_dos_date(unixdate, zone_offset);
- x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
- SIVAL(buf,offset,x);
-}
-
-/**
-put a dos 32 bit "unix like" date into a buffer. This routine takes
-GMT and converts it to LOCAL time before putting it (most SMBs assume
-localtime for this sort of date)
-**/
-void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset)
-{
- if (!null_time(unixdate)) {
- unixdate -= zone_offset;
- }
- SIVAL(buf,offset,unixdate);
-}
-
-/*******************************************************************
- interpret a 32 bit dos packed date/time to some parameters
-********************************************************************/
-static void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second)
-{
- uint32_t p0,p1,p2,p3;
-
- p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF;
- p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF;
-
- *second = 2*(p0 & 0x1F);
- *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3);
- *hour = (p1>>3)&0xFF;
- *day = (p2&0x1F);
- *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1;
- *year = ((p3>>1)&0xFF) + 80;
-}
-
-/**
- create a unix date (int GMT) from a dos date (which is actually in
- localtime)
-**/
-time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset)
-{
- uint32_t dos_date=0;
- struct tm t;
- time_t ret;
-
- dos_date = IVAL(date_ptr,0);
-
- if (dos_date == 0) return (time_t)0;
-
- interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon,
- &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
- t.tm_isdst = -1;
-
- ret = timegm(&t);
-
- ret += zone_offset;
-
- return ret;
-}
-
-/**
-like make_unix_date() but the words are reversed
-**/
-time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset)
-{
- uint32_t x,x2;
-
- x = IVAL(date_ptr,0);
- x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
- SIVAL(&x,0,x2);
-
- return pull_dos_date((const uint8_t *)&x, zone_offset);
-}
-
-/**
- create a unix GMT date from a dos date in 32 bit "unix like" format
- these generally arrive as localtimes, with corresponding DST
-**/
-time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset)
-{
- time_t t = (time_t)IVAL(date_ptr,0);
- if (!null_time(t)) {
- t += zone_offset;
- }
- return t;
-}
-
-/***************************************************************************
- Return a HTTP/1.0 time string.
-***************************************************************************/
-
-char *http_timestring(time_t t)
-{
- fstring buf;
- struct tm *tm = localtime(&t);
-
- if (t == TIME_T_MAX) {
- fstrcpy(buf, "never");
- } else if (!tm) {
- fstr_sprintf(buf, "%ld seconds since the Epoch", (long)t);
- } else {
-#ifndef HAVE_STRFTIME
- const char *asct = asctime(tm);
- fstrcpy(buf, asct ? asct : "unknown");
- }
- if(buf[strlen(buf)-1] == '\n') {
- buf[strlen(buf)-1] = 0;
-#else /* !HAVE_STRFTIME */
- strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
-#endif /* !HAVE_STRFTIME */
- }
- return talloc_strdup(talloc_tos(), buf);
-}
-
-
-/**
- Return the date and time as a string
-**/
-char *timestring(TALLOC_CTX *mem_ctx, time_t t)
-{
- char *TimeBuf;
- char tempTime[80];
- struct tm *tm;
-
- tm = localtime(&t);
- if (!tm) {
- return talloc_asprintf(mem_ctx,
- "%ld seconds since the Epoch",
- (long)t);
- }
-
-#ifdef HAVE_STRFTIME
- /* some versions of gcc complain about using %c. This is a bug
- in the gcc warning, not a bug in this code. See a recent
- strftime() manual page for details.
- */
- strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm);
- TimeBuf = talloc_strdup(mem_ctx, tempTime);
-#else
- TimeBuf = talloc_strdup(mem_ctx, asctime(tm));
-#endif
-
- return TimeBuf;
-}
-
-/**
- return a talloced string representing a NTTIME for human consumption
-*/
-const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt)
-{
- time_t t;
- if (nt == 0) {
- return "NTTIME(0)";
- }
- t = nt_time_to_unix(nt);
- return timestring(mem_ctx, t);
-}
-
-
-/**
parse a nttime as a large integer in a string and return a NTTIME
*/
NTTIME nttime_from_string(const char *s)
@@ -377,190 +100,6 @@ NTTIME nttime_from_string(const char *s)
return strtoull(s, NULL, 0);
}
-/**
- return (tv1 - tv2) in microseconds
-*/
-int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2)
-{
- int64_t sec_diff = tv1->tv_sec - tv2->tv_sec;
- return (sec_diff * 1000000) + (int64_t)(tv1->tv_usec - tv2->tv_usec);
-}
-
-
-/**
- return a zero timeval
-*/
-struct timeval timeval_zero(void)
-{
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- return tv;
-}
-
-/**
- return True if a timeval is zero
-*/
-bool timeval_is_zero(const struct timeval *tv)
-{
- return tv->tv_sec == 0 && tv->tv_usec == 0;
-}
-
-/**
- return a timeval for the current time
-*/
-struct timeval timeval_current(void)
-{
- struct timeval tv;
- GetTimeOfDay(&tv);
- return tv;
-}
-
-/**
- return a timeval struct with the given elements
-*/
-struct timeval timeval_set(uint32_t secs, uint32_t usecs)
-{
- struct timeval tv;
- tv.tv_sec = secs;
- tv.tv_usec = usecs;
- return tv;
-}
-
-
-/**
- return a timeval ofs microseconds after tv
-*/
-struct timeval timeval_add(const struct timeval *tv,
- uint32_t secs, uint32_t usecs)
-{
- struct timeval tv2 = *tv;
- const unsigned int million = 1000000;
- tv2.tv_sec += secs;
- tv2.tv_usec += usecs;
- tv2.tv_sec += tv2.tv_usec / million;
- tv2.tv_usec = tv2.tv_usec % million;
- return tv2;
-}
-
-/**
- return the sum of two timeval structures
-*/
-struct timeval timeval_sum(const struct timeval *tv1,
- const struct timeval *tv2)
-{
- return timeval_add(tv1, tv2->tv_sec, tv2->tv_usec);
-}
-
-/**
- return a timeval secs/usecs into the future
-*/
-struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs)
-{
- struct timeval tv = timeval_current();
- return timeval_add(&tv, secs, usecs);
-}
-
-/**
- compare two timeval structures.
- Return -1 if tv1 < tv2
- Return 0 if tv1 == tv2
- Return 1 if tv1 > tv2
-*/
-int timeval_compare(const struct timeval *tv1, const struct timeval *tv2)
-{
- if (tv1->tv_sec > tv2->tv_sec) return 1;
- if (tv1->tv_sec < tv2->tv_sec) return -1;
- if (tv1->tv_usec > tv2->tv_usec) return 1;
- if (tv1->tv_usec < tv2->tv_usec) return -1;
- return 0;
-}
-
-/**
- return True if a timer is in the past
-*/
-bool timeval_expired(const struct timeval *tv)
-{
- struct timeval tv2 = timeval_current();
- if (tv2.tv_sec > tv->tv_sec) return True;
- if (tv2.tv_sec < tv->tv_sec) return False;
- return (tv2.tv_usec >= tv->tv_usec);
-}
-
-/**
- return the number of seconds elapsed between two times
-*/
-double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2)
-{
- return (tv2->tv_sec - tv1->tv_sec) +
- (tv2->tv_usec - tv1->tv_usec)*1.0e-6;
-}
-
-/**
- return the number of seconds elapsed since a given time
-*/
-double timeval_elapsed(const struct timeval *tv)
-{
- struct timeval tv2 = timeval_current();
- return timeval_elapsed2(tv, &tv2);
-}
-
-/**
- return the lesser of two timevals
-*/
-struct timeval timeval_min(const struct timeval *tv1,
- const struct timeval *tv2)
-{
- if (tv1->tv_sec < tv2->tv_sec) return *tv1;
- if (tv1->tv_sec > tv2->tv_sec) return *tv2;
- if (tv1->tv_usec < tv2->tv_usec) return *tv1;
- return *tv2;
-}
-
-/**
- return the greater of two timevals
-*/
-struct timeval timeval_max(const struct timeval *tv1,
- const struct timeval *tv2)
-{
- if (tv1->tv_sec > tv2->tv_sec) return *tv1;
- if (tv1->tv_sec < tv2->tv_sec) return *tv2;
- if (tv1->tv_usec > tv2->tv_usec) return *tv1;
- return *tv2;
-}
-
-/**
- return the difference between two timevals as a timeval
- if tv1 comes after tv2, then return a zero timeval
- (this is *tv2 - *tv1)
-*/
-struct timeval timeval_until(const struct timeval *tv1,
- const struct timeval *tv2)
-{
- struct timeval t;
- if (timeval_compare(tv1, tv2) >= 0) {
- return timeval_zero();
- }
- t.tv_sec = tv2->tv_sec - tv1->tv_sec;
- if (tv1->tv_usec > tv2->tv_usec) {
- t.tv_sec--;
- t.tv_usec = 1000000 - (tv1->tv_usec - tv2->tv_usec);
- } else {
- t.tv_usec = tv2->tv_usec - tv1->tv_usec;
- }
- return t;
-}
-
-
-/**
- convert a timeval to a NTTIME
-*/
-NTTIME timeval_to_nttime(const struct timeval *tv)
-{
- return 10*(tv->tv_usec +
- ((TIME_FIXUP_CONSTANT_INT + (uint64_t)tv->tv_sec) * 1000000));
-}
-
/**************************************************************
Handle conversions between time_t and uint32, taking care to
preserve the "special" values.
@@ -592,44 +131,8 @@ time_t convert_uint32_to_time_t(uint32 u)
return (time_t)u;
}
-/*******************************************************************
- Yield the difference between *A and *B, in seconds, ignoring leap seconds.
-********************************************************************/
-
-static int tm_diff(struct tm *a, struct tm *b)
-{
- int ay = a->tm_year + (1900 - 1);
- int by = b->tm_year + (1900 - 1);
- int intervening_leap_days =
- (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
- int years = ay - by;
- int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
- int hours = 24*days + (a->tm_hour - b->tm_hour);
- int minutes = 60*hours + (a->tm_min - b->tm_min);
- int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
-
- return seconds;
-}
-
int extra_time_offset=0;
-/*******************************************************************
- Return the UTC offset in seconds west of UTC, or 0 if it cannot be determined.
-********************************************************************/
-
-int get_time_zone(time_t t)
-{
- struct tm *tm = gmtime(&t);
- struct tm tm_utc;
- if (!tm)
- return 0;
- tm_utc = *tm;
- tm = localtime(&t);
- if (!tm)
- return 0;
- return tm_diff(&tm_utc,tm)+60*extra_time_offset;
-}
-
/****************************************************************************
Check if NTTIME is 0.
****************************************************************************/
@@ -1084,24 +587,6 @@ time_t srv_make_unix_date3(const void *date_ptr)
return make_unix_date3(date_ptr, server_zone_offset);
}
-time_t convert_timespec_to_time_t(struct timespec ts)
-{
- /* 1 ns == 1,000,000,000 - one thousand millionths of a second.
- increment if it's greater than 500 millionth of a second. */
- if (ts.tv_nsec > 500000000) {
- return ts.tv_sec + 1;
- }
- return ts.tv_sec;
-}
-
-struct timespec convert_time_t_to_timespec(time_t t)
-{
- struct timespec ts;
- ts.tv_sec = t;
- ts.tv_nsec = 0;
- return ts;
-}
-
/****************************************************************************
Convert a normalized timeval to a timespec.
****************************************************************************/
@@ -1222,49 +707,6 @@ time_t cli_make_unix_date3(struct cli_state *cli, const void *date_ptr)
return make_unix_date3(date_ptr, cli->serverzone);
}
-/* Large integer version. */
-struct timespec nt_time_to_unix_timespec(NTTIME *nt)
-{
- int64 d;
- struct timespec ret;
-
- if (*nt == 0 || *nt == (int64)-1) {
- ret.tv_sec = 0;
- ret.tv_nsec = 0;
- return ret;
- }
-
- d = (int64)*nt;
- /* d is now in 100ns units, since jan 1st 1601".
- Save off the ns fraction. */
-
- /*
- * Take the last seven decimal digits and multiply by 100.
- * to convert from 100ns units to 1ns units.
- */
- ret.tv_nsec = (long) ((d % (1000 * 1000 * 10)) * 100);
-
- /* Convert to seconds */
- d /= 1000*1000*10;
-
- /* Now adjust by 369 years to make the secs since 1970 */
- d -= TIME_FIXUP_CONSTANT_INT;
-
- if (d <= (int64)TIME_T_MIN) {
- ret.tv_sec = TIME_T_MIN;
- ret.tv_nsec = 0;
- return ret;
- }
-
- if (d >= (int64)TIME_T_MAX) {
- ret.tv_sec = TIME_T_MAX;
- ret.tv_nsec = 0;
- return ret;
- }
-
- ret.tv_sec = (time_t)d;
- return ret;
-}
/****************************************************************************
Check if two NTTIMEs are the same.
****************************************************************************/
diff --git a/source3/lib/util.c b/source3/lib/util.c
index ec43ea7037..92b818b0aa 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -439,19 +439,6 @@ bool set_cmdline_auth_info_machine_account_creds(void)
return true;
}
-/**************************************************************************n
- Find a suitable temporary directory. The result should be copied immediately
- as it may be overwritten by a subsequent call.
-****************************************************************************/
-
-const char *tmpdir(void)
-{
- char *p;
- if ((p = getenv("TMPDIR")))
- return p;
- return "/tmp";
-}
-
/****************************************************************************
Add a gid to an array of gids if it's not already there.
****************************************************************************/
@@ -540,7 +527,7 @@ const char *get_numlist(const char *p, uint32 **num, int *count)
Check if a file exists - call vfs_file_exist for samba files.
********************************************************************/
-bool file_exist(const char *fname,SMB_STRUCT_STAT *sbuf)
+bool file_exist_stat(const char *fname,SMB_STRUCT_STAT *sbuf)
{
SMB_STRUCT_STAT st;
if (!sbuf)
@@ -566,24 +553,10 @@ bool socket_exist(const char *fname)
}
/*******************************************************************
- Check a files mod time.
-********************************************************************/
-
-time_t file_modtime(const char *fname)
-{
- SMB_STRUCT_STAT st;
-
- if (sys_stat(fname,&st) != 0)
- return(0);
-
- return(st.st_mtime);
-}
-
-/*******************************************************************
Check if a directory exists.
********************************************************************/
-bool directory_exist(char *dname,SMB_STRUCT_STAT *st)
+bool directory_exist_stat(char *dname,SMB_STRUCT_STAT *st)
{
SMB_STRUCT_STAT st2;
bool ret;
@@ -927,36 +900,6 @@ ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, SMB_OFF_T pos
#endif
}
-/****************************************************************************
- Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available,
- else
- if SYSV use O_NDELAY
- if BSD use FNDELAY
-****************************************************************************/
-
-int set_blocking(int fd, bool set)
-{
- int val;
-#ifdef O_NONBLOCK
-#define FLAG_TO_SET O_NONBLOCK
-#else
-#ifdef SYSV
-#define FLAG_TO_SET O_NDELAY
-#else /* BSD */
-#define FLAG_TO_SET FNDELAY
-#endif
-#endif
-
- if((val = sys_fcntl_long(fd, F_GETFL, 0)) == -1)
- return -1;
- if(set) /* Turn blocking on - ie. clear nonblock flag */
- val &= ~FLAG_TO_SET;
- else
- val |= FLAG_TO_SET;
- return sys_fcntl_long( fd, F_SETFL, val);
-#undef FLAG_TO_SET
-}
-
/*******************************************************************
Sleep for a specified number of milliseconds.
********************************************************************/
@@ -1130,26 +1073,6 @@ static void *realloc_(void *ptr, size_t size)
#endif /* PARANOID_MALLOC_CHECKER */
/****************************************************************************
- Type-safe malloc.
-****************************************************************************/
-
-void *malloc_array(size_t el_size, unsigned int count)
-{
- if (count >= MAX_ALLOC_SIZE/el_size) {
- return NULL;
- }
-
- if (el_size == 0 || count == 0) {
- return NULL;
- }
-#if defined(PARANOID_MALLOC_CHECKER)
- return malloc_(el_size*count);
-#else
- return malloc(el_size*count);
-#endif
-}
-
-/****************************************************************************
Type-safe memalign
****************************************************************************/
@@ -1250,21 +1173,6 @@ void *Realloc(void *p, size_t size, bool free_old_on_error)
}
/****************************************************************************
- Type-safe realloc.
-****************************************************************************/
-
-void *realloc_array(void *p, size_t el_size, unsigned int count, bool free_old_on_error)
-{
- if (count >= MAX_ALLOC_SIZE/el_size) {
- if (free_old_on_error) {
- SAFE_FREE(p);
- }
- return NULL;
- }
- return Realloc(p, el_size*count, free_old_on_error);
-}
-
-/****************************************************************************
(Hopefully) efficient array append.
****************************************************************************/
@@ -1334,7 +1242,7 @@ void safe_free(void *p)
Get my own name and IP.
****************************************************************************/
-char *get_myname(TALLOC_CTX *ctx)
+char *talloc_get_myname(TALLOC_CTX *ctx)
{
char *p;
char hostname[HOST_NAME_MAX];
@@ -1549,14 +1457,6 @@ bool process_exists(const struct server_id pid)
#endif
}
-bool process_exists_by_pid(pid_t pid)
-{
- /* Doing kill with a non-positive pid causes messages to be
- * sent to places we don't want. */
- SMB_ASSERT(pid > 0);
- return(kill(pid,0) == 0 || errno != ESRCH);
-}
-
/*******************************************************************
Convert a uid into a user name.
********************************************************************/
@@ -2003,42 +1903,6 @@ void free_namearray(name_compare_entry *name_array)
#define DBGC_CLASS DBGC_LOCKING
/****************************************************************************
- Simple routine to do POSIX file locking. Cruft in NFS and 64->32 bit mapping
- is dealt with in posix.c
- Returns True if the lock was granted, False otherwise.
-****************************************************************************/
-
-bool fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
-{
- SMB_STRUCT_FLOCK lock;
- int ret;
-
- DEBUG(8,("fcntl_lock fd=%d op=%d offset=%.0f count=%.0f type=%d\n",
- fd,op,(double)offset,(double)count,type));
-
- lock.l_type = type;
- lock.l_whence = SEEK_SET;
- lock.l_start = offset;
- lock.l_len = count;
- lock.l_pid = 0;
-
- ret = sys_fcntl_ptr(fd,op,&lock);
-
- if (ret == -1) {
- int sav = errno;
- DEBUG(3,("fcntl_lock: lock failed at offset %.0f count %.0f op %d type %d (%s)\n",
- (double)offset,(double)count,op,type,strerror(errno)));
- errno = sav;
- return False;
- }
-
- /* everything went OK */
- DEBUG(8,("fcntl_lock: Lock call successful\n"));
-
- return True;
-}
-
-/****************************************************************************
Simple routine to query existing file locks. Cruft in NFS and 64->32 bit mapping
is dealt with in posix.c
Returns True if we have information regarding this lock region (and returns
@@ -2210,57 +2074,6 @@ enum remote_arch_types get_remote_arch(void)
return ra_type;
}
-void print_asc(int level, const unsigned char *buf,int len)
-{
- int i;
- for (i=0;i<len;i++)
- DEBUG(level,("%c", isprint(buf[i])?buf[i]:'.'));
-}
-
-void dump_data(int level, const unsigned char *buf1,int len)
-{
- const unsigned char *buf = (const unsigned char *)buf1;
- int i=0;
- if (len<=0) return;
-
- if (!DEBUGLVL(level)) return;
-
- DEBUGADD(level,("[%03X] ",i));
- for (i=0;i<len;) {
- DEBUGADD(level,("%02X ",(int)buf[i]));
- i++;
- if (i%8 == 0) DEBUGADD(level,(" "));
- if (i%16 == 0) {
- print_asc(level,&buf[i-16],8); DEBUGADD(level,(" "));
- print_asc(level,&buf[i-8],8); DEBUGADD(level,("\n"));
- if (i<len) DEBUGADD(level,("[%03X] ",i));
- }
- }
- if (i%16) {
- int n;
- n = 16 - (i%16);
- DEBUGADD(level,(" "));
- if (n>8) DEBUGADD(level,(" "));
- while (n--) DEBUGADD(level,(" "));
- n = MIN(8,i%16);
- print_asc(level,&buf[i-(i%16)],n); DEBUGADD(level,( " " ));
- n = (i%16) - n;
- if (n>0) print_asc(level,&buf[i-n],n);
- DEBUGADD(level,("\n"));
- }
-}
-
-void dump_data_pw(const char *msg, const uchar * data, size_t len)
-{
-#ifdef DEBUG_PASSWORD
- DEBUG(11, ("%s", msg));
- if (data != NULL && len > 0)
- {
- dump_data(11, data, len);
- }
-#endif
-}
-
const char *tab_depth(int level, int depth)
{
if( CHECK_DEBUGLVL(level) ) {
@@ -2425,78 +2238,6 @@ void *smb_xmalloc_array(size_t size, unsigned int count)
return p;
}
-/**
- Memdup with smb_panic on fail.
-**/
-
-void *smb_xmemdup(const void *p, size_t size)
-{
- void *p2;
- p2 = SMB_XMALLOC_ARRAY(unsigned char,size);
- memcpy(p2, p, size);
- return p2;
-}
-
-/**
- strdup that aborts on malloc fail.
-**/
-
-char *smb_xstrdup(const char *s)
-{
-#if defined(PARANOID_MALLOC_CHECKER)
-#ifdef strdup
-#undef strdup
-#endif
-#endif
-
-#ifndef HAVE_STRDUP
-#define strdup rep_strdup
-#endif
-
- char *s1 = strdup(s);
-#if defined(PARANOID_MALLOC_CHECKER)
-#ifdef strdup
-#undef strdup
-#endif
-#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY
-#endif
- if (!s1) {
- smb_panic("smb_xstrdup: malloc failed");
- }
- return s1;
-
-}
-
-/**
- strndup that aborts on malloc fail.
-**/
-
-char *smb_xstrndup(const char *s, size_t n)
-{
-#if defined(PARANOID_MALLOC_CHECKER)
-#ifdef strndup
-#undef strndup
-#endif
-#endif
-
-#if (defined(BROKEN_STRNDUP) || !defined(HAVE_STRNDUP))
-#undef HAVE_STRNDUP
-#define strndup rep_strndup
-#endif
-
- char *s1 = strndup(s, n);
-#if defined(PARANOID_MALLOC_CHECKER)
-#ifdef strndup
-#undef strndup
-#endif
-#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY
-#endif
- if (!s1) {
- smb_panic("smb_xstrndup: malloc failed");
- }
- return s1;
-}
-
/*
vasprintf that aborts on malloc fail
*/
@@ -2506,7 +2247,7 @@ char *smb_xstrndup(const char *s, size_t n)
int n;
va_list ap2;
- VA_COPY(ap2, ap);
+ va_copy(ap2, ap);
n = vasprintf(ptr, format, ap2);
if (n == -1 || ! *ptr) {
@@ -2517,22 +2258,6 @@ char *smb_xstrndup(const char *s, size_t n)
}
/*****************************************************************
- Like strdup but for memory.
-*****************************************************************/
-
-void *memdup(const void *p, size_t size)
-{
- void *p2;
- if (size == 0)
- return NULL;
- p2 = SMB_MALLOC(size);
- if (!p2)
- return NULL;
- memcpy(p2, p, size);
- return p2;
-}
-
-/*****************************************************************
Get local hostname and cache result.
*****************************************************************/
@@ -2542,7 +2267,7 @@ char *myhostname(void)
if (ret == NULL) {
/* This is cached forever so
* use NULL talloc ctx. */
- ret = get_myname(NULL);
+ ret = talloc_get_myname(NULL);
}
return ret;
}
@@ -2561,7 +2286,7 @@ static char *xx_path(const char *name, const char *rootpath)
}
trim_string(fname,"","/");
- if (!directory_exist(fname,NULL)) {
+ if (!directory_exist(fname)) {
mkdir(fname,0755);
}
@@ -2972,25 +2697,6 @@ bool name_to_fqdn(fstring fqdn, const char *name)
}
/**********************************************************************
- Extension to talloc_get_type: Abort on type mismatch
-***********************************************************************/
-
-void *talloc_check_name_abort(const void *ptr, const char *name)
-{
- void *result;
-
- result = talloc_check_name(ptr, name);
- if (result != NULL)
- return result;
-
- DEBUG(0, ("Talloc type mismatch, expected %s, got %s\n",
- name, talloc_get_name(ptr)));
- smb_panic("talloc type mismatch");
- /* Keep the compiler happy */
- return NULL;
-}
-
-/**********************************************************************
Append a DATA_BLOB to a talloc'ed object
***********************************************************************/
diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c
index b628b06cc6..c5a9b7c29a 100644
--- a/source3/lib/util_file.c
+++ b/source3/lib/util_file.c
@@ -19,89 +19,11 @@
#include "includes.h"
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *)-1)
-#endif
-
-/****************************************************************************
- Read a line from a file with possible \ continuation chars.
- Blanks at the start or end of a line are stripped.
- The string will be allocated if s2 is NULL.
-****************************************************************************/
-
-char *fgets_slash(char *s2,int maxlen,XFILE *f)
-{
- char *s=s2;
- int len = 0;
- int c;
- bool start_of_line = True;
-
- if (x_feof(f)) {
- return(NULL);
- }
-
- if (maxlen <2) {
- return(NULL);
- }
-
- if (!s2) {
- maxlen = MIN(maxlen,8);
- s = (char *)SMB_MALLOC(maxlen);
- }
-
- if (!s) {
- return(NULL);
- }
-
- *s = 0;
-
- while (len < maxlen-1) {
- c = x_getc(f);
- switch (c) {
- case '\r':
- break;
- case '\n':
- while (len > 0 && s[len-1] == ' ') {
- s[--len] = 0;
- }
- if (len > 0 && s[len-1] == '\\') {
- s[--len] = 0;
- start_of_line = True;
- break;
- }
- return(s);
- case EOF:
- if (len <= 0 && !s2) {
- SAFE_FREE(s);
- }
- return(len>0?s:NULL);
- case ' ':
- if (start_of_line) {
- break;
- }
- default:
- start_of_line = False;
- s[len++] = c;
- s[len] = 0;
- }
-
- if (!s2 && len > maxlen-3) {
- maxlen *= 2;
- s = (char *)SMB_REALLOC(s,maxlen);
- if (!s) {
- DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
- return(NULL);
- }
- }
- }
- return(s);
-}
-
-/****************************************************************************
+/**
Load from a pipe into memory.
-****************************************************************************/
+**/
-static char *file_pload(char *syscmd, size_t *size)
+static char *file_pload(const char *syscmd, size_t *size)
{
int fd, n;
char *p;
@@ -143,215 +65,14 @@ static char *file_pload(char *syscmd, size_t *size)
return p;
}
-/****************************************************************************
- Load a file into memory from a fd.
- Truncate at maxsize. If maxsize == 0 - no limit.
-****************************************************************************/
-
-char *fd_load(int fd, size_t *psize, size_t maxsize)
-{
- SMB_STRUCT_STAT sbuf;
- size_t size;
- char *p;
-
- if (sys_fstat(fd, &sbuf) != 0) {
- return NULL;
- }
-
- size = sbuf.st_size;
- if (maxsize) {
- size = MIN(size, maxsize);
- }
-
- p = (char *)SMB_MALLOC(size+1);
- if (!p) {
- return NULL;
- }
-
- if (read(fd, p, size) != size) {
- SAFE_FREE(p);
- return NULL;
- }
- p[size] = 0;
-
- if (psize) {
- *psize = size;
- }
-
- return p;
-}
-
-/****************************************************************************
- Load a file into memory.
-****************************************************************************/
-
-char *file_load(const char *fname, size_t *size, size_t maxsize)
-{
- int fd;
- char *p;
-
- if (!fname || !*fname) {
- return NULL;
- }
-
- fd = open(fname,O_RDONLY);
- if (fd == -1) {
- return NULL;
- }
-
- p = fd_load(fd, size, maxsize);
- close(fd);
- return p;
-}
-
-/*******************************************************************
- unmap or free memory
-*******************************************************************/
-
-bool unmap_file(void* start, size_t size)
-{
-#ifdef HAVE_MMAP
- if ( munmap( start, size ) != 0 ) {
- DEBUG( 1, ("map_file: Failed to unmap address %p "
- "of size %u - %s\n",
- start, (unsigned int)size, strerror(errno) ));
- return False;
- }
- return True;
-#else
- SAFE_FREE( start );
- return True;
-#endif
-}
-
-/*******************************************************************
- mmap (if possible) or read a file.
-********************************************************************/
-
-void *map_file(char *fname, size_t size)
-{
- size_t s2 = 0;
- void *p = NULL;
-#ifdef HAVE_MMAP
- int fd;
- fd = open(fname, O_RDONLY, 0);
- if (fd == -1) {
- DEBUG(2,("map_file: Failed to load %s - %s\n", fname, strerror(errno)));
- return NULL;
- }
- p = mmap(NULL, size, PROT_READ, MAP_SHARED|MAP_FILE, fd, 0);
- close(fd);
- if (p == MAP_FAILED) {
- DEBUG(1,("map_file: Failed to mmap %s - %s\n", fname, strerror(errno)));
- return NULL;
- }
-#endif
- if (!p) {
- p = file_load(fname, &s2, 0);
- if (!p) {
- return NULL;
- }
- if (s2 != size) {
- DEBUG(1,("map_file: incorrect size for %s - got %lu expected %lu\n",
- fname, (unsigned long)s2, (unsigned long)size));
- SAFE_FREE(p);
- return NULL;
- }
- }
- return p;
-}
-
-/****************************************************************************
- Parse a buffer into lines.
-****************************************************************************/
-
-static char **file_lines_parse(char *p, size_t size, int *numlines)
-{
- int i;
- char *s, **ret;
-
- if (!p) {
- return NULL;
- }
-
- for (s = p, i=0; s < p+size; s++) {
- if (s[0] == '\n') i++;
- }
-
- ret = SMB_MALLOC_ARRAY(char *, i+2);
- if (!ret) {
- SAFE_FREE(p);
- return NULL;
- }
- memset(ret, 0, sizeof(ret[0])*(i+2));
-
- ret[0] = p;
- for (s = p, i=0; s < p+size; s++) {
- if (s[0] == '\n') {
- s[0] = 0;
- i++;
- ret[i] = s+1;
- }
- if (s[0] == '\r') {
- s[0] = 0;
- }
- }
-
- /* remove any blank lines at the end */
- while (i > 0 && ret[i-1][0] == 0) {
- i--;
- }
-
- if (numlines) {
- *numlines = i;
- }
-
- return ret;
-}
-
-/****************************************************************************
- Load a file into memory and return an array of pointers to lines in the file
- must be freed with file_lines_free().
-****************************************************************************/
-
-char **file_lines_load(const char *fname, int *numlines, size_t maxsize)
-{
- char *p;
- size_t size = 0;
-
- p = file_load(fname, &size, maxsize);
- if (!p) {
- return NULL;
- }
-
- return file_lines_parse(p, size, numlines);
-}
-
-/****************************************************************************
- Load a fd into memory and return an array of pointers to lines in the file
- must be freed with file_lines_free(). If convert is true calls unix_to_dos on
- the list.
-****************************************************************************/
-char **fd_lines_load(int fd, int *numlines, size_t maxsize)
-{
- char *p;
- size_t size;
- p = fd_load(fd, &size, maxsize);
- if (!p) {
- return NULL;
- }
-
- return file_lines_parse(p, size, numlines);
-}
-
-/****************************************************************************
+/**
Load a pipe into memory and return an array of pointers to lines in the data
must be freed with file_lines_free().
-****************************************************************************/
+**/
-char **file_lines_pload(char *syscmd, int *numlines)
+char **file_lines_pload(const char *syscmd, int *numlines)
{
char *p;
size_t size;
@@ -361,64 +82,5 @@ char **file_lines_pload(char *syscmd, int *numlines)
return NULL;
}
- return file_lines_parse(p, size, numlines);
-}
-
-/****************************************************************************
- Free lines loaded with file_lines_load.
-****************************************************************************/
-
-void file_lines_free(char **lines)
-{
- if (!lines) {
- return;
- }
- SAFE_FREE(lines[0]);
- SAFE_FREE(lines);
-}
-
-/****************************************************************************
- Take a list of lines and modify them to produce a list where \ continues
- a line.
-****************************************************************************/
-
-void file_lines_slashcont(char **lines)
-{
- int i, j;
-
- for (i=0; lines[i];) {
- int len = strlen(lines[i]);
- if (lines[i][len-1] == '\\') {
- lines[i][len-1] = ' ';
- if (lines[i+1]) {
- char *p = &lines[i][len];
- while (p < lines[i+1]) {
- *p++ = ' ';
- }
- for (j = i+1; lines[j]; j++) {
- lines[j] = lines[j+1];
- }
- }
- } else {
- i++;
- }
- }
-}
-
-/****************************************************************************
- Save a lump of data into a file. Mostly used for debugging.
-****************************************************************************/
-
-bool file_save(const char *fname, void *packet, size_t length)
-{
- int fd;
- fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (fd == -1) {
- return False;
- }
- if (write(fd, packet, length) != (size_t)length) {
- return False;
- }
- close(fd);
- return True;
+ return file_lines_parse(p, size, numlines, NULL);
}
diff --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c
index 428378505f..c0d37f1094 100644
--- a/source3/lib/util_pw.c
+++ b/source3/lib/util_pw.c
@@ -47,7 +47,7 @@ struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
struct passwd *temp, *cached;
temp = (struct passwd *)memcache_lookup_talloc(
- NULL, GETPWNAM_CACHE, data_blob_string_const(name));
+ NULL, GETPWNAM_CACHE, data_blob_string_const_null(name));
if (temp != NULL) {
return tcopy_passwd(mem_ctx, temp);
}
@@ -65,7 +65,7 @@ struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
return temp;
}
- memcache_add_talloc(NULL, GETPWNAM_CACHE, data_blob_string_const(name),
+ memcache_add_talloc(NULL, GETPWNAM_CACHE, data_blob_string_const_null(name),
cached);
return tcopy_passwd(mem_ctx, temp);
}
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index e20768ed89..f3dc3fc1d1 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -1706,7 +1706,7 @@ static bool lookup_nc(struct name_addr_pair *nc)
if (!memcache_lookup(
NULL, SINGLETON_CACHE,
- data_blob_string_const("get_peer_name"),
+ data_blob_string_const_null("get_peer_name"),
&tmp)) {
return false;
}
@@ -1733,7 +1733,7 @@ static void store_nc(const struct name_addr_pair *nc)
memcpy(tmp.data+sizeof(nc->ss), nc->name, namelen+1);
memcache_add(NULL, SINGLETON_CACHE,
- data_blob_string_const("get_peer_name"),
+ data_blob_string_const_null("get_peer_name"),
tmp);
data_blob_free(&tmp);
}
@@ -1945,7 +1945,7 @@ const char *get_mydnsfullname(void)
DATA_BLOB tmp;
if (memcache_lookup(NULL, SINGLETON_CACHE,
- data_blob_string_const("get_mydnsfullname"),
+ data_blob_string_const_null("get_mydnsfullname"),
&tmp)) {
SMB_ASSERT(tmp.length > 0);
return (const char *)tmp.data;
@@ -1989,11 +1989,11 @@ const char *get_mydnsfullname(void)
*/
memcache_add(NULL, SINGLETON_CACHE,
- data_blob_string_const("get_mydnsfullname"),
- data_blob_string_const(res->ai_canonname));
+ data_blob_string_const_null("get_mydnsfullname"),
+ data_blob_string_const_null(res->ai_canonname));
if (!memcache_lookup(NULL, SINGLETON_CACHE,
- data_blob_string_const("get_mydnsfullname"),
+ data_blob_string_const_null("get_mydnsfullname"),
&tmp)) {
tmp = data_blob_talloc(talloc_tos(), res->ai_canonname,
strlen(res->ai_canonname) + 1);
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 9f952abf10..f6783f10ff 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -939,7 +939,7 @@ DATA_BLOB strhex_to_data_blob(TALLOC_CTX *mem_ctx, const char *strhex)
* Routine to print a buffer as HEX digits, into an allocated string.
*/
-char *hex_encode(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len)
+char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len)
{
int i;
char *hex_buffer;
@@ -1843,136 +1843,6 @@ int fstr_sprintf(fstring s, const char *fmt, ...)
#define S_LIST_ABS 16 /* List Allocation Block Size */
-char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
-{
- char **list;
- const char *str;
- char *s;
- int num, lsize;
- char *tok;
-
- if (!string || !*string)
- return NULL;
-
- list = TALLOC_ARRAY(mem_ctx, char *, S_LIST_ABS+1);
- if (list == NULL) {
- return NULL;
- }
- lsize = S_LIST_ABS;
-
- s = talloc_strdup(list, string);
- if (s == NULL) {
- DEBUG(0,("str_list_make: Unable to allocate memory"));
- TALLOC_FREE(list);
- return NULL;
- }
- if (!sep) sep = LIST_SEP;
-
- num = 0;
- str = s;
-
- while (next_token_talloc(list, &str, &tok, sep)) {
-
- if (num == lsize) {
- char **tmp;
-
- lsize += S_LIST_ABS;
-
- tmp = TALLOC_REALLOC_ARRAY(mem_ctx, list, char *,
- lsize + 1);
- if (tmp == NULL) {
- DEBUG(0,("str_list_make: "
- "Unable to allocate memory"));
- TALLOC_FREE(list);
- return NULL;
- }
-
- list = tmp;
-
- memset (&list[num], 0,
- ((sizeof(char**)) * (S_LIST_ABS +1)));
- }
-
- list[num] = tok;
- num += 1;
- }
-
- list[num] = NULL;
-
- TALLOC_FREE(s);
- return list;
-}
-
-bool str_list_copy(TALLOC_CTX *mem_ctx, char ***dest, const char **src)
-{
- char **list;
- int i, num;
-
- *dest = NULL;
- if (!src)
- return false;
-
- num = 0;
- while (src[num] != NULL) {
- num += 1;
- }
-
- list = TALLOC_ARRAY(mem_ctx, char *, num+1);
- if (list == NULL) {
- return false;
- }
-
- for (i=0; i<num; i++) {
- list[i] = talloc_strdup(list, src[i]);
- if (list[i] == NULL) {
- TALLOC_FREE(list);
- return false;
- }
- }
- list[i] = NULL;
- *dest = list;
- return true;
-}
-
-/**
- * Return true if all the elements of the list match exactly.
- **/
-bool str_list_compare(char **list1, char **list2)
-{
- int num;
-
- if (!list1 || !list2)
- return (list1 == list2);
-
- for (num = 0; list1[num]; num++) {
- if (!list2[num])
- return false;
- if (!strcsequal(list1[num], list2[num]))
- return false;
- }
- if (list2[num])
- return false; /* if list2 has more elements than list1 fail */
-
- return true;
-}
-
-/******************************************************************************
- *****************************************************************************/
-
-int str_list_count( const char **list )
-{
- int i = 0;
-
- if ( ! list )
- return 0;
-
- /* count the number of list members */
-
- for ( i=0; *list; i++, list++ );
-
- return i;
-}
-
/******************************************************************************
version of standard_sub_basic() for string lists; uses talloc_sub_basic()
for the work
@@ -2386,10 +2256,10 @@ char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
}
/* read a SMB_BIG_UINT from a string */
-SMB_BIG_UINT STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr)
+uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr)
{
- SMB_BIG_UINT val = -1;
+ uint64_t val = -1;
const char *p = nptr;
if (!p) {
@@ -2402,11 +2272,7 @@ SMB_BIG_UINT STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr)
while (*p && isspace(*p))
p++;
-#ifdef LARGE_SMB_OFF_T
- sscanf(p,"%llu",&val);
-#else /* LARGE_SMB_OFF_T */
- sscanf(p,"%lu",&val);
-#endif /* LARGE_SMB_OFF_T */
+ sscanf(p,"%"PRIu64,&val);
if (entptr) {
while (*p && isdigit(*p))
p++;
diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c
index 8257232667..bb568bc22e 100644
--- a/source3/lib/util_tdb.c
+++ b/source3/lib/util_tdb.c
@@ -39,28 +39,6 @@ static void gotalarm_sig(void)
gotalarm = 1;
}
-/***************************************************************
- Make a TDB_DATA and keep the const warning in one place
-****************************************************************/
-
-TDB_DATA make_tdb_data(const uint8 *dptr, size_t dsize)
-{
- TDB_DATA ret;
- ret.dptr = CONST_DISCARD(uint8 *, dptr);
- ret.dsize = dsize;
- return ret;
-}
-
-TDB_DATA string_tdb_data(const char *string)
-{
- return make_tdb_data((const uint8 *)string, string ? strlen(string) : 0 );
-}
-
-TDB_DATA string_term_tdb_data(const char *string)
-{
- return make_tdb_data((const uint8 *)string, string ? strlen(string) + 1 : 0);
-}
-
/****************************************************************************
Lock a chain with timeout (in seconds).
****************************************************************************/
@@ -109,17 +87,6 @@ int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int tim
return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_WRLCK);
}
-/****************************************************************************
- Lock a chain by string. Return -1 if timeout or lock failed.
-****************************************************************************/
-
-int tdb_lock_bystring(TDB_CONTEXT *tdb, const char *keyval)
-{
- TDB_DATA key = string_term_tdb_data(keyval);
-
- return tdb_chainlock(tdb, key);
-}
-
int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
int timeout)
{
@@ -129,17 +96,6 @@ int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
}
/****************************************************************************
- Unlock a chain by string.
-****************************************************************************/
-
-void tdb_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval)
-{
- TDB_DATA key = string_term_tdb_data(keyval);
-
- tdb_chainunlock(tdb, key);
-}
-
-/****************************************************************************
Read lock a chain by string. Return -1 if timeout or lock failed.
****************************************************************************/
@@ -150,155 +106,8 @@ int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, un
return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_RDLCK);
}
-/****************************************************************************
- Read unlock a chain by string.
-****************************************************************************/
-
-void tdb_read_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval)
-{
- TDB_DATA key = string_term_tdb_data(keyval);
-
- tdb_chainunlock_read(tdb, key);
-}
-
-
-/****************************************************************************
- Fetch a int32 value by a arbitrary blob key, return -1 if not found.
- Output is int32 in native byte order.
-****************************************************************************/
-
-int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key)
-{
- TDB_DATA data;
- int32 ret;
-
- data = tdb_fetch(tdb, key);
- if (!data.dptr || data.dsize != sizeof(int32)) {
- SAFE_FREE(data.dptr);
- return -1;
- }
-
- ret = IVAL(data.dptr,0);
- SAFE_FREE(data.dptr);
- return ret;
-}
-
-/****************************************************************************
- Fetch a int32 value by string key, return -1 if not found.
- Output is int32 in native byte order.
-****************************************************************************/
-
-int32 tdb_fetch_int32(TDB_CONTEXT *tdb, const char *keystr)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_fetch_int32_byblob(tdb, key);
-}
-
-/****************************************************************************
- Store a int32 value by an arbitary blob key, return 0 on success, -1 on failure.
- Input is int32 in native byte order. Output in tdb is in little-endian.
-****************************************************************************/
-
-int tdb_store_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, int32 v)
-{
- TDB_DATA data;
- int32 v_store;
-
- SIVAL(&v_store,0,v);
- data.dptr = (uint8 *)&v_store;
- data.dsize = sizeof(int32);
-
- return tdb_store(tdb, key, data, TDB_REPLACE);
-}
-
-/****************************************************************************
- Store a int32 value by string key, return 0 on success, -1 on failure.
- Input is int32 in native byte order. Output in tdb is in little-endian.
-****************************************************************************/
-
-int tdb_store_int32(TDB_CONTEXT *tdb, const char *keystr, int32 v)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_store_int32_byblob(tdb, key, v);
-}
-
-/****************************************************************************
- Fetch a uint32 value by a arbitrary blob key, return -1 if not found.
- Output is uint32 in native byte order.
-****************************************************************************/
-
-bool tdb_fetch_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 *value)
-{
- TDB_DATA data;
-
- data = tdb_fetch(tdb, key);
- if (!data.dptr || data.dsize != sizeof(uint32)) {
- SAFE_FREE(data.dptr);
- return False;
- }
-
- *value = IVAL(data.dptr,0);
- SAFE_FREE(data.dptr);
- return True;
-}
-
-/****************************************************************************
- Fetch a uint32 value by string key, return -1 if not found.
- Output is uint32 in native byte order.
-****************************************************************************/
-
-bool tdb_fetch_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 *value)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_fetch_uint32_byblob(tdb, key, value);
-}
-
-/****************************************************************************
- Store a uint32 value by an arbitary blob key, return 0 on success, -1 on failure.
- Input is uint32 in native byte order. Output in tdb is in little-endian.
-****************************************************************************/
-
-bool tdb_store_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 value)
-{
- TDB_DATA data;
- uint32 v_store;
- bool ret = True;
-
- SIVAL(&v_store, 0, value);
- data.dptr = (uint8 *)&v_store;
- data.dsize = sizeof(uint32);
- if (tdb_store(tdb, key, data, TDB_REPLACE) == -1)
- ret = False;
- return ret;
-}
-
-/****************************************************************************
- Store a uint32 value by string key, return 0 on success, -1 on failure.
- Input is uint32 in native byte order. Output in tdb is in little-endian.
-****************************************************************************/
-
-bool tdb_store_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 value)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_store_uint32_byblob(tdb, key, value);
-}
-/****************************************************************************
- Store a buffer by a null terminated string key. Return 0 on success, -1
- on failure.
-****************************************************************************/
-
-int tdb_store_bystring(TDB_CONTEXT *tdb, const char *keystr, TDB_DATA data, int flags)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_store(tdb, key, data, flags);
-}
int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr,
TDB_DATA data, int flags)
@@ -309,112 +118,6 @@ int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr,
}
/****************************************************************************
- Fetch a buffer using a null terminated string key. Don't forget to call
- free() on the result dptr.
-****************************************************************************/
-
-TDB_DATA tdb_fetch_bystring(TDB_CONTEXT *tdb, const char *keystr)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_fetch(tdb, key);
-}
-
-/****************************************************************************
- Delete an entry using a null terminated string key.
-****************************************************************************/
-
-int tdb_delete_bystring(TDB_CONTEXT *tdb, const char *keystr)
-{
- TDB_DATA key = string_term_tdb_data(keystr);
-
- return tdb_delete(tdb, key);
-}
-
-/****************************************************************************
- Atomic integer change. Returns old value. To create, set initial value in *oldval.
-****************************************************************************/
-
-int32 tdb_change_int32_atomic(TDB_CONTEXT *tdb, const char *keystr, int32 *oldval, int32 change_val)
-{
- int32 val;
- int32 ret = -1;
-
- if (tdb_lock_bystring(tdb, keystr) == -1)
- return -1;
-
- if ((val = tdb_fetch_int32(tdb, keystr)) == -1) {
- /* The lookup failed */
- if (tdb_error(tdb) != TDB_ERR_NOEXIST) {
- /* but not because it didn't exist */
- goto err_out;
- }
-
- /* Start with 'old' value */
- val = *oldval;
-
- } else {
- /* It worked, set return value (oldval) to tdb data */
- *oldval = val;
- }
-
- /* Increment value for storage and return next time */
- val += change_val;
-
- if (tdb_store_int32(tdb, keystr, val) == -1)
- goto err_out;
-
- ret = 0;
-
- err_out:
-
- tdb_unlock_bystring(tdb, keystr);
- return ret;
-}
-
-/****************************************************************************
- Atomic unsigned integer change. Returns old value. To create, set initial value in *oldval.
-****************************************************************************/
-
-bool tdb_change_uint32_atomic(TDB_CONTEXT *tdb, const char *keystr, uint32 *oldval, uint32 change_val)
-{
- uint32 val;
- bool ret = False;
-
- if (tdb_lock_bystring(tdb, keystr) == -1)
- return False;
-
- if (!tdb_fetch_uint32(tdb, keystr, &val)) {
- /* It failed */
- if (tdb_error(tdb) != TDB_ERR_NOEXIST) {
- /* and not because it didn't exist */
- goto err_out;
- }
-
- /* Start with 'old' value */
- val = *oldval;
-
- } else {
- /* it worked, set return value (oldval) to tdb data */
- *oldval = val;
-
- }
-
- /* get a new value to store */
- val += change_val;
-
- if (!tdb_store_uint32(tdb, keystr, val))
- goto err_out;
-
- ret = True;
-
- err_out:
-
- tdb_unlock_bystring(tdb, keystr);
- return ret;
-}
-
-/****************************************************************************
Useful pair of routines for packing/unpacking data consisting of
integers and strings.
****************************************************************************/
diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c
index 3a8f7b3f4f..c681b66d34 100644
--- a/source3/lib/util_uuid.c
+++ b/source3/lib/util_uuid.c
@@ -20,12 +20,6 @@
#include "includes.h"
-/*
- * Offset between 15-Oct-1582 and 1-Jan-70
- */
-#define TIME_OFFSET_HIGH 0x01B21DD2
-#define TIME_OFFSET_LOW 0x13814000
-
void smb_uuid_pack(const struct GUID uu, UUID_FLAT *ptr)
{
SIVAL(ptr->info, 0, uu.time_low);
@@ -44,78 +38,6 @@ void smb_uuid_unpack(const UUID_FLAT in, struct GUID *uu)
memcpy(uu->node, in.info+10, 6);
}
-void smb_uuid_generate_random(struct GUID *uu)
-{
- UUID_FLAT tmp;
-
- generate_random_buffer(tmp.info, sizeof(tmp.info));
- smb_uuid_unpack(tmp, uu);
-
- uu->clock_seq[0] = (uu->clock_seq[0] & 0x3F) | 0x80;
- uu->time_hi_and_version = (uu->time_hi_and_version & 0x0FFF) | 0x4000;
-}
-
-const char *smb_uuid_string(TALLOC_CTX *mem_ctx, const struct GUID uu)
-{
- char *result;
-
- result = talloc_asprintf(
- mem_ctx,
- "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- uu.time_low, uu.time_mid, uu.time_hi_and_version,
- uu.clock_seq[0], uu.clock_seq[1],
- uu.node[0], uu.node[1], uu.node[2],
- uu.node[3], uu.node[4], uu.node[5]);
-
- SMB_ASSERT(result != NULL);
- return result;
-}
-
-bool smb_string_to_uuid(const char *in, struct GUID* uu)
-{
- bool ret = False;
- const char *ptr = in;
- char *end = (char *)in;
- int i;
- unsigned v1, v2;
-
- if (!in || !uu) goto out;
-
- uu->time_low = strtoul(ptr, &end, 16);
- if ((end - ptr) != 8 || *end != '-') goto out;
- ptr = (end + 1);
-
- uu->time_mid = strtoul(ptr, &end, 16);
- if ((end - ptr) != 4 || *end != '-') goto out;
- ptr = (end + 1);
-
- uu->time_hi_and_version = strtoul(ptr, &end, 16);
- if ((end - ptr) != 4 || *end != '-') goto out;
- ptr = (end + 1);
-
- if (sscanf(ptr, "%02x%02x", &v1, &v2) != 2) {
- goto out;
- }
- uu->clock_seq[0] = v1;
- uu->clock_seq[1] = v2;
- ptr += 4;
-
- if (*ptr != '-') goto out;
- ptr++;
-
- for (i = 0; i < 6; i++) {
- if (sscanf(ptr, "%02x", &v1) != 1) {
- goto out;
- }
- uu->node[i] = v1;
- ptr += 2;
- }
-
- ret = True;
-out:
- return ret;
-}
-
/*****************************************************************
Return the binary string representation of a GUID.
Caller must free.
diff --git a/source3/lib/xfile.c b/source3/lib/xfile.c
deleted file mode 100644
index e44a92d34d..0000000000
--- a/source3/lib/xfile.c
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- stdio replacement
- Copyright (C) Andrew Tridgell 2001
-
- 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/>.
-*/
-
-/*
- stdio is very convenient, but on some systems the file descriptor
- in FILE* is 8 bits, so it fails when more than 255 files are open.
-
- XFILE replaces stdio. It is less efficient, but at least it works
- when you have lots of files open
-
- The main restriction on XFILE is that it doesn't support seeking,
- and doesn't support O_RDWR. That keeps the code simple.
-*/
-
-#include "includes.h"
-
-#define XBUFSIZE BUFSIZ
-
-static XFILE _x_stdin = { 0, NULL, NULL, XBUFSIZE, 0, O_RDONLY, X_IOFBF, 0 };
-static XFILE _x_stdout = { 1, NULL, NULL, XBUFSIZE, 0, O_WRONLY, X_IOLBF, 0 };
-static XFILE _x_stderr = { 2, NULL, NULL, 0, 0, O_WRONLY, X_IONBF, 0 };
-
-XFILE *x_stdin = &_x_stdin;
-XFILE *x_stdout = &_x_stdout;
-XFILE *x_stderr = &_x_stderr;
-
-#define X_FLAG_EOF 1
-#define X_FLAG_ERROR 2
-#define X_FLAG_EINVAL 3
-
-/* simulate setvbuf() */
-int x_setvbuf(XFILE *f, char *buf, int mode, size_t size)
-{
- if (x_fflush(f) != 0) return -1;
- if (f->bufused) return -1;
-
- /* on files being read full buffering is the only option */
- if ((f->open_flags & O_ACCMODE) == O_RDONLY) {
- mode = X_IOFBF;
- }
-
- /* destroy any earlier buffer */
- SAFE_FREE(f->buf);
- f->buf = 0;
- f->bufsize = 0;
- f->next = NULL;
- f->bufused = 0;
- f->buftype = mode;
-
- if (f->buftype == X_IONBF) return 0;
-
- /* if buffering then we need some size */
- if (size == 0) size = XBUFSIZE;
-
- f->bufsize = size;
- f->bufused = 0;
-
- return 0;
-}
-
-/* allocate the buffer */
-static int x_allocate_buffer(XFILE *f)
-{
- if (f->buf) return 1;
- if (f->bufsize == 0) return 0;
- f->buf = (char *)SMB_MALLOC(f->bufsize);
- if (!f->buf) return 0;
- f->next = f->buf;
- return 1;
-}
-
-
-/* this looks more like open() than fopen(), but that is quite deliberate.
- I want programmers to *think* about O_EXCL, O_CREAT etc not just
- get them magically added
-*/
-XFILE *x_fopen(const char *fname, int flags, mode_t mode)
-{
- XFILE *ret;
-
- ret = SMB_MALLOC_P(XFILE);
- if (!ret) {
- return NULL;
- }
-
- memset(ret, 0, sizeof(XFILE));
-
- if ((flags & O_ACCMODE) == O_RDWR) {
- /* we don't support RDWR in XFILE - use file
- descriptors instead */
- SAFE_FREE(ret);
- errno = EINVAL;
- return NULL;
- }
-
- ret->open_flags = flags;
-
- ret->fd = sys_open(fname, flags, mode);
- if (ret->fd == -1) {
- SAFE_FREE(ret);
- return NULL;
- }
-
- x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE);
-
- return ret;
-}
-
-XFILE *x_fdup(const XFILE *f)
-{
- XFILE *ret;
- int fd;
-
- fd = dup(x_fileno(f));
- if (fd < 0) {
- return NULL;
- }
-
- ret = SMB_CALLOC_ARRAY(XFILE, 1);
- if (!ret) {
- close(fd);
- return NULL;
- }
-
- ret->fd = fd;
- ret->open_flags = f->open_flags;
- x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE);
- return ret;
-}
-
-/* simulate fclose() */
-int x_fclose(XFILE *f)
-{
- int ret;
-
- /* make sure we flush any buffered data */
- (void)x_fflush(f);
-
- ret = close(f->fd);
- f->fd = -1;
- if (f->buf) {
- /* make sure data can't leak into a later malloc */
- memset(f->buf, 0, f->bufsize);
- SAFE_FREE(f->buf);
- }
- /* check the file descriptor given to the function is NOT one of the static
- * descriptor of this libreary or we will free unallocated memory
- * --sss */
- if (f != x_stdin && f != x_stdout && f != x_stderr) {
- SAFE_FREE(f);
- }
- return ret;
-}
-
-/* simulate fwrite() */
-size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f)
-{
- ssize_t ret;
- size_t total=0;
-
- /* we might be writing unbuffered */
- if (f->buftype == X_IONBF ||
- (!f->buf && !x_allocate_buffer(f))) {
- ret = write(f->fd, p, size*nmemb);
- if (ret == -1) return -1;
- return ret/size;
- }
-
-
- while (total < size*nmemb) {
- size_t n = f->bufsize - f->bufused;
- n = MIN(n, (size*nmemb)-total);
-
- if (n == 0) {
- /* it's full, flush it */
- if (x_fflush(f) != 0) {
- return -1;
- }
- continue;
- }
-
- memcpy(f->buf + f->bufused, total+(const char *)p, n);
- f->bufused += n;
- total += n;
- }
-
- /* when line buffered we need to flush at the last linefeed. This can
- flush a bit more than necessary, but that is harmless */
- if (f->buftype == X_IOLBF && f->bufused) {
- int i;
- for (i=(size*nmemb)-1; i>=0; i--) {
- if (*(i+(const char *)p) == '\n') {
- if (x_fflush(f) != 0) {
- return -1;
- }
- break;
- }
- }
- }
-
- return total/size;
-}
-
-/* thank goodness for asprintf() */
- int x_vfprintf(XFILE *f, const char *format, va_list ap)
-{
- char *p;
- int len, ret;
- va_list ap2;
-
- VA_COPY(ap2, ap);
-
- len = vasprintf(&p, format, ap2);
- if (len <= 0) {
- va_end(ap2);
- return len;
- }
- ret = x_fwrite(p, 1, len, f);
- SAFE_FREE(p);
-
- va_end(ap2);
-
- return ret;
-}
-
- int x_fprintf(XFILE *f, const char *format, ...)
-{
- va_list ap;
- int ret;
-
- va_start(ap, format);
- ret = x_vfprintf(f, format, ap);
- va_end(ap);
- return ret;
-}
-
-/* at least fileno() is simple! */
-int x_fileno(const XFILE *f)
-{
- return f->fd;
-}
-
-/* simulate fflush() */
-int x_fflush(XFILE *f)
-{
- int ret;
-
- if (f->flags & X_FLAG_ERROR) return -1;
-
- if (f->bufused == 0 || !f->buf) return 0;
-
- if ((f->open_flags & O_ACCMODE) != O_WRONLY) {
- errno = EINVAL;
- return -1;
- }
-
- ret = write(f->fd, f->buf, f->bufused);
- if (ret == -1) return -1;
-
- f->bufused -= ret;
- if (f->bufused > 0) {
- f->flags |= X_FLAG_ERROR;
- memmove(f->buf, ret + (char *)f->buf, f->bufused);
- return -1;
- }
-
- return 0;
-}
-
-/* simulate setbuffer() */
-void x_setbuffer(XFILE *f, char *buf, size_t size)
-{
- x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, size);
-}
-
-/* simulate setbuf() */
-void x_setbuf(XFILE *f, char *buf)
-{
- x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, XBUFSIZE);
-}
-
-/* simulate setlinebuf() */
-void x_setlinebuf(XFILE *f)
-{
- x_setvbuf(f, NULL, X_IOLBF, 0);
-}
-
-
-/* simulate feof() */
-int x_feof(XFILE *f)
-{
- if (f->flags & X_FLAG_EOF) return 1;
- return 0;
-}
-
-/* simulate ferror() */
-int x_ferror(XFILE *f)
-{
- if (f->flags & X_FLAG_ERROR) return 1;
- return 0;
-}
-
-/* fill the read buffer */
-static void x_fillbuf(XFILE *f)
-{
- int n;
-
- if (f->bufused) return;
-
- if (!f->buf && !x_allocate_buffer(f)) return;
-
- n = read(f->fd, f->buf, f->bufsize);
- if (n <= 0) return;
- f->bufused = n;
- f->next = f->buf;
-}
-
-/* simulate fgetc() */
-int x_fgetc(XFILE *f)
-{
- int ret;
-
- if (f->flags & (X_FLAG_EOF | X_FLAG_ERROR)) return EOF;
-
- if (f->bufused == 0) x_fillbuf(f);
-
- if (f->bufused == 0) {
- f->flags |= X_FLAG_EOF;
- return EOF;
- }
-
- ret = *(unsigned char *)(f->next);
- f->next++;
- f->bufused--;
- return ret;
-}
-
-/* simulate fread */
-size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f)
-{
- size_t total = 0;
- while (total < size*nmemb) {
- int c = x_fgetc(f);
- if (c == EOF) break;
- (total+(char *)p)[0] = (char)c;
- total++;
- }
- return total/size;
-}
-
-/* simulate fgets() */
-char *x_fgets(char *s, int size, XFILE *stream)
-{
- char *s0 = s;
- int l = size;
- while (l>1) {
- int c = x_fgetc(stream);
- if (c == EOF) break;
- *s++ = (char)c;
- l--;
- if (c == '\n') break;
- }
- if (l==size || x_ferror(stream)) {
- return 0;
- }
- *s = 0;
- return s0;
-}
-
-/* trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is
- * set then an error is returned */
-off_t x_tseek(XFILE *f, off_t offset, int whence)
-{
- if (f->flags & X_FLAG_ERROR)
- return -1;
-
- /* only SEEK_SET and SEEK_END are supported */
- /* SEEK_CUR needs internal offset counter */
- if (whence != SEEK_SET && whence != SEEK_END) {
- f->flags |= X_FLAG_EINVAL;
- errno = EINVAL;
- return -1;
- }
-
- /* empty the buffer */
- switch (f->open_flags & O_ACCMODE) {
- case O_RDONLY:
- f->bufused = 0;
- break;
- case O_WRONLY:
- if (x_fflush(f) != 0)
- return -1;
- break;
- default:
- errno = EINVAL;
- return -1;
- }
-
- f->flags &= ~X_FLAG_EOF;
- return (off_t)sys_lseek(f->fd, offset, whence);
-}