Working with Rexec
-
hi, I'm working with Rexec in visual C++. I don't know any C++ so the going is slow. My task was to change the service, edit security so only certain ip's could remote execute. I succeded but, it only works in the debug mode used when -d is passed instead of -i and then allowing it to interact with the desktop. So when running as a Service it no longer does anything. I open a file and read data from it for the security addition and i'm wondering if that is the reason it doesn't work. can services do file manipulation? Any help is much appreciated, advice also welcomed because i'm a newb. here is the code i added, it shouldn't have an affect anywhere else: CAsyncSocket SrvSock; SrvSock.Create(9987); SrvSock.Listen(); CAsyncSocket CliSock; // struct sockaddr addr; struct sockaddr_in from; //putting all hosts.txt values in an array for faster more effecient check int count = 0; int i = 0; string ip; string ipArray[MAX_IP]; ifstream openFile("hosts.txt"); while(openFile.peek() != EOF) { openFile >> ip; openFile.ignore(255, '\n'); ipArray[count] = ip; count++; } printf("array initialized with %d values\n", count); openFile.close(); int nSize = sizeof(SOCKADDR); // Loop to maintain the search while the application is running. while (!m_pStop->Lock(0)) { // Check to see if a connection is being attempted. if(SrvSock.Accept(CliSock, (struct sockaddr*)&from, &nSize)) { printf("Remote Address %s \n", inet_ntoa(from.sin_addr));//andrew: to print ip SOCKET hSock = CliSock.m_hSocket; CliSock.Detach(); while(ip != "") { ip = ipArray[i]; if(inet_ntoa(from.sin_addr) == ip) //.compare(ip) == 0) { printf("MATCH Verified\nACCESS GRANTED!\n\n"); //Let a seperate thread handle the individual connections: AfxBeginThread(ProcConnectionFunc, (LPVOID)hSock); i = 0; break; } if(ipArray[i+1] == "") { printf("Verification Failed\nACCESS DENIED!\n"); ip = ""; i = 0; } i++; } ip = " "; // openFile.close(); } Sleep(1); } // Clean up... SrvSock.Close(); }
-
hi, I'm working with Rexec in visual C++. I don't know any C++ so the going is slow. My task was to change the service, edit security so only certain ip's could remote execute. I succeded but, it only works in the debug mode used when -d is passed instead of -i and then allowing it to interact with the desktop. So when running as a Service it no longer does anything. I open a file and read data from it for the security addition and i'm wondering if that is the reason it doesn't work. can services do file manipulation? Any help is much appreciated, advice also welcomed because i'm a newb. here is the code i added, it shouldn't have an affect anywhere else: CAsyncSocket SrvSock; SrvSock.Create(9987); SrvSock.Listen(); CAsyncSocket CliSock; // struct sockaddr addr; struct sockaddr_in from; //putting all hosts.txt values in an array for faster more effecient check int count = 0; int i = 0; string ip; string ipArray[MAX_IP]; ifstream openFile("hosts.txt"); while(openFile.peek() != EOF) { openFile >> ip; openFile.ignore(255, '\n'); ipArray[count] = ip; count++; } printf("array initialized with %d values\n", count); openFile.close(); int nSize = sizeof(SOCKADDR); // Loop to maintain the search while the application is running. while (!m_pStop->Lock(0)) { // Check to see if a connection is being attempted. if(SrvSock.Accept(CliSock, (struct sockaddr*)&from, &nSize)) { printf("Remote Address %s \n", inet_ntoa(from.sin_addr));//andrew: to print ip SOCKET hSock = CliSock.m_hSocket; CliSock.Detach(); while(ip != "") { ip = ipArray[i]; if(inet_ntoa(from.sin_addr) == ip) //.compare(ip) == 0) { printf("MATCH Verified\nACCESS GRANTED!\n\n"); //Let a seperate thread handle the individual connections: AfxBeginThread(ProcConnectionFunc, (LPVOID)hSock); i = 0; break; } if(ipArray[i+1] == "") { printf("Verification Failed\nACCESS DENIED!\n"); ip = ""; i = 0; } i++; } ip = " "; // openFile.close(); } Sleep(1); } // Clean up... SrvSock.Close(); }
I would try reposting this in the c++ forum, this isnt really the correct place for those types of questions. http://www.codeproject.com/script/comments/forums.asp?forumid=1647 Ryan