/*
 * utmpwatcher.c
 *
 * Copyright (C) 2006 Red Hat 
 * see file 'COPYING' for use and warranty information
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA     
 * 02111-1307  USA
 *
 * Authors:  
 *   Dan Walsh <dwalsh@redhat.com>
 *
 *
*/

#define _GNU_SOURCE
#include <sys/inotify.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>

#include <limits.h>
#include <utmp.h>
#include <sys/types.h>
#include <pwd.h>
#include "restorecond.h"
#include "utmpwatcher.h"
#include "stringslist.h"

static struct stringsList *utmp_ptr = NULL;
static int utmp_wd = -1;

unsigned int utmpwatcher_handle(int inotify_fd, int wd)
{
	int changed = 0;
	struct utmp u;
	const char *utmp_path = "/run/utmp";
	struct stringsList *prev_utmp_ptr = utmp_ptr;
	if (wd != utmp_wd)
		return -1;

	utmp_ptr = NULL;
	FILE *cfg = fopen(utmp_path, "r");
	if (!cfg)
		exitApp("Error reading utmp file.");

	while (fread(&u, sizeof(struct utmp), 1, cfg) > 0) {
		if (u.ut_type == USER_PROCESS)
			strings_list_add(&utmp_ptr, u.ut_user);
	}
	fclose(cfg);
	if (utmp_wd >= 0)
		inotify_rm_watch(inotify_fd, utmp_wd);

	utmp_wd =
	    inotify_add_watch(inotify_fd, utmp_path, IN_MOVED_FROM | IN_MODIFY);
	if (utmp_wd == -1)
		exitApp("Error watching utmp file.");

	changed = strings_list_diff(prev_utmp_ptr, utmp_ptr);
	if (prev_utmp_ptr) {
		strings_list_free(prev_utmp_ptr);
	}
	return changed;
}

static void watch_file(int inotify_fd, const char *file)
{
	struct stringsList *ptr = utmp_ptr;

	while (ptr) {
		struct passwd *pwd = getpwnam(ptr->string);
		if (pwd) {
			char *path = NULL;
			if (asprintf(&path, "%s%s", pwd->pw_dir, file) < 0)
				exitApp("Error allocating memory.");
			watch_list_add(inotify_fd, path);
			free(path);
		}
		ptr = ptr->next;
	}
}

void utmpwatcher_add(int inotify_fd, const char *path)
{
	if (utmp_ptr == NULL) {
		utmpwatcher_handle(inotify_fd, utmp_wd);
	}
	watch_file(inotify_fd, path);
}

void utmpwatcher_free(void)
{
	if (utmp_ptr)
		strings_list_free(utmp_ptr);
}

#ifdef TEST
int main(int argc, char **argv)
{
	read_utmp();
	return 0;
}
#endif
