Logo Search packages:      
Sourcecode: ldb version File versions  Download package

int ldb_msg_sanity_check ( struct ldb_context *  ldb,
const struct ldb_message msg 
)

Integrity check an ldb_message

This function performs basic sanity / integrity checks on an ldb_message.

Parameters:
msg the message to check
Returns:
LDB_SUCCESS if the message is OK, or a non-zero error code (one of LDB_ERR_INVALID_DN_SYNTAX, LDB_ERR_ENTRY_ALREADY_EXISTS or LDB_ERR_INVALID_ATTRIBUTE_SYNTAX) if there is a problem with a message.

Definition at line 606 of file ldb_msg.c.

References ldb_message::dn, ldb_message::elements, LDB_ERR_INVALID_ATTRIBUTE_SYNTAX, LDB_ERR_INVALID_DN_SYNTAX, LDB_SUCCESS, ldb_val::length, ldb_message_element::name, ldb_message::num_elements, ldb_message_element::num_values, and ldb_message_element::values.

{
      int i, j;

      /* basic check on DN */
      if (msg->dn == NULL) {
            /* TODO: return also an error string */
            ldb_set_errstring(ldb, "ldb message lacks a DN!");
            return LDB_ERR_INVALID_DN_SYNTAX;
      }

      /* basic syntax checks */
      for (i = 0; i < msg->num_elements; i++) {
            for (j = 0; j < msg->elements[i].num_values; j++) {
                  if (msg->elements[i].values[j].length == 0) {
                        TALLOC_CTX *mem_ctx = talloc_new(ldb);
                        /* an attribute cannot be empty */
                        /* TODO: return also an error string */
                        ldb_asprintf_errstring(ldb, "Element %s has empty attribute in ldb message (%s)!",
                                              msg->elements[i].name, 
                                              ldb_dn_get_linearized(msg->dn));
                        talloc_free(mem_ctx);
                        return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
                  }
            }
      }

      return LDB_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index