2 Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
20 #include <sys/types.h>
27 #include <atalk/afp.h>
28 #include <atalk/util.h>
29 #include <atalk/logger.h>
31 /* Removes all non-trivial ACLs from object. Returns full AFPERR code. */
32 int remove_acl(const char *name)
34 int ret,i, ace_count, trivial_aces, new_aces_count;
35 ace_t *old_aces = NULL;
36 ace_t *new_aces = NULL;
38 LOG(log_debug9, logtype_afpd, "remove_acl: BEGIN");
40 /* Get existing ACL and count trivial ACEs */
41 if ((ace_count = get_nfsv4_acl(name, &old_aces)) == -1)
44 for ( i=0; i < ace_count; i++) {
45 if (old_aces[i].a_flags & (ACE_OWNER | ACE_GROUP | ACE_EVERYONE))
49 /* malloc buffer for new ACL */
50 if ((new_aces = malloc(trivial_aces * sizeof(ace_t))) == NULL) {
51 LOG(log_error, logtype_afpd, "remove_acl: malloc %s", strerror(errno));
56 /* Now copy the trivial ACEs */
58 for (i=0; i < ace_count; i++) {
59 if (old_aces[i].a_flags & (ACE_OWNER | ACE_GROUP | ACE_EVERYONE)) {
60 memcpy(&new_aces[new_aces_count], &old_aces[i], sizeof(ace_t));
65 if ( (acl(name, ACE_SETACL, trivial_aces, new_aces)) == 0)
68 LOG(log_error, logtype_afpd, "set_acl: error setting acl: %s", strerror(errno));
69 if (errno == (EACCES | EPERM))
71 else if (errno == ENOENT)
81 LOG(log_debug9, logtype_afpd, "remove_acl: END");