diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/scripting/python/samba/__init__.py | 6 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/__init__.py | 17 | ||||
-rw-r--r-- | source4/torture/rpc/eventlog.c | 5 | ||||
-rw-r--r-- | source4/torture/rpc/spoolss_win.c | 18 | ||||
-rw-r--r-- | source4/torture/rpc/svcctl.c | 44 |
5 files changed, 61 insertions, 29 deletions
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index c5827b96e0..3ecb758595 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -233,10 +233,12 @@ def check_all_substituted(text): def valid_netbios_name(name): """Check whether a name is valid as a NetBIOS name. """ - # FIXME: There are probably more constraints here. - # crh has a paragraph on this in his book (1.4.1.1) + # See crh's book (1.4.1.1) if len(name) > 15: return False + for x in name: + if not x.isalnum() and not x in " !#$%&'()-.@^_{}~": + return False return True version = glue.version diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py index b342b93c49..3f8ee8da32 100644 --- a/source4/scripting/python/samba/tests/__init__.py +++ b/source4/scripting/python/samba/tests/__init__.py @@ -26,6 +26,7 @@ import tempfile import unittest class LdbTestCase(unittest.TestCase): + """Trivial test case for running tests against a LDB.""" def setUp(self): self.filename = os.tempnam() @@ -41,6 +42,7 @@ class LdbTestCase(unittest.TestCase): class TestCaseInTempDir(unittest.TestCase): + def setUp(self): super(TestCaseInTempDir, self).setUp() self.tempdir = tempfile.mkdtemp() @@ -52,6 +54,7 @@ class TestCaseInTempDir(unittest.TestCase): class SubstituteVarTestCase(unittest.TestCase): + def test_empty(self): self.assertEquals("", samba.substitute_var("", {})) @@ -75,6 +78,7 @@ class SubstituteVarTestCase(unittest.TestCase): class LdbExtensionTests(TestCaseInTempDir): + def test_searchone(self): path = self.tempdir + "/searchone.ldb" l = samba.Ldb(path) @@ -90,9 +94,22 @@ cmdline_loadparm = None cmdline_credentials = None class RpcInterfaceTestCase(unittest.TestCase): + def get_loadparm(self): assert cmdline_loadparm is not None return cmdline_loadparm def get_credentials(self): return cmdline_credentials + + +class ValidNetbiosNameTests(unittest.TestCase): + + def test_valid(self): + self.assertTrue(valid_netbios_name("FOO")) + + def test_too_long(self): + self.assertFalse(valid_netbios_name("FOO"*10)) + + def test_invalid_characters(self): + self.assertFalse(valid_netbios_name("()BLA")) diff --git a/source4/torture/rpc/eventlog.c b/source4/torture/rpc/eventlog.c index 10c4886259..865b4e2217 100644 --- a/source4/torture/rpc/eventlog.c +++ b/source4/torture/rpc/eventlog.c @@ -203,7 +203,6 @@ static bool test_ReadEventLog(struct torture_context *tctx, static bool test_ReportEventLog(struct torture_context *tctx, struct dcerpc_pipe *p) { - NTSTATUS status; struct eventlog_ReportEventW r; struct eventlog_CloseEventLog cr; struct policy_handle handle; @@ -237,7 +236,9 @@ static bool test_ReportEventLog(struct torture_context *tctx, r.out.record_number = &record_number; r.out.time_written = &time_written; - status = dcerpc_eventlog_ReportEventW(p, tctx, &r); + torture_assert_ntstatus_ok(tctx, + dcerpc_eventlog_ReportEventW(p, tctx, &r), + "ReportEventW failed"); torture_assert_ntstatus_ok(tctx, r.out.result, "ReportEventW failed"); diff --git a/source4/torture/rpc/spoolss_win.c b/source4/torture/rpc/spoolss_win.c index c50cbfbaee..42b6929557 100644 --- a/source4/torture/rpc/spoolss_win.c +++ b/source4/torture/rpc/spoolss_win.c @@ -34,6 +34,8 @@ struct test_spoolss_win_context { /* EnumPrinterKeys */ const char **printer_keys; + + bool printer_has_driver; }; /* This is a convenience function for all OpenPrinterEx calls */ @@ -256,6 +258,12 @@ static bool test_GetPrinter(struct torture_context *tctx, torture_assert_werr_ok(tctx, gp.out.result, "GetPrinter failed"); ctx->current_info = gp.out.info; + + if (level == 2 && gp.out.info) { + ctx->printer_has_driver = gp.out.info->info2.drivername && + strlen(gp.out.info->info2.drivername); + } + return true; } @@ -289,6 +297,7 @@ static bool test_EnumJobs(struct torture_context *tctx, static bool test_GetPrinterDriver2(struct torture_context *tctx, struct dcerpc_pipe *p, + struct test_spoolss_win_context *ctx, struct policy_handle *handle) { NTSTATUS status; @@ -313,8 +322,11 @@ static bool test_GetPrinterDriver2(struct torture_context *tctx, status = dcerpc_spoolss_GetPrinterDriver2(p, tctx, &gpd2); torture_assert_ntstatus_ok(tctx, status, "GetPrinterDriver2 failed"); - torture_assert_werr_ok(tctx, gpd2.out.result, - "GetPrinterDriver2 failed."); + + if (ctx->printer_has_driver) { + torture_assert_werr_ok(tctx, gpd2.out.result, + "GetPrinterDriver2 failed."); + } return true; } @@ -527,7 +539,7 @@ static bool test_WinXP(struct torture_context *tctx, struct dcerpc_pipe *p) ret &= test_ClosePrinter(tctx, p, &handle04); ret &= test_EnumPrinters(tctx, p, ctx, 1556); - ret &= test_GetPrinterDriver2(tctx, p, &handle03); + ret &= test_GetPrinterDriver2(tctx, p, ctx, &handle03); ret &= test_EnumForms(tctx, p, &handle03, 0); ret &= test_EnumPrinterKey(tctx, p, &handle03, "", ctx); diff --git a/source4/torture/rpc/svcctl.c b/source4/torture/rpc/svcctl.c index a4b9e6bed1..375df9f647 100644 --- a/source4/torture/rpc/svcctl.c +++ b/source4/torture/rpc/svcctl.c @@ -82,8 +82,8 @@ static bool test_QueryServiceStatusEx(struct torture_context *tctx, struct dcerp uint32_t info_level = SVC_STATUS_PROCESS_INFO; uint8_t *buffer; - uint32_t buf_size = 0; - uint32_t bytes_needed = 0; + uint32_t offered = 0; + uint32_t needed = 0; if (!test_OpenSCManager(p, tctx, &h)) return false; @@ -95,16 +95,16 @@ static bool test_QueryServiceStatusEx(struct torture_context *tctx, struct dcerp r.in.handle = &s; r.in.info_level = info_level; - r.in.buf_size = buf_size; + r.in.offered = offered; r.out.buffer = buffer; - r.out.bytes_needed = &bytes_needed; + r.out.needed = &needed; status = dcerpc_svcctl_QueryServiceStatusEx(p, tctx, &r); torture_assert_ntstatus_ok(tctx, status, "QueryServiceStatusEx failed!"); if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { - r.in.buf_size = bytes_needed; - buffer = talloc_array(tctx, uint8_t, bytes_needed); + r.in.offered = needed; + buffer = talloc_array(tctx, uint8_t, needed); r.out.buffer = buffer; status = dcerpc_svcctl_QueryServiceStatusEx(p, tctx, &r); @@ -129,8 +129,8 @@ static bool test_QueryServiceConfig2W(struct torture_context *tctx, struct dcerp uint32_t info_level = SERVICE_CONFIG_DESCRIPTION; uint8_t *buffer; - uint32_t buf_size = 0; - uint32_t bytes_needed = 0; + uint32_t offered = 0; + uint32_t needed = 0; if (!test_OpenSCManager(p, tctx, &h)) return false; @@ -142,16 +142,16 @@ static bool test_QueryServiceConfig2W(struct torture_context *tctx, struct dcerp r.in.handle = &s; r.in.info_level = info_level; - r.in.buf_size = buf_size; + r.in.offered = offered; r.out.buffer = buffer; - r.out.bytes_needed = &bytes_needed; + r.out.needed = &needed; status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r); torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfig2W failed!"); if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { - r.in.buf_size = bytes_needed; - buffer = talloc_array(tctx, uint8_t, bytes_needed); + r.in.offered = needed; + buffer = talloc_array(tctx, uint8_t, needed); r.out.buffer = buffer; status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r); @@ -160,16 +160,16 @@ static bool test_QueryServiceConfig2W(struct torture_context *tctx, struct dcerp } r.in.info_level = SERVICE_CONFIG_FAILURE_ACTIONS; - r.in.buf_size = buf_size; + r.in.offered = offered; r.out.buffer = buffer; - r.out.bytes_needed = &bytes_needed; + r.out.needed = &needed; status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r); torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfig2W failed!"); if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) { - r.in.buf_size = bytes_needed; - buffer = talloc_array(tctx, uint8_t, bytes_needed); + r.in.offered = needed; + buffer = talloc_array(tctx, uint8_t, needed); r.out.buffer = buffer; status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r); @@ -194,7 +194,7 @@ static bool test_EnumServicesStatus(struct torture_context *tctx, struct dcerpc_ NTSTATUS status; uint32_t resume_handle = 0; struct ENUM_SERVICE_STATUSW *service = NULL; - uint32_t bytes_needed = 0; + uint32_t needed = 0; uint32_t services_returned = 0; if (!test_OpenSCManager(p, tctx, &h)) @@ -203,20 +203,20 @@ static bool test_EnumServicesStatus(struct torture_context *tctx, struct dcerpc_ r.in.handle = &h; r.in.type = SERVICE_TYPE_WIN32; r.in.state = SERVICE_STATE_ALL; - r.in.buf_size = 0; + r.in.offered = 0; r.in.resume_handle = &resume_handle; r.out.service = NULL; r.out.resume_handle = &resume_handle; r.out.services_returned = &services_returned; - r.out.bytes_needed = &bytes_needed; + r.out.needed = &needed; status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r); torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!"); if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) { - r.in.buf_size = bytes_needed; - r.out.service = talloc_array(tctx, uint8_t, bytes_needed); + r.in.offered = needed; + r.out.service = talloc_array(tctx, uint8_t, needed); status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r); @@ -230,7 +230,7 @@ static bool test_EnumServicesStatus(struct torture_context *tctx, struct dcerpc_ DATA_BLOB blob; struct ndr_pull *ndr; - blob.length = r.in.buf_size; + blob.length = r.in.offered; blob.data = talloc_steal(tctx, r.out.service); ndr = ndr_pull_init_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx)); |