mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Leah Neukirchen <leah@vuxu.org>
Cc: Collin Funk <collin.funk1@gmail.com>, musl@lists.openwall.com
Subject: Re: [musl] getusershell should ignore comments and empty lines.
Date: Thu, 23 May 2024 11:27:33 -0400	[thread overview]
Message-ID: <20240523152733.GB10433@brightrain.aerifal.cx> (raw)
In-Reply-To: <20240523144744.GA10433@brightrain.aerifal.cx>

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

On Thu, May 23, 2024 at 10:47:44AM -0400, Rich Felker wrote:
> On Thu, May 23, 2024 at 03:45:10PM +0200, Leah Neukirchen wrote:
> > Rich Felker <dalias@libc.org> writes:
> > 
> > > It says:
> > >
> > >     "A hash mark (``#'') indicates the beginning of a comment;
> > >     subsequent characters up to the end of the line are not
> > >     interpreted by the routines which search the file."
> > >
> > > This isn't very clear whether # is only a comment on the beginning of
> > > a line (after potential whitespace?) or whether # appearing in a line
> > > with a shell pathname is a comment or part of the pathname. If it's a
> > > comment, it's not clear if whitespace before it is part of the shell
> > > pathname -- e.g. does "/bin/sh # best shell" define "/bin/sh" or
> > > "/bin/sh " as the shell pathname?
> > >
> > > It sounds like nobody ever thought about whitespace, quoting, or
> > > rigorous comment syntax here...
> > 
> > True:
> > 
> > OpenBSD drops the rest of the line with "#" and ignores lines not
> > starting with a "/".
> > 
> > glibc drops the rest of the line with "#", elides spaces after the
> > entry, and skips everything before the first "/" (quite bold).
> > 
> > pam_shells skips all lines that don't start with a "/" and doesn't
> > handle "#" specially.
> > 
> > gnome-terminal just tries to find one line that matches exactly the
> > the shell
> > 
> > util-linux skips lines from getusershell that start with "#".
> > Likewise "seunshare".
> 
> In general, musl policy is to support at most what's consistent
> between historical implementations.
> 
> It seems like they all ignore lines that start with a '#'. They might
> (not clear from the above) also ignore blank lines.
> 
> The minimal change both to avoid clashing with vaguely reasonable
> things user might want to put there (and violating least surprise),
> and to support the common behavior, seems to be just looping as long
> as the line is empty or starts with #.

Something like this?

Rich

[-- Attachment #2: usershell.diff --]
[-- Type: text/plain, Size: 496 bytes --]

diff --git a/src/legacy/getusershell.c b/src/legacy/getusershell.c
index 5fecdec2..1c5d98ec 100644
--- a/src/legacy/getusershell.c
+++ b/src/legacy/getusershell.c
@@ -25,8 +25,10 @@ char *getusershell(void)
 	ssize_t l;
 	if (!f) setusershell();
 	if (!f) return 0;
-	l = getline(&line, &linesize, f);
-	if (l <= 0) return 0;
+	do {
+		l = getline(&line, &linesize, f);
+		if (l <= 0) return 0;
+	} while (line[0] == '#' || line[0] == '\n');
 	if (line[l-1]=='\n') line[l-1]=0;
 	return line;
 }

  reply	other threads:[~2024-05-23 15:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-18  3:17 Collin Funk
2024-05-23 13:21 ` Rich Felker
2024-05-23 13:45   ` Leah Neukirchen
2024-05-23 13:59     ` Collin Funk
2024-05-23 14:47     ` Rich Felker
2024-05-23 15:27       ` Rich Felker [this message]
2024-05-25  0:16         ` Collin Funk
2024-06-22  1:06           ` 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=20240523152733.GB10433@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=collin.funk1@gmail.com \
    --cc=leah@vuxu.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).