Deleted Added
full compact
ulog_login.c (200421) ulog_login.c (202215)
1/*-
2 * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/lib/libulog/ulog_login.c 200421 2009-12-11 23:52:42Z ed $");
28__FBSDID("$FreeBSD: head/lib/libulog/ulog_login.c 202215 2010-01-13 18:53:06Z ed $");
29
29
30#include <sys/param.h>
30#include <sys/time.h>
31#include <paths.h>
31#include <sys/time.h>
32#include <paths.h>
33#include <sha.h>
32#include <string.h>
34#include <string.h>
35#include <unistd.h>
36#include <utmpx.h>
37#include "ulog.h"
33
38
34#include "ulog_internal.h"
35
36void
37ulog_login(const char *line, const char *user, const char *host)
39static void
40ulog_fill(struct utmpx *utx, const char *line)
38{
41{
39 struct ulog_utmpx utx;
42 SHA_CTX c;
43 char id[SHA_DIGEST_LENGTH];
40
41 /* Remove /dev/ component. */
42 if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
43 line += sizeof _PATH_DEV - 1;
44
44
45 /* Remove /dev/ component. */
46 if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
47 line += sizeof _PATH_DEV - 1;
48
45 memset(&utx, 0, sizeof utx);
49 memset(utx, 0, sizeof *utx);
46
50
47 /* XXX: ut_id, ut_pid missing. */
51 utx->ut_pid = getpid();
52 gettimeofday(&utx->ut_tv, NULL);
53 strncpy(utx->ut_line, line, sizeof utx->ut_line);
54
55 SHA1_Init(&c);
56 SHA1_Update(&c, "libulog", 7);
57 SHA1_Update(&c, utx->ut_line, sizeof utx->ut_line);
58 SHA_Final(id, &c);
59
60 memcpy(utx->ut_id, id, MIN(sizeof utx->ut_id, sizeof id));
61}
62
63void
64ulog_login(const char *line, const char *user, const char *host)
65{
66 struct utmpx utx;
67
68 ulog_fill(&utx, line);
48 utx.ut_type = USER_PROCESS;
69 utx.ut_type = USER_PROCESS;
49 strncpy(utx.ut_line, line, sizeof utx.ut_line);
50 strncpy(utx.ut_user, user, sizeof utx.ut_user);
51 if (host != NULL)
52 strncpy(utx.ut_host, host, sizeof utx.ut_host);
70 strncpy(utx.ut_user, user, sizeof utx.ut_user);
71 if (host != NULL)
72 strncpy(utx.ut_host, host, sizeof utx.ut_host);
53 gettimeofday(&utx.ut_tv, NULL);
54
55 ulog_pututxline(&utx);
73 pututxline(&utx);
56}
57
58void
59ulog_logout(const char *line)
60{
74}
75
76void
77ulog_logout(const char *line)
78{
61 struct ulog_utmpx utx;
79 struct utmpx utx;
62
80
63 /* Remove /dev/ component. */
64 if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
65 line += sizeof _PATH_DEV - 1;
66
67 memset(&utx, 0, sizeof utx);
68
69 /* XXX: ut_id, ut_pid missing. ut_line not needed */
81 ulog_fill(&utx, line);
70 utx.ut_type = DEAD_PROCESS;
82 utx.ut_type = DEAD_PROCESS;
71 strncpy(utx.ut_line, line, sizeof utx.ut_line);
72 gettimeofday(&utx.ut_tv, NULL);
73
74 ulog_pututxline(&utx);
83 pututxline(&utx);
75}
84}