get_master_ncs code

tridge at samba.org tridge at samba.org
Thu Dec 10 15:26:28 MST 2009


Hi Erick,

This is in answer to the question you asked on IRC about your
get_master_ncs() code, from this commit:

   http://repo.or.cz/w/Samba/nascimento.git/commitdiff/2e0a16450ed6bc2775e3694ec72fa072d50137ae

Your get_master_ncs() implementation has several errors. The first is
that it is doing a LDB_SCOPE_SUBTREE search. A subtree search in LDAP
means you are trying to find multiple object that match a search
expression below a point in the tree. In this case that isn't what you
want, as you know the DN of the object you are trying to query. So in
this case you should be doing a LDB_SCOPE_BASE search. 

A base search will never return more than one object, so it makes life
much simpler. It is also much more efficient!

The second main problem is the use of
ldb_msg_find_attr_as_string(). That function assumes that the
attribute is single valued (ie. that the attribute can only have one
value at a time).

The hasMasterNCs attribute is multi-valued. So you need to instead use
ldb_msg_find_element(), which will return a ldb_message_element
structure. That contains a num_values variable that tells you how many
values the attribute has. The actual values are in the values[] array.

Cheers, Tridge


More information about the samba-technical mailing list