user id -> user name?

user id -> user name?

Post by marc » Thu, 30 Jul 1998 04:00:00



Is there a C function which returns the user-name for the user id?

Thanks, Marc

 
 
 

user id -> user name?

Post by Andrew Giert » Thu, 30 Jul 1998 04:00:00


 marc> Is there a C function which returns the user-name for the user id?

getpwuid()

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

user id -> user name?

Post by mattr.. » Thu, 30 Jul 1998 04:00:00



>Is there a C function which returns the user-name for the user id?

>Thanks, Marc

There should be a function like getpwnam() or something like that
where you give the user id and it returns the user name.

Someone is borrowing my UNIX programming book so I can't tell you for
sure, but I do believe it exists.
------
Remove "nospam" to respond via email.

Matt

------
- These views are my own, not necessarily those of my company.

 
 
 

user id -> user name?

Post by Marc Dzaebe » Thu, 30 Jul 1998 04:00:00




>  marc> Is there a C function which returns the user-name for the user id?

> getpwuid()

> --
> Andrew.

Hi Andrew,  (hi Mattryan)

Ok, getpwuid(uid)->pw_name returns the /etc/passwd user and the
shadow password can also be determined by getspnam but what if you
are connected to NIS/YP-Server or other name services? Is there
a portable way to get the user-name on HP-UX, Solaris, Linux?
E.g. on HP-UX / SCO you need to use different commands (FAQ).
May be I should look in the 'id' command, but I don't have the
sources. However, I hope that your mentioned method works
for most cases. What Unix book would you recommend here?

Thanks a lot for you perfect help!

Yours, Marc Dzaebel

 
 
 

user id -> user name?

Post by mattr.. » Thu, 30 Jul 1998 04:00:00






>>  marc> Is there a C function which returns the user-name for the user id?

>> getpwuid()

>> --
>> Andrew.

>Hi Andrew,  (hi Mattryan)

>Ok, getpwuid(uid)->pw_name returns the /etc/passwd user and the
>shadow password can also be determined by getspnam but what if you
>are connected to NIS/YP-Server or other name services? Is there
>a portable way to get the user-name on HP-UX, Solaris, Linux?
>E.g. on HP-UX / SCO you need to use different commands (FAQ).
>May be I should look in the 'id' command, but I don't have the
>sources. However, I hope that your mentioned method works
>for most cases. What Unix book would you recommend here?

>Thanks a lot for you perfect help!

>Yours, Marc Dzaebel

Advanced Programming in the UNIX Environment by W. Richard Stevens is
highly recommended, at least by me.
------
Remove "nospam" to respond via email.

Matt

------
- These views are my own, not necessarily those of my company.

 
 
 

user id -> user name?

Post by Adel Abushae » Fri, 31 Jul 1998 04:00:00



> Is there a C function which returns the user-name for the user id?

man getpwuid(), probably it will help you.

Adel.

Quote:> Thanks, Marc

 
 
 

user id -> user name?

Post by Marc Dzaebe » Sun, 02 Aug 1998 04:00:00




> > Ok, getpwuid(uid)->pw_name returns the /etc/passwd user and the
> > shadow password can also be determined by getspnam but what if you
> > are connected to NIS/YP-Server or other name services? Is there
> > a portable way to get the user-name on HP-UX, Solaris, Linux?

> I can't say for all the flavors you mention, but getpwuid() on Solaris
> will automatically use NIS if /etc/nsswitch.conf is properly set.

> ron
> ----------------------------------------------------------------------
>               Ron Klatchko - Senior Software Engineer
>          UCSF Library and Center for Knowledge Management


Yes, many confirmed this but I experienced that the call is
dramatically slow (1/10 sec). So I would always recommend to cache uids
and user-names.

Thanks for your answer,

Marc Dzaebel

 
 
 

1. how to user C language to convert a known user id to a user name

Hi Everyone,

I am writing a progam that can find information for a file by using
stat() func. Although I can get user id and group id from this
function.I am trying to find if there's a function in C that can help
convert a known user id to a user name in Linux OS?And how to convert
a known group id to the group name? If there is no such a function,
can I write one and how to do it?
Thanks a lot!

David

2. disconnecting from the internet...computer grinds to a halt

3. How to change a users name (r->connection->user) in a module

4. problem with Solaris7 modload(1M)

5. get user ID from user name

6. monitoring network performance

7. user id vs effective user id

8. Linux vs Windows NT 4

9. ps -ef loses user ID -> login name

10. Qube3 user administration - length of user name > 12

11. scoadmin -> Account Manager -> Users -> Add New Users breaks /etc/password symlink

12. How to prevent two concurrent users with the same user ID/Password