1 // $OpenLDAP$
2 /*
3  * Copyright 2000-2021 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 
7 
8 #include "debug.h"
9 #include "config.h"
10 #include "ac/time.h"
11 #include "LDAPConstraints.h"
12 #include "LDAPControlSet.h"
13 
14 using namespace std;
15 
LDAPConstraints()16 LDAPConstraints::LDAPConstraints(){
17     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPConstraints::LDAPConstraints()" << endl);
18     m_aliasDeref=LDAPConstraints::DEREF_NEVER;
19 	m_maxTime=LDAP_NO_LIMIT;
20 	m_maxSize=LDAP_NO_LIMIT;
21 	m_referralChase=false;
22     m_HopLimit=7;
23     m_serverControls=0;
24     m_clientControls=0;
25     m_refRebind=0;
26 }
27 
LDAPConstraints(const LDAPConstraints & c)28 LDAPConstraints::LDAPConstraints(const LDAPConstraints& c){
29     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPConstraints::LDAPConstraints(&)" << endl);
30     m_aliasDeref=c.m_aliasDeref;
31     m_maxTime=c.m_maxTime;
32     m_maxSize=c.m_maxSize;
33     m_referralChase=c.m_referralChase;
34     m_HopLimit=c.m_HopLimit;
35     m_deref=c.m_deref;
36     if(c.m_serverControls){
37         m_serverControls=new LDAPControlSet(*c.m_serverControls);
38     }else{
39         m_serverControls=0;
40     }
41     if(c.m_clientControls){
42         m_clientControls=new LDAPControlSet(*c.m_clientControls);
43     }else{
44         m_clientControls=0;
45     }
46     m_refRebind=c.m_refRebind;
47 }
48 
~LDAPConstraints()49 LDAPConstraints::~LDAPConstraints(){
50     DEBUG(LDAP_DEBUG_DESTROY,"LDAPConstraints::~LDAPConstraints()" << endl);
51     delete m_clientControls;
52     delete m_serverControls;
53 }
54 
setAliasDeref(int deref)55 void LDAPConstraints::setAliasDeref(int deref){
56     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setAliasDeref()" << endl);
57     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
58             "   deref:" << deref << endl);
59     if( (deref == LDAPConstraints::DEREF_NEVER) ||
60             (deref == LDAPConstraints::DEREF_SEARCHING) ||
61             (deref == LDAPConstraints::DEREF_FINDING) ||
62             (deref == LDAPConstraints::DEREF_ALWAYS)
63         ){
64         m_aliasDeref=deref;
65     }
66 }
67 
68 
setMaxTime(int t)69 void LDAPConstraints::setMaxTime(int t){
70     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setMaxTime()" << endl);
71     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,"   time:" << t << endl);
72     m_maxTime=t;
73 }
74 
setSizeLimit(int s)75 void LDAPConstraints::setSizeLimit(int s){
76     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setSizeLimit()" << endl);
77     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,"   size:" << s << endl);
78 	m_maxSize=s;
79 }
80 
setReferralChase(bool rc)81 void LDAPConstraints::setReferralChase(bool rc){
82     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setReferralChase()" << endl);
83     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,"   rc:" << rc << endl);
84     m_referralChase=rc;
85 }
86 
setHopLimit(int limit)87 void LDAPConstraints::setHopLimit(int limit){
88     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setHopLimit()" << endl);
89     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
90             "   limit:" << limit << endl);
91     m_HopLimit=limit;
92 }
93 
setReferralRebind(const LDAPRebind * rebind)94 void LDAPConstraints::setReferralRebind(const LDAPRebind* rebind){
95     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setReferralRebind()" << endl);
96     m_refRebind = rebind;
97 }
98 
setServerControls(const LDAPControlSet * ctrls)99 void LDAPConstraints::setServerControls(const LDAPControlSet* ctrls){
100     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setServerControls()" << endl);
101     m_serverControls=new LDAPControlSet(*ctrls);
102 }
103 
setClientControls(const LDAPControlSet * ctrls)104 void LDAPConstraints::setClientControls(const LDAPControlSet* ctrls){
105     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::setClientControls()" << endl);
106     m_clientControls=new LDAPControlSet(*ctrls);
107 }
108 
getAliasDeref() const109 int LDAPConstraints::getAliasDeref() const {
110     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getAliasDeref()" << endl);
111     return m_aliasDeref;
112 }
113 
getMaxTime() const114 int LDAPConstraints::getMaxTime() const {
115     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getMaxTime()" << endl);
116 	return m_maxTime;
117 }
118 
getSizeLimit() const119 int LDAPConstraints::getSizeLimit() const {
120     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getSizeLimit()" << endl);
121 	return m_maxSize;
122 }
123 
getReferralRebind() const124 const LDAPRebind* LDAPConstraints::getReferralRebind() const{
125     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getReferralRebind()" << endl);
126     return m_refRebind;
127 }
128 
getServerControls() const129 const LDAPControlSet* LDAPConstraints::getServerControls() const{
130     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getServerControls()" << endl);
131     return m_serverControls;
132 }
133 
getClientControls() const134 const LDAPControlSet* LDAPConstraints::getClientControls() const{
135     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getClientControls()" << endl);
136     return m_clientControls;
137 }
138 
getSrvCtrlsArray() const139 LDAPControl** LDAPConstraints::getSrvCtrlsArray() const {
140     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getSrvCtrlsArray()" << endl);
141     if(m_serverControls){
142         return m_serverControls->toLDAPControlArray();
143     }else{
144         return 0;
145     }
146 }
147 
getClCtrlsArray() const148 LDAPControl** LDAPConstraints::getClCtrlsArray() const {
149     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getClCtrlsArray()" << endl);
150     if(m_clientControls){
151         return m_clientControls->toLDAPControlArray();
152     }else{
153         return 0;
154     }
155 }
156 
getTimeoutStruct() const157 timeval* LDAPConstraints::getTimeoutStruct() const {
158     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getTimeoutStruct()" << endl);
159     if(m_maxTime == LDAP_NO_LIMIT){
160         return 0;
161     }else{
162         timeval *ret = new timeval;
163         ret->tv_sec=m_maxTime;
164         ret->tv_usec=0;
165         return ret;
166     }
167 }
168 
getReferralChase() const169 bool LDAPConstraints::getReferralChase() const {
170     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getReferralChase()" << endl);
171 	return m_referralChase;
172 }
173 
getHopLimit() const174 int LDAPConstraints::getHopLimit() const{
175     DEBUG(LDAP_DEBUG_TRACE,"LDAPConstraints::getHopLimit()" << endl);
176     return m_HopLimit;
177 }
178 
179