[SCM] Samba Shared Repository - branch master updated - 264277b555a7bd9d2308ef6ec24ecef77fa1d401

Jelmer Vernooij jelmer at samba.org
Fri Oct 24 13:46:56 GMT 2008


The branch, master has been updated
       via  264277b555a7bd9d2308ef6ec24ecef77fa1d401 (commit)
       via  a8035258631d2773942c0dfab09c2741c2245390 (commit)
       via  12f7056aacef9d671cfd0dc453b70266f3232dae (commit)
       via  e37ce5ba9fda9e7becebb5a2e8535dfe0a8f848e (commit)
       via  27dce768d3801409a734f24765ea92e67ffbd014 (commit)
       via  61013deff80dbe3a3dfaa7b5060609500f1f63fa (commit)
       via  56a0b035c676af73eaa93446132e930cc95fae94 (commit)
       via  37d885c51a559d2be7dd15f46a80027e4f1dffef (commit)
       via  284f523ec70477c408887a478e8392671f12dfff (commit)
       via  8b06312f7eeff5ea8625677478792888774bd2be (commit)
       via  5d146d0178d7da8d8f14f340dacb5b01fd03fab8 (commit)
       via  2d46992337befd46c65df5e60a821bdf9f340b6e (commit)
       via  2cabbb2eeb7d62f8df1c4d20d90adbd53828dd8a (commit)
       via  9d679c9a67f6dcb1ed1597476c63c8adf3b3f426 (commit)
       via  e9ab9e52f0bbbf2c9f95b5344db1c7ba305bd59f (commit)
       via  922a29992ee38b8e1c851192677b89a2cd59a91a (commit)
       via  23b04a31f14dca0a3f9bcd58181f84db4b6092c7 (commit)
       via  0f043c197c473c801fc32c727194b5a2d6ae232f (commit)
       via  7ec58471dfd12cbd3aa38a07145b1ecceaec1933 (commit)
       via  5e4767b532cc2f7401a9a1e7601433bd5acbdf35 (commit)
       via  420781bf46a036bcf308eaa6390bd07ab18be7b1 (commit)
       via  09a63accb8863a883ef8aba3a44776ac92ae5764 (commit)
      from  0058176ae32eff7acb07c013d48cca294bd4bf82 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 264277b555a7bd9d2308ef6ec24ecef77fa1d401
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 15:45:13 2008 +0200

    Remove use of global_loadparm in last Python script.

commit a8035258631d2773942c0dfab09c2741c2245390
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 15:30:43 2008 +0200

    Regenerate SWIG files.

commit 12f7056aacef9d671cfd0dc453b70266f3232dae
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 15:00:09 2008 +0200

    Remove access to global_loadparm from python module.

commit e37ce5ba9fda9e7becebb5a2e8535dfe0a8f848e
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 14:57:55 2008 +0200

    Mark global_loadparm as deprecated.

commit 27dce768d3801409a734f24765ea92e67ffbd014
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 14:57:03 2008 +0200

    Remove more usages of global_loadparm.

commit 61013deff80dbe3a3dfaa7b5060609500f1f63fa
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 14:45:31 2008 +0200

    Remove dependency of charset code on loadparm.

commit 56a0b035c676af73eaa93446132e930cc95fae94
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 14:31:16 2008 +0200

    Remove more uses of global_loadparm.

commit 37d885c51a559d2be7dd15f46a80027e4f1dffef
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 14:26:46 2008 +0200

    Remove iconv_convenience argument from convert_string{,talloc}() but
    make them wrappers around convert_string{,talloc}_convenience().

commit 284f523ec70477c408887a478e8392671f12dfff
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 13:22:12 2008 +0200

    Remove a few more usages of global_loadparm.

commit 8b06312f7eeff5ea8625677478792888774bd2be
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 13:13:27 2008 +0200

    Eliminate another instance of global_loadparm.

commit 5d146d0178d7da8d8f14f340dacb5b01fd03fab8
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 04:39:09 2008 +0200

    Avoid retrieving iconv convenience during loops.

commit 2d46992337befd46c65df5e60a821bdf9f340b6e
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 04:38:31 2008 +0200

    Remove const so return value can be freed.

commit 2cabbb2eeb7d62f8df1c4d20d90adbd53828dd8a
Merge: 9d679c9a67f6dcb1ed1597476c63c8adf3b3f426 0058176ae32eff7acb07c013d48cca294bd4bf82
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 04:19:08 2008 +0200

    Merge branch 'master' of ssh://git.samba.org/data/git/samba

commit 9d679c9a67f6dcb1ed1597476c63c8adf3b3f426
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 04:18:47 2008 +0200

    Fix merged build paths.

commit e9ab9e52f0bbbf2c9f95b5344db1c7ba305bd59f
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 04:00:07 2008 +0200

    Just hardcode workgroup to empty string, to avoid use of
    global_loadparm.

commit 922a29992ee38b8e1c851192677b89a2cd59a91a
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 03:40:09 2008 +0200

    Remove iconv_convenience parameter from simple string push/pull
    functions.

commit 23b04a31f14dca0a3f9bcd58181f84db4b6092c7
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 02:58:12 2008 +0200

    Fix include path to pytalloc.

commit 0f043c197c473c801fc32c727194b5a2d6ae232f
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 02:52:51 2008 +0200

    Move pytalloc to talloc directory.

commit 7ec58471dfd12cbd3aa38a07145b1ecceaec1933
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 02:51:03 2008 +0200

    Split up codepoints code, use consistent _m suffix.

commit 5e4767b532cc2f7401a9a1e7601433bd5acbdf35
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 01:19:33 2008 +0200

    Rename string_replace_w to string_replace_m, which is more correct.

commit 420781bf46a036bcf308eaa6390bd07ab18be7b1
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 01:18:56 2008 +0200

    Remove unnecessary include, improve function name.

commit 09a63accb8863a883ef8aba3a44776ac92ae5764
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 24 00:06:35 2008 +0200

    Move charset library to top level.

-----------------------------------------------------------------------

Summary of changes:
 lib/talloc/pytalloc.c                          |   52 ++
 lib/talloc/pytalloc.h                          |   51 ++
 lib/util/charset/charcnv.c                     |  444 +++++++++++
 lib/util/charset/charset.h                     |  164 ++++
 lib/util/charset/codepoints.c                  |  118 +++
 lib/util/charset/config.m4                     |   86 +++
 lib/util/charset/config.mk                     |   11 +
 lib/util/charset/iconv.c                       |  711 ++++++++++++++++++
 lib/util/charset/tests/charset.c               |  272 +++++++
 lib/util/charset/tests/iconv.c                 |  424 +++++++++++
 lib/util/charset/util_unistr.c                 |  960 ++++++++++++++++++++++++
 lib/util/util.h                                |    2 +-
 librpc/ndr/libndr.h                            |    2 +-
 pidl/lib/Parse/Pidl/Samba4/Python.pm           |    2 +-
 source3/include/includes.h                     |    2 +-
 source3/samba4.m4                              |    2 +-
 source3/samba4.mk                              |    2 +-
 source4/Makefile                               |    2 +-
 source4/auth/ntlm/auth_server.c                |    2 +
 source4/auth/ntlm/auth_util.c                  |    2 +-
 source4/auth/ntlm/ntlm_check.c                 |    2 +-
 source4/auth/ntlmssp/ntlmssp_client.c          |    2 -
 source4/auth/ntlmssp/ntlmssp_parse.c           |   13 +-
 source4/auth/ntlmssp/ntlmssp_server.c          |    2 -
 source4/auth/ntlmssp/ntlmssp_sign.c            |    2 -
 source4/client/cifsdd.c                        |   14 +-
 source4/client/cifsdd.h                        |    3 +-
 source4/client/cifsddio.c                      |   18 +-
 source4/client/client.c                        |   17 +-
 source4/configure.ac                           |    2 +-
 source4/dsdb/common/util.c                     |    2 +-
 source4/dsdb/samdb/ldb_modules/password_hash.c |    6 +-
 source4/dsdb/schema/schema_init.c              |    2 +-
 source4/dsdb/schema/schema_syntax.c            |   11 +-
 source4/kdc/kpasswdd.c                         |    6 +-
 source4/lib/charset/charcnv.c                  |  768 -------------------
 source4/lib/charset/charset.h                  |  154 ----
 source4/lib/charset/config.m4                  |   86 ---
 source4/lib/charset/config.mk                  |   13 -
 source4/lib/charset/iconv.c                    |  711 ------------------
 source4/lib/charset/tests/charset.c            |  272 -------
 source4/lib/charset/tests/iconv.c              |  424 -----------
 source4/lib/charset/util_unistr.c              |  684 -----------------
 source4/lib/messaging/pymessaging.c            |   13 +-
 source4/lib/registry/ldb.c                     |   14 +-
 source4/lib/registry/patchfile.c               |    6 +-
 source4/lib/registry/registry.h                |    3 +-
 source4/lib/registry/registry.i                |   11 +-
 source4/lib/registry/registry_wrap.c           |   44 +-
 source4/lib/registry/tests/diff.c              |    2 +-
 source4/lib/registry/tests/generic.c           |    6 +-
 source4/lib/registry/tools/regpatch.c          |    2 +-
 source4/lib/registry/util.c                    |    4 +-
 source4/lib/tdr/tdr.c                          |    4 +-
 source4/lib/tdr/tdr.h                          |    2 +-
 source4/libcli/auth/smbencrypt.c               |   18 +-
 source4/libcli/cliconnect.c                    |   12 +-
 source4/libcli/raw/clitransport.c              |    9 +-
 source4/libcli/raw/clitree.c                   |   11 +-
 source4/libcli/raw/libcliraw.h                 |    3 +
 source4/libcli/raw/rawfileinfo.c               |    1 -
 source4/libcli/raw/rawrequest.c                |   12 +-
 source4/libcli/smb2/request.c                  |    4 +-
 source4/libcli/smb_composite/connect.c         |    2 +-
 source4/libcli/smb_composite/fetchfile.c       |    1 +
 source4/libcli/smb_composite/fsinfo.c          |    1 +
 source4/libcli/smb_composite/sesssetup.c       |    4 +-
 source4/libcli/smb_composite/smb_composite.h   |    3 +
 source4/libcli/util/clilsa.c                   |    2 +-
 source4/libnet/libnet_samdump.c                |    2 +-
 source4/libnet/libnet_user.h                   |    2 +-
 source4/librpc/ndr/ndr_string.c                |   20 +-
 source4/librpc/rpc/dcerpc_connect.c            |    2 +
 source4/main.mk                                |    2 +-
 source4/nsswitch/wbinfo.c                      |    2 +-
 source4/ntvfs/cifs/vfs_cifs.c                  |    1 +
 source4/ntvfs/posix/pvfs_util.c                |    5 +-
 source4/ntvfs/print/vfs_print.c                |    4 +-
 source4/param/loadparm.c                       |   12 +-
 source4/param/param.h                          |   12 +-
 source4/param/param.i                          |    3 -
 source4/param/param.py                         |    1 -
 source4/param/param_wrap.c                     |   25 -
 source4/rpc_server/samr/samr_password.c        |    6 +-
 source4/scripting/bin/subunitrun               |    2 -
 source4/scripting/python/config.mk             |    2 +-
 source4/scripting/python/modules.h             |    2 +
 source4/scripting/python/pytalloc.c            |   52 --
 source4/scripting/python/pytalloc.h            |   51 --
 source4/smb_server/blob.c                      |    4 +-
 source4/smb_server/smb/nttrans.c               |    2 +-
 source4/smb_server/smb/request.c               |    6 +-
 source4/smb_server/smb2/fileio.c               |    2 +-
 source4/static_deps.mk                         |    4 +-
 source4/torture/basic/base.c                   |    3 +-
 source4/torture/basic/charset.c                |    2 +-
 source4/torture/basic/misc.c                   |    1 +
 source4/torture/basic/scanner.c                |   21 +-
 source4/torture/basic/utable.c                 |    4 +-
 source4/torture/gentest.c                      |    3 +-
 source4/torture/local/config.mk                |    4 +-
 source4/torture/locktest.c                     |    3 +-
 source4/torture/masktest.c                     |    9 +-
 source4/torture/rap/rap.c                      |    2 +-
 source4/torture/raw/composite.c                |    2 +
 source4/torture/raw/lockbench.c                |    1 +
 source4/torture/raw/oplock.c                   |    3 +-
 source4/torture/raw/tconrate.c                 |    3 +-
 source4/torture/rpc/join.c                     |    6 +-
 source4/torture/rpc/netlogon.c                 |    2 +-
 source4/torture/rpc/samba3rpc.c                |   23 +-
 source4/torture/rpc/samlogon.c                 |    7 +-
 source4/torture/rpc/schannel.c                 |    4 +-
 source4/torture/rpc/spoolss_win.c              |    2 +-
 source4/torture/rpc/wkssvc.c                   |    3 +-
 source4/torture/unix/unix_info2.c              |    3 +-
 source4/torture/unix/whoami.c                  |    3 +-
 source4/torture/util_smb.c                     |    3 +-
 source4/winbind/wb_pam_auth.c                  |    1 -
 119 files changed, 3587 insertions(+), 3476 deletions(-)
 create mode 100644 lib/talloc/pytalloc.c
 create mode 100644 lib/talloc/pytalloc.h
 create mode 100644 lib/util/charset/charcnv.c
 create mode 100644 lib/util/charset/charset.h
 create mode 100644 lib/util/charset/codepoints.c
 create mode 100644 lib/util/charset/config.m4
 create mode 100644 lib/util/charset/config.mk
 create mode 100644 lib/util/charset/iconv.c
 create mode 100644 lib/util/charset/tests/charset.c
 create mode 100644 lib/util/charset/tests/iconv.c
 create mode 100644 lib/util/charset/util_unistr.c
 delete mode 100644 source4/lib/charset/charcnv.c
 delete mode 100644 source4/lib/charset/charset.h
 delete mode 100644 source4/lib/charset/config.m4
 delete mode 100644 source4/lib/charset/config.mk
 delete mode 100644 source4/lib/charset/iconv.c
 delete mode 100644 source4/lib/charset/tests/charset.c
 delete mode 100644 source4/lib/charset/tests/iconv.c
 delete mode 100644 source4/lib/charset/util_unistr.c
 delete mode 100644 source4/scripting/python/pytalloc.c
 delete mode 100644 source4/scripting/python/pytalloc.h


Changeset truncated at 500 lines:

diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
new file mode 100644
index 0000000..f4b7d10
--- /dev/null
+++ b/lib/talloc/pytalloc.c
@@ -0,0 +1,52 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Python/Talloc glue
+   Copyright (C) Jelmer Vernooij <jelmer at 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/>.
+*/
+
+#include <talloc.h>
+#include "../lib/talloc/pytalloc.h"
+
+void py_talloc_dealloc(PyObject* self)
+{
+	py_talloc_Object *obj = (py_talloc_Object *)self;
+	talloc_free(obj->talloc_ctx);
+	obj->talloc_ctx = NULL;
+	PyObject_Del(self);
+}
+
+PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, 
+						   void *ptr)
+{
+	py_talloc_Object *ret = PyObject_New(py_talloc_Object, py_type);
+	ret->talloc_ctx = talloc_new(NULL);
+	if (ret->talloc_ctx == NULL) {
+		return NULL;
+	}
+	if (talloc_reference(ret->talloc_ctx, mem_ctx) == NULL) {
+		return NULL;
+	}
+	ret->ptr = ptr;
+	return (PyObject *)ret;
+}
+
+PyObject *py_talloc_default_repr(PyObject *py_obj)
+{
+	py_talloc_Object *obj = (py_talloc_Object *)py_obj;
+	PyTypeObject *type = (PyTypeObject*)PyObject_Type((PyObject *)obj);
+
+	return PyString_FromFormat("<%s talloc object at 0x%x>", type->tp_name, (intptr_t)py_obj);
+}
diff --git a/lib/talloc/pytalloc.h b/lib/talloc/pytalloc.h
new file mode 100644
index 0000000..aad5840
--- /dev/null
+++ b/lib/talloc/pytalloc.h
@@ -0,0 +1,51 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Jelmer Vernooij <jelmer at 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 _PY_TALLOC_H_
+#define _PY_TALLOC_H_
+
+#include <Python.h>
+
+typedef struct {
+	PyObject_HEAD
+	TALLOC_CTX *talloc_ctx;
+	void *ptr;
+} py_talloc_Object;
+
+/* Deallocate a py_talloc_Object */
+void py_talloc_dealloc(PyObject* self);
+
+/* Retrieve the pointer for a py_talloc_object. Like talloc_get_type() 
+ * but for py_talloc_Objects. */
+
+/* FIXME: Call PyErr_SetString(PyExc_TypeError, "expected " __STR(type) ") 
+ * when talloc_get_type() returns NULL. */
+#define py_talloc_get_type(py_obj, type) \
+	talloc_get_type(py_talloc_get_ptr(py_obj), type)
+
+#define py_talloc_get_ptr(py_obj) ((py_talloc_Object *)py_obj)->ptr
+#define py_talloc_get_mem_ctx(py_obj)  ((py_talloc_Object *)py_obj)->talloc_ctx
+
+PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
+#define py_talloc_import(py_type, talloc_ptr) py_talloc_import_ex(py_type, talloc_ptr, talloc_ptr)
+
+/* Sane default implementation of reprfunc. */
+PyObject *py_talloc_default_repr(PyObject *py_obj);
+
+#endif /* _PY_TALLOC_H_ */
diff --git a/lib/util/charset/charcnv.c b/lib/util/charset/charcnv.c
new file mode 100644
index 0000000..d63a9ce
--- /dev/null
+++ b/lib/util/charset/charcnv.c
@@ -0,0 +1,444 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Character set conversion Extensions
+   Copyright (C) Igor Vergeichik <iverg at mail.ru> 2001
+   Copyright (C) Andrew Tridgell 2001
+   Copyright (C) Simo Sorce 2001
+   Copyright (C) Jelmer Vernooij 2007
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+#include "includes.h"
+#include "system/iconv.h"
+
+/**
+ * @file
+ *
+ * @brief Character-set conversion routines built on our iconv.
+ * 
+ * @note Samba's internal character set (at least in the 3.0 series)
+ * is always the same as the one for the Unix filesystem.  It is
+ * <b>not</b> necessarily UTF-8 and may be different on machines that
+ * need i18n filenames to be compatible with Unix software.  It does
+ * have to be a superset of ASCII.  All multibyte sequences must start
+ * with a byte with the high bit set.
+ *
+ * @sa lib/iconv.c
+ */
+
+struct smb_iconv_convenience {
+	const char *unix_charset;
+	const char *dos_charset;
+	bool native_iconv;
+	smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
+};
+
+
+/**
+ * Return the name of a charset to give to iconv().
+ **/
+static const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch)
+{
+	switch (ch) {
+	case CH_UTF16: return "UTF-16LE";
+	case CH_UNIX: return ic->unix_charset;
+	case CH_DOS: return ic->dos_charset;
+	case CH_UTF8: return "UTF8";
+	case CH_UTF16BE: return "UTF-16BE";
+	default:
+	return "ASCII";
+	}
+}
+
+/**
+ re-initialize iconv conversion descriptors
+**/
+static int close_iconv_convenience(struct smb_iconv_convenience *data)
+{
+	unsigned c1, c2;
+	for (c1=0;c1<NUM_CHARSETS;c1++) {
+		for (c2=0;c2<NUM_CHARSETS;c2++) {
+			if (data->conv_handles[c1][c2] != NULL) {
+				if (data->conv_handles[c1][c2] != (smb_iconv_t)-1) {
+					smb_iconv_close(data->conv_handles[c1][c2]);
+				}
+				data->conv_handles[c1][c2] = NULL;
+			}
+		}
+	}
+
+	return 0;
+}
+
+_PUBLIC_ struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx,
+							 const char *dos_charset,
+							 const char *unix_charset,
+							 bool native_iconv)
+{
+	struct smb_iconv_convenience *ret = talloc_zero(mem_ctx, 
+					struct smb_iconv_convenience);
+
+	if (ret == NULL) {
+		return NULL;
+	}
+
+	talloc_set_destructor(ret, close_iconv_convenience);
+
+	ret->dos_charset = talloc_strdup(ret, dos_charset);
+	ret->unix_charset = talloc_strdup(ret, unix_charset);
+	ret->native_iconv = native_iconv;
+
+	return ret;
+}
+
+/*
+  on-demand initialisation of conversion handles
+*/
+static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic,
+				   charset_t from, charset_t to)
+{
+	const char *n1, *n2;
+	static bool initialised;
+
+	if (initialised == false) {
+		initialised = true;
+		
+#ifdef LC_ALL
+		/* we set back the locale to C to get ASCII-compatible
+		   toupper/lower functions.  For now we do not need
+		   any other POSIX localisations anyway. When we
+		   should really need localized string functions one
+		   day we need to write our own ascii_tolower etc.
+		*/
+		setlocale(LC_ALL, "C");
+#endif
+	}
+
+	if (ic->conv_handles[from][to]) {
+		return ic->conv_handles[from][to];
+	}
+
+	n1 = charset_name(ic, from);
+	n2 = charset_name(ic, to);
+
+	ic->conv_handles[from][to] = smb_iconv_open_ex(ic, n2, n1, 
+						       ic->native_iconv);
+	
+	if (ic->conv_handles[from][to] == (smb_iconv_t)-1) {
+		if ((from == CH_DOS || to == CH_DOS) &&
+		    strcasecmp(charset_name(ic, CH_DOS), "ASCII") != 0) {
+			DEBUG(0,("dos charset '%s' unavailable - using ASCII\n",
+				 charset_name(ic, CH_DOS)));
+			ic->dos_charset = "ASCII";
+
+			n1 = charset_name(ic, from);
+			n2 = charset_name(ic, to);
+			
+			ic->conv_handles[from][to] = 
+				smb_iconv_open_ex(ic, n2, n1, ic->native_iconv);
+		}
+	}
+
+	return ic->conv_handles[from][to];
+}
+
+
+/**
+ * Convert string from one encoding to another, making error checking etc
+ *
+ * @param src pointer to source string (multibyte or singlebyte)
+ * @param srclen length of the source string in bytes
+ * @param dest pointer to destination string (multibyte or singlebyte)
+ * @param destlen maximal length allowed for string
+ * @returns the number of bytes occupied in the destination
+ **/
+_PUBLIC_ ssize_t convert_string_convenience(struct smb_iconv_convenience *ic,
+				charset_t from, charset_t to,
+				void const *src, size_t srclen, 
+				void *dest, size_t destlen)
+{
+	size_t i_len, o_len;
+	size_t retval;
+	const char* inbuf = (const char*)src;
+	char* outbuf = (char*)dest;
+	smb_iconv_t descriptor;
+
+	if (srclen == (size_t)-1)
+		srclen = strlen(inbuf)+1;
+
+	descriptor = get_conv_handle(ic, from, to);
+
+	if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
+		/* conversion not supported, use as is */
+		size_t len = MIN(srclen,destlen);
+		memcpy(dest,src,len);
+		return len;
+	}
+
+	i_len=srclen;
+	o_len=destlen;
+	retval = smb_iconv(descriptor,  &inbuf, &i_len, &outbuf, &o_len);
+	if(retval==(size_t)-1) {
+	    	const char *reason;
+		switch(errno) {
+			case EINVAL:
+				reason="Incomplete multibyte sequence";
+				return -1;
+			case E2BIG:
+				reason="No more room"; 
+				if (from == CH_UNIX) {
+					DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d - '%s'\n",
+						 charset_name(ic, from), charset_name(ic, to),
+						 (int)srclen, (int)destlen, 
+						 (const char *)src));
+				} else {
+					DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d\n",
+						 charset_name(ic, from), charset_name(ic, to),
+						 (int)srclen, (int)destlen));
+				}
+			       return -1;
+			case EILSEQ:
+			       reason="Illegal multibyte sequence";
+			       return -1;
+		}
+		/* smb_panic(reason); */
+	}
+	return destlen-o_len;
+}
+	
+_PUBLIC_ ssize_t convert_string_talloc_descriptor(TALLOC_CTX *ctx, smb_iconv_t descriptor, void const *src, size_t srclen, void **dest)
+{
+	size_t i_len, o_len, destlen;
+	size_t retval;
+	const char *inbuf = (const char *)src;
+	char *outbuf, *ob;
+
+	*dest = NULL;
+
+	/* it is _very_ rare that a conversion increases the size by
+	   more than 3x */
+	destlen = srclen;
+	outbuf = NULL;
+convert:
+	destlen = 2 + (destlen*3);
+	ob = talloc_realloc(ctx, outbuf, char, destlen);
+	if (!ob) {
+		DEBUG(0, ("convert_string_talloc: realloc failed!\n"));
+		talloc_free(outbuf);
+		return (size_t)-1;
+	} else {
+		outbuf = ob;
+	}
+
+	/* we give iconv 2 less bytes to allow us to terminate at the
+	   end */
+	i_len = srclen;
+	o_len = destlen-2;
+	retval = smb_iconv(descriptor,
+			   &inbuf, &i_len,
+			   &outbuf, &o_len);
+	if(retval == (size_t)-1) 		{
+	    	const char *reason="unknown error";
+		switch(errno) {
+			case EINVAL:
+				reason="Incomplete multibyte sequence";
+				break;
+			case E2BIG:
+				goto convert;		
+			case EILSEQ:
+				reason="Illegal multibyte sequence";
+				break;
+		}
+		DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf));
+		talloc_free(ob);
+		return (size_t)-1;
+	}
+	
+	destlen = (destlen-2) - o_len;
+
+	/* guarantee null termination in all charsets */
+	SSVAL(ob, destlen, 0);
+
+	*dest = ob;
+
+	return destlen;
+}
+
+/**
+ * Convert between character sets, allocating a new buffer using talloc for the result.
+ *
+ * @param srclen length of source buffer.
+ * @param dest always set at least to NULL
+ * @note -1 is not accepted for srclen.
+ *
+ * @returns Size in bytes of the converted string; or -1 in case of error.
+ **/
+
+_PUBLIC_ ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx, 
+				       struct smb_iconv_convenience *ic, 
+				       charset_t from, charset_t to, 
+				       void const *src, size_t srclen, 
+				       void **dest)
+{
+	smb_iconv_t descriptor;
+
+	*dest = NULL;
+
+	if (src == NULL || srclen == (size_t)-1 || srclen == 0)
+		return (size_t)-1;
+
+	descriptor = get_conv_handle(ic, from, to);
+
+	if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
+		/* conversion not supported, return -1*/
+		DEBUG(3, ("convert_string_talloc: conversion from %s to %s not supported!\n",
+			  charset_name(ic, from), 
+			  charset_name(ic, to)));
+		return -1;
+	}
+
+	return convert_string_talloc_descriptor(ctx, descriptor, src, srclen, dest);
+}
+
+/*
+  return the unicode codepoint for the next multi-byte CH_UNIX character
+  in the string
+
+  also return the number of bytes consumed (which tells the caller
+  how many bytes to skip to get to the next CH_UNIX character)
+
+  return INVALID_CODEPOINT if the next character cannot be converted
+*/
+_PUBLIC_ codepoint_t next_codepoint(struct smb_iconv_convenience *ic, 
+				    const char *str, size_t *size)
+{
+	/* it cannot occupy more than 4 bytes in UTF16 format */
+	uint8_t buf[4];
+	smb_iconv_t descriptor;
+	size_t ilen_orig;
+	size_t ilen;
+	size_t olen;
+	char *outbuf;
+
+	if ((str[0] & 0x80) == 0) {
+		*size = 1;
+		return (codepoint_t)str[0];
+	}
+
+	/* we assume that no multi-byte character can take
+	   more than 5 bytes. This is OK as we only
+	   support codepoints up to 1M */
+	ilen_orig = strnlen(str, 5);
+	ilen = ilen_orig;
+
+	descriptor = get_conv_handle(ic, CH_UNIX, CH_UTF16);
+	if (descriptor == (smb_iconv_t)-1) {
+		*size = 1;
+		return INVALID_CODEPOINT;
+	}
+
+	/* this looks a little strange, but it is needed to cope
+	   with codepoints above 64k */
+	olen = 2;
+	outbuf = (char *)buf;
+	smb_iconv(descriptor, &str, &ilen, &outbuf, &olen);
+	if (olen == 2) {
+		olen = 4;
+		outbuf = (char *)buf;
+		smb_iconv(descriptor,  &str, &ilen, &outbuf, &olen);
+		if (olen == 4) {
+			/* we didn't convert any bytes */
+			*size = 1;
+			return INVALID_CODEPOINT;
+		}
+		olen = 4 - olen;
+	} else {
+		olen = 2 - olen;
+	}
+
+	*size = ilen_orig - ilen;
+
+	if (olen == 2) {
+		return (codepoint_t)SVAL(buf, 0);
+	}
+	if (olen == 4) {
+		/* decode a 4 byte UTF16 character manually */
+		return (codepoint_t)0x10000 + 
+			(buf[2] | ((buf[3] & 0x3)<<8) | 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list