File indexing completed on 2024-12-15 04:50:16
0001 /* 0002 This file is part of libkldap. 0003 SPDX-FileCopyrightText: 2004-2006 Szombathelyi György <gyurco@freemail.hu> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QString> 0011 0012 #include "kldap_core_export.h" 0013 #include "ldapdn.h" 0014 #include "ldapurl.h" 0015 0016 // clazy:excludeall=copyable-polymorphic 0017 0018 namespace KLDAPCore 0019 { 0020 /** 0021 * @short A class that contains LDAP server connection settings. 0022 * 0023 * This class holds various parameters that are needed to connect 0024 * to an LDAP server. 0025 */ 0026 class KLDAP_CORE_EXPORT LdapServer 0027 { 0028 public: 0029 /** 0030 * Creates an empty LDAP server object. 0031 */ 0032 LdapServer(); 0033 0034 /** 0035 * Creates a new LDAP server object. 0036 * 0037 * @param url The LDAP url of the server. 0038 */ 0039 explicit LdapServer(const LdapUrl &url); 0040 0041 /** 0042 * Creates a new LDAP server object from an @p other object. 0043 */ 0044 LdapServer(const LdapServer &other); 0045 0046 /** 0047 * Overwrites the values of the LDAP server object with 0048 * the values from an @p other object. 0049 */ 0050 LdapServer &operator=(const LdapServer &other); 0051 0052 /** 0053 * Destroys the LDAP server object. 0054 */ 0055 ~LdapServer(); 0056 0057 /** 0058 * Describes the encryption settings that can be used 0059 * for the LDAP connection. 0060 */ 0061 using Security = enum { 0062 None, ///< Do not use any encryption. 0063 TLS, ///< Use TLS encryption. 0064 SSL ///< Use SSL encryption. 0065 }; 0066 0067 /** 0068 * Describes the authentication method that can be used 0069 * for the LDAP connection. 0070 */ 0071 using Auth = enum { 0072 Anonymous, ///< Do no authentication. 0073 Simple, ///< Authenticate via login and password. 0074 SASL ///< Azthenticate with the SASL framework. 0075 }; 0076 0077 /** 0078 * Describes the certificate request and check behaviour 0079 * for TLS/SSL connections. 0080 */ 0081 using TLSRequireCertificate = enum { 0082 TLSReqCertDefault, ///< Use system defaults 0083 TLSReqCertNever, ///< Do not require any certificates. 0084 TLSReqCertDemand, ///< Use LDAP_OPT_X_TLS_DEMAND. 0085 TLSReqCertAllow, ///< Use LDAP_OPT_X_TLS_ALLOW. 0086 TLSReqCertTry, ///< Use LDAP_OPT_X_TLS_TRY. 0087 TLSReqCertHard, ///< Use LDAP_OPT_X_TLS_HARD. 0088 }; 0089 0090 /** 0091 * Clears all server settings. 0092 */ 0093 void clear(); 0094 0095 /** 0096 * Sets the host of the LDAP connection. 0097 */ 0098 void setHost(const QString &host); 0099 0100 /** 0101 * Returns the host of the LDAP connection. 0102 */ 0103 [[nodiscard]] QString host() const; 0104 0105 /** 0106 * Sets the port of the LDAP connection. 0107 * If not port is set, 389 is used as default. 0108 * @param port the LDAP port connection to set 0109 */ 0110 void setPort(int port); 0111 0112 /** 0113 * Returns the port of the LDAP connection. 0114 */ 0115 [[nodiscard]] int port() const; 0116 0117 /** 0118 * Sets the @p baseDn of the LDAP connection. 0119 */ 0120 void setBaseDn(const LdapDN &baseDn); 0121 0122 /** 0123 * Returns the baseDn of the LDAP connection. 0124 */ 0125 [[nodiscard]] LdapDN baseDn() const; 0126 0127 /** 0128 * Sets the @p user of the LDAP connection. 0129 */ 0130 void setUser(const QString &user); 0131 0132 /** 0133 * Returns the user of the LDAP connection. 0134 */ 0135 [[nodiscard]] QString user() const; 0136 0137 /** 0138 * Sets the @p bindDn of the LDAP connection. 0139 */ 0140 void setBindDn(const QString &bindDn); 0141 0142 /** 0143 * Returns the bindDn of the LDAP connection. 0144 */ 0145 [[nodiscard]] QString bindDn() const; 0146 0147 /** 0148 * Sets the @p realm of the LDAP connection. 0149 */ 0150 void setRealm(const QString &realm); 0151 0152 /** 0153 * Returns the realm of the LDAP connection. 0154 */ 0155 [[nodiscard]] QString realm() const; 0156 0157 /** 0158 * Sets the @p password of the LDAP connection. 0159 */ 0160 void setPassword(const QString &password); 0161 0162 /** 0163 * Returns the password of the LDAP connection. 0164 */ 0165 QString password() const; 0166 0167 /** 0168 * Sets the protocol @p version of the LDAP connection. 0169 * If no version is set, 3 is used as default. 0170 * @param version the protocol version to set 0171 */ 0172 void setVersion(int version); 0173 0174 /** 0175 * Returns the protocol version of the LDAP connection. 0176 */ 0177 [[nodiscard]] int version() const; 0178 0179 /** 0180 * Sets the security @p mode of the LDAP connection. 0181 * If no security is set, None is used as default. 0182 * @param mode the security mode to set 0183 */ 0184 void setSecurity(Security mode); 0185 0186 /** 0187 * Returns the security mode of the LDAP connection. 0188 */ 0189 [[nodiscard]] Security security() const; 0190 0191 /** 0192 * Sets the @p authentication method of the LDAP connection. 0193 * If no authentication method is set, Anonymous is used as default. 0194 * @param authentication the authentication method to set 0195 */ 0196 void setAuth(Auth authentication); 0197 0198 /** 0199 * Returns the authentication method of the LDAP connection. 0200 */ 0201 [[nodiscard]] Auth auth() const; 0202 0203 /** 0204 * Sets the certificate require mode for TLS/SSL connections 0205 */ 0206 void setTLSRequireCertificate(TLSRequireCertificate reqCert); 0207 0208 /** 0209 * Returns the certificate require mode for TLS/SSL connections 0210 */ 0211 [[nodiscard]] TLSRequireCertificate tlsRequireCertificate() const; 0212 0213 /** 0214 * Sets the CA certificate file for TLS/SSL connections 0215 */ 0216 void setTLSCACertFile(const QString &caCertFile); 0217 0218 /** 0219 * Returns the CA certificate file used for TLS/SSL connections. 0220 */ 0221 [[nodiscard]] QString tlsCACertFile() const; 0222 0223 /** 0224 * Sets the @p mech of the LDAP connection. 0225 */ 0226 void setMech(const QString &mech); 0227 0228 /** 0229 * Returns the mech of the LDAP connection. 0230 */ 0231 [[nodiscard]] QString mech() const; 0232 0233 /** 0234 * Sets the @p timeout of the LDAP connection. 0235 */ 0236 void setTimeout(int timeout); 0237 0238 /** 0239 * Returns the timeout of the LDAP connection. 0240 */ 0241 [[nodiscard]] int timeout() const; 0242 0243 /** 0244 * Sets the search @p scope of the LDAP connection. 0245 */ 0246 void setScope(LdapUrl::Scope scope); 0247 0248 /** 0249 * Returns the search scope of the LDAP connection. 0250 */ 0251 [[nodiscard]] LdapUrl::Scope scope() const; 0252 0253 /** 0254 * Sets the time @p limit of the LDAP connection. 0255 */ 0256 void setTimeLimit(int limit); 0257 0258 /** 0259 * Returns the time limit of the LDAP connection. 0260 */ 0261 [[nodiscard]] int timeLimit() const; 0262 0263 /** 0264 * Sets the size @p limit of the LDAP connection. 0265 */ 0266 void setSizeLimit(int sizelimit); 0267 0268 /** 0269 * Returns the size limit of the LDAP connection. 0270 */ 0271 [[nodiscard]] int sizeLimit() const; 0272 0273 /** 0274 * Sets the page @p size of the LDAP connection. 0275 */ 0276 void setPageSize(int size); 0277 0278 /** 0279 * Returns the page size of the LDAP connection. 0280 */ 0281 [[nodiscard]] int pageSize() const; 0282 0283 /** 0284 * Sets the @p filter string of the LDAP connection. 0285 */ 0286 void setFilter(const QString &filter); 0287 0288 /** 0289 * Returns the filter string of the LDAP connection. 0290 */ 0291 [[nodiscard]] QString filter() const; 0292 0293 /** 0294 * Sets the server parameters from an RFC2255 compliant LDAP @p url. 0295 */ 0296 void setUrl(const LdapUrl &url); 0297 0298 /** 0299 * Returns the server parameters as an RFC2255 compliant LDAP Url. 0300 * The URL extensions which are supported: 0301 * Standard: bindname 0302 * KLDAP extensions: x-tls, x-version, x-sasl, x-mech, x-realm, 0303 * x-sizelimit, x-timelimit, x-pagesize, x-timeout 0304 */ 0305 [[nodiscard]] LdapUrl url() const; 0306 0307 void setCompletionWeight(int value); 0308 [[nodiscard]] int completionWeight() const; 0309 0310 private: 0311 class LdapServerPrivate; 0312 std::unique_ptr<LdapServerPrivate> const d; 0313 }; 0314 } 0315 KLDAP_CORE_EXPORT QDebug operator<<(QDebug d, const KLDAPCore::LdapServer &t);