This is used by dest_mode(). */
| 1082 | |
| 1083 | /* This is used by dest_mode(). */ |
| 1084 | int default_perms_for_dir(const char *dir) |
| 1085 | { |
| 1086 | rsync_acl racl; |
| 1087 | SMB_ACL_T sacl; |
| 1088 | BOOL ok; |
| 1089 | int perms; |
| 1090 | |
| 1091 | if (dir == NULL) |
| 1092 | dir = "."; |
| 1093 | perms = ACCESSPERMS & ~orig_umask; |
| 1094 | /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */ |
| 1095 | sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT); |
| 1096 | if (sacl == NULL) { |
| 1097 | /* Couldn't get an ACL. Darn. */ |
| 1098 | switch (errno) { |
| 1099 | case EINVAL: |
| 1100 | /* If SMB_ACL_TYPE_DEFAULT isn't valid, then the ACLs must be non-POSIX. */ |
| 1101 | break; |
| 1102 | #ifdef ENOTSUP |
| 1103 | case ENOTSUP: |
| 1104 | #endif |
| 1105 | case ENOSYS: |
| 1106 | /* No ACLs are available. */ |
| 1107 | break; |
| 1108 | default: |
| 1109 | if (dry_run && errno == ENOENT) { |
| 1110 | /* We're doing a dry run, so the containing directory |
| 1111 | * wasn't actually created. Don't worry about it. */ |
| 1112 | break; |
| 1113 | } |
| 1114 | rprintf(FWARNING, |
| 1115 | "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n", |
| 1116 | dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno)); |
| 1117 | } |
| 1118 | return perms; |
| 1119 | } |
| 1120 | |
| 1121 | /* Convert it. */ |
| 1122 | racl = empty_rsync_acl; |
| 1123 | ok = unpack_smb_acl(sacl, &racl); |
| 1124 | sys_acl_free_acl(sacl); |
| 1125 | if (!ok) { |
| 1126 | rprintf(FWARNING, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n"); |
| 1127 | return perms; |
| 1128 | } |
| 1129 | |
| 1130 | /* Apply the permission-bit entries of the default ACL, if any. */ |
| 1131 | if (racl.user_obj != NO_ENTRY) { |
| 1132 | perms = rsync_acl_get_perms(&racl); |
| 1133 | if (DEBUG_GTE(ACL, 1)) |
| 1134 | rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir); |
| 1135 | } |
| 1136 | |
| 1137 | rsync_acl_free(&racl); |
| 1138 | return perms; |
| 1139 | } |
| 1140 | |
| 1141 | #endif /* SUPPORT_ACLS */ |
no test coverage detected