KSocks::~KSocks() { stopSocks(); _me = 0; }
KSocks::~KSocks() { stopSocks(); _me = 0; delete d; }
KSocks::KSocks(KConfigBase *config) : _socksLib(0L), _st(0L) { _hasSocks = false; _useSocks = false; if (!config) return; if (!(config->readBoolEntry("SOCKS_enable", false))) { _disabled = true; } if (_disabled) return; _libPaths << "" << "/usr/lib" KDELIBSUFF "/" << "/usr/lib/" << "/usr/local/lib" KDELIBSUFF "/" << "/usr/local/lib/" << "/usr/local/socks5/lib" KDELIBSUFF "/" << "/usr/local/socks5/lib/" << "/opt/socks5/lib" KDELIBSUFF "/" << "/opt/socks5/lib/"; _libNames << "libsocks.so" // Dante << "libdsocksd.so.0" // Dante 1.1.14-2 on // Debian unstable 17-12-2003 << "libsocks5.so" // ? << "libsocks5_sh.so"; // NEC // Add the custom library paths here QStringList newlibs = config->readListEntry("SOCKS_lib_path"); for (QStringList::Iterator it = newlibs.begin(); it != newlibs.end(); ++it) { QString thisone = *it; if (thisone[thisone.length()-1] != '/') thisone += "/"; _libPaths << thisone; kdDebug(171) << "KSocks added a new library path: " << thisone << endl; } // Load the proper libsocks and KSocksTable KLibLoader *ll = KLibLoader::self(); int _meth = config->readNumEntry("SOCKS_method", 1); /**** Current methods * 1) Autodetect (read: any) 2) NEC * 3) Dante 4) Custom */ if (_meth == 4) { // try to load^H^H^H^Hguess at a custom library _socksLib = ll->library(config->readPathEntry("SOCKS_lib").latin1()); if (_socksLib && _socksLib->symbol("Rconnect")) { // Dante compatible? _st = new KDanteSocksTable; _useSocks = true; _hasSocks = true; } else if (_socksLib && _socksLib->symbol("connect")) { // NEC compatible? _st = new KNECSocksTable; _useSocks = true; _hasSocks = true; } else if (_socksLib) { _socksLib->unload(); _socksLib = 0L; } } else // leave this here "else for {}" for (QStringList::Iterator pit = _libPaths.begin(); !_hasSocks && pit != _libPaths.end(); ++pit) for (QStringList::Iterator it = _libNames.begin(); it != _libNames.end(); ++it) { _socksLib = ll->library((*pit + *it).latin1()); if (_socksLib) { if ((_meth == 1 || _meth == 2) && _socksLib->symbol("S5LogShowThreadIDS") != 0L) { // NEC SOCKS kdDebug(171) << "Found NEC SOCKS" << endl; _st = new KNECSocksTable; _useSocks = true; _hasSocks = true; break; } else if ((_meth == 1 || _meth == 3) && _socksLib->symbol("sockaddr2ruleaddress") != 0L) { //Dante kdDebug(171) << "Found Dante SOCKS" << endl; _st = new KDanteSocksTable; _useSocks = true; _hasSocks = true; break; } else { _socksLib->unload(); _socksLib = 0L; } } } // Load in all the symbols if (_st) { for (QMap<SymbolKeys,QString>::Iterator it = _st->symbols.begin(); it != _st->symbols.end(); ++it) { switch(it.key()) { case S_SOCKSinit: F_SOCKSinit = (int (*)(char *)) _socksLib->symbol(it.data().latin1()); break; case S_connect: F_connect = (int (*)(int, const struct sockaddr *, ksocklen_t)) _socksLib->symbol(it.data().latin1()); break; case S_read: F_read = (signed long int (*)(int, void *, unsigned long int)) _socksLib->symbol(it.data().latin1()); break; case S_write: F_write = (signed long int (*)(int, const void *, unsigned long int)) _socksLib->symbol(it.data().latin1()); break; case S_recvfrom: F_recvfrom = (int (*)(int, void *, unsigned long int, int, struct sockaddr *, ksocklen_t *)) _socksLib->symbol(it.data().latin1()); break; case S_sendto: F_sendto = (int (*)(int, const void *, unsigned long int, int, const struct sockaddr *, ksocklen_t)) _socksLib->symbol(it.data().latin1()); break; case S_recv: F_recv = (int (*)(int, void *, unsigned long int, int)) _socksLib->symbol(it.data().latin1()); break; case S_send: F_send = (int (*)(int, const void *, unsigned long int, int)) _socksLib->symbol(it.data().latin1()); break; case S_getsockname: F_getsockname = (int (*)(int, struct sockaddr *, ksocklen_t *)) _socksLib->symbol(it.data().latin1()); break; case S_getpeername: F_getpeername = (int (*)(int, struct sockaddr *, ksocklen_t *)) _socksLib->symbol(it.data().latin1()); break; case S_accept: F_accept = (int (*)(int, struct sockaddr *, ksocklen_t *)) _socksLib->symbol(it.data().latin1()); break; case S_select: F_select = (int (*)(int, fd_set *, fd_set *, fd_set *, struct timeval *)) _socksLib->symbol(it.data().latin1()); break; case S_listen: F_listen = (int (*)(int, int)) _socksLib->symbol(it.data().latin1()); break; case S_bind: F_bind = (int (*)(int, const struct sockaddr *, ksocklen_t)) _socksLib->symbol(it.data().latin1()); break; default: kdDebug(171) << "KSocks got a symbol it doesn't know about!" << endl; break; } } // Now we check for the critical stuff. if (F_SOCKSinit) { int rc = (*F_SOCKSinit)((char *)"KDE"); if (rc != 0) stopSocks(); else kdDebug(171) << "SOCKS has been activated!" << endl; } else { stopSocks(); } } }
KSocks::KSocks(const KConfigGroup *config) : d(new KSocksPrivate()) { if (!config) return; if (!config->readEntry("SOCKS_enable", false)) { _disabled = true; } if (_disabled) return; d->_libPaths << "" << "/usr/lib" KDELIBSUFF "/" << "/usr/lib/" << "/usr/local/lib" KDELIBSUFF "/" << "/usr/local/lib/" << "/usr/local/socks5/lib" KDELIBSUFF "/" << "/usr/local/socks5/lib/" << "/opt/socks5/lib" KDELIBSUFF "/" << "/opt/socks5/lib/"; d->_libNames << "libsocks.so" // Dante << "libdsocksd.so.0" // Dante 1.1.14-2 on // Debian unstable 17-12-2003 << "libsocks5.so" // ? << "libsocks5_sh.so"; // NEC // Add the custom library paths here QStringList newlibs = config->readEntry("SOCKS_lib_path", QStringList()); for (QStringList::Iterator it = newlibs.begin(); it != newlibs.end(); ++it) { QString thisone = *it; if (thisone[thisone.length()-1] != QLatin1Char('/')) thisone += QLatin1Char('/'); d->_libPaths << QFile::encodeName(thisone); kDebug(d->debugArea()) << "KSocks added a new library path: " << thisone; } // Load the proper libsocks and KSocksTable KLibLoader *ll = KLibLoader::self(); int _meth = config->readEntry("SOCKS_method", 1); /**** Current methods * 1) Autodetect (read: any) 2) NEC * 3) Dante 4) Custom */ if (_meth == 4) { // try to load^H^H^H^Hguess at a custom library d->_socksLib = ll->library(config->readPathEntry("SOCKS_lib", QString())); if (d->_socksLib && d->_socksLib->resolveFunction("Rconnect")) { // Dante compatible? d->_st = new KDanteSocksTable; d->_useSocks = true; d->_hasSocks = true; } else if (d->_socksLib && d->_socksLib->resolveFunction("connect")) { // NEC compatible? d->_st = new KNECSocksTable; d->_useSocks = true; d->_hasSocks = true; } else if (d->_socksLib) { d->_socksLib->unload(); d->_socksLib = 0L; } } else // leave this here "else for {}" for (QList<QByteArray>::const_iterator pit = d->_libPaths.constBegin(); !d->_hasSocks && pit != d->_libPaths.constEnd(); ++pit) for (QList<QByteArray>::const_iterator it = d->_libNames.constBegin(); it != d->_libNames.constEnd(); ++it) { d->_socksLib = ll->library(QLatin1String(*pit) + QLatin1String(*it)); if (d->_socksLib) { if ((_meth == 1 || _meth == 2) && d-> _socksLib->resolveFunction("S5LogShowThreadIDS") != 0L) { // NEC SOCKS kDebug(d->debugArea()) << "Found NEC SOCKS"; d->_st = new KNECSocksTable; d->_useSocks = true; d->_hasSocks = true; break; } else if ((_meth == 1 || _meth == 3) && d->_socksLib->resolveFunction("sockaddr2ruleaddress") != 0L) { //Dante kDebug(d->debugArea()) << "Found Dante SOCKS"; d->_st = new KDanteSocksTable; d->_useSocks = true; d->_hasSocks = true; break; } else { d->_socksLib->unload(); d->_socksLib = 0L; } } } // Load in all the symbols if (d->_st) { for (QMap<SymbolKeys,QByteArray>::Iterator it = d->_st->symbols.begin(); it != d->_st->symbols.end(); ++it) { switch(it.key()) { case S_SOCKSinit: F_SOCKSinit = (int (*)(char *)) d->_socksLib->resolveFunction(it.value()); break; case S_connect: F_connect = (int (*)(int, const struct sockaddr *, kde_socklen_t)) d->_socksLib->resolveFunction(it.value()); break; case S_read: F_read = (signed long int (*)(int, void *, unsigned long int)) d->_socksLib->resolveFunction(it.value()); break; case S_write: F_write = (signed long int (*)(int, const void *, unsigned long int)) d->_socksLib->resolveFunction(it.value()); break; case S_recvfrom: F_recvfrom = (int (*)(int, void *, unsigned long int, int, struct sockaddr *, kde_socklen_t *)) d->_socksLib->resolveFunction(it.value()); break; case S_sendto: F_sendto = (int (*)(int, const void *, unsigned long int, int, const struct sockaddr *, kde_socklen_t)) d->_socksLib->resolveFunction(it.value()); break; case S_recv: F_recv = (int (*)(int, void *, unsigned long int, int)) d->_socksLib->resolveFunction(it.value()); break; case S_send: F_send = (int (*)(int, const void *, unsigned long int, int)) d->_socksLib->resolveFunction(it.value()); break; case S_getsockname: F_getsockname = (int (*)(int, struct sockaddr *, kde_socklen_t *)) d->_socksLib->resolveFunction(it.value()); break; case S_getpeername: F_getpeername = (int (*)(int, struct sockaddr *, kde_socklen_t *)) d->_socksLib->resolveFunction(it.value()); break; case S_accept: F_accept = (int (*)(int, struct sockaddr *, kde_socklen_t *)) d->_socksLib->resolveFunction(it.value()); break; case S_select: F_select = (int (*)(int, fd_set *, fd_set *, fd_set *, struct timeval *)) d->_socksLib->resolveFunction(it.value()); break; case S_listen: F_listen = (int (*)(int, int)) d->_socksLib->resolveFunction(it.value()); break; case S_bind: F_bind = (int (*)(int, const struct sockaddr *, kde_socklen_t)) d->_socksLib->resolveFunction(it.value()); break; default: kDebug(d->debugArea()) << "KSocks got a symbol it doesn't know about!"; break; } } // Now we check for the critical stuff. if (F_SOCKSinit) { int rc = (*F_SOCKSinit)((char *)"KDE"); if (rc != 0) stopSocks(); else kDebug(d->debugArea()) << "SOCKS has been activated!"; } else { stopSocks(); } } }