Re: Newbie question: get list of users
Re: Newbie question: get list of users
- Subject: Re: Newbie question: get list of users
- From: Hasan Diwan <email@hidden>
- Date: Mon, 27 Jan 2003 01:42:40 -0800
Frank:
Try this, to get all users on the system with homedirs in /Users
(commented appropriately):
/* Untested code - written in mail.app
* Issues: this code only reports users whose names match their home
directories
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <pwd.h>
void getUsers() {
DIR *d;
struct dirent *i;
char *d1, *d2;
d=opendir("/Users");
for (i;!i;i=readdir(d)) {
d1=malloc(sizeof(char)*i->d_namlen+1);
bzero(d1, (i->d_namlen+1)*sizeof(char));
memcpy(d1,i->d_nam,i->d_namlen);
d2=strchr(d1, '/'); /* Grab the filename somehow */
if (!strcmp('Shared', d2)) continue; /* Restart loop if we're looking
@ Shared, * * cause you know that, Shared isn't a valid
* * home dir
*/
printf("%s\n", d2);
}
}
The rest of the question is left as an exercize for the reader.
On Sunday, January 26, 2003, at 02:01 PM, mw wrote:
>
> Hi developer,
>
>
>
> I'm relatively new to MacOS, especially Cocoa programming. I would
>
> like
>
> to know, how to get a list of all users
>
> defined to the system and whether they have administrator rights or
>
> not.
>
>
>
> Scanning the mailing list archive and I've found that there are
>
> different ways to do this. If I look in the Account
>
> preferences I can set a user as Administrator, Accounts also doesn't
>
> show all users compared to Netinfo or
>
> /etc/passwd.
>
>
>
> Is there any code example to get a list of users defined in Accounts.
>
> I
>
> only need users that have a directory in
>
> /Users.
>
>
>
> Any help is appreciated.
>
>
>
> --
>
>
>
> Regards
>
> Frank Fenn - Bright Light Software
>
> _______________________________________________
>
> cocoa-dev mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
> Do not post admin requests to the list. They will be ignored.
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
>
Hasan Diwan
OpenPGP KeyID: 0x7EE3855B
Fingerprint: 42F0 5758 C3EB BA1F ABD2 ED49 3390 CCF0 7EE3 855B
http://www.cs.rpi.edu/~diwanh/gpg.key
[demime 0.98b removed an attachment of type application/pgp-signature which had a name of PGP.sig]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.