From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4361 Path: news.gmane.org!not-for-mail From: Raphael Cohn Newsgroups: gmane.linux.lib.musl.general Subject: Patch to musl to provide wtmp for Linux PAM Date: Wed, 4 Dec 2013 14:49:32 +0000 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e013d08c462d1c104ecb6853f X-Trace: ger.gmane.org 1386168580 26933 80.91.229.3 (4 Dec 2013 14:49:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 4 Dec 2013 14:49:40 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4365-gllmg-musl=m.gmane.org@lists.openwall.com Wed Dec 04 15:49:46 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1VoDlp-0000fN-VI for gllmg-musl@plane.gmane.org; Wed, 04 Dec 2013 15:49:46 +0100 Original-Received: (qmail 5314 invoked by uid 550); 4 Dec 2013 14:49:45 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5306 invoked from network); 4 Dec 2013 14:49:45 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=P4USkuorYgHGUbDcsAv8/KaZk/3IBEXBBRTMxLSTZMA=; b=TQUwWQkZQjqVSojOI+vib5WkjY9S2r5gUnd1ZTElF8/qSDcUNtnIfgRIA5UwlNRgeH Nf+tO1IGYGF5/dsZruq00NCwHSkHk3apqqCux2uolS5DOpJl+hFLsZxwIPibk4yPdixU wb1Y1Eaj/h9otvzaqPDtVF1lOCyJ3xQKLU/onfoTvpHdJYJr6+k63uSyaHdjugnomrsv sIXXoxFRWjPS9R2wSyV7d+RQh6+XFsLi0flRUJEHoUplN6mvKaAhv4vYEjFNF+ZovlwJ 0YvGLFA1QjWjBkUf7emToSyqXmrXfzN/7uOMs8k5nm3nfOqnRYIJLBB7XSRAUNPQw4O8 Kneg== X-Gm-Message-State: ALoCoQmesvCTmqqt5KoCYGhXlrewAz6oNhGEypRjA3TqfXyXH2ESBBddlPmGLBf9oEf/YuH2gR8W X-Received: by 10.60.16.97 with SMTP id f1mr940169oed.77.1386168572856; Wed, 04 Dec 2013 06:49:32 -0800 (PST) X-Originating-IP: [2001:8b0:862:b944:5e8:bd81:6ce5:582e] Xref: news.gmane.org gmane.linux.lib.musl.general:4361 Archived-At: --089e013d08c462d1c104ecb6853f Content-Type: text/plain; charset=UTF-8 I've drafted a patch for musl which I'm using to get Linux-PAM to compile. This patch:- - defines _PATH_LASTLOG; - uses macros in the utmpx struct for documentary value; - adds an implementation of logwtmp - alters _PATH_*TMP It's probably not suitable for inclusion in musl mainline as it stands (especially the last part) - but hopefully it'll be useful to others. It's also quick and dirty, and so may be just plain wrong. By the way, are there any plans to support writing to lastlog / wtmp / etc? If not, I might create a private patch to redirect the writes to syslog. In my view, this is where information like this belongs... diff -N -u -r musl-0.9.14.orig/include/utmp.h musl-0.9.14/include/utmp.h --- musl-0.9.14.orig/include/utmp.h 2013-09-23 22:01:11.000000000 +0100 +++ musl-0.9.14/include/utmp.h 2013-12-04 10:34:43.000000000 +0000 @@ -7,10 +7,6 @@ #include -#define ACCOUNTING 9 -#define UT_NAMESIZE 32 -#define UT_HOSTSIZE 256 - struct lastlog { time_t ll_time; char ll_line[UT_LINESIZE]; @@ -32,8 +28,11 @@ void updwtmp(const char *, const struct utmp *); -#define _PATH_UTMP "/dev/null/utmp" -#define _PATH_WTMP "/dev/null/wtmp" +void logwtmp(const char *, const char *, const char *); + +#define _PATH_UTMP "/var/run/utmp" +#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_LASTLOG "/var/log/lastlog" #define UTMP_FILE _PATH_UTMP #define WTMP_FILE _PATH_WTMP diff -N -u -r musl-0.9.14.orig/include/utmpx.h musl-0.9.14/include/utmpx.h --- musl-0.9.14.orig/include/utmpx.h 2013-09-23 22:01:11.000000000 +0100 +++ musl-0.9.14/include/utmpx.h 2013-12-04 10:32:20.000000000 +0000 @@ -13,6 +13,8 @@ #include #define UT_LINESIZE 32 +#define UT_NAMESIZE 32 +#define UT_HOSTSIZE 256 struct utmpx { @@ -20,8 +22,8 @@ pid_t ut_pid; char ut_line[UT_LINESIZE]; char ut_id[4]; - char ut_user[32]; - char ut_host[256]; + char ut_user[UT_NAMESIZE]; + char ut_host[UT_HOSTSIZE]; struct { short e_termination; short e_exit; @@ -50,6 +52,7 @@ #define LOGIN_PROCESS 6 #define USER_PROCESS 7 #define DEAD_PROCESS 8 +#define ACCOUNTING 9 #ifdef __cplusplus } diff -N -u -r musl-0.9.14.orig/src/legacy/utmp.c musl-0.9.14/src/legacy/utmp.c --- musl-0.9.14.orig/src/legacy/utmp.c 1970-01-01 01:00:00.000000000 +0100 +++ musl-0.9.14/src/legacy/utmp.c 2013-12-04 14:25:40.000000000 +0000 @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include "libc.h" + +void logwtmp(const char * line, const char * name, const char * host) +{ + struct utmp u; + memset(&u, 0, sizeof(u)); + + u.ut_pid = getpid(); + u.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS; + strncpy(u.ut_line, line, sizeof(u.ut_line)); + strncpy(u.ut_name, name, sizeof(u.ut_name)); + strncpy(u.ut_host, host, sizeof(u.ut_host)); + gettimeofday(&(u.ut_tv), NULL); + + updwtmp(_PATH_WTMP, &u); +} Raph --089e013d08c462d1c104ecb6853f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I've drafted a patc= h for musl which I'm using to get Linux-PAM to compile.

Th= is patch:-
- defines _PATH_LASTLOG;
- uses macros in the = utmpx struct for documentary value;
- adds an implementation of logwtmp
- alters _PATH_*TMP
<= br>
It's probably not suitable for inclusion in musl mainline as i= t stands (especially the last part) - but hopefully it'll be useful to = others. It's also quick and dirty, and so may be just plain wrong.

By the way, are there any plans to support writing to lastlog / w= tmp / etc? If not, I might create a private patch to redirect the writes to= syslog. In my view, this is where information like this belongs...

diff -N -u -r musl-0.9.14.orig/= include/utmp.h musl-0.9.14/include/utmp.h
--- musl-0.9.14.orig/include/u= tmp.h=C2=A0=C2=A0=C2=A0 2013-09-23 22:01:11.000000000 +0100
+++ musl-0.9= .14/include/utmp.h=C2=A0=C2=A0=C2=A0 2013-12-04 10:34:43.000000000 +0000 @@ -7,10 +7,6 @@

=C2=A0#include <utmpx.h>

-#define ACCO= UNTING 9
-#define UT_NAMESIZE 32
-#define UT_HOSTSIZE 256
-
=C2= =A0struct lastlog {
=C2=A0=C2=A0=C2=A0=C2=A0 time_t ll_time;
=C2=A0= =C2=A0=C2=A0=C2=A0 char ll_line[UT_LINESIZE];
@@ -32,8 +28,11 @@

=C2=A0void updwtmp(const char *, const struct utm= p *);

-#define _PATH_UTMP "/dev/null/utmp"
-#define _PA= TH_WTMP "/dev/null/wtmp"
+void logwtmp(const char *, const cha= r *, const char *);
+
+#define _PATH_UTMP "/var/run/utmp"
+#define _PATH_WTMP &= quot;/var/log/wtmp"
+#define _PATH_LASTLOG "/var/log/lastlog&q= uot;

=C2=A0#define UTMP_FILE _PATH_UTMP
=C2=A0#define WTMP_FILE _= PATH_WTMP
diff -N -u -r musl-0.9.14.orig/include/utmpx.h musl-0.9.14/include/utmpx.h<= br>--- musl-0.9.14.orig/include/utmpx.h=C2=A0=C2=A0=C2=A0 2013-09-23 22:01:= 11.000000000 +0100
+++ musl-0.9.14/include/utmpx.h=C2=A0=C2=A0=C2=A0 201= 3-12-04 10:32:20.000000000 +0000
@@ -13,6 +13,8 @@
=C2=A0#include <bits/alltypes.h>

=C2=A0#d= efine UT_LINESIZE 32
+#define UT_NAMESIZE 32
+#define UT_HOSTSIZE 256=

=C2=A0struct utmpx
=C2=A0{
@@ -20,8 +22,8 @@
=C2=A0=C2=A0= =C2=A0=C2=A0 pid_t ut_pid;
=C2=A0=C2=A0=C2=A0=C2=A0 char ut_line[UT_LINE= SIZE];
=C2=A0=C2=A0=C2=A0=C2=A0 char ut_id[4];
-=C2=A0=C2=A0=C2=A0 char ut_user= [32];
-=C2=A0=C2=A0=C2=A0 char ut_host[256];
+=C2=A0=C2=A0=C2=A0 char= ut_user[UT_NAMESIZE];
+=C2=A0=C2=A0=C2=A0 char ut_host[UT_HOSTSIZE];=C2=A0=C2=A0=C2=A0=C2=A0 struct {
=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0 short e_termination;
=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 = short e_exit;
@@ -50,6 +52,7 @@
=C2=A0#define LOGIN_PROCESS=C2=A0=C2=A0 6
=C2=A0#de= fine USER_PROCESS=C2=A0=C2=A0=C2=A0 7
=C2=A0#define DEAD_PROCESS=C2=A0= =C2=A0=C2=A0 8
+#define ACCOUNTING=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 9
=C2=A0#ifdef __cplusplus
=C2=A0}
diff -N -u -r musl-0.9.14.orig/src= /legacy/utmp.c musl-0.9.14/src/legacy/utmp.c
--- musl-0.9.14.orig/src/legacy/utmp.c=C2=A0=C2=A0=C2=A0 1970-01-01 01:00:0= 0.000000000 +0100
+++ musl-0.9.14/src/legacy/utmp.c=C2=A0=C2=A0=C2=A0 20= 13-12-04 14:25:40.000000000 +0000
@@ -0,0 +1,20 @@
+#include <utmp= .h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include &qu= ot;libc.h"
+
+void logwtmp(const char * line, const char * name,= const char * host)
+{
+=C2=A0=C2=A0=C2=A0 struct utmp u;
+=C2=A0= =C2=A0=C2=A0 memset(&u, 0, sizeof(u));
+=C2=A0=C2=A0=C2=A0
+=C2=A0=C2=A0=C2=A0 u.ut_pid =3D getpid();
+=C2= =A0=C2=A0=C2=A0 u.ut_type =3D name[0] ? USER_PROCESS : DEAD_PROCESS;
+= =C2=A0=C2=A0=C2=A0 strncpy(u.ut_line, line, sizeof(u.ut_line));
+=C2=A0= =C2=A0=C2=A0 strncpy(u.ut_name, name, sizeof(u.ut_name));
+=C2=A0=C2=A0= =C2=A0 strncpy(u.ut_host, host, sizeof(u.ut_host));
+=C2=A0=C2=A0=C2=A0 gettimeofday(&(u.ut_tv), NULL);
+=C2=A0=C2=A0=C2= =A0
+=C2=A0=C2=A0=C2=A0 updwtmp(_PATH_WTMP, &u);
+}

Raph
--089e013d08c462d1c104ecb6853f--