31f3a62155f7f6d0d1ab44ad088fed413ded3053
[adu.git] / user.h
1 /** The columns of the id table. */
2 enum user_table_columns {
3         /** The numer of the directory. */
4         UT_DIR_NUM,
5         /** The number of bytes of all regular files in this dir owned by this id. */
6         UT_BYTES,
7         /** The number of files in this dir owned by this id. */
8         UT_FILES,
9         /** Number of columns in this table. */
10         NUM_UT_COLUMNS
11 };
12
13 /** Information about one admissible user. */
14 struct user_info {
15         /** User ID. */
16         uint32_t uid;
17         /** \sa enum uid_info_flags. */
18         uint32_t flags;
19         /** The user name.  */
20         char *pw_name;
21         /** The user table of this user.*/
22         struct osl_table *table;
23         /** Total number of files owned by this user. */
24         uint64_t files;
25         /** Total number of bytes owned by this user. */
26         uint64_t bytes;
27         /** Total number of directories that contain at least one file */
28         uint64_t dirs;
29         /** The description of the user table. */
30         struct osl_table_description *desc;
31 };
32
33 /** An opaque struct that contains info about which users are admissible. */
34 struct uid_range;
35
36 enum search_uid_flags {
37         OPEN_USER_TABLE = 1,
38         CREATE_USER_TABLE = 2,
39 };
40 int search_uid(uint32_t uid, struct uid_range *urs,
41                 enum search_uid_flags flags, struct user_info **ui_ptr);
42
43 int read_uid_file(struct uid_range *admissible_uids);
44 int write_uid_file(void);
45
46 void create_hash_table(unsigned bits);
47 void sort_hash_table(int (*comp)(const void *, const void *));
48
49 int for_each_admissible_user(int (*func)(struct user_info *, void *),
50                 void *data);
51 int parse_uid_arg(const char *orig_arg, struct uid_range **ur);
52 int append_users(char **users, int num_users,
53                 struct uid_range **admissible_uids, int num_uid_ranges);
54 void close_user_tables(void);