summaryrefslogtreecommitdiff
path: root/noncore/settings
Unidiff
Diffstat (limited to 'noncore/settings') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindow/mainwindowimp.cpp11
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp6
2 files changed, 11 insertions, 6 deletions
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
index 650e634..e81f603 100644
--- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
@@ -103,193 +103,194 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWi
103 } 103 }
104 } 104 }
105 105
106 //getInterfaceList(); 106 //getInterfaceList();
107 connectionList->header()->hide(); 107 connectionList->header()->hide();
108 108
109 Config cfg("NetworkSetup"); 109 Config cfg("NetworkSetup");
110 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 110 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
111 for ( QStringList::Iterator it = profiles.begin(); 111 for ( QStringList::Iterator it = profiles.begin();
112 it != profiles.end(); ++it) 112 it != profiles.end(); ++it)
113 profilesList->insertItem((*it)); 113 profilesList->insertItem((*it));
114 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 114 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
115 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 115 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
116 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 116 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
117 117
118 QFile file(scheme); 118 QFile file(scheme);
119 if ( file.open(IO_ReadOnly) ) 119 if ( file.open(IO_ReadOnly) )
120 { // file opened successfully 120 { // file opened successfully
121 QTextStream stream( &file ); // use a text stream 121 QTextStream stream( &file ); // use a text stream
122 while ( !stream.eof() ) 122 while ( !stream.eof() )
123 { // until end of file... 123 { // until end of file...
124 QString line = stream.readLine(); // line of text excluding '\n' 124 QString line = stream.readLine(); // line of text excluding '\n'
125 if(line.contains("SCHEME")) 125 if(line.contains("SCHEME"))
126 { 126 {
127 line = line.mid(7, line.length()); 127 line = line.mid(7, line.length());
128 currentProfileLabel->setText(line); 128 currentProfileLabel->setText(line);
129 break; 129 break;
130 } 130 }
131 } 131 }
132 file.close(); 132 file.close();
133 } 133 }
134 makeChannel(); 134 makeChannel();
135 initHostname(); 135 initHostname();
136} 136}
137 137
138/** 138/**
139 * Deconstructor. Save profiles. Delete loaded libraries. 139 * Deconstructor. Save profiles. Delete loaded libraries.
140 */ 140 */
141MainWindowImp::~MainWindowImp() 141MainWindowImp::~MainWindowImp()
142{ 142{
143 // Save profiles. 143 // Save profiles.
144 Config cfg("NetworkSetup"); 144 Config cfg("NetworkSetup");
145 cfg.setGroup("General"); 145 cfg.setGroup("General");
146 cfg.writeEntry("Profiles", profiles.join(" ")); 146 cfg.writeEntry("Profiles", profiles.join(" "));
147 147
148 // Delete all interfaces that don't have owners. 148 // Delete all interfaces that don't have owners.
149 QMap<Interface*, QListViewItem*>::Iterator iIt; 149 QMap<Interface*, QListViewItem*>::Iterator iIt;
150 for( iIt = items.begin(); iIt != items.end(); ++iIt ) 150 for( iIt = items.begin(); iIt != items.end(); ++iIt )
151 { 151 {
152 if(iIt.key()->getModuleOwner() == NULL) 152 if(iIt.key()->getModuleOwner() == NULL)
153 delete iIt.key(); 153 delete iIt.key();
154 } 154 }
155 155
156 // Delete Modules and Libraries 156 // Delete Modules and Libraries
157 QMap<Module*, QLibrary*>::Iterator it; 157 QMap<Module*, QLibrary*>::Iterator it;
158 for( it = libraries.begin(); it != libraries.end(); ++it ) 158 for( it = libraries.begin(); it != libraries.end(); ++it )
159 { 159 {
160 delete it.key(); 160 delete it.key();
161 // I wonder why I can't delete the libraries 161 // I wonder why I can't delete the libraries
162 // What fucking shit this is. 162 // What fucking shit this is.
163 //delete it.data(); 163 //delete it.data();
164 } 164 }
165} 165}
166 166
167/** 167/**
168 * Query the kernel for all of the interfaces. 168 * Query the kernel for all of the interfaces.
169 */ 169 */
170void MainWindowImp::getAllInterfaces() 170void MainWindowImp::getAllInterfaces()
171{ 171{
172 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 172 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
173 if(sockfd == -1) 173 if(sockfd == -1)
174 return; 174 return;
175 175
176 struct ifreq ifr; 176 struct ifreq ifr;
177 QStringList ifaces; 177 QStringList ifaces;
178 QFile procFile(QString(_PROCNETDEV)); 178 QFile procFile(QString(_PROCNETDEV));
179 int result; 179 int result;
180 Interface *i; 180 Interface *i;
181 181
182 if (! procFile.exists()) 182 if (! procFile.exists())
183 { 183 {
184 struct ifreq ifrs[100]; 184 struct ifreq ifrs[100];
185 struct ifconf ifc; 185 struct ifconf ifc;
186 ifc.ifc_len = sizeof(ifrs); 186 ifc.ifc_len = sizeof(ifrs);
187 ifc.ifc_req = ifrs; 187 ifc.ifc_req = ifrs;
188 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 188 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
189 189
190 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) 190 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
191 { 191 {
192 struct ifreq *pifr = &ifrs[i]; 192 struct ifreq *pifr = &ifrs[i];
193 if ( !QString( pifr->ifr_name ).startsWith( "wifi" ) ) ifaces += pifr->ifr_name; 193 if ( !QString( pifr->ifr_name ).startsWith( "wifi" ) ) ifaces += pifr->ifr_name;
194 else odebug << "ignoring hostap control interface " << pifr->ifr_name << oendl; 194 else odebug << "ignoring hostap control interface " << pifr->ifr_name << oendl;
195 } 195 }
196 } 196 }
197 else 197 else
198 { 198 {
199 procFile.open(IO_ReadOnly); 199 if (!procFile.open(IO_ReadOnly))
200 owarn << "Failed to open proc file " << procFile.name() << oendl;
200 QString line; 201 QString line;
201 QTextStream procTs(&procFile); 202 QTextStream procTs(&procFile);
202 int loc = -1; 203 int loc = -1;
203 204
204 procTs.readLine(); // eat a line 205 procTs.readLine(); // eat a line
205 procTs.readLine(); // eat a line 206 procTs.readLine(); // eat a line
206 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) 207 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
207 { 208 {
208 if((loc = line.find(":")) != -1) 209 if((loc = line.find(":")) != -1)
209 { 210 {
210 // ignore wifi* (hostap control interfaces) 211 // ignore wifi* (hostap control interfaces)
211 if ( !line.left(loc).startsWith( "wifi" ) ) ifaces += line.left(loc); 212 if ( !line.left(loc).startsWith( "wifi" ) ) ifaces += line.left(loc);
212 else odebug << "ignoring hostap control interface " << line.left(loc) << oendl; 213 else odebug << "ignoring hostap control interface " << line.left(loc) << oendl;
213 } 214 }
214 } 215 }
215 } 216 }
216 217
217 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) 218 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
218 { 219 {
219 int flags = 0; 220 int flags = 0;
220 if ( m_handledIfaces.contains( (*it) ) ) 221 if ( m_handledIfaces.contains( (*it) ) )
221 { 222 {
222 odebug << " " << (*it).latin1() << " is handled by a module" << oendl; 223 odebug << " " << (*it).latin1() << " is handled by a module" << oendl;
223 continue; 224 continue;
224 } 225 }
225 // int family; 226 // int family;
226 i = NULL; 227 i = NULL;
227 228
228 strcpy(ifr.ifr_name, (*it).latin1()); 229 strcpy(ifr.ifr_name, (*it).latin1());
229 230
230 struct ifreq ifcopy; 231 struct ifreq ifcopy;
231 ifcopy = ifr; 232 ifcopy = ifr;
232 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 233 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
233 flags = ifcopy.ifr_flags; 234 flags = ifcopy.ifr_flags;
234 i = new Interface(this, ifr.ifr_name, false); 235 i = new Interface(this, ifr.ifr_name, false);
235 i->setAttached(true); 236 i->setAttached(true);
236 if ((flags & IFF_UP) == IFF_UP) 237 if ((flags & IFF_UP) == IFF_UP)
237 i->setStatus(true); 238 i->setStatus(true);
238 else 239 else
239 i->setStatus(false); 240 i->setStatus(false);
240 241
241 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 242 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
242 i->setHardwareName("Ethernet"); 243 i->setHardwareName("Ethernet");
243 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 244 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
244 i->setHardwareName("Point to Point"); 245 i->setHardwareName("Point to Point");
245 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 246 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
246 i->setHardwareName("Multicast"); 247 i->setHardwareName("Multicast");
247 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 248 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
248 i->setHardwareName("Loopback"); 249 i->setHardwareName("Loopback");
249 else 250 else
250 i->setHardwareName("Unknown"); 251 i->setHardwareName("Unknown");
251 252
252 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl; 253 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl;
253 interfaceNames.insert(i->getInterfaceName(), i); 254 interfaceNames.insert(i->getInterfaceName(), i);
254 updateInterface(i); 255 updateInterface(i);
255 connect(i, SIGNAL(updateInterface(Interface*)), 256 connect(i, SIGNAL(updateInterface(Interface*)),
256 this, SLOT(updateInterface(Interface*))); 257 this, SLOT(updateInterface(Interface*)));
257 } 258 }
258 // now lets ask the plugins too ;) 259 // now lets ask the plugins too ;)
259 QMap<Module*, QLibrary*>::Iterator it; 260 QMap<Module*, QLibrary*>::Iterator it;
260 QList<Interface> ilist; 261 QList<Interface> ilist;
261 for( it = libraries.begin(); it != libraries.end(); ++it ) 262 for( it = libraries.begin(); it != libraries.end(); ++it )
262 { 263 {
263 if(it.key()) 264 if(it.key())
264 { 265 {
265 ilist = it.key()->getInterfaces(); 266 ilist = it.key()->getInterfaces();
266 for( i = ilist.first(); i != 0; i = ilist.next() ) 267 for( i = ilist.first(); i != 0; i = ilist.next() )
267 { 268 {
268 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl; 269 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl;
269 interfaceNames.insert(i->getInterfaceName(), i); 270 interfaceNames.insert(i->getInterfaceName(), i);
270 updateInterface(i); 271 updateInterface(i);
271 connect(i, SIGNAL(updateInterface(Interface*)), 272 connect(i, SIGNAL(updateInterface(Interface*)),
272 this, SLOT(updateInterface(Interface*))); 273 this, SLOT(updateInterface(Interface*)));
273 } 274 }
274 } 275 }
275 } 276 }
276} 277}
277 278
278/** 279/**
279 * Load all modules that are found in the path 280 * Load all modules that are found in the path
280 * @param path a directory that is scaned for any plugins that can be loaded 281 * @param path a directory that is scaned for any plugins that can be loaded
281 * and attempts to load them 282 * and attempts to load them
282 */ 283 */
283void MainWindowImp::loadModules(const QString &path) 284void MainWindowImp::loadModules(const QString &path)
284{ 285{
285#ifdef DEBUG 286#ifdef DEBUG
286 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl; 287 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl;
287#endif 288#endif
288 QDir d(path); 289 QDir d(path);
289 if(!d.exists()) 290 if(!d.exists())
290 return; 291 return;
291 292
292 QString lang = ::getenv("LANG"); 293 QString lang = ::getenv("LANG");
293 // Don't want sym links 294 // Don't want sym links
294 d.setFilter( QDir::Files | QDir::NoSymLinks ); 295 d.setFilter( QDir::Files | QDir::NoSymLinks );
295 const QFileInfoList *list = d.entryInfoList(); 296 const QFileInfoList *list = d.entryInfoList();
@@ -639,147 +640,149 @@ void MainWindowImp::removeProfile()
639 break; 640 break;
640 } 641 }
641 } 642 }
642 } 643 }
643} 644}
644 645
645/** 646/**
646 * A new profile has been selected, change. 647 * A new profile has been selected, change.
647 * @param newProfile the new profile. 648 * @param newProfile the new profile.
648 */ 649 */
649void MainWindowImp::changeProfile() 650void MainWindowImp::changeProfile()
650{ 651{
651 if(profilesList->currentItem() == -1) 652 if(profilesList->currentItem() == -1)
652 { 653 {
653 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 654 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
654 return; 655 return;
655 } 656 }
656 QString newProfile = profilesList->text(profilesList->currentItem()); 657 QString newProfile = profilesList->text(profilesList->currentItem());
657 if(newProfile != currentProfileLabel->text()) 658 if(newProfile != currentProfileLabel->text())
658 { 659 {
659 currentProfileLabel->setText(newProfile); 660 currentProfileLabel->setText(newProfile);
660 QFile::remove(scheme); 661 QFile::remove(scheme);
661 QFile file(scheme); 662 QFile file(scheme);
662 if ( file.open(IO_ReadWrite) ) 663 if ( file.open(IO_ReadWrite) )
663 { 664 {
664 QTextStream stream( &file ); 665 QTextStream stream( &file );
665 stream << QString("SCHEME=%1").arg(newProfile); 666 stream << QString("SCHEME=%1").arg(newProfile);
666 file.close(); 667 file.close();
667 } 668 }
668 // restart all up devices? 669 // restart all up devices?
669 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok) 670 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok)
670 { 671 {
671 // Go through them one by one 672 // Go through them one by one
672 QMap<Interface*, QListViewItem*>::Iterator it; 673 QMap<Interface*, QListViewItem*>::Iterator it;
673 for( it = items.begin(); it != items.end(); ++it ) 674 for( it = items.begin(); it != items.end(); ++it )
674 { 675 {
675 if(it.key()->getStatus() == true) 676 if(it.key()->getStatus() == true)
676 it.key()->restart(); 677 it.key()->restart();
677 } 678 }
678 } 679 }
679 } 680 }
680 // TODO change the profile in the modules 681 // TODO change the profile in the modules
681} 682}
682 683
683 684
684void MainWindowImp::makeChannel() 685void MainWindowImp::makeChannel()
685{ 686{
686 channel = new QCopChannel( "QPE/Application/networksettings", this ); 687 channel = new QCopChannel( "QPE/Application/networksettings", this );
687 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 688 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
688 this, SLOT(receive(const QCString&,const QByteArray&)) ); 689 this, SLOT(receive(const QCString&,const QByteArray&)) );
689} 690}
690 691
691void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) 692void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
692{ 693{
693 bool found = false; 694 bool found = false;
694 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; 695 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl;
695 if (msg == "raise") 696 if (msg == "raise")
696 { 697 {
697 raise(); 698 raise();
698 return; 699 return;
699 } 700 }
700 701
701 QString dest = msg.left(msg.find("(")); 702 QString dest = msg.left(msg.find("("));
702 QCString param = msg.right(msg.length() - msg.find("(") - 1); 703 QCString param = msg.right(msg.length() - msg.find("(") - 1);
703 param = param.left( param.length() - 1 ); 704 param = param.left( param.length() - 1 );
704 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; 705 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl;
705 706
706 QMap<Module*, QLibrary*>::Iterator it; 707 QMap<Module*, QLibrary*>::Iterator it;
707 for( it = libraries.begin(); it != libraries.end(); ++it ) 708 for( it = libraries.begin(); it != libraries.end(); ++it )
708 { 709 {
709 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; 710 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl;
710 if(it.key()->type() == dest) 711 if(it.key()->type() == dest)
711 { 712 {
712 it.key()->receive( param, arg ); 713 it.key()->receive( param, arg );
713 found = true; 714 found = true;
714 } 715 }
715 } 716 }
716 717
717 718
718 if (found) QPEApplication::setKeepRunning(); 719 if (found) QPEApplication::setKeepRunning();
719 else odebug << "Huh what do ya want" << oendl; 720 else odebug << "Huh what do ya want" << oendl;
720} 721}
721 722
722void MainWindowImp::setHostname() 723void MainWindowImp::setHostname()
723{ 724{
724 static QRegExp filter("[^A-Za-z0-9_\\-\\.]"); 725 static QRegExp filter("[^A-Za-z0-9_\\-\\.]");
725 if (filter.match(m_Nameinput->text())!=-1) { 726 if (filter.match(m_Nameinput->text())!=-1) {
726 odebug << "Wrong hostname" << oendl; 727 odebug << "Wrong hostname" << oendl;
727 QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot.")); 728 QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot."));
728 return; 729 return;
729 } 730 }
730 731
731 OProcess h; 732 OProcess h;
732 _procTemp=""; 733 _procTemp="";
733 h << "hostname" << m_Nameinput->text(); 734 h << "hostname" << m_Nameinput->text();
734 connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); 735 connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
735 h.start(OProcess::Block,OProcess::Stderr); 736 if (!h.start(OProcess::Block,OProcess::Stderr))
737 owarn << "Failed execution of 'hostname'. Are the paths correct?" << oendl;
736 odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl; 738 odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl;
737 if (h.exitStatus()!=0) { 739 if (h.exitStatus()!=0) {
738 QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace())); 740 QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace()));
739 return; 741 return;
740 } 742 }
741 _procTemp=""; 743 _procTemp="";
742 744
743 QFile f(_HOSTFILE); 745 QFile f(_HOSTFILE);
744 if (f.open(IO_Truncate|IO_WriteOnly)) 746 if (f.open(IO_Truncate|IO_WriteOnly))
745 { 747 {
746 QTextStream s(&f); 748 QTextStream s(&f);
747 s << m_Nameinput->text(); 749 s << m_Nameinput->text();
748 } else { 750 } else {
749 QMessageBox::critical(0, tr("Sorry"), tr("Could not save name.")); 751 QMessageBox::critical(0, tr("Sorry"), tr("Could not save name."));
750 return; 752 return;
751 } 753 }
752 754
753 f.close(); 755 f.close();
754 f.setName(_IRDANAME); 756 f.setName(_IRDANAME);
755 if (f.open(IO_WriteOnly)) 757 if (f.open(IO_WriteOnly))
756 { 758 {
757 QTextStream s(&f); 759 QTextStream s(&f);
758 s << m_Nameinput->text(); 760 s << m_Nameinput->text();
759 } else { 761 } else {
760 QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name.")); 762 QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name."));
761 } 763 }
762} 764}
763 765
764void MainWindowImp::initHostname() 766void MainWindowImp::initHostname()
765{ 767{
766 OProcess h; 768 OProcess h;
767 _procTemp=""; 769 _procTemp="";
768 770
769 h << "hostname"; 771 h << "hostname";
770 connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); 772 connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
771 h.start(OProcess::Block,OProcess::AllOutput); 773 if (!h.start(OProcess::Block,OProcess::AllOutput))
774 owarn << "Could not execute 'hostname'. Are the paths correct?" oendl;
772 odebug << "Got " << _procTemp <<oendl; 775 odebug << "Got " << _procTemp <<oendl;
773 m_Nameinput->setText(_procTemp.stripWhiteSpace()); 776 m_Nameinput->setText(_procTemp.stripWhiteSpace());
774 _procTemp=""; 777 _procTemp="";
775} 778}
776 779
777void MainWindowImp::slotHostname(Opie::Core::OProcess */*proc*/, char *buffer, int buflen) 780void MainWindowImp::slotHostname(Opie::Core::OProcess * /*proc*/, char *buffer, int buflen)
778{ 781{
779 if (buflen < 1 || buffer==0) return; 782 if (buflen < 1 || buffer==0) return;
780 char*_t = new char[buflen+1]; 783 char*_t = new char[buflen+1];
781 ::memset(_t,0,buflen+1); 784 ::memset(_t,0,buflen+1);
782 ::memcpy(_t,buffer,buflen); 785 ::memcpy(_t,buffer,buflen);
783 _procTemp+=_t; 786 _procTemp+=_t;
784 delete[]_t; 787 delete[]_t;
785} 788}
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index 7b2e2a3..17ada9b 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -675,194 +675,196 @@ int Modem::openLockfile( QString lockfile, int flags)
675 // } 675 // }
676 if ((fd = open(lockfile, flags, mode)) == -1) { 676 if ((fd = open(lockfile, flags, mode)) == -1) {
677 odebug << "error opening lockfile!" << oendl; 677 odebug << "error opening lockfile!" << oendl;
678 lockfile = QString::null; 678 lockfile = QString::null;
679 fd = open(DEVNULL, O_RDONLY); 679 fd = open(DEVNULL, O_RDONLY);
680 } else 680 } else
681 fchown(fd, 0, 0); 681 fchown(fd, 0, 0);
682 return fd; 682 return fd;
683} 683}
684 684
685 685
686 686
687void alarm_handler(int) { 687void alarm_handler(int) {
688 // fprintf(stderr, "alarm_handler(): Received SIGALRM\n"); 688 // fprintf(stderr, "alarm_handler(): Received SIGALRM\n");
689 689
690 // jump 690 // jump
691 siglongjmp(jmp_buffer, 1); 691 siglongjmp(jmp_buffer, 1);
692} 692}
693 693
694 694
695const char* Modem::authFile(Auth method, int version) { 695const char* Modem::authFile(Auth method, int version) {
696 switch(method|version) { 696 switch(method|version) {
697 case PAP|Original: 697 case PAP|Original:
698 return PAP_AUTH_FILE; 698 return PAP_AUTH_FILE;
699 break; 699 break;
700 case PAP|New: 700 case PAP|New:
701 return PAP_AUTH_FILE".new"; 701 return PAP_AUTH_FILE".new";
702 break; 702 break;
703 case PAP|Old: 703 case PAP|Old:
704 return PAP_AUTH_FILE".old"; 704 return PAP_AUTH_FILE".old";
705 break; 705 break;
706 case CHAP|Original: 706 case CHAP|Original:
707 return CHAP_AUTH_FILE; 707 return CHAP_AUTH_FILE;
708 break; 708 break;
709 case CHAP|New: 709 case CHAP|New:
710 return CHAP_AUTH_FILE".new"; 710 return CHAP_AUTH_FILE".new";
711 break; 711 break;
712 case CHAP|Old: 712 case CHAP|Old:
713 return CHAP_AUTH_FILE".old"; 713 return CHAP_AUTH_FILE".old";
714 break; 714 break;
715 default: 715 default:
716 return 0L; 716 return 0L;
717 } 717 }
718} 718}
719 719
720 720
721bool Modem::createAuthFile(Auth method, const char *username, const char *password) { 721bool Modem::createAuthFile(Auth method, const char *username, const char *password) {
722 const char *authfile, *oldName, *newName; 722 const char *authfile, *oldName, *newName;
723 char line[100]; 723 char line[100];
724 char regexp[2*MaxStrLen+30]; 724 char regexp[2*MaxStrLen+30];
725 regex_t preg; 725 regex_t preg;
726 726
727 if(!(authfile = authFile(method))) 727 if(!(authfile = authFile(method)))
728 return false; 728 return false;
729 729
730 if(!(newName = authFile(method, New))) 730 if(!(newName = authFile(method, New)))
731 return false; 731 return false;
732 732
733 // look for username, "username" or 'username' 733 // look for username, "username" or 'username'
734 // if you modify this RE you have to adapt regexp's size above 734 // if you modify this RE you have to adapt regexp's size above
735 snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']", 735 snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']",
736 username,username); 736 username,username);
737 MY_ASSERT(regcomp(&preg, regexp, 0) == 0); 737 MY_ASSERT(regcomp(&preg, regexp, 0) == 0);
738 738
739 // copy to new file pap- or chap-secrets 739 // copy to new file pap- or chap-secrets
740 int old_umask = umask(0077); 740 int old_umask = umask(0077);
741 FILE *fout = fopen(newName, "w"); 741 FILE *fout = fopen(newName, "w");
742 if(fout) { 742 if(fout) {
743 // copy old file 743 // copy old file
744 FILE *fin = fopen(authfile, "r"); 744 FILE *fin = fopen(authfile, "r");
745 if(fin) { 745 if(fin) {
746 while(fgets(line, sizeof(line), fin)) { 746 while(fgets(line, sizeof(line), fin)) {
747 if(regexec(&preg, line, 0, 0L, 0) == 0) 747 if(regexec(&preg, line, 0, 0L, 0) == 0)
748 continue; 748 continue;
749 fputs(line, fout); 749 fputs(line, fout);
750 } 750 }
751 fclose(fin); 751 fclose(fin);
752 } 752 }
753 753
754 // append user/pass pair 754 // append user/pass pair
755 fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password); 755 fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password);
756 fclose(fout); 756 fclose(fout);
757 } 757 }
758 758
759 // restore umask 759 // restore umask
760 umask(old_umask); 760 umask(old_umask);
761 761
762 // free memory allocated by regcomp 762 // free memory allocated by regcomp
763 regfree(&preg); 763 regfree(&preg);
764 764
765 if(!(oldName = authFile(method, Old))) 765 if(!(oldName = authFile(method, Old)))
766 return false; 766 return false;
767 767
768 // delete old file if any 768 // delete old file if any
769 unlink(oldName); 769 unlink(oldName);
770 770
771 rename(authfile, oldName); 771 if (rename(authfile, oldName) == -1)
772 rename(newName, authfile); 772 return false;
773 if (rename(newName, authfile) == -1)
774 return false;
773 775
774 return true; 776 return true;
775} 777}
776 778
777 779
778bool Modem::removeAuthFile(Auth method) { 780bool Modem::removeAuthFile(Auth method) {
779 const char *authfile, *oldName; 781 const char *authfile, *oldName;
780 782
781 if(!(authfile = authFile(method))) 783 if(!(authfile = authFile(method)))
782 return false; 784 return false;
783 if(!(oldName = authFile(method, Old))) 785 if(!(oldName = authFile(method, Old)))
784 return false; 786 return false;
785 787
786 if(access(oldName, F_OK) == 0) { 788 if(access(oldName, F_OK) == 0) {
787 unlink(authfile); 789 unlink(authfile);
788 return (rename(oldName, authfile) == 0); 790 return (rename(oldName, authfile) == 0);
789 } else 791 } else
790 return false; 792 return false;
791} 793}
792 794
793 795
794bool Modem::setSecret(int method, const char* name, const char* password) 796bool Modem::setSecret(int method, const char* name, const char* password)
795{ 797{
796 798
797 Auth auth; 799 Auth auth;
798 if(method == AUTH_PAPCHAP) 800 if(method == AUTH_PAPCHAP)
799 return setSecret(AUTH_PAP, name, password) && 801 return setSecret(AUTH_PAP, name, password) &&
800 setSecret(AUTH_CHAP, name, password); 802 setSecret(AUTH_CHAP, name, password);
801 803
802 switch(method) { 804 switch(method) {
803 case AUTH_PAP: 805 case AUTH_PAP:
804 auth = Modem::PAP; 806 auth = Modem::PAP;
805 break; 807 break;
806 case AUTH_CHAP: 808 case AUTH_CHAP:
807 auth = Modem::CHAP; 809 auth = Modem::CHAP;
808 break; 810 break;
809 default: 811 default:
810 return false; 812 return false;
811 } 813 }
812 814
813 return createAuthFile(auth, name, password); 815 return createAuthFile(auth, name, password);
814 816
815} 817}
816 818
817bool Modem::removeSecret(int method) 819bool Modem::removeSecret(int method)
818{ 820{
819 Auth auth; 821 Auth auth;
820 822
821 switch(method) { 823 switch(method) {
822 case AUTH_PAP: 824 case AUTH_PAP:
823 auth = Modem::PAP; 825 auth = Modem::PAP;
824 break; 826 break;
825 case AUTH_CHAP: 827 case AUTH_CHAP:
826 auth = Modem::CHAP; 828 auth = Modem::CHAP;
827 break; 829 break;
828 default: 830 default:
829 return false; 831 return false;
830 } 832 }
831 return removeAuthFile( auth ); 833 return removeAuthFile( auth );
832} 834}
833 835
834int checkForInterface() 836int checkForInterface()
835{ 837{
836// I don't know if Linux needs more initialization to get the ioctl to 838// I don't know if Linux needs more initialization to get the ioctl to
837// work, pppd seems to hint it does. But BSD doesn't, and the following 839// work, pppd seems to hint it does. But BSD doesn't, and the following
838// code should compile. 840// code should compile.
839#if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__) 841#if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__)
840 int s, ok; 842 int s, ok;
841 struct ifreq ifr; 843 struct ifreq ifr;
842 // extern char *no_ppp_msg; 844 // extern char *no_ppp_msg;
843 845
844 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) 846 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
845 return 1; /* can't tell */ 847 return 1; /* can't tell */
846 848
847 strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); 849 strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
848 ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; 850 ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
849 close(s); 851 close(s);
850 852
851 if (ok == -1) { 853 if (ok == -1) {
852// This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports 854// This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports
853// KLDs, the old LKM interface couldn't handle loading devices 855// KLDs, the old LKM interface couldn't handle loading devices
854// dynamically, and thus can't load ppp support on the fly 856// dynamically, and thus can't load ppp support on the fly
855#ifdef __FreeBSD__ 857#ifdef __FreeBSD__
856 // If we failed to load ppp support and don't have it already. 858 // If we failed to load ppp support and don't have it already.
857 if (kldload("if_ppp") == -1) { 859 if (kldload("if_ppp") == -1) {
858 return -1; 860 return -1;
859 } 861 }
860 return 0; 862 return 0;
861#else 863#else
862 return -1; 864 return -1;
863#endif 865#endif
864 } 866 }
865 return 0; 867 return 0;
866#else 868#else
867// We attempt to use the SunOS/SysVr4 method and stat /dev/ppp 869// We attempt to use the SunOS/SysVr4 method and stat /dev/ppp
868 struct stat buf; 870 struct stat buf;