1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

pylibsmb: Move set_acl() to python

The previous code was not available in threaded environments

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2020-11-12 09:26:10 +01:00 committed by Jeremy Allison
parent 3b81cc900f
commit 42be033b0b
2 changed files with 14 additions and 51 deletions

View File

@ -49,3 +49,17 @@ class Conn(LibsmbCConn):
finally:
self.close(fnum)
return sd
def set_acl(self,
filename,
sd,
sinfo = SECINFO_DEFAULT_FLAGS):
"""Set security descriptor for file."""
fnum = self.create(
Name=filename,
DesiredAccess=security.SEC_FLAG_MAXIMUM_ALLOWED,
ShareAccess=(FILE_SHARE_READ|FILE_SHARE_WRITE))
try:
self.set_sd(fnum, sd, sinfo)
finally:
self.close(fnum)

View File

@ -1360,54 +1360,6 @@ static PyObject *py_smb_get_sd(struct py_cli_state *self, PyObject *args)
"samba.dcerpc.security", "descriptor", sd, sd);
}
/*
* Set ACL on file/directory using given security descriptor object
*/
static PyObject *py_smb_setacl(struct py_cli_state *self, PyObject *args)
{
NTSTATUS status;
char *filename = NULL;
PyObject *py_sd = NULL;
struct security_descriptor *sd = NULL;
unsigned int sinfo = SECINFO_DEFAULT_FLAGS;
uint16_t fnum;
/* there's no async version of cli_set_security_descriptor() */
if (self->thread_state != NULL) {
PyErr_SetString(PyExc_RuntimeError,
"set_acl() is not supported on "
"a multi_threaded connection");
return NULL;
}
if (!PyArg_ParseTuple(args, "sO|I:set_acl", &filename, &py_sd,
&sinfo)) {
return NULL;
}
sd = pytalloc_get_type(py_sd, struct security_descriptor);
if (!sd) {
PyErr_Format(PyExc_TypeError,
"Expected dcerpc.security.descriptor as argument, got %s",
pytalloc_get_name(py_sd));
return NULL;
}
status = cli_ntcreate(self->cli, filename, 0,
SEC_FLAG_MAXIMUM_ALLOWED, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN, 0x0, 0x0, &fnum, NULL);
PyErr_NTSTATUS_IS_ERR_RAISE(status);
status = cli_set_security_descriptor(self->cli, fnum, sinfo, sd);
PyErr_NTSTATUS_IS_ERR_RAISE(status);
status = cli_close(self->cli, fnum);
PyErr_NTSTATUS_IS_ERR_RAISE(status);
Py_RETURN_NONE;
}
static PyObject *py_smb_set_sd(struct py_cli_state *self, PyObject *args)
{
PyObject *py_sd = NULL;
@ -1496,9 +1448,6 @@ static PyMethodDef py_cli_state_methods[] = {
{ "get_sd", (PyCFunction)py_smb_get_sd, METH_VARARGS,
"get_sd(fnum[, security_info=0]) -> security_descriptor object\n\n"
"\t\tGet security descriptor for opened file." },
{ "set_acl", (PyCFunction)py_smb_setacl, METH_VARARGS,
"set_acl(path, security_descriptor[, security_info=0]) -> None\n\n"
"\t\tSet security descriptor for file." },
{ "set_sd", (PyCFunction)py_smb_set_sd, METH_VARARGS,
"set_sd(fnum, security_descriptor[, security_info=0]) -> None\n\n"
"\t\tSet security descriptor for opened file." },