DocumentationGenerated on Thu Aug 31 00:02:37 2006 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Connection Class Reference#include <Connection.h>
Inheritance diagram for Connection: ![]()
Detailed Description
Definition at line 55 of file Connection.h. Constructor & Destructor Documentation
Definition at line 16 of file Connection.cpp. References _packet_size, _settings, _transfered, and READ_SIZE. 00017 { 00018 pthread_rwlock_init(&this->lock, NULL); 00019 this->_settings.reset(); 00020 this->_packet_size = READ_SIZE; 00021 this->_transfered = 0; 00022 }
Definition at line 24 of file Connection.cpp. References cleanup_list, cleanup_list_lock, and TLS_INITED. 00025 { 00026 if(this->_socket_id) 00027 close(this->_socket_id); 00028 00029 pthread_rwlock_destroy(&this->lock); 00030 00031 #ifdef USE_TLS 00032 // TLS cleanup here. 00033 if(this->settings(TLS_INITED)) 00034 { 00035 gnutls_db_remove_session(this->session); 00036 gnutls_deinit(this->session); 00037 } 00038 #endif 00039 if(this->thread_id()) 00040 { 00041 sem_wait(&cleanup_list_lock); 00042 cleanup_list.push_back(this->thread_id()); 00043 sem_post(&cleanup_list_lock); 00044 } 00045 }
Member Function Documentation
Definition at line 98 of file Connection.h. Referenced by Data::Data(), data_wrapper(), Data::open_active(), Data::open_passive(), and User::User().
Definition at line 138 of file Connection.cpp. References B_RESET, settings(), and TLS_ENABLED. 00139 { 00140 gnutls_bye(this->session, GNUTLS_SHUT_RDWR); 00141 this->settings(TLS_ENABLED, B_RESET); 00142 return true; 00143 }
Here is the call graph for this function: ![]()
Definition at line 104 of file Connection.cpp. References B_SET, packet_size(), session, settings(), tls_db_delete(), tls_db_fetch(), tls_db_store(), TLS_ENABLED, TLS_INITED, and x509_cred. Referenced by data_wrapper(), and Commands::list(). 00105 { 00106 bool ret = false; 00107 gnutls_init(&session, GNUTLS_SERVER); 00108 00109 gnutls_set_default_priority(this->session); 00110 00111 gnutls_credentials_set(this->session, GNUTLS_CRD_CERTIFICATE, x509_cred); 00112 00113 gnutls_certificate_server_set_request(this->session, GNUTLS_CERT_REQUEST); 00114 00115 gnutls_dh_set_prime_bits(this->session, 1024); 00116 00117 // these are for the connection cache 00118 gnutls_db_set_retrieve_function(this->session, tls_db_fetch); 00119 gnutls_db_set_remove_function(this->session, tls_db_delete); 00120 gnutls_db_set_store_function(this->session, tls_db_store); 00121 gnutls_db_set_ptr(this->session, NULL); 00122 00123 // associating the session with the socket. 00124 gnutls_transport_set_ptr(this->session, 00125 reinterpret_cast<gnutls_transport_ptr>(this->socket_id())); 00126 this->settings(TLS_INITED, B_SET); 00127 00128 if(gnutls_handshake(this->session) >= 0) 00129 { 00130 this->settings(TLS_ENABLED, B_SET); 00131 this->packet_size(gnutls_record_get_max_size(this->session)); 00132 ret = true; 00133 } 00134 00135 return ret; 00136 }
Here is the call graph for this function: ![]()
Definition at line 96 of file Connection.h. Referenced by data_wrapper(), User::User(), and verify_cert().
Definition at line 96 of file Connection.cpp. References B_SET, FAILURE, and settings(). 00097 { 00098 if(this->send(message.c_str(), message.size()) < 0) 00099 this->settings(FAILURE, B_SET); 00100 return *this; 00101 }
Here is the call graph for this function: ![]()
Definition at line 91 of file Connection.cpp. References Utilities::itos(), and util.
Here is the call graph for this function: ![]()
Definition at line 74 of file Connection.cpp. References _packet_size, TLS_ENABLED, and transfered(). Referenced by data_wrapper(). 00075 { 00076 assert(len <= this->_packet_size && len > 0); 00077 ssize_t ret = -1; 00078 00079 #ifdef USE_TLS 00080 if(this->settings(TLS_ENABLED)) 00081 ret = gnutls_record_recv(this->session, message, len); 00082 else 00083 #endif 00084 ret = read(this->socket_id(), message, len); 00085 00086 this->transfered(this->transfered() + ret); 00087 00088 return ret; 00089 }
Here is the call graph for this function: ![]()
Definition at line 47 of file Connection.cpp. References _packet_size, Utilities::itos(), Log::log_this(), logging, TLS_ENABLED, transfered(), TYPE_INFO, and util. Referenced by data_wrapper(). 00048 { 00049 assert(len <= this->_packet_size && len > 0); 00050 ssize_t ret = -1; 00051 00052 BABY_WRLOCK(this->lock); 00053 #ifdef USE_TLS 00054 if(this->settings(TLS_ENABLED)) 00055 { 00056 ret = gnutls_record_send(this->session, message, len); 00057 if(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) 00058 ret = gnutls_record_send(this->session, message, len); 00059 } 00060 else 00061 #endif // USE_TLS 00062 ret = write(this->_socket_id, message, len); 00063 00064 BABY_UNLOCK(this->lock); 00065 if(ret < 0) 00066 logging->log_this(3, TYPE_INFO, "write to socket " + 00067 util.itos(this->socket_id()) + " failed: %m"); 00068 else 00069 this->transfered(this->transfered() + ret); 00070 00071 return ret; 00072 }
Here is the call graph for this function: ![]()
Definition at line 80 of file Connection.h. References _settings, B_FLIP, B_RESET, and B_SET. 00081 { 00082 BABY_WRLOCK(this->lock); 00083 if(way == B_SET) 00084 this->_settings.set(bit); 00085 else if(way == B_RESET) 00086 this->_settings.reset(bit); 00087 else if(way == B_FLIP) 00088 this->_settings.flip(bit); 00089 BABY_UNLOCK(this->lock); 00090 }
Definition at line 72 of file Connection.h. References _settings, and TOTAL_U_BIT. 00073 { 00074 assert(bit < TOTAL_U_BIT); 00075 BABY_RDLOCK(this->lock); 00076 bool b = this->_settings.test(bit); 00077 BABY_UNLOCK(this->lock); 00078 return(b); 00079 }
Definition at line 68 of file Connection.h. References _settings. Referenced by Data::Data(), data_wrapper(), disengage_tls(), engage_tls(), Handler::init(), Handler::initializer(), Commands::list(), Data::open_active(), Data::open_passive(), operator<<(), User::operator>>(), Commands::retr(), and Commands::stor(). 00069 { 00070 return _settings; 00071 }
Definition at line 97 of file Connection.h. Referenced by Data::open_active(), Data::open_passive(), and User::User().
Definition at line 95 of file Connection.h. Referenced by Data::Data(), data_wrapper(), and User::User().
Definition at line 100 of file Connection.h. Referenced by Data::Data(), User::login(), Data::open_active(), Data::open_passive(), User::operator>>(), and User::User().
Definition at line 101 of file Connection.h. Referenced by data_wrapper(), verify_cert(), and Data::~Data().
Definition at line 145 of file Connection.cpp. References config, Configuration::general, host_name(), Utilities::is_set(), Log::log_this(), logging, TYPE_AUTH, TYPE_DEBUG, user_name(), util, and general_stru::verify_client. 00146 { 00147 bool ret = false; 00148 if (gnutls_certificate_type_get(this->session) == GNUTLS_CRT_X509) 00149 { 00150 int verified = gnutls_certificate_verify_peers(this->session); 00151 if(util.is_set(verified, GNUTLS_CERT_REVOKED)) 00152 logging->log_this(2, TYPE_AUTH, this->user_name() + 00153 + " tried to login with a revoked certificate."); 00154 else if(!util.is_set(verified, GNUTLS_CERT_INVALID) && 00155 !util.is_set(verified, GNUTLS_CERT_SIGNER_NOT_FOUND)) 00156 { 00157 unsigned int cert_list_size = 0; 00158 // I really hope gnutls has their locking code in shape. get_peers just 00159 // gives us some memory.. *shudder* 00160 const gnutls_datum *cert_list = gnutls_certificate_get_peers( 00161 this->session, &cert_list_size); 00162 if(cert_list_size > 0) 00163 { 00164 gnutls_x509_crt peer_cert; 00165 gnutls_x509_crt_init(&peer_cert); 00166 gnutls_x509_crt_import(peer_cert, &cert_list[0], GNUTLS_X509_FMT_DER); 00167 char dn_buf[200] = {0}, ca_buf[200] = {0}; 00168 size_t buf_size = 199, ca_size = 199; 00169 gnutls_x509_crt_get_dn(peer_cert, dn_buf, &buf_size); 00170 gnutls_x509_crt_get_issuer_dn(peer_cert, ca_buf, &ca_size); 00171 if(buf_size > 0 && ca_size > 0) 00172 { 00173 // here we call an external program to ask if this user may login 00174 // with this cert. 00175 // format is "<user> <host/ip> <ca-dn> <cert-dn>" 00176 string call = config->general.verify_client + " " + 00177 this->user_name() + " " + this->host_name() + 00178 " \"" + ca_buf + "\" \"" + dn_buf + "\""; 00179 logging->log_this(5, TYPE_DEBUG, "running:" + call); 00180 int approved = system(call.c_str()); 00181 if(WEXITSTATUS(approved) == 0) 00182 ret = true; 00183 } 00184 gnutls_x509_crt_deinit(peer_cert); 00185 } 00186 } 00187 } 00188 return ret; 00189 }
Here is the call graph for this function: ![]()
Member Data Documentation
Definition at line 98 of file Connection.h.
Definition at line 95 of file Connection.h.
Definition at line 94 of file Connection.h. Referenced by Connection(), Data::Data(), and settings().
Definition at line 96 of file Connection.h.
Definition at line 95 of file Connection.h.
Definition at line 100 of file Connection.h.
Definition at line 100 of file Connection.h.
Definition at line 58 of file Connection.h. Referenced by Commands::retr(), Commands::stor(), and Data::~Data().
The documentation for this class was generated from the following files: |
- Copyright © 2005, BabyFTPd
- Powered by: