mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: <shadow.h> function: fgetspent_r
Date: Sun, 20 Jan 2019 16:41:54 +0100	[thread overview]
Message-ID: <20190120154154.GA23924@voyager> (raw)
In-Reply-To: <20190118203725.GI29911@voyager>

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

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

[-- Attachment #2: 0005-Add-fgetspent_r.patch --]
[-- Type: text/x-diff, Size: 1887 bytes --]

From 3489f9e5ef055c80464252fe640fead8aeb1068e Mon Sep 17 00:00:00 2001
From: Markus Wichmann <nullplan@gmx.net>
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 <pthread.h>
+#include <limits.h>
+#include <stdio.h>
+
+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


  reply	other threads:[~2019-01-20 15:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 19:21 A. Wilcox
2019-01-16 20:50 ` Rich Felker
2019-01-16 21:38   ` A. Wilcox
2019-01-16 23:44     ` Rich Felker
2019-01-17  5:31       ` Markus Wichmann
2019-01-17 15:38         ` Rich Felker
2019-01-18 20:37           ` Markus Wichmann
2019-01-20 15:41             ` Markus Wichmann [this message]
2019-01-20 21:12               ` A. Wilcox
2019-01-21  0:50                 ` Rich Felker
2019-01-20 22:02               ` A. Wilcox

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=20190120154154.GA23924@voyager \
    --to=nullplan@gmx.net \
    --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).