Pa imas samo jednog usera sa jednim UIDom,to je pravilo UNIX systema.E sad ako mislis da ti je neko ubacio root account bez passworda onda to uradi ovako :
Code:
#include<pwd.h>
#include<unistd.h>
#define UID 0
/* This users only may have UID 0 */
char *users[2]={"root","toor"};
int main(){
int count = 0,invalid = 0,i = 0;
struct passwd * user;
while ( ( user = getpwent() ) != NULL ){
printf("User : %sn",user->pw_name);
if ( user->pw_uid == UID )
count++;
if ( user->pw_uid == UID )
if ( strcmp(users[0],user->pw_name) && strcmp(users[1],user->pw_name) ){
printf("Invalid root account : %sn",user->pw_name);
invalid++;
}
}
endpwent();
if (count >= 1){
printf("--------------------------------------n");
printf("Number of root accounts : %dn",count);
do {
printf("user : %sn",users[i]);
}while ( ++i < count);
}
if ( invalid > 1 )
printf("Too much root accountsn");
}
Malo pogledaj kod pa vidi kako se koristi getpwent i endpwent ...