Samba4/LDB/API: Difference between revisions

From SambaWiki
Line 260: Line 260:


Return: result code (LDB_SUCCESS if the record was added, otherwise a failure code)
Return: result code (LDB_SUCCESS if the record was added, otherwise a failure code)

== ldb_modify() ==

int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message);

Modify the specified attributes of a record

This function modifies a record that is in the database.

Parameters:
* ldb: the context associated with the database (from ldb_init())
* message: the message containing the changes required.

Return: result code (LDB_SUCCESS if the record was modified as requested, otherwise a failure code)

== ldb_rename() ==

int ldb_rename(struct ldb_context *ldb, struct ldb_dn *olddn, struct ldb_dn *newdn);

Rename a record in the database

This function renames a record in the database.

Parameters:
* ldb: the context associated with the database (from ldb_init())
* olddn: the DN for the record to be renamed.
* newdn: the new DN

Return: result code (LDB_SUCCESS if the record was renamed as requested, otherwise a failure code)

== ldb_delete() ==

int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn);

Delete a record from the database

This function deletes a record from the database.

Parameters:
* ldb: the context associated with the database (from ldb_init())
* dn: the DN for the record to be deleted.

Return: result code (LDB_SUCCESS if the record was deleted, otherwise a failure code)

Revision as of 23:29, 23 September 2009

DN

ldb_dn_get_linearized()

const char *ldb_dn_get_linearized(struct ldb_dn *dn);

Get the linear form of a DN (without any extended components)

Parameters:

  • dn: The DN to linearize

ldb_dn_alloc_linearized()

char *ldb_dn_alloc_linearized(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);

Allocate a copy of the linear form of a DN (without any extended components) onto the supplied memory context

Parameters:

  • dn: The DN to linearize
  • mem_ctx: TALLOC context to return result on

ldb_dn_get_extended_linearized()

char *ldb_dn_get_extended_linearized(void *mem_ctx, struct ldb_dn *dn, int mode);

Get the linear form of a DN (with any extended components)

Parameters:

  • mem_ctx: TALLOC context to return result on
  • dn: The DN to linearize
  • mode: Style of extended DN to return (0 is HEX representation of binary form, 1 is a string form)

ldb_dn_get_extended_component()

const struct ldb_val *ldb_dn_get_extended_component(struct ldb_dn *dn, const char *name);

ldb_dn_set_extended_component()

int ldb_dn_set_extended_component(struct ldb_dn *dn, const char *name, const struct ldb_val *val);

ldb_dn_remove_extended_components()

void ldb_dn_remove_extended_components(struct ldb_dn *dn);

ldb_dn_has_extended()

bool ldb_dn_has_extended(struct ldb_dn *dn);

ldb_dn_extended_add_syntax()

int ldb_dn_extended_add_syntax(struct ldb_context *ldb, unsigned flags, const struct ldb_dn_extended_syntax *syntax);

ldb_dn_new()

struct ldb_dn *ldb_dn_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const char *dn);

Allocate a new DN from a string

Parameters:

  • mem_ctx: TALLOC context to return resulting ldb_dn structure on
  • dn: The new DN

The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntacticly correct

ldb_dn_new_fmt()

struct ldb_dn *ldb_dn_new_fmt(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const char *new_fmt, ...) PRINTF_ATTRIBUTE(3,4);

Allocate a new DN from a printf style format string and arguments

Parameters:

  • mem_ctx: TALLOC context to return resulting ldb_dn structure on
  • new_fms: The new DN as a format string (plus arguments)

The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntacticly correct

ldb_dn_from_ldb_val()

struct ldb_dn *ldb_dn_from_ldb_val(void *mem_ctx, struct ldb_context *ldb, const struct ldb_val *strdn);

Allocate a new DN from a struct ldb_val (useful to avoid buffer overrun)

Parameters:

  • mem_ctx: TALLOC context to return resulting ldb_dn structure on
  • dn: The new DN

The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntacticly correct

ldb_dn_validate()

bool ldb_dn_validate(struct ldb_dn *dn);

Determine if this DN is syntactically valid

Parameters:

  • dn: The DN to validate

ldb_dn_escape_value()

char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value);

ldb_dn_get_casefold()

const char *ldb_dn_get_casefold(struct ldb_dn *dn);

ldb_dn_alloc_casefold()

char *ldb_dn_alloc_casefold(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);

ldb_dn_compare_base()

int ldb_dn_compare_base(struct ldb_dn *base, struct ldb_dn *dn);

ldb_dn_compare()

int ldb_dn_compare(struct ldb_dn *edn0, struct ldb_dn *edn1);

ldb_dn_add_base()

bool ldb_dn_add_base(struct ldb_dn *dn, struct ldb_dn *base);

ldb_dn_add_base_fmt()

bool ldb_dn_add_base_fmt(struct ldb_dn *dn, const char *base_fmt, ...) PRINTF_ATTRIBUTE(2,3);

ldb_dn_add_child()

bool ldb_dn_add_child(struct ldb_dn *dn, struct ldb_dn *child);

ldb_dn_add_child_fmt()

bool ldb_dn_add_child_fmt(struct ldb_dn *dn, const char *child_fmt, ...) PRINTF_ATTRIBUTE(2,3);

ldb_dn_remove_base_components()

bool ldb_dn_remove_base_components(struct ldb_dn *dn, unsigned int num);

ldb_dn_remove_child_components()

bool ldb_dn_remove_child_components(struct ldb_dn *dn, unsigned int num);

ldb_dn_copy()

struct ldb_dn *ldb_dn_copy(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);

ldb_dn_get_parent()

struct ldb_dn *ldb_dn_get_parent(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);

ldb_dn_canonical_string()

char *ldb_dn_canonical_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);

ldb_dn_canonical_ex_string()

char *ldb_dn_canonical_ex_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);

ldb_dn_get_comp_num()

int ldb_dn_get_comp_num(struct ldb_dn *dn);

ldb_dn_get_component_name()

const char *ldb_dn_get_component_name(struct ldb_dn *dn, unsigned int num);

ldb_dn_get_component_val()

const struct ldb_val *ldb_dn_get_component_val(struct ldb_dn *dn, unsigned int num);

ldb_dn_get_rdn_name()

const char *ldb_dn_get_rdn_name(struct ldb_dn *dn);

ldb_dn_get_rdn_val()

const struct ldb_val *ldb_dn_get_rdn_val(struct ldb_dn *dn);

ldb_dn_set_component()

int ldb_dn_set_component(struct ldb_dn *dn, int num, const char *name, const struct ldb_val val);

ldb_dn_is_valid()

bool ldb_dn_is_valid(struct ldb_dn *dn);

ldb_dn_is_special()

bool ldb_dn_is_special(struct ldb_dn *dn);

ldb_dn_check_special()

bool ldb_dn_check_special(struct ldb_dn *dn, const char *check);

ldb_dn_is_null()

bool ldb_dn_is_null(struct ldb_dn *dn);

ldb_attr_cmp()

#define ldb_attr_cmp(a, b) strcasecmp(a, b)

Compare two attributes

This function compares to attribute names. Note that this is a case-insensitive comparison.

Parameters:

  • a: the first attribute name to compare
  • b: the second attribute name to compare

Return 0 if the attribute names are the same, or only differ in case; non-zero if there are any differences

attribute names are restricted by rfc2251 so using strcasecmp and toupper here is ok. return 0 for match

ldb_attr_casefold()

char *ldb_attr_casefold(TALLOC_CTX *mem_ctx, const char *s);

ldb_attr_dn()

int ldb_attr_dn(const char *attr);

LDAP Operations

ldb_search()

int ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
    struct ldb_result **result, struct ldb_dn *base,
    enum ldb_scope scope, const char * const *attrs,
    const char *exp_fmt, ...) PRINTF_ATTRIBUTE(7,8);

Search the database

This function searches the database, and returns records that match an LDAP-like search expression

Parameters:

  • ldb the: context associated with the database (from ldb_init())
  • mem_ctx: the memory context to use for the request and the results
  • result: the return result
  • base: the Base Distinguished Name for the query (use ldb_dn_new() for an empty one)
  • scope: the search scope for the query
  • attrs: the search attributes for the query (pass NULL if none required)
  • exp_fmt: the search expression to use for this query (printf like)

Return: result code (LDB_SUCCESS on success, or a failure code)

Note: Use talloc_free() to free the ldb_result returned.

ldb_add()

int ldb_add(struct ldb_context *ldb, 
    const struct ldb_message *message);

Add a record to the database.

This function adds a record to the database. This function will fail if a record with the specified class and key already exists in the database.

Parameters:

  • ldb: the context associated with the database (from ldb_init())
  • message: the message containing the record to add.

Return: result code (LDB_SUCCESS if the record was added, otherwise a failure code)

ldb_modify()

int ldb_modify(struct ldb_context *ldb, 
    const struct ldb_message *message);

Modify the specified attributes of a record

This function modifies a record that is in the database.

Parameters:

  • ldb: the context associated with the database (from ldb_init())
  • message: the message containing the changes required.

Return: result code (LDB_SUCCESS if the record was modified as requested, otherwise a failure code)

ldb_rename()

int ldb_rename(struct ldb_context *ldb, struct ldb_dn *olddn, struct ldb_dn *newdn);

Rename a record in the database

This function renames a record in the database.

Parameters:

  • ldb: the context associated with the database (from ldb_init())
  • olddn: the DN for the record to be renamed.
  • newdn: the new DN

Return: result code (LDB_SUCCESS if the record was renamed as requested, otherwise a failure code)

ldb_delete()

int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn);

Delete a record from the database

This function deletes a record from the database.

Parameters:

  • ldb: the context associated with the database (from ldb_init())
  • dn: the DN for the record to be deleted.

Return: result code (LDB_SUCCESS if the record was deleted, otherwise a failure code)