r26529: Indeed, this belongs in the schema module. Ranged results need to use
[jelmer/samba4-debian.git] / source / lib / ldb / common / ldb_msg.c
index ed939aaa7d1039eb776c40d93cf343a9c33f3a21..c1ea9db56bfb11a4319fb6503258199bcac471dd 100644 (file)
@@ -18,8 +18,7 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
@@ -125,11 +124,6 @@ int ldb_msg_add_empty(     struct ldb_message *msg,
 {
        struct ldb_message_element *els;
 
-       /* FIXME: we should probably leave this to the schema module to check */
-       if (! ldb_valid_attr_name(attr_name)) {
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
        els = talloc_realloc(msg, msg->elements, 
                             struct ldb_message_element, msg->num_elements+1);
        if (!els) {
@@ -163,11 +157,14 @@ int ldb_msg_add(struct ldb_message *msg,
                const struct ldb_message_element *el, 
                int flags)
 {
+       /* We have to copy this, just in case *el is a pointer into
+        * what ldb_msg_add_empty() is about to realloc() */
+       struct ldb_message_element el_copy = *el;
        if (ldb_msg_add_empty(msg, el->name, flags, NULL) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       msg->elements[msg->num_elements-1] = *el;
+       msg->elements[msg->num_elements-1] = el_copy;
        msg->elements[msg->num_elements-1].flags = flags;
 
        return LDB_SUCCESS;
@@ -319,7 +316,8 @@ int ldb_msg_element_compare_name(struct ldb_message_element *el1,
   convenience functions to return common types from a message
   these return the first value if the attribute is multi-valued
 */
-const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg, const char *attr_name)
+const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg, 
+                                          const char *attr_name)
 {
        struct ldb_message_element *el = ldb_msg_find_element(msg, attr_name);
        if (!el || el->num_values == 0) {