150479Speter/*- 216125Swpaul * SPDX-License-Identifier: BSD-2-Clause 380029Sobrien * 480029Sobrien * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org> 516125Swpaul * All rights reserved. 680029Sobrien * 734130Sbde * Redistribution and use in source and binary forms, with or without 816155Swpaul * modification, are permitted provided that the following conditions 916125Swpaul * are met: 1016125Swpaul * 1. Redistributions of source code must retain the above copyright 1116125Swpaul * notice, this list of conditions and the following disclaimer. 12201390Sed * 2. Redistributions in binary form must reproduce the above copyright 13201390Sed * notice, this list of conditions and the following disclaimer in the 1418050Sbde * documentation and/or other materials provided with the distribution. 1518050Sbde * 1616125Swpaul * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1716125Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1816125Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1980029Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20231118Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2116125Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2216125Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2316125Swpaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2435910Sbde * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2516125Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2616125Swpaul * SUCH DAMAGE. 2716125Swpaul */ 2816125Swpaul 2935910Sbde#include <sys/cdefs.h> 3016125Swpaul#include "ulog.h" 3116125Swpaul#include "utempter.h" 3216125Swpaul 3316125Swpaulstatic int last_fd = -1; 3416125Swpaul 3516125Swpaulint 3616125Swpaulutempter_add_record(int fd, const char *host) 3716125Swpaul{ 38 39 ulog_login_pseudo(fd, host); 40 last_fd = fd; 41 return (0); 42} 43 44int 45utempter_remove_added_record(void) 46{ 47 48 if (last_fd < 0) 49 return (0); 50 ulog_logout_pseudo(last_fd); 51 last_fd = -1; 52 return (0); 53} 54 55int 56utempter_remove_record(int fd) 57{ 58 59 ulog_logout_pseudo(fd); 60 if (last_fd == fd) 61 last_fd = -1; 62 return (0); 63} 64 65void 66addToUtmp(const char *pty __unused, const char *host, int fd) 67{ 68 69 utempter_add_record(fd, host); 70} 71 72void 73removeFromUtmp(void) 74{ 75 76 utempter_remove_added_record(); 77} 78 79void 80removeLineFromUtmp(const char *pty __unused, int fd) 81{ 82 83 utempter_remove_record(fd); 84} 85