17c478bd9Sstevel@tonic-gate /* 27800901eSjbeck * Copyright (c) 2001-2003, 2005-2007 Sendmail, Inc. and its suppliers. 37c478bd9Sstevel@tonic-gate * All rights reserved. 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * By using this file, you agree to the terms and conditions set 67c478bd9Sstevel@tonic-gate * forth in the LICENSE file which can be found at the top level of 77c478bd9Sstevel@tonic-gate * the sendmail distribution. 87c478bd9Sstevel@tonic-gate * 9*e9af4bc0SJohn Beck * $Id: ldap.h,v 1.34 2008/11/17 21:02:54 ca Exp $ 107c478bd9Sstevel@tonic-gate */ 117c478bd9Sstevel@tonic-gate 127c478bd9Sstevel@tonic-gate #ifndef SM_LDAP_H 137c478bd9Sstevel@tonic-gate # define SM_LDAP_H 147c478bd9Sstevel@tonic-gate 157c478bd9Sstevel@tonic-gate # include <sm/conf.h> 167c478bd9Sstevel@tonic-gate # include <sm/rpool.h> 177c478bd9Sstevel@tonic-gate 187c478bd9Sstevel@tonic-gate /* 197c478bd9Sstevel@tonic-gate ** NOTE: These should be changed from LDAPMAP_* to SM_LDAP_* 20058561cbSjbeck ** in the next major release (8.x+1) of sendmail. 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate 237c478bd9Sstevel@tonic-gate # ifndef LDAPMAP_MAX_ATTR 247c478bd9Sstevel@tonic-gate # define LDAPMAP_MAX_ATTR 64 257c478bd9Sstevel@tonic-gate # endif /* ! LDAPMAP_MAX_ATTR */ 267c478bd9Sstevel@tonic-gate # ifndef LDAPMAP_MAX_FILTER 277c478bd9Sstevel@tonic-gate # define LDAPMAP_MAX_FILTER 1024 287c478bd9Sstevel@tonic-gate # endif /* ! LDAPMAP_MAX_FILTER */ 297c478bd9Sstevel@tonic-gate # ifndef LDAPMAP_MAX_PASSWD 307c478bd9Sstevel@tonic-gate # define LDAPMAP_MAX_PASSWD 256 317c478bd9Sstevel@tonic-gate # endif /* ! LDAPMAP_MAX_PASSWD */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate # if LDAPMAP 347c478bd9Sstevel@tonic-gate 35058561cbSjbeck /* maximum number of arguments in a map lookup, see sendmail.h: MAX_MAP_ARGS */ 36058561cbSjbeck # define SM_LDAP_ARGS 10 37058561cbSjbeck 38058561cbSjbeck /* error codes from sm_ldap_search*() */ 39058561cbSjbeck # define SM_LDAP_ERR (-1) /* generic error: ldap_search(3) */ 40058561cbSjbeck # define SM_LDAP_ERR_ARG_MISS (-2) /* an argument is missing */ 41058561cbSjbeck 427c478bd9Sstevel@tonic-gate /* Attribute types */ 437c478bd9Sstevel@tonic-gate # define SM_LDAP_ATTR_NONE (-1) 447c478bd9Sstevel@tonic-gate # define SM_LDAP_ATTR_OBJCLASS 0 457c478bd9Sstevel@tonic-gate # define SM_LDAP_ATTR_NORMAL 1 467c478bd9Sstevel@tonic-gate # define SM_LDAP_ATTR_DN 2 477c478bd9Sstevel@tonic-gate # define SM_LDAP_ATTR_FILTER 3 487c478bd9Sstevel@tonic-gate # define SM_LDAP_ATTR_URL 4 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* sm_ldap_results() flags */ 517c478bd9Sstevel@tonic-gate # define SM_LDAP_SINGLEMATCH 0x0001 527c478bd9Sstevel@tonic-gate # define SM_LDAP_MATCHONLY 0x0002 537c478bd9Sstevel@tonic-gate # define SM_LDAP_USE_ALLATTR 0x0004 5449218d4fSjbeck # define SM_LDAP_SINGLEDN 0x0008 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate struct sm_ldap_struct 577c478bd9Sstevel@tonic-gate { 587c478bd9Sstevel@tonic-gate /* needed for ldap_open or ldap_init */ 597c478bd9Sstevel@tonic-gate char *ldap_uri; 607c478bd9Sstevel@tonic-gate char *ldap_host; 617c478bd9Sstevel@tonic-gate int ldap_port; 627c478bd9Sstevel@tonic-gate int ldap_version; 637c478bd9Sstevel@tonic-gate pid_t ldap_pid; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* options set in ld struct before ldap_bind_s */ 667c478bd9Sstevel@tonic-gate int ldap_deref; 677c478bd9Sstevel@tonic-gate time_t ldap_timelimit; 687c478bd9Sstevel@tonic-gate int ldap_sizelimit; 697c478bd9Sstevel@tonic-gate int ldap_options; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* args for ldap_bind_s */ 727c478bd9Sstevel@tonic-gate LDAP *ldap_ld; 737c478bd9Sstevel@tonic-gate char *ldap_binddn; 747c478bd9Sstevel@tonic-gate char *ldap_secret; 757c478bd9Sstevel@tonic-gate int ldap_method; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* args for ldap_search */ 787c478bd9Sstevel@tonic-gate char *ldap_base; 797c478bd9Sstevel@tonic-gate int ldap_scope; 807c478bd9Sstevel@tonic-gate char *ldap_filter; 817c478bd9Sstevel@tonic-gate char *ldap_attr[LDAPMAP_MAX_ATTR + 1]; 827c478bd9Sstevel@tonic-gate int ldap_attr_type[LDAPMAP_MAX_ATTR + 1]; 837c478bd9Sstevel@tonic-gate char *ldap_attr_needobjclass[LDAPMAP_MAX_ATTR + 1]; 847c478bd9Sstevel@tonic-gate bool ldap_attrsonly; 85058561cbSjbeck bool ldap_multi_args; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* args for ldap_result */ 887c478bd9Sstevel@tonic-gate struct timeval ldap_timeout; 897c478bd9Sstevel@tonic-gate LDAPMessage *ldap_res; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* ldapmap_lookup options */ 927c478bd9Sstevel@tonic-gate char ldap_attrsep; 937c478bd9Sstevel@tonic-gate 947800901eSjbeck # if _FFR_LDAP_NETWORK_TIMEOUT 95*e9af4bc0SJohn Beck int ldap_networktmo; 967800901eSjbeck # endif /* _FFR_LDAP_NETWORK_TIMEOUT */ 977800901eSjbeck 987c478bd9Sstevel@tonic-gate /* Linked list of maps sharing the same LDAP binding */ 997c478bd9Sstevel@tonic-gate void *ldap_next; 1007c478bd9Sstevel@tonic-gate }; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate typedef struct sm_ldap_struct SM_LDAP_STRUCT; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate struct sm_ldap_recurse_entry 1057c478bd9Sstevel@tonic-gate { 1067c478bd9Sstevel@tonic-gate char *lr_search; 1077c478bd9Sstevel@tonic-gate int lr_type; 1087c478bd9Sstevel@tonic-gate LDAPURLDesc *lr_ludp; 1097c478bd9Sstevel@tonic-gate char **lr_attrs; 1107c478bd9Sstevel@tonic-gate bool lr_done; 1117c478bd9Sstevel@tonic-gate }; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate struct sm_ldap_recurse_list 1147c478bd9Sstevel@tonic-gate { 115058561cbSjbeck int lrl_size; 116058561cbSjbeck int lrl_cnt; 117058561cbSjbeck struct sm_ldap_recurse_entry **lrl_data; 1187c478bd9Sstevel@tonic-gate }; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate typedef struct sm_ldap_recurse_entry SM_LDAP_RECURSE_ENTRY; 1217c478bd9Sstevel@tonic-gate typedef struct sm_ldap_recurse_list SM_LDAP_RECURSE_LIST; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* functions */ 1247c478bd9Sstevel@tonic-gate extern void sm_ldap_clear __P((SM_LDAP_STRUCT *)); 1257c478bd9Sstevel@tonic-gate extern bool sm_ldap_start __P((char *, SM_LDAP_STRUCT *)); 1267c478bd9Sstevel@tonic-gate extern int sm_ldap_search __P((SM_LDAP_STRUCT *, char *)); 127058561cbSjbeck extern int sm_ldap_search_m __P((SM_LDAP_STRUCT *, char **)); 1287c478bd9Sstevel@tonic-gate extern int sm_ldap_results __P((SM_LDAP_STRUCT *, int, int, int, 1297c478bd9Sstevel@tonic-gate SM_RPOOL_T *, char **, int *, int *, 1307c478bd9Sstevel@tonic-gate SM_LDAP_RECURSE_LIST *)); 1317c478bd9Sstevel@tonic-gate extern void sm_ldap_setopts __P((LDAP *, SM_LDAP_STRUCT *)); 1327c478bd9Sstevel@tonic-gate extern int sm_ldap_geterrno __P((LDAP *)); 1337c478bd9Sstevel@tonic-gate extern void sm_ldap_close __P((SM_LDAP_STRUCT *)); 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* Portability defines */ 1367c478bd9Sstevel@tonic-gate # if !SM_CONF_LDAP_MEMFREE 1377c478bd9Sstevel@tonic-gate # define ldap_memfree(x) ((void) 0) 1387c478bd9Sstevel@tonic-gate # endif /* !SM_CONF_LDAP_MEMFREE */ 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate # endif /* LDAPMAP */ 1417c478bd9Sstevel@tonic-gate #endif /* ! SM_LDAP_H */ 142