ulog_login.c revision 200421
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 200421 2009-12-11 23:52:42Z 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);
51200421Sed	if (host != NULL)
52200421Sed		strncpy(utx.ut_host, host, sizeof utx.ut_host);
53200153Sed	gettimeofday(&utx.ut_tv, NULL);
54200062Sed
55200153Sed	ulog_pututxline(&utx);
56200062Sed}
57200062Sed
58200062Sedvoid
59200062Sedulog_logout(const char *line)
60200062Sed{
61200153Sed	struct ulog_utmpx utx;
62200062Sed
63200062Sed	/* Remove /dev/ component. */
64200062Sed	if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
65200062Sed		line += sizeof _PATH_DEV - 1;
66200062Sed
67200153Sed	memset(&utx, 0, sizeof utx);
68200062Sed
69200153Sed	/* XXX: ut_id, ut_pid missing. ut_line not needed */
70200153Sed	utx.ut_type = DEAD_PROCESS;
71200153Sed	strncpy(utx.ut_line, line, sizeof utx.ut_line);
72200153Sed	gettimeofday(&utx.ut_tv, NULL);
73200153Sed
74200153Sed	ulog_pututxline(&utx);
75200062Sed}
76