From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13624 Path: news.gmane.org!.POSTED!not-for-mail From: Markus Wichmann Newsgroups: gmane.linux.lib.musl.general Subject: Re: function: fgetspent_r Date: Sun, 20 Jan 2019 16:41:54 +0100 Message-ID: <20190120154154.GA23924@voyager> References: <4ac5ac1b-217f-442f-fc35-bfbf015287bb@adelielinux.org> <20190116205046.GK23599@brightrain.aerifal.cx> <20190116234410.GL23599@brightrain.aerifal.cx> <20190117053147.GH29911@voyager> <20190117153830.GN23599@brightrain.aerifal.cx> <20190118203725.GI29911@voyager> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: ciao.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="h31gzZEtNLTqOjlF" X-Trace: ciao.gmane.org 1547998969 92967 195.159.176.228 (20 Jan 2019 15:42:49 GMT) X-Complaints-To: usenet@ciao.gmane.org NNTP-Posting-Date: Sun, 20 Jan 2019 15:42:49 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) To: musl@lists.openwall.com Original-X-From: musl-return-13640-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jan 20 16:42:47 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by ciao.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1glFFB-000OAb-Hs for gllmg-musl@m.gmane.org; Sun, 20 Jan 2019 16:42:41 +0100 Original-Received: (qmail 5298 invoked by uid 550); 20 Jan 2019 15:42:46 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 5272 invoked from network); 20 Jan 2019 15:42:46 -0000 Content-Disposition: inline In-Reply-To: <20190118203725.GI29911@voyager> X-Provags-ID: V03:K1:6LGl6lfUwraj5je3JoL7i/6vMhZpq/czWfCjh8/CjhAQZfs5Dmv GvN2ukD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13624 Archived-At: --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, so, I wrote a version of fgetspent_r() now. I based it on fgetspent(). For style, I adopted the Linux style -- might need to refactor that. Returning EILSEQ on format error is a hack, but I found no better code. As I said, glibc loops on error, but we do that for no other src/passwd function, so we should either not start now or add that feature to every other function. One thing I noticed: If AccountService requires this interfaces, is it possible that it doesn't support TCB shadow files? Ciao, Markus --h31gzZEtNLTqOjlF Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0005-Add-fgetspent_r.patch" >From 3489f9e5ef055c80464252fe640fead8aeb1068e Mon Sep 17 00:00:00 2001 From: Markus Wichmann Date: Sun, 20 Jan 2019 16:31:34 +0100 Subject: [PATCH 5/5] Add fgetspent_r(). Interface was defined by glibc, and seems to have been adopted by Solaris. Some freedesktop software appears to require it, and it adds little bloat. Added without feature test macros, since no other interface in shadow.h requires it, even the ones documented to have required it in the past. --- include/shadow.h | 1 + src/passwd/fgetspent_r.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/passwd/fgetspent_r.c diff --git a/include/shadow.h b/include/shadow.h index 2b1be413..4edc90db 100644 --- a/include/shadow.h +++ b/include/shadow.h @@ -33,6 +33,7 @@ int putspent(const struct spwd *, FILE *); struct spwd *getspnam(const char *); int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **); +int fgetspent_r(FILE *f, struct spwd* sp, char *line, size_t size, struct spwd **spret); int lckpwdf(void); int ulckpwdf(void); diff --git a/src/passwd/fgetspent_r.c b/src/passwd/fgetspent_r.c new file mode 100644 index 00000000..643637de --- /dev/null +++ b/src/passwd/fgetspent_r.c @@ -0,0 +1,27 @@ +#include "pwf.h" +#include +#include +#include + +int fgetspent_r(FILE *f, struct spwd* sp, char *line, size_t size, struct spwd **spret) +{ + int res = 0; + int cs; + *spret = 0; + if (size > INT_MAX) + size = INT_MAX; //2GB ought to be enough for anyone + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + if (!fgets(line, size, f)) + goto out; + res = ERANGE; + if (line[strlen(line) - 1] != '\n') + goto out; + res = EILSEQ; + if ( __parsespent(line, sp) < 0) + goto out; + *spret = sp; + res = 0; +out: + pthread_setcancelstate(cs, 0); + return res; +} -- 2.19.1 --h31gzZEtNLTqOjlF--