int main(int argc, char **argv) { uid_t uid; DIR *dirp; struct dirent *directory_entry; char dirname[256]; /* validate the input and map name to uid */ if (argc != 2) { print_usage(argc, argv); return 1; } uid = user_id_from_name(argv[1]); if (uid == -1) { printf("Invalid username specified (not found)\n"); return 1; } /* now, walk directories in /proc fs */ if ((dirp = opendir(PROCFS_ROOT)) == NULL) { perror("Unabled to open /proc"); return 1; } do { if ((directory_entry = readdir(dirp)) != NULL) { if (directory_entry->d_type == DT_DIR || directory_entry->d_type == DT_LNK) { strcpy(&dirname[0], PROCFS_ROOT); strcat(&dirname[0], "/"); strcat(&dirname[0], directory_entry->d_name); check_dir(&dirname[0], uid); } } } while (directory_entry != NULL); return 0; }
int main (int argc, char *argv[]) { DIR *cwd_p; struct dirent *thisDir_p; acl_t acl; acl_entry_t entry; acl_tag_t tag; int entryId; uid_t *uid_p, cmdlineUid; gid_t *gid_p, cmdlineGid; UorG_t entryType; // cmdline args if (argc != 3) { usage (argv[0]); return 1; } switch (argv[1][0]) { case 'u': entryType = USER_e; if (!user_id_from_name (argv[2], &cmdlineUid)) { fprintf (stderr, "user_id_from_name() failure\n"); return 1; } break; case 'g': entryType = GROUP_e; if (!group_id_from_name (argv[2], &cmdlineGid)) { fprintf (stderr, "group_id_from_name() failure\n"); return 1; } break; default: usage (argv[0]); return 1; } cwd_p = opendir ("."); if (cwd_p == NULL) { perror ("opendir(.)"); return 1; } while ((thisDir_p = readdir (cwd_p)) != NULL) { if (thisDir_p->d_type != DT_REG) continue; acl = acl_get_file (thisDir_p->d_name, ACL_TYPE_ACCESS); if (acl == NULL) continue; for (entryId=ACL_FIRST_ENTRY; ; entryId=ACL_NEXT_ENTRY) { if (acl_get_entry (acl, entryId, &entry) == -1) break; if (acl_get_tag_type (entry, &tag) == -1) break; if (entryType == USER_e) { if (tag == ACL_USER) { uid_p = acl_get_qualifier (entry); if (uid_p == NULL) break; if (*uid_p == cmdlineUid) printf ("acl user matches: %s\n", thisDir_p->d_name); acl_free (uid_p); } } else { if (tag == ACL_GROUP) { gid_p = acl_get_qualifier (entry); if (gid_p == NULL) break; if (*gid_p == cmdlineGid) printf ("acl grp matches: %s\n", thisDir_p->d_name); acl_free (gid_p); } } } acl_free (acl); } closedir (cwd_p); return 0; }