From: finkler <finkler@officinamentis.org>
To: musl@lists.openwall.com
Subject: Re: utmpx support
Date: Sun, 04 Mar 2012 20:10:36 +0100 [thread overview]
Message-ID: <jj0end$ioj$1@dough.gmane.org> (raw)
In-Reply-To: <20120304181808.GU184@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 1411 bytes --]
On 04.03.2012 19:18, Rich Felker wrote:
> On Sun, Mar 04, 2012 at 06:41:25PM +0100, finkler wrote:
>
> It's intentional, but if you have a real need for utmp support, I'd be
> willing to hear about it.
Well, I am currently trying to implement new (POSIX) user-space
utilities for Linux, including my own init/login system.
I thought quite a bit about the purpose of utmp(x) myself I admit,
however, I came to the conclusion that even though I know no one who
still uses serial terminals to connect to a machine, connecting through
LAN/Internet is very popular, and it couldn't hurt that an administrator
has the means to easily see who is currently logged in (who).
I agree that utmpx has grown disproportionally and has lots of misuses
which just bloat the code.
But as I said, some method of accessing login information seems sane to
me. And if used with restrain utmpx is quite well suited for this ... I
think.
> Perhaps a better approach would be making a separate small static
> libutmp.a that could be linked by people wanting real utmp support as
> opposed to the stubs.
Certainly, for what it's worth, I hacked up an utmpx implementation.
I hope I didn't make any mistakes (code and standard wise), but the code
size is small, so it should be easily verifiable for another set of eyes
:-).
Regards, and thank you very much for the good work with this lib, it is
really great.
Finkler
[-- Attachment #2: utmpx.c --]
[-- Type: text/plain, Size: 1774 bytes --]
#include <utmpx.h>
#include <stddef.h>
#include "libc.h"
#define _PATH_UTMPX "/etc/utmp"
static FILE *f;
static struct utmpx ut;
void endutxent(void)
{
memset(&ut, 0, sizeof ut);
if (f == NULL) return;
fclose(f);
f == NULL;
}
void setutxent(void)
{
memset(&ut, 0, sizeof ut);
if (f == NULL) return;
rewind(f);
}
struct utmpx *getutxent(void)
{
if (f == NULL) {
f = fopen(_PATH_UTMPX, "a+");
if (f == NULL) {
f = fopen(_PATH_UTMPX, "r");
if (f == NULL) return NULL;
}
}
if (fread(&ut, sizeof ut, 1, f)) return &ut;
return NULL;
}
struct utmpx *getutxid(const struct utmpx *id)
{
while(getutxent()) {
switch (id->ut_type) {
case BOOT_TIME:
case OLD_TIME:
case NEW_TIME:
if (id->ut_type == ut.ut_type) return &ut;
break;
case INIT_PROCESS:
case LOGIN_PROCESS:
case USER_PROCESS:
case DEAD_PROCESS:
if (id->type == ut.ut_type && !strcmp(id->ut_id, ut.ut_id)) return &ut;
break;
}
}
return NULL;
}
struct utmpx *getutxline(const struct utmpx *line)
{
while(getutxent()) {
switch (ut.ut_type) {
case LOGIN_PROCESS:
case USER_PROCESS:
if (!strcmp(line->ut_line, ut.ut_line)) return &ut;
break;
}
}
return NULL;
}
struct utmpx *pututxline(const struct utmpx *utmpx)
{
setutxent();
if (getutxid(utmpx)) fseek(f, -(sizeof ut), SEEK_CUR);
if (fwrite(&ut, sizeof ut, 1, f)) return &ut;
return NULL;
}
void updwtmpx(const char *f, const struct utmpx *u)
{
}
weak_alias(endutxent, endutent);
weak_alias(setutxent, setutent);
weak_alias(getutxent, getutent);
weak_alias(getutxid, getutid);
weak_alias(getutxline, getutline);
weak_alias(pututxline, pututline);
weak_alias(updwtmpx, updwtmp);
next prev parent reply other threads:[~2012-03-04 19:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-04 17:41 finkler
2012-03-04 18:18 ` Rich Felker
2012-03-04 19:10 ` finkler [this message]
2012-03-06 1:30 ` Rich Felker
2012-03-16 14:05 ` finkler
2012-03-06 1:39 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='jj0end$ioj$1@dough.gmane.org' \
--to=finkler@officinamentis.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).