1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _ADUTILS_IMPL_H 27 #define _ADUTILS_IMPL_H 28 29 #include <stdlib.h> 30 #include <stdio.h> 31 #include <sys/types.h> 32 #include <ldap.h> 33 #include <pthread.h> 34 #include "addisc.h" 35 #include "idmap_priv.h" 36 #include "idmap_prot.h" 37 #include "libadutils.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 #define ADUTILS_SEARCH_TIMEOUT 3 44 #define ADUTILS_LDAP_OPEN_TIMEOUT 1 45 46 /* 47 * Maximum string SID size. 4 bytes for "S-1-", 15 for 2^48 (max authority), 48 * another '-', and ridcount (max 15) 10-digit RIDs plus '-' in between, plus 49 * a null. 50 */ 51 #define MAXSID 185 52 #define MAXDOMAINNAME 256 53 54 typedef struct adutils_sid { 55 uchar_t version; 56 uchar_t sub_authority_count; 57 uint64_t authority; /* really, 48-bits */ 58 uint32_t sub_authorities[ADUTILS_SID_MAX_SUB_AUTHORITIES]; 59 } adutils_sid_t; 60 61 struct adutils_host; 62 63 struct known_domain { 64 char name[MAXDOMAINNAME]; 65 char sid[MAXSID]; 66 }; 67 68 69 /* A set of DSs for a given AD partition */ 70 struct adutils_ad { 71 char *dflt_w2k_dom; /* used to qualify bare names */ 72 int num_known_domains; 73 struct known_domain *known_domains; 74 pthread_mutex_t lock; 75 uint32_t ref; 76 struct adutils_host *last_adh; 77 adutils_ad_partition_t partition; /* Data or global catalog? */ 78 }; 79 80 typedef struct adutils_attr { 81 char *attr_name; 82 uint_t num_values; 83 char **attr_values; 84 } adutils_attr_t; 85 86 /* typedef in libadutils.h */ 87 struct adutils_entry { 88 uint_t num_nvpairs; 89 adutils_attr_t *attr_nvpairs; 90 struct adutils_entry *next; 91 }; 92 93 /* typedef in libadutils.h */ 94 struct adutils_result { 95 uint_t num_entries; 96 adutils_entry_t *entries; 97 }; 98 99 /* A single DS */ 100 typedef struct adutils_host { 101 struct adutils_host *next; 102 struct adutils_ad *owner; /* ad_t to which this belongs */ 103 pthread_mutex_t lock; 104 LDAP *ld; /* LDAP connection */ 105 uint32_t ref; /* ref count */ 106 time_t idletime; /* time since last activity */ 107 int dead; /* error on LDAP connection */ 108 /* 109 * Used to distinguish between different instances of LDAP 110 * connections to this same DS. We need this so we never mix up 111 * results for a given msgID from one connection with those of 112 * another earlier connection where two batch state structures 113 * share this adutils_host object but used different LDAP connections 114 * to send their LDAP searches. 115 */ 116 uint64_t generation; 117 118 /* LDAP DS info */ 119 char *host; 120 int port; 121 122 /* hardwired to SASL GSSAPI only for now */ 123 char *saslmech; 124 unsigned saslflags; 125 126 /* Number of outstanding search requests */ 127 uint32_t max_requests; 128 uint32_t num_requests; 129 } adutils_host_t; 130 131 /* A place to put the results of a batched (async) query */ 132 typedef struct adutils_q { 133 const char *edomain; /* expected domain name */ 134 struct adutils_result **result; /* The LDAP search result */ 135 adutils_rc *rc; 136 int msgid; /* LDAP message ID */ 137 } adutils_q_t; 138 139 /* Batch context structure */ 140 struct adutils_query_state { 141 struct adutils_query_state *next; 142 int qsize; /* Size of queries */ 143 int ref_cnt; /* reference count */ 144 pthread_cond_t cv; /* Condition wait variable */ 145 uint32_t qcount; /* Number of items queued */ 146 uint32_t qinflight; /* how many queries in flight */ 147 uint16_t qdead; /* oops, lost LDAP connection */ 148 adutils_host_t *qadh; /* LDAP connection */ 149 uint64_t qadh_gen; /* same as qadh->generation */ 150 adutils_ldap_res_search_cb ldap_res_search_cb; 151 void *ldap_res_search_argp; 152 char *default_domain; 153 char *basedn; 154 adutils_q_t queries[1]; /* array of query results */ 155 }; 156 157 #ifdef __cplusplus 158 } 159 #endif 160 161 #endif /* _ADUTILS_IMPL_H */ 162