LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-07-2010, 08:26 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
getent does not work for usernames with numbers


Hi All,

Here is the output of getent, which I am finding strange.

Code:
[3001@CDCTGIMCLSA ~]$ sudo getent passwd 3001
Also the exit status is 2

But the user 3001 exists in the system.

Code:
[3001@CDCTGIMCLSA ~]$ cat /etc/passwd | grep 3001
3001:x:513:513::/home/3001:/bin/bash
Also getent works well for usernames having alpabets.

Code:
[3001@CDCTGIMCLSA ~]$ sudo getent passwd test
test:x:511:511::/home/test:/bin/bash
I am finding it pretty amazing. Does anyone know why getent behaves like this ?
 
Old 09-07-2010, 09:27 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
what is the content of your /etc/nsswitch.conf file?
 
Old 09-07-2010, 10:30 AM   #3
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by fpmurphy View Post
what is the content of your /etc/nsswitch.conf file?
Here is the contents of /etc/nsswitch.conf

Code:
passwd:     files
shadow:     files
group:      files
hosts:      files dns
bootparams: nisplus [NOTFOUND=return] files

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files

netgroup:   files nis

publickey:  nisplus

automount:  files nis
aliases:    files nisplus
 
Old 09-08-2010, 06:29 AM   #4
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Original Poster
Rep: Reputation: 55
Any idea on this behavior of getent ?
 
Old 09-10-2010, 09:45 PM   #5
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
You probably should contact the programmer of the tool.
But I think that it will try to find a userid if the parameter is a pure numerical value in stead of trying to find a user with that
name.

Try using something like u3021
_______________
gerrard

Last edited by gdejonge; 09-10-2010 at 09:46 PM.
 
Old 09-10-2010, 09:50 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
try adding another user with numbers, eg useradd 3002. useradd will complain. Did you add 3001 using useradd? or did someone just create an entry in passwd ?
 
Old 09-10-2010, 10:24 PM   #7
mgsmith7475
LQ Newbie
 
Registered: Mar 2008
Location: Michigan
Distribution: RHEL 5.4 / Ubuntu 9.10
Posts: 8

Rep: Reputation: 0
Worked fine for me when adding a user by the name of 4000. just typed - getent passwd | grep 4000
and it found this - getent passwd | grep 4000
4000:x:525:527::/home/4000:/bin/bash

Definitely no bug.

Using Ubuntu 10.04

It also worked just fine on a RHEL 5.5 Server that I have available to me.

Last edited by mgsmith7475; 09-10-2010 at 10:45 PM.
 
Old 09-11-2010, 12:05 AM   #8
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 113Reputation: 113
Quote:
Originally Posted by vinaytp View Post
Any idea on this behavior of getent ?
When you query numeric username it will search for uid not username

i.e when you run

sudo getent passwd 3001

it will detect 3001 as UID not username. if uid not present then your exit status return 2

quote from getent man page

Quote:
Each key must be in a format appropriate for searching on
the respective database. For example, it can be a username
or numeric-uid for passwd
So if you want to query numeric user names use their UIDs.

i.e

Code:
$ sudo getent passwd UID
HTH
 
Old 09-11-2010, 12:09 AM   #9
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 113Reputation: 113
Quote:
Originally Posted by mgsmith7475 View Post
Worked fine for me when adding a user by the name of 4000. just typed - getent passwd | grep 4000
and it found this - getent passwd | grep 4000
4000:x:525:527::/home/4000:/bin/bash

Definitely no bug.

Using Ubuntu 10.04

It also worked just fine on a RHEL 5.5 Server that I have available to me.
Filtering from whole databse is ok but when you query for specific numeric user it will show exit status 2.

i.e try to run below command

Code:
getent passwd 4000
 
Old 09-13-2010, 12:17 AM   #10
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Original Poster
Rep: Reputation: 55
Thanks for all your comments.

We cannot add a user with username 3001 in fedora. But we can add in RHEL and CentOS.

So getnent is not working as expected when it comes to numerical usernames.

Can we consider this as a bug in getent?

Last edited by vinaytp; 09-13-2010 at 12:19 AM.
 
Old 09-13-2010, 01:29 AM   #11
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 113Reputation: 113
Quote:
Originally Posted by vinaytp View Post
Thanks for all your comments.

We cannot add a user with username 3001 in fedora. But we can add in RHEL and CentOS.

So getnent is not working as expected when it comes to numerical usernames.

Can we consider this as a bug in getent?
when you query numeric username it consider as UID. read post #8.

It is not bug.
 
Old 09-14-2010, 12:02 AM   #12
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
Interestingly, I can add a user called "3001" in Fedora 13 without a problem.

But if I then use
Code:
getent passwd 3001
nothing is returned and the errno is 2.

System is standalone.
 
Old 09-14-2010, 02:07 AM   #13
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
I didn't think the system allowed you to create accounts (or groups) beginning with a numeric or special character.

I assume changing the usernames is out of the question?

It might be worth reviewing naming conventions to ensure that the issue doesn't get any worse (just a thought)
 
Old 09-14-2010, 02:34 AM   #14
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Officially this is the legal template for a username: [a-z_][a-z0-9_-]*

Some distro's do allow other characters and might let you start a username with a number, but this could get you into trouble.

Hope this helps.
 
Old 09-15-2010, 05:49 AM   #15
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
Quote:
Originally Posted by druuna View Post
Hi,
Officially this is the legal template for a username: [a-z_][a-z0-9_-]*
What do you mean by officially? Where is that specified in any formal specification?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command getent return nothing aspenbr Linux - Software 1 11-18-2008 12:01 AM
getent passwd only pulls local info - getent group works? epoh Linux - Server 2 03-14-2008 07:56 AM
System usernames versus user numbers -- incompatibility? eater Linux - Software 4 03-01-2008 10:53 AM
sequence of numbers, how to extract which numbers are missing jonlake Programming 13 06-26-2006 03:28 AM
Adding numbers, break on non-numbers... Cruger Programming 1 03-22-2004 09:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration