void clientmessage(XEvent *e) { XClientMessageEvent *ev = &e->xclient; Client *c; if (ev->message_type == atom[CloseWindow]) { if ((c = getclient(ev->window, clients, ClientWindow))) killclient(c); } else if (ev->message_type == atom[ActiveWindow]) { if ((c = getclient(ev->window, clients, ClientWindow))) { c->isicon = False; focus(c); arrange(curmonitor()); } } else if (ev->message_type == atom[CurDesk]) { view(tags[ev->data.l[0]]); } else if (ev->message_type == atom[WindowState]) { if ((c = getclient(ev->window, clients, ClientWindow))) { ewmh_process_state_atom(c, (Atom) ev->data.l[1], ev->data.l[0]); if (ev->data.l[2]) ewmh_process_state_atom(c, (Atom) ev->data.l[2], ev->data.l[0]); } } else if (ev->message_type == atom[WMChangeState]) { if ((c = getclient(ev->window, clients, ClientWindow))) { if (ev->data.l[0] == IconicState) { focus(c); iconify(NULL); } } } }
DWORD WINAPI myThread1(LPVOID lpParameter) { SOCKET new_socket = *((SOCKET*)lpParameter); char hashsend[256] = "1q2w3e4r";//Случайная последовательность char answer[1024]; char buffer[256]; int n; //Аутентификация пользователя int is_auntentity_ok = 0; char savebuf[256]; //do // { n = send(new_socket,"Please, give me your username and password via blank:",255,0); // if (n < 0) // error("ERROR writing to socket"); memset(buffer,0,256);//Взятие данных от пользователя n = recv(new_socket,buffer,256,0); Sleep(5); // if (n < 0) // error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); char temp[256]; memset(temp,0,256); memset(savebuf,0,256); strncpy_s(temp,buffer,strlen(buffer)); struct ArrFields arrfields = readFile(); int i = 0; int yes = 0; for(i = 0; i < arrfields.size; i++) { char usrpassw [256]; memset(usrpassw,0,256); strcat_s(usrpassw,arrfields.arr[i].username); strcat_s(usrpassw," "); strcat_s(usrpassw,arrfields.arr[i].password); if(strcmp(temp,usrpassw) == 0) { yes = 1; strncpy_s(savebuf,temp,strlen(temp)); } } printf("%i\n",yes); if(yes == 1) { is_auntentity_ok = 1; printf("%s\n",hashsend); printf("%i\n",strlen(hashsend)); n = send(new_socket,hashsend,strlen(hashsend),0); // if (n < 0) // error("ERROR writing to socket"); } else { n = send(new_socket,"Polzovatel' and Parol' neverny!",255,0); // if (n < 0) // error("ERROR writing to socket"); //close(newsockfd); //killclient(); } // } while(is_auntentity_ok != 1); is_auntentity_ok = 0; // do // { char hashbuf[256]; memset(hashbuf,0,256); strcat_s(hashbuf,savebuf); strcat_s(hashbuf,hashsend); printf("%s\n",hashbuf); printf("%i\n",strlen(hashbuf)); unsigned int res = HashH37(hashbuf);//Вычисление хэш-функции printf("%i\n",res); char ans [256]; memset(ans,0,256); memset(buffer,0,256); sprintf_s(buffer, "%d", res); strcpy_s(ans,buffer); printf("Подсчитанный хеш: %s\n",ans); printf("Подсчитанный хеш длина: %i\n",strlen(ans)); memset(buffer,0,256); n = recv(new_socket,buffer,256,0); printf("Полученный хеш: %s\n",buffer); printf("Полученный хеш длина: %i\n",strlen(buffer)); // if (n < 0) // error("ERROR reading from socket"); if (strcmp(ans,buffer) == 0) { printf("Hash ok\n"); n = send(new_socket,"Hello!",255,0); // if (n < 0) // error("ERROR writing to socket"); is_auntentity_ok = 1; } else { printf("Hash not ok\n"); n = send(new_socket,"Hash neveren",255,0); // if (n < 0) // error("ERROR writing to socket"); killclient(); } // } while(is_auntentity_ok != 1); while(1) { memset(buffer,0,256); memset(answer,0,256); n = recv(new_socket,buffer,256,0); // if (n < 0) // error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); char tempbuf[256]; memset(tempbuf,0,256); strncpy_s(tempbuf,buffer,strlen(buffer)-1); printf("%s\n",tempbuf); if(strcmp(tempbuf,"logout") == 0) { printf("logout yes\n"); n = send(new_socket,"Good Buy!",255,0); // if (n < 0) // error("ERROR writing to socket"); char path[256]; memset(path,0,256); closesocket(new_socket); } else if(strcmp(tempbuf,"who") == 0) { printf("who yes\n"); char whomessage[1024]; memset(whomessage,0,1024); chDirectory(arrfields, "/home/anton/workspace/tcpproj", "Anton"); strcpy_s(whomessage,createWhoMessage(arrfields)); n = send(new_socket,whomessage,255,0); // if (n < 0) // error("ERROR writing to socket"); } else { printf("%s\n",buffer); FILE *fp; int status; char path[256]; memset(path,0,256); fp = _popen(buffer, "r"); if (fp == NULL) error("Failed to execute a command in the terminal\n"); char prov[256]; memset(prov,0,256); strncpy_s(prov,buffer,strlen(buffer)-1); if((strcmp(prov,"cd") == 0) || (strcmp(prov,"cd ..") == 0)) { printf("cdok"); strcpy_s(answer,"cdok"); } else { while (fgets(path, 256, fp) != NULL) { printf("%s", path); memset(buffer,0,256); strncpy_s(buffer,path,strlen(path)); strcat_s(answer,buffer); } } n = send(new_socket,answer,strlen(answer),0); // if (n < 0) // error("ERROR writing to socket"); status = _pclose(fp); if (status == -1) { error("Error with executing of command\n"); } } } closesocket(new_socket); return 0; }
int main(int argc , char *argv[]) { setlocale(LC_ALL,"Russian"); DWORD myThreadID; WSADATA wsa; SOCKET sockfd, new_socket; int portno; char hashsend[256] = "1q2w3e4r"; int clilen; struct sockaddr_in serv_addr, cli_addr; printf("\nInitialising Winsock..."); if (WSAStartup(MAKEWORD(2,2),&wsa) != 0) { printf("Failed. Error Code : %d",WSAGetLastError()); return 1; } printf("Initialised.\n"); //Create a socket if((sockfd = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET) { printf("Could not create socket : %d" , WSAGetLastError()); } printf("Socket created.\n"); memset((char *) &serv_addr,0, sizeof(serv_addr)); portno = 8888; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); //Bind if( bind(sockfd ,(struct sockaddr *)&serv_addr , sizeof(serv_addr)) == SOCKET_ERROR) { printf("Bind failed with error code : %d" , WSAGetLastError()); } puts("Bind done"); //Listen to incoming connections listen(sockfd , 5); //Accept and incoming connection puts("Waiting for incoming connections..."); clilen = sizeof(struct sockaddr_in); new_socket = accept(sockfd , (struct sockaddr *)&cli_addr, &clilen); if (new_socket == INVALID_SOCKET) { printf("accept failed with error code : %d" , WSAGetLastError()); } char answer[1024]; char buffer[256]; int n; //Аутентификация пользователя int is_auntentity_ok = 0; char savebuf[256]; //do // { n = send(new_socket,"Please, give me your username and password via blank:",255,0); // if (n < 0) // error("ERROR writing to socket"); memset(buffer,0,256);//Взятие данных от пользователя n = recv(new_socket,buffer,256,0); // if (n < 0) // error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); char temp[256]; memset(temp,0,256); memset(savebuf,0,256); strncpy_s(temp,buffer,strlen(buffer)); struct ArrFields arrfields = readFile(); int i = 0; int yes = 0; for(i = 0; i < arrfields.size; i++) { char usrpassw [256]; memset(usrpassw,0,256); strcat_s(usrpassw,arrfields.arr[i].username); strcat_s(usrpassw," "); strcat_s(usrpassw,arrfields.arr[i].password); if(strcmp(temp,usrpassw) == 0) { yes = 1; strncpy_s(savebuf,temp,strlen(temp)); } } printf("%i\n",yes); if(yes == 1) { is_auntentity_ok = 1; printf("%s\n",hashsend); printf("%i\n",strlen(hashsend)); n = send(new_socket,hashsend,strlen(hashsend),0); // if (n < 0) // error("ERROR writing to socket"); } else { n = send(new_socket,"Polzovatel' and Parol' neverny!",255,0); // if (n < 0) // error("ERROR writing to socket"); //close(newsockfd); //killclient(); } // } while(is_auntentity_ok != 1); is_auntentity_ok = 0; // do // { char hashbuf[256]; memset(hashbuf,0,256); strcat_s(hashbuf,savebuf); strcat_s(hashbuf,hashsend); printf("%s\n",hashbuf); printf("%i\n",strlen(hashbuf)); unsigned int res = HashH37(hashbuf);//Вычисление хэш-функции printf("%i\n",res); char ans [256]; memset(ans,0,256); memset(buffer,0,256); sprintf_s(buffer, "%d", res); strcpy_s(ans,buffer); printf("Подсчитанный хеш: %s\n",ans); printf("Подсчитанный хеш длина: %i\n",strlen(ans)); memset(buffer,0,256); n = recv(new_socket,buffer,256,0); printf("Полученный хеш: %s\n",buffer); printf("Полученный хеш длина: %i\n",strlen(buffer)); // if (n < 0) // error("ERROR reading from socket"); if (strcmp(ans,buffer) == 0) { printf("Hash ok\n"); n = send(new_socket,"Hello!",255,0); // if (n < 0) // error("ERROR writing to socket"); is_auntentity_ok = 1; } else { printf("Hash not ok\n"); n = send(new_socket,"Hash neveren",255,0); // if (n < 0) // error("ERROR writing to socket"); killclient(); } // } while(is_auntentity_ok != 1); while(1) { memset(buffer,0,256); memset(answer,0,256); n = recv(new_socket,buffer,256,0); // if (n < 0) // error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); char tempbuf[256]; memset(tempbuf,0,256); strncpy_s(tempbuf,buffer,strlen(buffer)-1); printf("%s\n",tempbuf); if(strcmp(tempbuf,"logout") == 0) { printf("logout yes\n"); n = send(new_socket,"Good Buy!",255,0); // if (n < 0) // error("ERROR writing to socket"); char path[256]; memset(path,0,256); closesocket(new_socket); } else if(strcmp(tempbuf,"who") == 0) { printf("who yes\n"); char whomessage[1024]; memset(whomessage,0,1024); chDirectory(arrfields, "/home/anton/workspace/tcpproj", "Anton"); strcpy_s(whomessage,createWhoMessage(arrfields)); n = send(new_socket,whomessage,255,0); // if (n < 0) // error("ERROR writing to socket"); } else { printf("%s\n",buffer); FILE *fp; int status; char path[256]; memset(path,0,256); fp = _popen(buffer, "r"); if (fp == NULL) error("Failed to execute a command in the terminal\n"); char prov[256]; memset(prov,0,256); strncpy_s(prov,buffer,strlen(buffer)-1); if((strcmp(prov,"cd") == 0) || (strcmp(prov,"cd ..") == 0)) { printf("cdok"); strcpy_s(answer,"cdok"); } else { while (fgets(path, 256, fp) != NULL) { printf("%s", path); memset(buffer,0,256); strncpy_s(buffer,path,strlen(path)); strcat_s(answer,buffer); } } n = send(new_socket,answer,strlen(answer),0); // if (n < 0) // error("ERROR writing to socket"); status = _pclose(fp); if (status == -1) { error("Error with executing of command\n"); } } } /* while(1) { clilen = sizeof(struct sockaddr_in); printf("%i\n",clilen); newsockfd = accept(sockfd , (struct sockaddr *)&cli_addr, &clilen); if (newsockfd == INVALID_SOCKET) { printf("accept failed with error code : %d" , WSAGetLastError()); } printf("Est' soedineniye\n"); HANDLE myHandle1 = CreateThread(0, 0, myThread1,&newsockfd, 0, &myThreadID); //CloseHandle(myHandle1); }*/ closesocket(sockfd); WSACleanup(); return 0; }