1200185Sed/*-
2200185Sed * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org>
3200185Sed * All rights reserved.
4200185Sed *
5200185Sed * Redistribution and use in source and binary forms, with or without
6200185Sed * modification, are permitted provided that the following conditions
7200185Sed * are met:
8200185Sed * 1. Redistributions of source code must retain the above copyright
9200185Sed *    notice, this list of conditions and the following disclaimer.
10200185Sed * 2. Redistributions in binary form must reproduce the above copyright
11200185Sed *    notice, this list of conditions and the following disclaimer in the
12200185Sed *    documentation and/or other materials provided with the distribution.
13200185Sed *
14200185Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15200185Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16200185Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17200185Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18200185Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19200185Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20200185Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21200185Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22200185Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23200185Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24200185Sed * SUCH DAMAGE.
25200185Sed */
26200185Sed
27200185Sed#include <sys/cdefs.h>
28200185Sed__FBSDID("$FreeBSD$");
29200185Sed
30202215Sed#include "ulog.h"
31200185Sed#include "utempter.h"
32200185Sed
33200185Sedstatic int last_fd = -1;
34200185Sed
35200185Sedint
36200185Sedutempter_add_record(int fd, const char *host)
37200185Sed{
38200185Sed
39200185Sed	ulog_login_pseudo(fd, host);
40200185Sed	last_fd = fd;
41200185Sed	return (0);
42200185Sed}
43200185Sed
44200185Sedint
45200185Sedutempter_remove_added_record(void)
46200185Sed{
47200185Sed
48200185Sed	if (last_fd < 0)
49200185Sed		return (0);
50200185Sed	ulog_logout_pseudo(last_fd);
51200185Sed	last_fd = -1;
52200185Sed	return (0);
53200185Sed}
54200185Sed
55200185Sedint
56200185Sedutempter_remove_record(int fd)
57200185Sed{
58200185Sed
59200185Sed	ulog_logout_pseudo(fd);
60200185Sed	if (last_fd == fd)
61200185Sed		last_fd = -1;
62200185Sed	return (0);
63200185Sed}
64200185Sed
65200185Sedvoid
66200185SedaddToUtmp(const char *pty __unused, const char *host, int fd)
67200185Sed{
68200185Sed
69200185Sed	utempter_add_record(fd, host);
70200185Sed}
71200185Sed
72200185Sedvoid
73200185SedremoveFromUtmp(void)
74200185Sed{
75200185Sed
76200185Sed	utempter_remove_added_record();
77200185Sed}
78200185Sed
79200185Sedvoid
80200185SedremoveLineFromUtmp(const char *pty __unused, int fd)
81200185Sed{
82200185Sed
83200185Sed	utempter_remove_record(fd);
84200185Sed}
85