sysdb.h revision 4bbcc2d6d3f16b015796818746a45134861c93a4
/*
SSSD
System Database Header
Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SYS_DB_H__
#define __SYS_DB_H__
#include <tevent.h>
#define CACHE_SYSDB_FILE "cache_%s.ldb"
#define LOCAL_SYSDB_FILE "sssd.ldb"
#define SYSDB_BASE "cn=sysdb"
#define SYSDB_DOM_BASE "cn=%s,cn=sysdb"
#define SYSDB_USERS_CONTAINER "cn=users"
#define SYSDB_GROUPS_CONTAINER "cn=groups"
#define SYSDB_CUSTOM_CONTAINER "cn=custom"
#define SYSDB_NETGROUP_CONTAINER "cn=Netgroups"
#define SYSDB_RANGE_CONTAINER "cn=ranges"
#define SYSDB_VIEW_CONTAINER "cn=views"
#define SYSDB_SUBDOMAIN_CLASS "subdomain"
#define SYSDB_USER_CLASS "user"
#define SYSDB_GROUP_CLASS "group"
#define SYSDB_NETGROUP_CLASS "netgroup"
#define SYSDB_HOST_CLASS "host"
#define SYSDB_HOSTGROUP_CLASS "hostgroup"
#define SYSDB_SELINUX_USERMAP_CLASS "selinuxusermap"
#define SYSDB_SELINUX_CLASS "selinux"
#define SYSDB_ID_RANGE_CLASS "idRange"
#define SYSDB_DOMAIN_ID_RANGE_CLASS "domainIDRange"
#define SYSDB_TRUSTED_AD_DOMAIN_RANGE_CLASS "TrustedADDomainRange"
#define SYSDB_NAME "name"
#define SYSDB_NAME_ALIAS "nameAlias"
#define SYSDB_OBJECTCLASS "objectClass"
#define SYSDB_NEXTID "nextID"
#define SYSDB_UIDNUM "uidNumber"
#define SYSDB_GIDNUM "gidNumber"
#define SYSDB_CREATE_TIME "createTimestamp"
#define SYSDB_PWD "userPassword"
#define SYSDB_FULLNAME "fullName"
#define SYSDB_HOMEDIR "homeDirectory"
#define SYSDB_SHELL "loginShell"
#define SYSDB_MEMBEROF "memberOf"
#define SYSDB_DISABLED "disabled"
#define SYSDB_MEMBER "member"
#define SYSDB_MEMBERUID "memberUid"
#define SYSDB_GHOST "ghost"
#define SYSDB_POSIX "isPosix"
#define SYSDB_USER_CATEGORY "userCategory"
#define SYSDB_HOST_CATEGORY "hostCategory"
#define SYSDB_GROUP_TYPE "groupType"
#define SYSDB_GECOS "gecos"
#define SYSDB_LAST_LOGIN "lastLogin"
#define SYSDB_LAST_ONLINE_AUTH "lastOnlineAuth"
#define SYSDB_LAST_FAILED_LOGIN "lastFailedLogin"
#define SYSDB_FAILED_LOGIN_ATTEMPTS "failedLoginAttempts"
#define SYSDB_LAST_UPDATE "lastUpdate"
#define SYSDB_CACHE_EXPIRE "dataExpireTimestamp"
#define SYSDB_INITGR_EXPIRE "initgrExpireTimestamp"
#define SYSDB_AUTHORIZED_SERVICE "authorizedService"
#define SYSDB_AUTHORIZED_HOST "authorizedHost"
#define SYSDB_NETGROUP_TRIPLE "netgroupTriple"
#define SYSDB_ORIG_NETGROUP_MEMBER "originalMemberNisNetgroup"
#define SYSDB_ORIG_NETGROUP_EXTERNAL_HOST "originalExternalHost"
#define SYSDB_NETGROUP_DOMAIN "nisDomain"
#define SYSDB_NETGROUP_MEMBER "memberNisNetgroup"
#define SYSDB_DESCRIPTION "description"
#define SYSDB_FQDN "fqdn"
#define SYSDB_SERVERHOSTNAME "serverHostname"
#define SYSDB_CACHEDPWD "cachedPassword"
#define SYSDB_UUID "uniqueID"
#define SYSDB_SID "objectSID"
#define SYSDB_PRIMARY_GROUP "ADPrimaryGroupID"
#define SYSDB_PRIMARY_GROUP_GIDNUM "origPrimaryGroupGidNumber"
#define SYSDB_SID_STR "objectSIDString"
#define SYSDB_UPN "userPrincipalName"
#define SYSDB_CANONICAL_UPN "canonicalUserPrincipalName"
#define SYSDB_CCACHE_FILE "ccacheFile"
#define SYSDB_ORIG_DN "originalDN"
#define SYSDB_ORIG_MODSTAMP "originalModifyTimestamp"
#define SYSDB_ORIG_MEMBEROF "originalMemberOf"
#define SYSDB_ORIG_MEMBER "orig_member"
#define SYSDB_ORIG_MEMBER_USER "originalMemberUser"
#define SYSDB_ORIG_MEMBER_HOST "originalMemberHost"
#define SYSDB_USN "entryUSN"
#define SYSDB_HIGH_USN "highestUSN"
#define SYSDB_SSH_PUBKEY "sshPublicKey"
#define SYSDB_AUTH_TYPE "authType"
#define SYSDB_SUBDOMAIN_REALM "realmName"
#define SYSDB_SUBDOMAIN_FLAT "flatName"
#define SYSDB_SUBDOMAIN_ID "domainID"
#define SYSDB_SUBDOMAIN_MPG "mpg"
#define SYSDB_SUBDOMAIN_ENUM "enumerate"
#define SYSDB_SUBDOMAIN_FOREST "memberOfForest"
#define SYSDB_BASE_ID "baseID"
#define SYSDB_ID_RANGE_SIZE "idRangeSize"
#define SYSDB_BASE_RID "baseRID"
#define SYSDB_SECONDARY_BASE_RID "secondaryBaseRID"
#define SYSDB_DOMAIN_ID "domainID"
#define SYSDB_ID_RANGE_TYPE "idRangeType"
#define ORIGINALAD_PREFIX "originalAD"
#define OVERRIDE_PREFIX "override"
#define SYSDB_DEFAULT_OVERRIDE_NAME "defaultOverrideName"
#define SYSDB_AD_ACCOUNT_EXPIRES "adAccountExpires"
#define SYSDB_AD_USER_ACCOUNT_CONTROL "adUserAccountControl"
#define SYSDB_VIEW_CLASS "view"
#define SYSDB_VIEW_NAME "viewName"
#define SYSDB_DEFAULT_VIEW_NAME "default"
#define SYSDB_OVERRIDE_CLASS "overrride"
#define SYSDB_OVERRIDE_ANCHOR_UUID "overrideAnchorUUID"
#define SYSDB_OVERRIDE_USER_CLASS "userOverride"
#define SYSDB_OVERRIDE_GROUP_CLASS "groupOverride"
#define SYSDB_OVERRIDE_DN "overrideDN"
#define SYSDB_OVERRIDE_OBJECT_DN "overrideObjectDN"
#define SYSDB_PWNAM_FILTER "(&("SYSDB_UC")(|("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME"=%s)))"
#define SYSDB_GRNAM_FILTER "(&("SYSDB_GC")(|("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME"=%s)))"
#define SYSDB_GRNAM_MPG_FILTER "(&("SYSDB_MPGC")(|("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME"=%s)))"
#define SYSDB_NETGR_FILTER "(&("SYSDB_NC")(|("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME"=%s)))"
#define SYSDB_NETGR_TRIPLES_FILTER "(|("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME"=%s)("SYSDB_NAME_ALIAS"=%s)("SYSDB_MEMBEROF"=%s))"
#define SYSDB_HAS_ENUMERATED "has_enumerated"
#define SYSDB_DEFAULT_ATTRS SYSDB_LAST_UPDATE, \
SYSDB_UPN, \
NULL}
SYSDB_GHOST, \
NULL}
NULL}
#define SYSDB_INITGR_ATTR SYSDB_MEMBEROF
SYSDB_NAME, \
NULL}
#define SYSDB_MOD_ADD LDB_FLAG_MOD_ADD
#define SYSDB_MOD_DEL LDB_FLAG_MOD_DELETE
#define SYSDB_MOD_REP LDB_FLAG_MOD_REPLACE
/* sysdb version check macros */
#define SYSDB_VERSION_ERROR_HINT \
"but note that removing cache files will also remove all of your " \
"cached credentials.\n")
#define SYSDB_VERSION_LOWER_ERROR(ret) do { \
ERROR("Lower version of database is expected!\n"); \
} \
} while(0)
#define SYSDB_VERSION_HIGHER_ERROR(ret) do { \
if (ret == EMEDIUMTYPE) { \
ERROR("Higher version of database is expected!\n"); \
ERROR("In order to upgrade the database, you must run SSSD.\n"); \
} \
} while(0)
/* use this in daemons */
#define SYSDB_VERSION_ERROR_DAEMON(ret) \
/* use this in tools */
#define SYSDB_VERSION_ERROR(ret) \
struct confdb_ctx;
struct sysdb_ctx;
struct sysdb_attrs {
int num;
struct ldb_message_element *a;
};
/* sysdb_attrs helper functions */
struct range_info {
char *name;
char *trusted_dom_sid;
char *range_type;
};
/* values are copied in the structure, allocated on "attrs" */
const char *value);
struct sysdb_attrs *dst,
const char *name);
struct ldb_message_element **el);
const char **string);
struct ldb_message_element *el);
bool *value);
const char *newname);
const char *attr_name,
const char *domain,
const char *const *list);
struct sysdb_attrs *attrs,
const char *ldap_attr,
const char **_primary);
struct sysdb_attrs *attrs,
const char *primary,
bool lowercase,
const char ***_aliases);
struct sysdb_attrs **attr_list,
const char *ldap_attr,
char ***name_list);
struct sss_domain_info *domain,
const char *name_or_upn,
const char **_cname);
struct ldb_message **msgs,
struct sysdb_attrs ***attrs);
/* convert an ldb error into an errno error */
int sysdb_error_to_errno(int ldberr);
/* DNs related helper functions */
const char *name);
const char *name);
struct sss_domain_info *dom);
struct sss_domain_info *dom);
struct sss_domain_info *dom,
const char *object_name,
const char *subtree_name);
struct sss_domain_info *dom,
const char *subtree_name);
/* functions to start and finish transactions */
/* functions related to subdomains */
const char* forest);
struct range_info ***range_list);
struct range_info **ranges);
char **view_name);
struct sysdb_attrs *override_attrs,
struct sss_domain_info *domain,
const char *name,
const char **attrs,
struct ldb_result **override_obj,
struct ldb_result **orig_obj);
struct sss_domain_info *domain,
const char *name,
const char **attrs,
struct ldb_result **override_obj,
struct ldb_result **orig_obj);
struct sss_domain_info *domain,
const char *name,
struct ldb_result **override_obj,
struct ldb_result **orig_obj);
struct sss_domain_info *domain,
const char *name,
struct ldb_result **override_obj,
struct ldb_result **orig_obj);
struct sss_domain_info *domain,
struct ldb_result **override_obj,
struct ldb_result **orig_obj);
struct sss_domain_info *domain,
struct ldb_result **override_obj,
struct ldb_result **orig_obj);
struct ldb_message *obj,
struct ldb_message *override_obj,
const char **req_attrs);
struct ldb_message *obj);
struct sss_domain_info *domain,
const char *name,
struct ldb_result **res);
struct sss_domain_info *domain,
struct ldb_result **res);
struct sss_domain_info *domain,
const char *name,
struct ldb_result **res);
struct sss_domain_info *domain,
struct ldb_result **res);
struct ldb_message_element *
const struct ldb_message *msg,
const char *attr_name);
const struct ldb_message *msg,
const char *attr_name,
const char * default_value);
const struct ldb_message *msg,
const char *attr_name,
/* Sysdb initialization.
* call this function *only* once to initialize the database and get
* the sysdb ctx */
struct sss_domain_info *domains,
bool allow_upgrade);
/* Same as sysdb_init, but additionally allows to change
* file ownership of the sysdb databases. */
struct sss_domain_info *domains,
bool allow_upgrade,
bool chown_dbfile,
/* used to initialize only one domain database.
* Do NOT use if sysdb_init has already been called */
struct sss_domain_info *domain,
const char *db_path,
/* functions to retrieve information from sysdb
* These functions automatically starts an operation
* therefore they cannot be called within a transaction */
struct sss_domain_info *domain,
const char *name,
struct ldb_result **res);
struct sss_domain_info *domain,
struct ldb_result **res);
struct sss_domain_info *domain,
struct ldb_result **res);
struct sss_domain_info *domain,
struct ldb_result **res);
struct sss_domain_info *domain,
const char *name,
struct ldb_result **res);
struct sss_domain_info *domain,
struct ldb_result **res);
struct sss_domain_info *domain,
struct ldb_result **res);
struct sss_domain_info *domain,
struct ldb_result **res);
struct sysdb_netgroup_ctx {
union {
struct {
char *hostname;
char *username;
char *domainname;
} triple;
char *groupname;
} value;
};
struct sss_domain_info *domain,
const char *netgroup,
struct ldb_result **res);
struct sss_domain_info *domain,
const char *name,
struct ldb_result **res);
struct sss_domain_info *domain,
const char *name,
struct ldb_result **res);
struct sss_domain_info *domain,
const char *name,
const char **attributes,
struct ldb_result **res);
struct sss_domain_info *domain,
const char *name,
const char **attributes,
struct ldb_result **res);
struct sss_domain_info *domain,
const char *netgrname,
const char **attributes,
struct ldb_result **res);
/* functions that modify the databse
* they have to be called within a transaction
* See sysdb_transaction_send()/_recv() */
/* Permissive modify */
struct ldb_message *msg);
/* Delete Entry */
bool ignore_not_found);
bool ignore_not_found);
/* Search Entry */
const char *filter,
const char **attrs,
struct ldb_message ***_msgs);
exp_fmt, ...) do { \
int _sls_lret; \
\
exp_fmt, ##__VA_ARGS__); \
} \
} while(0)
/* Search User (by uid, sid or name) */
struct sss_domain_info *domain,
const char *name,
const char **attrs,
struct ldb_message **msg);
struct sss_domain_info *domain,
const char **attrs,
struct ldb_message **msg);
struct sss_domain_info *domain,
const char *sid_str,
const char **attrs,
struct ldb_message **msg);
struct sss_domain_info *domain,
const char *sid_str,
const char **attrs,
struct ldb_message **msg);
/* Search Group (by gid, sid or name) */
struct sss_domain_info *domain,
const char *name,
const char **attrs,
struct ldb_message **msg);
struct sss_domain_info *domain,
const char **attrs,
struct ldb_message **msg);
struct sss_domain_info *domain,
const char *sid_str,
const char **attrs,
struct ldb_message **msg);
/* Search Netgroup (by name) */
struct sss_domain_info *domain,
const char *name,
const char **attrs,
struct ldb_message **msg);
/* Replace entry attrs */
struct sysdb_attrs *attrs,
int mod_op);
/* Replace user attrs */
const char *name,
struct sysdb_attrs *attrs,
int mod_op);
/* Replace group attrs */
const char *name,
struct sysdb_attrs *attrs,
int mod_op);
/* Replace netgroup attrs */
const char *name,
struct sysdb_attrs *attrs,
int mod_op);
/* Allocate a new id */
/* Add user (only basic attrs and w/o checks) */
const char *name,
const char *gecos,
const char *homedir,
const char *shell);
/* Add user (all checks) */
const char *name,
const char *gecos,
const char *homedir,
const char *shell,
const char *orig_dn,
struct sysdb_attrs *attrs,
int cache_timeout,
/* Add group (only basic attrs and w/o checks) */
/* Add group (all checks) */
struct sysdb_attrs *attrs,
int cache_timeout,
const char *name,
const char *original_dn,
const char *sid_str,
bool posix,
/* Add netgroup (only basic attrs and w/o checks) */
const char *name, const char *description);
const char *name,
const char *description,
struct sysdb_attrs *attrs,
char **missing,
int cache_timeout,
/* mod_op must be either LDB_FLAG_MOD_ADD or LDB_FLAG_MOD_DELETE */
int mod_op);
const char *name,
const char *pwd,
const char *gecos,
const char *homedir,
const char *shell,
const char *orig_dn,
struct sysdb_attrs *attrs,
char **remove_attrs,
const char *name,
struct sysdb_attrs *attrs,
enum sysdb_member_type {
};
const char *group,
const char *member,
enum sysdb_member_type type,
bool is_dn);
const char *group,
const char *member,
enum sysdb_member_type type,
bool is_dn);
const char *member,
enum sysdb_member_type type,
const char *const *add_groups,
const char *const *del_groups);
const char *member,
enum sysdb_member_type type,
const char *const *add_groups,
const char *const *del_groups);
const char *view_name,
enum sysdb_member_type type,
/* Password caching function.
* If you are in a transaction ignore sysdb and pass in the handle.
* If you are not in a transaction pass NULL in handle and provide sysdb,
* in this case a transaction will be automatically started and the
* function will be completely wrapped in it's own sysdb transaction */
const char *username,
const char *password);
struct ldb_message *ldb_msg,
const char *name,
const char *password,
struct confdb_ctx *cdb,
bool just_check,
const char *object_name,
const char *subtree_name,
struct sysdb_attrs *attrs);
struct sss_domain_info *domain,
const char *filter,
const char *subtree_name,
const char **attrs,
struct ldb_message ***msgs);
struct sss_domain_info *domain,
const char *object_name,
const char *subtree_name,
const char **attrs,
struct ldb_message ***_msgs);
const char *object_name,
const char *subtree_name);
struct sss_domain_info *domain,
const char *expression,
const char *asq_attribute,
const char **attrs,
struct ldb_message ***msgs);
struct sss_domain_info *domain,
const char *sub_filter,
const char **attrs,
struct ldb_message ***msgs);
struct sss_domain_info *domain,
const char *sub_filter,
const char **attrs,
struct ldb_message ***msgs);
struct sss_domain_info *domain,
const char *sub_filter,
const char **attrs,
struct ldb_message ***msgs);
const char *name);
struct sss_domain_info *domain,
const char *sid_str);
struct sysdb_attrs **attrs,
int attr_count,
const char *attr_name,
char ***_list);
struct ldb_result *res,
struct sysdb_netgroup_ctx ***entries);
char **sanitized);
const char *attr_name,
bool *value);
const char *cn_value,
const char *attr_name,
bool value);
bool *has_enumerated);
bool enumerated);
const char *name,
enum sysdb_member_type type,
char **remove_attrs);
struct sss_domain_info *dom,
enum sysdb_member_type mtype,
const char *name,
char ***_direct_parents);
/* === Functions related to ID-mapping === */
#define SYSDB_IDMAP_CONTAINER "cn=id_mappings"
#define SYSDB_IDMAP_SUBTREE "idmap"
#define SYSDB_IDMAP_MAPPING_OC "id_mapping"
#define SYSDB_IDMAP_SID_ATTR "objectSID"
#define SYSDB_IDMAP_SLICE_ATTR "slice"
#define SYSDB_IDMAP_ATTRS { \
SYSDB_NAME, \
NULL }
const char *dom_name,
const char *dom_sid,
struct sss_domain_info *domain,
struct ldb_result **_result);
struct sss_domain_info *domain,
const char *sid_str,
const char **attrs,
struct ldb_result **res);
struct sss_domain_info *domain,
const char *uuid_str,
const char **attrs,
struct ldb_result **res);
/* === Functions related to GPOs === */
#define SYSDB_GPO_CONTAINER "cn=gpos,cn=ad,cn=custom"
/* === Functions related to GPO entries === */
#define SYSDB_GPO_OC "gpo"
#define SYSDB_GPO_GUID_ATTR "gpoGUID"
#define SYSDB_GPO_VERSION_ATTR "gpoVersion"
#define SYSDB_GPO_TIMEOUT_ATTR "gpoPolicyFileTimeout"
#define SYSDB_GPO_ATTRS { \
SYSDB_NAME, \
NULL }
const char *gpo_guid,
int gpo_version,
int cache_timeout,
struct sss_domain_info *domain,
const char *gpo_guid,
struct ldb_result **_result);
struct sss_domain_info *domain,
struct ldb_result **_result);
/* === Functions related to GPO Result object === */
#define SYSDB_GPO_RESULT_OC "gpo_result"
struct sss_domain_info *domain,
struct ldb_result **_result);
struct sss_domain_info *domain);
const char *policy_setting_key,
const char *policy_setting_value);
struct sss_domain_info *domain,
const char *policy_setting_key,
const char **policy_setting_value);
struct sss_domain_info *dom,
const char *group_name,
const char ***_sids,
const char ***_dns,
#endif /* __SYS_DB_H__ */