/*
 *  Copyright (C) 2015 - Preacher
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

void get_passwd(char *ptr);

int main(void)
{
	char *input = malloc(28);
	char *passwd = malloc(28);

	get_passwd(passwd);

	puts("Password: ");
	gets(input);

	if(!strcmp(input, passwd))
	{
		puts("Win!");
		return 0;
	}

	puts("Nop");

	return -1;
}

void get_passwd(char *ptr)
{
	int fd = 0;

	if((fd = open("id", O_RDONLY)) < 0)
	{
		perror("open");
		exit(-1);
	}

	if(read(fd, ptr, 20) != 20)
	{
		perror("read");
		close(fd);
		exit(-1);
	}

	close(fd);
}

