From 7dac0598ec6edb63f15a7cce7c231f56f9ab7f7d Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Sat, 16 Feb 2008 15:08:28 -0600 Subject: registry: Implement recursive deletes for ldb-backed registry. When deleting a registry key that contains subkeys or values, Windows performs a recursive deletion that removes any subkeys or values. This update makes deletes for an ldb-backed registry consistent with Windows. Under ldb, the deletion is done using an explicit transaction. If an error occurs during the deletion the entire transaction is cancelled, leaving the registry as it was before the deletions started. (This used to be commit ca796c8fb10598674a5eef31d15863e79bcf3db8) --- source4/lib/registry/ldb.c | 143 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 116 insertions(+), 27 deletions(-) (limited to 'source4') diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index 0c8a55396e..31b78d8246 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -440,33 +440,6 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent, return WERR_OK; } -static WERROR ldb_del_key(const struct hive_key *key, const char *name) -{ - int ret; - struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data); - struct ldb_dn *ldap_path; - TALLOC_CTX *mem_ctx = talloc_init("ldb_del_key"); - - ldap_path = reg_path_to_ldb(mem_ctx, key, name, NULL); - - ret = ldb_delete(parentkd->ldb, ldap_path); - - talloc_free(mem_ctx); - - if (ret == LDB_ERR_NO_SUCH_OBJECT) { - return WERR_BADFILE; - } else if (ret != LDB_SUCCESS) { - DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(parentkd->ldb))); - return WERR_FOOBAR; - } - - /* reset cache */ - talloc_free(parentkd->subkeys); - parentkd->subkeys = NULL; - - return WERR_OK; -} - static WERROR ldb_del_value (struct hive_key *key, const char *child) { int ret; @@ -499,6 +472,122 @@ static WERROR ldb_del_value (struct hive_key *key, const char *child) return WERR_OK; } +static WERROR ldb_del_key(const struct hive_key *key, const char *name) +{ + int i, ret; + struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data); + struct ldb_dn *ldap_path; + TALLOC_CTX *mem_ctx = talloc_init("ldb_del_key"); + struct ldb_context *c = parentkd->ldb; + struct ldb_result *res_keys; + struct ldb_result *res_vals; + WERROR werr; + struct hive_key *hk; + + /* Verify key exists by opening it */ + werr = ldb_open_key(mem_ctx, key, name, &hk); + if (!W_ERROR_IS_OK(werr)) { + talloc_free(mem_ctx); + return werr; + } + + ldap_path = reg_path_to_ldb(mem_ctx, key, name, NULL); + if (!ldap_path) { + talloc_free(mem_ctx); + return WERR_FOOBAR; + } + + /* Search for subkeys */ + ret = ldb_search(c, ldap_path, LDB_SCOPE_ONELEVEL, + "(key=*)", NULL, &res_keys); + + if (ret != LDB_SUCCESS) { + DEBUG(0, ("Error getting subkeys for '%s': %s\n", + ldb_dn_get_linearized(ldap_path), ldb_errstring(c))); + talloc_free(mem_ctx); + return WERR_FOOBAR; + } + + /* Search for values */ + ret = ldb_search(c, ldap_path, LDB_SCOPE_ONELEVEL, + "(value=*)", NULL, &res_vals); + + if (ret != LDB_SUCCESS) { + DEBUG(0, ("Error getting values for '%s': %s\n", + ldb_dn_get_linearized(ldap_path), ldb_errstring(c))); + talloc_free(mem_ctx); + return WERR_FOOBAR; + } + + /* Start an explicit transaction */ + ret = ldb_transaction_start(c); + + if (ret != LDB_SUCCESS) { + DEBUG(0, ("ldb_transaction_start: %s\n", ldb_errstring(c))); + talloc_free(mem_ctx); + return WERR_FOOBAR; + } + + if (res_keys->count || res_vals->count) + { + /* Delete any subkeys */ + for (i = 0; i < res_keys->count; i++) + { + werr = ldb_del_key(hk, ldb_msg_find_attr_as_string( + res_keys->msgs[i], + "key", NULL)); + if (!W_ERROR_IS_OK(werr)) { + ret = ldb_transaction_cancel(c); + talloc_free(mem_ctx); + return werr; + } + } + + /* Delete any values */ + for (i = 0; i < res_vals->count; i++) + { + werr = ldb_del_value(hk, ldb_msg_find_attr_as_string( + res_vals->msgs[i], + "value", NULL)); + if (!W_ERROR_IS_OK(werr)) { + ret = ldb_transaction_cancel(c); + talloc_free(mem_ctx); + return werr; + } + } + } + + /* Delete the key itself */ + ret = ldb_delete(c, ldap_path); + + if (ret != LDB_SUCCESS) + { + DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(c))); + ret = ldb_transaction_cancel(c); + talloc_free(mem_ctx); + return WERR_FOOBAR; + } + + /* Commit the transaction */ + ret = ldb_transaction_commit(c); + + if (ret != LDB_SUCCESS) + { + DEBUG(0, ("ldb_transaction_commit: %s\n", ldb_errstring(c))); + ret = ldb_transaction_cancel(c); + talloc_free(mem_ctx); + return WERR_FOOBAR; + } + + talloc_free(mem_ctx); + + /* reset cache */ + talloc_free(parentkd->subkeys); + parentkd->subkeys = NULL; + + return WERR_OK; +} + static WERROR ldb_set_value(struct hive_key *parent, const char *name, uint32_t type, const DATA_BLOB data) -- cgit From 2bbd319cafe64935682799240b9c0aa9ff4d7e7a Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Sat, 16 Feb 2008 15:15:50 -0600 Subject: registry: Implement recursive deletes for dir-backed registry. When deleting a registry key that contains subkeys or values, Windows performs a recursive deletion that removes any subkeys or values. This update makes deletes for an dir-backed registry consistent with Windows. The dir-backed registry relies on the underlying filesystem, which does not generally have transactional integrity when performing multiple operations. Therefore, if an error occurs during the recursive deletion, the dir-backed registry may be left in an inconsistent state. (This used to be commit 6b5fbf7e4e38342bcd80e63f46cd295f89ab1ee9) --- source4/lib/registry/dir.c | 60 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-) (limited to 'source4') diff --git a/source4/lib/registry/dir.c b/source4/lib/registry/dir.c index 27cae8c490..dc3717e886 100644 --- a/source4/lib/registry/dir.c +++ b/source4/lib/registry/dir.c @@ -55,18 +55,66 @@ static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx, return WERR_GENERAL_FAILURE; } +static WERROR reg_dir_delete_recursive(const char *name) +{ + DIR *d; + struct dirent *e; + WERROR werr; + + d = opendir(name); + if (d == NULL) { + DEBUG(3,("Unable to open '%s': %s\n", name, + strerror(errno))); + return WERR_BADFILE; + } + + while((e = readdir(d))) { + char *path; + struct stat stbuf; + + if (ISDOT(e->d_name) || ISDOTDOT(e->d_name)) + continue; + + path = talloc_asprintf(name, "%s/%s", name, e->d_name); + if (!path) + return WERR_NOMEM; + + stat(path, &stbuf); + + if (!S_ISDIR(stbuf.st_mode)) { + if (unlink(path) < 0) { + talloc_free(path); + closedir(d); + return WERR_GENERAL_FAILURE; + } + } else { + werr = reg_dir_delete_recursive(path); + if (!W_ERROR_IS_OK(werr)) { + talloc_free(path); + closedir(d); + return werr; + } + } + + talloc_free(path); + } + closedir(d); + + if (rmdir(name) == 0) + return WERR_OK; + else if (errno == ENOENT) + return WERR_BADFILE; + else + return WERR_GENERAL_FAILURE; +} + static WERROR reg_dir_del_key(const struct hive_key *k, const char *name) { struct dir_key *dk = talloc_get_type(k, struct dir_key); char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name); WERROR ret; - if (rmdir(child) == 0) - ret = WERR_OK; - else if (errno == ENOENT) - ret = WERR_BADFILE; - else - ret = WERR_GENERAL_FAILURE; + ret = reg_dir_delete_recursive(child); talloc_free(child); -- cgit From 79eea32976d2991319c9d0ad32a150f34b029f99 Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Sat, 16 Feb 2008 15:19:00 -0600 Subject: registry: Implement recursive deletes for regf-backed registry. When deleting a registry key that contains subkeys or values, Windows performs a recursive deletion that removes any subkeys or values. This update makes deletes for an regf-backed registry consistent with Windows. The regf-backed registry does not have transactional integrity when performing multiple operations. Therefore, if an error occurs during the recursive deletion, the regf-backed registry may be left in an inconsistent state. (This used to be commit b0321bad290d1a9399b4aba140a622e3af6d7575) --- source4/lib/registry/regf.c | 53 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'source4') diff --git a/source4/lib/registry/regf.c b/source4/lib/registry/regf.c index 15b60745f0..6a35799a7e 100644 --- a/source4/lib/registry/regf.c +++ b/source4/lib/registry/regf.c @@ -1618,10 +1618,55 @@ static WERROR regf_del_key(const struct hive_key *parent, const char *name) return WERR_BADFILE; } - if (key->nk->subkeys_offset != -1 || - key->nk->values_offset != -1) { - DEBUG(0, ("Key '%s' is not empty.\n", name)); - return WERR_FILE_EXISTS; + if (key->nk->subkeys_offset != -1) { + char *sk_name; + struct hive_key *sk = (struct hive_key *)key; + int i = key->nk->num_subkeys; + while (i--) { + /* Get subkey information. */ + error = regf_get_subkey_by_index(parent_nk, sk, 0, + (const char **)&sk_name, + NULL, NULL); + if (!W_ERROR_IS_OK(error)) { + DEBUG(0, ("Can't retrieve subkey by index.\n")); + return error; + } + + /* Delete subkey. */ + error = regf_del_key(sk, sk_name); + if (!W_ERROR_IS_OK(error)) { + DEBUG(0, ("Can't delete key '%s'.\n", sk_name)); + return error; + } + + talloc_free(sk_name); + } + } + + if (key->nk->values_offset != -1) { + char *val_name; + struct hive_key *sk = (struct hive_key *)key; + DATA_BLOB data; + int i = key->nk->num_values; + while (i--) { + /* Get value information. */ + error = regf_get_value(parent_nk, sk, 0, + (const char **)&val_name, + NULL, &data); + if (!W_ERROR_IS_OK(error)) { + DEBUG(0, ("Can't retrieve value by index.\n")); + return error; + } + + /* Delete value. */ + error = regf_del_value(sk, val_name); + if (!W_ERROR_IS_OK(error)) { + DEBUG(0, ("Can't delete value '%s'.\n", val_name)); + return error; + } + + talloc_free(val_name); + } } /* Delete it from the subkey list. */ -- cgit From a13395c8731db614e543e60d3da67873c3164ea2 Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Sat, 16 Feb 2008 15:21:26 -0600 Subject: registry: Add an explicit test for recursive deletion. (This used to be commit 5e905804993df4c2ac28090d056e6db6bb63ac44) --- source4/lib/registry/tests/hive.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'source4') diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 4d27e83a74..915782694f 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -110,6 +110,38 @@ static bool test_add_subkey(struct torture_context *tctx, return true; } +static bool test_del_recursive(struct torture_context *tctx, + const void *test_data) +{ + WERROR error; + struct hive_key *subkey; + struct hive_key *subkey2; + const struct hive_key *root = (const struct hive_key *)test_data; + TALLOC_CTX *mem_ctx = tctx; + uint32_t data = 42; + + /* Create a new key under the root */ + error = hive_key_add_name(mem_ctx, root, "Parent Key", NULL, + NULL, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + /* Create a new key under "Parent Key" */ + error = hive_key_add_name(mem_ctx, subkey, "Child Key", NULL, + NULL, &subkey2); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + /* Create a new value under "Child Key" */ + error = hive_key_set_value(subkey2, "Answer Recursive", REG_DWORD, + data_blob_talloc(mem_ctx, &data, sizeof(data))); + torture_assert_werr_ok(tctx, error, "hive_key_set_value"); + + /* Deleting "Parent Key" will also delete "Child Key" and the value. */ + error = hive_key_del(root, "Parent Key"); + torture_assert_werr_ok(tctx, error, "hive_key_del"); + + return true; +} + static bool test_flush_key(struct torture_context *tctx, void *test_data) { struct hive_key *root = (struct hive_key *)test_data; @@ -272,6 +304,11 @@ static void tcase_add_tests(struct torture_tcase *tcase) test_add_subkey); torture_tcase_add_simple_test(tcase, "flush_key", test_flush_key); + /* test_del_recursive() test must run before test_keyinfo_root(). + test_keyinfo_root() checks the number of subkeys, which verifies + the recursive delete worked properly. */ + torture_tcase_add_simple_test_const(tcase, "del_recursive", + test_del_recursive); torture_tcase_add_simple_test_const(tcase, "get_info", test_keyinfo_root); torture_tcase_add_simple_test(tcase, "get_info_nums", -- cgit From 497b17ac61995f0dd07de7d9d505de5ad3a46618 Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Tue, 19 Feb 2008 09:03:32 -0600 Subject: torture/rpc-winreg: General fixes for a number of tests. Cleaned up issues with tests being run without the correct state being setup. Also corrected an issue with a test expecting the wrong return value to indicate a successful test run. (This used to be commit d015e595ca82f8fd3941753c00a2f3d816300be9) --- source4/torture/rpc/winreg.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'source4') diff --git a/source4/torture/rpc/winreg.c b/source4/torture/rpc/winreg.c index 4695733671..96b1fb2174 100644 --- a/source4/torture/rpc/winreg.c +++ b/source4/torture/rpc/winreg.c @@ -1730,6 +1730,11 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, test_Cleanup(p, tctx, &handle, TEST_KEY3); test_Cleanup(p, tctx, &handle, TEST_KEY_BASE); + if (!test_CreateKey(p, tctx, &handle, TEST_KEY_BASE, NULL)) { + torture_comment(tctx, + "CreateKey (TEST_KEY_BASE) failed\n"); + } + if (!test_CreateKey(p, tctx, &handle, TEST_KEY1, NULL)) { torture_comment(tctx, "CreateKey failed - not considering a failure\n"); @@ -1763,9 +1768,12 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, } if (created && deleted && - test_OpenKey(p, tctx, &handle, TEST_KEY1, &newhandle)) { + !_test_OpenKey(p, tctx, &handle, TEST_KEY1, + SEC_FLAG_MAXIMUM_ALLOWED, &newhandle, + WERR_BADFILE, NULL)) { torture_comment(tctx, - "DeleteKey failed (OpenKey after Delete worked)\n"); + "DeleteKey failed (OpenKey after Delete " + "did not return WERR_BADFILE)\n"); ret = false; } @@ -1788,7 +1796,7 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, created4 = true; } - if (!created4 && !test_CloseKey(p, tctx, &newhandle)) { + if (created4 && !test_CloseKey(p, tctx, &newhandle)) { printf("CloseKey failed\n"); ret = false; } @@ -1803,7 +1811,7 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, } - if (created && !test_DeleteKey(p, tctx, &handle, TEST_KEY2)) { + if (created2 && !test_DeleteKey(p, tctx, &handle, TEST_KEY2)) { printf("DeleteKey failed\n"); ret = false; } @@ -1841,10 +1849,10 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, if(!test_key(p, tctx, &handle, MAX_DEPTH - 1)) { ret = false; } - } - - if (!test_key(p, tctx, &handle, 0)) { - ret = false; + } else { + if (!test_key(p, tctx, &handle, 0)) { + ret = false; + } } test_Cleanup(p, tctx, &handle, TEST_KEY_BASE); -- cgit From 1aa3d0649f45c6c13e007ad3e4655cb3c99170e8 Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Tue, 19 Feb 2008 09:13:14 -0600 Subject: torture/rpc-winreg: Modify test cases to work with recursive key deletion. (This used to be commit 3885acdee6fa3ec33cf4824826c2b8a98721382c) --- source4/torture/rpc/winreg.c | 43 ------------------------------------------- 1 file changed, 43 deletions(-) (limited to 'source4') diff --git a/source4/torture/rpc/winreg.c b/source4/torture/rpc/winreg.c index 96b1fb2174..31b9c2bb56 100644 --- a/source4/torture/rpc/winreg.c +++ b/source4/torture/rpc/winreg.c @@ -848,7 +848,6 @@ static bool test_SecurityDescriptorInheritance(struct dcerpc_pipe *p, out: test_CloseKey(p, tctx, &new_handle); - test_Cleanup(p, tctx, handle, TEST_SUBSUBKEY_SD); test_Cleanup(p, tctx, handle, TEST_SUBKEY_SD); test_RestoreSecurity(p, tctx, handle, key, sd_orig); @@ -971,7 +970,6 @@ static bool test_SecurityDescriptorBlockInheritance(struct dcerpc_pipe *p, out: test_CloseKey(p, tctx, &new_handle); - test_Cleanup(p, tctx, handle, TEST_SUBSUBKEY_SD); test_Cleanup(p, tctx, handle, TEST_SUBKEY_SD); test_RestoreSecurity(p, tctx, handle, key, sd_orig); @@ -1386,27 +1384,6 @@ static bool test_DeleteKey(struct dcerpc_pipe *p, struct torture_context *tctx, return true; } -/* DeleteKey on a key with subkey(s) should - * return WERR_ACCESS_DENIED. */ -static bool test_DeleteKeyWithSubkey(struct dcerpc_pipe *p, - struct torture_context *tctx, - struct policy_handle *handle, - const char *key) -{ - struct winreg_DeleteKey r; - - r.in.handle = handle; - init_winreg_String(&r.in.key, key); - - torture_assert_ntstatus_ok(tctx, dcerpc_winreg_DeleteKey(p, tctx, &r), - "DeleteKeyWithSubkey failed"); - - torture_assert_werr_equal(tctx, r.out.result, WERR_ACCESS_DENIED, - "DeleteKeyWithSubkey failed"); - - return true; -} - static bool test_QueryInfoKey(struct dcerpc_pipe *p, struct torture_context *tctx, struct policy_handle *handle, char *class) @@ -1721,13 +1698,6 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, torture_assert_ntstatus_ok(tctx, open_fn(p, tctx, &r), "open"); - test_Cleanup(p, tctx, &handle, TEST_KEY1); - test_Cleanup(p, tctx, &handle, TEST_SUBSUBKEY_SD); - test_Cleanup(p, tctx, &handle, TEST_SUBKEY_SD); - test_Cleanup(p, tctx, &handle, TEST_KEY4); - test_Cleanup(p, tctx, &handle, TEST_KEY2); - test_Cleanup(p, tctx, &handle, TEST_SUBKEY); - test_Cleanup(p, tctx, &handle, TEST_KEY3); test_Cleanup(p, tctx, &handle, TEST_KEY_BASE); if (!test_CreateKey(p, tctx, &handle, TEST_KEY_BASE, NULL)) { @@ -1826,19 +1796,6 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, } if (created_subkey && - !test_DeleteKeyWithSubkey(p, tctx, &handle, TEST_KEY3)) { - printf("DeleteKeyWithSubkey failed " - "(DeleteKey didn't return ACCESS_DENIED)\n"); - ret = false; - } - - if (created_subkey && - !test_DeleteKey(p, tctx, &handle, TEST_SUBKEY)) { - printf("DeleteKey failed\n"); - ret = false; - } - - if (created3 && !test_DeleteKey(p, tctx, &handle, TEST_KEY3)) { printf("DeleteKey failed\n"); ret = false; -- cgit From 846c81bccb67427d54e2b84cad08b4b32128e4ab Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Tue, 19 Feb 2008 09:18:10 -0600 Subject: torture/rpc-winreg: Split out the security descriptor tests. The security descriptor functionality has not been implemented yet. Now that the other tests run successfully, the security descriptor tests have been split out so they can be separately marked as knownfail. The tests that test security descriptor functionality are named "*-security", while those that don't are named "*-basic". (This used to be commit 7b7aec9a2f0a684bb27761df71af506cce244b2c) --- source4/torture/rpc/winreg.c | 169 +++++++++++++++++++++++++++++-------------- 1 file changed, 113 insertions(+), 56 deletions(-) (limited to 'source4') diff --git a/source4/torture/rpc/winreg.c b/source4/torture/rpc/winreg.c index 31b9c2bb56..8b602ef652 100644 --- a/source4/torture/rpc/winreg.c +++ b/source4/torture/rpc/winreg.c @@ -1420,10 +1420,12 @@ static bool test_QueryInfoKey(struct dcerpc_pipe *p, } static bool test_key(struct dcerpc_pipe *p, struct torture_context *tctx, - struct policy_handle *handle, int depth); + struct policy_handle *handle, int depth, + bool test_security); static bool test_EnumKey(struct dcerpc_pipe *p, struct torture_context *tctx, - struct policy_handle *handle, int depth) + struct policy_handle *handle, int depth, + bool test_security) { struct winreg_EnumKey r; struct winreg_StringBuf class, name; @@ -1456,7 +1458,8 @@ static bool test_EnumKey(struct dcerpc_pipe *p, struct torture_context *tctx, if (!test_OpenKey(p, tctx, handle, r.out.name->name, &key_handle)) { } else { - test_key(p, tctx, &key_handle, depth + 1); + test_key(p, tctx, &key_handle, + depth + 1, test_security); } } @@ -1653,7 +1656,8 @@ static bool test_InitiateSystemShutdownEx(struct torture_context *tctx, #define MAX_DEPTH 2 /* Only go this far down the tree */ static bool test_key(struct dcerpc_pipe *p, struct torture_context *tctx, - struct policy_handle *handle, int depth) + struct policy_handle *handle, int depth, + bool test_security) { if (depth == MAX_DEPTH) return true; @@ -1664,10 +1668,10 @@ static bool test_key(struct dcerpc_pipe *p, struct torture_context *tctx, if (!test_NotifyChangeKeyValue(p, tctx, handle)) { } - if (!test_GetKeySecurity(p, tctx, handle, NULL)) { + if (test_security && !test_GetKeySecurity(p, tctx, handle, NULL)) { } - if (!test_EnumKey(p, tctx, handle, depth)) { + if (!test_EnumKey(p, tctx, handle, depth, test_security)) { } if (!test_EnumValue(p, tctx, handle, 0xFF, 0xFFFF)) { @@ -1680,13 +1684,85 @@ static bool test_key(struct dcerpc_pipe *p, struct torture_context *tctx, typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *); +static bool test_Open_Security(struct torture_context *tctx, + struct dcerpc_pipe *p, void *userdata) +{ + struct policy_handle handle, newhandle; + bool ret = true, created2 = false; + bool created4 = false; + struct winreg_OpenHKLM r; + + winreg_open_fn open_fn = userdata; + + r.in.system_name = 0; + r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + r.out.handle = &handle; + + torture_assert_ntstatus_ok(tctx, open_fn(p, tctx, &r), + "open"); + + test_Cleanup(p, tctx, &handle, TEST_KEY_BASE); + + if (!test_CreateKey(p, tctx, &handle, TEST_KEY_BASE, NULL)) { + torture_comment(tctx, + "CreateKey (TEST_KEY_BASE) failed\n"); + } + + if (test_CreateKey_sd(p, tctx, &handle, TEST_KEY2, + NULL, &newhandle)) { + created2 = true; + } + + if (created2 && !test_CloseKey(p, tctx, &newhandle)) { + printf("CloseKey failed\n"); + ret = false; + } + + if (test_CreateKey_sd(p, tctx, &handle, TEST_KEY4, NULL, &newhandle)) { + created4 = true; + } + + if (created4 && !test_CloseKey(p, tctx, &newhandle)) { + printf("CloseKey failed\n"); + ret = false; + } + + if (created4 && !test_SecurityDescriptors(p, tctx, &handle, TEST_KEY4)) { + ret = false; + } + + if (created4 && !test_DeleteKey(p, tctx, &handle, TEST_KEY4)) { + printf("DeleteKey failed\n"); + ret = false; + } + + if (created2 && !test_DeleteKey(p, tctx, &handle, TEST_KEY2)) { + printf("DeleteKey failed\n"); + ret = false; + } + + /* The HKCR hive has a very large fanout */ + if (open_fn == (void *)dcerpc_winreg_OpenHKCR) { + if(!test_key(p, tctx, &handle, MAX_DEPTH - 1, true)) { + ret = false; + } + } else { + if (!test_key(p, tctx, &handle, 0, true)) { + ret = false; + } + } + + test_Cleanup(p, tctx, &handle, TEST_KEY_BASE); + + return ret; +} + static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, void *userdata) { struct policy_handle handle, newhandle; - bool ret = true, created = false, created2 = false, deleted = false; + bool ret = true, created = false, deleted = false; bool created3 = false, created_subkey = false; - bool created4 = false; struct winreg_OpenHKLM r; winreg_open_fn open_fn = userdata; @@ -1752,40 +1828,6 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, ret = false; } - if (created && test_CreateKey_sd(p, tctx, &handle, TEST_KEY2, - NULL, &newhandle)) { - created2 = true; - } - - if (created2 && !test_CloseKey(p, tctx, &newhandle)) { - printf("CloseKey failed\n"); - ret = false; - } - - if (test_CreateKey_sd(p, tctx, &handle, TEST_KEY4, NULL, &newhandle)) { - created4 = true; - } - - if (created4 && !test_CloseKey(p, tctx, &newhandle)) { - printf("CloseKey failed\n"); - ret = false; - } - - if (created4 && !test_SecurityDescriptors(p, tctx, &handle, TEST_KEY4)) { - ret = false; - } - - if (created4 && !test_DeleteKey(p, tctx, &handle, TEST_KEY4)) { - printf("DeleteKey failed\n"); - ret = false; - } - - - if (created2 && !test_DeleteKey(p, tctx, &handle, TEST_KEY2)) { - printf("DeleteKey failed\n"); - ret = false; - } - if (created && test_CreateKey(p, tctx, &handle, TEST_KEY3, NULL)) { created3 = true; } @@ -1803,11 +1845,11 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, /* The HKCR hive has a very large fanout */ if (open_fn == (void *)dcerpc_winreg_OpenHKCR) { - if(!test_key(p, tctx, &handle, MAX_DEPTH - 1)) { + if(!test_key(p, tctx, &handle, MAX_DEPTH - 1, false)) { ret = false; } } else { - if (!test_key(p, tctx, &handle, 0)) { + if (!test_key(p, tctx, &handle, 0, false)) { ret = false; } } @@ -1819,14 +1861,6 @@ static bool test_Open(struct torture_context *tctx, struct dcerpc_pipe *p, struct torture_suite *torture_rpc_winreg(TALLOC_CTX *mem_ctx) { - struct { - const char *name; - winreg_open_fn fn; - } open_fns[] = {{"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM }, - {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU }, - {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR }, - {"OpenHKCU", (winreg_open_fn)dcerpc_winreg_OpenHKCU }}; - int i; struct torture_rpc_tcase *tcase; struct torture_suite *suite = torture_suite_create(mem_ctx, "WINREG"); struct torture_test *test; @@ -1842,10 +1876,33 @@ struct torture_suite *torture_rpc_winreg(TALLOC_CTX *mem_ctx) test_InitiateSystemShutdownEx); test->dangerous = true; - for (i = 0; i < ARRAY_SIZE(open_fns); i++) { - torture_rpc_tcase_add_test_ex(tcase, open_fns[i].name, - test_Open, open_fns[i].fn); - } + /* Basic tests without security descriptors */ + torture_rpc_tcase_add_test_ex(tcase, "HKLM-basic", + test_Open, + (winreg_open_fn)dcerpc_winreg_OpenHKLM); + torture_rpc_tcase_add_test_ex(tcase, "HKU-basic", + test_Open, + (winreg_open_fn)dcerpc_winreg_OpenHKU); + torture_rpc_tcase_add_test_ex(tcase, "HKCR-basic", + test_Open, + (winreg_open_fn)dcerpc_winreg_OpenHKCR); + torture_rpc_tcase_add_test_ex(tcase, "HKCU-basic", + test_Open, + (winreg_open_fn)dcerpc_winreg_OpenHKCU); + + /* Security descriptor tests */ + torture_rpc_tcase_add_test_ex(tcase, "HKLM-security", + test_Open_Security, + (winreg_open_fn)dcerpc_winreg_OpenHKLM); + torture_rpc_tcase_add_test_ex(tcase, "HKU-security", + test_Open_Security, + (winreg_open_fn)dcerpc_winreg_OpenHKU); + torture_rpc_tcase_add_test_ex(tcase, "HKCR-security", + test_Open_Security, + (winreg_open_fn)dcerpc_winreg_OpenHKCR); + torture_rpc_tcase_add_test_ex(tcase, "HKCU-security", + test_Open_Security, + (winreg_open_fn)dcerpc_winreg_OpenHKCU); return suite; } -- cgit From 375df425c5014dc852995038e8e5668f98af8ba3 Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Tue, 26 Feb 2008 21:23:45 -0600 Subject: samba4-knownfail: Only the "*-security" rpc-winreg tests are expected to fail. (This used to be commit 67facda6368eeda88d312f2836a1fdae4a1f605a) --- source4/samba4-knownfail | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4') diff --git a/source4/samba4-knownfail b/source4/samba4-knownfail index 4d850caae5..e6a4ea1517 100644 --- a/source4/samba4-knownfail +++ b/source4/samba4-knownfail @@ -3,7 +3,7 @@ local.iconv.*.next_codepoint() base.delaywrite.finfo update on close base.delete.*.deltest20a base.delete.*.deltest20b -rpc.winreg +rpc.winreg.*security local.registry.*.security # Not implemented yet rpc.wkssvc rpc.handles.*.lsarpc-shared -- cgit From 48270181bac1a640d085ce5f5a58329d69c7a1ac Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Feb 2008 12:18:29 +0100 Subject: pvfs_open: make pvfs_locking_key() non static metze (This used to be commit 587373b97b95a8e562c3a5a59a62abade4dfed2f) --- source4/ntvfs/posix/pvfs_open.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4') diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 740a0a9d13..adf4c1ac18 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -144,8 +144,8 @@ static NTSTATUS pvfs_open_setup_eas_acl(struct pvfs_state *pvfs, form the lock context used for opendb locking. Note that we must zero here to take account of possible padding on some architectures */ -static NTSTATUS pvfs_locking_key(struct pvfs_filename *name, - TALLOC_CTX *mem_ctx, DATA_BLOB *key) +NTSTATUS pvfs_locking_key(struct pvfs_filename *name, + TALLOC_CTX *mem_ctx, DATA_BLOB *key) { struct { dev_t device; -- cgit From 98dafd5eb1948bbe8a0d78814ab1cd1910477733 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Feb 2008 09:06:49 +0100 Subject: opendb: add odb_get_path() metze (This used to be commit 02071f151a22257d31f8a8b254625e2067e7b94d) --- source4/cluster/ctdb/opendb_ctdb.c | 20 ++++++++++++++++++++ source4/ntvfs/common/opendb.c | 8 ++++++++ source4/ntvfs/common/opendb.h | 1 + source4/ntvfs/common/opendb_tdb.c | 20 ++++++++++++++++++++ 4 files changed, 49 insertions(+) (limited to 'source4') diff --git a/source4/cluster/ctdb/opendb_ctdb.c b/source4/cluster/ctdb/opendb_ctdb.c index 3d67162d6d..e84f2364d4 100644 --- a/source4/cluster/ctdb/opendb_ctdb.c +++ b/source4/cluster/ctdb/opendb_ctdb.c @@ -542,6 +542,25 @@ static NTSTATUS odb_ctdb_rename(struct odb_lock *lck, const char *path) return odb_push_record(lck, &file); } +/* + get the path of an open file +*/ +static NTSTATUS odb_ctdb_get_path(struct odb_lock *lck, const char **path) +{ + struct opendb_file file; + NTSTATUS status; + + *path = NULL; + + status = odb_pull_record(lck, &file); + /* we don't ignore NT_STATUS_OBJECT_NAME_NOT_FOUND here */ + NT_STATUS_NOT_OK_RETURN(status); + + *path = file.path; + + return NT_STATUS_OK; +} + /* update delete on close flag on an open file */ @@ -653,6 +672,7 @@ static const struct opendb_ops opendb_ctdb_ops = { .odb_close_file = odb_ctdb_close_file, .odb_remove_pending = odb_ctdb_remove_pending, .odb_rename = odb_ctdb_rename, + .odb_get_path = odb_ctdb_get_path, .odb_set_delete_on_close = odb_ctdb_set_delete_on_close, .odb_get_delete_on_close = odb_ctdb_get_delete_on_close, .odb_can_open = odb_ctdb_can_open, diff --git a/source4/ntvfs/common/opendb.c b/source4/ntvfs/common/opendb.c index d8cb67686b..6c1a9c070a 100644 --- a/source4/ntvfs/common/opendb.c +++ b/source4/ntvfs/common/opendb.c @@ -142,6 +142,14 @@ _PUBLIC_ NTSTATUS odb_rename(struct odb_lock *lck, const char *path) return ops->odb_rename(lck, path); } +/* + get back the path of an open file +*/ +_PUBLIC_ NTSTATUS odb_get_path(struct odb_lock *lck, const char **path) +{ + return ops->odb_get_path(lck, path); +} + /* update delete on close flag on an open file */ diff --git a/source4/ntvfs/common/opendb.h b/source4/ntvfs/common/opendb.h index 33f2e1c88d..69a7f718ba 100644 --- a/source4/ntvfs/common/opendb.h +++ b/source4/ntvfs/common/opendb.h @@ -36,6 +36,7 @@ struct opendb_ops { const char **delete_path); NTSTATUS (*odb_remove_pending)(struct odb_lock *lck, void *private); NTSTATUS (*odb_rename)(struct odb_lock *lck, const char *path); + NTSTATUS (*odb_get_path)(struct odb_lock *lck, const char **path); NTSTATUS (*odb_set_delete_on_close)(struct odb_lock *lck, bool del_on_close); NTSTATUS (*odb_get_delete_on_close)(struct odb_context *odb, DATA_BLOB *key, bool *del_on_close); diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 37c1c0850b..47b35f594c 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -713,6 +713,25 @@ static NTSTATUS odb_tdb_rename(struct odb_lock *lck, const char *path) return odb_push_record(lck, &file); } +/* + get the path of an open file +*/ +static NTSTATUS odb_tdb_get_path(struct odb_lock *lck, const char **path) +{ + struct opendb_file file; + NTSTATUS status; + + *path = NULL; + + status = odb_pull_record(lck, &file); + /* we don't ignore NT_STATUS_OBJECT_NAME_NOT_FOUND here */ + NT_STATUS_NOT_OK_RETURN(status); + + *path = file.path; + + return NT_STATUS_OK; +} + /* update delete on close flag on an open file */ @@ -802,6 +821,7 @@ static const struct opendb_ops opendb_tdb_ops = { .odb_close_file = odb_tdb_close_file, .odb_remove_pending = odb_tdb_remove_pending, .odb_rename = odb_tdb_rename, + .odb_get_path = odb_tdb_get_path, .odb_set_delete_on_close = odb_tdb_set_delete_on_close, .odb_get_delete_on_close = odb_tdb_get_delete_on_close, .odb_can_open = odb_tdb_can_open, -- cgit From c5d961586e72b181b24fcbaf98c8da2fa27aa2d1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 29 Feb 2008 13:04:08 +0100 Subject: pvfs_resolve: fix endless loop with trailing ".." We also need to move the NULL termination. metze (This used to be commit 4fc41065a31cc8bd477ff5bf2d89f9f595002227) --- source4/ntvfs/posix/pvfs_resolve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4') diff --git a/source4/ntvfs/posix/pvfs_resolve.c b/source4/ntvfs/posix/pvfs_resolve.c index 2bfc47beff..c129038572 100644 --- a/source4/ntvfs/posix/pvfs_resolve.c +++ b/source4/ntvfs/posix/pvfs_resolve.c @@ -399,7 +399,7 @@ static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx, if (ISDOTDOT(components[i])) { if (i < 1) return NT_STATUS_OBJECT_PATH_SYNTAX_BAD; memmove(&components[i-1], &components[i+1], - sizeof(char *)*(num_components-(i+1))); + sizeof(char *)*(num_components-i)); i -= 2; continue; } -- cgit From 5734a10c89b3ca90ee9463320a9be268fed38e8f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 29 Feb 2008 09:08:57 +0100 Subject: pvfs_resolve: "\\" and a trailing "\" need to be reduced metze (This used to be commit 356338b99a67bfaf09618f5ed7c8f5c4ff69fa06) --- source4/ntvfs/posix/pvfs_resolve.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source4') diff --git a/source4/ntvfs/posix/pvfs_resolve.c b/source4/ntvfs/posix/pvfs_resolve.c index c129038572..37b182733c 100644 --- a/source4/ntvfs/posix/pvfs_resolve.c +++ b/source4/ntvfs/posix/pvfs_resolve.c @@ -265,8 +265,15 @@ static NTSTATUS pvfs_unix_path(struct pvfs_state *pvfs, const char *cifs_name, of a name */ return NT_STATUS_ILLEGAL_CHARACTER; } - if (p > p_start && p[1] == 0) { - *p = 0; + if (p > p_start && (p[1] == '\\' || p[1] == '\0')) { + /* see if it is definately a "\\" or + * a trailing "\". If it is then fail here, + * and let the next layer up try again after + * pvfs_reduce_name() if it wants to. This is + * much more efficient on average than always + * scanning for these separately + */ + return NT_STATUS_OBJECT_PATH_SYNTAX_BAD; } else { *p = '/'; } -- cgit From 09173244d20448aa5d9432433f30f1ee58ba14e8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 29 Feb 2008 08:15:50 +0100 Subject: RAW-CHKPATH: also use qpathinfo NAME_INFO and check the returned name Also add some more test combinations. metze (This used to be commit 09985b061add8202f65e2e426d70e87c19819f74) --- source4/torture/raw/chkpath.c | 77 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 11 deletions(-) (limited to 'source4') diff --git a/source4/torture/raw/chkpath.c b/source4/torture/raw/chkpath.c index 42a3c3cebe..fa69c92caa 100644 --- a/source4/torture/raw/chkpath.c +++ b/source4/torture/raw/chkpath.c @@ -54,24 +54,68 @@ static NTSTATUS single_search(struct smbcli_state *cli, return status; } -static bool test_path(struct smbcli_state *cli, const char *path, NTSTATUS expected, NTSTATUS dos_expected) +static bool test_path_ex(struct smbcli_state *cli, struct torture_context *tctx, + const char *path, const char *path_expected, + NTSTATUS expected, NTSTATUS dos_expected) { union smb_chkpath io; + union smb_fileinfo finfo; NTSTATUS status; + io.chkpath.in.path = path; status = smb_raw_chkpath(cli->tree, &io); if (!NT_STATUS_EQUAL(status, expected) && !NT_STATUS_EQUAL(status, dos_expected)) { - printf("%-40s FAILED %s should be %s or %s\n", + printf("FAILED %-30s chkpath %s should be %s or %s\n", path, nt_errstr(status), nt_errstr(expected), nt_errstr(dos_expected)); return false; } else { - printf("%-40s correct (%s)\n", path, nt_errstr(status)); + printf("%-30s chkpath correct (%s)\n", path, nt_errstr(status)); + } + + if (NT_STATUS_EQUAL(expected, NT_STATUS_NOT_A_DIRECTORY)) { + expected = NT_STATUS_OK; + } + + ZERO_STRUCT(finfo); + finfo.generic.level = RAW_FILEINFO_NAME_INFO; + finfo.generic.in.file.path = path; + status = smb_raw_pathinfo(cli->tree, cli, &finfo); + if (!NT_STATUS_EQUAL(status, expected) && !NT_STATUS_EQUAL(status, dos_expected)) { + printf("FAILED: %-30s pathinfo %s should be %s or %s\n", + path, nt_errstr(status), nt_errstr(expected), nt_errstr(dos_expected)); + return false; + } + + if (!NT_STATUS_IS_OK(status)) { + printf("%-30s chkpath correct (%s)\n", path, nt_errstr(status)); + return true; + } + if (path_expected && + (!finfo.name_info.out.fname.s || + strcmp(finfo.name_info.out.fname.s, path_expected) != 0)) { + if (tctx && torture_setting_bool(tctx, "samba4", false)) { + printf("IGNORE: %-30s => %-20s should be %s\n", + path, finfo.name_info.out.fname.s, path_expected); + return true; + } + printf("FAILED: %-30s => %-20s should be %s\n", + path, finfo.name_info.out.fname.s, path_expected); + return false; } + printf("%-30s => %-20s correct\n", + path, finfo.name_info.out.fname.s); + return true; } -static bool test_chkpath(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static bool test_path(struct smbcli_state *cli, const char *path, + NTSTATUS expected, NTSTATUS dos_expected) +{ + return test_path_ex(cli, NULL, path, path, expected, dos_expected); +} + +static bool test_chkpath(struct smbcli_state *cli, struct torture_context *tctx) { union smb_chkpath io; NTSTATUS status; @@ -86,7 +130,7 @@ static bool test_chkpath(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) ret &= test_path(cli, BASEDIR "\\nodir", NT_STATUS_OBJECT_NAME_NOT_FOUND, NT_STATUS_DOS(ERRDOS,ERRbadpath)); - fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\test.txt.."); + fnum = create_complex_file(cli, tctx, BASEDIR "\\test.txt.."); if (fnum == -1) { printf("failed to open test.txt - %s\n", smbcli_errstr(cli->tree)); ret = false; @@ -101,9 +145,20 @@ static bool test_chkpath(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) goto done; } - ret &= test_path(cli, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); - ret &= test_path(cli, BASEDIR "\\foo\\..\\test.txt..", NT_STATUS_NOT_A_DIRECTORY, NT_STATUS_DOS(ERRDOS,ERRbadpath)); - ret &= test_path(cli, "", NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, BASEDIR, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, ((char *)BASEDIR) + 1, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, ((char *)BASEDIR"\\\\") + 1, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, ((char *)BASEDIR"\\foo\\..") + 1, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, ((char *)BASEDIR"\\f\\o\\o\\..\\..\\..") + 1, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, ((char *)BASEDIR"\\foo\\\\\..\\\\") + 1, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, BASEDIR"\\", BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, BASEDIR"\\\\..\\"BASEDIR, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, BASEDIR"\\\\\\", BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, "\\\\\\\\"BASEDIR"\\\\\\\\", BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, "\\\\\\\\"BASEDIR, BASEDIR, NT_STATUS_OK, NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, BASEDIR "\\foo\\..\\test.txt..", BASEDIR "\\test.txt..", + NT_STATUS_NOT_A_DIRECTORY, NT_STATUS_DOS(ERRDOS,ERRbadpath)); + ret &= test_path_ex(cli, tctx, "", "\\", NT_STATUS_OK, NT_STATUS_OK); ret &= test_path(cli, ".", NT_STATUS_OBJECT_NAME_INVALID, NT_STATUS_DOS(ERRDOS,ERRbadpath)); ret &= test_path(cli, ".\\", NT_STATUS_OBJECT_NAME_INVALID, NT_STATUS_DOS(ERRDOS,ERRbadpath)); ret &= test_path(cli, "\\\\\\.\\", NT_STATUS_OBJECT_NAME_INVALID, NT_STATUS_DOS(ERRDOS,ERRbadpath)); @@ -122,7 +177,7 @@ static bool test_chkpath(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) give different NT status returns for chkpth and findfirst. */ printf("testing findfirst on %s\n", "\\.\\\\\\\\\\\\."); - status = single_search(cli, mem_ctx, "\\.\\\\\\\\\\\\."); + status = single_search(cli, tctx, "\\.\\\\\\\\\\\\."); CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID,NT_STATUS_DOS(ERRDOS,ERRinvalidname)); ret &= test_path(cli, "\\.\\\\\\\\\\\\.", NT_STATUS_OBJECT_PATH_NOT_FOUND,NT_STATUS_DOS(ERRDOS,ERRbadpath)); @@ -164,7 +219,7 @@ static bool test_chkpath(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) ret &= test_path(cli, "\\..\\", NT_STATUS_OBJECT_PATH_SYNTAX_BAD,NT_STATUS_DOS(ERRDOS,ERRinvalidpath)); ret &= test_path(cli, "\\..", NT_STATUS_OBJECT_PATH_SYNTAX_BAD,NT_STATUS_DOS(ERRDOS,ERRinvalidpath)); ret &= test_path(cli, BASEDIR "\\.", NT_STATUS_OBJECT_NAME_INVALID,NT_STATUS_DOS(ERRDOS,ERRbadpath)); - ret &= test_path(cli, BASEDIR "\\..", NT_STATUS_OK,NT_STATUS_OK); + ret &= test_path_ex(cli, tctx, BASEDIR "\\..", "\\", NT_STATUS_OK,NT_STATUS_OK); ret &= test_path(cli, BASEDIR "\\nt\\V S\\VB98\\vb600", NT_STATUS_OBJECT_NAME_NOT_FOUND,NT_STATUS_DOS(ERRDOS,ERRbadpath)); ret &= test_path(cli, BASEDIR "\\nt\\V S\\VB98\\vb6.exe", NT_STATUS_NOT_A_DIRECTORY,NT_STATUS_DOS(ERRDOS,ERRbadpath)); @@ -183,7 +238,7 @@ static bool test_chkpath(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND,NT_STATUS_DOS(ERRDOS,ERRbadpath)); printf("testing findfirst on %s\n", BASEDIR".\\.\\.\\.\\foo\\..\\.\\"); - status = single_search(cli, mem_ctx, BASEDIR".\\.\\.\\.\\foo\\..\\.\\"); + status = single_search(cli, tctx, BASEDIR".\\.\\.\\.\\foo\\..\\.\\"); CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND,NT_STATUS_DOS(ERRDOS,ERRbadpath)); /* We expect this open to fail with the same error code as the chkpath below. */ -- cgit From f9b2d29d32197095c993d57e00ffbc09ab27184c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Feb 2008 12:14:17 +0100 Subject: pvfs_resolve: add pvfs_resolve_name_handle() metze (This used to be commit 714717253c035b31fc850df8456f8cf2b38bcb72) --- source4/ntvfs/posix/pvfs_resolve.c | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'source4') diff --git a/source4/ntvfs/posix/pvfs_resolve.c b/source4/ntvfs/posix/pvfs_resolve.c index 37b182733c..325bc74f8f 100644 --- a/source4/ntvfs/posix/pvfs_resolve.c +++ b/source4/ntvfs/posix/pvfs_resolve.c @@ -623,6 +623,86 @@ NTSTATUS pvfs_resolve_name_fd(struct pvfs_state *pvfs, int fd, return pvfs_fill_dos_info(pvfs, name, fd); } +/* + fill in the pvfs_filename info for an open file, given the current + info for a (possibly) non-open file. This is used by places that need + to update the pvfs_filename stat information, and the path + after a possible rename on a different handle. +*/ +NTSTATUS pvfs_resolve_name_handle(struct pvfs_state *pvfs, + struct pvfs_file_handle *h) +{ + NTSTATUS status; + + if (h->have_opendb_entry) { + struct odb_lock *lck; + const char *name = NULL; + + lck = odb_lock(h, h->pvfs->odb_context, &h->odb_locking_key); + if (lck == NULL) { + DEBUG(0,("%s: failed to lock file '%s' in opendb\n", + __FUNCTION__, h->name->full_name)); + /* we were supposed to do a blocking lock, so something + is badly wrong! */ + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + + status = odb_get_path(lck, &name); + if (NT_STATUS_IS_OK(status)) { + /* + * This relies an the fact that + * renames of open files are only + * allowed by setpathinfo() and setfileinfo() + * and there're only renames within the same + * directory supported + */ + if (strcmp(h->name->full_name, name) != 0) { + const char *orig_dir; + const char *new_file; + const char *new_orig; + char *delim; + + delim = strrchr(name, '/'); + if (!delim) { + talloc_free(lck); + return NT_STATUS_INTERNAL_ERROR; + } + + new_file = delim + 1; + delim = strrchr(h->name->original_name, '\\'); + if (delim) { + delim[0] = '\0'; + orig_dir = h->name->original_name; + new_orig = talloc_asprintf(h->name, "%s\\%s", + orig_dir, new_file); + if (!new_orig) { + talloc_free(lck); + return NT_STATUS_NO_MEMORY; + } + } else { + new_orig = talloc_strdup(h->name, new_file); + if (!new_orig) { + talloc_free(lck); + return NT_STATUS_NO_MEMORY; + } + } + + talloc_free(h->name->original_name); + talloc_free(h->name->full_name); + h->name->full_name = talloc_steal(h->name, name); + h->name->original_name = new_orig; + } + } + + talloc_free(lck); + } + + status = pvfs_resolve_name_fd(pvfs, h->fd, h->name); + NT_STATUS_NOT_OK_RETURN(status); + + return NT_STATUS_OK; +} + /* resolve the parent of a given name -- cgit From daa4dec695b53e0c7ea442b6ca0b012f128ed759 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Feb 2008 12:17:59 +0100 Subject: pvfs: use pvfs_resolve_name_handle() in qfileinfo and setfileinfo metze (This used to be commit 4b1a266f6fb04c8f923c48ea215ece6b45a18ea7) --- source4/ntvfs/posix/pvfs_qfileinfo.c | 2 +- source4/ntvfs/posix/pvfs_setfileinfo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4') diff --git a/source4/ntvfs/posix/pvfs_qfileinfo.c b/source4/ntvfs/posix/pvfs_qfileinfo.c index 6ed729541f..6bc21e5e3e 100644 --- a/source4/ntvfs/posix/pvfs_qfileinfo.c +++ b/source4/ntvfs/posix/pvfs_qfileinfo.c @@ -368,7 +368,7 @@ NTSTATUS pvfs_qfileinfo(struct ntvfs_module_context *ntvfs, } /* update the file information */ - status = pvfs_resolve_name_fd(pvfs, h->fd, h->name); + status = pvfs_resolve_name_handle(pvfs, h); if (!NT_STATUS_IS_OK(status)) { return status; } diff --git a/source4/ntvfs/posix/pvfs_setfileinfo.c b/source4/ntvfs/posix/pvfs_setfileinfo.c index da1e31e639..fcadbfd852 100644 --- a/source4/ntvfs/posix/pvfs_setfileinfo.c +++ b/source4/ntvfs/posix/pvfs_setfileinfo.c @@ -289,7 +289,7 @@ NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs, } /* update the file information */ - status = pvfs_resolve_name_fd(pvfs, h->fd, h->name); + status = pvfs_resolve_name_handle(pvfs, h); if (!NT_STATUS_IS_OK(status)) { return status; } -- cgit From 176e20bf2662838cbc28d42c342a4d442f6bc308 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Feb 2008 12:19:18 +0100 Subject: pvfs_setfileinfo: tell the opendb about renames metze (This used to be commit 9360eda2c5606b2c73edb768af8ca0e8ba310e30) --- source4/ntvfs/posix/pvfs_setfileinfo.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'source4') diff --git a/source4/ntvfs/posix/pvfs_setfileinfo.c b/source4/ntvfs/posix/pvfs_setfileinfo.c index fcadbfd852..18647c95c5 100644 --- a/source4/ntvfs/posix/pvfs_setfileinfo.c +++ b/source4/ntvfs/posix/pvfs_setfileinfo.c @@ -82,11 +82,13 @@ static uint32_t pvfs_setfileinfo_access(union smb_setfileinfo *info) static NTSTATUS pvfs_setfileinfo_rename(struct pvfs_state *pvfs, struct ntvfs_request *req, struct pvfs_filename *name, + DATA_BLOB *odb_locking_key, union smb_setfileinfo *info) { NTSTATUS status; struct pvfs_filename *name2; char *new_name, *p; + struct odb_lock *lck = NULL; /* renames are only allowed within a directory */ if (strchr_m(info->rename_information.in.new_name, '\\') && @@ -168,7 +170,18 @@ static NTSTATUS pvfs_setfileinfo_rename(struct pvfs_state *pvfs, return status; } + lck = odb_lock(req, pvfs->odb_context, odb_locking_key); + if (lck == NULL) { + DEBUG(0,("Unable to lock opendb for can_stat\n")); + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + status = pvfs_do_rename(pvfs, name, name2->full_name); + if (NT_STATUS_IS_OK(status)) { + status = odb_rename(lck, name2->full_name); + } + talloc_free(lck); + NT_STATUS_NOT_OK_RETURN(status); if (NT_STATUS_IS_OK(status)) { name->full_name = talloc_steal(name, name2->full_name); name->original_name = talloc_steal(name, name2->original_name); @@ -391,7 +404,8 @@ NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs, case RAW_SFILEINFO_RENAME_INFORMATION: case RAW_SFILEINFO_RENAME_INFORMATION_SMB2: - return pvfs_setfileinfo_rename(pvfs, req, h->name, + return pvfs_setfileinfo_rename(pvfs, req, h->name, + &h->odb_locking_key, info); case RAW_SFILEINFO_SEC_DESC: @@ -565,6 +579,7 @@ NTSTATUS pvfs_setpathinfo(struct ntvfs_module_context *ntvfs, uint32_t access_needed; uint32_t change_mask = 0; struct odb_lock *lck = NULL; + DATA_BLOB odb_locking_key; /* resolve the cifs name to a posix name */ status = pvfs_resolve_name(pvfs, req, info->generic.in.file.path, @@ -696,8 +711,12 @@ NTSTATUS pvfs_setpathinfo(struct ntvfs_module_context *ntvfs, case RAW_SFILEINFO_RENAME_INFORMATION: case RAW_SFILEINFO_RENAME_INFORMATION_SMB2: - return pvfs_setfileinfo_rename(pvfs, req, name, - info); + status = pvfs_locking_key(name, name, &odb_locking_key); + NT_STATUS_NOT_OK_RETURN(status); + status = pvfs_setfileinfo_rename(pvfs, req, name, + &odb_locking_key, info); + NT_STATUS_NOT_OK_RETURN(status); + return NT_STATUS_OK; case RAW_SFILEINFO_DISPOSITION_INFO: case RAW_SFILEINFO_DISPOSITION_INFORMATION: -- cgit From d5f9559688c318cdd21608be05cf56dbfd3badb9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Feb 2008 12:20:22 +0100 Subject: selftest: we pass RAW-OPLOCK BATCH19 and 20 now metze (This used to be commit 752d686385925d06e64c0a7adfbd9021f787811d) --- source4/samba4-knownfail | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4') diff --git a/source4/samba4-knownfail b/source4/samba4-knownfail index aaa11774ae..4d850caae5 100644 --- a/source4/samba4-knownfail +++ b/source4/samba4-knownfail @@ -3,8 +3,6 @@ local.iconv.*.next_codepoint() base.delaywrite.finfo update on close base.delete.*.deltest20a base.delete.*.deltest20b -raw.oplock.*BATCH19 -raw.oplock.*BATCH20 rpc.winreg local.registry.*.security # Not implemented yet rpc.wkssvc -- cgit From a0235410aee5edab4a2a1af432bd73b5a1980d2d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 29 Feb 2008 09:10:12 +0100 Subject: pvfs_setfileinfo: support renaming of directories metze (This used to be commit 2ecc7ec8b392cf3ec698d168bf6fb7898e1978f1) --- source4/ntvfs/posix/pvfs_setfileinfo.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source4') diff --git a/source4/ntvfs/posix/pvfs_setfileinfo.c b/source4/ntvfs/posix/pvfs_setfileinfo.c index 18647c95c5..5ac9cedc48 100644 --- a/source4/ntvfs/posix/pvfs_setfileinfo.c +++ b/source4/ntvfs/posix/pvfs_setfileinfo.c @@ -96,11 +96,6 @@ static NTSTATUS pvfs_setfileinfo_rename(struct pvfs_state *pvfs, return NT_STATUS_NOT_SUPPORTED; } - if (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) { - /* don't allow this for now */ - return NT_STATUS_FILE_IS_A_DIRECTORY; - } - /* don't allow stream renames for now */ if (name->stream_name) { return NT_STATUS_INVALID_PARAMETER; -- cgit From 863e65e9556749affdfea544785fdbb301774f6b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Feb 2008 12:10:27 +0100 Subject: RAW-SFILEINFO-RENAME: test renaming by path while a handle is open on a file metze (This used to be commit 6c0395d4d980c6165ee0a378b632bced22e8f1d3) --- source4/torture/raw/setfileinfo.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source4') diff --git a/source4/torture/raw/setfileinfo.c b/source4/torture/raw/setfileinfo.c index e58b3fd760..e8e4031ea4 100644 --- a/source4/torture/raw/setfileinfo.c +++ b/source4/torture/raw/setfileinfo.c @@ -554,6 +554,31 @@ bool torture_raw_sfileinfo_rename(struct torture_context *torture, CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_INVALID_PARAMETER); CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname); + if (torture_setting_bool(torture, "samba3", false)) { + printf("SKIP: Trying rename by path while a handle is open\n"); + goto done; + } + + printf("Trying rename by path while a handle is open\n"); + fnum_saved = fnum; + fnum = create_complex_file(cli, torture, path_fname); + sfinfo.rename_information.in.new_name = path_fname_new+strlen(BASEDIR)+1; + sfinfo.rename_information.in.overwrite = 0; + sfinfo.rename_information.in.root_fid = 0; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_fname_new); + /* check that the handle returns the same name */ + check_fnum = true; + CHECK_STR(NAME_INFO, name_info, fname.s, path_fname_new); + /* rename it back on the handle */ + sfinfo.rename_information.in.new_name = path_fname+strlen(BASEDIR)+1; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_fname); + check_fnum = false; + CHECK_STR(NAME_INFO, name_info, fname.s, path_fname); + smbcli_close(cli->tree, fnum); + fnum = fnum_saved; + done: smb_raw_exit(cli->session); smbcli_close(cli->tree, fnum); -- cgit From e0081626ecf784351ad5f0bf7f6faeab8601e648 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 29 Feb 2008 09:03:47 +0100 Subject: RAW-SFILEINFO-RENAME: test renaming of directories by path and handle metze (This used to be commit ce2b7cec10af5bb222715e2e3c0ff139f659ed6e) --- source4/torture/raw/setfileinfo.c | 92 +++++++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 8 deletions(-) (limited to 'source4') diff --git a/source4/torture/raw/setfileinfo.c b/source4/torture/raw/setfileinfo.c index e8e4031ea4..90ccde7213 100644 --- a/source4/torture/raw/setfileinfo.c +++ b/source4/torture/raw/setfileinfo.c @@ -453,6 +453,10 @@ bool torture_raw_sfileinfo_rename(struct torture_context *torture, char *fnum_fname_new; char *path_fname; char *path_fname_new; + char *path_dname; + char *path_dname_new; + char *saved_name; + char *saved_name_new; union smb_fileinfo finfo1, finfo2; union smb_setfileinfo sfinfo; NTSTATUS status, status2; @@ -464,6 +468,8 @@ bool torture_raw_sfileinfo_rename(struct torture_context *torture, asprintf(&path_fname_new, BASEDIR "\\fname_test_new_%d.txt", n); asprintf(&fnum_fname, BASEDIR "\\fnum_test_%d.txt", n); asprintf(&fnum_fname_new, BASEDIR "\\fnum_test_new_%d.txt", n); + asprintf(&path_dname, BASEDIR "\\dname_test_%d", n); + asprintf(&path_dname_new, BASEDIR "\\dname_test_new_%d", n); if (!torture_setup_dir(cli, BASEDIR)) { return false; @@ -553,12 +559,50 @@ bool torture_raw_sfileinfo_rename(struct torture_context *torture, sfinfo.rename_information.in.root_fid = d_fnum; CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_INVALID_PARAMETER); CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname); + smbcli_close(cli->tree, d_fnum); + + printf("Trying rename directory\n"); + if (!torture_setup_dir(cli, path_dname)) { + ret = false; + goto done; + } + saved_name = path_fname; + saved_name_new = path_fname_new; + path_fname = path_dname; + path_fname_new = path_dname_new; + sfinfo.rename_information.in.new_name = path_dname_new+strlen(BASEDIR)+1; + sfinfo.rename_information.in.overwrite = 0; + sfinfo.rename_information.in.root_fid = 0; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_dname_new); + path_fname = saved_name; + path_fname_new = saved_name_new; if (torture_setting_bool(torture, "samba3", false)) { + printf("SKIP: Trying rename directory with a handle\n"); printf("SKIP: Trying rename by path while a handle is open\n"); + printf("SKIP: Trying rename directory by path while a handle is open\n"); goto done; } + printf("Trying rename directory with a handle\n"); + status = create_directory_handle(cli->tree, path_dname_new, &d_fnum); + fnum_saved = fnum; + fnum = d_fnum; + saved_name = fnum_fname; + saved_name_new = fnum_fname_new; + fnum_fname = path_dname; + fnum_fname_new = path_dname_new; + sfinfo.rename_information.in.new_name = path_dname+strlen(BASEDIR)+1; + sfinfo.rename_information.in.overwrite = 0; + sfinfo.rename_information.in.root_fid = 0; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_dname); + smbcli_close(cli->tree, d_fnum); + fnum = fnum_saved; + fnum_fname = saved_name; + fnum_fname_new = saved_name_new; + printf("Trying rename by path while a handle is open\n"); fnum_saved = fnum; fnum = create_complex_file(cli, torture, path_fname); @@ -579,16 +623,48 @@ bool torture_raw_sfileinfo_rename(struct torture_context *torture, smbcli_close(cli->tree, fnum); fnum = fnum_saved; + printf("Trying rename directory by path while a handle is open\n"); + status = create_directory_handle(cli->tree, path_dname, &d_fnum); + fnum_saved = fnum; + fnum = d_fnum; + saved_name = path_fname; + saved_name_new = path_fname_new; + path_fname = path_dname; + path_fname_new = path_dname_new; + sfinfo.rename_information.in.new_name = path_dname_new+strlen(BASEDIR)+1; + sfinfo.rename_information.in.overwrite = 0; + sfinfo.rename_information.in.root_fid = 0; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_dname_new); + path_fname = saved_name; + path_fname_new = saved_name_new; + saved_name = fnum_fname; + saved_name_new = fnum_fname_new; + fnum_fname = path_dname; + fnum_fname_new = path_dname_new; + /* check that the handle returns the same name */ + check_fnum = true; + CHECK_STR(NAME_INFO, name_info, fname.s, path_dname_new); + /* rename it back on the handle */ + sfinfo.rename_information.in.new_name = path_dname+strlen(BASEDIR)+1; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_dname); + fnum_fname = saved_name; + fnum_fname_new = saved_name_new; + saved_name = path_fname; + saved_name_new = path_fname_new; + path_fname = path_dname; + path_fname_new = path_dname_new; + check_fnum = false; + CHECK_STR(NAME_INFO, name_info, fname.s, path_dname); + smbcli_close(cli->tree, d_fnum); + fnum = fnum_saved; + path_fname = saved_name; + path_fname_new = saved_name_new; + done: smb_raw_exit(cli->session); - smbcli_close(cli->tree, fnum); - if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fnum_fname))) { - printf("Failed to delete %s - %s\n", fnum_fname, smbcli_errstr(cli->tree)); - } - if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, path_fname))) { - printf("Failed to delete %s - %s\n", path_fname, smbcli_errstr(cli->tree)); - } - + smbcli_deltree(cli->tree, BASEDIR); return ret; } -- cgit From 232d51e666a9a9dd65579d9c7b5873bafa9f669d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 29 Feb 2008 15:32:33 +0100 Subject: Remove useless include, simplify generated CFLAGS lines in Makefile. (This used to be commit 3157ce9876aa69de54acf3f08e0ee2b16cfaff80) --- source4/Makefile | 1 - source4/build/smb_build/makefile.pm | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'source4') diff --git a/source4/Makefile b/source4/Makefile index f9a753eb67..1fddfefce3 100644 --- a/source4/Makefile +++ b/source4/Makefile @@ -23,7 +23,6 @@ default: all include rules.mk include data.mk -include extra_cflags.txt DEFAULT_HEADERS = $(srcdir)/lib/util/dlinklist.h \ $(srcdir)/version.h diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index 902e8f7f42..c5cc3d3e8c 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -442,13 +442,7 @@ sub CFlags($$) my $cflags = join(' ', @cflags); - foreach (@{$key->{OBJ_LIST}}) { - my $ofile = $_; - my $dfile = $_; - $dfile =~ s/\.o$/.d/; - $dfile =~ s/\.ho$/.d/; - $self->output("$ofile $dfile: CFLAGS+= $cflags\n"); - } + $self->output("\$(patsubst %.ho,%.d,\$(key->{NAME}_OBJ_FILES:.o=.d)) \$($key->{NAME}_OBJ_FILES): CFLAGS+= $cflags\n"); } 1; -- cgit From 9817a667331bfa31b06d9895aa96451b1ff0a9d9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 29 Feb 2008 15:39:18 +0100 Subject: Use special make variables. (This used to be commit dfb4ddcd5dbd27d275e7a41ede5441be25db9a35) --- source4/librpc/config.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4') diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk index e37bd4fae7..7abc693960 100644 --- a/source4/librpc/config.mk +++ b/source4/librpc/config.mk @@ -297,9 +297,9 @@ clean:: include librpc/idl-deps librpc/gen_ndr/tables.c: $(IDL_NDR_PARSE_H_FILES) - @echo Generating librpc/gen_ndr/tables.c - @$(PERL) $(srcdir)/librpc/tables.pl --output=librpc/gen_ndr/tables.c $(IDL_NDR_PARSE_H_FILES) > librpc/gen_ndr/tables.x - mv librpc/gen_ndr/tables.x librpc/gen_ndr/tables.c + @echo Generating $@ + @$(PERL) $(srcdir)/librpc/tables.pl --output=$@ $^ > librpc/gen_ndr/tables.x + @mv librpc/gen_ndr/tables.x $@ [SUBSYSTEM::NDR_TABLE] OBJ_FILES = ndr/ndr_table.o gen_ndr/tables.o -- cgit From 21b54de82fc1bbbd80c80908d351fde2409a3feb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 25 Feb 2008 17:20:33 +0100 Subject: Allow absolute paths to be specified to mkproto.pl. (This used to be commit 46d8d02028869c97226648113d6bff1c06477d61) --- source4/script/mkproto.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4') diff --git a/source4/script/mkproto.pl b/source4/script/mkproto.pl index 5aeece7155..87a68e33fa 100755 --- a/source4/script/mkproto.pl +++ b/source4/script/mkproto.pl @@ -157,7 +157,9 @@ sub process_file($$$) $filename =~ s/\.o$/\.c/g; - if (!open(FH, "< $builddir/$filename")) { + if ($filename =~ /^\//) { + open(FH, "<$filename") or die("Failed to open $filename"); + } elsif (!open(FH, "< $builddir/$filename")) { open(FH, "< $srcdir/$filename") || die "Failed to open $filename"; } -- cgit From bb176a124ee9c36a66092f9a60aa6893ad9555f9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 25 Feb 2008 18:05:47 +0100 Subject: Move automatic dependencies code out of perl code. (This used to be commit 58a93ef94b878ff2d2d0029fc2d443551842e712) --- source4/Makefile | 30 +++++++++++++++++++++++++++++- source4/build/smb_build/makefile.pm | 37 ++----------------------------------- source4/rules.mk | 3 --- 3 files changed, 31 insertions(+), 39 deletions(-) (limited to 'source4') diff --git a/source4/Makefile b/source4/Makefile index 1fddfefce3..97518ebcb6 100644 --- a/source4/Makefile +++ b/source4/Makefile @@ -19,11 +19,39 @@ BNLD_FLAGS = $(LDFLAGS) $(SYS_LDFLAGS) HOSTCC_FLAGS = -D_SAMBA_HOSTCC_ $(CFLAGS) HOSTLD_FLAGS = $(LDFLAGS) $(SYS_LDFLAGS) -default: all +.DEFAULT_GOAL := all + +ifneq ($(automatic_deps),yes) +ALL_PREDEP = proto +.NOTPARALLEL: +endif include rules.mk include data.mk +DEP_FILES = $(patsubst %.ho,%.hd,$(patsubst %.o,%.d,$(ALL_OBJS))) \ + include/includes.d + +ifeq ($(automatic_deps),yes) +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(MAKECMDGOALS),distclean) +ifneq ($(MAKECMDGOALS),realdistclean) +ifneq ($(SKIP_DEP_FILES),yes) +-include $(DEP_FILES) +endif +endif +endif +endif + +ifneq ($(SKIP_DEP_FILES),yes) +clean:: + @echo Removing dependency files + @find . -name '*.d' -o -name '*.hd' | xargs rm -f +endif +else +include $(srcdir)/static_deps.mk +endif + DEFAULT_HEADERS = $(srcdir)/lib/util/dlinklist.h \ $(srcdir)/version.h diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index c5cc3d3e8c..26f986eacf 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -30,11 +30,6 @@ sub new($$$) $self->output("################################################\n"); $self->output("\n"); - if (!$self->{automatic_deps}) { - $self->output("ALL_PREDEP = proto\n"); - $self->output(".NOTPARALLEL:\n"); - } - return $self; } @@ -78,23 +73,17 @@ sub _prepare_mk_files($) push (@tmp, $_); } - if ($self->{gnu_make}) { - $self->output(" + $self->output(" ifneq (\$(MAKECMDGOALS),clean) ifneq (\$(MAKECMDGOALS),distclean) ifneq (\$(MAKECMDGOALS),realdistclean) "); - } - $self->output("MK_FILES = " . array2oneperline(\@tmp) . "\n"); - - if ($self->{gnu_make}) { - $self->output(" + $self->output(" endif endif endif "); - } } sub array2oneperline($) @@ -369,28 +358,6 @@ sub write($$) $self->output($self->{mkfile}); - if ($self->{automatic_deps}) { - $self->output(" -ifneq (\$(MAKECMDGOALS),clean) -ifneq (\$(MAKECMDGOALS),distclean) -ifneq (\$(MAKECMDGOALS),realdistclean) -ifneq (\$(SKIP_DEP_FILES),yes) --include \$(DEP_FILES) -endif -endif -endif -endif - -ifneq (\$(SKIP_DEP_FILES),yes) -clean:: - \@echo Removing dependency files - \@find . -name '*.d' -o -name '*.hd' | xargs rm -f -endif -"); - } else { - $self->output("include \$(srcdir)/static_deps.mk\n"); - } - open(MAKEFILE,">$file") || die ("Can't open $file\n"); print MAKEFILE $self->{output}; close(MAKEFILE); diff --git a/source4/rules.mk b/source4/rules.mk index d0be997d0c..5f91f8132e 100644 --- a/source4/rules.mk +++ b/source4/rules.mk @@ -162,9 +162,6 @@ DOCBOOK_MANPAGE_URL = http://docbook.sourceforge.net/release/xsl/current/manpage .8.xml.8: $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $< -DEP_FILES = $(patsubst %.ho,%.hd,$(patsubst %.o,%.d,$(ALL_OBJS))) \ - include/includes.d - dist:: idl_full manpages configure distclean configure: -- cgit From 7071276c65e0335386441bd2b81afeac73283808 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 16 Feb 2008 20:24:47 +0100 Subject: Simpler handling of sonameflag. (This used to be commit 1e786bb7da689c3aa435e92975f33db5a308b6a7) --- source4/build/smb_build/makefile.pm | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'source4') diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index 26f986eacf..52bd5ed610 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -225,31 +225,22 @@ sub SharedLibrary($$) $self->_prepare_list($ctx, "DEPEND_LIST"); $self->_prepare_list($ctx, "LINK_FLAGS"); - my $soarg = ""; - my $lns = ""; - if ($self->{config}->{SONAMEFLAG} ne "#" and defined($ctx->{LIBRARY_SONAME})) { - $soarg = "$self->{config}->{SONAMEFLAG}$ctx->{LIBRARY_SONAME}"; - if ($ctx->{LIBRARY_REALNAME} ne $ctx->{LIBRARY_SONAME}) { - $lns .= "\n\t\@test \$($ctx->{NAME}_VERSION) = \$($ctx->{NAME}_SOVERSION) || ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}"; - } - } - - $lns .= "\nifdef $ctx->{NAME}_SOVERSION"; - $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}"; - $lns .= "\nendif"; - $self->output(<< "__EOD__" -# $ctx->{RESULT_SHARED_LIBRARY}: \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST) \@echo Linking \$\@ \@mkdir -p \$(\@D) \@\$(SHLD) \$(LDFLAGS) \$(SHLD_FLAGS) \$(INTERN_LDFLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\ \$($ctx->{NAME}\_FULL_OBJ_LIST) \\ \$($ctx->{NAME}_LINK_FLAGS) \\ - $soarg$lns + \$(if \$(SONAMEFLAG), \$(SONAMEFLAG)$ctx->{LIBRARY_SONAME}) __EOD__ ); - $self->output("\n"); + if ($ctx->{LIBRARY_REALNAME} ne $ctx->{LIBRARY_SONAME}) { + $self->output("\t\@test \$($ctx->{NAME}_VERSION) = \$($ctx->{NAME}_SOVERSION) || ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}\n"); + } + $self->output("ifdef $ctx->{NAME}_SOVERSION\n"); + $self->output("\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}\n"); + $self->output("endif\n"); } sub MergedObj($$) -- cgit From 2bb8e49a7e8f38f053fb3d282ec62cfa4b52196e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 29 Feb 2008 15:47:04 +0100 Subject: Fix variable name. (This used to be commit b5db8defcae0a718e5239e8c7705c9bf6eb431ec) --- source4/build/smb_build/makefile.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4') diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index 52bd5ed610..f2bff1a029 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -400,7 +400,7 @@ sub CFlags($$) my $cflags = join(' ', @cflags); - $self->output("\$(patsubst %.ho,%.d,\$(key->{NAME}_OBJ_FILES:.o=.d)) \$($key->{NAME}_OBJ_FILES): CFLAGS+= $cflags\n"); + $self->output("\$(patsubst %.ho,%.d,\$(key->{NAME}_OBJ_LIST:.o=.d)) \$($key->{NAME}_OBJ_LIST): CFLAGS+= $cflags\n"); } 1; -- cgit From 98db64734367da419877dd87d0548d93be23d483 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 29 Feb 2008 17:04:57 +0100 Subject: Remove duplicate message. (This used to be commit 87074881a926f6216276ebc263047c1ffb8aee10) --- source4/build/smb_build/main.pl | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4') diff --git a/source4/build/smb_build/main.pl b/source4/build/smb_build/main.pl index 7312749f28..c3dc46461b 100644 --- a/source4/build/smb_build/main.pl +++ b/source4/build/smb_build/main.pl @@ -86,6 +86,4 @@ header::create_smb_build_h($OUTPUT, "include/build.h"); summary::show($OUTPUT, \%config::config); -print "To build Samba, run $config::config{MAKE}\n"; - 1; -- cgit From 0de1a63c18a83fd97938816fe869c42cbe92aac9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 1 Mar 2008 10:05:25 +0100 Subject: pvfs_rename: move odb_rename() onto pvfs_do_rename() metze (This used to be commit 5a1f0c0ce995064c23e9f726bceddbd8442c4293) --- source4/ntvfs/posix/pvfs_rename.c | 25 ++++++++++++------------- source4/ntvfs/posix/pvfs_setfileinfo.c | 5 +---- 2 files changed, 13 insertions(+), 17 deletions(-) (limited to 'source4') diff --git a/source4/ntvfs/posix/pvfs_rename.c b/source4/ntvfs/posix/pvfs_rename.c index 185e35f800..29b2d03005 100644 --- a/source4/ntvfs/posix/pvfs_rename.c +++ b/source4/ntvfs/posix/pvfs_rename.c @@ -28,16 +28,22 @@ /* do a file rename, and send any notify triggers */ -NTSTATUS pvfs_do_rename(struct pvfs_state *pvfs, const struct pvfs_filename *name1, +NTSTATUS pvfs_do_rename(struct pvfs_state *pvfs, + struct odb_lock *lck, + const struct pvfs_filename *name1, const char *name2) { const char *r1, *r2; uint32_t mask; + NTSTATUS status; if (rename(name1->full_name, name2) == -1) { return pvfs_map_errno(pvfs, errno); } + status = odb_rename(lck, name2); + NT_STATUS_NOT_OK_RETURN(status); + if (name1->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) { mask = FILE_NOTIFY_CHANGE_DIR_NAME; } else { @@ -315,11 +321,7 @@ static NTSTATUS pvfs_rename_one(struct pvfs_state *pvfs, return NT_STATUS_NO_MEMORY; } - status = pvfs_do_rename(pvfs, name1, fname2); - - if (NT_STATUS_IS_OK(status)) { - status = odb_rename(lck, fname2); - } + status = pvfs_do_rename(pvfs, lck, name1, fname2); failed: talloc_free(mem_ctx); @@ -448,9 +450,9 @@ static NTSTATUS pvfs_rename_mv(struct ntvfs_module_context *ntvfs, return status; } - status = pvfs_do_rename(pvfs, name1, name2->full_name); - if (NT_STATUS_IS_OK(status)) { - status = odb_rename(lck, name2->full_name); + status = pvfs_do_rename(pvfs, lck, name1, name2->full_name); + if (!NT_STATUS_IS_OK(status)) { + return status; } return NT_STATUS_OK; @@ -532,10 +534,7 @@ static NTSTATUS pvfs_rename_nt(struct ntvfs_module_context *ntvfs, case RENAME_FLAG_RENAME: status = pvfs_access_check_parent(pvfs, req, name2, SEC_DIR_ADD_FILE); NT_STATUS_NOT_OK_RETURN(status); - status = pvfs_do_rename(pvfs, name1, name2->full_name); - if (NT_STATUS_IS_OK(status)) { - status = odb_rename(lck, name2->full_name); - } + status = pvfs_do_rename(pvfs, lck, name1, name2->full_name); NT_STATUS_NOT_OK_RETURN(status); break; diff --git a/source4/ntvfs/posix/pvfs_setfileinfo.c b/source4/ntvfs/posix/pvfs_setfileinfo.c index 5ac9cedc48..ad47fe90c9 100644 --- a/source4/ntvfs/posix/pvfs_setfileinfo.c +++ b/source4/ntvfs/posix/pvfs_setfileinfo.c @@ -171,10 +171,7 @@ static NTSTATUS pvfs_setfileinfo_rename(struct pvfs_state *pvfs, return NT_STATUS_INTERNAL_DB_CORRUPTION; } - status = pvfs_do_rename(pvfs, name, name2->full_name); - if (NT_STATUS_IS_OK(status)) { - status = odb_rename(lck, name2->full_name); - } + status = pvfs_do_rename(pvfs, lck, name, name2->full_name); talloc_free(lck); NT_STATUS_NOT_OK_RETURN(status); if (NT_STATUS_IS_OK(status)) { -- cgit From 748f1c09629b251176a36f24c871b045192206ed Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Mar 2008 13:01:02 +0100 Subject: Fix error handling in ldb.add(). (This used to be commit a7f89b5bb28601597a4a0f75ec2b97bac02370d9) --- source4/lib/ldb/ldb.i | 84 +++++++++++------------- source4/lib/ldb/ldb_wrap.c | 158 +++++++++++++-------------------------------- 2 files changed, 81 insertions(+), 161 deletions(-) (limited to 'source4') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 336100c4f0..2c04662f25 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -547,6 +547,43 @@ PyObject *PyExc_LdbError; talloc_free($1); }; +%typemap(in,numinputs=1) ldb_msg *add_msg { + ldb_error ret; + int dict_pos, msg_pos; + PyObject *key, *value; + ldb_msg_element *msgel; + + if (PyDict_Check($input)) { + $1 = ldb_msg_new(NULL); + $1->elements = talloc_zero_array($1, struct ldb_message_element, PyDict_Size($input)); + msg_pos = dict_pos = 0; + while (PyDict_Next($input, &dict_pos, &key, &value)) { + if (!strcmp(PyString_AsString(key), "dn")) { + if (ldb_dn_from_pyobject($1, value, $self, &$1->dn) != 0) { + SWIG_exception(SWIG_TypeError, "unable to import dn object"); + } + } else { + msgel = ldb_msg_element_from_pyobject($1->elements, value, 0, PyString_AsString(key)); + if (msgel == NULL) { + SWIG_exception(SWIG_TypeError, "unable to import element"); + } + memcpy(&$1->elements[msg_pos], msgel, sizeof(*msgel)); + msg_pos++; + } + } + + if ($1->dn == NULL) { + SWIG_exception(SWIG_TypeError, "no dn set"); + } + + $1->num_elements = msg_pos; + } else { + if (SWIG_ConvertPtr($input, (void **)&$1, SWIGTYPE_p_ldb_message, 0) != 0) { + SWIG_exception(SWIG_TypeError, "unable to convert ldb message"); + } + } +} + /* Top-level ldb operations */ typedef struct ldb_context { %extend { @@ -604,53 +641,6 @@ typedef struct ldb_context { struct ldb_control **parse_control_strings(TALLOC_CTX *mem_ctx, const char * const*control_strings); ldb_error add(ldb_msg *add_msg); - ldb_error add(PyObject *py_msg) - { - ldb_error ret; - int dict_pos, msg_pos; - PyObject *key, *value; - ldb_msg_element *msgel; - ldb_msg *msg = NULL; - - if (PyDict_Check(py_msg)) { - msg = ldb_msg_new(NULL); - msg->elements = talloc_zero_array(msg, struct ldb_message_element, PyDict_Size(py_msg)); - msg_pos = dict_pos = 0; - while (PyDict_Next(py_msg, &dict_pos, &key, &value)) { - if (!strcmp(PyString_AsString(key), "dn")) { - if (ldb_dn_from_pyobject(msg, value, $self, &msg->dn) != 0) { - return LDB_ERR_OTHER; - } - } else { - msgel = ldb_msg_element_from_pyobject(msg->elements, value, 0, PyString_AsString(key)); - if (msgel == NULL) { - SWIG_exception(SWIG_TypeError, "unable to import element"); - return LDB_ERR_OTHER; - } - memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel)); - msg_pos++; - } - } - - if (msg->dn == NULL) { - SWIG_exception(SWIG_TypeError, "no dn set"); - return LDB_ERR_OTHER; - } - - msg->num_elements = msg_pos; - } else { - if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0) - return LDB_ERR_OTHER; - } - - ret = ldb_add($self, msg); - - talloc_free(msg); - return ret; - - fail: - return LDB_ERR_OTHER; - } ldb_error modify(ldb_msg *message); ldb_dn *get_config_basedn(); ldb_dn *get_root_basedn(); diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index 51022e5930..937cb7e47c 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -3113,52 +3113,6 @@ SWIGINTERN ldb_error ldb_search_ex(ldb *self,TALLOC_CTX *mem_ctx,ldb_dn *base,en *OUT = res; return ret; } -SWIGINTERN ldb_error ldb_add__SWIG_1(ldb *self,PyObject *py_msg){ - ldb_error ret; - int dict_pos, msg_pos; - PyObject *key, *value; - ldb_msg_element *msgel; - ldb_msg *msg = NULL; - - if (PyDict_Check(py_msg)) { - msg = ldb_msg_new(NULL); - msg->elements = talloc_zero_array(msg, struct ldb_message_element, PyDict_Size(py_msg)); - msg_pos = dict_pos = 0; - while (PyDict_Next(py_msg, &dict_pos, &key, &value)) { - if (!strcmp(PyString_AsString(key), "dn")) { - if (ldb_dn_from_pyobject(msg, value, self, &msg->dn) != 0) { - return 80; - } - } else { - msgel = ldb_msg_element_from_pyobject(msg->elements, value, 0, PyString_AsString(key)); - if (msgel == NULL) { - SWIG_exception(SWIG_TypeError, "unable to import element"); - return 80; - } - memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel)); - msg_pos++; - } - } - - if (msg->dn == NULL) { - SWIG_exception(SWIG_TypeError, "no dn set"); - return 80; - } - - msg->num_elements = msg_pos; - } else { - if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0) - return 80; - } - - ret = ldb_add(self, msg); - - talloc_free(msg); - return ret; - - fail: - return 80; - } SWIGINTERN PyObject *ldb_schema_format_value(ldb *self,char const *element_name,PyObject *val){ const struct ldb_schema_attribute *a; struct ldb_val old_val; @@ -4733,27 +4687,61 @@ fail: } -SWIGINTERN PyObject *_wrap_Ldb_add__SWIG_0(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) { +SWIGINTERN PyObject *_wrap_Ldb_add(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_msg *arg2 = (ldb_msg *) 0 ; ldb_error result; void *argp1 = 0 ; int res1 = 0 ; - void *argp2 = 0 ; - int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "add_msg", NULL + }; - if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_add",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_add" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); - res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_ldb_message, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_add" "', argument " "2"" of type '" "ldb_msg *""'"); + { + ldb_error ret; + int dict_pos, msg_pos; + PyObject *key, *value; + ldb_msg_element *msgel; + + if (PyDict_Check(obj1)) { + arg2 = ldb_msg_new(NULL); + arg2->elements = talloc_zero_array(arg2, struct ldb_message_element, PyDict_Size(obj1)); + msg_pos = dict_pos = 0; + while (PyDict_Next(obj1, &dict_pos, &key, &value)) { + if (!strcmp(PyString_AsString(key), "dn")) { + if (ldb_dn_from_pyobject(arg2, value, obj0, &arg2->dn) != 0) { + SWIG_exception(SWIG_TypeError, "unable to import dn object"); + } + } else { + msgel = ldb_msg_element_from_pyobject(arg2->elements, value, 0, PyString_AsString(key)); + if (msgel == NULL) { + SWIG_exception(SWIG_TypeError, "unable to import element"); + } + memcpy(&arg2->elements[msg_pos], msgel, sizeof(*msgel)); + msg_pos++; + } + } + + if (arg2->dn == NULL) { + SWIG_exception(SWIG_TypeError, "no dn set"); + } + + arg2->num_elements = msg_pos; + } else { + if (SWIG_ConvertPtr(obj1, (void **)&arg2, SWIGTYPE_p_ldb_message, 0) != 0) { + SWIG_exception(SWIG_TypeError, "unable to convert ldb message"); + } + } } - arg2 = (ldb_msg *)(argp2); if (arg1 == NULL) SWIG_exception(SWIG_ValueError, "ldb context must be non-NULL"); @@ -4772,64 +4760,6 @@ fail: } -SWIGINTERN PyObject *_wrap_Ldb_add__SWIG_1(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) { - PyObject *resultobj = 0; - ldb *arg1 = (ldb *) 0 ; - PyObject *arg2 = (PyObject *) 0 ; - ldb_error result; - void *argp1 = 0 ; - int res1 = 0 ; - - if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_add" "', argument " "1"" of type '" "ldb *""'"); - } - arg1 = (ldb *)(argp1); - arg2 = swig_obj[1]; - if (arg1 == NULL) - SWIG_exception(SWIG_ValueError, - "ldb context must be non-NULL"); - result = ldb_add__SWIG_1(arg1,arg2); - if (result != 0) { - PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", result, ldb_strerror(result))); - SWIG_fail; - } - resultobj = Py_None; - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_Ldb_add(PyObject *self, PyObject *args) { - int argc; - PyObject *argv[3]; - - if (!(argc = SWIG_Python_UnpackTuple(args,"Ldb_add",0,2,argv))) SWIG_fail; - --argc; - if (argc == 2) { - int _v = 0; - { - void *vptr = 0; - int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_ldb_message, 0); - _v = SWIG_CheckState(res); - } - if (!_v) goto check_1; - return _wrap_Ldb_add__SWIG_0(self, argc, argv); - } -check_1: - - if (argc == 2) { - return _wrap_Ldb_add__SWIG_1(self, argc, argv); - } - -fail: - SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'Ldb_add'.\n Possible C/C++ prototypes are:\n"" add(ldb *,ldb_msg *)\n"" add(ldb *,PyObject *)\n"); - return NULL; -} - - SWIGINTERN PyObject *_wrap_Ldb_modify(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; @@ -5729,7 +5659,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Ldb_delete", (PyCFunction) _wrap_Ldb_delete, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_rename", (PyCFunction) _wrap_Ldb_rename, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_parse_control_strings", (PyCFunction) _wrap_Ldb_parse_control_strings, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_add", _wrap_Ldb_add, METH_VARARGS, NULL}, + { (char *)"Ldb_add", (PyCFunction) _wrap_Ldb_add, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_modify", (PyCFunction) _wrap_Ldb_modify, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_get_config_basedn", (PyCFunction)_wrap_Ldb_get_config_basedn, METH_O, NULL}, { (char *)"Ldb_get_root_basedn", (PyCFunction)_wrap_Ldb_get_root_basedn, METH_O, NULL}, -- cgit From 830051b494ea52475e9349e6908ff8576a990051 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Mar 2008 21:18:12 +0100 Subject: Remove unused variable, fix (80, 'Other error') exceptions from ldb python bindings (This used to be commit 2303063cbd2e65580618124ef8ecf42867d2b952) --- source4/lib/ldb/ldb.i | 4 ++-- source4/lib/ldb/ldb_wrap.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 2c04662f25..da4c52f778 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -548,7 +548,6 @@ PyObject *PyExc_LdbError; }; %typemap(in,numinputs=1) ldb_msg *add_msg { - ldb_error ret; int dict_pos, msg_pos; PyObject *key, *value; ldb_msg_element *msgel; @@ -559,7 +558,8 @@ PyObject *PyExc_LdbError; msg_pos = dict_pos = 0; while (PyDict_Next($input, &dict_pos, &key, &value)) { if (!strcmp(PyString_AsString(key), "dn")) { - if (ldb_dn_from_pyobject($1, value, $self, &$1->dn) != 0) { + /* using argp0 (magic SWIG value) here is a hack */ + if (ldb_dn_from_pyobject($1, value, argp1, &$1->dn) != 0) { SWIG_exception(SWIG_TypeError, "unable to import dn object"); } } else { diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index 937cb7e47c..7886778b3a 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -4707,7 +4707,6 @@ SWIGINTERN PyObject *_wrap_Ldb_add(PyObject *SWIGUNUSEDPARM(self), PyObject *arg } arg1 = (ldb *)(argp1); { - ldb_error ret; int dict_pos, msg_pos; PyObject *key, *value; ldb_msg_element *msgel; @@ -4718,7 +4717,8 @@ SWIGINTERN PyObject *_wrap_Ldb_add(PyObject *SWIGUNUSEDPARM(self), PyObject *arg msg_pos = dict_pos = 0; while (PyDict_Next(obj1, &dict_pos, &key, &value)) { if (!strcmp(PyString_AsString(key), "dn")) { - if (ldb_dn_from_pyobject(arg2, value, obj0, &arg2->dn) != 0) { + /* using argp0 (magic SWIG value) here is a hack */ + if (ldb_dn_from_pyobject(arg2, value, argp1, &arg2->dn) != 0) { SWIG_exception(SWIG_TypeError, "unable to import dn object"); } } else { -- cgit From 85d53f7b603f7c15b007f8c3fdde1989f07a6eb2 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 2 Mar 2008 10:46:47 +0100 Subject: Some cleanups for the ldb doxygen docs. (This used to be commit 5972308add8b1078e190beab204c1ba4b3a25747) --- source4/lib/ldb/include/ldb.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source4') diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 2e54920c17..2e13a774b9 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -290,7 +290,7 @@ char *ldb_filter_from_tree(TALLOC_CTX *mem_ctx, struct ldb_parse_tree *tree); 2254 (Section 4). This function also escapes any non-printable characters. - \param ctx the memory context to allocate the return string in. + \param mem_ctx the memory context to allocate the return string in. \param val the (potentially) binary data to be encoded \return the encoded data as a null terminated string @@ -886,7 +886,7 @@ int ldb_search_default_callback(struct ldb_context *ldb, void *context, struct l \param attrs the search attributes for the query (pass NULL if none required) \param controls an array of controls \param context the callback function context - \param the callback function to handle the async replies + \param callback the callback function to handle the async replies \return result code (LDB_SUCCESS on success, or a failure code) */ @@ -911,7 +911,7 @@ int ldb_build_search_req(struct ldb_request **ret_req, \param message contains the entry to be added \param controls an array of controls \param context the callback function context - \param the callback function to handle the async replies + \param callback the callback function to handle the async replies \return result code (LDB_SUCCESS on success, or a failure code) */ @@ -933,7 +933,7 @@ int ldb_build_add_req(struct ldb_request **ret_req, \param message contains the entry to be modified \param controls an array of controls \param context the callback function context - \param the callback function to handle the async replies + \param callback the callback function to handle the async replies \return result code (LDB_SUCCESS on success, or a failure code) */ @@ -955,7 +955,7 @@ int ldb_build_mod_req(struct ldb_request **ret_req, \param dn the DN to be deleted \param controls an array of controls \param context the callback function context - \param the callback function to handle the async replies + \param callback the callback function to handle the async replies \return result code (LDB_SUCCESS on success, or a failure code) */ @@ -978,7 +978,7 @@ int ldb_build_del_req(struct ldb_request **ret_req, \param newdn the new DN \param controls an array of controls \param context the callback function context - \param the callback function to handle the async replies + \param callback the callback function to handle the async replies \return result code (LDB_SUCCESS on success, or a failure code) */ @@ -997,7 +997,7 @@ int ldb_build_rename_req(struct ldb_request **ret_req, \param req the request struct where to add the control \param oid the object identifier of the control as string - \param ciritical whether the control should be critical or not + \param critical whether the control should be critical or not \param data a talloc pointer to the control specific data \return result code (LDB_SUCCESS on success, or a failure code) @@ -1137,7 +1137,7 @@ int ldb_extended_default_callback(struct ldb_context *ldb, void *context, struct it needs to be NULL or a valid talloc pointer! talloc_get_type() will be used on it \param controls an array of controls \param context the callback function context - \param the callback function to handle the async replies + \param callback the callback function to handle the async replies \return result code (LDB_SUCCESS on success, or a failure code) */ @@ -1226,6 +1226,7 @@ int ldb_valid_attr_name(const char *s); /* ldif manipulation functions */ + /** Write an LDIF message @@ -1418,8 +1419,8 @@ bool ldb_dn_is_null(struct ldb_dn *dn); This function compares to attribute names. Note that this is a case-insensitive comparison. - \param attr1 the first attribute name to compare - \param attr2 the second attribute name to compare + \param a the first attribute name to compare + \param b the second attribute name to compare \return 0 if the attribute names are the same, or only differ in case; non-zero if there are any differences @@ -1562,6 +1563,7 @@ int ldb_msg_check_string_attribute(const struct ldb_message *msg, This function performs basic sanity / integrity checks on an ldb_message. + \param ldb context in which to perform the checks \param msg the message to check \return LDB_SUCCESS if the message is OK, or a non-zero error code -- cgit From 2db6aec31fe2b106e394dd7027064de4e6951b36 Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Sun, 2 Mar 2008 07:57:13 -0600 Subject: Fix blackbox.kinit test by issuing new certificates good for 25 years. (This used to be commit 4f40c5940b4aa4343152cf367566d4d26765e234) --- source4/selftest/target/Samba4.pm | 83 +++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 34 deletions(-) (limited to 'source4') diff --git a/source4/selftest/target/Samba4.pm b/source4/selftest/target/Samba4.pm index e0be8048a0..48fda17599 100644 --- a/source4/selftest/target/Samba4.pm +++ b/source4/selftest/target/Samba4.pm @@ -389,25 +389,26 @@ yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG EOF #generated with - #hxtool issue-certificate --self-signed --issue-ca --ca-private-key=FILE:$KEYFILE \ - # --subject="CN=CA,$BASEDN" --certificate="FILE:$CAFILE" + # hxtool issue-certificate --self-signed --issue-ca \ + # --ca-private-key="FILE:$KEYFILE" \ + # --subject="CN=CA,DC=samba,DC=example,DC=com" \ + # --certificate="FILE:$CAFILE" --lifetime="25 years" open(CAFILE, ">$cafile"); print CAFILE <$kdccertfile"); print KDCCERTFILE <$admincertfile"); print ADMINCERTFILE < Date: Mon, 3 Mar 2008 11:08:59 +1100 Subject: Fix member server provision Can't add "member server" because the script aborts with null reference when no match on serverrole. This is fixed by checking for the keyword "member server". (This used to be commit 62536750ae06248a49c6b56c86d01b0062bb54f0) --- source4/scripting/python/samba/provision.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4') diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 55935b0037..e9aded205a 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -830,7 +830,7 @@ def provision(lp, setup_dir, message, paths, session_info, message("Setting up smb.conf") if serverrole == "domain controller": smbconfsuffix = "dc" - elif serverrole == "member": + elif serverrole == "member server": smbconfsuffix = "member" setup_file(setup_path("provision.smb.conf.%s" % smbconfsuffix), paths.smbconf, { -- cgit From 4d4a898742a0439d3f60c84194b02901412f4679 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 3 Mar 2008 13:03:19 +1100 Subject: Fix failure to re-provision. Somewhere in the conversion from ejs we lost calling the 'delete partitions' code. However, we have to be careful not to wipe partitions when we are the second client connecting to an LDAP server. Andrew Bartlett (This used to be commit 272eb765b81e3eab216a07249334f9b7d20e530b) --- source4/samba4-knownfail | 1 - source4/scripting/python/samba/__init__.py | 11 +++++++++-- source4/scripting/python/samba/provision.py | 19 ++++++++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'source4') diff --git a/source4/samba4-knownfail b/source4/samba4-knownfail index e6a4ea1517..66565ca6fc 100644 --- a/source4/samba4-knownfail +++ b/source4/samba4-knownfail @@ -33,5 +33,4 @@ rpc.netlogon.*.GetTrustPasswords base.charset.*.Testing partial surrogate .*net.api.delshare.* # DelShare isn't implemented yet rap.*netservergetinfo -samba4.blackbox.provision.py.reprovision # Fails with entry already exists local.torture.provision diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index b041165800..8d5f4250c9 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -127,7 +127,7 @@ class Ldb(ldb.Ldb): try: self.delete(msg.dn) except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _): - # Ignor eno such object errors + # Ignore no such object errors pass res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", ["distinguishedName"]) @@ -151,7 +151,14 @@ class Ldb(ldb.Ldb): previous_remaining = current_remaining current_remaining = len(res2) for msg in res2: - self.delete(msg.dn) + try: + self.delete(msg.dn) + # Ignore no such object errors + except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _): + pass + # Ignore not allowed on non leaf errors + except ldb.LdbError, (LDB_ERR_NOT_ALLOWED_ON_NON_LEAF, _): + pass def load_ldif_file_add(self, ldif_path): """Load a LDIF file. diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index e9aded205a..ea2feb981b 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -279,8 +279,6 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, Alternatively, provision() may call this, and then populate the database. - :param erase: Remove the existing data present in the database. - :note: This will wipe the Sam Database! :note: This function always removes the local SAM LDB file. The erase @@ -289,10 +287,15 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, """ assert session_info is not None - if os.path.exists(samdb_path): + samdb = SamDB(samdb_path, session_info=session_info, + credentials=credentials, lp=lp) + + # Wipes the database + try: + samdb.erase() + except: os.unlink(samdb_path) - # Also wipes the database samdb = SamDB(samdb_path, session_info=session_info, credentials=credentials, lp=lp) @@ -547,7 +550,7 @@ def setup_self_join(samdb, configdn, schemadn, domaindn, def setup_samdb(path, setup_path, session_info, credentials, lp, schemadn, configdn, domaindn, dnsdomain, realm, - netbiosname, message, hostname, rootdn, erase, + netbiosname, message, hostname, rootdn, domainsid, aci, domainguid, policyguid, domainname, fill, adminpass, krbtgtpass, machinepass, hostguid, invocationid, dnspass, @@ -560,6 +563,8 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, assert serverrole in ("domain controller", "member server") + erase = (fill != FILL_DRS) + # Also wipes the database setup_samdb_partitions(path, setup_path, schemadn=schemadn, configdn=configdn, domaindn=domaindn, message=message, lp=lp, @@ -726,7 +731,7 @@ def provision(lp, setup_dir, message, paths, session_info, hostguid=None, adminpass=None, krbtgtpass=None, domainguid=None, policyguid=None, invocationid=None, machinepass=None, dnspass=None, root=None, nobody=None, nogroup=None, users=None, - wheel=None, backup=None, aci=None, serverrole=None, erase=False, + wheel=None, backup=None, aci=None, serverrole=None, ldap_backend=None, ldap_backend_type=None, sitename=DEFAULTSITE): """Provision samba4 @@ -873,7 +878,7 @@ def provision(lp, setup_dir, message, paths, session_info, configdn=configdn, domaindn=domaindn, dnsdomain=dnsdomain, netbiosname=netbiosname, realm=realm, message=message, hostname=hostname, - rootdn=rootdn, erase=erase, domainsid=domainsid, + rootdn=rootdn, domainsid=domainsid, aci=aci, domainguid=domainguid, policyguid=policyguid, domainname=domain, fill=samdb_fill, adminpass=adminpass, krbtgtpass=krbtgtpass, -- cgit