Discussion:
using getent(3) and specifying more arguments after the key?
Jeremy C. Reed
2014-06-25 18:02:01 UTC
Permalink
The getent.1 manual says:

For cgetcap(3) style databases (disktab, printcap) specifying a key,
lists the entry for that key, and specifying more arguments after the key
are used as fields in that key, and only the values of the keys are
returned. For boolean keys true is returned if the key is found. If a
key is not found, then false is always returned.

I only looked at this part of the code briefly. I think the manpage
means to say:

"... only the values of the fields are returned. For boolean fields,
`true' is returned if the field is found. If a field is not found, then
`false' is always returned."

But I cannot reproduce it, for example:

t1:reed$ getent disktab floppy ty
t1:reed$ getent disktab floppy ob
t1:reed$ getent disktab floppy pc
t1:reed$ getent gettytab Console rw

But I would think it would be like this:

t1:reed$ getent disktab floppy ty
floppy
t1:reed$ getent disktab floppy ob
0
t1:reed$ getent disktab floppy pc
2880
t1:reed$ getent gettytab Console rw
true

Note that getent with the entry does work:

t1:reed$ getent disktab floppy
floppy|3.5in High Density
Floppy:ty=floppy:se#512:nt#2:rm#300:ns#18:nc#80:pa#2880:oa#0:ba#4096:fa#512:ta=4.2BSD:pb#2880:ob#0:pc#2880:oc#0:

t1:getent$ ./getent gettytab Console
Console|Console Decwriter II:rw:sp#300:

Am I doing this wrong to get the value? Or is this not working? Or maybe
I don't understand the manual.

(By the way, I just sent a patch to tech-userlevel to add login.conf
support to getent(1) but this problem is in an unpatched version too.)

Thanks,

Jeremy C. Reed

echo 'EhZ[h ^jjf0%%h[[Zc[Z_W$d[j%Xeeai%ZW[ced#]dk#f[d]k_d%' | \
tr '#-~' '\-.-{'
Christos Zoulas
2014-06-25 18:22:49 UTC
Permalink
Post by Jeremy C. Reed
For cgetcap(3) style databases (disktab, printcap) specifying a key,
lists the entry for that key, and specifying more arguments after the key
are used as fields in that key, and only the values of the keys are
returned. For boolean keys true is returned if the key is found. If a
key is not found, then false is always returned.
I only looked at this part of the code briefly. I think the manpage
"... only the values of the fields are returned. For boolean fields,
`true' is returned if the field is found. If a field is not found, then
`false' is always returned."
t1:reed$ getent disktab floppy ty
t1:reed$ getent disktab floppy ob
t1:reed$ getent disktab floppy pc
t1:reed$ getent gettytab Console rw
t1:reed$ getent disktab floppy ty
floppy
t1:reed$ getent disktab floppy ob
0
t1:reed$ getent disktab floppy pc
2880
t1:reed$ getent gettytab Console rw
true
t1:reed$ getent disktab floppy
floppy|3.5in High Density
Looks broken to me. Fix it.

christos
Jeremy C. Reed
2014-06-25 18:59:40 UTC
Permalink
Post by Christos Zoulas
Looks broken to me. Fix it.
Okay, one line fix. I will commit if nobody objects.

t1:getent$ ./getent gettytab Console junk rw sp
false
true
300

Index: getent.1
===================================================================
RCS file: /cvsroot/src/usr.bin/getent/getent.1,v
retrieving revision 1.23
diff -U 7 -r1.23 getent.1
--- getent.1 11 Oct 2011 20:39:40 -0000 1.23
+++ getent.1 25 Jun 2014 18:58:28 -0000
@@ -23,15 +23,15 @@
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd October 11, 2011
+.Dd June 25, 2014
.Dt GETENT 1
.Os
.Sh NAME
.Nm getent
.Nd get entries from administrative databases
.Sh SYNOPSIS
.Nm getent
@@ -97,20 +97,23 @@
will be retrieved using the appropriate enumeration function and printed.
.Pp
For
.Xr cgetcap 3
style databases
.Sy ( disktab ,
.Sy printcap )
-specifying a key, lists the entry for that key, and specifying more arguments
-after the key are used as fields in that key, and only the values of the keys
-are returned.
-For boolean keys
+specifying a key,
+.Nm
+lists the record entry for that key.
+Additional arguments specified after the key are used as capability
+fields in that record, and only the values of the fields are
+returned.
+For boolean fields,
.Dv true
-is returned if the key is found.
+is returned if the capability is found.
If a key is not found, then
.Dv false
is always
returned.
.Sh DIAGNOSTICS
.Nm
exits 0 on success,
Index: getent.c
===================================================================
RCS file: /cvsroot/src/usr.bin/getent/getent.c,v
retrieving revision 1.19
diff -U 7 -r1.19 getent.c
--- getent.c 15 Mar 2012 02:02:23 -0000 1.19
+++ getent.c 25 Jun 2014 18:58:28 -0000
@@ -634,15 +634,15 @@
}
} else {
if ((b = mygetent(db_array, argv[0])) == NULL)
return RV_NOTFOUND;
if (argc == 1)
handleone(db_array, b, recurse, pretty, 0);
else {
- for (i = 2; i < argc; i++) {
+ for (i = 1; i < argc; i++) {
for (j = 0; j < sizeof(sfx) - 1; j++) {
cap = cgetcap(b, argv[i], sfx[j]);
if (cap) {
capprint(cap);
break;
}
}
Christos Zoulas
2014-06-25 23:06:13 UTC
Permalink
Post by Jeremy C. Reed
Post by Christos Zoulas
Looks broken to me. Fix it.
Okay, one line fix. I will commit if nobody objects.
t1:getent$ ./getent gettytab Console junk rw sp
false
true
300
I'd follow what sysctl(*) does (default print name=value
with -n print just value).

christos

(*) without extra spaces
Jeremy C. Reed
2014-06-25 23:42:11 UTC
Permalink
Post by Christos Zoulas
Post by Jeremy C. Reed
Okay, one line fix. I will commit if nobody objects.
t1:getent$ ./getent gettytab Console junk rw sp
false
true
300
I'd follow what sysctl(*) does (default print name=value
with -n print just value).
christos
(*) without extra spaces
I think that is a better idea. But I don't know if worked before (I
didn't check) and maybe some rely on the documented behavior. Also maybe
some other system has the same feature to be same as. I didn't see the
capabilities lookup on Linux getent or Solaris getent though. If I do
this change, should I send a "head up" or ask for feedback first for
default output change?
Christos Zoulas
2014-06-26 01:32:02 UTC
Permalink
On Jun 25, 6:42pm, ***@reedmedia.net ("Jeremy C. Reed") wrote:
-- Subject: Re: using getent(3) and specifying more arguments after the key?

| On Wed, 25 Jun 2014, Christos Zoulas wrote:
|
| > >Okay, one line fix. I will commit if nobody objects.
| > >
| > >t1:getent$ ./getent gettytab Console junk rw sp
| > >false
| > >true
| > >300
| >
| > I'd follow what sysctl(*) does (default print name=value
| > with -n print just value).
| >
| > christos
| >
| > (*) without extra spaces
|
| I think that is a better idea. But I don't know if worked before (I
| didn't check) and maybe some rely on the documented behavior. Also maybe
| some other system has the same feature to be same as. I didn't see the
| capabilities lookup on Linux getent or Solaris getent though. If I do
| this change, should I send a "head up" or ask for feedback first for
| default output change?

I'd implement it first... Since getent on linux does not support key-value
databases, I don't think there is an issue. The problem is that both linux
and solaris allow multiple keys, so perhaps separate the fields with --?

./gettent gettytab ppp Console -- junk rw sp

christos

Loading...