Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- int main() {
- int fd[2];
- if(pipe(fd) == -1) {
- perror("Pipe failed");
- return 1;
- }
- int id;
- char password[256];
- if (fork() == 0) {
- dup2(fd[0],STDIN_FILENO);
- dup2(fd[0],STDIN_FILENO);
- dup2(fd[1],STDOUT_FILENO);
- execlp("./validate", "./validate", (char*)NULL);
- perror("Exec error!");
- exit(0);
- } else {
- printf("Introduza o ID do User: ");
- scanf("%d", &id);
- getchar();
- printf("Introduza a Password: ");
- fgets(password, 255, stdin);
- close(fd[0]);
- write(fd[1], &id, sizeof(int));
- write(fd[1], password, sizeof(password));
- int status;
- wait(&status);
- status = WEXITSTATUS(status);
- if (status == 3) {
- printf("No such user\n");
- } else if (status == 2) {
- printf("Invalid password\n");
- } else if (status == 1) {
- printf("Password verified\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement