UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2023 Olaf Wintermann. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef LDAP_RESOURCE_H 30 #define LDAP_RESOURCE_H 31 32 #include "resourcepool.h" 33 34 #include <ldap.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #ifndef LDAP_PORT 41 #define LDAP_PORT 389 42 #endif 43 #ifndef LDAPS_PORT 44 #define LDAPS_PORT 636 45 #endif 46 47 typedef struct LDAPResourcePool { 48 /* 49 * ResourcePool parameters 50 */ 51 pblock *param; 52 53 /* 54 * Cfg memorypool 55 */ 56 pool_handle_t *pool; 57 58 /* 59 * ResourcePool name 60 */ 61 const char *name; 62 63 /* 64 * ldap uri 65 */ 66 char *ldap_uri; 67 68 /* 69 * ldap host 70 * 71 * only used when no ldap_uri is specified 72 */ 73 char *host; 74 75 /* 76 * ldap port 77 */ 78 int port; 79 80 /* 81 * admin binddn 82 */ 83 char *binddn; 84 85 /* 86 * admin bindpw 87 */ 88 char *bindpw; 89 90 /* 91 * bind every LDAP session to binddn 92 */ 93 WSBool bind; 94 95 96 } LDAPResourcePool; 97 98 typedef struct LDAPResource { 99 LDAP *ldap; 100 LDAPResourcePool *res_pool; 101 } LDAPResource; 102 103 ResourceType* ldap_get_resource_type(void); 104 105 106 LDAP* ws_ldap_resource_create_connection( 107 const char *hostname, 108 int port, 109 int ssl, 110 int ldap_version); 111 112 LDAP* ws_ldap_resource_create_uri_connection( 113 const char *uri, 114 int ldap_version); 115 116 void ws_ldap_close(LDAP *ldap); 117 118 119 /* resource pool implementation functions */ 120 void * ldap_resourcepool_init(pool_handle_t *pool, const char *rpname, pblock *pb); 121 void ldap_resourcepool_destroy(LDAPResourcePool *pool); 122 void * ldap_resourcepool_createresource(LDAPResourcePool *respool); 123 void ldap_resourcepool_freeresource(LDAPResourcePool *pool, LDAPResource *res); 124 int ldap_resourcepool_prepare(LDAPResourcePool *pool, LDAPResource *res); 125 int ldap_resourcepool_finish(LDAPResourcePool *pool, LDAPResource *res); 126 void * ldap_resourcepool_getresourcedata(LDAPResource *res); 127 128 129 int ldap_resource_bind(LDAPResourcePool *respool, LDAP *ldap, struct berval **server_cred); 130 131 int ws_ldap_bind(LDAP *ldap, const char *binddn, const char *bindpw, struct berval **server_cred); 132 133 134 135 #ifdef __cplusplus 136 } 137 #endif 138 139 #endif /* LDAP_RESOURCE_H */ 140 141