sysdb.h revision 0228e28a3f07b5dc909cdc154dc89c4952f09280
842ae4bd224140319ae7feec1872b93dfd491143fielding System Database Header
842ae4bd224140319ae7feec1872b93dfd491143fielding Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd This program is free software; you can redistribute it and/or modify
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse it under the terms of the GNU General Public License as published by
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd the Free Software Foundation; either version 3 of the License, or
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd (at your option) any later version.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd This program is distributed in the hope that it will be useful,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd but WITHOUT ANY WARRANTY; without even the implied warranty of
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd GNU General Public License for more details.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd You should have received a copy of the GNU General Public License
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd along with this program. If not, see <http://www.gnu.org/licenses/>.
71c00f988beb28388702e14cb7fe06f08bd792bbdougm#define SYSDB_TMPL_USER_BASE SYSDB_USERS_CONTAINER",cn=%s,"SYSDB_BASE
71c00f988beb28388702e14cb7fe06f08bd792bbdougm#define SYSDB_TMPL_GROUP_BASE SYSDB_GROUPS_CONTAINER",cn=%s,"SYSDB_BASE
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_TMPL_CUSTOM_BASE SYSDB_CUSTOM_CONTAINER",cn=%s,"SYSDB_BASE
0c44ed1cffad38b900b39e8c65996b9b9cff061djim#define SYSDB_FAILED_LOGIN_ATTEMPTS "failedLoginAttempts"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#define SYSDB_PWNAM_FILTER "(&("SYSDB_UC")("SYSDB_NAME"=%s))"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#define SYSDB_PWUID_FILTER "(&("SYSDB_UC")("SYSDB_UIDNUM"=%lu))"
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_GRNAM_FILTER "(&("SYSDB_GC")("SYSDB_NAME"=%s))"
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_GRNA2_FILTER "(&("SYSDB_UC")("SYSDB_MEMBEROF"=%s))"
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_GRGID_FILTER "(&("SYSDB_GC")("SYSDB_GIDNUM"=%lu))"
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_GRNAM_MPG_FILTER "(&("SYSDB_MPGC")("SYSDB_NAME"=%s))"
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_GRGID_MPG_FILTER "(&("SYSDB_MPGC")("SYSDB_GIDNUM"=%lu))"
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_INITGR_FILTER "(&("SYSDB_GC")("SYSDB_GIDNUM"=*))"
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_GETCACHED_FILTER "(&"SYSDB_UC")("SYSDB_LAST_LOGIN">=%lu))"
176c2742db03fcb7b7d13e6408dd967d87e542e9ben "objectClass"
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_GRENT_ATTRS {SYSDB_NAME, SYSDB_UIDNUM, SYSDB_MEMBEROF, \
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_TMPL_USER SYSDB_NAME"=%s,"SYSDB_TMPL_USER_BASE
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_TMPL_GROUP SYSDB_NAME"=%s,"SYSDB_TMPL_GROUP_BASE
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_TMPL_CUSTOM_SUBTREE "cn=%s,"SYSDB_TMPL_CUSTOM_BASE
7933d4a963def02417113b6798d87a36395053b0rse#define SYSDB_TMPL_CUSTOM SYSDB_NAME"=%s,cn=%s,"SYSDB_TMPL_CUSTOM_BASE
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse/* sysdb_attrs helper functions */
cde1010d880fb6230f80c9d697842ea0b1cb79c7dougm/* values are copied in the structure, allocated on "attrs" */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrseint sysdb_attrs_get_el(struct sysdb_attrs *attrs, const char *name,
7933d4a963def02417113b6798d87a36395053b0rseint sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse const char **string);
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrseint sysdb_attrs_get_string_array(struct sysdb_attrs *attrs, const char *name,
a72de14bfdbf0be9d935be9bdc2df631ca5e032bdougmint sysdb_attrs_replace_name(struct sysdb_attrs *attrs, const char *oldname,
a72de14bfdbf0be9d935be9bdc2df631ca5e032bdougm const char *newname);
a72de14bfdbf0be9d935be9bdc2df631ca5e032bdougmint sysdb_attrs_users_from_str_list(struct sysdb_attrs *attrs,
7933d4a963def02417113b6798d87a36395053b0rse const char *attr_name,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse const char *domain,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse const char **list);
7933d4a963def02417113b6798d87a36395053b0rseint sysdb_attrs_users_from_ldb_vals(struct sysdb_attrs *attrs,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse const char *attr_name,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse const char *domain,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse/* convert an ldb error into an errno error */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse/* DNs related helper functions */
7933d4a963def02417113b6798d87a36395053b0rsestruct ldb_dn *sysdb_user_dn(struct sysdb_ctx *ctx, void *memctx,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrsestruct ldb_dn *sysdb_group_dn(struct sysdb_ctx *ctx, void *memctx,
0839d91ee551a0e19ea9577bb00976b97308dfddmartinerrno_t sysdb_group_dn_name(struct sysdb_ctx *ctx, void *memctx,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrsestruct ldb_dn *sysdb_domain_dn(struct sysdb_ctx *ctx, void *memctx,
e6e65585927961caf45d4e9e932bb1f4e9e89ca1jerenkrantz const char *domain);
e8f95a682820a599fe41b22977010636be5c2717jimstruct ldb_dn *sysdb_custom_dn(struct sysdb_ctx *ctx, void *memctx,
e8f95a682820a599fe41b22977010636be5c2717jim const char *subtree_name);
e6e65585927961caf45d4e9e932bb1f4e9e89ca1jerenkrantzstruct ldb_dn *sysdb_custom_subtree_dn(struct sysdb_ctx *ctx, void *memctx,
e8f95a682820a599fe41b22977010636be5c2717jim const char *domain,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse const char *subtree_name);
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wrowestruct ldb_context *sysdb_ctx_get_ldb(struct sysdb_ctx *ctx);
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wroweint compare_ldb_dn_comp_num(const void *m1, const void *m2);
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wrowe/* functions to start and finish transactions */
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wrowe/* Sysdb initialization.
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wrowe * call this function *only* once to initialize the database and get
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wrowe * the sysdb ctx */
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wrowe const char *alt_db_path,
239dd0cf663713025d4451ddd465685021007d82wrowe/* used to initialize only one domain database.
239dd0cf663713025d4451ddd465685021007d82wrowe * Do NOT use if sysdb_init has already been called */
239dd0cf663713025d4451ddd465685021007d82wrowe const char *db_path,
56bd16e394f49423a22aa82643eb27f26db2c748jortonint sysdb_get_ctx_from_list(struct sysdb_ctx_list *ctx_list,
e8f95a682820a599fe41b22977010636be5c2717jim/* functions to retrieve information from sysdb
e8f95a682820a599fe41b22977010636be5c2717jim * These functions automatically starts an operation
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wrowe * therefore they cannot be called within a transaction */
2b7078b0c4fd5b6054f6f2d4f626177844f5c6f7wrowe const char *name,
b5451913a64155af2eab4f12ecbaf16e15acafc3wrowe const char *name,
8dc154408549195c828b823e9dc7396f107f2512jorton const char *name,
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm const char *name,
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm const char **attributes,
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm/* functions that modify the databse
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm * they have to be called within a transaction
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm * See sysdb_transaction_send()/_recv() */
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm/* Delete Entry */
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm/* Search Entry */
cde1010d880fb6230f80c9d697842ea0b1cb79c7dougm const char *filter,
cde1010d880fb6230f80c9d697842ea0b1cb79c7dougm const char **attrs,
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm/* Search User (by uid or name) */
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm const char *name,
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm const char **attrs,
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm const char **attrs,
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm/* Search Group (gy gid or name) */
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm const char *name,
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm const char **attrs,
469549ac22c6f7b9ecdd9df2565925563e4df84djwoolley const char **attrs,
a943533fd4d91d114af622731a405407990c4fb1rse/* Replace entry attrs */
9cb81d96f6b556cec1aa456191f43f7932aabaaedougm/* Replace user attrs */
a943533fd4d91d114af622731a405407990c4fb1rse const char *name,
a943533fd4d91d114af622731a405407990c4fb1rse/* Replace group attrs */
2261f694ce2fc09f9df6c65bd8e1f4230313696bjorton const char *name,
71c00f988beb28388702e14cb7fe06f08bd792bbdougm/* Allocate a new id */
469549ac22c6f7b9ecdd9df2565925563e4df84djwoolley/* Add user (only basic attrs and w/o checks) */
2261f694ce2fc09f9df6c65bd8e1f4230313696bjorton const char *name,
e16695d440d82ec6f9a4b9af18ae38dbeaa19366jerenkrantz const char *gecos,
71c00f988beb28388702e14cb7fe06f08bd792bbdougm const char *homedir,
a943533fd4d91d114af622731a405407990c4fb1rse const char *shell);
a943533fd4d91d114af622731a405407990c4fb1rse/* Add user (all checks) */
d28d7091912b3d911bdbe18df2d37d315681054bdougm const char *name,
931b4fd1cc9dd3da096c45f4bf7ddcc14e0985c1dougm const char *gecos,
a943533fd4d91d114af622731a405407990c4fb1rse const char *homedir,
a943533fd4d91d114af622731a405407990c4fb1rse const char *shell,
a943533fd4d91d114af622731a405407990c4fb1rse/* Add group (only basic attrs and w/o checks) */
a943533fd4d91d114af622731a405407990c4fb1rse/* Add group (all checks) */
a943533fd4d91d114af622731a405407990c4fb1rse/* mod_op must be either LDB_FLAG_MOD_ADD or LDB_FLAG_MOD_DELETE */
2f32a3d146dc55d81b31660386e17c3b83ad61b8bnicholes const char *name,
a943533fd4d91d114af622731a405407990c4fb1rse const char *pwd,
71c00f988beb28388702e14cb7fe06f08bd792bbdougm const char *gecos,
a943533fd4d91d114af622731a405407990c4fb1rse const char *homedir,
7933d4a963def02417113b6798d87a36395053b0rse const char *shell,
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe const char *name,
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe const char *group,
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe const char *user);
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe const char *group,
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe const char *user);
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe/* Password caching function.
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe * If you are in a transaction ignore sysdb and pass in the handle.
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe * If you are not in a transaction pass NULL in handle and provide sysdb,
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe * in this case a transaction will be automatically started and the
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe * function will be completely wrapped in it's own sysdb transaction */
2261f694ce2fc09f9df6c65bd8e1f4230313696bjorton const char *username,
2261f694ce2fc09f9df6c65bd8e1f4230313696bjorton const char *password);
e726f34f8da08c01ee8bc90904b26196b69c8587wroweerrno_t check_failed_login_attempts(TALLOC_CTX *mem_ctx,
e726f34f8da08c01ee8bc90904b26196b69c8587wrowe const char *name,
7933d4a963def02417113b6798d87a36395053b0rse const char *object_name,
a943533fd4d91d114af622731a405407990c4fb1rse const char *filter,
a943533fd4d91d114af622731a405407990c4fb1rse const char **attrs,
a943533fd4d91d114af622731a405407990c4fb1rse const char *object_name,
825479074daa2c65852666c4b26d771dff957507jorton const char **attrs,
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm const char *object_name,
7933d4a963def02417113b6798d87a36395053b0rse const char *subtree_name);
7933d4a963def02417113b6798d87a36395053b0rse const char *expression,
7933d4a963def02417113b6798d87a36395053b0rse const char *asq_attribute,
7933d4a963def02417113b6798d87a36395053b0rse const char **attrs,
const char *sub_filter,
const char **attrs,
const char *sub_filter,
const char **attrs,
int attr_count,
const char *attr_name,
char ***_list);