summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/appweb/mpr/miniMpr.c7
-rw-r--r--source4/lib/appweb/mpr/miniMpr.h2
-rw-r--r--source4/lib/charset/util_unistr.c34
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c4
-rw-r--r--source4/lib/ldb/modules/rdn_name.c3
-rw-r--r--source4/lib/registry/hive.c3
-rw-r--r--source4/lib/registry/hive.h3
-rw-r--r--source4/lib/registry/ldb.c14
-rw-r--r--source4/lib/registry/patchfile.c9
-rw-r--r--source4/lib/registry/patchfile.h1
-rw-r--r--source4/lib/registry/patchfile_dotreg.c3
-rw-r--r--source4/lib/registry/patchfile_preg.c17
-rw-r--r--source4/lib/registry/regf.c10
-rw-r--r--source4/lib/registry/tests/hive.c4
-rw-r--r--source4/lib/registry/tools/regdiff.c2
-rw-r--r--source4/lib/replace/Makefile.in2
-rw-r--r--source4/lib/replace/getifaddrs.c79
-rw-r--r--source4/lib/replace/getifaddrs.m424
-rw-r--r--source4/lib/replace/test/getifaddrs.c100
-rw-r--r--source4/lib/replace/test/testsuite.c9
20 files changed, 223 insertions, 107 deletions
diff --git a/source4/lib/appweb/mpr/miniMpr.c b/source4/lib/appweb/mpr/miniMpr.c
index 949d64fcf1..52b23608aa 100644
--- a/source4/lib/appweb/mpr/miniMpr.c
+++ b/source4/lib/appweb/mpr/miniMpr.c
@@ -30,6 +30,7 @@
*/
#include "miniMpr.h"
+#include "param/param.h"
/************************************ Code ************************************/
#if !BLD_APPWEB
@@ -49,6 +50,12 @@ void *mprMemCtx(void)
return mpr_ctx;
}
+/* return the loadparm context being used for all ejs variables */
+struct loadparm_context *mprLpCtx(void)
+{
+ return global_loadparm;
+}
+
void mprFree(void *ptr)
{
talloc_free(ptr);
diff --git a/source4/lib/appweb/mpr/miniMpr.h b/source4/lib/appweb/mpr/miniMpr.h
index 836fdab9f2..15ce30c8df 100644
--- a/source4/lib/appweb/mpr/miniMpr.h
+++ b/source4/lib/appweb/mpr/miniMpr.h
@@ -272,6 +272,8 @@ extern int mprMemcpy(char *dest, int destMax, const char *src, int nbytes);
extern void mprSetCtx(void *ctx);
extern void *mprMemCtx(void);
+struct loadparm_context;
+extern struct loadparm_context *mprLpCtx(void);
/* This function needs to be provided by anyone using ejs */
void ejs_exception(const char *reason);
diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c
index e0e1aed222..9b87f49800 100644
--- a/source4/lib/charset/util_unistr.c
+++ b/source4/lib/charset/util_unistr.c
@@ -123,6 +123,7 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
{
codepoint_t c1=0, c2=0;
size_t size1, size2;
+ struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm);
/* handle null ptr comparisons to simplify the use in qsort */
if (s1 == s2) return 0;
@@ -130,8 +131,8 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
if (s2 == NULL) return 1;
while (*s1 && *s2) {
- c1 = next_codepoint(lp_iconv_convenience(global_loadparm), s1, &size1);
- c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s2, &size2);
+ c1 = next_codepoint(iconv_convenience, s1, &size1);
+ c2 = next_codepoint(iconv_convenience, s2, &size2);
s1 += size1;
s2 += size2;
@@ -207,6 +208,7 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n)
{
codepoint_t c1=0, c2=0;
size_t size1, size2;
+ struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm);
/* handle null ptr comparisons to simplify the use in qsort */
if (s1 == s2) return 0;
@@ -216,8 +218,8 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n)
while (*s1 && *s2 && n) {
n--;
- c1 = next_codepoint(lp_iconv_convenience(global_loadparm), s1, &size1);
- c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s2, &size2);
+ c1 = next_codepoint(iconv_convenience, s1, &size1);
+ c2 = next_codepoint(iconv_convenience, s2, &size2);
s1 += size1;
s2 += size2;
@@ -480,6 +482,7 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src)
{
size_t size=0;
char *dest;
+ struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm);
/* this takes advantage of the fact that upper/lower can't
change the length of a character by more than 1 byte */
@@ -490,12 +493,12 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src)
while (*src) {
size_t c_size;
- codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), src, &c_size);
+ codepoint_t c = next_codepoint(iconv_convenience, src, &c_size);
src += c_size;
c = tolower_w(c);
- c_size = push_codepoint(lp_iconv_convenience(global_loadparm), dest+size, c);
+ c_size = push_codepoint(iconv_convenience, dest+size, c);
if (c_size == -1) {
talloc_free(dest);
return NULL;
@@ -520,6 +523,7 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src)
{
size_t size=0;
char *dest;
+ struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm);
if (!src) {
return NULL;
@@ -534,12 +538,12 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src)
while (*src) {
size_t c_size;
- codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), src, &c_size);
+ codepoint_t c = next_codepoint(iconv_convenience, src, &c_size);
src += c_size;
c = toupper_w(c);
- c_size = push_codepoint(lp_iconv_convenience(global_loadparm), dest+size, c);
+ c_size = push_codepoint(iconv_convenience, dest+size, c);
if (c_size == -1) {
talloc_free(dest);
return NULL;
@@ -563,6 +567,7 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src)
_PUBLIC_ void strlower_m(char *s)
{
char *d;
+ struct smb_iconv_convenience *iconv_convenience;
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
@@ -576,12 +581,14 @@ _PUBLIC_ void strlower_m(char *s)
if (!*s)
return;
+ iconv_convenience = lp_iconv_convenience(global_loadparm);
+
d = s;
while (*s) {
size_t c_size, c_size2;
- codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size);
- c_size2 = push_codepoint(lp_iconv_convenience(global_loadparm), d, tolower_w(c));
+ codepoint_t c = next_codepoint(iconv_convenience, s, &c_size);
+ c_size2 = push_codepoint(iconv_convenience, d, tolower_w(c));
if (c_size2 > c_size) {
DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n",
c, tolower_w(c), (int)c_size, (int)c_size2));
@@ -599,6 +606,7 @@ _PUBLIC_ void strlower_m(char *s)
_PUBLIC_ void strupper_m(char *s)
{
char *d;
+ struct smb_iconv_convenience *iconv_convenience;
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
@@ -612,12 +620,14 @@ _PUBLIC_ void strupper_m(char *s)
if (!*s)
return;
+ iconv_convenience = lp_iconv_convenience(global_loadparm);
+
d = s;
while (*s) {
size_t c_size, c_size2;
- codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size);
- c_size2 = push_codepoint(lp_iconv_convenience(global_loadparm), d, toupper_w(c));
+ codepoint_t c = next_codepoint(iconv_convenience, s, &c_size);
+ c_size2 = push_codepoint(iconv_convenience, d, toupper_w(c));
if (c_size2 > c_size) {
DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n",
c, toupper_w(c), (int)c_size, (int)c_size2));
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index 995b584f51..79958a86eb 100644
--- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c
+++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
@@ -816,8 +816,8 @@ _PUBLIC_ const struct ldb_backend_ops ldb_ldap_backend_ops = {
.connect_fn = ildb_connect
};
-_PUBLIC_ const struct ldb_backend_ops ldb_ildap_backend_ops = {
- .name = "ildap",
+_PUBLIC_ const struct ldb_backend_ops ldb_ldapi_backend_ops = {
+ .name = "ldapi",
.connect_fn = ildb_connect
};
diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c
index c4de8e8da8..65c044c0f4 100644
--- a/source4/lib/ldb/modules/rdn_name.c
+++ b/source4/lib/ldb/modules/rdn_name.c
@@ -119,7 +119,8 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
"RDN mismatch on %s: %s (%s)",
ldb_dn_get_linearized(msg->dn), rdn_name, rdn_val.data);
talloc_free(down_req);
- return LDB_ERR_OPERATIONS_ERROR;
+ /* Match AD's error here */
+ return LDB_ERR_INVALID_DN_SYNTAX;
}
}
diff --git a/source4/lib/registry/hive.c b/source4/lib/registry/hive.c
index 5d56a30b3e..ad6a6421ab 100644
--- a/source4/lib/registry/hive.c
+++ b/source4/lib/registry/hive.c
@@ -22,6 +22,7 @@
#include "includes.h"
#include "hive.h"
#include "system/filesys.h"
+#include "param/param.h"
/** Open a registry file/host/etc */
_PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
@@ -52,7 +53,7 @@ _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
if (!strncmp(peek, "regf", 4)) {
close(fd);
- return reg_open_regf_file(parent_ctx, location, lp_ctx, root);
+ return reg_open_regf_file(parent_ctx, location, lp_iconv_convenience(lp_ctx), root);
} else if (!strncmp(peek, "TDB file", 8)) {
close(fd);
return reg_open_ldb_file(parent_ctx, location, session_info,
diff --git a/source4/lib/registry/hive.h b/source4/lib/registry/hive.h
index 6d9a69c7c5..87f335663d 100644
--- a/source4/lib/registry/hive.h
+++ b/source4/lib/registry/hive.h
@@ -188,7 +188,7 @@ WERROR hive_key_flush(struct hive_key *key);
WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key);
WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
- const char *location, struct loadparm_context *lp_ctx,
+ const char *location, struct smb_iconv_convenience *iconv_convenience,
struct hive_key **key);
WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
struct auth_session_info *session_info,
@@ -200,6 +200,7 @@ WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
const char *location, struct hive_key **key);
WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx,
+ struct smb_iconv_convenience *iconv_convenience,
const char *location,
int major_version,
struct hive_key **key);
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index 0c8a55396e..dfd368ea80 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -36,7 +36,9 @@ struct ldb_key_data
int subkey_count, value_count;
};
-static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg,
+static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
+ struct smb_iconv_convenience *iconv_convenience,
+ struct ldb_message *msg,
const char **name, uint32_t *type,
DATA_BLOB *data)
{
@@ -57,7 +59,7 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg,
{
case REG_SZ:
case REG_EXPAND_SZ:
- data->length = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF8, CH_UTF16,
+ data->length = convert_string_talloc(mem_ctx, iconv_convenience, CH_UTF8, CH_UTF16,
val->data, val->length,
(void **)&data->data);
break;
@@ -281,7 +283,7 @@ static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, struct hive_key *k,
if (idx >= kd->value_count)
return WERR_NO_MORE_ITEMS;
- reg_ldb_unpack_value(mem_ctx, kd->values[idx],
+ reg_ldb_unpack_value(mem_ctx, lp_iconv_convenience(global_loadparm), kd->values[idx],
name, data_type, data);
return WERR_OK;
@@ -310,7 +312,7 @@ static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
if (res->count == 0)
return WERR_BADFILE;
- reg_ldb_unpack_value(mem_ctx, res->msgs[0], NULL, data_type, data);
+ reg_ldb_unpack_value(mem_ctx, lp_iconv_convenience(global_loadparm), res->msgs[0], NULL, data_type, data);
return WERR_OK;
}
@@ -607,7 +609,9 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
if (max_valbufsize != NULL) {
DATA_BLOB data;
- reg_ldb_unpack_value(mem_ctx, kd->values[i], NULL,
+ reg_ldb_unpack_value(mem_ctx,
+ lp_iconv_convenience(global_loadparm),
+ kd->values[i], NULL,
NULL, &data);
*max_valbufsize = MAX(*max_valbufsize, data.length);
talloc_free(data.data);
diff --git a/source4/lib/registry/patchfile.c b/source4/lib/registry/patchfile.c
index a4579010cd..687fd4b91b 100644
--- a/source4/lib/registry/patchfile.c
+++ b/source4/lib/registry/patchfile.c
@@ -27,6 +27,7 @@
_PUBLIC_ WERROR reg_preg_diff_load(int fd,
+ struct smb_iconv_convenience *iconv_convenience,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
@@ -273,6 +274,7 @@ _PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
* Load diff file
*/
_PUBLIC_ WERROR reg_diff_load(const char *filename,
+ struct smb_iconv_convenience *iconv_convenience,
const struct reg_diff_callbacks *callbacks,
void *callback_data)
{
@@ -305,10 +307,10 @@ _PUBLIC_ WERROR reg_diff_load(const char *filename,
#endif
if (strncmp(hdr, "PReg", 4) == 0) {
/* Must be a GPO Registry.pol file */
- return reg_preg_diff_load(fd, callbacks, callback_data);
+ return reg_preg_diff_load(fd, iconv_convenience, callbacks, callback_data);
} else {
/* Must be a normal .REG file */
- return reg_dotreg_diff_load(fd, lp_iconv_convenience(global_loadparm), callbacks, callback_data);
+ return reg_dotreg_diff_load(fd, iconv_convenience, callbacks, callback_data);
}
}
@@ -442,5 +444,6 @@ _PUBLIC_ WERROR reg_diff_apply(struct registry_context *ctx, const char *filenam
callbacks.del_all_values = reg_diff_apply_del_all_values;
callbacks.done = NULL;
- return reg_diff_load(filename, &callbacks, ctx);
+ return reg_diff_load(filename, lp_iconv_convenience(global_loadparm),
+ &callbacks, ctx);
}
diff --git a/source4/lib/registry/patchfile.h b/source4/lib/registry/patchfile.h
index 08a977d9cd..9289390685 100644
--- a/source4/lib/registry/patchfile.h
+++ b/source4/lib/registry/patchfile.h
@@ -43,6 +43,7 @@ WERROR reg_generate_diff(struct registry_context *ctx1,
const struct reg_diff_callbacks *callbacks,
void *callback_data);
WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
+ struct smb_iconv_convenience *iconv_convenience,
struct reg_diff_callbacks **callbacks,
void **callback_data);
WERROR reg_generate_diff_key(struct registry_key *oldkey,
diff --git a/source4/lib/registry/patchfile_dotreg.c b/source4/lib/registry/patchfile_dotreg.c
index 46ea7c0008..6de642ecb8 100644
--- a/source4/lib/registry/patchfile_dotreg.c
+++ b/source4/lib/registry/patchfile_dotreg.c
@@ -101,6 +101,7 @@ static WERROR reg_dotreg_diff_del_all_values(void *callback_data,
* Save registry diff
*/
_PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
+ struct smb_iconv_convenience *iconv_convenience,
struct reg_diff_callbacks **callbacks,
void **callback_data)
{
@@ -109,7 +110,7 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
data = talloc_zero(ctx, struct dotreg_data);
*callback_data = data;
- data->iconv_convenience = lp_iconv_convenience(global_loadparm);
+ data->iconv_convenience = iconv_convenience;
if (filename) {
data->fd = open(filename, O_CREAT, 0755);
diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c
index 9cc9a5dec2..0d39e67450 100644
--- a/source4/lib/registry/patchfile_preg.c
+++ b/source4/lib/registry/patchfile_preg.c
@@ -29,14 +29,14 @@ struct preg_data {
int fd;
};
-static WERROR preg_read_utf16(int fd, char *c)
+static WERROR preg_read_utf16(struct smb_iconv_convenience *ic, int fd, char *c)
{
uint16_t v;
if (read(fd, &v, 2) < 2) {
return WERR_GENERAL_FAILURE;
}
- push_codepoint(lp_iconv_convenience(global_loadparm), c, v);
+ push_codepoint(ic, c, v);
return WERR_OK;
}
@@ -123,6 +123,7 @@ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename,
* Load diff file
*/
_PUBLIC_ WERROR reg_preg_diff_load(int fd,
+ struct smb_iconv_convenience *iconv_convenience,
const struct reg_diff_callbacks *callbacks,
void *callback_data)
{
@@ -162,7 +163,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd,
while(1) {
uint32_t value_type, length;
- if (!W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr))) {
+ if (!W_ERROR_IS_OK(preg_read_utf16(iconv_convenience, fd, buf_ptr))) {
break;
}
if (*buf_ptr != '[') {
@@ -173,7 +174,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd,
/* Get the path */
buf_ptr = buf;
- while (W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
+ while (W_ERROR_IS_OK(preg_read_utf16(iconv_convenience, fd, buf_ptr)) &&
*buf_ptr != ';' && buf_ptr-buf < buf_size) {
buf_ptr++;
}
@@ -181,7 +182,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd,
/* Get the name */
buf_ptr = buf;
- while (W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
+ while (W_ERROR_IS_OK(preg_read_utf16(iconv_convenience, fd, buf_ptr)) &&
*buf_ptr != ';' && buf_ptr-buf < buf_size) {
buf_ptr++;
}
@@ -195,7 +196,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd,
}
/* Read past delimiter */
buf_ptr = buf;
- if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
+ if (!(W_ERROR_IS_OK(preg_read_utf16(iconv_convenience, fd, buf_ptr)) &&
*buf_ptr == ';') && buf_ptr-buf < buf_size) {
DEBUG(0, ("Error in PReg file.\n"));
ret = WERR_GENERAL_FAILURE;
@@ -209,7 +210,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd,
}
/* Read past delimiter */
buf_ptr = buf;
- if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
+ if (!(W_ERROR_IS_OK(preg_read_utf16(iconv_convenience, fd, buf_ptr)) &&
*buf_ptr == ';') && buf_ptr-buf < buf_size) {
DEBUG(0, ("Error in PReg file.\n"));
ret = WERR_GENERAL_FAILURE;
@@ -227,7 +228,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd,
/* Check if delimiter is in place (whine if it isn't) */
buf_ptr = buf;
- if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) &&
+ if (!(W_ERROR_IS_OK(preg_read_utf16(iconv_convenience, fd, buf_ptr)) &&
*buf_ptr == ']') && buf_ptr-buf < buf_size) {
DEBUG(0, ("Warning: Missing ']' in PReg file, expected ']', got '%c' 0x%x.\n",
*buf_ptr, *buf_ptr));
diff --git a/source4/lib/registry/regf.c b/source4/lib/registry/regf.c
index 15b60745f0..cf3e564c0e 100644
--- a/source4/lib/registry/regf.c
+++ b/source4/lib/registry/regf.c
@@ -1863,7 +1863,9 @@ static WERROR regf_save_hbin(struct regf_data *regf)
return WERR_OK;
}
-WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location,
+WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx,
+ struct smb_iconv_convenience *iconv_convenience,
+ const char *location,
int minor_version, struct hive_key **key)
{
struct regf_data *regf;
@@ -1874,7 +1876,7 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location,
regf = (struct regf_data *)talloc_zero(NULL, struct regf_data);
- regf->iconv_convenience = lp_iconv_convenience(global_loadparm);
+ regf->iconv_convenience = iconv_convenience;
W_ERROR_HAVE_NO_MEMORY(regf);
@@ -1950,7 +1952,7 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location,
}
WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, const char *location,
- struct loadparm_context *lp_ctx, struct hive_key **key)
+ struct smb_iconv_convenience *iconv_convenience, struct hive_key **key)
{
struct regf_data *regf;
struct regf_hdr *regf_hdr;
@@ -1959,7 +1961,7 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, const char *location,
regf = (struct regf_data *)talloc_zero(NULL, struct regf_data);
- regf->iconv_convenience = lp_iconv_convenience(lp_ctx);
+ regf->iconv_convenience = iconv_convenience;
W_ERROR_HAVE_NO_MEMORY(regf);
diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c
index 4d27e83a74..1dcb464d80 100644
--- a/source4/lib/registry/tests/hive.c
+++ b/source4/lib/registry/tests/hive.c
@@ -25,6 +25,7 @@
#include "torture/torture.h"
#include "librpc/gen_ndr/winreg.h"
#include "system/filesys.h"
+#include "param/param.h"
static bool test_del_nonexistant_key(struct torture_context *tctx,
const void *test_data)
@@ -349,7 +350,8 @@ static bool hive_setup_regf(struct torture_context *tctx, void **data)
rmdir(dirname);
- error = reg_create_regf_file(tctx, dirname, 5, &key);
+ error = reg_create_regf_file(tctx, lp_iconv_convenience(tctx->lp_ctx),
+ dirname, 5, &key);
if (!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Unable to create new regf file\n");
return false;
diff --git a/source4/lib/registry/tools/regdiff.c b/source4/lib/registry/tools/regdiff.c
index 406eaeea3d..c94380efd2 100644
--- a/source4/lib/registry/tools/regdiff.c
+++ b/source4/lib/registry/tools/regdiff.c
@@ -126,7 +126,7 @@ int main(int argc, const char **argv)
poptFreeContext(pc);
- error = reg_dotreg_diff_save(ctx, outputfile, &callbacks,
+ error = reg_dotreg_diff_save(ctx, outputfile, lp_iconv_convenience(cmdline_lp_ctx), &callbacks,
&callback_data);
if (!W_ERROR_IS_OK(error)) {
fprintf(stderr, "Problem saving registry diff to '%s': %s\n",
diff --git a/source4/lib/replace/Makefile.in b/source4/lib/replace/Makefile.in
index af9522f3a6..c989835a8d 100644
--- a/source4/lib/replace/Makefile.in
+++ b/source4/lib/replace/Makefile.in
@@ -40,7 +40,7 @@ test: all
installcheck: install test
-TEST_OBJS = test/testsuite.o test/os2_delete.o test/strptime.o
+TEST_OBJS = test/testsuite.o test/os2_delete.o test/strptime.o test/getifaddrs.o
testsuite: libreplace.a $(TEST_OBJS)
$(CC) -o testsuite $(TEST_OBJS) -L. -lreplace $(LDFLAGS) $(LIBS)
diff --git a/source4/lib/replace/getifaddrs.c b/source4/lib/replace/getifaddrs.c
index 053657475d..f6f0ec080c 100644
--- a/source4/lib/replace/getifaddrs.c
+++ b/source4/lib/replace/getifaddrs.c
@@ -44,13 +44,14 @@
void rep_freeifaddrs(struct ifaddrs *ifp)
{
- free(ifp->ifa_name);
- free(ifp->ifa_addr);
- free(ifp->ifa_netmask);
- free(ifp->ifa_dstaddr);
- if (ifp->ifa_next != NULL)
+ if (ifp != NULL) {
+ free(ifp->ifa_name);
+ free(ifp->ifa_addr);
+ free(ifp->ifa_netmask);
+ free(ifp->ifa_dstaddr);
freeifaddrs(ifp->ifa_next);
- free(ifp);
+ free(ifp);
+ }
}
static struct sockaddr *sockaddr_dup(struct sockaddr *sa)
@@ -109,38 +110,33 @@ int rep_getifaddrs(struct ifaddrs **ifap)
/* Loop through interfaces, looking for given IP address */
for (i=n-1; i>=0; i--) {
- if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) {
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) == -1) {
freeifaddrs(*ifap);
+ return -1;
}
curif = calloc(1, sizeof(struct ifaddrs));
- if (lastif == NULL) {
- *ifap = curif;
- } else {
- lastif->ifa_next = curif;
- }
-
curif->ifa_name = strdup(ifr[i].ifr_name);
- curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr);
+ curif->ifa_flags = ifr[i].ifr_flags;
curif->ifa_dstaddr = NULL;
curif->ifa_data = NULL;
curif->ifa_next = NULL;
- curif->ifa_netmask = NULL;
- if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) {
- freeifaddrs(*ifap);
- return -1;
- }
-
- curif->ifa_flags = ifr[i].ifr_flags;
-
- if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) {
- freeifaddrs(*ifap);
- return -1;
- }
+ curif->ifa_addr = NULL;
+ if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != -1) {
+ curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr);
+ }
- curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr);
+ curif->ifa_netmask = NULL;
+ if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != -1) {
+ curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr);
+ }
+ if (lastif == NULL) {
+ *ifap = curif;
+ } else {
+ lastif->ifa_next = curif;
+ }
lastif = curif;
}
@@ -363,32 +359,3 @@ int rep_getifaddrs(struct ifaddrs **ifap)
return -1;
}
#endif
-
-#ifdef AUTOCONF_TEST
-/* this is the autoconf driver to test getifaddrs() */
-
- int main()
-{
- struct ifaddrs *ifs = NULL;
- int ret;
-
- ret = getifaddrs(&ifs);
- if (ret != 0) {
- perror("getifaddrs() failed");
- return 1;
- }
-
- while (ifs) {
- printf("%-10s ", ifs->ifa_name);
- if (ifs->ifa_addr != NULL &&
- ifs->ifa_addr->sa_family == AF_INET) {
- printf("IP=%s ", inet_ntoa(((struct sockaddr_in *)ifs->ifa_addr)->sin_addr));
- if (ifs->ifa_netmask != NULL)
- printf("NETMASK=%s", inet_ntoa(((struct sockaddr_in *)ifs->ifa_netmask)->sin_addr));
- }
- printf("\n");
- ifs = ifs->ifa_next;
- }
- return 0;
-}
-#endif
diff --git a/source4/lib/replace/getifaddrs.m4 b/source4/lib/replace/getifaddrs.m4
index 767797e8d2..6cca155de3 100644
--- a/source4/lib/replace/getifaddrs.m4
+++ b/source4/lib/replace/getifaddrs.m4
@@ -49,7 +49,11 @@ AC_TRY_RUN([
#define AUTOCONF_TEST 1
#define SOCKET_WRAPPER_NOT_REPLACE
#include "$libreplacedir/replace.c"
-#include "$libreplacedir/getifaddrs.c"],
+#include "$libreplacedir/inet_ntop.c"
+#include "$libreplacedir/snprintf.c"
+#include "$libreplacedir/getifaddrs.c"
+#define getifaddrs_test main
+#include "$libreplacedir/test/getifaddrs.c"],
libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
@@ -67,7 +71,11 @@ AC_TRY_RUN([
#undef _XOPEN_SOURCE_EXTENDED
#define SOCKET_WRAPPER_NOT_REPLACE
#include "$libreplacedir/replace.c"
-#include "$libreplacedir/getifaddrs.c"],
+#include "$libreplacedir/inet_ntop.c"
+#include "$libreplacedir/snprintf.c"
+#include "$libreplacedir/getifaddrs.c"
+#define getifaddrs_test main
+#include "$libreplacedir/test/getifaddrs.c"],
libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
@@ -84,7 +92,11 @@ AC_TRY_RUN([
#define AUTOCONF_TEST 1
#define SOCKET_WRAPPER_NOT_REPLACE
#include "$libreplacedir/replace.c"
-#include "$libreplacedir/getifaddrs.c"],
+#include "$libreplacedir/inet_ntop.c"
+#include "$libreplacedir/snprintf.c"
+#include "$libreplacedir/getifaddrs.c"
+#define getifaddrs_test main
+#include "$libreplacedir/test/getifaddrs.c"],
libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
@@ -100,7 +112,11 @@ AC_TRY_RUN([
#define AUTOCONF_TEST 1
#define SOCKET_WRAPPER_NOT_REPLACE
#include "$libreplacedir/replace.c"
-#include "$libreplacedir/getifaddrs.c"],
+#include "$libreplacedir/inet_ntop.c"
+#include "$libreplacedir/snprintf.c"
+#include "$libreplacedir/getifaddrs.c"
+#define getifaddrs_test main
+#include "$libreplacedir/test/getifaddrs.c"],
libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
diff --git a/source4/lib/replace/test/getifaddrs.c b/source4/lib/replace/test/getifaddrs.c
new file mode 100644
index 0000000000..8b00ac2f40
--- /dev/null
+++ b/source4/lib/replace/test/getifaddrs.c
@@ -0,0 +1,100 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * libreplace getifaddrs test
+ *
+ * Copyright (C) Michael Adam <obnox@samba.org> 2008
+ *
+ * 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/>.
+ */
+
+#ifndef AUTOCONF_TEST
+#include "replace.h"
+#include "system/network.h"
+#endif
+
+#ifdef HAVE_INET_NTOP
+#define rep_inet_ntop inet_ntop
+#endif
+
+static const char *format_sockaddr(struct sockaddr *addr,
+ char *addrstring,
+ socklen_t addrlen)
+{
+ const char *result = NULL;
+
+ if (addr->sa_family == AF_INET) {
+ result = rep_inet_ntop(AF_INET,
+ &((struct sockaddr_in *)addr)->sin_addr,
+ addrstring,
+ addrlen);
+#ifdef HAVE_STRUCT_SOCKADDR_IN6
+ } else if (addr->sa_family == AF_INET6) {
+ result = rep_inet_ntop(AF_INET6,
+ &((struct sockaddr_in6 *)addr)->sin6_addr,
+ addrstring,
+ addrlen);
+#endif
+ }
+ return result;
+}
+
+int getifaddrs_test(void)
+{
+ struct ifaddrs *ifs = NULL;
+ struct ifaddrs *ifs_head = NULL;
+ int ret;
+
+ ret = getifaddrs(&ifs);
+ ifs_head = ifs;
+ if (ret != 0) {
+ fprintf(stderr, "getifaddrs() failed: %s\n", strerror(errno));
+ return 1;
+ }
+
+ while (ifs) {
+ printf("%-10s ", ifs->ifa_name);
+ if (ifs->ifa_addr != NULL) {
+ char addrstring[INET6_ADDRSTRLEN];
+ const char *result;
+
+ result = format_sockaddr(ifs->ifa_addr,
+ addrstring,
+ sizeof(addrstring));
+ if (result != NULL) {
+ printf("IP=%s ", addrstring);
+ }
+
+ if (ifs->ifa_netmask != NULL) {
+ result = format_sockaddr(ifs->ifa_netmask,
+ addrstring,
+ sizeof(addrstring));
+ if (result != NULL) {
+ printf("NETMASK=%s", addrstring);
+ }
+ } else {
+ printf("AF=%d ", ifs->ifa_addr->sa_family);
+ }
+ } else {
+ printf("<no address>");
+ }
+
+ printf("\n");
+ ifs = ifs->ifa_next;
+ }
+
+ freeifaddrs(ifs_head);
+
+ return 0;
+}
diff --git a/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c
index c9f3301005..b538360365 100644
--- a/source4/lib/replace/test/testsuite.c
+++ b/source4/lib/replace/test/testsuite.c
@@ -856,21 +856,18 @@ static int test_strptime(void)
return libreplace_test_strptime();
}
+extern int getifaddrs_test(void);
+
static int test_getifaddrs(void)
{
- struct ifaddrs *ifa;
- int ret;
printf("test: getifaddrs\n");
- ret = getifaddrs(&ifa);
- if (ret != 0) {
+ if (getifaddrs_test() != 0) {
printf("failure: getifaddrs\n");
return false;
}
- freeifaddrs(ifa);
-
printf("success: getifaddrs\n");
return true;
}