ulog_login.c revision 200153
1200062Sed/*- 2200062Sed * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org> 3200062Sed * All rights reserved. 4200062Sed * 5200062Sed * Redistribution and use in source and binary forms, with or without 6200062Sed * modification, are permitted provided that the following conditions 7200062Sed * are met: 8200062Sed * 1. Redistributions of source code must retain the above copyright 9200062Sed * notice, this list of conditions and the following disclaimer. 10200062Sed * 2. Redistributions in binary form must reproduce the above copyright 11200062Sed * notice, this list of conditions and the following disclaimer in the 12200062Sed * documentation and/or other materials provided with the distribution. 13200062Sed * 14200062Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15200062Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16200062Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17200062Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18200062Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19200062Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20200062Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21200062Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22200062Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23200062Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24200062Sed * SUCH DAMAGE. 25200062Sed */ 26200062Sed 27200062Sed#include <sys/cdefs.h> 28200062Sed__FBSDID("$FreeBSD: head/lib/libulog/ulog_login.c 200153 2009-12-05 19:53:29Z ed $"); 29200062Sed 30200153Sed#include <sys/time.h> 31200062Sed#include <paths.h> 32200062Sed#include <string.h> 33200062Sed 34200062Sed#include "ulog_internal.h" 35200062Sed 36200062Sedvoid 37200062Sedulog_login(const char *line, const char *user, const char *host) 38200062Sed{ 39200153Sed struct ulog_utmpx utx; 40200062Sed 41200062Sed /* Remove /dev/ component. */ 42200062Sed if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0) 43200062Sed line += sizeof _PATH_DEV - 1; 44200062Sed 45200153Sed memset(&utx, 0, sizeof utx); 46200062Sed 47200153Sed /* XXX: ut_id, ut_pid missing. */ 48200153Sed utx.ut_type = USER_PROCESS; 49200153Sed strncpy(utx.ut_line, line, sizeof utx.ut_line); 50200153Sed strncpy(utx.ut_user, user, sizeof utx.ut_user); 51200153Sed strncpy(utx.ut_host, host, sizeof utx.ut_host); 52200153Sed gettimeofday(&utx.ut_tv, NULL); 53200062Sed 54200153Sed ulog_pututxline(&utx); 55200062Sed} 56200062Sed 57200062Sedvoid 58200062Sedulog_logout(const char *line) 59200062Sed{ 60200153Sed struct ulog_utmpx utx; 61200062Sed 62200062Sed /* Remove /dev/ component. */ 63200062Sed if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0) 64200062Sed line += sizeof _PATH_DEV - 1; 65200062Sed 66200153Sed memset(&utx, 0, sizeof utx); 67200062Sed 68200153Sed /* XXX: ut_id, ut_pid missing. ut_line not needed */ 69200153Sed utx.ut_type = DEAD_PROCESS; 70200153Sed strncpy(utx.ut_line, line, sizeof utx.ut_line); 71200153Sed gettimeofday(&utx.ut_tv, NULL); 72200153Sed 73200153Sed ulog_pututxline(&utx); 74200062Sed} 75