summaryrefslogtreecommitdiffstats
path: root/lib/libulog/ulog_login.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2010-01-13 18:53:06 +0000
committered <ed@FreeBSD.org>2010-01-13 18:53:06 +0000
commitfee8e21b50dac7cfc13624b364dc2947480b06fd (patch)
treed4c5b51c2df66017f358d1de47d262911d580341 /lib/libulog/ulog_login.c
parent55b15dac03499c76fbd5fe0a6b03c5c19cb02165 (diff)
downloadFreeBSD-src-fee8e21b50dac7cfc13624b364dc2947480b06fd.zip
FreeBSD-src-fee8e21b50dac7cfc13624b364dc2947480b06fd.tar.gz
Remove utmpx stub from libulog.
I'm not increasing the shlib major version for this, because not a single application outside the base system should have used these functions in such a short timespan. Rewrite ulog_login(3) and ulog_logout(3) to build on top of the utmpx implementation in libc.
Diffstat (limited to 'lib/libulog/ulog_login.c')
-rw-r--r--lib/libulog/ulog_login.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/lib/libulog/ulog_login.c b/lib/libulog/ulog_login.c
index 15d607e..3058b9f 100644
--- a/lib/libulog/ulog_login.c
+++ b/lib/libulog/ulog_login.c
@@ -27,49 +27,58 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/param.h>
#include <sys/time.h>
#include <paths.h>
+#include <sha.h>
#include <string.h>
+#include <unistd.h>
+#include <utmpx.h>
+#include "ulog.h"
-#include "ulog_internal.h"
-
-void
-ulog_login(const char *line, const char *user, const char *host)
+static void
+ulog_fill(struct utmpx *utx, const char *line)
{
- struct ulog_utmpx utx;
+ SHA_CTX c;
+ char id[SHA_DIGEST_LENGTH];
/* Remove /dev/ component. */
if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
line += sizeof _PATH_DEV - 1;
- memset(&utx, 0, sizeof utx);
+ memset(utx, 0, sizeof *utx);
+
+ utx->ut_pid = getpid();
+ gettimeofday(&utx->ut_tv, NULL);
+ strncpy(utx->ut_line, line, sizeof utx->ut_line);
+
+ SHA1_Init(&c);
+ SHA1_Update(&c, "libulog", 7);
+ SHA1_Update(&c, utx->ut_line, sizeof utx->ut_line);
+ SHA_Final(id, &c);
+
+ memcpy(utx->ut_id, id, MIN(sizeof utx->ut_id, sizeof id));
+}
+
+void
+ulog_login(const char *line, const char *user, const char *host)
+{
+ struct utmpx utx;
- /* XXX: ut_id, ut_pid missing. */
+ ulog_fill(&utx, line);
utx.ut_type = USER_PROCESS;
- strncpy(utx.ut_line, line, sizeof utx.ut_line);
strncpy(utx.ut_user, user, sizeof utx.ut_user);
if (host != NULL)
strncpy(utx.ut_host, host, sizeof utx.ut_host);
- gettimeofday(&utx.ut_tv, NULL);
-
- ulog_pututxline(&utx);
+ pututxline(&utx);
}
void
ulog_logout(const char *line)
{
- struct ulog_utmpx utx;
+ struct utmpx utx;
- /* Remove /dev/ component. */
- if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
- line += sizeof _PATH_DEV - 1;
-
- memset(&utx, 0, sizeof utx);
-
- /* XXX: ut_id, ut_pid missing. ut_line not needed */
+ ulog_fill(&utx, line);
utx.ut_type = DEAD_PROCESS;
- strncpy(utx.ut_line, line, sizeof utx.ut_line);
- gettimeofday(&utx.ut_tv, NULL);
-
- ulog_pututxline(&utx);
+ pututxline(&utx);
}
OpenPOWER on IntegriCloud