diff options
author | Günther Deschner <gd@samba.org> | 2016-11-10 15:15:05 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2017-01-06 12:28:19 +0100 |
commit | 06978c65414a3afb25e22d40379208ca3857bcbc (patch) | |
tree | e65cd896ab63fe91618844fc7783b9f3aa5b7498 /libgpo | |
parent | dcb26801632d354e4037f146f89d55448fbbb622 (diff) | |
download | samba-06978c65414a3afb25e22d40379208ca3857bcbc.tar.gz |
libgpo: deal with non utf16-le ini files.
Guenther
Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'libgpo')
-rw-r--r-- | libgpo/gpo_ini.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/libgpo/gpo_ini.c b/libgpo/gpo_ini.c index 603d3044171..0d45dbb2de4 100644 --- a/libgpo/gpo_ini.c +++ b/libgpo/gpo_ini.c @@ -87,12 +87,22 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx, return NT_STATUS_INVALID_PARAMETER; } - data_in = (uint8_t *)file_load(filename_in, &n, 0, NULL); + data_in = (uint8_t *)file_load(filename_in, &n, 0, mem_ctx); if (!data_in) { status = NT_STATUS_NO_SUCH_FILE; goto out; } + DEBUG(11,("convert_file_from_ucs2: " + "data_in[0]: 0x%x, data_in[1]: 0x%x, data_in[2]: 0x%x\n", + data_in[0], data_in[1], data_in[2])); + + if ((data_in[0] != 0xff) || (data_in[1] != 0xfe) || (data_in[2] != 0x0d)) { + *filename_out = NULL; + status = NT_STATUS_OK; + goto out; + } + tmp_name = talloc_asprintf(mem_ctx, "%s/convert_file_from_ucs2.XXXXXX", tmpdir()); if (!tmp_name) { @@ -115,20 +125,12 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx, goto out; } - /* skip utf8 BOM */ DEBUG(11,("convert_file_from_ucs2: " - "data_out[0]: 0x%x, data_out[1]: 0x%x, data_out[2]: 0x%x\n", - data_out[0], data_out[1], data_out[2])); + "%s skipping utf16-le BOM\n", tmp_name)); - if ((data_out[0] == 0xef) && (data_out[1] == 0xbb) && - (data_out[2] == 0xbf)) { - DEBUG(11,("convert_file_from_ucs2: " - "%s skipping utf8 BOM\n", tmp_name)); - data_out += 3; - converted_size -= 3; - } + converted_size -= 3; - if (write(tmp_fd, data_out, converted_size) != converted_size) { + if (write(tmp_fd, data_out + 3, converted_size) != converted_size) { status = map_nt_error_from_unix_common(errno); goto out; } @@ -143,6 +145,7 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx, } talloc_free(data_in); + talloc_free(data_out); return status; } @@ -323,7 +326,8 @@ NTSTATUS gp_inifile_init_context(TALLOC_CTX *mem_ctx, goto failed; } - rv = pm_process(tmp_filename, change_section, store_keyval_pair, ctx); + rv = pm_process(tmp_filename != NULL ? tmp_filename : ini_filename, + change_section, store_keyval_pair, ctx); if (!rv) { return NT_STATUS_NO_SUCH_FILE; } @@ -373,7 +377,7 @@ NTSTATUS gp_inifile_init_context_direct(TALLOC_CTX *mem_ctx, goto failed; } - rv = pm_process(tmp_filename, + rv = pm_process(tmp_filename != NULL ? tmp_filename : unix_path, change_section, store_keyval_pair, gp_ctx); |