There''s a bit of the previous patch that won''t make sense (and is wrong) without some context. I am trying to shift away from the hand hacked parsing of the command line towards allowing getopts::long to do it instead. This means getting rid of the checks starting at around line 115, but make no sense without the part attached in this email. So, this part of the patch attempts to only address the getopt handling (but there is some dief mixed in - this is meant to be applied after the first patch). Sorry about that. -- ----------------------------------------------------------------- | ,''''`. Stephen Gran | | : :'' : sgran@debian.org | | `. `'' Debian user, admin, and developer | | `- http://www.debian.org | ----------------------------------------------------------------- _______________________________________________ Adduser-devel mailing list Adduser-devel@lists.alioth.debian.org http://lists.alioth.debian.org/mailman/listinfo/adduser-devel
On Thu, Mar 09, 2006 at 10:32:59PM +0000, Stephen Gran wrote:> # Parse options, sanity checks > +exit 1 unless ( > GetOptions ("quiet" => sub { $verbose = 0 }, > "force-badname" => \$allow_badname, > "help|h" => sub { &usage(); exit 0 }, > @@ -92,10 +93,10 @@ > "gid=i" => \$new_gid, > "conf=s" => \$configfile, > "no-create-home" => \$no_create_home, > - "debug" => sub { $verbose = 2 } ); > + "debug" => sub { $verbose = 2 } ) );Doesn''t this cause adduser to exit silently without error message in case of a misparse? Greetings Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don''t trust Computers. They | Mailadresse im Header Mannheim, Germany | lose things." Winona Ryder | Fon: *49 621 72739834 Nordisch by Nature | How to make an American Quilt | Fax: *49 621 72739835
This one time, at band camp, Marc Haber said:> On Thu, Mar 09, 2006 at 10:32:59PM +0000, Stephen Gran wrote: > > # Parse options, sanity checks > > +exit 1 unless ( > > GetOptions ("quiet" => sub { $verbose = 0 }, > > "force-badname" => \$allow_badname, > > "help|h" => sub { &usage(); exit 0 }, > > @@ -92,10 +93,10 @@ > > "gid=i" => \$new_gid, > > "conf=s" => \$configfile, > > "no-create-home" => \$no_create_home, > > - "debug" => sub { $verbose = 2 } ); > > + "debug" => sub { $verbose = 2 } ) ); > > Doesn''t this cause adduser to exit silently without error message in > case of a misparse?The Getopt routine should error with "unknown option: $option". I will run some further tests to be sure. -- ----------------------------------------------------------------- | ,''''`. Stephen Gran | | : :'' : sgran@debian.org | | `. `'' Debian user, admin, and developer | | `- http://www.debian.org | ----------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://lists.alioth.debian.org/pipermail/adduser-devel/attachments/20060426/3167aaea/attachment.pgp
On Wed, Apr 26, 2006 at 11:55:58AM +0100, Stephen Gran wrote:> This one time, at band camp, Marc Haber said: > > On Thu, Mar 09, 2006 at 10:32:59PM +0000, Stephen Gran wrote: > > > # Parse options, sanity checks > > > +exit 1 unless ( > > > GetOptions ("quiet" => sub { $verbose = 0 }, > > > "force-badname" => \$allow_badname, > > > "help|h" => sub { &usage(); exit 0 }, > > > @@ -92,10 +93,10 @@ > > > "gid=i" => \$new_gid, > > > "conf=s" => \$configfile, > > > "no-create-home" => \$no_create_home, > > > - "debug" => sub { $verbose = 2 } ); > > > + "debug" => sub { $verbose = 2 } ) ); > > > > Doesn''t this cause adduser to exit silently without error message in > > case of a misparse? > > The Getopt routine should error with "unknown option: $option".How about "usage() unless ( GetOptions... )"?> I will run some further tests to be sure.Thanks. Greetings Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don''t trust Computers. They | Mailadresse im Header Mannheim, Germany | lose things." Winona Ryder | Fon: *49 621 72739834 Nordisch by Nature | How to make an American Quilt | Fax: *49 621 72739835
This one time, at band camp, Marc Haber said:> On Wed, Apr 26, 2006 at 11:55:58AM +0100, Stephen Gran wrote: > > How about > "usage() unless ( GetOptions... )"?Changing it to &usage, exit 1 unless ( GetOptions...> > I will run some further tests to be sure.Gives me this output: steve@gashuffer:~/adduser-3.86$ ./adduser --foo Unknown option: foo adduser [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID] [--firstuid ID] [--lastuid ID] [--gecos GECOS] [--ingroup GROUP | --gid ID] [--disabled-password] [--disabled-login] user Add a normal user adduser --system [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID] [--gecos GECOS] [--group | --ingroup GROUP | --gid ID] [--disabled-password] [--disabled-login] user Add a system user adduser --group [--gid ID] group addgroup [--gid ID] group Add a user group addgroup --system [--gid ID] group Add a system group adduser user group Add an existing user to an existing group Other options are [--quiet] [--force-badname] [--help] [--version] [--conf FILE]. steve@gashuffer:~/adduser-3.86$ echo $? 1 Which seems right. Thanks, -- ----------------------------------------------------------------- | ,''''`. Stephen Gran | | : :'' : sgran@debian.org | | `. `'' Debian user, admin, and developer | | `- http://www.debian.org | ----------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://lists.alioth.debian.org/pipermail/adduser-devel/attachments/20060426/d82a99ba/attachment.pgp
On Wed, Apr 26, 2006 at 02:44:07PM +0100, Stephen Gran wrote:> Changing it to > &usage, exit 1 unless ( GetOptions...Besides from this construct rating rather high on the obfuscated perl scale, its output seems acceptable to me. Greetings Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don''t trust Computers. They | Mailadresse im Header Mannheim, Germany | lose things." Winona Ryder | Fon: *49 621 72739834 Nordisch by Nature | How to make an American Quilt | Fax: *49 621 72739835
This one time, at band camp, Marc Haber said:> On Wed, Apr 26, 2006 at 02:44:07PM +0100, Stephen Gran wrote: > > Changing it to > > &usage, exit 1 unless ( GetOptions... > > Besides from this construct rating rather high on the obfuscated perl > scale, its output seems acceptable to me.OK, fair enough :) It can be rewritten more clearly as: unless ( GetOptions... [ ... ] ) { &usage; exit 1; } If that makes you more comfortable. -- ----------------------------------------------------------------- | ,''''`. Stephen Gran | | : :'' : sgran@debian.org | | `. `'' Debian user, admin, and developer | | `- http://www.debian.org | ----------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://lists.alioth.debian.org/pipermail/adduser-devel/attachments/20060426/9016d74e/attachment.pgp
On Wed, Apr 26, 2006 at 03:04:39PM +0100, Stephen Gran wrote:> It can be rewritten more clearly as: > > unless ( GetOptions... > [ ... ] > ) { > &usage; > exit 1; > } > > If that makes you more comfortable.It does, a lot. Thanks. Greetings Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don''t trust Computers. They | Mailadresse im Header Mannheim, Germany | lose things." Winona Ryder | Fon: *49 621 72739834 Nordisch by Nature | How to make an American Quilt | Fax: *49 621 72739835
This one time, at band camp, Stephen Gran said:> This one time, at band camp, Marc Haber said: > > On Wed, Apr 26, 2006 at 02:44:07PM +0100, Stephen Gran wrote: > > > Changing it to > > > &usage, exit 1 unless ( GetOptions... > > > > Besides from this construct rating rather high on the obfuscated perl > > scale, its output seems acceptable to me. > > OK, fair enough :)and so here is a patch that does so. It also fixes up 2 sorts of errors: The first: dief ("$0: " which results in output like: adduser: adduser: The second is and constructs like: "foo ", gtx( ... which produces no output at all. gtx is a subroutine that just returns gettext''ized text from the input, so it doesn''t itself output anything. Take care, Index: adduser ==================================================================--- adduser (revision 556) +++ adduser (working copy) @@ -105,6 +105,7 @@ our @names; # Parse options, sanity checks +unless ( GetOptions ("quiet" => sub { $verbose = 0 }, "force-badname" => \$allow_badname, "help|h" => sub { &usage(); exit 0 }, @@ -123,10 +124,14 @@ "gid=i" => \$new_gid, "conf=s" => \$configfile, "no-create-home" => \$no_create_home, - "debug" => sub { $verbose = 2 } ); + "debug" => sub { $verbose = 2 } ) +) { + &usage; + exit 1; +} # everyone can issue "--help" and "--version", but only root can go on -dief ("$0: ",gtx("Only root may add a user or group to the system.\n")) if ($> != 0); +dief (gtx("Only root may add a user or group to the system.\n")) if ($> != 0); if( defined($configfile) ) { @defaults = ($configfile); } @@ -149,12 +154,12 @@ } if ( (! defined $names[0]) || length($names[0]) == 0 || @names > 2) { - dief ("$0: ",gtx("Only one or two names allowed.\n")); + dief (gtx("Only one or two names allowed.\n")); } if (@names == 2) { # must be addusertogroup - dief ("$0: ",gtx("Specify only one name in this mode.\n")) + dief (gtx("Specify only one name in this mode.\n")) if ($action eq "addsysuser" || $found_group_opt); $action = "addusertogroup"; $existing_user = shift (@names); @@ -170,18 +175,18 @@ if ($action ne "addgroup" && defined($found_group_opt) +defined($ingroup_name) +defined($new_gid) > 1 ) { - dief ("$0: ",gtx("The --group, --ingroup, and --gid options are mutually exclusive.\n")); + dief (gtx("The --group, --ingroup, and --gid options are mutually exclusive.\n")); } if ((defined($special_home)) && ($special_home !~ m+^/+ )) { - (dief "$0: ",gtx("The home dir must be an absolute path.\n")) + (dief (gtx("The home dir must be an absolute path.\n"))); } if (defined($special_home) && $verbose) { - print "$0: ",gtx("Warning: The home dir you specified already exists.\n") + print "$0: " . gtx("Warning: The home dir you specified already exists.\n") if (!defined($no_create_home) && -d $special_home); - print "$0: ",gtx("Warning: The home dir you specified does not exist.\n") + print "$0: " . gtx("Warning: The home dir you specified does not exist.\n") if (defined($no_create_home) && ! -d $special_home); } @@ -746,7 +751,7 @@ my ($name) = @_; if ($name !~ /^[_.A-Za-z0-9][-_.A-Za-z0-9]*\$?$/) { print STDERR -("$0: ",gtx("To avoid problems, the username should consist of +("$0: " . gtx("To avoid problems, the username should consist of letters, digits, underscores, periods and dashes, and not start with a dash (as defined by IEEE Std 1003.1-2001). For compatibility with Samba machine accounts \$ is also supported at the end of the username\n")); @@ -758,7 +763,7 @@ } else { print STDERR -("$0: ",gtx("Please enter a username matching the regular expression configured +("$0: " . gtx("Please enter a username matching the regular expression configured via the name_regex configuration variable. Use the `--force-badname'' option to relax this check or reconfigure name_regex.\n")); exit 1; -- ----------------------------------------------------------------- | ,''''`. Stephen Gran | | : :'' : sgran@debian.org | | `. `'' Debian user, admin, and developer | | `- http://www.debian.org | ----------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://lists.alioth.debian.org/pipermail/adduser-devel/attachments/20060426/2c411376/attachment-0001.pgp
On Wed, Apr 26, 2006 at 03:57:30PM +0100, Stephen Gran wrote:> This one time, at band camp, Stephen Gran said: > > This one time, at band camp, Marc Haber said: > > > On Wed, Apr 26, 2006 at 02:44:07PM +0100, Stephen Gran wrote: > > > > Changing it to > > > > &usage, exit 1 unless ( GetOptions... > > > > > > Besides from this construct rating rather high on the obfuscated perl > > > scale, its output seems acceptable to me. > > > > OK, fair enough :) > > and so here is a patch that does so. > > It also fixes up 2 sorts of errors:(Manually) Applied to svn, thanks. Greetings Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don''t trust Computers. They | Mailadresse im Header Mannheim, Germany | lose things." Winona Ryder | Fon: *49 621 72739834 Nordisch by Nature | How to make an American Quilt | Fax: *49 621 72739835
This one time, at band camp, Marc Haber said:> On Wed, Apr 26, 2006 at 03:57:30PM +0100, Stephen Gran wrote: > > > > and so here is a patch that does so. > > > > It also fixes up 2 sorts of errors: > > (Manually) Applied to svn, thanks.Did you mean to leave the <<<<<<''s in? And what is going on that my patches don''t apply correctly? I svn up, edit, svn diff, submit. I am not that used to svn, admittedly, since I only started using it a few weeks ago, but I thought that should do the right thing. Thanks, -- ----------------------------------------------------------------- | ,''''`. Stephen Gran | | : :'' : sgran@debian.org | | `. `'' Debian user, admin, and developer | | `- http://www.debian.org | ----------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://lists.alioth.debian.org/pipermail/adduser-devel/attachments/20060426/9ed22ca5/attachment.pgp
On Wed, Apr 26, 2006 at 04:51:02PM +0100, Stephen Gran wrote:> This one time, at band camp, Marc Haber said: > > On Wed, Apr 26, 2006 at 03:57:30PM +0100, Stephen Gran wrote: > > > > > > and so here is a patch that does so. > > > > > > It also fixes up 2 sorts of errors: > > > > (Manually) Applied to svn, thanks. > > Did you mean to leave the <<<<<<''s in?No, and there aren''t any in my local copy? Which file are you refering to?> And what is going on that my > patches don''t apply correctly? I svn up, edit, svn diff, submit.And if I commit other changes in the mean time, we get conflicts, which cannot be elegantly solved since you cannot (yet) commit. I think this is bad luck for today, since I spent some time with adduser today (which I don''t do every day). It would probably be helpful to svn update again before doing the diff so that you at least incorporate changes that somebody else committed while you were editing into your diff. Greetings Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don''t trust Computers. They | Mailadresse im Header Mannheim, Germany | lose things." Winona Ryder | Fon: *49 621 72739834 Nordisch by Nature | How to make an American Quilt | Fax: *49 621 72739835
This one time, at band camp, Marc Haber said:> On Wed, Apr 26, 2006 at 04:51:02PM +0100, Stephen Gran wrote: > > > > Did you mean to leave the <<<<<<''s in? > > No, and there aren''t any in my local copy? Which file are you refering > to?steve@gashuffer:~/trunk$ svn up At revision 562. steve@gashuffer:~/trunk$ egrep -n ''(< \.mine|> \.r562)'' adduser 109:<<<<<<< .mine 114:>>>>>>> .r562 132:<<<<<<< .mine 144:>>>>>>> .r562 196:<<<<<<< .mine 200:>>>>>>> .r562 204:<<<<<<< .mine 208:>>>>>>> .r562 210:<<<<<<< .mine 214:>>>>>>> .r562> > And what is going on that my > > patches don''t apply correctly? I svn up, edit, svn diff, submit. > > And if I commit other changes in the mean time, we get conflicts, > which cannot be elegantly solved since you cannot (yet) commit. I > think this is bad luck for today, since I spent some time with adduser > today (which I don''t do every day). > > It would probably be helpful to svn update again before doing the diff > so that you at least incorporate changes that somebody else committed > while you were editing into your diff.Fair enough. I will try to get better at it. In the meantime, sorry for the messiness. -- ----------------------------------------------------------------- | ,''''`. Stephen Gran | | : :'' : sgran@debian.org | | `. `'' Debian user, admin, and developer | | `- http://www.debian.org | ----------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://lists.alioth.debian.org/pipermail/adduser-devel/attachments/20060426/17adf346/attachment.pgp
On Wed, Apr 26, 2006 at 06:16:27PM +0100, Stephen Gran wrote:> This one time, at band camp, Marc Haber said: > > On Wed, Apr 26, 2006 at 04:51:02PM +0100, Stephen Gran wrote: > > > > > > Did you mean to leave the <<<<<<''s in? > > > > No, and there aren''t any in my local copy? Which file are you refering > > to? > > steve@gashuffer:~/trunk$ svn up > At revision 562. > steve@gashuffer:~/trunk$ egrep -n ''(< \.mine|> \.r562)'' adduser > 109:<<<<<<< .mine > 114:>>>>>>> .r562 > 132:<<<<<<< .mine > 144:>>>>>>> .r562 > 196:<<<<<<< .mine > 200:>>>>>>> .r562 > 204:<<<<<<< .mine > 208:>>>>>>> .r562 > 210:<<<<<<< .mine > 214:>>>>>>> .r562Looks like conflicts of your local working copy with the repository. try svn revert adduser.> > It would probably be helpful to svn update again before doing the diff > > so that you at least incorporate changes that somebody else committed > > while you were editing into your diff. > > Fair enough. I will try to get better at it. In the meantime, sorry > for the messiness.No need to be sorry about that, you''re a great help. Greetings Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don''t trust Computers. They | Mailadresse im Header Mannheim, Germany | lose things." Winona Ryder | Fon: *49 621 72739834 Nordisch by Nature | How to make an American Quilt | Fax: *49 621 72739835
This one time, at band camp, Marc Haber said:> On Wed, Apr 26, 2006 at 06:16:27PM +0100, Stephen Gran wrote: > > This one time, at band camp, Marc Haber said: > > > On Wed, Apr 26, 2006 at 04:51:02PM +0100, Stephen Gran wrote: > > > > > > > > Did you mean to leave the <<<<<<''s in? > > > > > > No, and there aren''t any in my local copy? Which file are you refering > > > to? > > 210:<<<<<<< .mine > > 214:>>>>>>> .r562 > > Looks like conflicts of your local working copy with the repository. > try svn revert adduser.Duh! That was staring me in the face. Well, thanks, fixed now. /me goes back to reading svn docs ... -- ----------------------------------------------------------------- | ,''''`. Stephen Gran | | : :'' : sgran@debian.org | | `. `'' Debian user, admin, and developer | | `- http://www.debian.org | ----------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://lists.alioth.debian.org/pipermail/adduser-devel/attachments/20060426/d9da56c0/attachment-0001.pgp