12b4a7802SBaban Kenkre /* 22b4a7802SBaban Kenkre * CDDL HEADER START 32b4a7802SBaban Kenkre * 42b4a7802SBaban Kenkre * The contents of this file are subject to the terms of the 52b4a7802SBaban Kenkre * Common Development and Distribution License (the "License"). 62b4a7802SBaban Kenkre * You may not use this file except in compliance with the License. 72b4a7802SBaban Kenkre * 82b4a7802SBaban Kenkre * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92b4a7802SBaban Kenkre * or http://www.opensolaris.org/os/licensing. 102b4a7802SBaban Kenkre * See the License for the specific language governing permissions 112b4a7802SBaban Kenkre * and limitations under the License. 122b4a7802SBaban Kenkre * 132b4a7802SBaban Kenkre * When distributing Covered Code, include this CDDL HEADER in each 142b4a7802SBaban Kenkre * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152b4a7802SBaban Kenkre * If applicable, add the following below this CDDL HEADER, with the 162b4a7802SBaban Kenkre * fields enclosed by brackets "[]" replaced with your own identifying 172b4a7802SBaban Kenkre * information: Portions Copyright [yyyy] [name of copyright owner] 182b4a7802SBaban Kenkre * 192b4a7802SBaban Kenkre * CDDL HEADER END 202b4a7802SBaban Kenkre */ 212b4a7802SBaban Kenkre /* 222b4a7802SBaban Kenkre * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 232b4a7802SBaban Kenkre * Use is subject to license terms. 242b4a7802SBaban Kenkre */ 252b4a7802SBaban Kenkre 262b4a7802SBaban Kenkre #ifndef _LIBADUTILS_H 272b4a7802SBaban Kenkre #define _LIBADUTILS_H 282b4a7802SBaban Kenkre 292b4a7802SBaban Kenkre #include <stdlib.h> 302b4a7802SBaban Kenkre #include <stdio.h> 312b4a7802SBaban Kenkre #include <sys/types.h> 322b4a7802SBaban Kenkre #include <rpc/rpc.h> 332b4a7802SBaban Kenkre #include <ldap.h> 342b4a7802SBaban Kenkre 352b4a7802SBaban Kenkre #ifdef __cplusplus 362b4a7802SBaban Kenkre extern "C" { 372b4a7802SBaban Kenkre #endif 382b4a7802SBaban Kenkre 392b4a7802SBaban Kenkre #define ADUTILS_DEF_NUM_RETRIES 2 402b4a7802SBaban Kenkre #define ADUTILS_SID_MAX_SUB_AUTHORITIES 15 412b4a7802SBaban Kenkre #define ADUTILS_MAXBINSID\ 422b4a7802SBaban Kenkre (1 + 1 + 6 + (ADUTILS_SID_MAX_SUB_AUTHORITIES * 4)) 432b4a7802SBaban Kenkre #define ADUTILS_MAXHEXBINSID (ADUTILS_MAXBINSID * 3) 442b4a7802SBaban Kenkre 452b4a7802SBaban Kenkre typedef struct adutils_ad adutils_ad_t; 462b4a7802SBaban Kenkre typedef struct adutils_entry adutils_entry_t; 472b4a7802SBaban Kenkre typedef struct adutils_result adutils_result_t; 482b4a7802SBaban Kenkre typedef struct adutils_ctx adutils_ctx_t; 492b4a7802SBaban Kenkre typedef struct adutils_query_state adutils_query_state_t; 502b4a7802SBaban Kenkre 512b4a7802SBaban Kenkre /* 522b4a7802SBaban Kenkre * Typedef for callback routine for adutils_lookup_batch_start. 532b4a7802SBaban Kenkre * This callback routine is used to process the result of 542b4a7802SBaban Kenkre * ldap_result(3LDAP). 552b4a7802SBaban Kenkre * ld - LDAP handle used by ldap_result(3LDAP) 562b4a7802SBaban Kenkre * res - Entry returned by ldap_result(3LDAP) 572b4a7802SBaban Kenkre * rc - Return value of ldap_result(3LDAP) 582b4a7802SBaban Kenkre * qid - Query ID that corresponds to the result. 592b4a7802SBaban Kenkre * argp - Argument passed by the caller at the time 602b4a7802SBaban Kenkre * of adutils_lookup_batch_start. 612b4a7802SBaban Kenkre */ 622b4a7802SBaban Kenkre typedef void (*adutils_ldap_res_search_cb)(LDAP *ld, LDAPMessage **res, 632b4a7802SBaban Kenkre int rc, int qid, void *argp); 642b4a7802SBaban Kenkre 652b4a7802SBaban Kenkre typedef enum { 662b4a7802SBaban Kenkre ADUTILS_SUCCESS = 0, 672b4a7802SBaban Kenkre ADUTILS_ERR_INTERNAL = -10000, 682b4a7802SBaban Kenkre ADUTILS_ERR_OTHER, 692b4a7802SBaban Kenkre ADUTILS_ERR_NOTFOUND, 702b4a7802SBaban Kenkre ADUTILS_ERR_RETRIABLE_NET_ERR, 712b4a7802SBaban Kenkre ADUTILS_ERR_MEMORY, 722b4a7802SBaban Kenkre ADUTILS_ERR_DOMAIN 732b4a7802SBaban Kenkre } adutils_rc; 742b4a7802SBaban Kenkre 752b4a7802SBaban Kenkre /* 762b4a7802SBaban Kenkre * We use the port numbers for normal LDAP and global catalog LDAP as 772b4a7802SBaban Kenkre * the enum values for this enumeration. Clever? Silly? You decide. 782b4a7802SBaban Kenkre * Although we never actually use these enum values as port numbers and 792b4a7802SBaban Kenkre * never will, so this is just cute. 802b4a7802SBaban Kenkre */ 812b4a7802SBaban Kenkre typedef enum adutils_ad_partition { 822b4a7802SBaban Kenkre ADUTILS_AD_DATA = 389, 832b4a7802SBaban Kenkre ADUTILS_AD_GLOBAL_CATALOG = 3268 842b4a7802SBaban Kenkre } adutils_ad_partition_t; 852b4a7802SBaban Kenkre 862b4a7802SBaban Kenkre 872b4a7802SBaban Kenkre /* 882b4a7802SBaban Kenkre * adutils interfaces: 892b4a7802SBaban Kenkre * 902b4a7802SBaban Kenkre * - an adutils_ad_t represents an AD partition 912b4a7802SBaban Kenkre * - a DS (hostname + port, if port != 0) can be added/removed from an 922b4a7802SBaban Kenkre * adutils_ad_t 932b4a7802SBaban Kenkre * - an adutils_ad_t can be allocated, ref'ed and released; last release 942b4a7802SBaban Kenkre * releases resources 952b4a7802SBaban Kenkre * 962b4a7802SBaban Kenkre * 972b4a7802SBaban Kenkre * adutils_lookup_batch_xxx interfaces: 982b4a7802SBaban Kenkre * 992b4a7802SBaban Kenkre * These interfaces allow the caller to batch AD lookup requests. The 1002b4a7802SBaban Kenkre * batched requests are processed asynchronously. The actual lookup 1012b4a7802SBaban Kenkre * is currently implement using libldap's ldap_search_ext(3LDAP) and 1022b4a7802SBaban Kenkre * ldap_result(3LDAP) APIs. 1032b4a7802SBaban Kenkre * 1042b4a7802SBaban Kenkre * Example: 1052b4a7802SBaban Kenkre * adutils_query_state_t *qs; 1062b4a7802SBaban Kenkre * adutils_lookup_batch_start(..., &qs); 1072b4a7802SBaban Kenkre * for each request { 1082b4a7802SBaban Kenkre * rc = adutils_lookup_batch_add(qs, ...); 1092b4a7802SBaban Kenkre * if (rc != success) 1102b4a7802SBaban Kenkre * break; 1112b4a7802SBaban Kenkre * } 1122b4a7802SBaban Kenkre * if (rc == success) 1132b4a7802SBaban Kenkre * adutils_lookup_batch_end(&qs); 1142b4a7802SBaban Kenkre * else 1152b4a7802SBaban Kenkre * adutils_lookup_batch_release(&qs); 1162b4a7802SBaban Kenkre * 1172b4a7802SBaban Kenkre * The adutils_lookup_batch_start interface allows the caller to pass 1182b4a7802SBaban Kenkre * in a callback function that's invoked when ldap_result() returns 1192b4a7802SBaban Kenkre * LDAP_RES_SEARCH_RESULT and LDAP_RES_SEARCH_ENTRY for each request. 1202b4a7802SBaban Kenkre * 1212b4a7802SBaban Kenkre * If no callback is provided then adutils batch API falls back to its 1222b4a7802SBaban Kenkre * default behaviour which is: 1232b4a7802SBaban Kenkre * For LDAP_RES_SEARCH_ENTRY, add the entry to the entry set. 1242b4a7802SBaban Kenkre * For LDAP_RES_SEARCH_RESULT, set return code to 1252b4a7802SBaban Kenkre * ADUTILS_ERR_NOTFOUND if the entry set is empty. 1262b4a7802SBaban Kenkre * 1272b4a7802SBaban Kenkre * See $SRC/cmd/idmap/idmapd/adutils.c for an example of 1282b4a7802SBaban Kenkre * non-default callback routine. 1292b4a7802SBaban Kenkre * 1302b4a7802SBaban Kenkre */ 1312b4a7802SBaban Kenkre 1322b4a7802SBaban Kenkre extern adutils_rc adutils_ad_alloc(adutils_ad_t **new_ad, 1332b4a7802SBaban Kenkre const char *default_domain, 1342b4a7802SBaban Kenkre adutils_ad_partition_t part); 1352b4a7802SBaban Kenkre extern void adutils_ad_free(adutils_ad_t **ad); 1362b4a7802SBaban Kenkre extern adutils_rc adutils_add_ds(adutils_ad_t *ad, 1372b4a7802SBaban Kenkre const char *host, int port); 138*4d61c878SJulian Pullen extern adutils_rc adutils_add_domain(adutils_ad_t *ad, 139*4d61c878SJulian Pullen const char *domain_name, 140*4d61c878SJulian Pullen const char *domain_sid); 1412b4a7802SBaban Kenkre extern void adutils_set_log(int pri, bool_t syslog, 1422b4a7802SBaban Kenkre bool_t degraded); 1432b4a7802SBaban Kenkre extern void adutils_freeresult(adutils_result_t **result); 1442b4a7802SBaban Kenkre extern adutils_rc adutils_lookup(adutils_ad_t *ad, 1452b4a7802SBaban Kenkre const char *searchfilter, 1462b4a7802SBaban Kenkre const char **attrs, const char *domain, 1472b4a7802SBaban Kenkre adutils_result_t **result); 1482b4a7802SBaban Kenkre extern char **adutils_getattr(const adutils_entry_t *entry, 1492b4a7802SBaban Kenkre const char *attrname); 1502b4a7802SBaban Kenkre extern const adutils_entry_t *adutils_getfirstentry( 1512b4a7802SBaban Kenkre adutils_result_t *result); 1522b4a7802SBaban Kenkre extern int adutils_txtsid2hexbinsid(const char *txt, 1532b4a7802SBaban Kenkre const uint32_t *rid, 1542b4a7802SBaban Kenkre char *hexbinsid, int hexbinsidlen); 1552b4a7802SBaban Kenkre extern char *adutils_bv_name2str(BerValue *bval); 1562b4a7802SBaban Kenkre extern char *adutils_bv_objsid2sidstr(BerValue *bval, 1572b4a7802SBaban Kenkre uint32_t *rid); 1582b4a7802SBaban Kenkre extern void adutils_reap_idle_connections(void); 1592b4a7802SBaban Kenkre extern char *adutils_dn2dns(const char *dn); 1602b4a7802SBaban Kenkre extern adutils_rc adutils_lookup_batch_start(adutils_ad_t *ad, 1612b4a7802SBaban Kenkre int nqueries, 1622b4a7802SBaban Kenkre adutils_ldap_res_search_cb ldap_res_search_cb, 1632b4a7802SBaban Kenkre void *ldap_res_search_argp, 1642b4a7802SBaban Kenkre adutils_query_state_t **state); 1652b4a7802SBaban Kenkre extern adutils_rc adutils_lookup_batch_add(adutils_query_state_t *state, 1662b4a7802SBaban Kenkre const char *filter, const char **attrs, 1672b4a7802SBaban Kenkre const char *edomain, adutils_result_t **result, 1682b4a7802SBaban Kenkre adutils_rc *rc); 1692b4a7802SBaban Kenkre extern adutils_rc adutils_lookup_batch_end( 1702b4a7802SBaban Kenkre adutils_query_state_t **state); 1712b4a7802SBaban Kenkre extern void adutils_lookup_batch_release( 1722b4a7802SBaban Kenkre adutils_query_state_t **state); 1732b4a7802SBaban Kenkre extern const char *adutils_lookup_batch_getdefdomain( 1742b4a7802SBaban Kenkre adutils_query_state_t *state); 175*4d61c878SJulian Pullen extern int adutils_lookup_check_domain( 176*4d61c878SJulian Pullen adutils_query_state_t *state, 177*4d61c878SJulian Pullen const char *domain); 178*4d61c878SJulian Pullen extern int adutils_lookup_check_sid_prefix( 179*4d61c878SJulian Pullen adutils_query_state_t *state, 180*4d61c878SJulian Pullen const char *sid); 1812b4a7802SBaban Kenkre 1822b4a7802SBaban Kenkre #ifdef __cplusplus 1832b4a7802SBaban Kenkre } 1842b4a7802SBaban Kenkre #endif 1852b4a7802SBaban Kenkre 1862b4a7802SBaban Kenkre #endif /* _LIBADUTILS_H */ 187