BusyBox Bug and Patch Tracking
BusyBox
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000938 [uClibc] New Features minor always 07-08-06 17:08 01-04-08 23:06
Reporter zen View Status public  
Assigned To uClibc
Priority normal Resolution fixed  
Status closed   Product Version 0.9.28
Summary 0000938: getent: minor feature additions and code clean-up
Description I had occasion to look at the uClibc script "getent" and felt compelled to clean out the cargo-cult programming style. I believe that this version is clearer, and I've added some minor features while I was in there:
  * usage clause, if no arguments or "--help" requested
  * original version appears to have been intending to "exit 2" on failure to match, but didn't
  * basic, probably good enough, support for ethers and netgroups
  * faster ;-) [as if that matters for this script]
Additional Information
Attached Files  getent [^] (982 bytes) 07-08-06 17:08
 getent-v2 [^] (1,144 bytes) 07-10-06 18:23

- Relationships

- Notes
(0001505)
psm
07-10-06 02:20

Anything you do the script should behave as the getent binary from glibc
I don't really see the need for NIS related stuff
 
(0001506)
zen
07-10-06 03:06
edited on: 07-10-06 03:07

1) If the script in uClibc-0.9.28 behaved like that in glibc, then this one does too; if it didn't then this one doesn't either. If you're asking me to fix something that is broken, please be more clear about the request? An example of a feature that behaves differently (or is missing) would be helpful as a starting point.

2) If by "NIS related stuff" you're referring to "ethers and netgroups", that was prompted by a comment in the 0.9.28 file about "not implemented", and my implementation was simply to add those two files to one of the case branches (the one already handling hosts|protocols|rpc|services). Perhaps it'd be strange for someone to have a /etc/netgroups file and want to query it with getent, but the code to (minimally) support it is trivial, so why not?

 
(0001507)
psm
07-10-06 03:20

I am the "author" of that file, despite the header part, I have also added the
comment about missing features. I originally tried to make the script behave
as glibc-2.2.5's, some changes where though later necessary to it (see svn logs)
I haven't checked if you took the .28 or svn version as starting point, svn is
for sure better (I haven't even compared yet what you did, I commented only on
the comments you provided). Ethers and netgroups are not ok iirc by simply adding
them to the existing check, I can't recall though why
 
(0001509)
zen
07-10-06 14:00

Version: I thought I was taking the .28 version, but it turns out that the Gentoo emerge of uClibc that I'm using actually patches the getent script to align with what is currently at the head of svn (except for the lead-in comment).

But... you're critiquing it and you didn't even *look* at it? Really, this was just intended as a _minor_ tweak. Look at the code. Perhaps my commentary made it sound like I am proposing more elaborate changes than I really am. Here is the fragment that most offended me in the original:
       /bin/egrep -v "^#" $1 | /bin/sed 's/#.*$//' | /bin/egrep "${string}" | /bin/sed -n 1p

That is just silly. First off, there is a bug in that retval is set based on the $? of that line, which will always be zero unless something is very broken (like /bin/sed missing), but it is clear that the intent is that if the entry is not found that retval should be 2. Second off, it is just clumsy. Here is my rewrite:
       /bin/sed "s/#.*//; /$match/q; d" "$file" | grep .
(the grep here is just to detect a non-match). The $match (formerly ${string}) expression looks a little different; this is accounted for in the attached code.

While I was "fixing" that, I also adressed the fact that the code had several redundant and/or extraneous conditionals. The new code is much more straightforward. And all of this discussion is more verbose and less clear than the code itself.


What I'm hearing so far is this:
  1) instead of deleting the comment about "ethers|netgroup (not done, needed)?" I should instead change it to "ethers|netgroup (not completely correct)" (okay, sure, that makes sense)
  2) for you to consider looking at the code I should research what exactly glibc does with *its* getent, and add at least some of the missing functionality/compatabilty to this lightweight script, without any hints about what is considered broken with the existing implementation (surely this isn't right?)
 
(0001510)
psm
07-10-06 14:18

I finally looked at what you did and the only "requirement" it should fullfil:
work with busybox ash (maybe msh) as shell and busybox's implementation of sed/grep
 
(0001511)
psm
07-10-06 14:35

networks fails
 
(0001513)
psm
07-10-06 15:17

could you explain why you removed \< \> ?
 
(0001514)
zen
07-10-06 18:19

networks: oops -- I obviously didn't read the original code properly (and never personally use the file), and thought matches looked like shadow (with the trailing ":"); fixed in new version (attached). I also note that the netgroup file is keyed in the same format, so moved its case-match entry.

\< \> -- for the most part their use was redundant: for a properly keyed database file, $foo\>: and $foo: will always match the same thing, and similarly for ^\<$foo and ^$foo (because for real keys $foo is all "word" characters, and neither ^ nor : match as word characters). I find the extra metacharacters distracting; YMMV. For passwd,group I tightened up the matching patterns to only match in the username and [ug]id fields; for aliases (and now networks and netgroup) I've loosened the pattern to allow whitespace surrounding the key.

compatability: Tested in a busybox-only environment. While my version does demand more of sed's RE engine (which busybox sed handles fine), my version uses fewer features of the shell than the original, so it should work with any of the targeted shells. I note that I happened to use "grep" intead of "egrep" for no particular reason; if egrep is preferred for any reason, use that.
 
(0003404)
vapier
01-04-08 23:06

i made a few tweaks (like removing the hard coded paths and tweaking style), but otherwise committed the new version

thanks!
 

- Issue History
Date Modified Username Field Change
07-08-06 17:08 zen New Issue
07-08-06 17:08 zen Status new => assigned
07-08-06 17:08 zen Assigned To  => uClibc
07-08-06 17:08 zen File Added: getent
07-10-06 02:20 psm Note Added: 0001505
07-10-06 03:06 zen Note Added: 0001506
07-10-06 03:07 zen Note Edited: 0001506
07-10-06 03:20 psm Note Added: 0001507
07-10-06 14:00 zen Note Added: 0001509
07-10-06 14:18 psm Note Added: 0001510
07-10-06 14:35 psm Note Added: 0001511
07-10-06 15:17 psm Note Added: 0001513
07-10-06 18:19 zen Note Added: 0001514
07-10-06 18:21 zen Issue Monitored: zen
07-10-06 18:21 zen Issue End Monitor: zen
07-10-06 18:23 zen File Added: getent-v2
01-04-08 23:06 vapier Note Added: 0003404
01-04-08 23:06 vapier Status assigned => closed
01-04-08 23:06 vapier Resolution open => fixed


Copyright © 2000 - 2006 Mantis Group
Powered by Mantis Bugtracker