class Smb3UnixTests(samba.tests.libsmb.LibsmbTests):
- def enable_smb3unix(self):
- with open(self.global_inject, 'w') as f:
- f.write("smb3 unix extensions = yes\n")
-
- def disable_smb3unix(self):
- with open(self.global_inject, 'w') as f:
- f.truncate()
-
def test_negotiate_context_posix(self):
- try:
- self.enable_smb3unix()
+ c = libsmb.Conn(
+ self.server_ip,
+ "tmp",
+ self.lp,
+ self.creds,
+ posix=True)
+ self.assertTrue(c.have_posix())
+ def test_negotiate_context_posix_invalid_length(self):
+ with self.assertRaises(NTSTATUSError) as cm:
c = libsmb.Conn(
self.server_ip,
"tmp",
self.lp,
self.creds,
- posix=True)
- self.assertTrue(c.have_posix())
+ negotiate_contexts=[(0x100, b'01234')])
- finally:
- self.disable_smb3unix()
+ e = cm.exception
+ self.assertEqual(e.args[0], ntstatus.NT_STATUS_INVALID_PARAMETER)
- def test_negotiate_context_noposix(self):
+ def test_negotiate_context_posix_invalid_blob(self):
c = libsmb.Conn(
- self.server_ip,
- "tmp",
- self.lp,
- self.creds,
- posix=True)
+ self.server_ip,
+ "tmp",
+ self.lp,
+ self.creds,
+ negotiate_contexts=[(0x100, b'0123456789012345')])
self.assertFalse(c.have_posix())
- def test_negotiate_context_posix_invalid_length(self):
- try:
- self.enable_smb3unix()
-
- with self.assertRaises(NTSTATUSError) as cm:
- c = libsmb.Conn(
- self.server_ip,
- "tmp",
- self.lp,
- self.creds,
- negotiate_contexts=[(0x100, b'01234')])
-
- e = cm.exception
- self.assertEqual(e.args[0], ntstatus.NT_STATUS_INVALID_PARAMETER)
-
- finally:
- self.disable_smb3unix()
-
- def test_negotiate_context_posix_invalid_blob(self):
- try:
- self.enable_smb3unix()
-
- c = libsmb.Conn(
- self.server_ip,
- "tmp",
- self.lp,
- self.creds,
- negotiate_contexts=[(0x100, b'0123456789012345')])
- self.assertFalse(c.have_posix())
-
- finally:
- self.disable_smb3unix()
-
def test_posix_create_context(self):
- try:
- self.enable_smb3unix()
-
- c = libsmb.Conn(
- self.server_ip,
- "tmp",
- self.lp,
- self.creds,
- posix=True)
- self.assertTrue(c.have_posix())
-
- cc_in=[(libsmb.SMB2_CREATE_TAG_POSIX,b'0000')]
- fnum,_,cc_out = c.create_ex("",CreateContexts=cc_in)
- self.assertEqual(cc_in[0][0],cc_out[0][0])
-
- c.close(fnum)
-
- finally:
- self.disable_smb3unix()
-
- def test_posix_create_context_noposix(self):
c = libsmb.Conn(
self.server_ip,
"tmp",
self.lp,
self.creds,
posix=True)
- self.assertFalse(c.have_posix())
+ self.assertTrue(c.have_posix())
cc_in=[(libsmb.SMB2_CREATE_TAG_POSIX,b'0000')]
fnum,_,cc_out = c.create_ex("",CreateContexts=cc_in)
- self.assertEqual(len(cc_out), 0)
+ self.assertEqual(cc_in[0][0],cc_out[0][0])
c.close(fnum)
def test_posix_create_invalid_context_length(self):
- try:
- self.enable_smb3unix()
-
- c = libsmb.Conn(
- self.server_ip,
- "tmp",
- self.lp,
- self.creds,
- posix=True)
- self.assertTrue(c.have_posix())
-
- cc_in=[(libsmb.SMB2_CREATE_TAG_POSIX,b'00000')]
+ c = libsmb.Conn(
+ self.server_ip,
+ "tmp",
+ self.lp,
+ self.creds,
+ posix=True)
+ self.assertTrue(c.have_posix())
- with self.assertRaises(NTSTATUSError) as cm:
- fnum,_,cc_out = c.create_ex("",CreateContexts=cc_in)
+ cc_in=[(libsmb.SMB2_CREATE_TAG_POSIX,b'00000')]
- e = cm.exception
- self.assertEqual(e.args[0], ntstatus.NT_STATUS_INVALID_PARAMETER)
+ with self.assertRaises(NTSTATUSError) as cm:
+ fnum,_,cc_out = c.create_ex("",CreateContexts=cc_in)
- finally:
- self.disable_smb3unix()
+ e = cm.exception
+ self.assertEqual(e.args[0], ntstatus.NT_STATUS_INVALID_PARAMETER)
def delete_test_file(self, c, fname, mode=0):
f,_,cc_out = c.create_ex(fname,
def test_posix_query_dir(self):
test_files = []
try:
- self.enable_smb3unix()
-
c = libsmb.Conn(
self.server_ip,
"smb3_posix_share",
for fname in test_files:
self.delete_test_file(c, fname)
- self.disable_smb3unix()
-
def test_posix_reserved_char(self):
- try:
- self.enable_smb3unix()
-
- c = libsmb.Conn(
- self.server_ip,
- "smb3_posix_share",
- self.lp,
- self.creds,
- posix=True)
- self.assertTrue(c.have_posix())
-
- test_files = ['a ', 'a ', '. ', '. ', 'a.',
- '.a', ' \\ ', '>', '<' '?']
-
- for fname in test_files:
- try:
- f,_,cc_out = c.create_ex('\\%s' % fname,
- CreateDisposition=libsmb.FILE_CREATE,
- DesiredAccess=security.SEC_STD_DELETE,
- CreateContexts=[posix_context(0o744)])
- except NTSTATUSError as e:
- self.fail(e)
- c.delete_on_close(f, True)
- c.close(f)
-
- finally:
- self.disable_smb3unix()
-
- def test_posix_delete_on_close(self):
- try:
- self.enable_smb3unix()
+ c = libsmb.Conn(
+ self.server_ip,
+ "smb3_posix_share",
+ self.lp,
+ self.creds,
+ posix=True)
+ self.assertTrue(c.have_posix())
- c = libsmb.Conn(
- self.server_ip,
- "smb3_posix_share",
- self.lp,
- self.creds,
- posix=True)
- self.assertTrue(c.have_posix())
+ test_files = ['a ', 'a ', '. ', '. ', 'a.',
+ '.a', ' \\ ', '>', '<' '?']
- f,_,cc_out = c.create_ex('\\TESTING999',
- DesiredAccess=security.SEC_STD_ALL,
- CreateDisposition=libsmb.FILE_CREATE,
- CreateContexts=[posix_context(0o744)])
+ for fname in test_files:
+ try:
+ f,_,cc_out = c.create_ex('\\%s' % fname,
+ CreateDisposition=libsmb.FILE_CREATE,
+ DesiredAccess=security.SEC_STD_DELETE,
+ CreateContexts=[posix_context(0o744)])
+ except NTSTATUSError as e:
+ self.fail(e)
c.delete_on_close(f, True)
c.close(f)
- finally:
- self.disable_smb3unix()
+ def test_posix_delete_on_close(self):
+ c = libsmb.Conn(
+ self.server_ip,
+ "smb3_posix_share",
+ self.lp,
+ self.creds,
+ posix=True)
+ self.assertTrue(c.have_posix())
+
+ f,_,cc_out = c.create_ex('\\TESTING999',
+ DesiredAccess=security.SEC_STD_ALL,
+ CreateDisposition=libsmb.FILE_CREATE,
+ CreateContexts=[posix_context(0o744)])
+ c.delete_on_close(f, True)
+ c.close(f)
def test_posix_case_sensitive(self):
try:
- self.enable_smb3unix()
-
c = libsmb.Conn(
self.server_ip,
"smb3_posix_share",
finally:
self.delete_test_file(c, '\\xx')
- self.disable_smb3unix()
-
def test_posix_perm_files(self):
test_files = {}
try:
- self.enable_smb3unix()
-
c = libsmb.Conn(
self.server_ip,
"smb3_posix_share",
for fname in test_files.keys():
self.delete_test_file(c, '\\%s' % fname)
- self.disable_smb3unix()
-
def test_share_root_null_sids_fid(self):
- try:
- self.enable_smb3unix()
-
- c = libsmb.Conn(
- self.server_ip,
- "smb3_posix_share",
- self.lp,
- self.creds,
- posix=True)
- self.assertTrue(c.have_posix())
-
- res = c.list("", info_level=100, posix=True)
- found_files = {get_string(i['name']): i for i in res}
- dotdot = found_files['..']
- self.assertEqual('S-1-0-0', dotdot['owner_sid'],
- 'The owner sid for .. was not NULL')
- self.assertEqual('S-1-0-0', dotdot['group_sid'],
- 'The group sid for .. was not NULL')
- self.assertEqual(0, dotdot['ino'], 'The ino for .. was not 0')
- self.assertEqual(0, dotdot['dev'], 'The dev for .. was not 0')
- finally:
- self.disable_smb3unix()
+ c = libsmb.Conn(
+ self.server_ip,
+ "smb3_posix_share",
+ self.lp,
+ self.creds,
+ posix=True)
+ self.assertTrue(c.have_posix())
+
+ res = c.list("", info_level=100, posix=True)
+ found_files = {get_string(i['name']): i for i in res}
+ dotdot = found_files['..']
+ self.assertEqual('S-1-0-0', dotdot['owner_sid'],
+ 'The owner sid for .. was not NULL')
+ self.assertEqual('S-1-0-0', dotdot['group_sid'],
+ 'The group sid for .. was not NULL')
+ self.assertEqual(0, dotdot['ino'], 'The ino for .. was not 0')
+ self.assertEqual(0, dotdot['dev'], 'The dev for .. was not 0')
return smbd_smb2_request_error(req, status);
}
- if (lp_smb3_unix_extensions()) {
- in_posix = smb2_negotiate_context_find(&in_c,
- SMB2_POSIX_EXTENSIONS_AVAILABLE);
-
- if (in_posix != NULL) {
- const uint8_t *inbuf = in_posix->data.data;
- size_t inbuflen = in_posix->data.length;
- bool posix_found = false;
- /*
- * For now the server only supports one variant.
- * Check it's the right one.
- */
- if ((inbuflen % 16) != 0) {
- return smbd_smb2_request_error(req,
- NT_STATUS_INVALID_PARAMETER);
- }
- SMB_ASSERT(strlen(SMB2_CREATE_TAG_POSIX) == 16);
- for (ofs=0; ofs<inbuflen; ofs+=16) {
- if (memcmp(inbuf+ofs,
- SMB2_CREATE_TAG_POSIX,
- 16) == 0) {
- posix_found = true;
- break;
- }
- }
- if (posix_found) {
- DBG_DEBUG("Client requested SMB2 unix "
- "extensions\n");
- } else {
- DBG_DEBUG("Client requested unknown "
- "SMB2 unix extensions:\n");
- dump_data(10, inbuf, inbuflen);
- in_posix = NULL;
+ in_posix = smb2_negotiate_context_find(
+ &in_c,
+ SMB2_POSIX_EXTENSIONS_AVAILABLE);
+
+ if (in_posix != NULL) {
+ const uint8_t *inbuf = in_posix->data.data;
+ size_t inbuflen = in_posix->data.length;
+ bool posix_found = false;
+ /*
+ * For now the server only supports one variant.
+ * Check it's the right one.
+ */
+ if ((inbuflen % 16) != 0) {
+ return smbd_smb2_request_error(
+ req,
+ NT_STATUS_INVALID_PARAMETER);
+ }
+ SMB_ASSERT(strlen(SMB2_CREATE_TAG_POSIX) == 16);
+ for (ofs = 0; ofs < inbuflen; ofs += 16) {
+ if (memcmp(inbuf + ofs,
+ SMB2_CREATE_TAG_POSIX,
+ 16) == 0) {
+ posix_found = true;
+ break;
}
}
+ if (posix_found) {
+ DBG_DEBUG("Client requested SMB2 unix "
+ "extensions\n");
+ } else {
+ DBG_DEBUG("Client requested unknown "
+ "SMB2 unix extensions:\n");
+ dump_data(10, inbuf, inbuflen);
+ in_posix = NULL;
+ }
}
}