1 /* $NetBSD: back-ndb.h,v 1.3 2021/08/14 16:15:00 christos Exp $ */ 2 3 /* $OpenLDAP$ */ 4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 2008-2021 The OpenLDAP Foundation. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted only as authorized by the OpenLDAP 11 * Public License. 12 * 13 * A copy of this license is available in the file LICENSE in the 14 * top-level directory of the distribution or, alternatively, at 15 * <http://www.OpenLDAP.org/license.html>. 16 */ 17 /* ACKNOWLEDGEMENTS: 18 * This work was initially developed by Howard Chu for inclusion 19 * in OpenLDAP Software. This work was sponsored by MySQL. 20 */ 21 22 #ifndef SLAPD_NDB_H 23 #define SLAPD_NDB_H 24 25 #include "slap.h" 26 27 #include <mysql.h> 28 #include <NdbApi.hpp> 29 30 LDAP_BEGIN_DECL 31 32 /* The general design is to use one relational table per objectclass. This is 33 * complicated by objectclass inheritance and auxiliary classes though. 34 * 35 * Attributes must only occur in a single table. For objectclasses that inherit 36 * from other classes, attributes defined in the superior class are only stored 37 * in the superior class' table. When multiple unrelated classes define the same 38 * attributes, an attributeSet should be defined instead, containing all of the 39 * common attributes. 40 * 41 * The no_set table lists which other attributeSets apply to the current 42 * objectClass. The no_attrs table lists all of the non-inherited attributes of 43 * the class, including those residing in an attributeSet. 44 * 45 * Usually the table is named identically to the objectClass, but it can also 46 * be explicitly named something else if needed. 47 */ 48 #define NDB_MAX_OCSETS 8 49 50 struct ndb_attrinfo; 51 52 typedef struct ndb_ocinfo { 53 struct berval no_name; /* objectclass cname */ 54 struct berval no_table; 55 ObjectClass *no_oc; 56 struct ndb_ocinfo *no_sets[NDB_MAX_OCSETS]; 57 struct ndb_attrinfo **no_attrs; 58 int no_flag; 59 int no_nsets; 60 int no_nattrs; 61 } NdbOcInfo; 62 63 #define NDB_INFO_ATLEN 0x01 64 #define NDB_INFO_ATSET 0x02 65 #define NDB_INFO_INDEX 0x04 66 #define NDB_INFO_ATBLOB 0x08 67 68 typedef struct ndb_attrinfo { 69 struct berval na_name; /* attribute cname */ 70 AttributeDescription *na_desc; 71 AttributeType *na_attr; 72 NdbOcInfo *na_oi; 73 int na_flag; 74 int na_len; 75 int na_column; 76 int na_ixcol; 77 } NdbAttrInfo; 78 79 typedef struct ListNode { 80 struct ListNode *ln_next; 81 void *ln_data; 82 } ListNode; 83 84 #define NDB_IS_OPEN(ni) (ni->ni_cluster != NULL) 85 86 struct ndb_info { 87 /* NDB connection */ 88 char *ni_connectstr; 89 char *ni_dbname; 90 Ndb_cluster_connection **ni_cluster; 91 92 /* MySQL connection parameters */ 93 MYSQL ni_sql; 94 char *ni_hostname; 95 char *ni_username; 96 char *ni_password; 97 char *ni_socket; 98 unsigned long ni_clflag; 99 unsigned int ni_port; 100 101 /* Search filter processing */ 102 int ni_search_stack_depth; 103 void *ni_search_stack; 104 105 #define DEFAULT_SEARCH_STACK_DEPTH 16 106 #define MINIMUM_SEARCH_STACK_DEPTH 8 107 108 /* Schema config */ 109 NdbOcInfo *ni_opattrs; 110 ListNode *ni_attridxs; 111 ListNode *ni_attrlens; 112 ListNode *ni_attrsets; 113 ListNode *ni_attrblobs; 114 ldap_pvt_thread_rdwr_t ni_ai_rwlock; 115 Avlnode *ni_ai_tree; 116 ldap_pvt_thread_rdwr_t ni_oc_rwlock; 117 Avlnode *ni_oc_tree; 118 int ni_nconns; /* number of connections to open */ 119 int ni_nextconn; /* next conn to use */ 120 ldap_pvt_thread_mutex_t ni_conn_mutex; 121 }; 122 123 #define NDB_MAX_RDNS 16 124 #define NDB_RDN_LEN 128 125 #define NDB_MAX_OCS 64 126 127 #define DN2ID_TABLE "OL_dn2id" 128 #define EID_COLUMN 0U 129 #define VID_COLUMN 1U 130 #define OCS_COLUMN 1U 131 #define RDN_COLUMN 2U 132 #define IDX_COLUMN (2U+NDB_MAX_RDNS) 133 134 #define NEXTID_TABLE "OL_nextid" 135 136 #define NDB_OC_BUFLEN 1026 /* 1024 data plus 2 len bytes */ 137 138 #define INDEX_NAME "OL_index" 139 140 typedef struct NdbRdns { 141 short nr_num; 142 char nr_buf[NDB_MAX_RDNS][NDB_RDN_LEN+1]; 143 } NdbRdns; 144 145 typedef struct NdbOcs { 146 int no_ninfo; 147 int no_ntext; 148 int no_nitext; /* number of implicit classes */ 149 NdbOcInfo *no_info[NDB_MAX_OCS]; 150 struct berval no_text[NDB_MAX_OCS]; 151 struct berval no_itext[NDB_MAX_OCS]; /* implicit classes */ 152 } NdbOcs; 153 154 typedef struct NdbArgs { 155 Ndb *ndb; 156 NdbTransaction *txn; 157 Entry *e; 158 NdbRdns *rdns; 159 struct berval *ocs; 160 int erdns; 161 } NdbArgs; 162 163 #define NDB_NO_SUCH_OBJECT 626 164 #define NDB_ALREADY_EXISTS 630 165 166 LDAP_END_DECL 167 168 #include "proto-ndb.h" 169 170 #endif 171