summaryrefslogtreecommitdiff
path: root/noncore/net/opie-smb/qsmb.cpp
Unidiff
Diffstat (limited to 'noncore/net/opie-smb/qsmb.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opie-smb/qsmb.cpp76
1 files changed, 23 insertions, 53 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp
index d6d1b23..c1ee9a9 100644
--- a/noncore/net/opie-smb/qsmb.cpp
+++ b/noncore/net/opie-smb/qsmb.cpp
@@ -16,6 +16,7 @@
16#include <qcheckbox.h> 16#include <qcheckbox.h>
17#include <qtextview.h> 17#include <qtextview.h>
18#include <qmessagebox.h> 18#include <qmessagebox.h>
19#include <qtextstream.h>
19 20
20 21
21#include <pthread.h> 22#include <pthread.h>
@@ -100,12 +101,7 @@ void Qsmb::scan()
100 scanning = true; 101 scanning = true;
101 102
102 QString match; 103 QString match;
103 char lmhosts[512];
104 QString cmd; 104 QString cmd;
105 char result[256];
106
107 FILE *pipe, *pipe2;
108
109 LScan->setText("Scanning..."); 105 LScan->setText("Scanning...");
110 qApp->processEvents(); 106 qApp->processEvents();
111 107
@@ -117,61 +113,35 @@ void Qsmb::scan()
117 113
118 match = ip.left(5); 114 match = ip.left(5);
119 115
120 cmd = "smbfind"; 116 QStringList ccmd;
121 owarn <<"cmd: " << cmd << oendl; 117 TextViewOutput->append("smbfind");
122
123 TextViewOutput->append(cmd);
124
125 snprintf(lmhosts, 512, "echo '127.0.0.1 localhost'>/etc/samba/lmhosts");
126
127 if ((pipe2 = popen(lmhosts, "r")) == NULL) {
128 snprintf(result, 256, "Error: Can't run %s", lmhosts);
129 //TextViewOutput->append(result);
130 return;
131 }
132 118
133 /* run command & read output */ 119 QFile lmhosts("/etc/samba/lmhosts");
134 if ((pipe = popen(cmd.latin1(), "r")) == NULL) { 120 QTextStream lms(&lmhosts);
135 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 121 lmhosts.open(IO_WriteOnly);
136 TextViewOutput->append(result); 122 lms << "127.0.0.1 localhost\n";
137 return;
138 }
139 123
140 /* parse output and display in ListViewScan */ 124 /* parse output and display in ListViewScan */
141 while(fgets(result, 256, pipe) != NULL) { 125 ccmd = "smbfind";
142 /* put result into TextViewOutput */ 126 owarn <<"cmd: " << ccmd << oendl;
143 TextViewOutput->append(result); 127 runCommand(ccmd);
144
145 if( strstr(result, match.latin1()) != NULL ) {
146 char ip_addr[256], host[256], *ptr1;
147
148 strcpy( ip_addr, result);
149 ptr1 = strchr(ip_addr,' ');
150 strcpy( host, ptr1);
151 ip_addr[ptr1 - ip_addr]='\0';
152
153 for(i = 0; i < 256; i++) {
154 if(host[i]!=' ') {
155 strcpy( host, host + i);
156 break;
157 }
158 }
159 ptr1 = strchr(host,' ');
160 host[ptr1 - host] = '\0';
161
162 owarn << "add host: " << host << oendl;
163 128
129 QTextStream s(&out, IO_ReadOnly);
130
131 while ( !s.atEnd() ) {
132 QString ip_addr, host, output;
133 QString tmp = s.readLine();
134 bool ok;
135 tmp.left(1).toInt( &ok, 10 );
136 if(ok) {
137 QStringList token = QStringList::split(' ', tmp );
138 ip_addr = token[0];
139 host = token[1];
164 CBHost->insertItem( host, -1); 140 CBHost->insertItem( host, -1);
165 snprintf( lmhosts, 512, "echo '%s %s'>>/etc/samba/lmhosts", ip_addr,host); 141 lms << ip_addr+" "+host+"\n";
166
167 owarn << "lmhosts: " << lmhosts << oendl;
168
169 if ((pipe2 = popen(lmhosts, "r")) == NULL) {
170 snprintf(result, 256, "Error: Can't run %s", lmhosts);
171 return;
172 }
173 } 142 }
174 } 143 }
144 lmhosts.close();
175 145
176 TextViewOutput->append("\n\n============================================\n"); 146 TextViewOutput->append("\n\n============================================\n");
177 LScan->setText(""); 147 LScan->setText("");