Back to index

openldap  2.4.31
config.c
Go to the documentation of this file.
00001 /* config.c - ldap backend configuration file routine */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2003-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 1999-2003 Howard Chu.
00007  * Portions Copyright 2000-2003 Pierangelo Masarati.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted only as authorized by the OpenLDAP
00012  * Public License.
00013  *
00014  * A copy of this license is available in the file LICENSE in the
00015  * top-level directory of the distribution or, alternatively, at
00016  * <http://www.OpenLDAP.org/license.html>.
00017  */
00018 /* ACKNOWLEDGEMENTS:
00019  * This work was initially developed by the Howard Chu for inclusion
00020  * in OpenLDAP Software and subsequently enhanced by Pierangelo
00021  * Masarati.
00022  */
00023 
00024 #include "portable.h"
00025 
00026 #include <stdio.h>
00027 
00028 #include <ac/string.h>
00029 #include <ac/ctype.h>
00030 #include <ac/socket.h>
00031 
00032 #include "slap.h"
00033 #include "config.h"
00034 #include "back-ldap.h"
00035 #include "lutil.h"
00036 #include "ldif.h"
00037 
00038 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
00039 
00040 static ConfigDriver ldap_back_cf_gen;
00041 static ConfigDriver ldap_pbind_cf_gen;
00042 
00043 enum {
00044        LDAP_BACK_CFG_URI = 1,
00045        LDAP_BACK_CFG_TLS,
00046        LDAP_BACK_CFG_ACL_AUTHCDN,
00047        LDAP_BACK_CFG_ACL_PASSWD,
00048        LDAP_BACK_CFG_ACL_METHOD,
00049        LDAP_BACK_CFG_ACL_BIND,
00050        LDAP_BACK_CFG_IDASSERT_MODE,
00051        LDAP_BACK_CFG_IDASSERT_AUTHCDN,
00052        LDAP_BACK_CFG_IDASSERT_PASSWD,
00053        LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
00054        LDAP_BACK_CFG_IDASSERT_PASSTHRU,
00055        LDAP_BACK_CFG_IDASSERT_METHOD,
00056        LDAP_BACK_CFG_IDASSERT_BIND,
00057        LDAP_BACK_CFG_REBIND,
00058        LDAP_BACK_CFG_CHASE,
00059        LDAP_BACK_CFG_T_F,
00060        LDAP_BACK_CFG_WHOAMI,
00061        LDAP_BACK_CFG_TIMEOUT,
00062        LDAP_BACK_CFG_IDLE_TIMEOUT,
00063        LDAP_BACK_CFG_CONN_TTL,
00064        LDAP_BACK_CFG_NETWORK_TIMEOUT,
00065        LDAP_BACK_CFG_VERSION,
00066        LDAP_BACK_CFG_SINGLECONN,
00067        LDAP_BACK_CFG_USETEMP,
00068        LDAP_BACK_CFG_CONNPOOLMAX,
00069        LDAP_BACK_CFG_CANCEL,
00070        LDAP_BACK_CFG_QUARANTINE,
00071        LDAP_BACK_CFG_ST_REQUEST,
00072        LDAP_BACK_CFG_NOREFS,
00073        LDAP_BACK_CFG_NOUNDEFFILTER,
00074 
00075        LDAP_BACK_CFG_REWRITE,
00076 
00077        LDAP_BACK_CFG_LAST
00078 };
00079 
00080 static ConfigTable ldapcfg[] = {
00081        { "uri", "uri", 2, 2, 0,
00082               ARG_MAGIC|LDAP_BACK_CFG_URI,
00083               ldap_back_cf_gen, "( OLcfgDbAt:0.14 "
00084                      "NAME 'olcDbURI' "
00085                      "DESC 'URI (list) for remote DSA' "
00086                      "SYNTAX OMsDirectoryString "
00087                      "SINGLE-VALUE )",
00088               NULL, NULL },
00089        { "tls", "what", 2, 0, 0,
00090               ARG_MAGIC|LDAP_BACK_CFG_TLS,
00091               ldap_back_cf_gen, "( OLcfgDbAt:3.1 "
00092                      "NAME 'olcDbStartTLS' "
00093                      "DESC 'StartTLS' "
00094                      "SYNTAX OMsDirectoryString "
00095                      "SINGLE-VALUE )",
00096               NULL, NULL },
00097        { "acl-authcDN", "DN", 2, 2, 0,
00098               ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
00099               ldap_back_cf_gen, "( OLcfgDbAt:3.2 "
00100                      "NAME 'olcDbACLAuthcDn' "
00101                      "DESC 'Remote ACL administrative identity' "
00102                      "OBSOLETE "
00103                      "SYNTAX OMsDN "
00104                      "SINGLE-VALUE )",
00105               NULL, NULL },
00106        /* deprecated, will be removed; aliases "acl-authcDN" */
00107        { "binddn", "DN", 2, 2, 0,
00108               ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
00109               ldap_back_cf_gen, NULL, NULL, NULL },
00110        { "acl-passwd", "cred", 2, 2, 0,
00111               ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
00112               ldap_back_cf_gen, "( OLcfgDbAt:3.3 "
00113                      "NAME 'olcDbACLPasswd' "
00114                      "DESC 'Remote ACL administrative identity credentials' "
00115                      "OBSOLETE "
00116                      "SYNTAX OMsDirectoryString "
00117                      "SINGLE-VALUE )",
00118               NULL, NULL },
00119        /* deprecated, will be removed; aliases "acl-passwd" */
00120        { "bindpw", "cred", 2, 2, 0,
00121               ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
00122               ldap_back_cf_gen, NULL, NULL, NULL },
00123        /* deprecated, will be removed; aliases "acl-bind" */
00124        { "acl-method", "args", 2, 0, 0,
00125               ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD,
00126               ldap_back_cf_gen, NULL, NULL, NULL },
00127        { "acl-bind", "args", 2, 0, 0,
00128               ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
00129               ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
00130                      "NAME 'olcDbACLBind' "
00131                      "DESC 'Remote ACL administrative identity auth bind configuration' "
00132                      "SYNTAX OMsDirectoryString "
00133                      "SINGLE-VALUE )",
00134               NULL, NULL },
00135        { "idassert-authcDN", "DN", 2, 2, 0,
00136               ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
00137               ldap_back_cf_gen, "( OLcfgDbAt:3.5 "
00138                      "NAME 'olcDbIDAssertAuthcDn' "
00139                      "DESC 'Remote Identity Assertion administrative identity' "
00140                      "OBSOLETE "
00141                      "SYNTAX OMsDN "
00142                      "SINGLE-VALUE )",
00143               NULL, NULL },
00144        /* deprecated, will be removed; partially aliases "idassert-authcDN" */
00145        { "proxyauthzdn", "DN", 2, 2, 0,
00146               ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
00147               ldap_back_cf_gen, NULL, NULL, NULL },
00148        { "idassert-passwd", "cred", 2, 2, 0,
00149               ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
00150               ldap_back_cf_gen, "( OLcfgDbAt:3.6 "
00151                      "NAME 'olcDbIDAssertPasswd' "
00152                      "DESC 'Remote Identity Assertion administrative identity credentials' "
00153                      "OBSOLETE "
00154                      "SYNTAX OMsDirectoryString "
00155                      "SINGLE-VALUE )",
00156               NULL, NULL },
00157        /* deprecated, will be removed; partially aliases "idassert-passwd" */
00158        { "proxyauthzpw", "cred", 2, 2, 0,
00159               ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
00160               ldap_back_cf_gen, NULL, NULL, NULL },
00161        { "idassert-bind", "args", 2, 0, 0,
00162               ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
00163               ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
00164                      "NAME 'olcDbIDAssertBind' "
00165                      "DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
00166                      "SYNTAX OMsDirectoryString "
00167                      "SINGLE-VALUE )",
00168               NULL, NULL },
00169        { "idassert-method", "args", 2, 0, 0,
00170               ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD,
00171               ldap_back_cf_gen, NULL, NULL, NULL },
00172        { "idassert-mode", "mode>|u:<user>|[dn:]<DN", 2, 0, 0,
00173               ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_MODE,
00174               ldap_back_cf_gen, "( OLcfgDbAt:3.8 "
00175                      "NAME 'olcDbIDAssertMode' "
00176                      "DESC 'Remote Identity Assertion mode' "
00177                      "OBSOLETE "
00178                      "SYNTAX OMsDirectoryString "
00179                      "SINGLE-VALUE)",
00180               NULL, NULL },
00181        { "idassert-authzFrom", "authzRule", 2, 2, 0,
00182               ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
00183               ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
00184                      "NAME 'olcDbIDAssertAuthzFrom' "
00185                      "DESC 'Remote Identity Assertion authz rules' "
00186                      "EQUALITY caseIgnoreMatch "
00187                      "SYNTAX OMsDirectoryString "
00188                      "X-ORDERED 'VALUES' )",
00189               NULL, NULL },
00190        { "rebind-as-user", "true|FALSE", 1, 2, 0,
00191               ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_REBIND,
00192               ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
00193                      "NAME 'olcDbRebindAsUser' "
00194                      "DESC 'Rebind as user' "
00195                      "SYNTAX OMsBoolean "
00196                      "SINGLE-VALUE )",
00197               NULL, NULL },
00198        { "chase-referrals", "true|FALSE", 2, 2, 0,
00199               ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_CHASE,
00200               ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
00201                      "NAME 'olcDbChaseReferrals' "
00202                      "DESC 'Chase referrals' "
00203                      "SYNTAX OMsBoolean "
00204                      "SINGLE-VALUE )",
00205               NULL, NULL },
00206        { "t-f-support", "true|FALSE|discover", 2, 2, 0,
00207               ARG_MAGIC|LDAP_BACK_CFG_T_F,
00208               ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
00209                      "NAME 'olcDbTFSupport' "
00210                      "DESC 'Absolute filters support' "
00211                      "SYNTAX OMsDirectoryString "
00212                      "SINGLE-VALUE )",
00213               NULL, NULL },
00214        { "proxy-whoami", "true|FALSE", 1, 2, 0,
00215               ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_WHOAMI,
00216               ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
00217                      "NAME 'olcDbProxyWhoAmI' "
00218                      "DESC 'Proxy whoAmI exop' "
00219                      "SYNTAX OMsBoolean "
00220                      "SINGLE-VALUE )",
00221               NULL, NULL },
00222        { "timeout", "timeout(list)", 2, 0, 0,
00223               ARG_MAGIC|LDAP_BACK_CFG_TIMEOUT,
00224               ldap_back_cf_gen, "( OLcfgDbAt:3.14 "
00225                      "NAME 'olcDbTimeout' "
00226                      "DESC 'Per-operation timeouts' "
00227                      "SYNTAX OMsDirectoryString "
00228                      "SINGLE-VALUE )",
00229               NULL, NULL },
00230        { "idle-timeout", "timeout", 2, 2, 0,
00231               ARG_MAGIC|LDAP_BACK_CFG_IDLE_TIMEOUT,
00232               ldap_back_cf_gen, "( OLcfgDbAt:3.15 "
00233                      "NAME 'olcDbIdleTimeout' "
00234                      "DESC 'connection idle timeout' "
00235                      "SYNTAX OMsDirectoryString "
00236                      "SINGLE-VALUE )",
00237               NULL, NULL },
00238        { "conn-ttl", "ttl", 2, 2, 0,
00239               ARG_MAGIC|LDAP_BACK_CFG_CONN_TTL,
00240               ldap_back_cf_gen, "( OLcfgDbAt:3.16 "
00241                      "NAME 'olcDbConnTtl' "
00242                      "DESC 'connection ttl' "
00243                      "SYNTAX OMsDirectoryString "
00244                      "SINGLE-VALUE )",
00245               NULL, NULL },
00246        { "network-timeout", "timeout", 2, 2, 0,
00247               ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
00248               ldap_back_cf_gen, "( OLcfgDbAt:3.17 "
00249                      "NAME 'olcDbNetworkTimeout' "
00250                      "DESC 'connection network timeout' "
00251                      "SYNTAX OMsDirectoryString "
00252                      "SINGLE-VALUE )",
00253               NULL, NULL },
00254        { "protocol-version", "version", 2, 2, 0,
00255               ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_VERSION,
00256               ldap_back_cf_gen, "( OLcfgDbAt:3.18 "
00257                      "NAME 'olcDbProtocolVersion' "
00258                      "DESC 'protocol version' "
00259                      "SYNTAX OMsInteger "
00260                      "SINGLE-VALUE )",
00261               NULL, NULL },
00262        { "single-conn", "true|FALSE", 2, 2, 0,
00263               ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_SINGLECONN,
00264               ldap_back_cf_gen, "( OLcfgDbAt:3.19 "
00265                      "NAME 'olcDbSingleConn' "
00266                      "DESC 'cache a single connection per identity' "
00267                      "SYNTAX OMsBoolean "
00268                      "SINGLE-VALUE )",
00269               NULL, NULL },
00270        { "cancel", "ABANDON|ignore|exop", 2, 2, 0,
00271               ARG_MAGIC|LDAP_BACK_CFG_CANCEL,
00272               ldap_back_cf_gen, "( OLcfgDbAt:3.20 "
00273                      "NAME 'olcDbCancel' "
00274                      "DESC 'abandon/ignore/exop operations when appropriate' "
00275                      "SYNTAX OMsDirectoryString "
00276                      "SINGLE-VALUE )",
00277               NULL, NULL },
00278        { "quarantine", "retrylist", 2, 2, 0,
00279               ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
00280               ldap_back_cf_gen, "( OLcfgDbAt:3.21 "
00281                      "NAME 'olcDbQuarantine' "
00282                      "DESC 'Quarantine database if connection fails and retry according to rule' "
00283                      "SYNTAX OMsDirectoryString "
00284                      "SINGLE-VALUE )",
00285               NULL, NULL },
00286        { "use-temporary-conn", "true|FALSE", 2, 2, 0,
00287               ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_USETEMP,
00288               ldap_back_cf_gen, "( OLcfgDbAt:3.22 "
00289                      "NAME 'olcDbUseTemporaryConn' "
00290                      "DESC 'Use temporary connections if the cached one is busy' "
00291                      "SYNTAX OMsBoolean "
00292                      "SINGLE-VALUE )",
00293               NULL, NULL },
00294        { "conn-pool-max", "<n>", 2, 2, 0,
00295               ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_CONNPOOLMAX,
00296               ldap_back_cf_gen, "( OLcfgDbAt:3.23 "
00297                      "NAME 'olcDbConnectionPoolMax' "
00298                      "DESC 'Max size of privileged connections pool' "
00299                      "SYNTAX OMsInteger "
00300                      "SINGLE-VALUE )",
00301               NULL, NULL },
00302 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
00303        { "session-tracking-request", "true|FALSE", 2, 2, 0,
00304               ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_ST_REQUEST,
00305               ldap_back_cf_gen, "( OLcfgDbAt:3.24 "
00306                      "NAME 'olcDbSessionTrackingRequest' "
00307                      "DESC 'Add session tracking control to proxied requests' "
00308                      "SYNTAX OMsBoolean "
00309                      "SINGLE-VALUE )",
00310               NULL, NULL },
00311 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
00312        { "norefs", "true|FALSE", 2, 2, 0,
00313               ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOREFS,
00314               ldap_back_cf_gen, "( OLcfgDbAt:3.25 "
00315                      "NAME 'olcDbNoRefs' "
00316                      "DESC 'Do not return search reference responses' "
00317                      "SYNTAX OMsBoolean "
00318                      "SINGLE-VALUE )",
00319               NULL, NULL },
00320        { "noundeffilter", "true|FALSE", 2, 2, 0,
00321               ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOUNDEFFILTER,
00322               ldap_back_cf_gen, "( OLcfgDbAt:3.26 "
00323                      "NAME 'olcDbNoUndefFilter' "
00324                      "DESC 'Do not propagate undefined search filters' "
00325                      "SYNTAX OMsBoolean "
00326                      "SINGLE-VALUE )",
00327               NULL, NULL },
00328        { "idassert-passThru", "authzRule", 2, 2, 0,
00329               ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSTHRU,
00330               ldap_back_cf_gen, "( OLcfgDbAt:3.27 "
00331                      "NAME 'olcDbIDAssertPassThru' "
00332                      "DESC 'Remote Identity Assertion passthru rules' "
00333                      "EQUALITY caseIgnoreMatch "
00334                      "SYNTAX OMsDirectoryString "
00335                      "X-ORDERED 'VALUES' )",
00336               NULL, NULL },
00337 
00338        { "suffixmassage", "[virtual]> <real", 2, 3, 0,
00339               ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
00340               ldap_back_cf_gen, NULL, NULL, NULL },
00341        { "map", "attribute|objectClass> [*|<local>] *|<remote", 3, 4, 0,
00342               ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
00343               ldap_back_cf_gen, NULL, NULL, NULL },
00344        { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
00345               ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
00346               ldap_back_cf_gen, NULL, NULL, NULL },
00347        { NULL, NULL, 0, 0, 0, ARG_IGNORED,
00348               NULL, NULL, NULL, NULL }
00349 };
00350 
00351 static ConfigOCs ldapocs[] = {
00352        { "( OLcfgDbOc:3.1 "
00353               "NAME 'olcLDAPConfig' "
00354               "DESC 'LDAP backend configuration' "
00355               "SUP olcDatabaseConfig "
00356               "MAY ( olcDbURI "
00357                      "$ olcDbStartTLS "
00358                      "$ olcDbACLAuthcDn "
00359                      "$ olcDbACLPasswd "
00360                      "$ olcDbACLBind "
00361                      "$ olcDbIDAssertAuthcDn "
00362                      "$ olcDbIDAssertPasswd "
00363                      "$ olcDbIDAssertBind "
00364                      "$ olcDbIDAssertMode "
00365                      "$ olcDbIDAssertAuthzFrom "
00366                      "$ olcDbIDAssertPassThru "
00367                      "$ olcDbRebindAsUser "
00368                      "$ olcDbChaseReferrals "
00369                      "$ olcDbTFSupport "
00370                      "$ olcDbProxyWhoAmI "
00371                      "$ olcDbTimeout "
00372                      "$ olcDbIdleTimeout "
00373                      "$ olcDbConnTtl "
00374                      "$ olcDbNetworkTimeout "
00375                      "$ olcDbProtocolVersion "
00376                      "$ olcDbSingleConn "
00377                      "$ olcDbCancel "
00378                      "$ olcDbQuarantine "
00379                      "$ olcDbUseTemporaryConn "
00380                      "$ olcDbConnectionPoolMax "
00381 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
00382                      "$ olcDbSessionTrackingRequest "
00383 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
00384                      "$ olcDbNoRefs "
00385                      "$ olcDbNoUndefFilter "
00386               ") )",
00387                      Cft_Database, ldapcfg},
00388        { NULL, 0, NULL }
00389 };
00390 
00391 static ConfigTable pbindcfg[] = {
00392        { "uri", "uri", 2, 2, 0,
00393               ARG_MAGIC|LDAP_BACK_CFG_URI,
00394               ldap_pbind_cf_gen, "( OLcfgDbAt:0.14 "
00395                      "NAME 'olcDbURI' "
00396                      "DESC 'URI (list) for remote DSA' "
00397                      "SYNTAX OMsDirectoryString "
00398                      "SINGLE-VALUE )",
00399               NULL, NULL },
00400        { "tls", "what", 2, 0, 0,
00401               ARG_MAGIC|LDAP_BACK_CFG_TLS,
00402               ldap_pbind_cf_gen, "( OLcfgDbAt:3.1 "
00403                      "NAME 'olcDbStartTLS' "
00404                      "DESC 'StartTLS' "
00405                      "SYNTAX OMsDirectoryString "
00406                      "SINGLE-VALUE )",
00407               NULL, NULL },
00408        { "network-timeout", "timeout", 2, 2, 0,
00409               ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
00410               ldap_pbind_cf_gen, "( OLcfgDbAt:3.17 "
00411                      "NAME 'olcDbNetworkTimeout' "
00412                      "DESC 'connection network timeout' "
00413                      "SYNTAX OMsDirectoryString "
00414                      "SINGLE-VALUE )",
00415               NULL, NULL },
00416        { "quarantine", "retrylist", 2, 2, 0,
00417               ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
00418               ldap_pbind_cf_gen, "( OLcfgDbAt:3.21 "
00419                      "NAME 'olcDbQuarantine' "
00420                      "DESC 'Quarantine database if connection fails and retry according to rule' "
00421                      "SYNTAX OMsDirectoryString "
00422                      "SINGLE-VALUE )",
00423               NULL, NULL },
00424        { NULL, NULL, 0, 0, 0, ARG_IGNORED,
00425               NULL, NULL, NULL, NULL }
00426 };
00427 
00428 static ConfigOCs pbindocs[] = {
00429        { "( OLcfgOvOc:3.3 "
00430               "NAME 'olcPBindConfig' "
00431               "DESC 'Proxy Bind configuration' "
00432               "SUP olcOverlayConfig "
00433               "MUST olcDbURI "
00434               "MAY ( olcDbStartTLS "
00435                      "$ olcDbNetworkTimeout "
00436                      "$ olcDbQuarantine "
00437               ") )",
00438                      Cft_Overlay, pbindcfg},
00439        { NULL, 0, NULL }
00440 };
00441 
00442 static slap_verbmasks idassert_mode[] = {
00443        { BER_BVC("self"),          LDAP_BACK_IDASSERT_SELF },
00444        { BER_BVC("anonymous"),            LDAP_BACK_IDASSERT_ANONYMOUS },
00445        { BER_BVC("none"),          LDAP_BACK_IDASSERT_NOASSERT },
00446        { BER_BVC("legacy"),        LDAP_BACK_IDASSERT_LEGACY },
00447        { BER_BVNULL,               0 }
00448 };
00449 
00450 static slap_verbmasks tls_mode[] = {
00451        { BER_BVC( "propagate" ),   LDAP_BACK_F_TLS_PROPAGATE_MASK },
00452        { BER_BVC( "try-propagate" ),      LDAP_BACK_F_PROPAGATE_TLS },
00453        { BER_BVC( "start" ),              LDAP_BACK_F_TLS_USE_MASK },
00454        { BER_BVC( "try-start" ),   LDAP_BACK_F_USE_TLS },
00455        { BER_BVC( "ldaps" ),              LDAP_BACK_F_TLS_LDAPS },
00456        { BER_BVC( "none" ),        LDAP_BACK_F_NONE },
00457        { BER_BVNULL,               0 }
00458 };
00459 
00460 static slap_verbmasks t_f_mode[] = {
00461        { BER_BVC( "yes" ),         LDAP_BACK_F_T_F },
00462        { BER_BVC( "discover" ),    LDAP_BACK_F_T_F_DISCOVER },
00463        { BER_BVC( "no" ),          LDAP_BACK_F_NONE },
00464        { BER_BVNULL,               0 }
00465 };
00466 
00467 static slap_verbmasks cancel_mode[] = {
00468        { BER_BVC( "ignore" ),             LDAP_BACK_F_CANCEL_IGNORE },
00469        { BER_BVC( "exop" ),        LDAP_BACK_F_CANCEL_EXOP },
00470        { BER_BVC( "exop-discover" ),      LDAP_BACK_F_CANCEL_EXOP_DISCOVER },
00471        { BER_BVC( "abandon" ),            LDAP_BACK_F_CANCEL_ABANDON },
00472        { BER_BVNULL,               0 }
00473 };
00474 
00475 /* see enum in slap.h */
00476 static slap_cf_aux_table timeout_table[] = {
00477        { BER_BVC("bind="),  SLAP_OP_BIND * sizeof( time_t ),   'u', 0, NULL },
00478        /* unbind makes no sense */
00479        { BER_BVC("add="),   SLAP_OP_ADD * sizeof( time_t ),           'u', 0, NULL },
00480        { BER_BVC("delete="),       SLAP_OP_DELETE * sizeof( time_t ), 'u', 0, NULL },
00481        { BER_BVC("modrdn="),       SLAP_OP_MODRDN * sizeof( time_t ), 'u', 0, NULL },
00482        { BER_BVC("modify="),       SLAP_OP_MODIFY * sizeof( time_t ), 'u', 0, NULL },
00483        { BER_BVC("compare="),      SLAP_OP_COMPARE * sizeof( time_t ),       'u', 0, NULL },
00484        { BER_BVC("search="),       SLAP_OP_SEARCH * sizeof( time_t ), 'u', 0, NULL },
00485        /* abandon makes little sense */
00486 #if 0  /* not implemented yet */
00487        { BER_BVC("extended="),     SLAP_OP_EXTENDED * sizeof( time_t ),      'u', 0, NULL },
00488 #endif
00489        { BER_BVNULL, 0, 0, 0, NULL }
00490 };
00491 
00492 int
00493 slap_retry_info_parse(
00494        char                 *in,
00495        slap_retry_info_t    *ri,
00496        char                 *buf,
00497        ber_len_t            buflen )
00498 {
00499        char                 **retrylist = NULL;
00500        int                  rc = 0;
00501        int                  i;
00502 
00503        slap_str2clist( &retrylist, in, " ;" );
00504        if ( retrylist == NULL ) {
00505               return 1;
00506        }
00507 
00508        for ( i = 0; retrylist[ i ] != NULL; i++ )
00509               /* count */ ;
00510 
00511        ri->ri_interval = ch_calloc( sizeof( time_t ), i + 1 );
00512        ri->ri_num = ch_calloc( sizeof( int ), i + 1 );
00513 
00514        for ( i = 0; retrylist[ i ] != NULL; i++ ) {
00515               unsigned long t;
00516               char          *sep = strchr( retrylist[ i ], ',' );
00517 
00518               if ( sep == NULL ) {
00519                      snprintf( buf, buflen,
00520                             "missing comma in retry pattern #%d \"%s\"",
00521                             i, retrylist[ i ] );
00522                      rc = 1;
00523                      goto done;
00524               }
00525 
00526               *sep++ = '\0';
00527 
00528               if ( lutil_parse_time( retrylist[ i ], &t ) ) {
00529                      snprintf( buf, buflen,
00530                             "unable to parse interval #%d \"%s\"",
00531                             i, retrylist[ i ] );
00532                      rc = 1;
00533                      goto done;
00534               }
00535               ri->ri_interval[ i ] = (time_t)t;
00536 
00537               if ( strcmp( sep, "+" ) == 0 ) {
00538                      if ( retrylist[ i + 1 ] != NULL ) {
00539                             snprintf( buf, buflen,
00540                                    "extra cruft after retry pattern "
00541                                    "#%d \"%s,+\" with \"forever\" mark",
00542                                    i, retrylist[ i ] );
00543                             rc = 1;
00544                             goto done;
00545                      }
00546                      ri->ri_num[ i ] = SLAP_RETRYNUM_FOREVER;
00547                      
00548               } else if ( lutil_atoi( &ri->ri_num[ i ], sep ) ) {
00549                      snprintf( buf, buflen,
00550                             "unable to parse retry num #%d \"%s\"",
00551                             i, sep );
00552                      rc = 1;
00553                      goto done;
00554               }
00555        }
00556 
00557        ri->ri_num[ i ] = SLAP_RETRYNUM_TAIL;
00558 
00559        ri->ri_idx = 0;
00560        ri->ri_count = 0;
00561        ri->ri_last = (time_t)(-1);
00562 
00563 done:;
00564        ldap_charray_free( retrylist );
00565 
00566        if ( rc ) {
00567               slap_retry_info_destroy( ri );
00568        }
00569 
00570        return rc;
00571 }
00572 
00573 int
00574 slap_retry_info_unparse(
00575        slap_retry_info_t    *ri,
00576        struct berval        *bvout )
00577 {
00578        char          buf[ BUFSIZ * 2 ],
00579                      *ptr = buf;
00580        int           i, len, restlen = (int) sizeof( buf );
00581        struct berval bv;
00582 
00583        assert( ri != NULL );
00584        assert( bvout != NULL );
00585 
00586        BER_BVZERO( bvout );
00587 
00588        for ( i = 0; ri->ri_num[ i ] != SLAP_RETRYNUM_TAIL; i++ ) {
00589               if ( i > 0 ) {
00590                      if ( --restlen <= 0 ) {
00591                             return 1;
00592                      }
00593                      *ptr++ = ';';
00594               }
00595 
00596               if ( lutil_unparse_time( ptr, restlen, ri->ri_interval[i] ) < 0 ) {
00597                      return 1;
00598               }
00599               len = (int) strlen( ptr );
00600               if ( (restlen -= len + 1) <= 0 ) {
00601                      return 1;
00602               }
00603               ptr += len;
00604               *ptr++ = ',';
00605 
00606               if ( ri->ri_num[i] == SLAP_RETRYNUM_FOREVER ) {
00607                      if ( --restlen <= 0 ) {
00608                             return 1;
00609                      }
00610                      *ptr++ = '+';
00611 
00612               } else {
00613                      len = snprintf( ptr, restlen, "%d", ri->ri_num[i] );
00614                      if ( (restlen -= len) <= 0 || len < 0 ) {
00615                             return 1;
00616                      }
00617                      ptr += len;
00618               }
00619        }
00620 
00621        bv.bv_val = buf;
00622        bv.bv_len = ptr - buf;
00623        ber_dupbv( bvout, &bv );
00624 
00625        return 0;
00626 }
00627 
00628 void
00629 slap_retry_info_destroy(
00630        slap_retry_info_t    *ri )
00631 {
00632        assert( ri != NULL );
00633 
00634        assert( ri->ri_interval != NULL );
00635        ch_free( ri->ri_interval );
00636        ri->ri_interval = NULL;
00637 
00638        assert( ri->ri_num != NULL );
00639        ch_free( ri->ri_num );
00640        ri->ri_num = NULL;
00641 }
00642 
00643 static int
00644 slap_idassert_authzfrom_parse( ConfigArgs *c, slap_idassert_t *si )
00645 {
00646        struct berval bv;
00647        struct berval in;
00648        int           rc;
00649 
00650        if ( strcmp( c->argv[ 1 ], "*" ) == 0
00651               || strcmp( c->argv[ 1 ], "dn:*" ) == 0
00652               || strcasecmp( c->argv[ 1 ], "dn.regex:.*" ) == 0 )
00653        {
00654               if ( si->si_authz != NULL ) {
00655                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
00656                             "\"idassert-authzFrom <authz>\": "
00657                             "\"%s\" conflicts with existing authz rules",
00658                             c->argv[ 1 ] );
00659                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00660                      return 1;
00661               }
00662  
00663               si->si_flags |= LDAP_BACK_AUTH_AUTHZ_ALL;
00664  
00665               return 0;
00666  
00667        } else if ( ( si->si_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) ) {
00668               snprintf( c->cr_msg, sizeof( c->cr_msg ),
00669                      "\"idassert-authzFrom <authz>\": "
00670                      "\"<authz>\" conflicts with \"*\"" );
00671               Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00672               return 1;
00673        }
00674        
00675        ber_str2bv( c->argv[ 1 ], 0, 0, &in );
00676        rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
00677        if ( rc != LDAP_SUCCESS ) {
00678               snprintf( c->cr_msg, sizeof( c->cr_msg ),
00679                      "\"idassert-authzFrom <authz>\": "
00680                      "invalid syntax" );
00681               Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00682               return 1;
00683        }
00684 
00685        if ( c->valx == -1 ) {
00686               ber_bvarray_add( &si->si_authz, &bv );
00687 
00688        } else {
00689               int i = 0;
00690               if ( si->si_authz != NULL ) {
00691                      for ( ; !BER_BVISNULL( &si->si_authz[ i ] ); i++ )
00692                             ;
00693               }
00694 
00695               if ( i <= c->valx ) {
00696                      ber_bvarray_add( &si->si_authz, &bv );
00697 
00698               } else {
00699                      BerVarray tmp = ber_memrealloc( si->si_authz,
00700                             sizeof( struct berval )*( i + 2 ) );
00701                      if ( tmp == NULL ) {
00702                             return -1;
00703                      }
00704                      si->si_authz = tmp;
00705                      for ( ; i > c->valx; i-- ) {
00706                             si->si_authz[ i ] = si->si_authz[ i - 1 ];
00707                      }
00708                      si->si_authz[ c->valx ] = bv;
00709               }
00710        }
00711 
00712        return 0;
00713 }
00714 
00715 static int
00716 slap_idassert_passthru_parse( ConfigArgs *c, slap_idassert_t *si )
00717 {
00718        struct berval bv;
00719        struct berval in;
00720        int           rc;
00721 
00722        ber_str2bv( c->argv[ 1 ], 0, 0, &in );
00723        rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
00724        if ( rc != LDAP_SUCCESS ) {
00725               snprintf( c->cr_msg, sizeof( c->cr_msg ),
00726                      "\"idassert-passThru <authz>\": "
00727                      "invalid syntax" );
00728               Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00729               return 1;
00730        }
00731   
00732        if ( c->valx == -1 ) {
00733               ber_bvarray_add( &si->si_passthru, &bv );
00734 
00735        } else {
00736               int i = 0;
00737               if ( si->si_passthru != NULL ) {
00738                      for ( ; !BER_BVISNULL( &si->si_passthru[ i ] ); i++ )
00739                             ;
00740               }
00741 
00742               if ( i <= c->valx ) {
00743                      ber_bvarray_add( &si->si_passthru, &bv );
00744 
00745               } else {
00746                      BerVarray tmp = ber_memrealloc( si->si_passthru,
00747                             sizeof( struct berval )*( i + 2 ) );
00748                      if ( tmp == NULL ) {
00749                             return -1;
00750                      }
00751                      si->si_passthru = tmp;
00752                      for ( ; i > c->valx; i-- ) {
00753                             si->si_passthru[ i ] = si->si_passthru[ i - 1 ];
00754                      }
00755                      si->si_passthru[ c->valx ] = bv;
00756               }
00757        }
00758 
00759        return 0;
00760 }
00761 
00762 static int
00763 slap_idassert_parse( ConfigArgs *c, slap_idassert_t *si )
00764 {
00765        int           i;
00766 
00767        for ( i = 1; i < c->argc; i++ ) {
00768               if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
00769                      char   *argvi = c->argv[ i ] + STRLENOF( "mode=" );
00770                      int    j;
00771 
00772                      j = verb_to_mask( argvi, idassert_mode );
00773                      if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
00774                             snprintf( c->cr_msg, sizeof( c->cr_msg ),
00775                                    "\"idassert-bind <args>\": "
00776                                    "unknown mode \"%s\"",
00777                                    argvi );
00778                             Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00779                             return 1;
00780                      }
00781 
00782                      si->si_mode = idassert_mode[ j ].mask;
00783 
00784               } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
00785                      char   *argvi = c->argv[ i ] + STRLENOF( "authz=" );
00786 
00787                      if ( strcasecmp( argvi, "native" ) == 0 ) {
00788                             if ( si->si_bc.sb_method != LDAP_AUTH_SASL ) {
00789                                    snprintf( c->cr_msg, sizeof( c->cr_msg ),
00790                                           "\"idassert-bind <args>\": "
00791                                           "authz=\"native\" incompatible "
00792                                           "with auth method" );
00793                                    Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00794                                    return 1;
00795                             }
00796                             si->si_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
00797 
00798                      } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
00799                             si->si_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
00800 
00801                      } else {
00802                             snprintf( c->cr_msg, sizeof( c->cr_msg ),
00803                                    "\"idassert-bind <args>\": "
00804                                    "unknown authz \"%s\"",
00805                                    argvi );
00806                             Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00807                             return 1;
00808                      }
00809 
00810               } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
00811                      char   *argvi = c->argv[ i ] + STRLENOF( "flags=" );
00812                      char   **flags = ldap_str2charray( argvi, "," );
00813                      int    j, err = 0;
00814 
00815                      if ( flags == NULL ) {
00816                             snprintf( c->cr_msg, sizeof( c->cr_msg ),
00817                                    "\"idassert-bind <args>\": "
00818                                    "unable to parse flags \"%s\"",
00819                                    argvi );
00820                             Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00821                             return 1;
00822                      }
00823 
00824                      for ( j = 0; flags[ j ] != NULL; j++ ) {
00825 
00826                             if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
00827                                    si->si_flags |= LDAP_BACK_AUTH_OVERRIDE;
00828 
00829                             } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
00830                                    si->si_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
00831 
00832                             } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
00833                                    si->si_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
00834 
00835                             } else if ( strcasecmp( flags[ j ], "obsolete-proxy-authz" ) == 0 ) {
00836                                    if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
00837                                           Debug( LDAP_DEBUG_ANY,
00838                                                                "%s: \"obsolete-proxy-authz\" flag "
00839                                                                "in \"idassert-mode <args>\" "
00840                                                                "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
00841                                                                c->log, 0, 0 );
00842                                           err = 1;
00843                                           break;
00844 
00845                                    } else {
00846                                           si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
00847                                    }
00848 
00849                             } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
00850                                    if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
00851                                           Debug( LDAP_DEBUG_ANY,
00852                                                                "%s: \"obsolete-encoding-workaround\" flag "
00853                                                         "in \"idassert-mode <args>\" "
00854                                                         "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
00855                                                         c->log, 0, 0 );
00856                                           err = 1;
00857                                           break;
00858 
00859                                    } else {
00860                                           si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
00861                                    }
00862 
00863                             } else if ( strcasecmp( flags[ j ], "proxy-authz-critical" ) == 0 ) {
00864                                    si->si_flags |= LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;
00865 
00866                             } else if ( strcasecmp( flags[ j ], "proxy-authz-non-critical" ) == 0 ) {
00867                                    si->si_flags &= ~LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;
00868 
00869                             } else {
00870                                    snprintf( c->cr_msg, sizeof( c->cr_msg ),
00871                                           "\"idassert-bind <args>\": "
00872                                           "unknown flag \"%s\"",
00873                                           flags[ j ] );
00874                                    Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00875                                    err = 1;
00876                                    break;
00877                             }
00878                      }
00879 
00880                      ldap_charray_free( flags );
00881                      if ( err ) {
00882                             return 1;
00883                      }
00884 
00885               } else if ( bindconf_parse( c->argv[ i ], &si->si_bc ) ) {
00886                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
00887                             "\"idassert-bind <args>\": "
00888                             "unable to parse field \"%s\"",
00889                             c->argv[ i ] );
00890                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00891                      return 1;
00892               }
00893        }
00894 
00895        if ( si->si_bc.sb_method == LDAP_AUTH_SIMPLE ) {
00896               if ( BER_BVISNULL( &si->si_bc.sb_binddn )
00897                      || BER_BVISNULL( &si->si_bc.sb_cred ) )
00898               {
00899                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
00900                             "\"idassert-bind <args>\": "
00901                             "SIMPLE needs \"binddn\" and \"credentials\"" );
00902                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
00903                      return 1;
00904               }
00905        }
00906 
00907        bindconf_tls_defaults( &si->si_bc );
00908 
00909        return 0;
00910 }
00911 
00912 /* NOTE: temporary, until back-meta is ported to back-config */
00913 int
00914 slap_idassert_authzfrom_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si )
00915 {
00916        ConfigArgs    c = { 0 };
00917        char          *argv[ 3 ];
00918 
00919        snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
00920        c.argc = 2;
00921        c.argv = argv;
00922        argv[ 0 ] = "idassert-authzFrom";
00923        argv[ 1 ] = (char *)arg;
00924        argv[ 2 ] = NULL;
00925 
00926        return slap_idassert_authzfrom_parse( &c, si );
00927 }
00928 
00929 int
00930 slap_idassert_passthru_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si )
00931 {
00932        ConfigArgs    c = { 0 };
00933        char          *argv[ 3 ];
00934 
00935        snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
00936        c.argc = 2;
00937        c.argv = argv;
00938        argv[ 0 ] = "idassert-passThru";
00939        argv[ 1 ] = (char *)arg;
00940        argv[ 2 ] = NULL;
00941 
00942        return slap_idassert_passthru_parse( &c, si );
00943 }
00944 
00945 int
00946 slap_idassert_parse_cf( const char *fname, int lineno, int argc, char *argv[], slap_idassert_t *si )
00947 {
00948        ConfigArgs    c = { 0 };
00949 
00950        snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
00951        c.argc = argc;
00952        c.argv = argv;
00953 
00954        return slap_idassert_parse( &c, si );
00955 }
00956 
00957 static int
00958 ldap_back_cf_gen( ConfigArgs *c )
00959 {
00960        ldapinfo_t    *li = ( ldapinfo_t * )c->be->be_private;
00961        int           rc = 0;
00962        int           i;
00963 
00964        if ( c->op == SLAP_CONFIG_EMIT ) {
00965               struct berval bv = BER_BVNULL;
00966 
00967               if ( li == NULL ) {
00968                      return 1;
00969               }
00970 
00971               switch( c->type ) {
00972               case LDAP_BACK_CFG_URI:
00973                      if ( li->li_uri != NULL ) {
00974                             struct berval bv, bv2;
00975 
00976                             ber_str2bv( li->li_uri, 0, 0, &bv );
00977                             bv2.bv_len = bv.bv_len + STRLENOF( "\"\"" );
00978                             bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
00979                             snprintf( bv2.bv_val, bv2.bv_len + 1,
00980                                    "\"%s\"", bv.bv_val );
00981                             ber_bvarray_add( &c->rvalue_vals, &bv2 );
00982 
00983                      } else {
00984                             rc = 1;
00985                      }
00986                      break;
00987 
00988               case LDAP_BACK_CFG_TLS: {
00989                      struct berval bc = BER_BVNULL, bv2;
00990                      enum_to_verb( tls_mode, ( li->li_flags & LDAP_BACK_F_TLS_MASK ), &bv );
00991                      assert( !BER_BVISNULL( &bv ) );
00992                      bindconf_tls_unparse( &li->li_tls, &bc );
00993 
00994                      if ( !BER_BVISEMPTY( &bc )) {
00995                             bv2.bv_len = bv.bv_len + bc.bv_len + 1;
00996                             bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
00997                             strcpy( bv2.bv_val, bv.bv_val );
00998                             bv2.bv_val[bv.bv_len] = ' ';
00999                             strcpy( &bv2.bv_val[bv.bv_len + 1], bc.bv_val );
01000                             ber_bvarray_add( &c->rvalue_vals, &bv2 );
01001 
01002                      } else {
01003                             value_add_one( &c->rvalue_vals, &bv );
01004                      }
01005                      ber_memfree( bc.bv_val );
01006                      }
01007                      break;
01008 
01009               case LDAP_BACK_CFG_ACL_AUTHCDN:
01010               case LDAP_BACK_CFG_ACL_PASSWD:
01011               case LDAP_BACK_CFG_ACL_METHOD:
01012                      /* handled by LDAP_BACK_CFG_ACL_BIND */
01013                      rc = 1;
01014                      break;
01015 
01016               case LDAP_BACK_CFG_ACL_BIND: {
01017                      int    i;
01018 
01019                      if ( li->li_acl_authmethod == LDAP_AUTH_NONE ) {
01020                             return 1;
01021                      }
01022 
01023                      bindconf_unparse( &li->li_acl, &bv );
01024 
01025                      for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
01026                             /* count spaces */ ;
01027 
01028                      if ( i ) {
01029                             bv.bv_len -= i;
01030                             AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
01031                                    bv.bv_len + 1 );
01032                      }
01033 
01034                      ber_bvarray_add( &c->rvalue_vals, &bv );
01035                      break;
01036               }
01037 
01038               case LDAP_BACK_CFG_IDASSERT_MODE:
01039               case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
01040               case LDAP_BACK_CFG_IDASSERT_PASSWD:
01041               case LDAP_BACK_CFG_IDASSERT_METHOD:
01042                      /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
01043                      rc = 1;
01044                      break;
01045 
01046               case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
01047               case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
01048                      BerVarray     *bvp;
01049                      int           i;
01050                      struct berval bv = BER_BVNULL;
01051                      char          buf[SLAP_TEXT_BUFLEN];
01052 
01053                      switch ( c->type ) {
01054                      case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
01055                      case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
01056                      default: assert( 0 ); break;
01057                      }
01058 
01059                      if ( *bvp == NULL ) {
01060                             if ( bvp == &li->li_idassert_authz
01061                                    && ( li->li_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) )
01062                             {
01063                                    BER_BVSTR( &bv, "*" );
01064                                    value_add_one( &c->rvalue_vals, &bv );
01065 
01066                             } else {
01067                                    rc = 1;
01068                             }
01069                             break;
01070                      }
01071 
01072                      for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ ) {
01073                             char *ptr;
01074                             int len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
01075                             bv.bv_len = ((*bvp)[ i ]).bv_len + len;
01076                             bv.bv_val = ber_memrealloc( bv.bv_val, bv.bv_len + 1 );
01077                             ptr = bv.bv_val;
01078                             ptr = lutil_strcopy( ptr, buf );
01079                             ptr = lutil_strncopy( ptr, ((*bvp)[ i ]).bv_val, ((*bvp)[ i ]).bv_len );
01080                             value_add_one( &c->rvalue_vals, &bv );
01081                      }
01082                      if ( bv.bv_val ) {
01083                             ber_memfree( bv.bv_val );
01084                      }
01085                      break;
01086               }
01087 
01088               case LDAP_BACK_CFG_IDASSERT_BIND: {
01089                      int           i;
01090                      struct berval bc = BER_BVNULL;
01091                      char          *ptr;
01092 
01093                      if ( li->li_idassert_authmethod == LDAP_AUTH_NONE ) {
01094                             return 1;
01095                      }
01096 
01097                      if ( li->li_idassert_authmethod != LDAP_AUTH_NONE ) {
01098                             ber_len_t     len;
01099 
01100                             switch ( li->li_idassert_mode ) {
01101                             case LDAP_BACK_IDASSERT_OTHERID:
01102                             case LDAP_BACK_IDASSERT_OTHERDN:
01103                                    break;
01104 
01105                             default: {
01106                                    struct berval mode = BER_BVNULL;
01107 
01108                                    enum_to_verb( idassert_mode, li->li_idassert_mode, &mode );
01109                                    if ( BER_BVISNULL( &mode ) ) {
01110                                           /* there's something wrong... */
01111                                           assert( 0 );
01112                                           rc = 1;
01113        
01114                                    } else {
01115                                           bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
01116                                           bv.bv_val = ch_malloc( bv.bv_len + 1 );
01117 
01118                                           ptr = lutil_strcopy( bv.bv_val, "mode=" );
01119                                           ptr = lutil_strcopy( ptr, mode.bv_val );
01120                                    }
01121                                    break;
01122                             }
01123                             }
01124 
01125                             if ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
01126                                    len = bv.bv_len + STRLENOF( "authz=native" );
01127 
01128                                    if ( !BER_BVISEMPTY( &bv ) ) {
01129                                           len += STRLENOF( " " );
01130                                    }
01131 
01132                                    bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
01133 
01134                                    ptr = &bv.bv_val[ bv.bv_len ];
01135 
01136                                    if ( !BER_BVISEMPTY( &bv ) ) {
01137                                           ptr = lutil_strcopy( ptr, " " );
01138                                    }
01139 
01140                                    (void)lutil_strcopy( ptr, "authz=native" );
01141                             }
01142 
01143                             len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override,obsolete-encoding-workaround,proxy-authz-non-critical" );
01144                             /* flags */
01145                             if ( !BER_BVISEMPTY( &bv ) ) {
01146                                    len += STRLENOF( " " );
01147                             }
01148 
01149                             bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
01150 
01151                             ptr = &bv.bv_val[ bv.bv_len ];
01152 
01153                             if ( !BER_BVISEMPTY( &bv ) ) {
01154                                    ptr = lutil_strcopy( ptr, " " );
01155                             }
01156 
01157                             ptr = lutil_strcopy( ptr, "flags=" );
01158 
01159                             if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
01160                                    ptr = lutil_strcopy( ptr, "prescriptive" );
01161                             } else {
01162                                    ptr = lutil_strcopy( ptr, "non-prescriptive" );
01163                             }
01164 
01165                             if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
01166                                    ptr = lutil_strcopy( ptr, ",override" );
01167                             }
01168 
01169                             if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
01170                                    ptr = lutil_strcopy( ptr, ",obsolete-proxy-authz" );
01171 
01172                             } else if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
01173                                    ptr = lutil_strcopy( ptr, ",obsolete-encoding-workaround" );
01174                             }
01175 
01176                             if ( li->li_idassert_flags & LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL ) {
01177                                    ptr = lutil_strcopy( ptr, ",proxy-authz-critical" );
01178 
01179                             } else {
01180                                    ptr = lutil_strcopy( ptr, ",proxy-authz-non-critical" );
01181                             }
01182 
01183                             bv.bv_len = ( ptr - bv.bv_val );
01184                             /* end-of-flags */
01185                      }
01186 
01187                      bindconf_unparse( &li->li_idassert.si_bc, &bc );
01188 
01189                      if ( !BER_BVISNULL( &bv ) ) {
01190                             ber_len_t     len = bv.bv_len + bc.bv_len;
01191 
01192                             bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
01193 
01194                             assert( bc.bv_val[ 0 ] == ' ' );
01195 
01196                             ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
01197                             free( bc.bv_val );
01198                             bv.bv_len = ptr - bv.bv_val;
01199 
01200                      } else {
01201                             for ( i = 0; isspace( (unsigned char) bc.bv_val[ i ] ); i++ )
01202                                    /* count spaces */ ;
01203 
01204                             if ( i ) {
01205                                    bc.bv_len -= i;
01206                                    AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
01207                             }
01208 
01209                             bv = bc;
01210                      }
01211                      
01212                      ber_bvarray_add( &c->rvalue_vals, &bv );
01213 
01214                      break;
01215               }
01216 
01217               case LDAP_BACK_CFG_REBIND:
01218                      c->value_int = LDAP_BACK_SAVECRED( li );
01219                      break;
01220 
01221               case LDAP_BACK_CFG_CHASE:
01222                      c->value_int = LDAP_BACK_CHASE_REFERRALS( li );
01223                      break;
01224 
01225               case LDAP_BACK_CFG_T_F:
01226                      enum_to_verb( t_f_mode, (li->li_flags & LDAP_BACK_F_T_F_MASK2), &bv );
01227                      if ( BER_BVISNULL( &bv ) ) {
01228                             /* there's something wrong... */
01229                             assert( 0 );
01230                             rc = 1;
01231 
01232                      } else {
01233                             value_add_one( &c->rvalue_vals, &bv );
01234                      }
01235                      break;
01236 
01237               case LDAP_BACK_CFG_WHOAMI:
01238                      c->value_int = LDAP_BACK_PROXY_WHOAMI( li );
01239                      break;
01240 
01241               case LDAP_BACK_CFG_TIMEOUT:
01242                      BER_BVZERO( &bv );
01243 
01244                      for ( i = 0; i < SLAP_OP_LAST; i++ ) {
01245                             if ( li->li_timeout[ i ] != 0 ) {
01246                                    break;
01247                             }
01248                      }
01249 
01250                      if ( i == SLAP_OP_LAST ) {
01251                             return 1;
01252                      }
01253 
01254                      slap_cf_aux_table_unparse( li->li_timeout, &bv, timeout_table );
01255 
01256                      if ( BER_BVISNULL( &bv ) ) {
01257                             return 1;
01258                      }
01259 
01260                      for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
01261                             /* count spaces */ ;
01262 
01263                      if ( i ) {
01264                             bv.bv_len -= i;
01265                             AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
01266                                    bv.bv_len + 1 );
01267                      }
01268 
01269                      ber_bvarray_add( &c->rvalue_vals, &bv );
01270                      break;
01271 
01272               case LDAP_BACK_CFG_IDLE_TIMEOUT: {
01273                      char   buf[ SLAP_TEXT_BUFLEN ];
01274 
01275                      if ( li->li_idle_timeout == 0 ) {
01276                             return 1;
01277                      }
01278 
01279                      lutil_unparse_time( buf, sizeof( buf ), li->li_idle_timeout );
01280                      ber_str2bv( buf, 0, 0, &bv );
01281                      value_add_one( &c->rvalue_vals, &bv );
01282                      } break;
01283 
01284               case LDAP_BACK_CFG_CONN_TTL: {
01285                      char   buf[ SLAP_TEXT_BUFLEN ];
01286 
01287                      if ( li->li_conn_ttl == 0 ) {
01288                             return 1;
01289                      }
01290 
01291                      lutil_unparse_time( buf, sizeof( buf ), li->li_conn_ttl );
01292                      ber_str2bv( buf, 0, 0, &bv );
01293                      value_add_one( &c->rvalue_vals, &bv );
01294                      } break;
01295 
01296               case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
01297                      char   buf[ SLAP_TEXT_BUFLEN ];
01298 
01299                      if ( li->li_network_timeout == 0 ) {
01300                             return 1;
01301                      }
01302 
01303                      snprintf( buf, sizeof( buf ), "%ld",
01304                             (long)li->li_network_timeout );
01305                      ber_str2bv( buf, 0, 0, &bv );
01306                      value_add_one( &c->rvalue_vals, &bv );
01307                      } break;
01308 
01309               case LDAP_BACK_CFG_VERSION:
01310                      if ( li->li_version == 0 ) {
01311                             return 1;
01312                      }
01313 
01314                      c->value_int = li->li_version;
01315                      break;
01316 
01317               case LDAP_BACK_CFG_SINGLECONN:
01318                      c->value_int = LDAP_BACK_SINGLECONN( li );
01319                      break;
01320 
01321               case LDAP_BACK_CFG_USETEMP:
01322                      c->value_int = LDAP_BACK_USE_TEMPORARIES( li );
01323                      break;
01324 
01325               case LDAP_BACK_CFG_CONNPOOLMAX:
01326                      c->value_int = li->li_conn_priv_max;
01327                      break;
01328 
01329               case LDAP_BACK_CFG_CANCEL: {
01330                      slap_mask_t   mask = LDAP_BACK_F_CANCEL_MASK2;
01331 
01332                      if ( LDAP_BACK_CANCEL_DISCOVER( li ) ) {
01333                             mask &= ~LDAP_BACK_F_CANCEL_EXOP;
01334                      }
01335                      enum_to_verb( cancel_mode, (li->li_flags & mask), &bv );
01336                      if ( BER_BVISNULL( &bv ) ) {
01337                             /* there's something wrong... */
01338                             assert( 0 );
01339                             rc = 1;
01340 
01341                      } else {
01342                             value_add_one( &c->rvalue_vals, &bv );
01343                      }
01344                      } break;
01345 
01346               case LDAP_BACK_CFG_QUARANTINE:
01347                      if ( !LDAP_BACK_QUARANTINE( li ) ) {
01348                             rc = 1;
01349                             break;
01350                      }
01351 
01352                      rc = slap_retry_info_unparse( &li->li_quarantine, &bv );
01353                      if ( rc == 0 ) {
01354                             ber_bvarray_add( &c->rvalue_vals, &bv );
01355                      }
01356                      break;
01357 
01358 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
01359               case LDAP_BACK_CFG_ST_REQUEST:
01360                      c->value_int = LDAP_BACK_ST_REQUEST( li );
01361                      break;
01362 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
01363 
01364               case LDAP_BACK_CFG_NOREFS:
01365                      c->value_int = LDAP_BACK_NOREFS( li );
01366                      break;
01367 
01368               case LDAP_BACK_CFG_NOUNDEFFILTER:
01369                      c->value_int = LDAP_BACK_NOUNDEFFILTER( li );
01370                      break;
01371 
01372               default:
01373                      /* FIXME: we need to handle all... */
01374                      assert( 0 );
01375                      break;
01376               }
01377               return rc;
01378 
01379        } else if ( c->op == LDAP_MOD_DELETE ) {
01380               switch( c->type ) {
01381               case LDAP_BACK_CFG_URI:
01382                      if ( li->li_uri != NULL ) {
01383                             ch_free( li->li_uri );
01384                             li->li_uri = NULL;
01385 
01386                             assert( li->li_bvuri != NULL );
01387                             ber_bvarray_free( li->li_bvuri );
01388                             li->li_bvuri = NULL;
01389                      }
01390 
01391                      /* better cleanup the cached connections... */
01392                      /* NOTE: don't worry about locking: if we got here,
01393                       * other threads are suspended. */
01394                      if ( li->li_conninfo.lai_tree != NULL ) {
01395                             avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
01396                             li->li_conninfo.lai_tree = NULL;
01397                      }
01398                      
01399                      break;
01400 
01401               case LDAP_BACK_CFG_TLS:
01402                      rc = 1;
01403                      break;
01404 
01405               case LDAP_BACK_CFG_ACL_AUTHCDN:
01406               case LDAP_BACK_CFG_ACL_PASSWD:
01407               case LDAP_BACK_CFG_ACL_METHOD:
01408                      /* handled by LDAP_BACK_CFG_ACL_BIND */
01409                      rc = 1;
01410                      break;
01411 
01412               case LDAP_BACK_CFG_ACL_BIND:
01413                      bindconf_free( &li->li_acl );
01414                      break;
01415 
01416               case LDAP_BACK_CFG_IDASSERT_MODE:
01417               case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
01418               case LDAP_BACK_CFG_IDASSERT_PASSWD:
01419               case LDAP_BACK_CFG_IDASSERT_METHOD:
01420                      /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
01421                      rc = 1;
01422                      break;
01423 
01424               case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
01425               case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
01426                      BerVarray *bvp;
01427 
01428                      switch ( c->type ) {
01429                      case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
01430                      case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
01431                      default: assert( 0 ); break;
01432                      }
01433 
01434                      if ( c->valx < 0 ) {
01435                             if ( *bvp != NULL ) {
01436                                    ber_bvarray_free( *bvp );
01437                                    *bvp = NULL;
01438                             }
01439 
01440                      } else {
01441                             int i;
01442 
01443                             if ( *bvp == NULL ) {
01444                                    rc = 1;
01445                                    break;
01446                             }
01447 
01448                             for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ )
01449                                    ;
01450 
01451                             if ( i >= c->valx ) {
01452                                    rc = 1;
01453                                    break;
01454                             }
01455                             ber_memfree( ((*bvp)[ c->valx ]).bv_val );
01456                             for ( i = c->valx; !BER_BVISNULL( &((*bvp)[ i + 1 ]) ); i++ ) {
01457                                    (*bvp)[ i ] = (*bvp)[ i + 1 ];
01458                             }
01459                             BER_BVZERO( &((*bvp)[ i ]) );
01460                      }
01461                      } break;
01462 
01463               case LDAP_BACK_CFG_IDASSERT_BIND:
01464                      bindconf_free( &li->li_idassert.si_bc );
01465                      memset( &li->li_idassert, 0, sizeof( slap_idassert_t ) );
01466                      break;
01467 
01468               case LDAP_BACK_CFG_REBIND:
01469               case LDAP_BACK_CFG_CHASE:
01470               case LDAP_BACK_CFG_T_F:
01471               case LDAP_BACK_CFG_WHOAMI:
01472               case LDAP_BACK_CFG_CANCEL:
01473                      rc = 1;
01474                      break;
01475 
01476               case LDAP_BACK_CFG_TIMEOUT:
01477                      for ( i = 0; i < SLAP_OP_LAST; i++ ) {
01478                             li->li_timeout[ i ] = 0;
01479                      }
01480                      break;
01481 
01482               case LDAP_BACK_CFG_IDLE_TIMEOUT:
01483                      li->li_idle_timeout = 0;
01484                      break;
01485 
01486               case LDAP_BACK_CFG_CONN_TTL:
01487                      li->li_conn_ttl = 0;
01488                      break;
01489 
01490               case LDAP_BACK_CFG_NETWORK_TIMEOUT:
01491                      li->li_network_timeout = 0;
01492                      break;
01493 
01494               case LDAP_BACK_CFG_VERSION:
01495                      li->li_version = 0;
01496                      break;
01497 
01498               case LDAP_BACK_CFG_SINGLECONN:
01499                      li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
01500                      break;
01501 
01502               case LDAP_BACK_CFG_USETEMP:
01503                      li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
01504                      break;
01505 
01506               case LDAP_BACK_CFG_CONNPOOLMAX:
01507                      li->li_conn_priv_max = LDAP_BACK_CONN_PRIV_MIN;
01508                      break;
01509 
01510               case LDAP_BACK_CFG_QUARANTINE:
01511                      if ( !LDAP_BACK_QUARANTINE( li ) ) {
01512                             break;
01513                      }
01514 
01515                      slap_retry_info_destroy( &li->li_quarantine );
01516                      ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex );
01517                      li->li_isquarantined = 0;
01518                      li->li_flags &= ~LDAP_BACK_F_QUARANTINE;
01519                      break;
01520 
01521 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
01522               case LDAP_BACK_CFG_ST_REQUEST:
01523                      li->li_flags &= ~LDAP_BACK_F_ST_REQUEST;
01524                      break;
01525 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
01526 
01527               case LDAP_BACK_CFG_NOREFS:
01528                      li->li_flags &= ~LDAP_BACK_F_NOREFS;
01529                      break;
01530 
01531               case LDAP_BACK_CFG_NOUNDEFFILTER:
01532                      li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER;
01533                      break;
01534 
01535               default:
01536                      /* FIXME: we need to handle all... */
01537                      assert( 0 );
01538                      break;
01539               }
01540               return rc;
01541 
01542        }
01543 
01544        switch( c->type ) {
01545        case LDAP_BACK_CFG_URI: {
01546               LDAPURLDesc   *tmpludp, *lud;
01547               char          **urllist = NULL;
01548               int           urlrc = LDAP_URL_SUCCESS, i;
01549 
01550               if ( li->li_uri != NULL ) {
01551                      ch_free( li->li_uri );
01552                      li->li_uri = NULL;
01553 
01554                      assert( li->li_bvuri != NULL );
01555                      ber_bvarray_free( li->li_bvuri );
01556                      li->li_bvuri = NULL;
01557               }
01558 
01559               /* PARANOID: DN and more are not required nor allowed */
01560               urlrc = ldap_url_parselist_ext( &lud, c->argv[ 1 ], ", \t", LDAP_PVT_URL_PARSE_NONE );
01561               if ( urlrc != LDAP_URL_SUCCESS ) {
01562                      char   *why;
01563 
01564                      switch ( urlrc ) {
01565                      case LDAP_URL_ERR_MEM:
01566                             why = "no memory";
01567                             break;
01568                      case LDAP_URL_ERR_PARAM:
01569                             why = "parameter is bad";
01570                             break;
01571                      case LDAP_URL_ERR_BADSCHEME:
01572                             why = "URL doesn't begin with \"[c]ldap[si]://\"";
01573                             break;
01574                      case LDAP_URL_ERR_BADENCLOSURE:
01575                             why = "URL is missing trailing \">\"";
01576                             break;
01577                      case LDAP_URL_ERR_BADURL:
01578                             why = "URL is bad";
01579                             break;
01580                      case LDAP_URL_ERR_BADHOST:
01581                             why = "host/port is bad";
01582                             break;
01583                      case LDAP_URL_ERR_BADATTRS:
01584                             why = "bad (or missing) attributes";
01585                             break;
01586                      case LDAP_URL_ERR_BADSCOPE:
01587                             why = "scope string is invalid (or missing)";
01588                             break;
01589                      case LDAP_URL_ERR_BADFILTER:
01590                             why = "bad or missing filter";
01591                             break;
01592                      case LDAP_URL_ERR_BADEXTS:
01593                             why = "bad or missing extensions";
01594                             break;
01595                      default:
01596                             why = "unknown reason";
01597                             break;
01598                      }
01599                      snprintf( c->cr_msg, sizeof( c->cr_msg),
01600                                    "unable to parse uri \"%s\" "
01601                                    "in \"uri <uri>\" line: %s",
01602                                    c->value_string, why );
01603                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01604                      urlrc = 1;
01605                      goto done_url;
01606               }
01607 
01608               for ( i = 0, tmpludp = lud;
01609                             tmpludp;
01610                             i++, tmpludp = tmpludp->lud_next )
01611               {
01612                      if ( ( tmpludp->lud_dn != NULL
01613                                           && tmpludp->lud_dn[0] != '\0' )
01614                                    || tmpludp->lud_attrs != NULL
01615                                    /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
01616                                    || tmpludp->lud_filter != NULL
01617                                    || tmpludp->lud_exts != NULL )
01618                      {
01619                             snprintf( c->cr_msg, sizeof( c->cr_msg ),
01620                                           "warning, only protocol, "
01621                                           "host and port allowed "
01622                                           "in \"uri <uri>\" statement "
01623                                           "for uri #%d of \"%s\"",
01624                                           i, c->argv[ 1 ] );
01625                             Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01626                      }
01627               }
01628 
01629               for ( i = 0, tmpludp = lud;
01630                             tmpludp;
01631                             i++, tmpludp = tmpludp->lud_next )
01632                      /* just count */
01633                      ;
01634               urllist = ch_calloc( sizeof( char * ), i + 1 );
01635 
01636               for ( i = 0, tmpludp = lud;
01637                             tmpludp;
01638                             i++, tmpludp = tmpludp->lud_next )
01639               {
01640                      LDAPURLDesc   tmplud;
01641 
01642                      tmplud = *tmpludp;
01643                      tmplud.lud_dn = "";
01644                      tmplud.lud_attrs = NULL;
01645                      tmplud.lud_filter = NULL;
01646                      if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
01647                             tmplud.lud_exts = NULL;
01648                             tmplud.lud_crit_exts = 0;
01649                      }
01650 
01651                      urllist[ i ]  = ldap_url_desc2str( &tmplud );
01652 
01653                      if ( urllist[ i ] == NULL ) {
01654                             snprintf( c->cr_msg, sizeof( c->cr_msg),
01655                                    "unable to rebuild uri "
01656                                    "in \"uri <uri>\" statement "
01657                                    "for \"%s\"",
01658                                    c->argv[ 1 ] );
01659                             Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01660                             urlrc = 1;
01661                             goto done_url;
01662                      }
01663               }
01664 
01665               li->li_uri = ldap_charray2str( urllist, " " );
01666               for ( i = 0; urllist[ i ] != NULL; i++ ) {
01667                      struct berval bv;
01668 
01669                      ber_str2bv( urllist[ i ], 0, 0, &bv );
01670                      ber_bvarray_add( &li->li_bvuri, &bv );
01671                      urllist[ i ] = NULL;
01672               }
01673               ldap_memfree( urllist );
01674               urllist = NULL;
01675 
01676 done_url:;
01677               if ( urllist ) {
01678                      ldap_charray_free( urllist );
01679               }
01680               if ( lud ) {
01681                      ldap_free_urllist( lud );
01682               }
01683               if ( urlrc != LDAP_URL_SUCCESS ) {
01684                      return 1;
01685               }
01686               break;
01687        }
01688 
01689        case LDAP_BACK_CFG_TLS:
01690               i = verb_to_mask( c->argv[1], tls_mode );
01691               if ( BER_BVISNULL( &tls_mode[i].word ) ) {
01692                      return 1;
01693               }
01694               li->li_flags &= ~LDAP_BACK_F_TLS_MASK;
01695               li->li_flags |= tls_mode[i].mask;
01696               if ( c->argc > 2 ) {
01697                      for ( i=2; i<c->argc; i++ ) {
01698                             if ( bindconf_tls_parse( c->argv[i], &li->li_tls ))
01699                                    return 1;
01700                      }
01701                      bindconf_tls_defaults( &li->li_tls );
01702               }
01703               break;
01704 
01705        case LDAP_BACK_CFG_ACL_AUTHCDN:
01706               switch ( li->li_acl_authmethod ) {
01707               case LDAP_AUTH_NONE:
01708                      li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
01709                      break;
01710 
01711               case LDAP_AUTH_SIMPLE:
01712                      break;
01713 
01714               default:
01715                      snprintf( c->cr_msg, sizeof( c->cr_msg),
01716                             "\"acl-authcDN <DN>\" incompatible "
01717                             "with auth method %d",
01718                             li->li_acl_authmethod );
01719                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01720                      return 1;
01721               }
01722               if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
01723                      free( li->li_acl_authcDN.bv_val );
01724               }
01725               ber_memfree_x( c->value_dn.bv_val, NULL );
01726               li->li_acl_authcDN = c->value_ndn;
01727               BER_BVZERO( &c->value_dn );
01728               BER_BVZERO( &c->value_ndn );
01729               break;
01730 
01731        case LDAP_BACK_CFG_ACL_PASSWD:
01732               switch ( li->li_acl_authmethod ) {
01733               case LDAP_AUTH_NONE:
01734                      li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
01735                      break;
01736 
01737               case LDAP_AUTH_SIMPLE:
01738                      break;
01739 
01740               default:
01741                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
01742                             "\"acl-passwd <cred>\" incompatible "
01743                             "with auth method %d",
01744                             li->li_acl_authmethod );
01745                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01746                      return 1;
01747               }
01748               if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
01749                      free( li->li_acl_passwd.bv_val );
01750               }
01751               ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_acl_passwd );
01752               break;
01753 
01754        case LDAP_BACK_CFG_ACL_METHOD:
01755        case LDAP_BACK_CFG_ACL_BIND:
01756               for ( i = 1; i < c->argc; i++ ) {
01757                      if ( bindconf_parse( c->argv[ i ], &li->li_acl ) ) {
01758                             return 1;
01759                      }
01760               }
01761               bindconf_tls_defaults( &li->li_acl );
01762               break;
01763 
01764        case LDAP_BACK_CFG_IDASSERT_MODE:
01765               i = verb_to_mask( c->argv[1], idassert_mode );
01766               if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
01767                      if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
01768                             li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
01769                             ber_str2bv( c->argv[1], 0, 1, &li->li_idassert_authzID );
01770                             li->li_idassert_authzID.bv_val[ 0 ] = 'u';
01771                             
01772                      } else {
01773                             struct berval id, ndn;
01774 
01775                             ber_str2bv( c->argv[1], 0, 0, &id );
01776 
01777                             if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
01778                                    id.bv_val += STRLENOF( "dn:" );
01779                                    id.bv_len -= STRLENOF( "dn:" );
01780                             }
01781 
01782                             rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
01783                                 if ( rc != LDAP_SUCCESS ) {
01784                                         Debug( LDAP_DEBUG_ANY,
01785                                                 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
01786                                                 c->fname, c->lineno, c->argv[1] );
01787                                         return 1;
01788                                 }
01789 
01790                                 li->li_idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
01791                                 li->li_idassert_authzID.bv_val = ch_malloc( li->li_idassert_authzID.bv_len + 1 );
01792                                 AC_MEMCPY( li->li_idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
01793                                 AC_MEMCPY( &li->li_idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
01794                                 ch_free( ndn.bv_val );
01795 
01796                                 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
01797                      }
01798 
01799               } else {
01800                      li->li_idassert_mode = idassert_mode[i].mask;
01801               }
01802 
01803               if ( c->argc > 2 ) {
01804                      int    i;
01805 
01806                      for ( i = 2; i < c->argc; i++ ) {
01807                             if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
01808                                    li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
01809 
01810                             } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
01811                                    li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
01812 
01813                             } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
01814                                    li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
01815 
01816                             } else if ( strcasecmp( c->argv[ i ], "obsolete-proxy-authz" ) == 0 ) {
01817                                    if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
01818                                           Debug( LDAP_DEBUG_ANY,
01819                                                         "%s: line %d: \"obsolete-proxy-authz\" flag "
01820                                                  "in \"idassert-mode <args>\" "
01821                                                  "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
01822                                                  c->fname, c->lineno, 0 );
01823                                           return 1;
01824                                    }
01825                                    li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
01826 
01827                             } else if ( strcasecmp( c->argv[ i ], "obsolete-encoding-workaround" ) == 0 ) {
01828                                    if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
01829                                           Debug( LDAP_DEBUG_ANY,
01830                                                         "%s: line %d: \"obsolete-encoding-workaround\" flag "
01831                                                  "in \"idassert-mode <args>\" "
01832                                                  "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
01833                                                  c->fname, c->lineno, 0 );
01834                                           return 1;
01835                                    }
01836                                    li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
01837 
01838                             } else {
01839                                    Debug( LDAP_DEBUG_ANY,
01840                                           "%s: line %d: unknown flag #%d "
01841                                           "in \"idassert-mode <args> "
01842                                           "[<flags>]\" line.\n",
01843                                           c->fname, c->lineno, i - 2 );
01844                                    return 1;
01845                             }
01846                         }
01847                 }
01848               break;
01849 
01850        case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
01851               switch ( li->li_idassert_authmethod ) {
01852               case LDAP_AUTH_NONE:
01853                      li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
01854                      break;
01855 
01856               case LDAP_AUTH_SIMPLE:
01857                      break;
01858 
01859               default:
01860                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
01861                             "\"idassert-authcDN <DN>\" incompatible "
01862                             "with auth method %d",
01863                             li->li_idassert_authmethod );
01864                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01865                      return 1;
01866               }
01867               if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
01868                      free( li->li_idassert_authcDN.bv_val );
01869               }
01870               ber_memfree_x( c->value_dn.bv_val, NULL );
01871               li->li_idassert_authcDN = c->value_ndn;
01872               BER_BVZERO( &c->value_dn );
01873               BER_BVZERO( &c->value_ndn );
01874               break;
01875 
01876        case LDAP_BACK_CFG_IDASSERT_PASSWD:
01877               switch ( li->li_idassert_authmethod ) {
01878               case LDAP_AUTH_NONE:
01879                      li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
01880                      break;
01881 
01882               case LDAP_AUTH_SIMPLE:
01883                      break;
01884 
01885               default:
01886                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
01887                             "\"idassert-passwd <cred>\" incompatible "
01888                             "with auth method %d",
01889                             li->li_idassert_authmethod );
01890                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01891                      return 1;
01892               }
01893               if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
01894                      free( li->li_idassert_passwd.bv_val );
01895               }
01896               ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_idassert_passwd );
01897               break;
01898 
01899        case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
01900               rc = slap_idassert_authzfrom_parse( c, &li->li_idassert );
01901               break;
01902 
01903        case LDAP_BACK_CFG_IDASSERT_PASSTHRU:
01904               rc = slap_idassert_passthru_parse( c, &li->li_idassert );
01905               break;
01906 
01907        case LDAP_BACK_CFG_IDASSERT_METHOD:
01908               /* no longer supported */
01909               snprintf( c->cr_msg, sizeof( c->cr_msg ),
01910                      "\"idassert-method <args>\": "
01911                      "no longer supported; use \"idassert-bind\"" );
01912               Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01913               return 1;
01914 
01915        case LDAP_BACK_CFG_IDASSERT_BIND:
01916               rc = slap_idassert_parse( c, &li->li_idassert );
01917               break;
01918 
01919        case LDAP_BACK_CFG_REBIND:
01920               if ( c->argc == 1 || c->value_int ) {
01921                      li->li_flags |= LDAP_BACK_F_SAVECRED;
01922 
01923               } else {
01924                      li->li_flags &= ~LDAP_BACK_F_SAVECRED;
01925               }
01926               break;
01927 
01928        case LDAP_BACK_CFG_CHASE:
01929               if ( c->argc == 1 || c->value_int ) {
01930                      li->li_flags |= LDAP_BACK_F_CHASE_REFERRALS;
01931 
01932               } else {
01933                      li->li_flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
01934               }
01935               break;
01936 
01937        case LDAP_BACK_CFG_T_F: {
01938               slap_mask_t          mask;
01939 
01940               i = verb_to_mask( c->argv[1], t_f_mode );
01941               if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
01942                      return 1;
01943               }
01944 
01945               mask = t_f_mode[i].mask;
01946 
01947               if ( LDAP_BACK_ISOPEN( li )
01948                      && mask == LDAP_BACK_F_T_F_DISCOVER
01949                      && !LDAP_BACK_T_F( li ) )
01950               {
01951                      slap_bindconf sb = { BER_BVNULL };
01952                      int           rc;
01953 
01954                      if ( li->li_uri == NULL ) {
01955                             snprintf( c->cr_msg, sizeof( c->cr_msg ),
01956                                    "need URI to discover absolute filters support "
01957                                    "in \"t-f-support discover\"" );
01958                             Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
01959                             return 1;
01960                      }
01961 
01962                      ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
01963                      sb.sb_version = li->li_version;
01964                      sb.sb_method = LDAP_AUTH_SIMPLE;
01965                      BER_BVSTR( &sb.sb_binddn, "" );
01966 
01967                      rc = slap_discover_feature( &sb,
01968                                    slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
01969                                    LDAP_FEATURE_ABSOLUTE_FILTERS );
01970                      if ( rc == LDAP_COMPARE_TRUE ) {
01971                             mask |= LDAP_BACK_F_T_F;
01972                      }
01973               }
01974 
01975               li->li_flags &= ~LDAP_BACK_F_T_F_MASK2;
01976               li->li_flags |= mask;
01977               } break;
01978 
01979        case LDAP_BACK_CFG_WHOAMI:
01980               if ( c->argc == 1 || c->value_int ) {
01981                      li->li_flags |= LDAP_BACK_F_PROXY_WHOAMI;
01982                      load_extop( (struct berval *)&slap_EXOP_WHOAMI,
01983                                    0, ldap_back_exop_whoami );
01984 
01985               } else {
01986                      li->li_flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
01987               }
01988               break;
01989 
01990        case LDAP_BACK_CFG_TIMEOUT:
01991               for ( i = 1; i < c->argc; i++ ) {
01992                      if ( isdigit( (unsigned char) c->argv[ i ][ 0 ] ) ) {
01993                             int           j;
01994                             unsigned      u;
01995 
01996                             if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) {
01997                                    snprintf( c->cr_msg, sizeof( c->cr_msg),
01998                                           "unable to parse timeout \"%s\"",
01999                                           c->argv[ i ] );
02000                                    Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02001                                    return 1;
02002                             }
02003 
02004                             for ( j = 0; j < SLAP_OP_LAST; j++ ) {
02005                                    li->li_timeout[ j ] = u;
02006                             }
02007 
02008                             continue;
02009                      }
02010 
02011                      if ( slap_cf_aux_table_parse( c->argv[ i ], li->li_timeout, timeout_table, "slapd-ldap timeout" ) ) {
02012                             snprintf( c->cr_msg, sizeof( c->cr_msg),
02013                                    "unable to parse timeout \"%s\"",
02014                                    c->argv[ i ] );
02015                             Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02016                             return 1;
02017                      }
02018               }
02019               break;
02020 
02021        case LDAP_BACK_CFG_IDLE_TIMEOUT: {
02022               unsigned long t;
02023 
02024               if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
02025                      snprintf( c->cr_msg, sizeof( c->cr_msg),
02026                             "unable to parse idle timeout \"%s\"",
02027                             c->argv[ 1 ] );
02028                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02029                      return 1;
02030               }
02031               li->li_idle_timeout = (time_t)t;
02032               } break;
02033 
02034        case LDAP_BACK_CFG_CONN_TTL: {
02035               unsigned long t;
02036 
02037               if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
02038                      snprintf( c->cr_msg, sizeof( c->cr_msg),
02039                             "unable to parse conn ttl\"%s\"",
02040                             c->argv[ 1 ] );
02041                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02042                      return 1;
02043               }
02044               li->li_conn_ttl = (time_t)t;
02045               } break;
02046 
02047        case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
02048               unsigned long t;
02049 
02050               if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
02051                      snprintf( c->cr_msg, sizeof( c->cr_msg),
02052                             "unable to parse network timeout \"%s\"",
02053                             c->argv[ 1 ] );
02054                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02055                      return 1;
02056               }
02057               li->li_network_timeout = (time_t)t;
02058               } break;
02059 
02060        case LDAP_BACK_CFG_VERSION:
02061               if ( c->value_int != 0 && ( c->value_int < LDAP_VERSION_MIN || c->value_int > LDAP_VERSION_MAX ) ) {
02062                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
02063                             "unsupported version \"%s\" "
02064                             "in \"protocol-version <version>\"",
02065                             c->argv[ 1 ] );
02066                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02067                      return 1;
02068               }
02069 
02070               li->li_version = c->value_int;
02071               break;
02072 
02073        case LDAP_BACK_CFG_SINGLECONN:
02074               if ( c->value_int ) {
02075                      li->li_flags |= LDAP_BACK_F_SINGLECONN;
02076 
02077               } else {
02078                      li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
02079               }
02080               break;
02081 
02082        case LDAP_BACK_CFG_USETEMP:
02083               if ( c->value_int ) {
02084                      li->li_flags |= LDAP_BACK_F_USE_TEMPORARIES;
02085 
02086               } else {
02087                      li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
02088               }
02089               break;
02090 
02091        case LDAP_BACK_CFG_CONNPOOLMAX:
02092               if ( c->value_int < LDAP_BACK_CONN_PRIV_MIN
02093                      || c->value_int > LDAP_BACK_CONN_PRIV_MAX )
02094               {
02095                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
02096                             "invalid max size " "of privileged "
02097                             "connections pool \"%s\" "
02098                             "in \"conn-pool-max <n> "
02099                             "(must be between %d and %d)\"",
02100                             c->argv[ 1 ],
02101                             LDAP_BACK_CONN_PRIV_MIN,
02102                             LDAP_BACK_CONN_PRIV_MAX );
02103                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02104                      return 1;
02105               }
02106               li->li_conn_priv_max = c->value_int;
02107               break;
02108 
02109        case LDAP_BACK_CFG_CANCEL: {
02110               slap_mask_t          mask;
02111 
02112               i = verb_to_mask( c->argv[1], cancel_mode );
02113               if ( BER_BVISNULL( &cancel_mode[i].word ) ) {
02114                      return 1;
02115               }
02116 
02117               mask = cancel_mode[i].mask;
02118 
02119               if ( LDAP_BACK_ISOPEN( li )
02120                      && mask == LDAP_BACK_F_CANCEL_EXOP_DISCOVER
02121                      && !LDAP_BACK_CANCEL( li ) )
02122               {
02123                      slap_bindconf sb = { BER_BVNULL };
02124                      int           rc;
02125 
02126                      if ( li->li_uri == NULL ) {
02127                             snprintf( c->cr_msg, sizeof( c->cr_msg ),
02128                                    "need URI to discover \"cancel\" support "
02129                                    "in \"cancel exop-discover\"" );
02130                             Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02131                             return 1;
02132                      }
02133 
02134                      ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
02135                      sb.sb_version = li->li_version;
02136                      sb.sb_method = LDAP_AUTH_SIMPLE;
02137                      BER_BVSTR( &sb.sb_binddn, "" );
02138 
02139                      rc = slap_discover_feature( &sb,
02140                                    slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
02141                                    LDAP_EXOP_CANCEL );
02142                      if ( rc == LDAP_COMPARE_TRUE ) {
02143                             mask |= LDAP_BACK_F_CANCEL_EXOP;
02144                      }
02145               }
02146 
02147               li->li_flags &= ~LDAP_BACK_F_CANCEL_MASK2;
02148               li->li_flags |= mask;
02149               } break;
02150 
02151        case LDAP_BACK_CFG_QUARANTINE:
02152               if ( LDAP_BACK_QUARANTINE( li ) ) {
02153                      snprintf( c->cr_msg, sizeof( c->cr_msg ),
02154                             "quarantine already defined" );
02155                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02156                      return 1;
02157               }
02158               rc = slap_retry_info_parse( c->argv[1], &li->li_quarantine,
02159                      c->cr_msg, sizeof( c->cr_msg ) );
02160               if ( rc ) {
02161                      Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02162 
02163               } else {
02164                      ldap_pvt_thread_mutex_init( &li->li_quarantine_mutex );
02165                      /* give it a chance to retry if the pattern gets reset
02166                       * via back-config */
02167                      li->li_isquarantined = 0;
02168                      li->li_flags |= LDAP_BACK_F_QUARANTINE;
02169               }
02170               break;
02171 
02172 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
02173        case LDAP_BACK_CFG_ST_REQUEST:
02174               if ( c->value_int ) {
02175                      li->li_flags |= LDAP_BACK_F_ST_REQUEST;
02176 
02177               } else {
02178                      li->li_flags &= ~LDAP_BACK_F_ST_REQUEST;
02179               }
02180               break;
02181 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
02182 
02183        case LDAP_BACK_CFG_NOREFS:
02184               if ( c->value_int ) {
02185                      li->li_flags |= LDAP_BACK_F_NOREFS;
02186 
02187               } else {
02188                      li->li_flags &= ~LDAP_BACK_F_NOREFS;
02189               }
02190               break;
02191 
02192        case LDAP_BACK_CFG_NOUNDEFFILTER:
02193               if ( c->value_int ) {
02194                      li->li_flags |= LDAP_BACK_F_NOUNDEFFILTER;
02195 
02196               } else {
02197                      li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER;
02198               }
02199               break;
02200 
02201        case LDAP_BACK_CFG_REWRITE:
02202               snprintf( c->cr_msg, sizeof( c->cr_msg ),
02203                      "rewrite/remap capabilities have been moved "
02204                      "to the \"rwm\" overlay; see slapo-rwm(5) "
02205                      "for details (hint: add \"overlay rwm\" "
02206                      "and prefix all directives with \"rwm-\")" );
02207               Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
02208               return 1;
02209               
02210        default:
02211               /* FIXME: try to catch inconsistencies */
02212               assert( 0 );
02213               break;
02214        }
02215 
02216        return rc;
02217 }
02218 
02219 int
02220 ldap_back_init_cf( BackendInfo *bi )
02221 {
02222        int                  rc;
02223        AttributeDescription *ad = NULL;
02224        const char           *text;
02225 
02226        /* Make sure we don't exceed the bits reserved for userland */
02227        config_check_userland( LDAP_BACK_CFG_LAST );
02228 
02229        bi->bi_cf_ocs = ldapocs;
02230 
02231        rc = config_register_schema( ldapcfg, ldapocs );
02232        if ( rc ) {
02233               return rc;
02234        }
02235 
02236        /* setup olcDbAclPasswd and olcDbIDAssertPasswd 
02237         * to be base64-encoded when written in LDIF form;
02238         * basically, we don't care if it fails */
02239        rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
02240        if ( rc ) {
02241               Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
02242                      "warning, unable to get \"olcDbACLPasswd\" "
02243                      "attribute description: %d: %s\n",
02244                      rc, text, 0 );
02245        } else {
02246               (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
02247                      ad->ad_type->sat_oid );
02248        }
02249 
02250        ad = NULL;
02251        rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
02252        if ( rc ) {
02253               Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
02254                      "warning, unable to get \"olcDbIDAssertPasswd\" "
02255                      "attribute description: %d: %s\n",
02256                      rc, text, 0 );
02257        } else {
02258               (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
02259                      ad->ad_type->sat_oid );
02260        }
02261 
02262        return 0;
02263 }
02264 
02265 static int
02266 ldap_pbind_cf_gen( ConfigArgs *c )
02267 {
02268        slap_overinst *on = (slap_overinst *)c->bi;
02269        void   *private = c->be->be_private;
02270        int           rc;
02271 
02272        c->be->be_private = on->on_bi.bi_private;
02273        rc = ldap_back_cf_gen( c );
02274        c->be->be_private = private;
02275        return rc;
02276 }
02277 
02278 int
02279 ldap_pbind_init_cf( BackendInfo *bi )
02280 {
02281        bi->bi_cf_ocs = pbindocs;
02282 
02283        return config_register_schema( pbindcfg, pbindocs );
02284 }
02285 
02286 static int
02287 ldap_back_exop_whoami(
02288               Operation     *op,
02289               SlapReply     *rs )
02290 {
02291        struct berval *bv = NULL;
02292 
02293        if ( op->oq_extended.rs_reqdata != NULL ) {
02294               /* no request data should be provided */
02295               rs->sr_text = "no request data expected";
02296               return rs->sr_err = LDAP_PROTOCOL_ERROR;
02297        }
02298 
02299        Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
02300            op->o_log_prefix, 0, 0, 0, 0 );
02301 
02302        rs->sr_err = backend_check_restrictions( op, rs, 
02303                      (struct berval *)&slap_EXOP_WHOAMI );
02304        if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
02305 
02306        /* if auth'd by back-ldap and request is proxied, forward it */
02307        if ( op->o_conn->c_authz_backend
02308               && !strcmp( op->o_conn->c_authz_backend->be_type, "ldap" )
02309               && !dn_match( &op->o_ndn, &op->o_conn->c_ndn ) )
02310        {
02311               ldapconn_t    *lc = NULL;
02312               LDAPControl c, *ctrls[2] = {NULL, NULL};
02313               LDAPMessage *res;
02314               Operation op2 = *op;
02315               ber_int_t msgid;
02316               int doretry = 1;
02317               char *ptr;
02318 
02319               ctrls[0] = &c;
02320               op2.o_ndn = op->o_conn->c_ndn;
02321               if ( !ldap_back_dobind( &lc, &op2, rs, LDAP_BACK_SENDERR ) ) {
02322                      return -1;
02323               }
02324               c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
02325               c.ldctl_iscritical = 1;
02326               c.ldctl_value.bv_val = op->o_tmpalloc(
02327                      op->o_ndn.bv_len + STRLENOF( "dn:" ) + 1,
02328                      op->o_tmpmemctx );
02329               c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
02330               ptr = c.ldctl_value.bv_val;
02331               ptr = lutil_strcopy( ptr, "dn:" );
02332               ptr = lutil_strncopy( ptr, op->o_ndn.bv_val, op->o_ndn.bv_len );
02333               ptr[ 0 ] = '\0';
02334 
02335 retry:
02336               rs->sr_err = ldap_whoami( lc->lc_ld, ctrls, NULL, &msgid );
02337               if ( rs->sr_err == LDAP_SUCCESS ) {
02338                      /* by now, make sure no timeout is used (ITS#6282) */
02339                      struct timeval tv = { -1, 0 };
02340                      if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) == -1 ) {
02341                             ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
02342                                    &rs->sr_err );
02343                             if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
02344                                    doretry = 0;
02345                                    if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
02346                                           goto retry;
02347                                    }
02348                             }
02349 
02350                      } else {
02351                             /* NOTE: are we sure "bv" will be malloc'ed
02352                              * with the appropriate memory? */
02353                             rs->sr_err = ldap_parse_whoami( lc->lc_ld, res, &bv );
02354                             ldap_msgfree(res);
02355                      }
02356               }
02357               op->o_tmpfree( c.ldctl_value.bv_val, op->o_tmpmemctx );
02358               if ( rs->sr_err != LDAP_SUCCESS ) {
02359                      rs->sr_err = slap_map_api2result( rs );
02360               }
02361 
02362               if ( lc != NULL ) {
02363                      ldap_back_release_conn( (ldapinfo_t *)op2.o_bd->be_private, lc );
02364               }
02365 
02366        } else {
02367               /* else just do the same as before */
02368               bv = (struct berval *) ch_malloc( sizeof( struct berval ) );
02369               if ( !BER_BVISEMPTY( &op->o_dn ) ) {
02370                      bv->bv_len = op->o_dn.bv_len + STRLENOF( "dn:" );
02371                      bv->bv_val = ch_malloc( bv->bv_len + 1 );
02372                      AC_MEMCPY( bv->bv_val, "dn:", STRLENOF( "dn:" ) );
02373                      AC_MEMCPY( &bv->bv_val[ STRLENOF( "dn:" ) ], op->o_dn.bv_val,
02374                             op->o_dn.bv_len );
02375                      bv->bv_val[ bv->bv_len ] = '\0';
02376 
02377               } else {
02378                      bv->bv_len = 0;
02379                      bv->bv_val = NULL;
02380               }
02381        }
02382 
02383        rs->sr_rspdata = bv;
02384        return rs->sr_err;
02385 }
02386 
02387