1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright (c) 1995-2001 by Sun Microsystems, Inc. 3*0Sstevel@tonic-gate * All rights reserved. 4*0Sstevel@tonic-gate */ 5*0Sstevel@tonic-gate 6*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gate #include <stdio.h> 9*0Sstevel@tonic-gate #include <string.h> 10*0Sstevel@tonic-gate #include "lber.h" 11*0Sstevel@tonic-gate #include "ldap.h" 12*0Sstevel@tonic-gate #include "ldap-private.h" 13*0Sstevel@tonic-gate #include "ldap-int.h" 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gate extern LDAPControl ** ldap_controls_dup(LDAPControl **ctrls); 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gate /* 18*0Sstevel@tonic-gate * ldap_get_option() 19*0Sstevel@tonic-gate */ 20*0Sstevel@tonic-gate int 21*0Sstevel@tonic-gate ldap_get_option(LDAP *ld, int option, void *outvalue) 22*0Sstevel@tonic-gate { 23*0Sstevel@tonic-gate if (ld == NULL) 24*0Sstevel@tonic-gate return (-1); 25*0Sstevel@tonic-gate #ifdef _REENTRANT 26*0Sstevel@tonic-gate LOCK_LDAP(ld); 27*0Sstevel@tonic-gate #endif 28*0Sstevel@tonic-gate switch (option) { 29*0Sstevel@tonic-gate case LDAP_OPT_API_INFO: 30*0Sstevel@tonic-gate ((LDAPAPIInfo *)outvalue)->ldapai_api_version = 31*0Sstevel@tonic-gate LDAP_API_VERSION; 32*0Sstevel@tonic-gate if (((LDAPAPIInfo *)outvalue)->ldapai_info_version != 33*0Sstevel@tonic-gate LDAP_API_INFO_VERSION) { 34*0Sstevel@tonic-gate ((LDAPAPIInfo *)outvalue)->ldapai_info_version = 35*0Sstevel@tonic-gate LDAP_API_INFO_VERSION; 36*0Sstevel@tonic-gate #ifdef _REENTRANT 37*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 38*0Sstevel@tonic-gate #endif 39*0Sstevel@tonic-gate return (-1); 40*0Sstevel@tonic-gate } 41*0Sstevel@tonic-gate ((LDAPAPIInfo *)outvalue)->ldapai_protocol_version = 42*0Sstevel@tonic-gate LDAP_VERSION_MAX; 43*0Sstevel@tonic-gate /* No extensions are currently supported */ 44*0Sstevel@tonic-gate ((LDAPAPIInfo *)outvalue)->ldapai_extensions = NULL; 45*0Sstevel@tonic-gate ((LDAPAPIInfo *)outvalue)->ldapai_vendor_name = 46*0Sstevel@tonic-gate strdup(LDAP_VENDOR_NAME); 47*0Sstevel@tonic-gate ((LDAPAPIInfo *)outvalue)->ldapai_vendor_version = 48*0Sstevel@tonic-gate LDAP_VENDOR_VERSION; 49*0Sstevel@tonic-gate break; 50*0Sstevel@tonic-gate case LDAP_OPT_DESC: /* depricated option */ 51*0Sstevel@tonic-gate *(int *)outvalue = ld->ld_sb.sb_sd; 52*0Sstevel@tonic-gate break; 53*0Sstevel@tonic-gate case LDAP_OPT_DEREF: 54*0Sstevel@tonic-gate *(int *)outvalue = ld->ld_deref; 55*0Sstevel@tonic-gate break; 56*0Sstevel@tonic-gate case LDAP_OPT_SIZELIMIT: 57*0Sstevel@tonic-gate *(int *)outvalue = ld->ld_sizelimit; 58*0Sstevel@tonic-gate break; 59*0Sstevel@tonic-gate case LDAP_OPT_TIMELIMIT: 60*0Sstevel@tonic-gate *(int *)outvalue = ld->ld_timelimit; 61*0Sstevel@tonic-gate break; 62*0Sstevel@tonic-gate case LDAP_OPT_REBIND_FN: /* depricated option */ 63*0Sstevel@tonic-gate outvalue = (void *)ld->ld_rebindproc; 64*0Sstevel@tonic-gate break; 65*0Sstevel@tonic-gate case LDAP_OPT_REBIND_ARG: /* depricated option */ 66*0Sstevel@tonic-gate outvalue = ld->ld_rebind_extra_arg; 67*0Sstevel@tonic-gate break; 68*0Sstevel@tonic-gate case LDAP_OPT_REFERRALS: 69*0Sstevel@tonic-gate *(int *)outvalue = ld->ld_follow_referral; 70*0Sstevel@tonic-gate break; 71*0Sstevel@tonic-gate case LDAP_OPT_RESTART: 72*0Sstevel@tonic-gate *(int *)outvalue = ld->ld_restart; 73*0Sstevel@tonic-gate break; 74*0Sstevel@tonic-gate case LDAP_OPT_PROTOCOL_VERSION: 75*0Sstevel@tonic-gate *(int *)outvalue = ld->ld_version; 76*0Sstevel@tonic-gate break; 77*0Sstevel@tonic-gate case LDAP_OPT_SERVER_CONTROLS: 78*0Sstevel@tonic-gate outvalue = ld->ld_srvctrls; 79*0Sstevel@tonic-gate break; 80*0Sstevel@tonic-gate case LDAP_OPT_CLIENT_CONTROLS: 81*0Sstevel@tonic-gate outvalue = ld->ld_cltctrls; 82*0Sstevel@tonic-gate break; 83*0Sstevel@tonic-gate case LDAP_OPT_API_FEATURE_INFO: 84*0Sstevel@tonic-gate if ((((LDAPAPIFeatureInfo *)outvalue)->ldapaif_info_version != 85*0Sstevel@tonic-gate LDAP_FEATURE_INFO_VERSION) || 86*0Sstevel@tonic-gate (((LDAPAPIFeatureInfo *)outvalue)->ldapaif_name == 87*0Sstevel@tonic-gate NULL)) { 88*0Sstevel@tonic-gate ((LDAPAPIFeatureInfo *)outvalue)->ldapaif_info_version = 89*0Sstevel@tonic-gate LDAP_FEATURE_INFO_VERSION; 90*0Sstevel@tonic-gate #ifdef _REENTRANT 91*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 92*0Sstevel@tonic-gate #endif 93*0Sstevel@tonic-gate return (-1); 94*0Sstevel@tonic-gate } 95*0Sstevel@tonic-gate /* 96*0Sstevel@tonic-gate * This option must be completed when optional api's (or 97*0Sstevel@tonic-gate * (extensions) are supported by this library. Right now 98*0Sstevel@tonic-gate * there are none, and therefore this section can not be 99*0Sstevel@tonic-gate * completed. 100*0Sstevel@tonic-gate */ 101*0Sstevel@tonic-gate break; 102*0Sstevel@tonic-gate case LDAP_OPT_HOST_NAME: 103*0Sstevel@tonic-gate *(char **)outvalue = ld->ld_host; 104*0Sstevel@tonic-gate break; 105*0Sstevel@tonic-gate case LDAP_OPT_ERROR_NUMBER: 106*0Sstevel@tonic-gate *(int *)outvalue = ld->ld_errno; 107*0Sstevel@tonic-gate break; 108*0Sstevel@tonic-gate case LDAP_OPT_ERROR_STRING: 109*0Sstevel@tonic-gate *(char **)outvalue = ld->ld_error; 110*0Sstevel@tonic-gate break; 111*0Sstevel@tonic-gate case LDAP_OPT_MATCHED_DN: 112*0Sstevel@tonic-gate /* case LDAP_OPT_ERROR_MATCHED: depricated option */ 113*0Sstevel@tonic-gate *(char **)outvalue = ld->ld_matched; 114*0Sstevel@tonic-gate break; 115*0Sstevel@tonic-gate case LDAP_X_OPT_CONNECT_TIMEOUT: 116*0Sstevel@tonic-gate *((int *)outvalue) = ld->ld_connect_timeout; 117*0Sstevel@tonic-gate break; 118*0Sstevel@tonic-gate default: 119*0Sstevel@tonic-gate #ifdef _REENTRANT 120*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 121*0Sstevel@tonic-gate #endif 122*0Sstevel@tonic-gate return (-1); 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate #ifdef _REENTRANT 126*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 127*0Sstevel@tonic-gate #endif 128*0Sstevel@tonic-gate return (0); 129*0Sstevel@tonic-gate } 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate int 132*0Sstevel@tonic-gate ldap_set_option(LDAP *ld, int option, void *invalue) 133*0Sstevel@tonic-gate { 134*0Sstevel@tonic-gate if (ld == NULL) 135*0Sstevel@tonic-gate return (-1); 136*0Sstevel@tonic-gate #ifdef _REENTRANT 137*0Sstevel@tonic-gate LOCK_LDAP(ld); 138*0Sstevel@tonic-gate #endif 139*0Sstevel@tonic-gate switch (option) { 140*0Sstevel@tonic-gate case LDAP_OPT_DESC: 141*0Sstevel@tonic-gate break; 142*0Sstevel@tonic-gate case LDAP_OPT_DEREF: 143*0Sstevel@tonic-gate if (*(int *)invalue != LDAP_DEREF_NEVER && 144*0Sstevel@tonic-gate *(int *)invalue != LDAP_DEREF_SEARCHING && 145*0Sstevel@tonic-gate *(int *)invalue != LDAP_DEREF_FINDING && 146*0Sstevel@tonic-gate *(int *)invalue != LDAP_DEREF_ALWAYS) { 147*0Sstevel@tonic-gate #ifdef _REENTRANT 148*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 149*0Sstevel@tonic-gate #endif 150*0Sstevel@tonic-gate return (-1); 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate ld->ld_deref = *(int *)invalue; 153*0Sstevel@tonic-gate break; 154*0Sstevel@tonic-gate case LDAP_OPT_SIZELIMIT: 155*0Sstevel@tonic-gate ld->ld_sizelimit = *(int *)invalue; 156*0Sstevel@tonic-gate break; 157*0Sstevel@tonic-gate case LDAP_OPT_TIMELIMIT: 158*0Sstevel@tonic-gate ld->ld_timelimit = *(int *)invalue; 159*0Sstevel@tonic-gate break; 160*0Sstevel@tonic-gate case LDAP_OPT_REBIND_FN: 161*0Sstevel@tonic-gate /* cast needs to be updated when ldap.h gets updated */ 162*0Sstevel@tonic-gate ld->ld_rebindproc = (LDAP_REBIND_FUNCTION *)invalue; 163*0Sstevel@tonic-gate break; 164*0Sstevel@tonic-gate case LDAP_OPT_REBIND_ARG: 165*0Sstevel@tonic-gate ld->ld_rebind_extra_arg = invalue; 166*0Sstevel@tonic-gate break; 167*0Sstevel@tonic-gate case LDAP_OPT_REFERRALS: 168*0Sstevel@tonic-gate if (invalue != LDAP_OPT_ON && invalue != LDAP_OPT_OFF) { 169*0Sstevel@tonic-gate #ifdef _REENTRANT 170*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 171*0Sstevel@tonic-gate #endif 172*0Sstevel@tonic-gate return (-1); 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate ld->ld_follow_referral = invalue ? 1 : 0; 175*0Sstevel@tonic-gate break; 176*0Sstevel@tonic-gate case LDAP_OPT_RESTART: 177*0Sstevel@tonic-gate if (invalue != LDAP_OPT_ON && invalue != LDAP_OPT_OFF) { 178*0Sstevel@tonic-gate #ifdef _REENTRANT 179*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 180*0Sstevel@tonic-gate #endif 181*0Sstevel@tonic-gate return (-1); 182*0Sstevel@tonic-gate } 183*0Sstevel@tonic-gate ld->ld_restart = invalue ? 1 : 0; 184*0Sstevel@tonic-gate break; 185*0Sstevel@tonic-gate case LDAP_OPT_PROTOCOL_VERSION: 186*0Sstevel@tonic-gate if (*(int *)invalue < LDAP_VERSION1 || 187*0Sstevel@tonic-gate *(int *)invalue > LDAP_VERSION3) { 188*0Sstevel@tonic-gate #ifdef _REENTRANT 189*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 190*0Sstevel@tonic-gate #endif 191*0Sstevel@tonic-gate return (-1); 192*0Sstevel@tonic-gate } 193*0Sstevel@tonic-gate ld->ld_version = *(int *)invalue; 194*0Sstevel@tonic-gate break; 195*0Sstevel@tonic-gate case LDAP_OPT_SERVER_CONTROLS: 196*0Sstevel@tonic-gate if (ld->ld_srvctrls != NULL) { 197*0Sstevel@tonic-gate ldap_controls_free(ld->ld_srvctrls); 198*0Sstevel@tonic-gate } 199*0Sstevel@tonic-gate ld->ld_srvctrls = NULL; 200*0Sstevel@tonic-gate if (invalue != NULL) 201*0Sstevel@tonic-gate ld->ld_srvctrls = ldap_controls_dup(invalue); 202*0Sstevel@tonic-gate break; 203*0Sstevel@tonic-gate case LDAP_OPT_CLIENT_CONTROLS: 204*0Sstevel@tonic-gate if (ld->ld_cltctrls != NULL) { 205*0Sstevel@tonic-gate ldap_controls_free(ld->ld_cltctrls); 206*0Sstevel@tonic-gate } 207*0Sstevel@tonic-gate ld->ld_cltctrls = NULL; 208*0Sstevel@tonic-gate if (invalue != NULL) 209*0Sstevel@tonic-gate ld->ld_cltctrls = ldap_controls_dup(invalue); 210*0Sstevel@tonic-gate break; 211*0Sstevel@tonic-gate case LDAP_OPT_HOST_NAME: 212*0Sstevel@tonic-gate if (ld->ld_host != NULL) { 213*0Sstevel@tonic-gate free(ld->ld_host); 214*0Sstevel@tonic-gate } 215*0Sstevel@tonic-gate ld->ld_host = NULL; 216*0Sstevel@tonic-gate if ((char *)invalue != NULL) 217*0Sstevel@tonic-gate ld->ld_host = strdup((char *)invalue); 218*0Sstevel@tonic-gate break; 219*0Sstevel@tonic-gate case LDAP_OPT_ERROR_NUMBER: 220*0Sstevel@tonic-gate break; 221*0Sstevel@tonic-gate case LDAP_OPT_ERROR_STRING: 222*0Sstevel@tonic-gate break; 223*0Sstevel@tonic-gate case LDAP_OPT_MATCHED_DN: 224*0Sstevel@tonic-gate if (ld->ld_matched) 225*0Sstevel@tonic-gate free(ld->ld_matched); 226*0Sstevel@tonic-gate ld->ld_matched = NULL; 227*0Sstevel@tonic-gate if ((char *)invalue != NULL) 228*0Sstevel@tonic-gate ld->ld_matched = strdup((char *)invalue); 229*0Sstevel@tonic-gate break; 230*0Sstevel@tonic-gate case LDAP_X_OPT_CONNECT_TIMEOUT: 231*0Sstevel@tonic-gate ld->ld_connect_timeout = *((int *)invalue); 232*0Sstevel@tonic-gate break; 233*0Sstevel@tonic-gate default: 234*0Sstevel@tonic-gate #ifdef _REENTRANT 235*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 236*0Sstevel@tonic-gate #endif 237*0Sstevel@tonic-gate return (-1); 238*0Sstevel@tonic-gate } 239*0Sstevel@tonic-gate #ifdef _REENTRANT 240*0Sstevel@tonic-gate UNLOCK_LDAP(ld); 241*0Sstevel@tonic-gate #endif 242*0Sstevel@tonic-gate return (0); 243*0Sstevel@tonic-gate } 244