mirror of
https://github.com/samba-team/samba.git
synced 2025-06-12 23:17:06 +03:00
Implemented routines to convert from a Python dictionary to a SEC_DESC
structure. Cleaned up debugging stuff. (This used to be commit f3f4f0d3978f90c589894234bbcc63728940a246)
This commit is contained in:
parent
9a1df3d668
commit
f530f9c25d
@ -50,12 +50,7 @@ BOOL py_to_SID(DOM_SID *sid, PyObject *obj)
|
|||||||
if (!PyString_Check(obj))
|
if (!PyString_Check(obj))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
result = string_to_sid(sid, PyString_AsString(obj));
|
return string_to_sid(sid, PyString_AsString(obj));
|
||||||
|
|
||||||
if (result)
|
|
||||||
DEBUG(0, ("py: got sid %s\n", PyString_AsString(obj)));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace)
|
BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace)
|
||||||
@ -96,16 +91,12 @@ BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict)
|
|||||||
|
|
||||||
ace_type = PyInt_AsLong(obj);
|
ace_type = PyInt_AsLong(obj);
|
||||||
|
|
||||||
DEBUG(0, ("py: got ace_type %d\n", ace_type));
|
|
||||||
|
|
||||||
if (!(obj = PyDict_GetItemString(dict, "flags")) ||
|
if (!(obj = PyDict_GetItemString(dict, "flags")) ||
|
||||||
!PyInt_Check(obj))
|
!PyInt_Check(obj))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
ace_flags = PyInt_AsLong(obj);
|
ace_flags = PyInt_AsLong(obj);
|
||||||
|
|
||||||
DEBUG(0, ("py: got ace_flags %d\n", ace_flags));
|
|
||||||
|
|
||||||
if (!(obj = PyDict_GetItemString(dict, "trustee")) ||
|
if (!(obj = PyDict_GetItemString(dict, "trustee")) ||
|
||||||
!PyString_Check(obj))
|
!PyString_Check(obj))
|
||||||
return False;
|
return False;
|
||||||
@ -113,18 +104,18 @@ BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict)
|
|||||||
if (!py_to_SID(&trustee, obj))
|
if (!py_to_SID(&trustee, obj))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
DEBUG(0, ("py: got trustee\n"));
|
|
||||||
|
|
||||||
if (!(obj = PyDict_GetItemString(dict, "mask")) ||
|
if (!(obj = PyDict_GetItemString(dict, "mask")) ||
|
||||||
!PyInt_Check(obj))
|
!PyInt_Check(obj))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
sec_access.mask = PyInt_AsLong(obj);
|
sec_access.mask = PyInt_AsLong(obj);
|
||||||
|
|
||||||
DEBUG(0, ("py: got mask 0x%08x\n", sec_access.mask));
|
|
||||||
|
|
||||||
init_sec_ace(ace, &trustee, ace_type, sec_access, ace_flags);
|
init_sec_ace(ace, &trustee, ace_type, sec_access, ace_flags);
|
||||||
|
|
||||||
|
/* Fill in size field */
|
||||||
|
|
||||||
|
ace->size = SEC_ACE_HEADER_SIZE + sid_size(&trustee);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,25 +159,22 @@ BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict, TALLOC_CTX *mem_ctx)
|
|||||||
|
|
||||||
acl->revision = PyInt_AsLong(obj);
|
acl->revision = PyInt_AsLong(obj);
|
||||||
|
|
||||||
DEBUG(0, ("py: got revision %d\n", acl->revision));
|
|
||||||
|
|
||||||
if (!(obj = PyDict_GetItemString(dict, "ace_list")) ||
|
if (!(obj = PyDict_GetItemString(dict, "ace_list")) ||
|
||||||
!PyList_Check(obj))
|
!PyList_Check(obj))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
acl->num_aces = PyList_Size(obj);
|
acl->num_aces = PyList_Size(obj);
|
||||||
|
|
||||||
DEBUG(0, ("py: got num_aces %d\n", acl->num_aces));
|
|
||||||
|
|
||||||
acl->ace = talloc(mem_ctx, acl->num_aces * sizeof(SEC_ACE));
|
acl->ace = talloc(mem_ctx, acl->num_aces * sizeof(SEC_ACE));
|
||||||
|
acl->size = SEC_ACL_HEADER_SIZE;
|
||||||
|
|
||||||
for (i = 0; i < acl->num_aces; i++) {
|
for (i = 0; i < acl->num_aces; i++) {
|
||||||
PyObject *py_ace = PyList_GetItem(obj, i);
|
PyObject *py_ace = PyList_GetItem(obj, i);
|
||||||
|
|
||||||
if (!py_to_ACE(acl->ace, py_ace))
|
if (!py_to_ACE(&acl->ace[i], py_ace))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
DEBUG(0, ("py: got ace %d\n", i));
|
acl->size += acl->ace[i].size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
@ -221,8 +209,8 @@ BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx)
|
|||||||
uint16 revision;
|
uint16 revision;
|
||||||
DOM_SID owner_sid, group_sid;
|
DOM_SID owner_sid, group_sid;
|
||||||
SEC_ACL sacl, dacl;
|
SEC_ACL sacl, dacl;
|
||||||
size_t sd_size;
|
|
||||||
BOOL got_dacl = False, got_sacl = False;
|
BOOL got_dacl = False, got_sacl = False;
|
||||||
|
BOOL got_owner_sid = False, got_group_sid = False;
|
||||||
|
|
||||||
ZERO_STRUCT(dacl); ZERO_STRUCT(sacl);
|
ZERO_STRUCT(dacl); ZERO_STRUCT(sacl);
|
||||||
ZERO_STRUCT(owner_sid); ZERO_STRUCT(group_sid);
|
ZERO_STRUCT(owner_sid); ZERO_STRUCT(group_sid);
|
||||||
@ -232,29 +220,41 @@ BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx)
|
|||||||
|
|
||||||
revision = PyInt_AsLong(obj);
|
revision = PyInt_AsLong(obj);
|
||||||
|
|
||||||
if (!(obj = PyDict_GetItemString(dict, "owner_sid")))
|
if ((obj = PyDict_GetItemString(dict, "owner_sid"))) {
|
||||||
return False;
|
|
||||||
|
|
||||||
if (!py_to_SID(&owner_sid, obj))
|
if (obj != Py_None) {
|
||||||
return False;
|
|
||||||
|
|
||||||
if (!(obj = PyDict_GetItemString(dict, "group_sid")))
|
if (!py_to_SID(&owner_sid, obj))
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
if (!py_to_SID(&group_sid, obj))
|
got_owner_sid = True;
|
||||||
return False;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((obj = PyDict_GetItemString(dict, "group_sid"))) {
|
||||||
|
|
||||||
|
if (obj != Py_None) {
|
||||||
|
|
||||||
|
if (!py_to_SID(&group_sid, obj))
|
||||||
|
return False;
|
||||||
|
|
||||||
|
got_group_sid = True;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((obj = PyDict_GetItemString(dict, "dacl"))) {
|
if ((obj = PyDict_GetItemString(dict, "dacl"))) {
|
||||||
|
|
||||||
if (!py_to_ACL(&dacl, obj, mem_ctx))
|
if (obj != Py_None) {
|
||||||
return False;
|
|
||||||
|
|
||||||
got_dacl = True;
|
if (!py_to_ACL(&dacl, obj, mem_ctx))
|
||||||
|
return False;
|
||||||
|
|
||||||
|
got_dacl = True;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(0, ("py: got dacl\n"));
|
|
||||||
|
|
||||||
if ((obj = PyDict_GetItemString(dict, "sacl"))) {
|
if ((obj = PyDict_GetItemString(dict, "sacl"))) {
|
||||||
|
|
||||||
if (obj != Py_None) {
|
if (obj != Py_None) {
|
||||||
|
|
||||||
if (!py_to_ACL(&sacl, obj, mem_ctx))
|
if (!py_to_ACL(&sacl, obj, mem_ctx))
|
||||||
@ -264,11 +264,11 @@ BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(0, ("py: got sacl\n"));
|
*sd = make_sec_desc(mem_ctx, revision,
|
||||||
|
got_owner_sid ? &owner_sid : NULL,
|
||||||
*sd = make_sec_desc(mem_ctx, revision, &owner_sid, &group_sid,
|
got_group_sid ? &group_sid : NULL,
|
||||||
got_sacl ? &sacl : NULL,
|
got_sacl ? &sacl : NULL,
|
||||||
got_dacl ? &dacl : NULL, &sd_size);
|
got_dacl ? &dacl : NULL);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user