--- projects/libstatgrab/examples/user_list.c 2003/08/24 20:24:09 1.2 +++ projects/libstatgrab/examples/user_list.c 2004/01/06 15:35:04 1.5 @@ -24,22 +24,31 @@ #include int main(int argc, char **argv){ - + extern char *optarg; - extern int optind; - int c; + extern int optind; + int c; int delay = 1; user_stat_t *users; - while ((c = getopt(argc, argv, "d:")) != EOF){ - switch (c){ - case 'd': - delay = atoi(optarg); - break; + while ((c = getopt(argc, argv, "d:")) != -1){ + switch (c){ + case 'd': + delay = atoi(optarg); + break; } } + /* Initialise statgrab */ + statgrab_init(); + + /* Drop setuid/setgid privileges. */ + if (statgrab_drop_privileges() != 0) { + perror("Error. Failed to drop privileges"); + return 1; + } + if( (users = get_user_stats()) != NULL){ printf("Users : %s\n", users->name_list); printf("Number of users : %d\n", users->num_entries); @@ -47,6 +56,3 @@ int main(int argc, char **argv){ exit(0); } - - -