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 typedef struct adutils_sid { 47 uchar_t version; 48 uchar_t sub_authority_count; 49 uint64_t authority; /* really, 48-bits */ 50 uint32_t sub_authorities[ADUTILS_SID_MAX_SUB_AUTHORITIES]; 51 } adutils_sid_t; 52 53 struct adutils_host; 54 55 56 /* A set of DSs for a given AD partition */ 57 struct adutils_ad { 58 char *dflt_w2k_dom; /* used to qualify bare names */ 59 pthread_mutex_t lock; 60 uint32_t ref; 61 struct adutils_host *last_adh; 62 adutils_ad_partition_t partition; /* Data or global catalog? */ 63 }; 64 65 typedef struct adutils_attr { 66 char *attr_name; 67 uint_t num_values; 68 char **attr_values; 69 } adutils_attr_t; 70 71 /* typedef in libadutils.h */ 72 struct adutils_entry { 73 uint_t num_nvpairs; 74 adutils_attr_t *attr_nvpairs; 75 struct adutils_entry *next; 76 }; 77 78 /* typedef in libadutils.h */ 79 struct adutils_result { 80 uint_t num_entries; 81 adutils_entry_t *entries; 82 }; 83 84 /* A single DS */ 85 typedef struct adutils_host { 86 struct adutils_host *next; 87 struct adutils_ad *owner; /* ad_t to which this belongs */ 88 pthread_mutex_t lock; 89 LDAP *ld; /* LDAP connection */ 90 uint32_t ref; /* ref count */ 91 time_t idletime; /* time since last activity */ 92 int dead; /* error on LDAP connection */ 93 /* 94 * Used to distinguish between different instances of LDAP 95 * connections to this same DS. We need this so we never mix up 96 * results for a given msgID from one connection with those of 97 * another earlier connection where two batch state structures 98 * share this adutils_host object but used different LDAP connections 99 * to send their LDAP searches. 100 */ 101 uint64_t generation; 102 103 /* LDAP DS info */ 104 char *host; 105 int port; 106 107 /* hardwired to SASL GSSAPI only for now */ 108 char *saslmech; 109 unsigned saslflags; 110 111 /* Number of outstanding search requests */ 112 uint32_t max_requests; 113 uint32_t num_requests; 114 } adutils_host_t; 115 116 /* A place to put the results of a batched (async) query */ 117 typedef struct adutils_q { 118 const char *edomain; /* expected domain name */ 119 struct adutils_result **result; /* The LDAP search result */ 120 adutils_rc *rc; 121 int msgid; /* LDAP message ID */ 122 } adutils_q_t; 123 124 /* Batch context structure */ 125 struct adutils_query_state { 126 struct adutils_query_state *next; 127 int qcount; /* how many queries */ 128 int ref_cnt; /* reference count */ 129 pthread_cond_t cv; /* Condition wait variable */ 130 uint32_t qlastsent; 131 uint32_t qinflight; /* how many queries in flight */ 132 uint16_t qdead; /* oops, lost LDAP connection */ 133 adutils_host_t *qadh; /* LDAP connection */ 134 uint64_t qadh_gen; /* same as qadh->generation */ 135 adutils_ldap_res_search_cb ldap_res_search_cb; 136 void *ldap_res_search_argp; 137 char *default_domain; 138 char *basedn; 139 adutils_q_t queries[1]; /* array of query results */ 140 }; 141 142 #ifdef __cplusplus 143 } 144 #endif 145 146 #endif /* _ADUTILS_IMPL_H */ 147