1 /************************************************************************** 2 * Copyright (C) 2005-2020 by Oleksandr Shneyder * 3 * <o.shneyder@phoca-gmbh.de> * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. * 16 ***************************************************************************/ 17 18 #ifndef LDAPSESSION_H 19 #define LDAPSESSION_H 20 #define LDAP_DEPRECATED 1 21 #include "x2goclientconfig.h" 22 23 #ifdef USELDAP 24 #include <ldap.h> 25 #include <string> 26 #include <list> 27 using namespace std; 28 29 struct LDAPExeption 30 { LDAPExeptionLDAPExeption31 LDAPExeption ( string type,string str ) {err_type=type;err_str=str;} 32 string err_type; 33 string err_str; 34 }; 35 36 class ByteArray 37 { 38 public: 39 ByteArray(); 40 ByteArray ( const ByteArray& ); 41 ~ByteArray(); getData()42 const char* getData() {return data;} asString()43 string asString() {return data;} length()44 int length() {return size;} 45 void load ( const char*,int ); 46 void fromStdStr ( const string& ); 47 void operator = ( const ByteArray& ); 48 private: 49 void _delete(); 50 char* data; 51 int size; 52 }; 53 54 55 struct LDAPBinValue 56 { 57 string attr; 58 list<ByteArray> value; 59 }; 60 61 struct LDAPStringValue 62 { 63 string attr; 64 list<string> value; 65 }; 66 67 typedef list<LDAPStringValue> LDAPStringEntry; 68 typedef list<LDAPBinValue> LDAPBinEntry; 69 #endif 70 71 class LDAPSession 72 { 73 #ifdef USELDAP 74 public: 75 LDAPSession ( string,int,string,string, bool simple=false, 76 bool start_tls=true ); 77 ~LDAPSession(); 78 void addStringValue ( string dn, 79 const list<LDAPStringValue>& values ); 80 void remove ( string ); 81 static list<string> getStringAttrValues ( 82 const LDAPStringEntry& entry, 83 string attr ); 84 static list<ByteArray> getBinAttrValues ( 85 const LDAPBinEntry& entry, 86 string attr ); 87 void modifyStringValue ( string dn, 88 const list<LDAPStringValue>& values ); 89 void stringSearch ( string dn,const list<string> &attributes, 90 string searchParam, 91 list<LDAPStringEntry> &result ); 92 void binSearch ( string dn,const list<string> &attributes, 93 string searchParam, 94 list<LDAPBinEntry> &result ); 95 96 private: 97 LDAP* ld; 98 #endif 99 }; 100 101 #endif 102