/**
- * @brief Update (or create) an entry in an @b minimal ACL.
- *
- * This function will not work if @c aclp contains extended
- * entries. This is fine for our purposes, since we call @c wipe_acls
- * on each path before applying the default to it.
- *
- * The assumption that there are no extended entries makes things much
- * simpler. For example, we only have to update the @c ACL_USER_OBJ,
- * @c ACL_GROUP_OBJ, and @c ACL_OTHER entries -- all others can simply
- * be created anew. This means we don't have to fool around comparing
- * named-user/group entries.
+ * @brief Update an entry in an @b minimal ACL.
*
* @param aclp
- * A pointer to the acl_t structure whose entry we want to modify.
+ * A pointer to the acl_t structure whose entry we want to update.
*
* @param entry
- * The new entry. If @c entry contains a user/group/other entry, we
- * update the existing one. Otherwise we create a new entry.
- *
- * @return If there is an unexpected library error, @c ACL_ERROR is
- * returned. Otherwise, @c ACL_SUCCESS.
+ * The new entry.
*
+ * @return
+ * - @c ACL_SUCCESS - If we update an existing entry.
+ * - @c ACL_FAILURE - If we don't find an entry to update.
+ * - @c ACL_ERROR - Unexpected library error.
*/
-int acl_set_entry(acl_t* aclp, acl_entry_t entry) {
+int acl_update_entry(acl_t aclp, acl_entry_t entry) {
if (aclp == NULL || entry == NULL) {
errno = EINVAL;
- perror("acl_set_entry (args)");
+ perror("acl_update_entry (args)");
return ACL_ERROR;
}
acl_tag_t entry_tag;
if (acl_get_tag_type(entry, &entry_tag) == ACL_ERROR) {
- perror("acl_set_entry (acl_get_tag_type)");
+ perror("acl_update_entry (acl_get_tag_type)");
return ACL_ERROR;
}
acl_permset_t entry_permset;
if (acl_get_permset(entry, &entry_permset) == ACL_ERROR) {
- perror("acl_set_entry (acl_get_permset)");
+ perror("acl_update_entry (acl_get_permset)");
return ACL_ERROR;
}
acl_entry_t existing_entry;
/* Loop through the given ACL looking for matching entries. */
- int result = acl_get_entry(*aclp, ACL_FIRST_ENTRY, &existing_entry);
+ int result = acl_get_entry(aclp, ACL_FIRST_ENTRY, &existing_entry);
while (result == ACL_SUCCESS) {
acl_tag_t existing_tag = ACL_UNDEFINED_TAG;
if (existing_tag == entry_tag) {
/* If we update something, we're done and return ACL_SUCCESS */
if (acl_set_permset(existing_entry, entry_permset) == ACL_ERROR) {
- perror("acl_set_entry (acl_set_permset)");
+ perror("acl_update_entry (acl_set_permset)");
return ACL_ERROR;
}
return ACL_SUCCESS;
}
- result = acl_get_entry(*aclp, ACL_NEXT_ENTRY, &existing_entry);
+ result = acl_get_entry(aclp, ACL_NEXT_ENTRY, &existing_entry);
}
/* This catches both the initial acl_get_entry and the ones at the
end of the loop. */
if (result == ACL_ERROR) {
- perror("acl_set_entry (acl_get_entry)");
- return ACL_ERROR;
- }
-
- /* If we've made it this far, we need to add a new entry to the
- ACL. */
- acl_entry_t new_entry;
-
- /* The acl_create_entry() function can allocate new memory and/or
- * change the location of the ACL structure entirely. When that
- * happens, the value pointed to by aclp is updated, which means
- * that a new acl_t gets "passed out" to our caller, eventually to
- * be fed to acl_free(). In other words, we should still be freeing
- * the right thing, even if the value pointed to by aclp changes.
- */
- if (acl_create_entry(aclp, &new_entry) == ACL_ERROR) {
- perror("acl_set_entry (acl_create_entry)");
- return ACL_ERROR;
- }
-
- if (acl_set_tag_type(new_entry, entry_tag) == ACL_ERROR) {
- perror("acl_set_entry (acl_set_tag_type)");
+ perror("acl_update_entry (acl_get_entry)");
return ACL_ERROR;
}
- if (acl_set_permset(new_entry, entry_permset) == ACL_ERROR) {
- perror("acl_set_entry (acl_set_permset)");
- return ACL_ERROR;
- }
-
- if (entry_tag == ACL_USER || entry_tag == ACL_GROUP) {
- /* We need to set the qualifier too. */
- void* entry_qual = acl_get_qualifier(entry);
- if (entry_qual == (void*)NULL) {
- perror("acl_set_entry (acl_get_qualifier)");
- return ACL_ERROR;
- }
-
- if (acl_set_qualifier(new_entry, entry_qual) == ACL_ERROR) {
- perror("acl_set_entry (acl_set_qualifier)");
- return ACL_ERROR;
- }
- }
-
- return ACL_SUCCESS;
+ return ACL_FAILURE;
}
}
}
- /* Finally, add the permset to the access ACL. It's actually
- * important that we pass in the address of "new_acl" here, and not
- * "new_acl" itself. Why? The call to acl_create_entry() within
- * acl_set_entry() can allocate new memory for the entry.
- * Sometimes that can be done in-place, in which case everything
- * is cool and the new memory gets released when we call
- * acl_free(acl).
- *
- * But occasionally, the whole ACL structure will have to be moved
- * in order to allocate the extra space. When that happens,
- * acl_create_entry() modifies the pointer it was passed (in this
- * case, &acl) to point to the new location. We want to call
- * acl_free() on the new location, and since acl_free() gets
- * called right here, we need acl_create_entry() to update the
- * value of "new_acl". To do that, it needs the address of "new_acl".
- */
-
- if (acl_set_entry(&new_acl, entry) == ACL_ERROR) {
- perror("apply_default_acl_ex (acl_set_entry)");
+ if (acl_update_entry(new_acl, entry) == ACL_ERROR) {
+ perror("apply_default_acl_ex (acl_update_entry)");
result = ACL_ERROR;
goto cleanup;
}