/* This file is part of the KDE project Copyright (C) 2000,2001 Alexander Neundorf This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tdeio_lan.h" #ifndef AF_LOCAL #define AF_LOCAL AF_UNIX #endif #define PORTSETTINGS_CHECK 0 #define PORTSETTINGS_PROVIDE 1 #define PORTSETTINGS_DISABLE 2 using namespace TDEIO; #ifndef SHUT_RDWR #define SHUT_RDWR 2 #endif extern "C" { KDE_EXPORT int kdemain(int argc, char **argv); } int kdemain( int argc, char **argv ) { TDEInstance instance( "tdeio_lan" ); if (argc != 4) { fprintf(stderr, "Usage: tdeio_lan protocol domain-socket1 domain-socket2\n"); exit(-1); } int isLanIoslave=(strcmp("lan",argv[1])==0); // Trigger creation to make sure we pick up KIOSK settings correctly. (void)TDEGlobal::dirs(); (void)TDEGlobal::locale(); (void)TDEGlobal::config(); kdDebug(7101) << "LAN: kdemain: starting" << endl; LANProtocol slave(isLanIoslave, argv[2], argv[3]); slave.dispatchLoop(); return 0; } LANProtocol::LANProtocol(int isLanIoslave, const TQCString &pool, const TQCString &app ) :TCPSlaveBase(7741,isLanIoslave?"lan":"rlan", pool, app) ,m_currentHost("") ,m_port(7741) ,m_maxAge(15*60) ,m_isLanIoslave(isLanIoslave?true:false) { TDEConfig *config=TDEGlobal::config(); m_protocolInfo[KIOLAN_FTP].enabled=config->readNumEntry("Support_FTP",PORTSETTINGS_CHECK); m_protocolInfo[KIOLAN_HTTP].enabled=config->readNumEntry("Support_HTTP",PORTSETTINGS_CHECK); m_protocolInfo[KIOLAN_NFS].enabled=config->readNumEntry("Support_NFS",PORTSETTINGS_CHECK); m_protocolInfo[KIOLAN_SMB].enabled=config->readNumEntry("Support_SMB",PORTSETTINGS_CHECK); m_protocolInfo[KIOLAN_FISH].enabled=config->readNumEntry("Support_FISH",PORTSETTINGS_CHECK); m_defaultLisaHost=config->readEntry("DefaultLisaHost", "localhost"); m_shortHostnames=config->readBoolEntry("ShowShortHostnames",false); m_maxAge=config->readNumEntry("MaxAge",15)*60; if (m_maxAge<0) m_maxAge=0; strcpy(m_protocolInfo[KIOLAN_NFS].name,"NFS"); strcpy(m_protocolInfo[KIOLAN_FTP].name,"FTP"); strcpy(m_protocolInfo[KIOLAN_SMB].name,"SMB"); strcpy(m_protocolInfo[KIOLAN_HTTP].name,"HTTP"); strcpy(m_protocolInfo[KIOLAN_FISH].name,"FISH"); // Now we check for port 445 for SMB/CIFS also. But we call both entries // SMB. Clients will see only one SMB folder, though, whichever // port (or both) is detected. The smb ioslave should be able // to figure out which port to actually use. m_protocolInfo[KIOLAN_NFS].ports.push_back(2049); m_protocolInfo[KIOLAN_FTP].ports.push_back(21); m_protocolInfo[KIOLAN_SMB].ports.push_back(445); m_protocolInfo[KIOLAN_SMB].ports.push_back(139); m_protocolInfo[KIOLAN_HTTP].ports.push_back(80); m_protocolInfo[KIOLAN_FISH].ports.push_back(22); m_hostInfoCache.setAutoDelete(true); } LANProtocol::~LANProtocol() { m_hostInfoCache.clear(); } int LANProtocol::readDataFromServer() { if (m_isLanIoslave) return lanReadDataFromServer(); else return rlanReadDataFromServer(); return 0; } int LANProtocol::lanReadDataFromServer() { kdDebug(7101)<<"LANProtocol::lanReadDataFromServer() host: "<The Lisa daemon does not appear to be running.

" "In order to use the LAN Browser the Lisa daemon must be " "installed and activated by the system administrator.")); return 0; } kdDebug(7101)<<"LANProtocol::lanReadDataFromServer() connected"<0) { char *newBuf=new char[receivedBytes+bytesRead]; if (receiveBuffer!=0) memcpy(newBuf,receiveBuffer,receivedBytes); memcpy(newBuf+receivedBytes,tmpBuf,bytesRead); receivedBytes+=bytesRead; if (receiveBuffer!=0) delete [] receiveBuffer; receiveBuffer=newBuf; } } } while (bytesRead>0); closeDescriptor(); if ((bytesRead<0) || (receivedBytes<4)) { delete [] receiveBuffer; error(ERR_INTERNAL_SERVER,i18n("Received unexpected data from %1").arg(m_currentHost)); return 0; } UDSEntry entry; char *currentBuf=receiveBuffer; int bytesLeft=receivedBytes; //this should be large enough for a name char tmpName[4*1024]; //this should be large enough for the hostname char tmpHostname[4*1024]; while (bytesLeft>0) { int tmpIP=2; tmpName[0]='\0'; if ((memchr(currentBuf,0,bytesLeft)==0) || (memchr(currentBuf,int('\n'),bytesLeft)==0)) { delete [] receiveBuffer; error(ERR_INTERNAL_SERVER,i18n("Received unexpected data from %1").arg(m_currentHost)); return 0; } kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: processing "<pw_name; else //should never happen socketname+="???"; strlcpy(addr.sun_path,socketname,sizeof(addr.sun_path)); int result=::connect(sockFD,(sockaddr*)&addr, sizeof(addr)); kdDebug(7101)<<"readDataFromServer(): result: "<0) { char *newBuf=new char[receivedBytes+bytesRead]; if (receiveBuffer!=0) memcpy(newBuf,receiveBuffer,receivedBytes); memcpy(newBuf+receivedBytes,tmpBuf,bytesRead); receivedBytes+=bytesRead; if (receiveBuffer!=0) delete [] receiveBuffer; receiveBuffer=newBuf; } } } while (bytesRead>0); ::close(sockFD); if ((bytesRead<0) || (receivedBytes<4)) { delete [] receiveBuffer; error(ERR_CANNOT_OPEN_FOR_READING,socketname); return 0; } UDSEntry entry; char *currentBuf=receiveBuffer; int bytesLeft=receivedBytes; //this should be large enough for a name char tmpName[4*1024]; //this should be large enough for the hostname char tmpHostname[4*1024]; while (bytesLeft>0) { int tmpIP=2; tmpName[0]='\0'; if ((memchr(currentBuf,0,bytesLeft)==0) || (memchr(currentBuf,int('\n'),bytesLeft)==0)) { delete [] receiveBuffer; error(ERR_INTERNAL_SERVER,i18n("Received unexpected data from %1").arg(socketname.data())); return 0; } kdDebug(7101)<<"RLANProtocol::readDataFromServer: processing "<created)>m_maxAge) { kdDebug(7101)<<"LAN::checkHost() cache content too old, deleting it"<h_addr, sizeof(ip)); for (int i=0; iservices[i]=result; } hostInfo->created=time(0); m_hostInfoCache.insert(hostUpper,hostInfo); } //here hostInfo is always != 0 if (hostInfo==0) { error( ERR_INTERNAL, "hostInfo==0" ); return 0; } UDSEntry entry; for (int i=0; iservices[i]==1) { kdDebug(7101)<<"LAN::checkHost(): Host ["<& _ports, in_addr ip ) { int _port=0; struct sockaddr_in to_scan; to_scan.sin_family = AF_INET; to_scan.sin_addr = ip; for (TQValueVector::iterator i= _ports.begin(); i != _ports.end(); i++) { _port=(*i); kdDebug(7101)<<"LANProtocol::checkPort: "<<_port<2) { kdDebug(7101)<<"LANProtocol::listDir: too deep path: "<