getpwnam problem
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > getpwnam problem




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    getpwnam problem  
ultra


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-04 10:58 PM

Hi there,
I have a program that call getpwnam to get the user info, but sometimes
the call returned NULL with errno EINVAL. I always pass the same user to the
call. Anyone know what is the reason? I'm running HP11.00 and NIS.







[ Post a follow-up to this message ]



    Re: getpwnam problem  
Aaron Isotton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-04 10:58 PM

ultra wrote:
> Hi there,
>     I have a program that call getpwnam to get the user info, but sometime
s
> the call returned NULL with errno EINVAL. I always pass the same user to t
he
> call. Anyone know what is the reason? I'm running HP11.00 and NIS.
>
>

getpwnam() returns NULL if:

a) the user doesn't exits
b) an error occurred

When an error occurred, errno is set appropriately. When the user
doesn't exist, errno is NOT set.  Thus you want to use some code as follows:

struct passwd *pw;

/* we reset errno so we can tell whether an error happens in getpwnam()
* or not */
errno = 0;
pw = getpwnam("some_user");
if (!pw) {
if (errno) fprintf(stderr, "error: %s\n", strerror(errno));
else fprintf(stderr, "no such user\n");
}

Greetings,
Aaron
--
Aaron Isotton | http://www.isotton.com/
You know it's Monday when you wake up and it's Tuesday. -- Garfield





[ Post a follow-up to this message ]



    Re: getpwnam problem  
ultra


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-04 10:58 PM

>
> getpwnam() returns NULL if:
>
> a) the user doesn't exits
> b) an error occurred
>
> When an error occurred, errno is set appropriately. When the user
> doesn't exist, errno is NOT set.  Thus you want to use some code as
follows:
>
> struct passwd *pw;
>
> /* we reset errno so we can tell whether an error happens in getpwnam()
>   * or not */
> errno = 0;
> pw = getpwnam("some_user");
> if (!pw) {
> if (errno) fprintf(stderr, "error: %s\n", strerror(errno));
> else fprintf(stderr, "no such user\n");
> }
>
> Greetings,
> Aaron
> --
> Aaron Isotton | http://www.isotton.com/
> You know it's Monday when you wake up and it's Tuesday. -- Garfield

But the problem is I always pass the same user(exist in the system) to
getpwnam, sometimes it works but sometimes it fails with NULL. Any idea?







[ Post a follow-up to this message ]



    Re: getpwnam problem  
Jim Hollenback


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-04 10:58 PM

ultra (ultraman@rogers_NOSPAM.com) wrote:
: >
: > getpwnam() returns NULL if:
: >
: > a) the user doesn't exits
: > b) an error occurred
: >
: > When an error occurred, errno is set appropriately. When the user
: > doesn't exist, errno is NOT set.  Thus you want to use some code as
: follows:
: >
: > struct passwd *pw;
: >
: > /* we reset errno so we can tell whether an error happens in getpwnam()
: >   * or not */
: > errno = 0;
: > pw = getpwnam("some_user");
: > if (!pw) {
: > if (errno) fprintf(stderr, "error: %s\n", strerror(errno));
: > else fprintf(stderr, "no such user\n");
: > }
: >

: But the problem is I always pass the same user(exist in the system) to
: getpwnam, sometimes it works but sometimes it fails with NULL. Any idea?

what is the errno when it fails?

--
Jim Hollenback
jholly@cup.hp.com
my opinion.





[ Post a follow-up to this message ]



    Re: getpwnam problem  
Dragan Cvetkovic


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-04 10:58 PM

jholly@cup.hp.com (Jim Hollenback) writes:

> ultra (ultraman@rogers_NOSPAM.com) wrote:
> : But the problem is I always pass the same user(exist in the system) to
> : getpwnam, sometimes it works but sometimes it fails with NULL. Any idea?
>
> what is the errno when it fails?

Apparently EINVAL. Here is the original message:

> I have a program that call getpwnam to get the user info, but sometimes
> the call returned NULL with errno EINVAL. I always pass the same user to t
he
> call. Anyone know what is the reason? I'm running HP11.00 and NIS.
>

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!





[ Post a follow-up to this message ]



    Re: getpwnam problem  
ultra


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-04 10:58 PM

> what is the errno when it fails?
>
> --
> Jim Hollenback
> jholly@cup.hp.com
> my opinion.

it didn't set the errno when it failed...







[ Post a follow-up to this message ]



    Re: getpwnam problem  
Dragan Cvetkovic


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-04 10:58 PM

"ultra" <ultraman@rogers_NOSPAM.com> writes:
 
>
> it didn't set the errno when it failed...
>
>

Huh? What do you mean it didn't set the errno? Here is your original
message:

> I have a program that call getpwnam to get the user info, but sometimes
> the call returned NULL with errno EINVAL.




--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!





[ Post a follow-up to this message ]



    Re: getpwnam problem  
ultra


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-04 10:58 PM

ya.. I didn't errno=0 before the call at the begining. Once I set errno=0
before the call, it is still errno=0 after the call fail...

"Dragan Cvetkovic" <me@privacy.net> wrote in message
news:lmu0w1qjtq.fsf@privacy.net...
> "ultra" <ultraman@rogers_NOSPAM.com> writes:
> 
>
> Huh? What do you mean it didn't set the errno? Here is your original
> message:
> 
>
>
>
>
> --
> Dragan Cvetkovic,
>
> To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer
>
> !!! Sender/From address is bogus. Use reply-to one !!!







[ Post a follow-up to this message ]



    Re: getpwnam problem  
Chuck Dillon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-22-04 11:01 PM

ultra wrote:
> Hi there,
>     I have a program that call getpwnam to get the user info, but sometime
s
> the call returned NULL with errno EINVAL. I always pass the same user to t
he
> call. Anyone know what is the reason? I'm running HP11.00 and NIS.
>
>

Is the program threaded?  Try getpwnam_r?

-- ced

--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.





[ Post a follow-up to this message ]



    Re: getpwnam problem  
Aaron Isotton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-04 12:50 PM

ultra wrote:
> ya.. I didn't errno=0 before the call at the begining. Once I set errno=0
> before the call, it is still errno=0 after the call fail...

In this case, the system thinks that the user doesn't exist. Maybe
there's some problem with your NIS configuration.

Greetings,
Aaron
--
Aaron Isotton | http://www.isotton.com/
You know it's Monday when you wake up and it's Tuesday. -- Garfield





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:11 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register