patch to allow controls in add function for python bindings

Matthieu Patou mat at matws.net
Wed Sep 23 10:47:00 MDT 2009


Andrew,
You said you wanted to make relax the default control.
I made a small variation on the last patch so that now ["relax:0"] is 
the default control (I had to made it non critical otherwise provision 
fails ...).
Pick the one that suits best to your need at the end.

Matthieu.
On 09/23/2009 08:19 PM, Matthieu Patou wrote:
> Hello,
> Find attached the whole set of patch for this only the patch concerning
> the python binding has been reworked to comply with jelmer remarks.
>
> On 09/23/2009 04:41 PM, Jelmer Vernooij wrote:
>> Hi Matthieu,
>>
>> Matthieu Patou wrote:
>>> Take 2
>> Almost there...
>>
>>> diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
>>> index b4f03dc..8c2285d 100644
>>> --- a/source4/lib/ldb/pyldb.c
>>> +++ b/source4/lib/ldb/pyldb.c
>>> @@ -656,6 +656,66 @@ static PyObject *py_ldb_modify(PyLdbObject
>>> *self, PyObject *args)
>>> Py_RETURN_NONE;
>>> }
>>>
>>> +/* autostarts a transacion if none active */
>>> +static int ldb_autotransaction_request(struct ldb_context *ldb,
>>> + struct ldb_request *req)
>>> +{
>>> + int ret;
>>> +
>>> + ret = ldb_transaction_start(ldb);
>>> + if (ret != LDB_SUCCESS) {
>>> + return ret;
>>> + }
>>> +
>>> + ret = ldb_request(ldb, req);
>>> + if (ret == LDB_SUCCESS) {
>>> + ret = ldb_wait(req->handle, LDB_WAIT_ALL);
>>> + }
>>> +
>>> + if (ret == LDB_SUCCESS) {
>>> + return ldb_transaction_commit(ldb);
>>> + }
>>> + ldb_transaction_cancel(ldb);
>>> +
>>> + if (ldb->err_string == NULL) {
>>> + /* no error string was setup by the backend */
>>> + ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret);
>>> + }
>>> +
>>> + return ret;
>>> +}
>>>
>> ^^^ Doesn't LDB do this by itself already? I don't think it's necessary.
>>
>>> +/*
>>> + add a record to the database. Will fail if a record with the given
>>> class
>>> + and key already exists.
>>> + Allow to supply controls
>>> +*/
>>> +static int ldb_add_w_ctrls(struct ldb_context *ldb,
>>> + const struct ldb_message *message,
>>> + struct ldb_control **controls)
>>> +{
>>> + struct ldb_request *req;
>>> + int ret;
>>> +
>>> + ret = ldb_msg_sanity_check(ldb, message);
>>> + if (ret != LDB_SUCCESS) {
>>> + return ret;
>>> + }
>>> +
>>> + ret = ldb_build_add_req(&req, ldb, ldb,
>>> + message,
>>> + controls,
>>> + NULL,
>>> + ldb_op_default_callback,
>>> + NULL);
>>> +
>>> + if (ret != LDB_SUCCESS) return ret;
>>> +
>>> + /* do request and autostart a transaction */
>>> + ret = ldb_autotransaction_request(ldb, req);
>>> +
>>> + talloc_free(req);
>>> + return ret;
>>> +}
>>>
>> ^^ Please keep an empty line in between functions, per the coding style.
>> This code also seems simple enough to fold into py_ldb_add. That way you
>> can also raise exceptions with clearer messages.
>>
>> Cheers,
>>
>> Jelmer
>



More information about the samba-technical mailing list