From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/611 Path: news.gmane.org!not-for-mail From: finkler Newsgroups: gmane.linux.lib.musl.general Subject: Re: utmpx support Date: Sun, 04 Mar 2012 20:10:36 +0100 Message-ID: References: <20120304181808.GU184@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090603050002020005020408" X-Trace: dough.gmane.org 1330888265 19429 80.91.229.3 (4 Mar 2012 19:11:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 4 Mar 2012 19:11:05 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-612-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 04 20:11:03 2012 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 1S4Gpi-0005KW-Cg for gllmg-musl@plane.gmane.org; Sun, 04 Mar 2012 20:11:02 +0100 Original-Received: (qmail 14124 invoked by uid 550); 4 Mar 2012 19:11:02 -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 14116 invoked from network); 4 Mar 2012 19:11:02 -0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 138 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: wrzb-4d005420.pool.mediaways.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: <20120304181808.GU184@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:611 Archived-At: This is a multi-part message in MIME format. --------------090603050002020005020408 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------090603050002020005020408 Content-Type: text/plain; name="utmpx.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="utmpx.c" #include #include #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); --------------090603050002020005020408--