From 6090601c8b6abde1642906351d1dd9bb41e576b6 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 14 Jun 2007 11:29:35 +0000 Subject: r23485: This checkin consists mostly of refactorings in preparation of the activation of global registry options in loadparm.c, mainly to extract functionality from net_conf.c to be made availabel elsewhere and to minimize linker dependencies. In detail: * move functions registry_push/pull_value from lib/util_reg.c to new file lib/util_reg_api.c * create a fake user token consisting of builtin administrators sid and se_disk_operators privilege by hand instead of using get_root_nt_token() to minimize linker deps for bin/net. + new function registry_create_admin_token() in new lib/util_reg_smbconf.c + move dup_nt_token from auth/token_util.c to new file lib/util_nttoken.c + adapt net_conf.c and Makefile.in accordingly. * split lib/profiles.c into two parts: new file lib/profiles_basic.c takes all the low level mask manipulation and format conversion functions (se_priv, privset, luid). the privs array is completely hidden from profiles.c by adding some access-functions. some mask-functions are not static anymore. Generally, SID- and LUID-related stuff that has more dependencies is kept in lib/profiles.c * Move initialization of regdb from net_conf.c into a function registry_init_regdb() in lib/util_reg_smbconf.c. Michael (This used to be commit efd3e2bfb756ac5c4df7984791c67e7ae20a582e) --- source3/lib/util_reg_api.c | 136 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 source3/lib/util_reg_api.c (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c new file mode 100644 index 0000000000..aad53e8e7c --- /dev/null +++ b/source3/lib/util_reg_api.c @@ -0,0 +1,136 @@ +/* + * Unix SMB/CIFS implementation. + * Registry helper routines + * Copyright (C) Volker Lendecke 2006 + * + * 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., 675 + * Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +WERROR registry_pull_value(TALLOC_CTX *mem_ctx, + struct registry_value **pvalue, + enum winreg_Type type, uint8 *data, + uint32 size, uint32 length) +{ + struct registry_value *value; + WERROR err; + + if (!(value = TALLOC_ZERO_P(mem_ctx, struct registry_value))) { + return WERR_NOMEM; + } + + value->type = type; + + switch (type) { + case REG_DWORD: + if ((size != 4) || (length != 4)) { + err = WERR_INVALID_PARAM; + goto error; + } + value->v.dword = IVAL(data, 0); + break; + case REG_SZ: + case REG_EXPAND_SZ: + { + /* + * Make sure we get a NULL terminated string for + * convert_string_talloc(). + */ + + smb_ucs2_t *tmp; + uint32 num_ucs2 = length / 2; + + if ((length % 2) != 0) { + err = WERR_INVALID_PARAM; + goto error; + } + + if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, num_ucs2+1))) { + err = WERR_NOMEM; + goto error; + } + + memcpy((void *)tmp, (const void *)data, length); + tmp[num_ucs2] = 0; + + value->v.sz.len = convert_string_talloc( + value, CH_UTF16LE, CH_UNIX, tmp, length+2, + &value->v.sz.str, False); + + SAFE_FREE(tmp); + + if (value->v.sz.len == (size_t)-1) { + err = WERR_INVALID_PARAM; + goto error; + } + break; + } + case REG_MULTI_SZ: + err = reg_pull_multi_sz(value, (void *)data, length, + &value->v.multi_sz.num_strings, + &value->v.multi_sz.strings); + if (!(W_ERROR_IS_OK(err))) { + goto error; + } + break; + case REG_BINARY: + value->v.binary.data = talloc_move(value, &data); + value->v.binary.length = length; + break; + default: + err = WERR_INVALID_PARAM; + goto error; + } + + *pvalue = value; + return WERR_OK; + + error: + TALLOC_FREE(value); + return err; +} + +WERROR registry_push_value(TALLOC_CTX *mem_ctx, + const struct registry_value *value, + DATA_BLOB *presult) +{ + switch (value->type) { + case REG_DWORD: { + char buf[4]; + SIVAL(buf, 0, value->v.dword); + *presult = data_blob_talloc(mem_ctx, (void *)buf, 4); + if (presult->data == NULL) { + return WERR_NOMEM; + } + break; + } + case REG_SZ: + case REG_EXPAND_SZ: { + presult->length = convert_string_talloc( + mem_ctx, CH_UNIX, CH_UTF16LE, value->v.sz.str, + MIN(value->v.sz.len, strlen(value->v.sz.str)+1), + (void *)&(presult->data), False); + if (presult->length == (size_t)-1) { + return WERR_NOMEM; + } + break; + } + default: + return WERR_INVALID_PARAM; + } + + return WERR_OK; +} -- cgit From 7a3f98e5080ee2fadfe236e2ab6d34ddb05981fa Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 30 Jun 2007 23:52:23 +0000 Subject: r23668: When creating a new string value, win2k regedit delivers one byte of data despite characters being two-byte. This modifies registry_pull_value, to change the data to the correct two-byte version of the empty string, (as delivered by winxp), when only one byte of data is received. Michael (This used to be commit a4c2b20296d6853cd1578601f17330cde75c4038) --- source3/lib/util_reg_api.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index aad53e8e7c..423fdfd3be 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -53,19 +53,33 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, smb_ucs2_t *tmp; uint32 num_ucs2 = length / 2; - if ((length % 2) != 0) { + if (length == 1) { + /* win2k regedit gives us a string of 1 byte when + * creating a new value of type REG_SZ. this workaround + * replaces the input by using the same string as + * winxp delivers. */ + length = 2; + if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, 2))) { + err = WERR_NOMEM; + goto error; + } + tmp[0] = 2; + tmp[1] = 0; + } + else if ((length % 2) != 0) { err = WERR_INVALID_PARAM; goto error; } - - if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, num_ucs2+1))) { - err = WERR_NOMEM; - goto error; + else { + if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, num_ucs2+1))) { + err = WERR_NOMEM; + goto error; + } + + memcpy((void *)tmp, (const void *)data, length); + tmp[num_ucs2] = 0; } - memcpy((void *)tmp, (const void *)data, length); - tmp[num_ucs2] = 0; - value->v.sz.len = convert_string_talloc( value, CH_UTF16LE, CH_UNIX, tmp, length+2, &value->v.sz.str, False); -- cgit From b3b83941d8d5947944ba0c6423fabdc4532e0f5f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 1 Jul 2007 00:09:20 +0000 Subject: r23669: Move a variable into the only block where it is used. (This used to be commit 82be4137b7bba6a9a433ec011e7f47587935ae61) --- source3/lib/util_reg_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index 423fdfd3be..8668bd8817 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -51,7 +51,6 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, */ smb_ucs2_t *tmp; - uint32 num_ucs2 = length / 2; if (length == 1) { /* win2k regedit gives us a string of 1 byte when @@ -71,6 +70,7 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, goto error; } else { + uint32 num_ucs2 = length / 2; if (!(tmp = SMB_MALLOC_ARRAY(smb_ucs2_t, num_ucs2+1))) { err = WERR_NOMEM; goto error; -- cgit From 56f6f58df2bae009e10352a0435ba4d70c5cacb7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 2 Jul 2007 20:51:09 +0000 Subject: r23673: Check for integer wrap on incoming data. Jeremy. (This used to be commit 77a46c7aee2ad4c402527cf78e5ae70a792d65d4) --- source3/lib/util_reg_api.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index 8668bd8817..a4fb0261e3 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -80,6 +80,12 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, tmp[num_ucs2] = 0; } + if (length + 2 < length) { + /* Integer wrap. */ + err = WERR_INVALID_PARAM; + goto error; + } + value->v.sz.len = convert_string_talloc( value, CH_UTF16LE, CH_UNIX, tmp, length+2, &value->v.sz.str, False); -- cgit From 1a7eb52aeeee94e2e91fae69a003ce1b23e4eecd Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 9 Jul 2007 07:55:09 +0000 Subject: r23756: Fix Coverity id 388 (This used to be commit 91af086823265ed66bbd0bdc1cced070b7dd0629) --- source3/lib/util_reg_api.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index a4fb0261e3..43ad347d4b 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -82,6 +82,7 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, if (length + 2 < length) { /* Integer wrap. */ + SAFE_FREE(tmp); err = WERR_INVALID_PARAM; goto error; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/util_reg_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index 43ad347d4b..3c3a8c3dcd 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -5,7 +5,7 @@ * * 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) + * 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 -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/lib/util_reg_api.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index 3c3a8c3dcd..0a6fdffd96 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -14,8 +14,7 @@ * 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., 675 - * Mass Ave, Cambridge, MA 02139, USA. + * this program; if not, see . */ #include "includes.h" -- cgit From e14d97bd101e03280c8fc97cf38dfc9b10b94677 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 24 Jul 2007 09:42:15 +0000 Subject: r24023: Correctly support REG_BINARY in registry_push_value() and registry_pull_value(). Guenther (This used to be commit 6a3c44fd99c91beddd9d6a04a30c35d429d0b9a5) --- source3/lib/util_reg_api.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index 0a6fdffd96..dcf45f3c61 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -107,8 +107,7 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, } break; case REG_BINARY: - value->v.binary.data = talloc_move(value, &data); - value->v.binary.length = length; + value->v.binary = data_blob_talloc(mem_ctx, data, length); break; default: err = WERR_INVALID_PARAM; @@ -148,6 +147,11 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx, } break; } + case REG_BINARY: + *presult = data_blob_talloc(mem_ctx, + value->v.binary.data, + value->v.binary.length); + break; default: return WERR_INVALID_PARAM; } -- cgit From 1523103164675b2ffe938f9d8014574c9381f4b2 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 21 Aug 2007 21:55:51 +0000 Subject: r24609: Fix the fix of r23668 for win2k giving one zero byte instead of a 2-byte zero character. I can't recall what rode me when I put that "2" there. But now I think I have got it right... :-) Michael (This used to be commit fa010bef11b78ac3bbf0091870ce8cd5a53334af) --- source3/lib/util_reg_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index dcf45f3c61..ee9f22884b 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -61,7 +61,7 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, err = WERR_NOMEM; goto error; } - tmp[0] = 2; + tmp[0] = 0; tmp[1] = 0; } else if ((length % 2) != 0) { -- cgit From f71a4fa3af115e28ef707d3d2ba63008c39ca6dc Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 21 Aug 2007 21:57:58 +0000 Subject: r24610: Add a debug message that the workaround has been activated... (This used to be commit a12f3bf6e93f7a902a1f6274d67f15cc4eeb20bd) --- source3/lib/util_reg_api.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index ee9f22884b..243499cb99 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -63,6 +63,8 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, } tmp[0] = 0; tmp[1] = 0; + DEBUG(10, ("got REG_SZ value of length 1 - workaround " + "activated.\n")); } else if ((length % 2) != 0) { err = WERR_INVALID_PARAM; -- cgit From 6334c7cc5f686a6c13063190986914482f54784f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 28 Sep 2007 23:05:52 +0000 Subject: r25417: Use DBGC_REGISTRY class. Guenther (This used to be commit 43ca04918a5a1b2379083dc624b346ceb8476a38) --- source3/lib/util_reg_api.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index 243499cb99..fccc38ebc0 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -19,6 +19,9 @@ #include "includes.h" +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_REGISTRY + WERROR registry_pull_value(TALLOC_CTX *mem_ctx, struct registry_value **pvalue, enum winreg_Type type, uint8 *data, -- cgit From 2ca280d551e5e99ccfd8d68449b0b6e1117c2be1 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 8 Apr 2008 17:44:40 +0200 Subject: registry: add support for REG_MULTI_SZ to registry_push_value(). This enables us to fetch multi_sz values from registry... Michael (This used to be commit a8cedfef27a0400c6aa05ddb5e51308ce0b789bd) --- source3/lib/util_reg_api.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index fccc38ebc0..60031d97d3 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -152,6 +152,62 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx, } break; } + case REG_MULTI_SZ: { + uint32_t count; + size_t len = 0; + char **strings; + size_t *string_lengths; + uint32_t ofs; + TALLOC_CTX *tmp_ctx = talloc_stackframe(); + + strings = TALLOC_ARRAY(tmp_ctx, char *, + value->v.multi_sz.num_strings); + if (strings == NULL) { + return WERR_NOMEM; + } + + string_lengths = TALLOC_ARRAY(tmp_ctx, size_t, + value->v.multi_sz.num_strings); + if (string_lengths == NULL) { + TALLOC_FREE(tmp_ctx); + return WERR_NOMEM; + } + + /* convert the single strings */ + for (count = 0; count < value->v.multi_sz.num_strings; count++) + { + string_lengths[count] = convert_string_talloc( + strings, CH_UNIX, CH_UTF16LE, + value->v.multi_sz.strings[count], + strlen(value->v.multi_sz.strings[count])+1, + (void *)&strings[count], false); + if (string_lengths[count] == (size_t)-1) { + TALLOC_FREE(tmp_ctx); + return WERR_NOMEM; + } + len += string_lengths[count]; + } + + /* now concatenate all into the data blob */ + presult->data = TALLOC_ARRAY(mem_ctx, uint8_t, len); + if (presult->data == NULL) { + TALLOC_FREE(tmp_ctx); + return WERR_NOMEM; + } + for (count = 0, ofs = 0; + count < value->v.multi_sz.num_strings; + count++) + { + memcpy(presult->data + ofs, strings[count], + string_lengths[count]); + ofs += string_lengths[count]; + } + presult->length = len; + + TALLOC_FREE(tmp_ctx); + + break; + } case REG_BINARY: *presult = data_blob_talloc(mem_ctx, value->v.binary.data, -- cgit From fb37f156009611af0dd454a0fb0829a09cd638ac Mon Sep 17 00:00:00 2001 From: Tim Prouty Date: Tue, 29 Apr 2008 14:36:24 -0700 Subject: Cleanup size_t return values in callers of convert_string_allocate This patch is the second iteration of an inside-out conversion to cleanup functions in charcnv.c returning size_t == -1 to indicate failure. (This used to be commit 6b189dabc562d86dcaa685419d0cb6ea276f100d) --- source3/lib/util_reg_api.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'source3/lib/util_reg_api.c') diff --git a/source3/lib/util_reg_api.c b/source3/lib/util_reg_api.c index 60031d97d3..8f28e9c282 100644 --- a/source3/lib/util_reg_api.c +++ b/source3/lib/util_reg_api.c @@ -91,16 +91,15 @@ WERROR registry_pull_value(TALLOC_CTX *mem_ctx, goto error; } - value->v.sz.len = convert_string_talloc( - value, CH_UTF16LE, CH_UNIX, tmp, length+2, - &value->v.sz.str, False); - - SAFE_FREE(tmp); - - if (value->v.sz.len == (size_t)-1) { + if (!convert_string_talloc(value, CH_UTF16LE, CH_UNIX, tmp, + length+2, &value->v.sz.str, + &value->v.sz.len, False)) { + SAFE_FREE(tmp); err = WERR_INVALID_PARAM; goto error; } + + SAFE_FREE(tmp); break; } case REG_MULTI_SZ: @@ -143,11 +142,13 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx, } case REG_SZ: case REG_EXPAND_SZ: { - presult->length = convert_string_talloc( - mem_ctx, CH_UNIX, CH_UTF16LE, value->v.sz.str, - MIN(value->v.sz.len, strlen(value->v.sz.str)+1), - (void *)&(presult->data), False); - if (presult->length == (size_t)-1) { + if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16LE, + value->v.sz.str, + MIN(value->v.sz.len, + strlen(value->v.sz.str)+1), + (void *)&(presult->data), + &presult->length, False)) + { return WERR_NOMEM; } break; @@ -176,12 +177,13 @@ WERROR registry_push_value(TALLOC_CTX *mem_ctx, /* convert the single strings */ for (count = 0; count < value->v.multi_sz.num_strings; count++) { - string_lengths[count] = convert_string_talloc( - strings, CH_UNIX, CH_UTF16LE, - value->v.multi_sz.strings[count], + if (!convert_string_talloc(strings, CH_UNIX, + CH_UTF16LE, value->v.multi_sz.strings[count], strlen(value->v.multi_sz.strings[count])+1, - (void *)&strings[count], false); - if (string_lengths[count] == (size_t)-1) { + (void *)&strings[count], + &string_lengths[count], false)) + { + TALLOC_FREE(tmp_ctx); return WERR_NOMEM; } -- cgit