From 1b9a29344c7641572288f38d709badf576b86e97 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 10 Nov 2008 01:28:58 +0100 Subject: [PATCH] user.c: Add some more source code documentation. --- user.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/user.c b/user.c index 5151025..0de05d0 100644 --- a/user.c +++ b/user.c @@ -29,6 +29,7 @@ struct uid_range { uint32_t high; }; +/** Iterate over all uid ranges. */ #define FOR_EACH_UID_RANGE(ur, urs) for (ur = urs; ur->low <= ur->high; ur++) /** Flags for the user hash table. */ @@ -38,6 +39,7 @@ enum uid_info_flags { /** Whether this uid should be taken into account. */ UI_FL_ADMISSIBLE = 2, }; + /* * Contains info for each user that owns at least one regular file. * @@ -144,6 +146,15 @@ out: return ret; } +/** + * Convert the --uid argument to an array of uid ranges. + * + * \param orig_arg The argument to the --uid option. + * \param ur Result pointer. + * + * Returns Negative on errors. On success, the number of uid ranges + * is returned. + */ int parse_uid_arg(const char *orig_arg, struct uid_range **ur) { char *arg, **argv; @@ -192,6 +203,22 @@ out: return ret; } +/** + * Add each given user to the array of admissible users. + * + * \param users Array of user names to add. + * \param num_users Length of \a users. + * \param admissible_uids The users which are already admissible. + * \param num_uid_ranges The number of intervals of \a admissible_uids. + * + * For each given user, the function checks whether that user is already + * admissible, i.e. its uid is contained in one of the ranges given by \a + * admissible_uids. If it is, the function ignores that user. Otherwise, a new + * length-one range consisting of that uid only is appended to \a + * admissible_uids. + * + * \return Negative on errors, the new number of uid ranges on success. + */ int append_users(char **users, int num_users, struct uid_range **admissible_uids, int num_uid_ranges) { @@ -273,9 +300,23 @@ err: return ret; } +/** Iterate over each user in the uid hash table. */ #define FOR_EACH_USER(ui) for (ui = uid_hash_table; ui < \ uid_hash_table + uid_hash_table_size; ui++) + +/** + * Execute the given function for each admissible user. + * + * \param func The function to execute. + * \param data Arbitrary pointer. + * + * This function calls \a func for each admissible user in the uid hash table. + * The \a data pointer is passed as the second argument to \a func. + * + * \return As soon as \a func returns a negative value, the loop is terminated + * and that negative value is returned. Otherwise, the function returns 1. + */ int for_each_admissible_user(int (*func)(struct user_info *, void *), void *data) { -- 2.39.5