-
User Info
Hi All,
Just wondering if anyone could reccomend a way of getting user account into (name, homedir and any plan they may have) in C from a username. kinda like finger I guess. I thought of verifying a users homedir but that's not an option as users without a homedir would be excluded. The info would then be passed onto a series of GTK labels, but i'll worry about that later ;)
Thanks very much!
Dave.
-
-
Thanks, that looks ot be just what I'm looking for! - Now to work out how to use it...
-
Ok, I've been trying to find out some info on using getpwent for a good few hours now and have found nothing, would someone be kind enough to shove me in the right directtion with a link? - There seems to be little of use in the man pages :(
-
I found this site I hope it helps
here
[EDIT]After more searching I have found this also[/EDIT]
Here
-
Thanks, just what I was looking for.
-
I've just been toying with the code on metashell and it works fine if I just print the results straight away, but if I run a simple if statement nothing is returned...
Code:
ViewUserInfo() {
struct passwd *user;
/* open the user database */
setpwent();
/* read the user data one by one and print their names to stdout */
while( (user = getpwent())!=NULL )
if (user->pw_name == "root") {
printf("YAY\n");
}
// printf("%s\n", user->pw_dir);
// printf("%s\n", user->pw_name);
/* close the database */
endpwent();
}
Anyone happen to have an idea as to why?
-
You can't compare strings like that.
You should use strcmp from <string.h>, assuming you're using C.
Code:
ViewUserInfo() {
struct passwd *user;
/* open the user database */
setpwent();
/* read the user data one by one and print their names to stdout */
while( (user = getpwent())!=NULL )
if (!strcmp(user->pw_name, "root")) {
printf("YAY\n");
}
// printf("%s\n", user->pw_dir);
// printf("%s\n", user->pw_name);
/* close the database */
endpwent();
}
The ! is there because it will return -1 if the first one is "bigger", 0 if they're equal and 1 if the second one is "bigger". I can't remember what is the comparison it does right now, but you're looking for it to return a 0.
EDIT: Fixed a typo.
Also, with the if statement you had, it was comparing one pointer to another, and they'll never be equal in this function.
-
Thanks! - It gets a bit much at times, learning PHP, C, Javascript and being told I may have to learn ASP (again) and .Net :/
-
-
fj
you do not need to put yourself through all that bull$$$$ just use echo and the $user but that is only if you are logged on to that account so you might have to put yourself through all that bull$$$$ and also the most common working directory is /home/user just to let you know hope that helped
-
a) Watch the language.
b) Don't bump month-old posts.
c) He wanted to be able to get info about any user, not just the currently logged in one.