| 1 | To use this patch, run these commands for a successful build: |
| 2 | |
| 3 | patch -p1 <patches/acls.diff |
| 4 | ./prepare-source |
| 5 | ./configure --enable-acl-support |
| 6 | make |
| 7 | |
| 8 | See the --acls (-A) option in the revised man page for a note on using this |
| 9 | latest ACL-enabling patch to send files to an older ACL-enabled rsync. |
| 10 | |
| 11 | --- old/Makefile.in |
| 12 | +++ new/Makefile.in |
| 13 | @@ -26,15 +26,15 @@ VERSION=@VERSION@ |
| 14 | .SUFFIXES: |
| 15 | .SUFFIXES: .c .o |
| 16 | |
| 17 | -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h |
| 18 | +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h |
| 19 | LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \ |
| 20 | - lib/permstring.o lib/pool_alloc.o @LIBOBJS@ |
| 21 | + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@ |
| 22 | ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \ |
| 23 | zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o |
| 24 | OBJS1=flist.o rsync.o generator.o receiver.o cleanup.o sender.o exclude.o \ |
| 25 | util.o main.o checksum.o match.o syscall.o log.o backup.o |
| 26 | OBJS2=options.o io.o compat.o hlink.o token.o uidlist.o socket.o \ |
| 27 | - fileio.o batch.o clientname.o chmod.o |
| 28 | + fileio.o batch.o clientname.o chmod.o acls.o |
| 29 | OBJS3=progress.o pipe.o |
| 30 | DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o |
| 31 | popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \ |
| 32 | --- old/acls.c |
| 33 | +++ new/acls.c |
| 34 | @@ -0,0 +1,1094 @@ |
| 35 | +/* |
| 36 | + * Handle passing Access Control Lists between systems. |
| 37 | + * |
| 38 | + * Copyright (C) 1996 Andrew Tridgell |
| 39 | + * Copyright (C) 1996 Paul Mackerras |
| 40 | + * Copyright (C) 2006 Wayne Davison |
| 41 | + * |
| 42 | + * This program is free software; you can redistribute it and/or modify |
| 43 | + * it under the terms of the GNU General Public License as published by |
| 44 | + * the Free Software Foundation; either version 2 of the License, or |
| 45 | + * (at your option) any later version. |
| 46 | + * |
| 47 | + * This program is distributed in the hope that it will be useful, |
| 48 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 49 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 50 | + * GNU General Public License for more details. |
| 51 | + * |
| 52 | + * You should have received a copy of the GNU General Public License along |
| 53 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 54 | + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
| 55 | + */ |
| 56 | + |
| 57 | +#include "rsync.h" |
| 58 | +#include "lib/sysacls.h" |
| 59 | + |
| 60 | +#ifdef SUPPORT_ACLS |
| 61 | + |
| 62 | +extern int dry_run; |
| 63 | +extern int read_only; |
| 64 | +extern int list_only; |
| 65 | +extern int orig_umask; |
| 66 | +extern int protocol_version; |
| 67 | + |
| 68 | +/* === ACL structures === */ |
| 69 | + |
| 70 | +typedef struct { |
| 71 | + id_t id; |
| 72 | + uchar access; |
| 73 | +} id_access; |
| 74 | + |
| 75 | +typedef struct { |
| 76 | + id_access *idas; |
| 77 | + int count; |
| 78 | +} ida_entries; |
| 79 | + |
| 80 | +#define NO_ENTRY ((uchar)0x80) |
| 81 | +typedef struct rsync_acl { |
| 82 | + ida_entries users; |
| 83 | + ida_entries groups; |
| 84 | + /* These will be NO_ENTRY if there's no such entry. */ |
| 85 | + uchar user_obj; |
| 86 | + uchar group_obj; |
| 87 | + uchar mask; |
| 88 | + uchar other; |
| 89 | +} rsync_acl; |
| 90 | + |
| 91 | +typedef struct { |
| 92 | + rsync_acl racl; |
| 93 | + SMB_ACL_T sacl; |
| 94 | +} acl_duo; |
| 95 | + |
| 96 | +static const rsync_acl empty_rsync_acl = { |
| 97 | + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY |
| 98 | +}; |
| 99 | + |
| 100 | +static item_list access_acl_list = EMPTY_ITEM_LIST; |
| 101 | +static item_list default_acl_list = EMPTY_ITEM_LIST; |
| 102 | + |
| 103 | +/* === Calculations on ACL types === */ |
| 104 | + |
| 105 | +static const char *str_acl_type(SMB_ACL_TYPE_T type) |
| 106 | +{ |
| 107 | + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" |
| 108 | + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" |
| 109 | + : "unknown SMB_ACL_TYPE_T"; |
| 110 | +} |
| 111 | + |
| 112 | +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t)) |
| 113 | +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT) |
| 114 | + |
| 115 | +static int count_racl_entries(const rsync_acl *racl) |
| 116 | +{ |
| 117 | + return racl->users.count + racl->groups.count |
| 118 | + + (racl->user_obj != NO_ENTRY) |
| 119 | + + (racl->group_obj != NO_ENTRY) |
| 120 | + + (racl->mask != NO_ENTRY) |
| 121 | + + (racl->other != NO_ENTRY); |
| 122 | +} |
| 123 | + |
| 124 | +static int calc_sacl_entries(const rsync_acl *racl) |
| 125 | +{ |
| 126 | + /* A System ACL always gets user/group/other permission entries. */ |
| 127 | + return racl->users.count + racl->groups.count |
| 128 | +#ifdef ACLS_NEED_MASK |
| 129 | + + 4; |
| 130 | +#else |
| 131 | + + (racl->mask != NO_ENTRY) + 3; |
| 132 | +#endif |
| 133 | +} |
| 134 | + |
| 135 | +/* Extracts and returns the permission bits from the ACL. This cannot be |
| 136 | + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */ |
| 137 | +static int rsync_acl_get_perms(const rsync_acl *racl) |
| 138 | +{ |
| 139 | + return (racl->user_obj << 6) |
| 140 | + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3) |
| 141 | + + racl->other; |
| 142 | +} |
| 143 | + |
| 144 | +/* Removes the permission-bit entries from the ACL because these |
| 145 | + * can be reconstructed from the file's mode. */ |
| 146 | +static void rsync_acl_strip_perms(rsync_acl *racl) |
| 147 | +{ |
| 148 | + racl->user_obj = NO_ENTRY; |
| 149 | + if (racl->mask == NO_ENTRY) |
| 150 | + racl->group_obj = NO_ENTRY; |
| 151 | + else { |
| 152 | + if (racl->group_obj == racl->mask) |
| 153 | + racl->group_obj = NO_ENTRY; |
| 154 | + racl->mask = NO_ENTRY; |
| 155 | + } |
| 156 | + racl->other = NO_ENTRY; |
| 157 | +} |
| 158 | + |
| 159 | +/* Given an empty rsync_acl, fake up the permission bits. */ |
| 160 | +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode) |
| 161 | +{ |
| 162 | + racl->user_obj = (mode >> 6) & 7; |
| 163 | + racl->group_obj = (mode >> 3) & 7; |
| 164 | + racl->other = mode & 7; |
| 165 | +} |
| 166 | + |
| 167 | +/* === Rsync ACL functions === */ |
| 168 | + |
| 169 | +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2) |
| 170 | +{ |
| 171 | + id_access *ida1, *ida2; |
| 172 | + int count = ial1->count; |
| 173 | + if (count != ial2->count) |
| 174 | + return False; |
| 175 | + ida1 = ial1->idas; |
| 176 | + ida2 = ial2->idas; |
| 177 | + for (; count--; ida1++, ida2++) { |
| 178 | + if (ida1->access != ida2->access || ida1->id != ida2->id) |
| 179 | + return False; |
| 180 | + } |
| 181 | + return True; |
| 182 | +} |
| 183 | + |
| 184 | +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2) |
| 185 | +{ |
| 186 | + return racl1->user_obj == racl2->user_obj |
| 187 | + && racl1->group_obj == racl2->group_obj |
| 188 | + && racl1->mask == racl2->mask |
| 189 | + && racl1->other == racl2->other |
| 190 | + && ida_entries_equal(&racl1->users, &racl2->users) |
| 191 | + && ida_entries_equal(&racl1->groups, &racl2->groups); |
| 192 | +} |
| 193 | + |
| 194 | +/* Are the extended (non-permission-bit) entries equal? If so, the rest of |
| 195 | + * the ACL will be handled by the normal mode-preservation code. This is |
| 196 | + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated |
| 197 | + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means |
| 198 | + * that it might have several of its permission objects set to NO_ENTRY. */ |
| 199 | +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1, |
| 200 | + const rsync_acl *racl2, mode_t m) |
| 201 | +{ |
| 202 | + if ((racl1->mask ^ racl2->mask) & NO_ENTRY) |
| 203 | + return False; /* One has a mask and the other doesn't */ |
| 204 | + |
| 205 | + /* When there's a mask, the group_obj becomes an extended entry. */ |
| 206 | + if (racl1->mask != NO_ENTRY) { |
| 207 | + /* A condensed rsync_acl with a mask can only have no |
| 208 | + * group_obj when it was identical to the mask. This |
| 209 | + * means that it was also identical to the group attrs |
| 210 | + * from the mode. */ |
| 211 | + if (racl2->group_obj == NO_ENTRY) { |
| 212 | + if (racl1->group_obj != ((m >> 3) & 7)) |
| 213 | + return False; |
| 214 | + } else if (racl1->group_obj != racl2->group_obj) |
| 215 | + return False; |
| 216 | + } |
| 217 | + return ida_entries_equal(&racl1->users, &racl2->users) |
| 218 | + && ida_entries_equal(&racl1->groups, &racl2->groups); |
| 219 | +} |
| 220 | + |
| 221 | +static void rsync_acl_free(rsync_acl *racl) |
| 222 | +{ |
| 223 | + if (racl->users.idas) |
| 224 | + free(racl->users.idas); |
| 225 | + if (racl->groups.idas) |
| 226 | + free(racl->groups.idas); |
| 227 | + *racl = empty_rsync_acl; |
| 228 | +} |
| 229 | + |
| 230 | +void free_acl(statx *sxp) |
| 231 | +{ |
| 232 | + if (sxp->acc_acl) { |
| 233 | + rsync_acl_free(sxp->acc_acl); |
| 234 | + free(sxp->acc_acl); |
| 235 | + sxp->acc_acl = NULL; |
| 236 | + } |
| 237 | + if (sxp->def_acl) { |
| 238 | + rsync_acl_free(sxp->def_acl); |
| 239 | + free(sxp->def_acl); |
| 240 | + sxp->def_acl = NULL; |
| 241 | + } |
| 242 | +} |
| 243 | + |
| 244 | +static int id_access_sorter(const void *r1, const void *r2) |
| 245 | +{ |
| 246 | + id_access *ida1 = (id_access *)r1; |
| 247 | + id_access *ida2 = (id_access *)r2; |
| 248 | + id_t rid1 = ida1->id, rid2 = ida2->id; |
| 249 | + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1; |
| 250 | +} |
| 251 | + |
| 252 | +static void sort_ida_entries(ida_entries *idal) |
| 253 | +{ |
| 254 | + if (!idal->count) |
| 255 | + return; |
| 256 | + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter); |
| 257 | +} |
| 258 | + |
| 259 | +/* Transfer the count id_access items out of the temp_ida_list into either |
| 260 | + * the users or groups ida_entries list in racl. */ |
| 261 | +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type) |
| 262 | +{ |
| 263 | + id_access *idas; |
| 264 | + ida_entries *ent; |
| 265 | + |
| 266 | + if (temp_ida_list->count) { |
| 267 | + int cnt = temp_ida_list->count; |
| 268 | + id_access *temp_idas = temp_ida_list->items; |
| 269 | + if (!(idas = new_array(id_access, cnt))) |
| 270 | + out_of_memory("save_idas"); |
| 271 | + memcpy(idas, temp_idas, cnt * sizeof *temp_idas); |
| 272 | + } else |
| 273 | + idas = NULL; |
| 274 | + |
| 275 | + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups; |
| 276 | + |
| 277 | + if (ent->count) { |
| 278 | + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type); |
| 279 | + exit_cleanup(RERR_UNSUPPORTED); |
| 280 | + } |
| 281 | + ent->count = temp_ida_list->count; |
| 282 | + ent->idas = idas; |
| 283 | + |
| 284 | + /* Truncate the temporary list now that its idas have been saved. */ |
| 285 | + temp_ida_list->count = 0; |
| 286 | +} |
| 287 | + |
| 288 | +/* === System ACLs === */ |
| 289 | + |
| 290 | +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */ |
| 291 | +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl) |
| 292 | +{ |
| 293 | + static item_list temp_ida_list = EMPTY_ITEM_LIST; |
| 294 | + SMB_ACL_TAG_T prior_list_type = 0; |
| 295 | + SMB_ACL_ENTRY_T entry; |
| 296 | + const char *errfun; |
| 297 | + int rc; |
| 298 | + |
| 299 | + errfun = "sys_acl_get_entry"; |
| 300 | + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry); |
| 301 | + rc == 1; |
| 302 | + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) { |
| 303 | + SMB_ACL_TAG_T tag_type; |
| 304 | + SMB_ACL_PERMSET_T permset; |
| 305 | + uchar access; |
| 306 | + void *qualifier; |
| 307 | + id_access *ida; |
| 308 | + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) { |
| 309 | + errfun = "sys_acl_get_tag_type"; |
| 310 | + break; |
| 311 | + } |
| 312 | + if ((rc = sys_acl_get_permset(entry, &permset))) { |
| 313 | + errfun = "sys_acl_get_tag_type"; |
| 314 | + break; |
| 315 | + } |
| 316 | + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0) |
| 317 | + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0) |
| 318 | + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0); |
| 319 | + /* continue == done with entry; break == store in temporary ida list */ |
| 320 | + switch (tag_type) { |
| 321 | + case SMB_ACL_USER_OBJ: |
| 322 | + if (racl->user_obj == NO_ENTRY) |
| 323 | + racl->user_obj = access; |
| 324 | + else |
| 325 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n"); |
| 326 | + continue; |
| 327 | + case SMB_ACL_USER: |
| 328 | + break; |
| 329 | + case SMB_ACL_GROUP_OBJ: |
| 330 | + if (racl->group_obj == NO_ENTRY) |
| 331 | + racl->group_obj = access; |
| 332 | + else |
| 333 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n"); |
| 334 | + continue; |
| 335 | + case SMB_ACL_GROUP: |
| 336 | + break; |
| 337 | + case SMB_ACL_MASK: |
| 338 | + if (racl->mask == NO_ENTRY) |
| 339 | + racl->mask = access; |
| 340 | + else |
| 341 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n"); |
| 342 | + continue; |
| 343 | + case SMB_ACL_OTHER: |
| 344 | + if (racl->other == NO_ENTRY) |
| 345 | + racl->other = access; |
| 346 | + else |
| 347 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n"); |
| 348 | + continue; |
| 349 | + default: |
| 350 | + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n"); |
| 351 | + continue; |
| 352 | + } |
| 353 | + if (!(qualifier = sys_acl_get_qualifier(entry))) { |
| 354 | + errfun = "sys_acl_get_tag_type"; |
| 355 | + rc = EINVAL; |
| 356 | + break; |
| 357 | + } |
| 358 | + if (tag_type != prior_list_type) { |
| 359 | + if (prior_list_type) |
| 360 | + save_idas(&temp_ida_list, racl, prior_list_type); |
| 361 | + prior_list_type = tag_type; |
| 362 | + } |
| 363 | + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10); |
| 364 | + ida->id = *((id_t *)qualifier); |
| 365 | + ida->access = access; |
| 366 | + sys_acl_free_qualifier(qualifier, tag_type); |
| 367 | + } |
| 368 | + if (rc) { |
| 369 | + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun); |
| 370 | + rsync_acl_free(racl); |
| 371 | + return False; |
| 372 | + } |
| 373 | + if (prior_list_type) |
| 374 | + save_idas(&temp_ida_list, racl, prior_list_type); |
| 375 | + |
| 376 | + sort_ida_entries(&racl->users); |
| 377 | + sort_ida_entries(&racl->groups); |
| 378 | + |
| 379 | +#ifdef ACLS_NEED_MASK |
| 380 | + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) { |
| 381 | + /* Throw away a superfluous mask, but mask off the |
| 382 | + * group perms with it first. */ |
| 383 | + racl->group_obj &= racl->mask; |
| 384 | + racl->mask = NO_ENTRY; |
| 385 | + } |
| 386 | +#endif |
| 387 | + |
| 388 | + return True; |
| 389 | +} |
| 390 | + |
| 391 | +/* Synactic sugar for system calls */ |
| 392 | + |
| 393 | +#define CALL_OR_ERROR(func,args,str) \ |
| 394 | + do { \ |
| 395 | + if (func args) { \ |
| 396 | + errfun = str; \ |
| 397 | + goto error_exit; \ |
| 398 | + } \ |
| 399 | + } while (0) |
| 400 | + |
| 401 | +#define COE(func,args) CALL_OR_ERROR(func,args,#func) |
| 402 | +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL) |
| 403 | + |
| 404 | +/* Store the permissions in the system ACL entry. */ |
| 405 | +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry) |
| 406 | +{ |
| 407 | + const char *errfun = NULL; |
| 408 | + SMB_ACL_PERMSET_T permset; |
| 409 | + |
| 410 | + COE( sys_acl_get_permset,(entry, &permset) ); |
| 411 | + COE( sys_acl_clear_perms,(permset) ); |
| 412 | + if (access & 4) |
| 413 | + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) ); |
| 414 | + if (access & 2) |
| 415 | + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) ); |
| 416 | + if (access & 1) |
| 417 | + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) ); |
| 418 | + COE( sys_acl_set_permset,(entry, permset) ); |
| 419 | + |
| 420 | + return 0; |
| 421 | + |
| 422 | + error_exit: |
| 423 | + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun); |
| 424 | + return -1; |
| 425 | +} |
| 426 | + |
| 427 | +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */ |
| 428 | +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl) |
| 429 | +{ |
| 430 | +#ifdef ACLS_NEED_MASK |
| 431 | + uchar mask_bits; |
| 432 | +#endif |
| 433 | + size_t count; |
| 434 | + id_access *ida; |
| 435 | + const char *errfun = NULL; |
| 436 | + SMB_ACL_ENTRY_T entry; |
| 437 | + |
| 438 | + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) { |
| 439 | + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()"); |
| 440 | + return False; |
| 441 | + } |
| 442 | + |
| 443 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
| 444 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) ); |
| 445 | + COE2( store_access_in_entry,(racl->user_obj & 7, entry) ); |
| 446 | + |
| 447 | + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) { |
| 448 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
| 449 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) ); |
| 450 | + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) ); |
| 451 | + COE2( store_access_in_entry,(ida->access, entry) ); |
| 452 | + } |
| 453 | + |
| 454 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
| 455 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) ); |
| 456 | + COE2( store_access_in_entry,(racl->group_obj & 7, entry) ); |
| 457 | + |
| 458 | + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) { |
| 459 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
| 460 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) ); |
| 461 | + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) ); |
| 462 | + COE2( store_access_in_entry,(ida->access, entry) ); |
| 463 | + } |
| 464 | + |
| 465 | +#ifdef ACLS_NEED_MASK |
| 466 | + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask; |
| 467 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
| 468 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) ); |
| 469 | + COE2( store_access_in_entry,(mask_bits, entry) ); |
| 470 | +#else |
| 471 | + if (racl->mask != NO_ENTRY) { |
| 472 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
| 473 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) ); |
| 474 | + COE2( store_access_in_entry,(racl->mask, entry) ); |
| 475 | + } |
| 476 | +#endif |
| 477 | + |
| 478 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
| 479 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) ); |
| 480 | + COE2( store_access_in_entry,(racl->other & 7, entry) ); |
| 481 | + |
| 482 | +#ifdef DEBUG |
| 483 | + if (sys_acl_valid(*smb_acl) < 0) |
| 484 | + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n"); |
| 485 | +#endif |
| 486 | + |
| 487 | + return True; |
| 488 | + |
| 489 | + error_exit: |
| 490 | + if (errfun) { |
| 491 | + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun); |
| 492 | + } |
| 493 | + sys_acl_free_acl(*smb_acl); |
| 494 | + return False; |
| 495 | +} |
| 496 | + |
| 497 | +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type, |
| 498 | + const item_list *racl_list, |
| 499 | + const rsync_acl *racl) |
| 500 | +{ |
| 501 | + static int access_match = -1, default_match = -1; |
| 502 | + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match; |
| 503 | + size_t count = racl_list->count; |
| 504 | + |
| 505 | + /* If this is the first time through or we didn't match the last |
| 506 | + * time, then start at the end of the list, which should be the |
| 507 | + * best place to start hunting. */ |
| 508 | + if (*match == -1) |
| 509 | + *match = racl_list->count - 1; |
| 510 | + while (count--) { |
| 511 | + rsync_acl *base = racl_list->items; |
| 512 | + if (rsync_acl_equal(base + *match, racl)) |
| 513 | + return *match; |
| 514 | + if (!(*match)--) |
| 515 | + *match = racl_list->count - 1; |
| 516 | + } |
| 517 | + |
| 518 | + *match = -1; |
| 519 | + return *match; |
| 520 | +} |
| 521 | + |
| 522 | +/* Return the Access Control List for the given filename. */ |
| 523 | +int get_acl(const char *fname, statx *sxp) |
| 524 | +{ |
| 525 | + SMB_ACL_TYPE_T type; |
| 526 | + |
| 527 | + if (S_ISLNK(sxp->st.st_mode)) |
| 528 | + return 0; |
| 529 | + |
| 530 | + type = SMB_ACL_TYPE_ACCESS; |
| 531 | + do { |
| 532 | + SMB_ACL_T sacl = sys_acl_get_file(fname, type); |
| 533 | + rsync_acl *racl = new(rsync_acl); |
| 534 | + |
| 535 | + if (!racl) |
| 536 | + out_of_memory("get_acl"); |
| 537 | + *racl = empty_rsync_acl; |
| 538 | + if (type == SMB_ACL_TYPE_ACCESS) |
| 539 | + sxp->acc_acl = racl; |
| 540 | + else |
| 541 | + sxp->def_acl = racl; |
| 542 | + |
| 543 | + if (sacl) { |
| 544 | + BOOL ok = unpack_smb_acl(racl, sacl); |
| 545 | + |
| 546 | + sys_acl_free_acl(sacl); |
| 547 | + if (!ok) { |
| 548 | + free_acl(sxp); |
| 549 | + return -1; |
| 550 | + } |
| 551 | + } else if (errno == ENOTSUP || errno == ENOSYS) { |
| 552 | + /* ACLs are not supported, so pretend we have a basic ACL. */ |
| 553 | + if (type == SMB_ACL_TYPE_ACCESS) |
| 554 | + rsync_acl_fake_perms(racl, sxp->st.st_mode); |
| 555 | + } else { |
| 556 | + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)", |
| 557 | + fname, str_acl_type(type)); |
| 558 | + free_acl(sxp); |
| 559 | + return -1; |
| 560 | + } |
| 561 | + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode)); |
| 562 | + |
| 563 | + return 0; |
| 564 | +} |
| 565 | + |
| 566 | +/* === Send functions === */ |
| 567 | + |
| 568 | +/* The general strategy with the tag_type <-> character mapping is that |
| 569 | + * lowercase implies that no qualifier follows, where uppercase does. |
| 570 | + * A similar idiom for the ACL type (access or default) itself, but |
| 571 | + * lowercase in this instance means there's no ACL following, so the |
| 572 | + * ACL is a repeat, so the receiver should reuse the last of the same |
| 573 | + * type ACL. */ |
| 574 | + |
| 575 | +/* Send the ida list over the file descriptor. */ |
| 576 | +static void send_ida_entries(int f, const ida_entries *idal, char tag_char) |
| 577 | +{ |
| 578 | + id_access *ida; |
| 579 | + size_t count = idal->count; |
| 580 | + for (ida = idal->idas; count--; ida++) { |
| 581 | + write_byte(f, tag_char); |
| 582 | + write_byte(f, ida->access); |
| 583 | + write_int(f, ida->id); |
| 584 | + /* FIXME: sorta wasteful: we should maybe buffer as |
| 585 | + * many ids as max(ACL_USER + ACL_GROUP) objects to |
| 586 | + * keep from making so many calls. */ |
| 587 | + if (tag_char == 'U') |
| 588 | + add_uid(ida->id); |
| 589 | + else |
| 590 | + add_gid(ida->id); |
| 591 | + } |
| 592 | +} |
| 593 | + |
| 594 | +/* Send an rsync ACL over the file descriptor. */ |
| 595 | +static void send_rsync_acl(int f, const rsync_acl *racl) |
| 596 | +{ |
| 597 | + size_t count = count_racl_entries(racl); |
| 598 | + write_int(f, count); |
| 599 | + if (racl->user_obj != NO_ENTRY) { |
| 600 | + write_byte(f, 'u'); |
| 601 | + write_byte(f, racl->user_obj); |
| 602 | + } |
| 603 | + send_ida_entries(f, &racl->users, 'U'); |
| 604 | + if (racl->group_obj != NO_ENTRY) { |
| 605 | + write_byte(f, 'g'); |
| 606 | + write_byte(f, racl->group_obj); |
| 607 | + } |
| 608 | + send_ida_entries(f, &racl->groups, 'G'); |
| 609 | + if (racl->mask != NO_ENTRY) { |
| 610 | + write_byte(f, 'm'); |
| 611 | + write_byte(f, racl->mask); |
| 612 | + } |
| 613 | + if (racl->other != NO_ENTRY) { |
| 614 | + write_byte(f, 'o'); |
| 615 | + write_byte(f, racl->other); |
| 616 | + } |
| 617 | +} |
| 618 | + |
| 619 | +/* Send the ACL from the statx structure down the indicated file descriptor. |
| 620 | + * This also frees the ACL data. */ |
| 621 | +void send_acl(statx *sxp, int f) |
| 622 | +{ |
| 623 | + SMB_ACL_TYPE_T type; |
| 624 | + rsync_acl *racl, *new_racl; |
| 625 | + item_list *racl_list; |
| 626 | + int ndx; |
| 627 | + |
| 628 | + if (S_ISLNK(sxp->st.st_mode)) |
| 629 | + return; |
| 630 | + |
| 631 | + type = SMB_ACL_TYPE_ACCESS; |
| 632 | + racl = sxp->acc_acl; |
| 633 | + racl_list = &access_acl_list; |
| 634 | + do { |
| 635 | + if (!racl) { |
| 636 | + racl = new(rsync_acl); |
| 637 | + if (!racl) |
| 638 | + out_of_memory("send_acl"); |
| 639 | + *racl = empty_rsync_acl; |
| 640 | + if (type == SMB_ACL_TYPE_ACCESS) { |
| 641 | + rsync_acl_fake_perms(racl, sxp->st.st_mode); |
| 642 | + sxp->acc_acl = racl; |
| 643 | + } else |
| 644 | + sxp->def_acl = racl; |
| 645 | + } |
| 646 | + |
| 647 | + /* Avoid sending values that can be inferred from other data. */ |
| 648 | + if (type == SMB_ACL_TYPE_ACCESS && protocol_version >= 30) |
| 649 | + rsync_acl_strip_perms(racl); |
| 650 | + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) { |
| 651 | + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd'); |
| 652 | + write_int(f, ndx); |
| 653 | + } else { |
| 654 | + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000); |
| 655 | + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D'); |
| 656 | + send_rsync_acl(f, racl); |
| 657 | + *new_racl = *racl; |
| 658 | + *racl = empty_rsync_acl; |
| 659 | + } |
| 660 | + racl = sxp->def_acl; |
| 661 | + racl_list = &default_acl_list; |
| 662 | + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode)); |
| 663 | + |
| 664 | + free_acl(sxp); |
| 665 | +} |
| 666 | + |
| 667 | +/* === Receive functions === */ |
| 668 | + |
| 669 | +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type) |
| 670 | +{ |
| 671 | + static item_list temp_ida_list = EMPTY_ITEM_LIST; |
| 672 | + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0; |
| 673 | + uchar computed_mask_bits = 0; |
| 674 | + id_access *ida; |
| 675 | + size_t count; |
| 676 | + |
| 677 | + if (!(count = read_int(f))) |
| 678 | + return; |
| 679 | + |
| 680 | + while (count--) { |
| 681 | + char tag = read_byte(f); |
| 682 | + uchar access = read_byte(f); |
| 683 | + if (access & ~ (4 | 2 | 1)) { |
| 684 | + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n", |
| 685 | + access); |
| 686 | + exit_cleanup(RERR_STREAMIO); |
| 687 | + } |
| 688 | + switch (tag) { |
| 689 | + case 'u': |
| 690 | + if (racl->user_obj != NO_ENTRY) { |
| 691 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n"); |
| 692 | + exit_cleanup(RERR_STREAMIO); |
| 693 | + } |
| 694 | + racl->user_obj = access; |
| 695 | + continue; |
| 696 | + case 'U': |
| 697 | + tag_type = SMB_ACL_USER; |
| 698 | + break; |
| 699 | + case 'g': |
| 700 | + if (racl->group_obj != NO_ENTRY) { |
| 701 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n"); |
| 702 | + exit_cleanup(RERR_STREAMIO); |
| 703 | + } |
| 704 | + racl->group_obj = access; |
| 705 | + continue; |
| 706 | + case 'G': |
| 707 | + tag_type = SMB_ACL_GROUP; |
| 708 | + break; |
| 709 | + case 'm': |
| 710 | + if (racl->mask != NO_ENTRY) { |
| 711 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n"); |
| 712 | + exit_cleanup(RERR_STREAMIO); |
| 713 | + } |
| 714 | + racl->mask = access; |
| 715 | + continue; |
| 716 | + case 'o': |
| 717 | + if (racl->other != NO_ENTRY) { |
| 718 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n"); |
| 719 | + exit_cleanup(RERR_STREAMIO); |
| 720 | + } |
| 721 | + racl->other = access; |
| 722 | + continue; |
| 723 | + default: |
| 724 | + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n", |
| 725 | + tag); |
| 726 | + exit_cleanup(RERR_STREAMIO); |
| 727 | + } |
| 728 | + if (tag_type != prior_list_type) { |
| 729 | + if (prior_list_type) |
| 730 | + save_idas(&temp_ida_list, racl, prior_list_type); |
| 731 | + prior_list_type = tag_type; |
| 732 | + } |
| 733 | + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10); |
| 734 | + ida->access = access; |
| 735 | + ida->id = read_int(f); |
| 736 | + computed_mask_bits |= access; |
| 737 | + } |
| 738 | + if (prior_list_type) |
| 739 | + save_idas(&temp_ida_list, racl, prior_list_type); |
| 740 | + |
| 741 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
| 742 | + /* Ensure that these are never unset. */ |
| 743 | + if (racl->user_obj == NO_ENTRY) |
| 744 | + racl->user_obj = 7; |
| 745 | + if (racl->group_obj == NO_ENTRY) |
| 746 | + racl->group_obj = 0; |
| 747 | + if (racl->other == NO_ENTRY) |
| 748 | + racl->other = 0; |
| 749 | + } |
| 750 | + |
| 751 | + if (!racl->users.count && !racl->groups.count) { |
| 752 | + /* If we received a superfluous mask, throw it away. */ |
| 753 | + if (racl->mask != NO_ENTRY) { |
| 754 | + /* Mask off the group perms with it first. */ |
| 755 | + racl->group_obj &= racl->mask | NO_ENTRY; |
| 756 | + racl->mask = NO_ENTRY; |
| 757 | + } |
| 758 | + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */ |
| 759 | + racl->mask = computed_mask_bits | (racl->group_obj & 7); |
| 760 | +} |
| 761 | + |
| 762 | +/* Receive the ACL info the sender has included for this file-list entry. */ |
| 763 | +void receive_acl(struct file_struct *file, int f) |
| 764 | +{ |
| 765 | + SMB_ACL_TYPE_T type; |
| 766 | + item_list *racl_list; |
| 767 | + |
| 768 | + if (S_ISLNK(file->mode)) |
| 769 | + return; |
| 770 | + |
| 771 | + type = SMB_ACL_TYPE_ACCESS; |
| 772 | + racl_list = &access_acl_list; |
| 773 | + do { |
| 774 | + char tag = read_byte(f); |
| 775 | + int ndx; |
| 776 | + |
| 777 | + if (tag == 'A' || tag == 'a') { |
| 778 | + if (type != SMB_ACL_TYPE_ACCESS) { |
| 779 | + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n", |
| 780 | + f_name(file, NULL)); |
| 781 | + exit_cleanup(RERR_STREAMIO); |
| 782 | + } |
| 783 | + } else if (tag == 'D' || tag == 'd') { |
| 784 | + if (type == SMB_ACL_TYPE_ACCESS) { |
| 785 | + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n", |
| 786 | + f_name(file, NULL)); |
| 787 | + exit_cleanup(RERR_STREAMIO); |
| 788 | + } |
| 789 | + } else { |
| 790 | + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n", |
| 791 | + f_name(file, NULL), tag); |
| 792 | + exit_cleanup(RERR_STREAMIO); |
| 793 | + } |
| 794 | + if (tag == 'A' || tag == 'D') { |
| 795 | + acl_duo *duo_item; |
| 796 | + ndx = racl_list->count; |
| 797 | + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000); |
| 798 | + duo_item->racl = empty_rsync_acl; |
| 799 | + receive_rsync_acl(&duo_item->racl, f, type); |
| 800 | + duo_item->sacl = NULL; |
| 801 | + } else { |
| 802 | + ndx = read_int(f); |
| 803 | + if (ndx < 0 || (size_t)ndx >= racl_list->count) { |
| 804 | + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n", |
| 805 | + f_name(file, NULL), str_acl_type(type), ndx); |
| 806 | + exit_cleanup(RERR_STREAMIO); |
| 807 | + } |
| 808 | + } |
| 809 | + if (type == SMB_ACL_TYPE_ACCESS) |
| 810 | + F_ACL(file) = ndx; |
| 811 | + else |
| 812 | + F_DEF_ACL(file) = ndx; |
| 813 | + racl_list = &default_acl_list; |
| 814 | + } while (BUMP_TYPE(type) && S_ISDIR(file->mode)); |
| 815 | +} |
| 816 | + |
| 817 | +/* Turn the ACL data in statx into cached ACL data, setting the index |
| 818 | + * values in the file struct. */ |
| 819 | +void cache_acl(struct file_struct *file, statx *sxp) |
| 820 | +{ |
| 821 | + SMB_ACL_TYPE_T type; |
| 822 | + rsync_acl *racl; |
| 823 | + item_list *racl_list; |
| 824 | + int ndx; |
| 825 | + |
| 826 | + if (S_ISLNK(file->mode)) |
| 827 | + return; |
| 828 | + |
| 829 | + type = SMB_ACL_TYPE_ACCESS; |
| 830 | + racl = sxp->acc_acl; |
| 831 | + racl_list = &access_acl_list; |
| 832 | + do { |
| 833 | + if (!racl) |
| 834 | + ndx = -1; |
| 835 | + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) { |
| 836 | + acl_duo *new_duo; |
| 837 | + ndx = racl_list->count; |
| 838 | + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000); |
| 839 | + new_duo->racl = *racl; |
| 840 | + new_duo->sacl = NULL; |
| 841 | + *racl = empty_rsync_acl; |
| 842 | + } |
| 843 | + if (type == SMB_ACL_TYPE_ACCESS) |
| 844 | + F_ACL(file) = ndx; |
| 845 | + else |
| 846 | + F_DEF_ACL(file) = ndx; |
| 847 | + racl = sxp->def_acl; |
| 848 | + racl_list = &default_acl_list; |
| 849 | + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode)); |
| 850 | + |
| 851 | + free_acl(sxp); |
| 852 | +} |
| 853 | + |
| 854 | +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode) |
| 855 | +{ |
| 856 | + SMB_ACL_ENTRY_T entry; |
| 857 | + const char *errfun; |
| 858 | + int rc; |
| 859 | + |
| 860 | + if (S_ISDIR(mode)) { |
| 861 | + /* If the sticky bit is going on, it's not safe to allow all |
| 862 | + * the new ACL to go into effect before it gets set. */ |
| 863 | +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS |
| 864 | + if (mode & S_ISVTX) |
| 865 | + mode &= ~0077; |
| 866 | +#else |
| 867 | + if (mode & S_ISVTX && !(old_mode & S_ISVTX)) |
| 868 | + mode &= ~0077; |
| 869 | + } else { |
| 870 | + /* If setuid or setgid is going off, it's not safe to allow all |
| 871 | + * the new ACL to go into effect before they get cleared. */ |
| 872 | + if ((old_mode & S_ISUID && !(mode & S_ISUID)) |
| 873 | + || (old_mode & S_ISGID && !(mode & S_ISGID))) |
| 874 | + mode &= ~0077; |
| 875 | +#endif |
| 876 | + } |
| 877 | + |
| 878 | + errfun = "sys_acl_get_entry"; |
| 879 | + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry); |
| 880 | + rc == 1; |
| 881 | + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) { |
| 882 | + SMB_ACL_TAG_T tag_type; |
| 883 | + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) { |
| 884 | + errfun = "sys_acl_get_tag_type"; |
| 885 | + break; |
| 886 | + } |
| 887 | + switch (tag_type) { |
| 888 | + case SMB_ACL_USER_OBJ: |
| 889 | + COE2( store_access_in_entry,((mode >> 6) & 7, entry) ); |
| 890 | + break; |
| 891 | + case SMB_ACL_GROUP_OBJ: |
| 892 | + /* group is only empty when identical to group perms. */ |
| 893 | + if (racl->group_obj != NO_ENTRY) |
| 894 | + break; |
| 895 | + COE2( store_access_in_entry,((mode >> 3) & 7, entry) ); |
| 896 | + break; |
| 897 | + case SMB_ACL_MASK: |
| 898 | +#ifndef ACLS_NEED_MASK |
| 899 | + /* mask is only empty when we don't need it. */ |
| 900 | + if (racl->mask == NO_ENTRY) |
| 901 | + break; |
| 902 | +#endif |
| 903 | + COE2( store_access_in_entry,((mode >> 3) & 7, entry) ); |
| 904 | + break; |
| 905 | + case SMB_ACL_OTHER: |
| 906 | + COE2( store_access_in_entry,(mode & 7, entry) ); |
| 907 | + break; |
| 908 | + } |
| 909 | + } |
| 910 | + if (rc) { |
| 911 | + error_exit: |
| 912 | + if (errfun) { |
| 913 | + rsyserr(FERROR, errno, "change_sacl_perms: %s()", |
| 914 | + errfun); |
| 915 | + } |
| 916 | + return (mode_t)~0; |
| 917 | + } |
| 918 | + |
| 919 | +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS |
| 920 | + /* Ensure that chmod() will be called to restore any lost setid bits. */ |
| 921 | + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX) |
| 922 | + && BITS_EQUAL(old_mode, mode, CHMOD_BITS)) |
| 923 | + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX); |
| 924 | +#endif |
| 925 | + |
| 926 | + /* Return the mode of the file on disk, as we will set them. */ |
| 927 | + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS); |
| 928 | +} |
| 929 | + |
| 930 | +/* Set ACL on indicated filename. |
| 931 | + * |
| 932 | + * This sets extended access ACL entries and default ACL. If convenient, |
| 933 | + * it sets permission bits along with the access ACL and signals having |
| 934 | + * done so by modifying sxp->st.st_mode. |
| 935 | + * |
| 936 | + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this |
| 937 | + * with fname set to NULL to just check if the ACL is unchanged. */ |
| 938 | +int set_acl(const char *fname, const struct file_struct *file, statx *sxp) |
| 939 | +{ |
| 940 | + int unchanged = 1; |
| 941 | + SMB_ACL_TYPE_T type; |
| 942 | + |
| 943 | + if (!dry_run && (read_only || list_only)) { |
| 944 | + errno = EROFS; |
| 945 | + return -1; |
| 946 | + } |
| 947 | + |
| 948 | + if (S_ISLNK(file->mode)) |
| 949 | + return 1; |
| 950 | + |
| 951 | + type = SMB_ACL_TYPE_ACCESS; |
| 952 | + do { |
| 953 | + acl_duo *duo_item; |
| 954 | + int32 ndx; |
| 955 | + BOOL eq; |
| 956 | + |
| 957 | + if (type == SMB_ACL_TYPE_ACCESS) { |
| 958 | + ndx = F_ACL(file); |
| 959 | + if (ndx < 0 || (size_t)ndx >= access_acl_list.count) |
| 960 | + continue; |
| 961 | + duo_item = access_acl_list.items; |
| 962 | + duo_item += ndx; |
| 963 | + eq = sxp->acc_acl |
| 964 | + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode); |
| 965 | + } else { |
| 966 | + ndx = F_DEF_ACL(file); |
| 967 | + if (ndx < 0 || (size_t)ndx >= default_acl_list.count) |
| 968 | + continue; |
| 969 | + duo_item = default_acl_list.items; |
| 970 | + duo_item += ndx; |
| 971 | + eq = sxp->def_acl |
| 972 | + && rsync_acl_equal(sxp->def_acl, &duo_item->racl); |
| 973 | + } |
| 974 | + if (eq) |
| 975 | + continue; |
| 976 | + if (!dry_run && fname) { |
| 977 | + if (type == SMB_ACL_TYPE_DEFAULT |
| 978 | + && duo_item->racl.user_obj == NO_ENTRY) { |
| 979 | + if (sys_acl_delete_def_file(fname) < 0) { |
| 980 | + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)", |
| 981 | + fname); |
| 982 | + unchanged = -1; |
| 983 | + continue; |
| 984 | + } |
| 985 | + } else { |
| 986 | + mode_t cur_mode = sxp->st.st_mode; |
| 987 | + if (!duo_item->sacl |
| 988 | + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) { |
| 989 | + unchanged = -1; |
| 990 | + continue; |
| 991 | + } |
| 992 | + if (type == SMB_ACL_TYPE_ACCESS) { |
| 993 | + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl, |
| 994 | + cur_mode, file->mode); |
| 995 | + if (cur_mode == (mode_t)~0) |
| 996 | + continue; |
| 997 | + } |
| 998 | + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) { |
| 999 | + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)", |
| 1000 | + fname, str_acl_type(type)); |
| 1001 | + unchanged = -1; |
| 1002 | + continue; |
| 1003 | + } |
| 1004 | + if (type == SMB_ACL_TYPE_ACCESS) |
| 1005 | + sxp->st.st_mode = cur_mode; |
| 1006 | + } |
| 1007 | + } |
| 1008 | + if (unchanged == 1) |
| 1009 | + unchanged = 0; |
| 1010 | + } while (BUMP_TYPE(type) && S_ISDIR(file->mode)); |
| 1011 | + |
| 1012 | + return unchanged; |
| 1013 | +} |
| 1014 | + |
| 1015 | +/* === Enumeration functions for uid mapping === */ |
| 1016 | + |
| 1017 | +/* Context -- one and only one. Should be cycled through once on uid |
| 1018 | + * mapping and once on gid mapping. */ |
| 1019 | +static item_list *_enum_racl_lists[] = { |
| 1020 | + &access_acl_list, &default_acl_list, NULL |
| 1021 | +}; |
| 1022 | + |
| 1023 | +static item_list **enum_racl_list = &_enum_racl_lists[0]; |
| 1024 | +static int enum_ida_index = 0; |
| 1025 | +static size_t enum_racl_index = 0; |
| 1026 | + |
| 1027 | +/* This returns the next tag_type id from the given ACL for the next entry, |
| 1028 | + * or it returns 0 if there are no more tag_type ids in the acl. */ |
| 1029 | +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl) |
| 1030 | +{ |
| 1031 | + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups; |
| 1032 | + if (enum_ida_index < idal->count) { |
| 1033 | + id_access *ida = &idal->idas[enum_ida_index++]; |
| 1034 | + return &ida->id; |
| 1035 | + } |
| 1036 | + enum_ida_index = 0; |
| 1037 | + return NULL; |
| 1038 | +} |
| 1039 | + |
| 1040 | +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list) |
| 1041 | +{ |
| 1042 | + for (; enum_racl_index < racl_list->count; enum_racl_index++) { |
| 1043 | + id_t *id; |
| 1044 | + acl_duo *duo_item = racl_list->items; |
| 1045 | + duo_item += enum_racl_index; |
| 1046 | + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL) |
| 1047 | + return id; |
| 1048 | + } |
| 1049 | + enum_racl_index = 0; |
| 1050 | + return NULL; |
| 1051 | +} |
| 1052 | + |
| 1053 | +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type) |
| 1054 | +{ |
| 1055 | + for (; *enum_racl_list; enum_racl_list++) { |
| 1056 | + id_t *id = next_acl_id(tag_type, *enum_racl_list); |
| 1057 | + if (id) |
| 1058 | + return id; |
| 1059 | + } |
| 1060 | + enum_racl_list = &_enum_racl_lists[0]; |
| 1061 | + return NULL; |
| 1062 | +} |
| 1063 | + |
| 1064 | +id_t *next_acl_uid() |
| 1065 | +{ |
| 1066 | + return next_acl_list_id(SMB_ACL_USER); |
| 1067 | +} |
| 1068 | + |
| 1069 | +id_t *next_acl_gid() |
| 1070 | +{ |
| 1071 | + return next_acl_list_id(SMB_ACL_GROUP); |
| 1072 | +} |
| 1073 | + |
| 1074 | +/* This is used by dest_mode(). */ |
| 1075 | +int default_perms_for_dir(const char *dir) |
| 1076 | +{ |
| 1077 | + rsync_acl racl; |
| 1078 | + SMB_ACL_T sacl; |
| 1079 | + BOOL ok; |
| 1080 | + int perms; |
| 1081 | + |
| 1082 | + if (dir == NULL) |
| 1083 | + dir = "."; |
| 1084 | + perms = ACCESSPERMS & ~orig_umask; |
| 1085 | + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */ |
| 1086 | + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT); |
| 1087 | + if (sacl == NULL) { |
| 1088 | + /* Couldn't get an ACL. Darn. */ |
| 1089 | + switch (errno) { |
| 1090 | + case ENOTSUP: |
| 1091 | + case ENOSYS: |
| 1092 | + /* No ACLs are available. */ |
| 1093 | + break; |
| 1094 | + case ENOENT: |
| 1095 | + if (dry_run) { |
| 1096 | + /* We're doing a dry run, so the containing directory |
| 1097 | + * wasn't actually created. Don't worry about it. */ |
| 1098 | + break; |
| 1099 | + } |
| 1100 | + /* Otherwise fall through. */ |
| 1101 | + default: |
| 1102 | + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n", |
| 1103 | + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno)); |
| 1104 | + } |
| 1105 | + return perms; |
| 1106 | + } |
| 1107 | + |
| 1108 | + /* Convert it. */ |
| 1109 | + racl = empty_rsync_acl; |
| 1110 | + ok = unpack_smb_acl(&racl, sacl); |
| 1111 | + sys_acl_free_acl(sacl); |
| 1112 | + if (!ok) { |
| 1113 | + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n"); |
| 1114 | + return perms; |
| 1115 | + } |
| 1116 | + |
| 1117 | + /* Apply the permission-bit entries of the default ACL, if any. */ |
| 1118 | + if (racl.user_obj != NO_ENTRY) { |
| 1119 | + perms = rsync_acl_get_perms(&racl); |
| 1120 | + if (verbose > 2) |
| 1121 | + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir); |
| 1122 | + } |
| 1123 | + |
| 1124 | + rsync_acl_free(&racl); |
| 1125 | + return perms; |
| 1126 | +} |
| 1127 | + |
| 1128 | +#endif /* SUPPORT_ACLS */ |
| 1129 | --- old/backup.c |
| 1130 | +++ new/backup.c |
| 1131 | @@ -22,6 +22,7 @@ |
| 1132 | |
| 1133 | extern int verbose; |
| 1134 | extern int am_root; |
| 1135 | +extern int preserve_acls; |
| 1136 | extern int preserve_devices; |
| 1137 | extern int preserve_specials; |
| 1138 | extern int preserve_links; |
| 1139 | @@ -92,7 +93,8 @@ path |
| 1140 | ****************************************************************************/ |
| 1141 | static int make_bak_dir(char *fullpath) |
| 1142 | { |
| 1143 | - STRUCT_STAT st; |
| 1144 | + statx sx; |
| 1145 | + struct file_struct *file; |
| 1146 | char *rel = fullpath + backup_dir_len; |
| 1147 | char *end = rel + strlen(rel); |
| 1148 | char *p = end; |
| 1149 | @@ -124,15 +126,24 @@ static int make_bak_dir(char *fullpath) |
| 1150 | if (p >= rel) { |
| 1151 | /* Try to transfer the directory settings of the |
| 1152 | * actual dir that the files are coming from. */ |
| 1153 | - if (do_stat(rel, &st) < 0) { |
| 1154 | + if (do_stat(rel, &sx.st) < 0) { |
| 1155 | rsyserr(FERROR, errno, |
| 1156 | "make_bak_dir stat %s failed", |
| 1157 | full_fname(rel)); |
| 1158 | } else { |
| 1159 | - do_lchown(fullpath, st.st_uid, st.st_gid); |
| 1160 | -#ifdef HAVE_CHMOD |
| 1161 | - do_chmod(fullpath, st.st_mode); |
| 1162 | +#ifdef SUPPORT_ACLS |
| 1163 | + sx.acc_acl = sx.def_acl = NULL; |
| 1164 | +#endif |
| 1165 | + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS))) |
| 1166 | + continue; |
| 1167 | +#ifdef SUPPORT_ACLS |
| 1168 | + if (preserve_acls) { |
| 1169 | + get_acl(rel, &sx); |
| 1170 | + cache_acl(file, &sx); |
| 1171 | + } |
| 1172 | #endif |
| 1173 | + set_file_attrs(fullpath, file, NULL, 0); |
| 1174 | + free(file); |
| 1175 | } |
| 1176 | } |
| 1177 | *p = '/'; |
| 1178 | @@ -170,15 +181,18 @@ static int robust_move(const char *src, |
| 1179 | * We will move the file to be deleted into a parallel directory tree. */ |
| 1180 | static int keep_backup(const char *fname) |
| 1181 | { |
| 1182 | - STRUCT_STAT st; |
| 1183 | + statx sx; |
| 1184 | struct file_struct *file; |
| 1185 | char *buf; |
| 1186 | int kept = 0; |
| 1187 | int ret_code; |
| 1188 | |
| 1189 | /* return if no file to keep */ |
| 1190 | - if (do_lstat(fname, &st) < 0) |
| 1191 | + if (do_lstat(fname, &sx.st) < 0) |
| 1192 | return 1; |
| 1193 | +#ifdef SUPPORT_ACLS |
| 1194 | + sx.acc_acl = sx.def_acl = NULL; |
| 1195 | +#endif |
| 1196 | |
| 1197 | if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) |
| 1198 | return 1; /* the file could have disappeared */ |
| 1199 | @@ -188,6 +202,13 @@ static int keep_backup(const char *fname |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | +#ifdef SUPPORT_ACLS |
| 1204 | + if (preserve_acls) { |
| 1205 | + get_acl(fname, &sx); |
| 1206 | + cache_acl(file, &sx); |
| 1207 | + } |
| 1208 | +#endif |
| 1209 | + |
| 1210 | /* Check to see if this is a device file, or link */ |
| 1211 | if ((am_root && preserve_devices && IS_DEVICE(file->mode)) |
| 1212 | || (preserve_specials && IS_SPECIAL(file->mode))) { |
| 1213 | @@ -259,7 +280,7 @@ static int keep_backup(const char *fname |
| 1214 | if (robust_move(fname, buf) != 0) { |
| 1215 | rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"", |
| 1216 | full_fname(fname), buf); |
| 1217 | - } else if (st.st_nlink > 1) { |
| 1218 | + } else if (sx.st.st_nlink > 1) { |
| 1219 | /* If someone has hard-linked the file into the backup |
| 1220 | * dir, rename() might return success but do nothing! */ |
| 1221 | robust_unlink(fname); /* Just in case... */ |
| 1222 | --- old/compat.c |
| 1223 | +++ new/compat.c |
| 1224 | @@ -40,6 +40,7 @@ extern int prune_empty_dirs; |
| 1225 | extern int protocol_version; |
| 1226 | extern int preserve_uid; |
| 1227 | extern int preserve_gid; |
| 1228 | +extern int preserve_acls; |
| 1229 | extern int preserve_hard_links; |
| 1230 | extern int need_messages_from_generator; |
| 1231 | extern int delete_mode, delete_before, delete_during, delete_after; |
| 1232 | @@ -60,6 +61,8 @@ void setup_protocol(int f_out,int f_in) |
| 1233 | preserve_uid = ++file_extra_cnt; |
| 1234 | if (preserve_gid) |
| 1235 | preserve_gid = ++file_extra_cnt; |
| 1236 | + if (preserve_acls && !am_sender) |
| 1237 | + preserve_acls = ++file_extra_cnt; |
| 1238 | |
| 1239 | if (remote_protocol == 0) { |
| 1240 | if (!read_batch) |
| 1241 | --- old/configure.in |
| 1242 | +++ new/configure.in |
| 1243 | @@ -542,6 +542,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no |
| 1244 | AC_CHECK_LIB(resolv, strcasecmp) |
| 1245 | fi |
| 1246 | |
| 1247 | +AC_CHECK_FUNCS(aclsort) |
| 1248 | +if test x"$ac_cv_func_aclsort" = x"no"; then |
| 1249 | + AC_CHECK_LIB(sec, aclsort) |
| 1250 | +fi |
| 1251 | + |
| 1252 | dnl At the moment we don't test for a broken memcmp(), because all we |
| 1253 | dnl need to do is test for equality, not comparison, and it seems that |
| 1254 | dnl every platform has a memcmp that can do at least that. |
| 1255 | @@ -806,6 +811,78 @@ AC_SUBST(OBJ_RESTORE) |
| 1256 | AC_SUBST(CC_SHOBJ_FLAG) |
| 1257 | AC_SUBST(BUILD_POPT) |
| 1258 | |
| 1259 | +AC_CHECK_HEADERS(sys/acl.h acl/libacl.h) |
| 1260 | +AC_CHECK_FUNCS(_acl __acl _facl __facl) |
| 1261 | +################################################# |
| 1262 | +# check for ACL support |
| 1263 | + |
| 1264 | +AC_MSG_CHECKING(whether to support ACLs) |
| 1265 | +AC_ARG_ENABLE(acl-support, |
| 1266 | +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]), |
| 1267 | +[ case "$enableval" in |
| 1268 | + yes) |
| 1269 | + |
| 1270 | + case "$host_os" in |
| 1271 | + *sysv5*) |
| 1272 | + AC_MSG_RESULT(Using UnixWare ACLs) |
| 1273 | + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs]) |
| 1274 | + ;; |
| 1275 | + *solaris*|*cygwin*) |
| 1276 | + AC_MSG_RESULT(Using solaris ACLs) |
| 1277 | + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs]) |
| 1278 | + ;; |
| 1279 | + *hpux*) |
| 1280 | + AC_MSG_RESULT(Using HPUX ACLs) |
| 1281 | + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs]) |
| 1282 | + ;; |
| 1283 | + *irix*) |
| 1284 | + AC_MSG_RESULT(Using IRIX ACLs) |
| 1285 | + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs]) |
| 1286 | + ;; |
| 1287 | + *aix*) |
| 1288 | + AC_MSG_RESULT(Using AIX ACLs) |
| 1289 | + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs]) |
| 1290 | + ;; |
| 1291 | + *osf*) |
| 1292 | + AC_MSG_RESULT(Using Tru64 ACLs) |
| 1293 | + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs]) |
| 1294 | + LIBS="$LIBS -lpacl" |
| 1295 | + ;; |
| 1296 | + *) |
| 1297 | + AC_MSG_RESULT(ACLs requested -- running tests) |
| 1298 | + AC_CHECK_LIB(acl,acl_get_file) |
| 1299 | + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[ |
| 1300 | + AC_TRY_LINK([#include <sys/types.h> |
| 1301 | +#include <sys/acl.h>], |
| 1302 | +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);], |
| 1303 | +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)]) |
| 1304 | + AC_MSG_CHECKING(ACL test results) |
| 1305 | + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then |
| 1306 | + AC_MSG_RESULT(Using posix ACLs) |
| 1307 | + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs]) |
| 1308 | + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[ |
| 1309 | + AC_TRY_LINK([#include <sys/types.h> |
| 1310 | +#include <sys/acl.h>], |
| 1311 | +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);], |
| 1312 | +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)]) |
| 1313 | + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then |
| 1314 | + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np]) |
| 1315 | + fi |
| 1316 | + else |
| 1317 | + AC_MSG_ERROR(Failed to find ACL support) |
| 1318 | + fi |
| 1319 | + ;; |
| 1320 | + esac |
| 1321 | + ;; |
| 1322 | + *) |
| 1323 | + AC_MSG_RESULT(no) |
| 1324 | + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs]) |
| 1325 | + ;; |
| 1326 | + esac ], |
| 1327 | + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs]) |
| 1328 | + AC_MSG_RESULT(no) |
| 1329 | +) |
| 1330 | + |
| 1331 | AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig]) |
| 1332 | AC_OUTPUT |
| 1333 | |
| 1334 | --- old/flist.c |
| 1335 | +++ new/flist.c |
| 1336 | @@ -41,6 +41,7 @@ extern int filesfrom_fd; |
| 1337 | extern int one_file_system; |
| 1338 | extern int copy_dirlinks; |
| 1339 | extern int keep_dirlinks; |
| 1340 | +extern int preserve_acls; |
| 1341 | extern int preserve_links; |
| 1342 | extern int preserve_hard_links; |
| 1343 | extern int preserve_devices; |
| 1344 | @@ -152,6 +153,8 @@ static void list_file_entry(struct file_ |
| 1345 | permstring(permbuf, f->mode); |
| 1346 | len = F_LENGTH(f); |
| 1347 | |
| 1348 | + /* TODO: indicate '+' if the entry has an ACL. */ |
| 1349 | + |
| 1350 | #ifdef SUPPORT_LINKS |
| 1351 | if (preserve_links && S_ISLNK(f->mode)) { |
| 1352 | rprintf(FINFO, "%s %11.0f %s %s -> %s\n", |
| 1353 | @@ -714,6 +717,12 @@ static struct file_struct *recv_file_ent |
| 1354 | } |
| 1355 | #endif |
| 1356 | |
| 1357 | +#ifdef SUPPORT_ACLS |
| 1358 | + /* We need one or two index int32s when we're preserving ACLs. */ |
| 1359 | + if (preserve_acls) |
| 1360 | + extra_len += (S_ISDIR(mode) ? 2 : 1) * EXTRA_LEN; |
| 1361 | +#endif |
| 1362 | + |
| 1363 | if (always_checksum && S_ISREG(mode)) |
| 1364 | extra_len += SUM_EXTRA_CNT * EXTRA_LEN; |
| 1365 | |
| 1366 | @@ -851,6 +860,11 @@ static struct file_struct *recv_file_ent |
| 1367 | read_buf(f, bp, checksum_len); |
| 1368 | } |
| 1369 | |
| 1370 | +#ifdef SUPPORT_ACLS |
| 1371 | + if (preserve_acls) |
| 1372 | + receive_acl(file, f); |
| 1373 | +#endif |
| 1374 | + |
| 1375 | if (S_ISREG(mode) || S_ISLNK(mode)) |
| 1376 | stats.total_size += file_length; |
| 1377 | |
| 1378 | @@ -1122,6 +1136,9 @@ static struct file_struct *send_file_nam |
| 1379 | int flags, int filter_flags) |
| 1380 | { |
| 1381 | struct file_struct *file; |
| 1382 | +#ifdef SUPPORT_ACLS |
| 1383 | + statx sx; |
| 1384 | +#endif |
| 1385 | |
| 1386 | file = make_file(fname, flist, stp, flags, filter_flags); |
| 1387 | if (!file) |
| 1388 | @@ -1130,12 +1147,26 @@ static struct file_struct *send_file_nam |
| 1389 | if (chmod_modes && !S_ISLNK(file->mode)) |
| 1390 | file->mode = tweak_mode(file->mode, chmod_modes); |
| 1391 | |
| 1392 | +#ifdef SUPPORT_ACLS |
| 1393 | + if (preserve_acls && f >= 0) { |
| 1394 | + sx.st.st_mode = file->mode; |
| 1395 | + sx.acc_acl = sx.def_acl = NULL; |
| 1396 | + if (get_acl(fname, &sx) < 0) |
| 1397 | + return NULL; |
| 1398 | + } |
| 1399 | +#endif |
| 1400 | + |
| 1401 | maybe_emit_filelist_progress(flist->count + flist_count_offset); |
| 1402 | |
| 1403 | flist_expand(flist); |
| 1404 | flist->files[flist->count++] = file; |
| 1405 | - if (f >= 0) |
| 1406 | + if (f >= 0) { |
| 1407 | send_file_entry(f, file, flist->count - 1); |
| 1408 | +#ifdef SUPPORT_ACLS |
| 1409 | + if (preserve_acls) |
| 1410 | + send_acl(&sx, f); |
| 1411 | +#endif |
| 1412 | + } |
| 1413 | return file; |
| 1414 | } |
| 1415 | |
| 1416 | --- old/generator.c |
| 1417 | +++ new/generator.c |
| 1418 | @@ -35,6 +35,7 @@ extern int do_progress; |
| 1419 | extern int relative_paths; |
| 1420 | extern int implied_dirs; |
| 1421 | extern int keep_dirlinks; |
| 1422 | +extern int preserve_acls; |
| 1423 | extern int preserve_links; |
| 1424 | extern int preserve_devices; |
| 1425 | extern int preserve_specials; |
| 1426 | @@ -89,6 +90,7 @@ extern int force_delete; |
| 1427 | extern int one_file_system; |
| 1428 | extern struct stats stats; |
| 1429 | extern dev_t filesystem_dev; |
| 1430 | +extern mode_t orig_umask; |
| 1431 | extern char *backup_dir; |
| 1432 | extern char *backup_suffix; |
| 1433 | extern int backup_suffix_len; |
| 1434 | @@ -511,22 +513,31 @@ static void do_delete_pass(struct file_l |
| 1435 | rprintf(FINFO, " \r"); |
| 1436 | } |
| 1437 | |
| 1438 | -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st) |
| 1439 | +int unchanged_attrs(const char *fname, struct file_struct *file, statx *sxp) |
| 1440 | { |
| 1441 | - if (preserve_perms && !BITS_EQUAL(st->st_mode, file->mode, CHMOD_BITS)) |
| 1442 | + if (preserve_perms && !BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS)) |
| 1443 | return 0; |
| 1444 | |
| 1445 | - if (am_root && preserve_uid && st->st_uid != F_UID(file)) |
| 1446 | + if (am_root && preserve_uid && sxp->st.st_uid != F_UID(file)) |
| 1447 | return 0; |
| 1448 | |
| 1449 | - if (preserve_gid && F_GID(file) != GID_NONE && st->st_gid != F_GID(file)) |
| 1450 | + if (preserve_gid && F_GID(file) != GID_NONE && sxp->st.st_gid != F_GID(file)) |
| 1451 | return 0; |
| 1452 | |
| 1453 | +#ifdef SUPPORT_ACLS |
| 1454 | + if (preserve_acls) { |
| 1455 | + if (!ACL_READY(*sxp)) |
| 1456 | + get_acl(fname, sxp); |
| 1457 | + if (set_acl(NULL, file, sxp) == 0) |
| 1458 | + return 0; |
| 1459 | + } |
| 1460 | +#endif |
| 1461 | + |
| 1462 | return 1; |
| 1463 | } |
| 1464 | |
| 1465 | -void itemize(struct file_struct *file, int ndx, int statret, |
| 1466 | - STRUCT_STAT *st, int32 iflags, uchar fnamecmp_type, |
| 1467 | +void itemize(const char *fname, struct file_struct *file, int ndx, int statret, |
| 1468 | + statx *sxp, int32 iflags, uchar fnamecmp_type, |
| 1469 | const char *xname) |
| 1470 | { |
| 1471 | if (statret >= 0) { /* A from-dest-dir statret can == 1! */ |
| 1472 | @@ -534,20 +545,28 @@ void itemize(struct file_struct *file, i |
| 1473 | : S_ISDIR(file->mode) ? !omit_dir_times |
| 1474 | : !S_ISLNK(file->mode); |
| 1475 | |
| 1476 | - if (S_ISREG(file->mode) && F_LENGTH(file) != st->st_size) |
| 1477 | + if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size) |
| 1478 | iflags |= ITEM_REPORT_SIZE; |
| 1479 | if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time |
| 1480 | && !(iflags & ITEM_MATCHED) |
| 1481 | && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname)) |
| 1482 | - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0)) |
| 1483 | + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0)) |
| 1484 | iflags |= ITEM_REPORT_TIME; |
| 1485 | - if (!BITS_EQUAL(st->st_mode, file->mode, CHMOD_BITS)) |
| 1486 | + if (!BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS)) |
| 1487 | iflags |= ITEM_REPORT_PERMS; |
| 1488 | - if (preserve_uid && am_root && F_UID(file) != st->st_uid) |
| 1489 | + if (preserve_uid && am_root && F_UID(file) != sxp->st.st_uid) |
| 1490 | iflags |= ITEM_REPORT_OWNER; |
| 1491 | if (preserve_gid && F_GID(file) != GID_NONE |
| 1492 | - && st->st_gid != F_GID(file)) |
| 1493 | + && sxp->st.st_gid != F_GID(file)) |
| 1494 | iflags |= ITEM_REPORT_GROUP; |
| 1495 | +#ifdef SUPPORT_ACLS |
| 1496 | + if (preserve_acls) { |
| 1497 | + if (!ACL_READY(*sxp)) |
| 1498 | + get_acl(fname, sxp); |
| 1499 | + if (set_acl(NULL, file, sxp) == 0) |
| 1500 | + iflags |= ITEM_REPORT_ACL; |
| 1501 | + } |
| 1502 | +#endif |
| 1503 | } else |
| 1504 | iflags |= ITEM_IS_NEW; |
| 1505 | |
| 1506 | @@ -783,7 +802,7 @@ static int find_fuzzy(struct file_struct |
| 1507 | * handling the file, -1 if no dest-linking occurred, or a non-negative |
| 1508 | * value if we found an alternate basis file. */ |
| 1509 | static int try_dests_reg(struct file_struct *file, char *fname, int ndx, |
| 1510 | - char *cmpbuf, STRUCT_STAT *stp, int itemizing, |
| 1511 | + char *cmpbuf, statx *sxp, int itemizing, |
| 1512 | enum logcode code) |
| 1513 | { |
| 1514 | int best_match = -1; |
| 1515 | @@ -792,7 +811,7 @@ static int try_dests_reg(struct file_str |
| 1516 | |
| 1517 | do { |
| 1518 | pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
| 1519 | - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode)) |
| 1520 | + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode)) |
| 1521 | continue; |
| 1522 | switch (match_level) { |
| 1523 | case 0: |
| 1524 | @@ -800,16 +819,16 @@ static int try_dests_reg(struct file_str |
| 1525 | match_level = 1; |
| 1526 | /* FALL THROUGH */ |
| 1527 | case 1: |
| 1528 | - if (!unchanged_file(cmpbuf, file, stp)) |
| 1529 | + if (!unchanged_file(cmpbuf, file, &sxp->st)) |
| 1530 | continue; |
| 1531 | best_match = j; |
| 1532 | match_level = 2; |
| 1533 | /* FALL THROUGH */ |
| 1534 | case 2: |
| 1535 | - if (!unchanged_attrs(file, stp)) |
| 1536 | + if (!unchanged_attrs(cmpbuf, file, sxp)) |
| 1537 | continue; |
| 1538 | if (always_checksum > 0 && preserve_times |
| 1539 | - && cmp_time(stp->st_mtime, file->modtime)) |
| 1540 | + && cmp_time(sxp->st.st_mtime, file->modtime)) |
| 1541 | continue; |
| 1542 | best_match = j; |
| 1543 | match_level = 3; |
| 1544 | @@ -824,7 +843,7 @@ static int try_dests_reg(struct file_str |
| 1545 | if (j != best_match) { |
| 1546 | j = best_match; |
| 1547 | pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
| 1548 | - if (link_stat(cmpbuf, stp, 0) < 0) |
| 1549 | + if (link_stat(cmpbuf, &sxp->st, 0) < 0) |
| 1550 | return -1; |
| 1551 | } |
| 1552 | |
| 1553 | @@ -834,16 +853,16 @@ static int try_dests_reg(struct file_str |
| 1554 | if (!hard_link_one(file, fname, cmpbuf, 1)) |
| 1555 | goto try_a_copy; |
| 1556 | if (preserve_hard_links && F_IS_HLINKED(file)) |
| 1557 | - finish_hard_link(file, fname, stp, itemizing, code, j); |
| 1558 | + finish_hard_link(file, fname, &sxp->st, itemizing, code, j); |
| 1559 | if (itemizing && (verbose > 1 || stdout_format_has_i > 1)) { |
| 1560 | - itemize(file, ndx, 1, stp, |
| 1561 | + itemize(fname, file, ndx, 1, sxp, |
| 1562 | ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, |
| 1563 | 0, ""); |
| 1564 | } |
| 1565 | } else |
| 1566 | #endif |
| 1567 | if (itemizing) |
| 1568 | - itemize(file, ndx, 0, stp, 0, 0, NULL); |
| 1569 | + itemize(fname, file, ndx, 0, sxp, 0, 0, NULL); |
| 1570 | if (verbose > 1 && maybe_ATTRS_REPORT) |
| 1571 | rprintf(FCLIENT, "%s is uptodate\n", fname); |
| 1572 | return -2; |
| 1573 | @@ -861,7 +880,7 @@ static int try_dests_reg(struct file_str |
| 1574 | return -1; |
| 1575 | } |
| 1576 | if (itemizing) |
| 1577 | - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL); |
| 1578 | + itemize(fname, file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL); |
| 1579 | set_file_attrs(fname, file, NULL, 0); |
| 1580 | if (maybe_ATTRS_REPORT |
| 1581 | && ((!itemizing && verbose && match_level == 2) |
| 1582 | @@ -872,7 +891,7 @@ static int try_dests_reg(struct file_str |
| 1583 | } |
| 1584 | #ifdef SUPPORT_HARD_LINKS |
| 1585 | if (preserve_hard_links && F_IS_HLINKED(file)) |
| 1586 | - finish_hard_link(file, fname, stp, itemizing, code, -1); |
| 1587 | + finish_hard_link(file, fname, &sxp->st, itemizing, code, -1); |
| 1588 | #endif |
| 1589 | return -2; |
| 1590 | } |
| 1591 | @@ -884,7 +903,7 @@ static int try_dests_reg(struct file_str |
| 1592 | * handling the file, or -1 if no dest-linking occurred, or a non-negative |
| 1593 | * value if we found an alternate basis file. */ |
| 1594 | static int try_dests_non(struct file_struct *file, char *fname, int ndx, |
| 1595 | - char *cmpbuf, STRUCT_STAT *stp, int itemizing, |
| 1596 | + char *cmpbuf, statx *sxp, int itemizing, |
| 1597 | enum logcode code) |
| 1598 | { |
| 1599 | char lnk[MAXPATHLEN]; |
| 1600 | @@ -917,24 +936,24 @@ static int try_dests_non(struct file_str |
| 1601 | |
| 1602 | do { |
| 1603 | pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
| 1604 | - if (link_stat(cmpbuf, stp, 0) < 0) |
| 1605 | + if (link_stat(cmpbuf, &sxp->st, 0) < 0) |
| 1606 | continue; |
| 1607 | switch (type) { |
| 1608 | case TYPE_DIR: |
| 1609 | - if (!S_ISDIR(stp->st_mode)) |
| 1610 | + if (!S_ISDIR(sxp->st.st_mode)) |
| 1611 | continue; |
| 1612 | break; |
| 1613 | case TYPE_SPECIAL: |
| 1614 | - if (!IS_SPECIAL(stp->st_mode)) |
| 1615 | + if (!IS_SPECIAL(sxp->st.st_mode)) |
| 1616 | continue; |
| 1617 | break; |
| 1618 | case TYPE_DEVICE: |
| 1619 | - if (!IS_DEVICE(stp->st_mode)) |
| 1620 | + if (!IS_DEVICE(sxp->st.st_mode)) |
| 1621 | continue; |
| 1622 | break; |
| 1623 | #ifdef SUPPORT_LINKS |
| 1624 | case TYPE_SYMLINK: |
| 1625 | - if (!S_ISLNK(stp->st_mode)) |
| 1626 | + if (!S_ISLNK(sxp->st.st_mode)) |
| 1627 | continue; |
| 1628 | break; |
| 1629 | #endif |
| 1630 | @@ -949,7 +968,7 @@ static int try_dests_non(struct file_str |
| 1631 | case TYPE_SPECIAL: |
| 1632 | case TYPE_DEVICE: |
| 1633 | devp = F_RDEV_P(file); |
| 1634 | - if (stp->st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp))) |
| 1635 | + if (sxp->st.st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp))) |
| 1636 | continue; |
| 1637 | break; |
| 1638 | #ifdef SUPPORT_LINKS |
| 1639 | @@ -966,7 +985,7 @@ static int try_dests_non(struct file_str |
| 1640 | match_level = 2; |
| 1641 | best_match = j; |
| 1642 | } |
| 1643 | - if (unchanged_attrs(file, stp)) { |
| 1644 | + if (unchanged_attrs(cmpbuf, file, sxp)) { |
| 1645 | match_level = 3; |
| 1646 | best_match = j; |
| 1647 | break; |
| 1648 | @@ -979,7 +998,7 @@ static int try_dests_non(struct file_str |
| 1649 | if (j != best_match) { |
| 1650 | j = best_match; |
| 1651 | pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
| 1652 | - if (link_stat(cmpbuf, stp, 0) < 0) |
| 1653 | + if (link_stat(cmpbuf, &sxp->st, 0) < 0) |
| 1654 | return -1; |
| 1655 | } |
| 1656 | |
| 1657 | @@ -1010,7 +1029,7 @@ static int try_dests_non(struct file_str |
| 1658 | : ITEM_LOCAL_CHANGE |
| 1659 | + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0); |
| 1660 | char *lp = match_level == 3 ? "" : NULL; |
| 1661 | - itemize(file, ndx, 0, stp, chg + ITEM_MATCHED, 0, lp); |
| 1662 | + itemize(fname, file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp); |
| 1663 | } |
| 1664 | if (verbose > 1 && maybe_ATTRS_REPORT) { |
| 1665 | rprintf(FCLIENT, "%s%s is uptodate\n", |
| 1666 | @@ -1023,6 +1042,7 @@ static int try_dests_non(struct file_str |
| 1667 | } |
| 1668 | |
| 1669 | static int phase = 0; |
| 1670 | +static int dflt_perms; |
| 1671 | |
| 1672 | /* Acts on the indicated item in cur_flist whose name is fname. If a dir, |
| 1673 | * make sure it exists, and has the right permissions/timestamp info. For |
| 1674 | @@ -1043,7 +1063,8 @@ static void recv_generator(char *fname, |
| 1675 | static int need_fuzzy_dirlist = 0; |
| 1676 | struct file_struct *fuzzy_file = NULL; |
| 1677 | int fd = -1, f_copy = -1; |
| 1678 | - STRUCT_STAT st, real_st, partial_st; |
| 1679 | + statx sx, real_sx; |
| 1680 | + STRUCT_STAT partial_st; |
| 1681 | struct file_struct *back_file = NULL; |
| 1682 | int statret, real_ret, stat_errno; |
| 1683 | char *fnamecmp, *partialptr, *backupptr = NULL; |
| 1684 | @@ -1088,6 +1109,9 @@ static void recv_generator(char *fname, |
| 1685 | return; |
| 1686 | } |
| 1687 | } |
| 1688 | +#ifdef SUPPORT_ACLS |
| 1689 | + sx.acc_acl = sx.def_acl = NULL; |
| 1690 | +#endif |
| 1691 | if (dry_run > 1) { |
| 1692 | if (fuzzy_dirlist) { |
| 1693 | flist_free(fuzzy_dirlist); |
| 1694 | @@ -1100,7 +1124,7 @@ static void recv_generator(char *fname, |
| 1695 | const char *dn = file->dirname ? file->dirname : "."; |
| 1696 | if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) { |
| 1697 | if (relative_paths && !implied_dirs |
| 1698 | - && do_stat(dn, &st) < 0 |
| 1699 | + && do_stat(dn, &sx.st) < 0 |
| 1700 | && create_directory_path(fname) < 0) { |
| 1701 | rsyserr(FERROR, errno, |
| 1702 | "recv_generator: mkdir %s failed", |
| 1703 | @@ -1112,6 +1136,10 @@ static void recv_generator(char *fname, |
| 1704 | } |
| 1705 | if (fuzzy_basis) |
| 1706 | need_fuzzy_dirlist = 1; |
| 1707 | +#ifdef SUPPORT_ACLS |
| 1708 | + if (!preserve_perms) |
| 1709 | + dflt_perms = default_perms_for_dir(dn); |
| 1710 | +#endif |
| 1711 | } |
| 1712 | parent_dirname = dn; |
| 1713 | |
| 1714 | @@ -1121,7 +1149,7 @@ static void recv_generator(char *fname, |
| 1715 | need_fuzzy_dirlist = 0; |
| 1716 | } |
| 1717 | |
| 1718 | - statret = link_stat(fname, &st, |
| 1719 | + statret = link_stat(fname, &sx.st, |
| 1720 | keep_dirlinks && S_ISDIR(file->mode)); |
| 1721 | stat_errno = errno; |
| 1722 | } |
| 1723 | @@ -1149,8 +1177,8 @@ static void recv_generator(char *fname, |
| 1724 | * file of that name and it is *not* a directory, then |
| 1725 | * we need to delete it. If it doesn't exist, then |
| 1726 | * (perhaps recursively) create it. */ |
| 1727 | - if (statret == 0 && !S_ISDIR(st.st_mode)) { |
| 1728 | - if (delete_item(fname, st.st_mode, "directory", del_opts) != 0) |
| 1729 | + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) { |
| 1730 | + if (delete_item(fname, sx.st.st_mode, "directory", del_opts) != 0) |
| 1731 | return; |
| 1732 | statret = -1; |
| 1733 | } |
| 1734 | @@ -1159,18 +1187,18 @@ static void recv_generator(char *fname, |
| 1735 | dry_run++; |
| 1736 | } |
| 1737 | real_ret = statret; |
| 1738 | - real_st = st; |
| 1739 | + real_sx = sx; |
| 1740 | if (new_root_dir) { |
| 1741 | if (*fname == '.' && fname[1] == '\0') |
| 1742 | statret = -1; |
| 1743 | new_root_dir = 0; |
| 1744 | } |
| 1745 | if (!preserve_perms) { /* See comment in non-dir code below. */ |
| 1746 | - file->mode = dest_mode(file->mode, st.st_mode, |
| 1747 | - statret == 0); |
| 1748 | + file->mode = dest_mode(file->mode, sx.st.st_mode, |
| 1749 | + dflt_perms, statret == 0); |
| 1750 | } |
| 1751 | if (statret != 0 && basis_dir[0] != NULL) { |
| 1752 | - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st, |
| 1753 | + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, |
| 1754 | itemizing, code); |
| 1755 | if (j == -2) { |
| 1756 | itemizing = 0; |
| 1757 | @@ -1179,7 +1207,7 @@ static void recv_generator(char *fname, |
| 1758 | statret = 1; |
| 1759 | } |
| 1760 | if (itemizing && f_out != -1) { |
| 1761 | - itemize(file, ndx, statret, &st, |
| 1762 | + itemize(fname, file, ndx, statret, &sx, |
| 1763 | statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL); |
| 1764 | } |
| 1765 | if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) { |
| 1766 | @@ -1193,38 +1221,39 @@ static void recv_generator(char *fname, |
| 1767 | "*** Skipping any contents from this failed directory ***\n"); |
| 1768 | missing_below = F_DEPTH(file); |
| 1769 | file->flags |= FLAG_MISSING_DIR; |
| 1770 | - return; |
| 1771 | + goto cleanup; |
| 1772 | } |
| 1773 | } |
| 1774 | - if (set_file_attrs(fname, file, real_ret ? NULL : &real_st, 0) |
| 1775 | + if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, 0) |
| 1776 | && verbose && code != FNONE && f_out != -1) |
| 1777 | rprintf(code, "%s/\n", fname); |
| 1778 | if (real_ret != 0 && one_file_system) |
| 1779 | - real_st.st_dev = filesystem_dev; |
| 1780 | + real_sx.st.st_dev = filesystem_dev; |
| 1781 | if (inc_recurse) { |
| 1782 | if (one_file_system) { |
| 1783 | uint32 *devp = F_DIRDEV_P(file); |
| 1784 | - DEV_MAJOR(devp) = major(real_st.st_dev); |
| 1785 | - DEV_MINOR(devp) = minor(real_st.st_dev); |
| 1786 | + DEV_MAJOR(devp) = major(real_sx.st.st_dev); |
| 1787 | + DEV_MINOR(devp) = minor(real_sx.st.st_dev); |
| 1788 | } |
| 1789 | } |
| 1790 | else if (delete_during && f_out != -1 && !phase && dry_run < 2 |
| 1791 | && (file->flags & FLAG_XFER_DIR)) |
| 1792 | - delete_in_dir(cur_flist, fname, file, &real_st.st_dev); |
| 1793 | - return; |
| 1794 | + delete_in_dir(cur_flist, fname, file, &real_sx.st.st_dev); |
| 1795 | + goto cleanup; |
| 1796 | } |
| 1797 | |
| 1798 | /* If we're not preserving permissions, change the file-list's |
| 1799 | * mode based on the local permissions and some heuristics. */ |
| 1800 | if (!preserve_perms) { |
| 1801 | - int exists = statret == 0 && !S_ISDIR(st.st_mode); |
| 1802 | - file->mode = dest_mode(file->mode, st.st_mode, exists); |
| 1803 | + int exists = statret == 0 && !S_ISDIR(sx.st.st_mode); |
| 1804 | + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, |
| 1805 | + exists); |
| 1806 | } |
| 1807 | |
| 1808 | #ifdef SUPPORT_HARD_LINKS |
| 1809 | if (preserve_hard_links && F_HLINK_NOT_FIRST(file) |
| 1810 | - && hard_link_check(file, ndx, fname, statret, &st, itemizing, code)) |
| 1811 | - return; |
| 1812 | + && hard_link_check(file, ndx, fname, statret, &sx, itemizing, code)) |
| 1813 | + goto cleanup; |
| 1814 | #endif |
| 1815 | |
| 1816 | if (preserve_links && S_ISLNK(file->mode)) { |
| 1817 | @@ -1244,28 +1273,28 @@ static void recv_generator(char *fname, |
| 1818 | char lnk[MAXPATHLEN]; |
| 1819 | int len; |
| 1820 | |
| 1821 | - if (!S_ISLNK(st.st_mode)) |
| 1822 | + if (!S_ISLNK(sx.st.st_mode)) |
| 1823 | statret = -1; |
| 1824 | else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0 |
| 1825 | && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') { |
| 1826 | /* The link is pointing to the right place. */ |
| 1827 | if (itemizing) |
| 1828 | - itemize(file, ndx, 0, &st, 0, 0, NULL); |
| 1829 | - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT); |
| 1830 | + itemize(fname, file, ndx, 0, &sx, 0, 0, NULL); |
| 1831 | + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT); |
| 1832 | #ifdef SUPPORT_HARD_LINKS |
| 1833 | if (preserve_hard_links && F_IS_HLINKED(file)) |
| 1834 | - finish_hard_link(file, fname, &st, itemizing, code, -1); |
| 1835 | + finish_hard_link(file, fname, &sx.st, itemizing, code, -1); |
| 1836 | #endif |
| 1837 | if (remove_source_files == 1) |
| 1838 | goto return_with_success; |
| 1839 | - return; |
| 1840 | + goto cleanup; |
| 1841 | } |
| 1842 | /* Not the right symlink (or not a symlink), so |
| 1843 | * delete it. */ |
| 1844 | - if (delete_item(fname, st.st_mode, "symlink", del_opts) != 0) |
| 1845 | - return; |
| 1846 | + if (delete_item(fname, sx.st.st_mode, "symlink", del_opts) != 0) |
| 1847 | + goto cleanup; |
| 1848 | } else if (basis_dir[0] != NULL) { |
| 1849 | - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st, |
| 1850 | + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, |
| 1851 | itemizing, code); |
| 1852 | if (j == -2) { |
| 1853 | #ifndef CAN_HARDLINK_SYMLINK |
| 1854 | @@ -1274,7 +1303,7 @@ static void recv_generator(char *fname, |
| 1855 | } else |
| 1856 | #endif |
| 1857 | if (!copy_dest) |
| 1858 | - return; |
| 1859 | + goto cleanup; |
| 1860 | itemizing = 0; |
| 1861 | code = FNONE; |
| 1862 | } else if (j >= 0) |
| 1863 | @@ -1282,7 +1311,7 @@ static void recv_generator(char *fname, |
| 1864 | } |
| 1865 | #ifdef SUPPORT_HARD_LINKS |
| 1866 | if (preserve_hard_links && F_HLINK_NOT_LAST(file)) |
| 1867 | - return; |
| 1868 | + goto cleanup; |
| 1869 | #endif |
| 1870 | if (do_symlink(sl, fname) != 0) { |
| 1871 | rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed", |
| 1872 | @@ -1290,7 +1319,7 @@ static void recv_generator(char *fname, |
| 1873 | } else { |
| 1874 | set_file_attrs(fname, file, NULL, 0); |
| 1875 | if (itemizing) { |
| 1876 | - itemize(file, ndx, statret, &st, |
| 1877 | + itemize(fname, file, ndx, statret, &sx, |
| 1878 | ITEM_LOCAL_CHANGE, 0, NULL); |
| 1879 | } |
| 1880 | if (code != FNONE && verbose) |
| 1881 | @@ -1306,7 +1335,7 @@ static void recv_generator(char *fname, |
| 1882 | goto return_with_success; |
| 1883 | } |
| 1884 | #endif |
| 1885 | - return; |
| 1886 | + goto cleanup; |
| 1887 | } |
| 1888 | |
| 1889 | if ((am_root && preserve_devices && IS_DEVICE(file->mode)) |
| 1890 | @@ -1316,33 +1345,33 @@ static void recv_generator(char *fname, |
| 1891 | if (statret == 0) { |
| 1892 | char *t; |
| 1893 | if (IS_DEVICE(file->mode)) { |
| 1894 | - if (!IS_DEVICE(st.st_mode)) |
| 1895 | + if (!IS_DEVICE(sx.st.st_mode)) |
| 1896 | statret = -1; |
| 1897 | t = "device file"; |
| 1898 | } else { |
| 1899 | - if (!IS_SPECIAL(st.st_mode)) |
| 1900 | + if (!IS_SPECIAL(sx.st.st_mode)) |
| 1901 | statret = -1; |
| 1902 | t = "special file"; |
| 1903 | } |
| 1904 | if (statret == 0 |
| 1905 | - && BITS_EQUAL(st.st_mode, file->mode, _S_IFMT) |
| 1906 | - && st.st_rdev == rdev) { |
| 1907 | + && BITS_EQUAL(sx.st.st_mode, file->mode, _S_IFMT) |
| 1908 | + && sx.st.st_rdev == rdev) { |
| 1909 | /* The device or special file is identical. */ |
| 1910 | if (itemizing) |
| 1911 | - itemize(file, ndx, 0, &st, 0, 0, NULL); |
| 1912 | - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT); |
| 1913 | + itemize(fname, file, ndx, 0, &sx, 0, 0, NULL); |
| 1914 | + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT); |
| 1915 | #ifdef SUPPORT_HARD_LINKS |
| 1916 | if (preserve_hard_links && F_IS_HLINKED(file)) |
| 1917 | - finish_hard_link(file, fname, &st, itemizing, code, -1); |
| 1918 | + finish_hard_link(file, fname, &sx.st, itemizing, code, -1); |
| 1919 | #endif |
| 1920 | if (remove_source_files == 1) |
| 1921 | goto return_with_success; |
| 1922 | - return; |
| 1923 | + goto cleanup; |
| 1924 | } |
| 1925 | - if (delete_item(fname, st.st_mode, t, del_opts) != 0) |
| 1926 | - return; |
| 1927 | + if (delete_item(fname, sx.st.st_mode, t, del_opts) != 0) |
| 1928 | + goto cleanup; |
| 1929 | } else if (basis_dir[0] != NULL) { |
| 1930 | - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st, |
| 1931 | + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, |
| 1932 | itemizing, code); |
| 1933 | if (j == -2) { |
| 1934 | #ifndef CAN_HARDLINK_SPECIAL |
| 1935 | @@ -1351,7 +1380,7 @@ static void recv_generator(char *fname, |
| 1936 | } else |
| 1937 | #endif |
| 1938 | if (!copy_dest) |
| 1939 | - return; |
| 1940 | + goto cleanup; |
| 1941 | itemizing = 0; |
| 1942 | code = FNONE; |
| 1943 | } else if (j >= 0) |
| 1944 | @@ -1359,7 +1388,7 @@ static void recv_generator(char *fname, |
| 1945 | } |
| 1946 | #ifdef SUPPORT_HARD_LINKS |
| 1947 | if (preserve_hard_links && F_HLINK_NOT_LAST(file)) |
| 1948 | - return; |
| 1949 | + goto cleanup; |
| 1950 | #endif |
| 1951 | if (verbose > 2) { |
| 1952 | rprintf(FINFO, "mknod(%s, 0%o, [%ld,%ld])\n", |
| 1953 | @@ -1372,7 +1401,7 @@ static void recv_generator(char *fname, |
| 1954 | } else { |
| 1955 | set_file_attrs(fname, file, NULL, 0); |
| 1956 | if (itemizing) { |
| 1957 | - itemize(file, ndx, statret, &st, |
| 1958 | + itemize(fname, file, ndx, statret, &sx, |
| 1959 | ITEM_LOCAL_CHANGE, 0, NULL); |
| 1960 | } |
| 1961 | if (code != FNONE && verbose) |
| 1962 | @@ -1384,14 +1413,14 @@ static void recv_generator(char *fname, |
| 1963 | if (remove_source_files == 1) |
| 1964 | goto return_with_success; |
| 1965 | } |
| 1966 | - return; |
| 1967 | + goto cleanup; |
| 1968 | } |
| 1969 | |
| 1970 | if (!S_ISREG(file->mode)) { |
| 1971 | if (solo_file) |
| 1972 | fname = f_name(file, NULL); |
| 1973 | rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname); |
| 1974 | - return; |
| 1975 | + goto cleanup; |
| 1976 | } |
| 1977 | |
| 1978 | if (max_size > 0 && F_LENGTH(file) > max_size) { |
| 1979 | @@ -1400,7 +1429,7 @@ static void recv_generator(char *fname, |
| 1980 | fname = f_name(file, NULL); |
| 1981 | rprintf(FINFO, "%s is over max-size\n", fname); |
| 1982 | } |
| 1983 | - return; |
| 1984 | + goto cleanup; |
| 1985 | } |
| 1986 | if (min_size > 0 && F_LENGTH(file) < min_size) { |
| 1987 | if (verbose > 1) { |
| 1988 | @@ -1408,39 +1437,39 @@ static void recv_generator(char *fname, |
| 1989 | fname = f_name(file, NULL); |
| 1990 | rprintf(FINFO, "%s is under min-size\n", fname); |
| 1991 | } |
| 1992 | - return; |
| 1993 | + goto cleanup; |
| 1994 | } |
| 1995 | |
| 1996 | if (ignore_existing > 0 && statret == 0) { |
| 1997 | if (verbose > 1) |
| 1998 | rprintf(FINFO, "%s exists\n", fname); |
| 1999 | - return; |
| 2000 | + goto cleanup; |
| 2001 | } |
| 2002 | |
| 2003 | if (update_only > 0 && statret == 0 |
| 2004 | - && cmp_time(st.st_mtime, file->modtime) > 0) { |
| 2005 | + && cmp_time(sx.st.st_mtime, file->modtime) > 0) { |
| 2006 | if (verbose > 1) |
| 2007 | rprintf(FINFO, "%s is newer\n", fname); |
| 2008 | - return; |
| 2009 | + goto cleanup; |
| 2010 | } |
| 2011 | |
| 2012 | fnamecmp = fname; |
| 2013 | fnamecmp_type = FNAMECMP_FNAME; |
| 2014 | |
| 2015 | - if (statret == 0 && !S_ISREG(st.st_mode)) { |
| 2016 | - if (delete_item(fname, st.st_mode, "regular file", del_opts) != 0) |
| 2017 | - return; |
| 2018 | + if (statret == 0 && !S_ISREG(sx.st.st_mode)) { |
| 2019 | + if (delete_item(fname, sx.st.st_mode, "regular file", del_opts) != 0) |
| 2020 | + goto cleanup; |
| 2021 | statret = -1; |
| 2022 | stat_errno = ENOENT; |
| 2023 | } |
| 2024 | |
| 2025 | if (statret != 0 && basis_dir[0] != NULL) { |
| 2026 | - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st, |
| 2027 | + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx, |
| 2028 | itemizing, code); |
| 2029 | if (j == -2) { |
| 2030 | if (remove_source_files == 1) |
| 2031 | goto return_with_success; |
| 2032 | - return; |
| 2033 | + goto cleanup; |
| 2034 | } |
| 2035 | if (j >= 0) { |
| 2036 | fnamecmp = fnamecmpbuf; |
| 2037 | @@ -1450,7 +1479,7 @@ static void recv_generator(char *fname, |
| 2038 | } |
| 2039 | |
| 2040 | real_ret = statret; |
| 2041 | - real_st = st; |
| 2042 | + real_sx = sx; |
| 2043 | |
| 2044 | if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL |
| 2045 | && link_stat(partialptr, &partial_st, 0) == 0 |
| 2046 | @@ -1469,7 +1498,7 @@ static void recv_generator(char *fname, |
| 2047 | rprintf(FINFO, "fuzzy basis selected for %s: %s\n", |
| 2048 | fname, fnamecmpbuf); |
| 2049 | } |
| 2050 | - st.st_size = F_LENGTH(fuzzy_file); |
| 2051 | + sx.st.st_size = F_LENGTH(fuzzy_file); |
| 2052 | statret = 0; |
| 2053 | fnamecmp = fnamecmpbuf; |
| 2054 | fnamecmp_type = FNAMECMP_FUZZY; |
| 2055 | @@ -1479,45 +1508,45 @@ static void recv_generator(char *fname, |
| 2056 | if (statret != 0) { |
| 2057 | #ifdef SUPPORT_HARD_LINKS |
| 2058 | if (preserve_hard_links && F_HLINK_NOT_LAST(file)) |
| 2059 | - return; |
| 2060 | + goto cleanup; |
| 2061 | #endif |
| 2062 | if (stat_errno == ENOENT) |
| 2063 | goto notify_others; |
| 2064 | rsyserr(FERROR, stat_errno, "recv_generator: failed to stat %s", |
| 2065 | full_fname(fname)); |
| 2066 | - return; |
| 2067 | + goto cleanup; |
| 2068 | } |
| 2069 | |
| 2070 | - if (append_mode > 0 && st.st_size > F_LENGTH(file)) |
| 2071 | - return; |
| 2072 | + if (append_mode > 0 && sx.st.st_size > F_LENGTH(file)) |
| 2073 | + goto cleanup; |
| 2074 | |
| 2075 | if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) |
| 2076 | ; |
| 2077 | else if (fnamecmp_type == FNAMECMP_FUZZY) |
| 2078 | ; |
| 2079 | - else if (unchanged_file(fnamecmp, file, &st)) { |
| 2080 | + else if (unchanged_file(fnamecmp, file, &sx.st)) { |
| 2081 | if (partialptr) { |
| 2082 | do_unlink(partialptr); |
| 2083 | handle_partial_dir(partialptr, PDIR_DELETE); |
| 2084 | } |
| 2085 | if (itemizing) |
| 2086 | - itemize(file, ndx, statret, &st, 0, 0, NULL); |
| 2087 | - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT); |
| 2088 | + itemize(fnamecmp, file, ndx, statret, &sx, 0, 0, NULL); |
| 2089 | + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT); |
| 2090 | #ifdef SUPPORT_HARD_LINKS |
| 2091 | if (preserve_hard_links && F_IS_HLINKED(file)) |
| 2092 | - finish_hard_link(file, fname, &st, itemizing, code, -1); |
| 2093 | + finish_hard_link(file, fname, &sx.st, itemizing, code, -1); |
| 2094 | #endif |
| 2095 | if (remove_source_files != 1) |
| 2096 | - return; |
| 2097 | + goto cleanup; |
| 2098 | return_with_success: |
| 2099 | if (!dry_run) |
| 2100 | send_msg_int(MSG_SUCCESS, ndx); |
| 2101 | - return; |
| 2102 | + goto cleanup; |
| 2103 | } |
| 2104 | |
| 2105 | prepare_to_open: |
| 2106 | if (partialptr) { |
| 2107 | - st = partial_st; |
| 2108 | + sx.st = partial_st; |
| 2109 | fnamecmp = partialptr; |
| 2110 | fnamecmp_type = FNAMECMP_PARTIAL_DIR; |
| 2111 | statret = 0; |
| 2112 | @@ -1542,7 +1571,7 @@ static void recv_generator(char *fname, |
| 2113 | /* pretend the file didn't exist */ |
| 2114 | #ifdef SUPPORT_HARD_LINKS |
| 2115 | if (preserve_hard_links && F_HLINK_NOT_LAST(file)) |
| 2116 | - return; |
| 2117 | + goto cleanup; |
| 2118 | #endif |
| 2119 | statret = real_ret = -1; |
| 2120 | goto notify_others; |
| 2121 | @@ -1551,7 +1580,7 @@ static void recv_generator(char *fname, |
| 2122 | if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) { |
| 2123 | if (!(backupptr = get_backup_name(fname))) { |
| 2124 | close(fd); |
| 2125 | - return; |
| 2126 | + goto cleanup; |
| 2127 | } |
| 2128 | if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) { |
| 2129 | close(fd); |
| 2130 | @@ -1562,7 +1591,7 @@ static void recv_generator(char *fname, |
| 2131 | full_fname(backupptr)); |
| 2132 | unmake_file(back_file); |
| 2133 | close(fd); |
| 2134 | - return; |
| 2135 | + goto cleanup; |
| 2136 | } |
| 2137 | if ((f_copy = do_open(backupptr, |
| 2138 | O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) { |
| 2139 | @@ -1570,14 +1599,14 @@ static void recv_generator(char *fname, |
| 2140 | full_fname(backupptr)); |
| 2141 | unmake_file(back_file); |
| 2142 | close(fd); |
| 2143 | - return; |
| 2144 | + goto cleanup; |
| 2145 | } |
| 2146 | fnamecmp_type = FNAMECMP_BACKUP; |
| 2147 | } |
| 2148 | |
| 2149 | if (verbose > 3) { |
| 2150 | rprintf(FINFO, "gen mapped %s of size %.0f\n", |
| 2151 | - fnamecmp, (double)st.st_size); |
| 2152 | + fnamecmp, (double)sx.st.st_size); |
| 2153 | } |
| 2154 | |
| 2155 | if (verbose > 2) |
| 2156 | @@ -1601,26 +1630,30 @@ static void recv_generator(char *fname, |
| 2157 | iflags |= ITEM_BASIS_TYPE_FOLLOWS; |
| 2158 | if (fnamecmp_type == FNAMECMP_FUZZY) |
| 2159 | iflags |= ITEM_XNAME_FOLLOWS; |
| 2160 | - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type, |
| 2161 | + itemize(fnamecmp, file, -1, real_ret, &real_sx, iflags, fnamecmp_type, |
| 2162 | fuzzy_file ? fuzzy_file->basename : NULL); |
| 2163 | +#ifdef SUPPORT_ACLS |
| 2164 | + if (preserve_acls) |
| 2165 | + free_acl(&real_sx); |
| 2166 | +#endif |
| 2167 | } |
| 2168 | |
| 2169 | if (!do_xfers) { |
| 2170 | #ifdef SUPPORT_HARD_LINKS |
| 2171 | if (preserve_hard_links && F_IS_HLINKED(file)) |
| 2172 | - finish_hard_link(file, fname, &st, itemizing, code, -1); |
| 2173 | + finish_hard_link(file, fname, &sx.st, itemizing, code, -1); |
| 2174 | #endif |
| 2175 | - return; |
| 2176 | + goto cleanup; |
| 2177 | } |
| 2178 | if (read_batch) |
| 2179 | - return; |
| 2180 | + goto cleanup; |
| 2181 | |
| 2182 | if (statret != 0 || whole_file) { |
| 2183 | write_sum_head(f_out, NULL); |
| 2184 | - return; |
| 2185 | + goto cleanup; |
| 2186 | } |
| 2187 | |
| 2188 | - generate_and_send_sums(fd, st.st_size, f_out, f_copy); |
| 2189 | + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy); |
| 2190 | |
| 2191 | if (f_copy >= 0) { |
| 2192 | close(f_copy); |
| 2193 | @@ -1633,6 +1666,13 @@ static void recv_generator(char *fname, |
| 2194 | } |
| 2195 | |
| 2196 | close(fd); |
| 2197 | + |
| 2198 | + cleanup: |
| 2199 | +#ifdef SUPPORT_ACLS |
| 2200 | + if (preserve_acls) |
| 2201 | + free_acl(&sx); |
| 2202 | +#endif |
| 2203 | + return; |
| 2204 | } |
| 2205 | |
| 2206 | static void touch_up_dirs(struct file_list *flist, int ndx) |
| 2207 | @@ -1803,6 +1843,8 @@ void generate_files(int f_out, const cha |
| 2208 | * notice that and let us know via the redo pipe (or its closing). */ |
| 2209 | ignore_timeout = 1; |
| 2210 | |
| 2211 | + dflt_perms = (ACCESSPERMS & ~orig_umask); |
| 2212 | + |
| 2213 | do { |
| 2214 | if (inc_recurse && delete_during && cur_flist->ndx_start) { |
| 2215 | struct file_struct *fp = dir_flist->files[cur_flist->parent_ndx]; |
| 2216 | --- old/hlink.c |
| 2217 | +++ new/hlink.c |
| 2218 | @@ -26,6 +26,7 @@ extern int verbose; |
| 2219 | extern int dry_run; |
| 2220 | extern int do_xfers; |
| 2221 | extern int link_dest; |
| 2222 | +extern int preserve_acls; |
| 2223 | extern int make_backups; |
| 2224 | extern int protocol_version; |
| 2225 | extern int remove_source_files; |
| 2226 | @@ -267,15 +268,15 @@ void match_hard_links(void) |
| 2227 | } |
| 2228 | |
| 2229 | static int maybe_hard_link(struct file_struct *file, int ndx, |
| 2230 | - const char *fname, int statret, STRUCT_STAT *stp, |
| 2231 | + const char *fname, int statret, statx *sxp, |
| 2232 | const char *oldname, STRUCT_STAT *old_stp, |
| 2233 | const char *realname, int itemizing, enum logcode code) |
| 2234 | { |
| 2235 | if (statret == 0) { |
| 2236 | - if (stp->st_dev == old_stp->st_dev |
| 2237 | - && stp->st_ino == old_stp->st_ino) { |
| 2238 | + if (sxp->st.st_dev == old_stp->st_dev |
| 2239 | + && sxp->st.st_ino == old_stp->st_ino) { |
| 2240 | if (itemizing) { |
| 2241 | - itemize(file, ndx, statret, stp, |
| 2242 | + itemize(fname, file, ndx, statret, sxp, |
| 2243 | ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, |
| 2244 | 0, ""); |
| 2245 | } |
| 2246 | @@ -296,7 +297,7 @@ static int maybe_hard_link(struct file_s |
| 2247 | |
| 2248 | if (hard_link_one(file, fname, oldname, 0)) { |
| 2249 | if (itemizing) { |
| 2250 | - itemize(file, ndx, statret, stp, |
| 2251 | + itemize(fname, file, ndx, statret, sxp, |
| 2252 | ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0, |
| 2253 | realname); |
| 2254 | } |
| 2255 | @@ -310,7 +311,7 @@ static int maybe_hard_link(struct file_s |
| 2256 | /* Only called if FLAG_HLINKED is set and FLAG_HLINK_FIRST is not. Returns: |
| 2257 | * 0 = process the file, 1 = skip the file, -1 = error occurred. */ |
| 2258 | int hard_link_check(struct file_struct *file, int ndx, const char *fname, |
| 2259 | - int statret, STRUCT_STAT *stp, int itemizing, |
| 2260 | + int statret, statx *sxp, int itemizing, |
| 2261 | enum logcode code) |
| 2262 | { |
| 2263 | STRUCT_STAT prev_st; |
| 2264 | @@ -361,18 +362,20 @@ int hard_link_check(struct file_struct * |
| 2265 | if (statret < 0 && basis_dir[0] != NULL) { |
| 2266 | /* If we match an alt-dest item, we don't output this as a change. */ |
| 2267 | char cmpbuf[MAXPATHLEN]; |
| 2268 | - STRUCT_STAT alt_st; |
| 2269 | + statx alt_sx; |
| 2270 | int j = 0; |
| 2271 | +#ifdef SUPPORT_ACLS |
| 2272 | + alt_sx.acc_acl = alt_sx.def_acl = NULL; |
| 2273 | +#endif |
| 2274 | do { |
| 2275 | pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); |
| 2276 | - if (link_stat(cmpbuf, &alt_st, 0) < 0) |
| 2277 | + if (link_stat(cmpbuf, &alt_sx.st, 0) < 0) |
| 2278 | continue; |
| 2279 | if (link_dest) { |
| 2280 | - if (prev_st.st_dev != alt_st.st_dev |
| 2281 | - || prev_st.st_ino != alt_st.st_ino) |
| 2282 | + if (prev_st.st_dev != alt_sx.st.st_dev |
| 2283 | + || prev_st.st_ino != alt_sx.st.st_ino) |
| 2284 | continue; |
| 2285 | statret = 1; |
| 2286 | - *stp = alt_st; |
| 2287 | if (verbose < 2 || !stdout_format_has_i) { |
| 2288 | itemizing = 0; |
| 2289 | code = FNONE; |
| 2290 | @@ -381,16 +384,32 @@ int hard_link_check(struct file_struct * |
| 2291 | } |
| 2292 | break; |
| 2293 | } |
| 2294 | - if (!unchanged_file(cmpbuf, file, &alt_st)) |
| 2295 | + if (!unchanged_file(cmpbuf, file, &alt_sx.st)) |
| 2296 | continue; |
| 2297 | statret = 1; |
| 2298 | - *stp = alt_st; |
| 2299 | - if (unchanged_attrs(file, &alt_st)) |
| 2300 | + if (unchanged_attrs(cmpbuf, file, &alt_sx)) |
| 2301 | break; |
| 2302 | } while (basis_dir[++j] != NULL); |
| 2303 | + if (statret == 1) { |
| 2304 | + sxp->st = alt_sx.st; |
| 2305 | +#ifdef SUPPORT_ACLS |
| 2306 | + if (preserve_acls) { |
| 2307 | + if (!ACL_READY(*sxp)) |
| 2308 | + get_acl(cmpbuf, sxp); |
| 2309 | + else { |
| 2310 | + sxp->acc_acl = alt_sx.acc_acl; |
| 2311 | + sxp->def_acl = alt_sx.def_acl; |
| 2312 | + } |
| 2313 | + } |
| 2314 | +#endif |
| 2315 | + } |
| 2316 | +#ifdef SUPPORT_ACLS |
| 2317 | + else if (preserve_acls) |
| 2318 | + free_acl(&alt_sx); |
| 2319 | +#endif |
| 2320 | } |
| 2321 | |
| 2322 | - if (maybe_hard_link(file, ndx, fname, statret, stp, prev_name, &prev_st, |
| 2323 | + if (maybe_hard_link(file, ndx, fname, statret, sxp, prev_name, &prev_st, |
| 2324 | realname, itemizing, code) < 0) |
| 2325 | return -1; |
| 2326 | |
| 2327 | @@ -425,7 +444,8 @@ void finish_hard_link(struct file_struct |
| 2328 | STRUCT_STAT *stp, int itemizing, enum logcode code, |
| 2329 | int alt_dest) |
| 2330 | { |
| 2331 | - STRUCT_STAT st, prev_st; |
| 2332 | + statx prev_sx; |
| 2333 | + STRUCT_STAT st; |
| 2334 | char alt_name[MAXPATHLEN], *prev_name; |
| 2335 | const char *our_name; |
| 2336 | int prev_statret, ndx, prev_ndx = F_HL_PREV(file); |
| 2337 | @@ -449,14 +469,24 @@ void finish_hard_link(struct file_struct |
| 2338 | } else |
| 2339 | our_name = fname; |
| 2340 | |
| 2341 | +#ifdef SUPPORT_ACLS |
| 2342 | + prev_sx.acc_acl = prev_sx.def_acl = NULL; |
| 2343 | +#endif |
| 2344 | + |
| 2345 | while ((ndx = prev_ndx) >= 0) { |
| 2346 | + int val; |
| 2347 | file = FPTR(ndx); |
| 2348 | file->flags = (file->flags & ~FLAG_HLINK_FIRST) | FLAG_HLINK_DONE; |
| 2349 | prev_ndx = F_HL_PREV(file); |
| 2350 | prev_name = f_name(file, NULL); |
| 2351 | - prev_statret = link_stat(prev_name, &prev_st, 0); |
| 2352 | - if (maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_st, |
| 2353 | - our_name, stp, fname, itemizing, code) < 0) |
| 2354 | + prev_statret = link_stat(prev_name, &prev_sx.st, 0); |
| 2355 | + val = maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_sx, |
| 2356 | + our_name, stp, fname, itemizing, code); |
| 2357 | +#ifdef SUPPORT_ACLS |
| 2358 | + if (preserve_acls) |
| 2359 | + free_acl(&prev_sx); |
| 2360 | +#endif |
| 2361 | + if (val < 0) |
| 2362 | continue; |
| 2363 | if (remove_source_files == 1 && do_xfers) |
| 2364 | send_msg_int(MSG_SUCCESS, ndx); |
| 2365 | --- old/lib/sysacls.c |
| 2366 | +++ new/lib/sysacls.c |
| 2367 | @@ -0,0 +1,3251 @@ |
| 2368 | +/* |
| 2369 | + Unix SMB/CIFS implementation. |
| 2370 | + Samba system utilities for ACL support. |
| 2371 | + Copyright (C) Jeremy Allison 2000. |
| 2372 | + |
| 2373 | + This program is free software; you can redistribute it and/or modify |
| 2374 | + it under the terms of the GNU General Public License as published by |
| 2375 | + the Free Software Foundation; either version 2 of the License, or |
| 2376 | + (at your option) any later version. |
| 2377 | + |
| 2378 | + This program is distributed in the hope that it will be useful, |
| 2379 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 2380 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 2381 | + GNU General Public License for more details. |
| 2382 | + |
| 2383 | + You should have received a copy of the GNU General Public License |
| 2384 | + along with this program; if not, write to the Free Software |
| 2385 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 2386 | +*/ |
| 2387 | + |
| 2388 | +#include "rsync.h" |
| 2389 | +#include "sysacls.h" /****** ADDED ******/ |
| 2390 | + |
| 2391 | +#ifdef SUPPORT_ACLS |
| 2392 | + |
| 2393 | +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/ |
| 2394 | +#ifdef DEBUG |
| 2395 | +#undef DEBUG |
| 2396 | +#endif |
| 2397 | +#define DEBUG(x,y) |
| 2398 | + |
| 2399 | +void SAFE_FREE(void *mem) |
| 2400 | +{ |
| 2401 | + if (mem) |
| 2402 | + free(mem); |
| 2403 | +} |
| 2404 | + |
| 2405 | +char *uidtoname(uid_t uid) |
| 2406 | +{ |
| 2407 | + static char idbuf[12]; |
| 2408 | + struct passwd *pw; |
| 2409 | + |
| 2410 | + if ((pw = getpwuid(uid)) == NULL) { |
| 2411 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid); |
| 2412 | + return idbuf; |
| 2413 | + } |
| 2414 | + return pw->pw_name; |
| 2415 | +} |
| 2416 | +/****** EXTRAS -- END ******/ |
| 2417 | + |
| 2418 | +/* |
| 2419 | + This file wraps all differing system ACL interfaces into a consistent |
| 2420 | + one based on the POSIX interface. It also returns the correct errors |
| 2421 | + for older UNIX systems that don't support ACLs. |
| 2422 | + |
| 2423 | + The interfaces that each ACL implementation must support are as follows : |
| 2424 | + |
| 2425 | + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 2426 | + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
| 2427 | + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p |
| 2428 | + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
| 2429 | + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
| 2430 | + SMB_ACL_T sys_acl_get_fd(int fd) |
| 2431 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); |
| 2432 | + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); |
| 2433 | + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) |
| 2434 | + SMB_ACL_T sys_acl_init( int count) |
| 2435 | + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
| 2436 | + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
| 2437 | + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
| 2438 | + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
| 2439 | + int sys_acl_valid( SMB_ACL_T theacl ) |
| 2440 | + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
| 2441 | + int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
| 2442 | + int sys_acl_delete_def_file(const char *path) |
| 2443 | + |
| 2444 | + This next one is not POSIX complient - but we *have* to have it ! |
| 2445 | + More POSIX braindamage. |
| 2446 | + |
| 2447 | + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
| 2448 | + |
| 2449 | + The generic POSIX free is the following call. We split this into |
| 2450 | + several different free functions as we may need to add tag info |
| 2451 | + to structures when emulating the POSIX interface. |
| 2452 | + |
| 2453 | + int sys_acl_free( void *obj_p) |
| 2454 | + |
| 2455 | + The calls we actually use are : |
| 2456 | + |
| 2457 | + int sys_acl_free_text(char *text) - free acl_to_text |
| 2458 | + int sys_acl_free_acl(SMB_ACL_T posix_acl) |
| 2459 | + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype) |
| 2460 | + |
| 2461 | +*/ |
| 2462 | + |
| 2463 | +#if defined(HAVE_POSIX_ACLS) |
| 2464 | + |
| 2465 | +/* Identity mapping - easy. */ |
| 2466 | + |
| 2467 | +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 2468 | +{ |
| 2469 | + return acl_get_entry( the_acl, entry_id, entry_p); |
| 2470 | +} |
| 2471 | + |
| 2472 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
| 2473 | +{ |
| 2474 | + return acl_get_tag_type( entry_d, tag_type_p); |
| 2475 | +} |
| 2476 | + |
| 2477 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
| 2478 | +{ |
| 2479 | + return acl_get_permset( entry_d, permset_p); |
| 2480 | +} |
| 2481 | + |
| 2482 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
| 2483 | +{ |
| 2484 | + return acl_get_qualifier( entry_d); |
| 2485 | +} |
| 2486 | + |
| 2487 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
| 2488 | +{ |
| 2489 | + return acl_get_file( path_p, type); |
| 2490 | +} |
| 2491 | + |
| 2492 | +SMB_ACL_T sys_acl_get_fd(int fd) |
| 2493 | +{ |
| 2494 | + return acl_get_fd(fd); |
| 2495 | +} |
| 2496 | + |
| 2497 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
| 2498 | +{ |
| 2499 | + return acl_clear_perms(permset); |
| 2500 | +} |
| 2501 | + |
| 2502 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
| 2503 | +{ |
| 2504 | + return acl_add_perm(permset, perm); |
| 2505 | +} |
| 2506 | + |
| 2507 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
| 2508 | +{ |
| 2509 | +#if defined(HAVE_ACL_GET_PERM_NP) |
| 2510 | + /* |
| 2511 | + * Required for TrustedBSD-based ACL implementations where |
| 2512 | + * non-POSIX.1e functions are denoted by a _np (non-portable) |
| 2513 | + * suffix. |
| 2514 | + */ |
| 2515 | + return acl_get_perm_np(permset, perm); |
| 2516 | +#else |
| 2517 | + return acl_get_perm(permset, perm); |
| 2518 | +#endif |
| 2519 | +} |
| 2520 | + |
| 2521 | +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) |
| 2522 | +{ |
| 2523 | + return acl_to_text( the_acl, plen); |
| 2524 | +} |
| 2525 | + |
| 2526 | +SMB_ACL_T sys_acl_init( int count) |
| 2527 | +{ |
| 2528 | + return acl_init(count); |
| 2529 | +} |
| 2530 | + |
| 2531 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
| 2532 | +{ |
| 2533 | + return acl_create_entry(pacl, pentry); |
| 2534 | +} |
| 2535 | + |
| 2536 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
| 2537 | +{ |
| 2538 | + return acl_set_tag_type(entry, tagtype); |
| 2539 | +} |
| 2540 | + |
| 2541 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
| 2542 | +{ |
| 2543 | + return acl_set_qualifier(entry, qual); |
| 2544 | +} |
| 2545 | + |
| 2546 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
| 2547 | +{ |
| 2548 | + return acl_set_permset(entry, permset); |
| 2549 | +} |
| 2550 | + |
| 2551 | +int sys_acl_valid( SMB_ACL_T theacl ) |
| 2552 | +{ |
| 2553 | + return acl_valid(theacl); |
| 2554 | +} |
| 2555 | + |
| 2556 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
| 2557 | +{ |
| 2558 | + return acl_set_file(name, acltype, theacl); |
| 2559 | +} |
| 2560 | + |
| 2561 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
| 2562 | +{ |
| 2563 | + return acl_set_fd(fd, theacl); |
| 2564 | +} |
| 2565 | + |
| 2566 | +int sys_acl_delete_def_file(const char *name) |
| 2567 | +{ |
| 2568 | + return acl_delete_def_file(name); |
| 2569 | +} |
| 2570 | + |
| 2571 | +int sys_acl_free_text(char *text) |
| 2572 | +{ |
| 2573 | + return acl_free(text); |
| 2574 | +} |
| 2575 | + |
| 2576 | +int sys_acl_free_acl(SMB_ACL_T the_acl) |
| 2577 | +{ |
| 2578 | + return acl_free(the_acl); |
| 2579 | +} |
| 2580 | + |
| 2581 | +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype)) |
| 2582 | +{ |
| 2583 | + return acl_free(qual); |
| 2584 | +} |
| 2585 | + |
| 2586 | +#elif defined(HAVE_TRU64_ACLS) |
| 2587 | +/* |
| 2588 | + * The interface to DEC/Compaq Tru64 UNIX ACLs |
| 2589 | + * is based on Draft 13 of the POSIX spec which is |
| 2590 | + * slightly different from the Draft 16 interface. |
| 2591 | + * |
| 2592 | + * Also, some of the permset manipulation functions |
| 2593 | + * such as acl_clear_perm() and acl_add_perm() appear |
| 2594 | + * to be broken on Tru64 so we have to manipulate |
| 2595 | + * the permission bits in the permset directly. |
| 2596 | + */ |
| 2597 | +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 2598 | +{ |
| 2599 | + SMB_ACL_ENTRY_T entry; |
| 2600 | + |
| 2601 | + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) { |
| 2602 | + return -1; |
| 2603 | + } |
| 2604 | + |
| 2605 | + errno = 0; |
| 2606 | + if ((entry = acl_get_entry(the_acl)) != NULL) { |
| 2607 | + *entry_p = entry; |
| 2608 | + return 1; |
| 2609 | + } |
| 2610 | + |
| 2611 | + return errno ? -1 : 0; |
| 2612 | +} |
| 2613 | + |
| 2614 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
| 2615 | +{ |
| 2616 | + return acl_get_tag_type( entry_d, tag_type_p); |
| 2617 | +} |
| 2618 | + |
| 2619 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
| 2620 | +{ |
| 2621 | + return acl_get_permset( entry_d, permset_p); |
| 2622 | +} |
| 2623 | + |
| 2624 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
| 2625 | +{ |
| 2626 | + return acl_get_qualifier( entry_d); |
| 2627 | +} |
| 2628 | + |
| 2629 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
| 2630 | +{ |
| 2631 | + return acl_get_file((char *)path_p, type); |
| 2632 | +} |
| 2633 | + |
| 2634 | +SMB_ACL_T sys_acl_get_fd(int fd) |
| 2635 | +{ |
| 2636 | + return acl_get_fd(fd, ACL_TYPE_ACCESS); |
| 2637 | +} |
| 2638 | + |
| 2639 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
| 2640 | +{ |
| 2641 | + *permset = 0; /* acl_clear_perm() is broken on Tru64 */ |
| 2642 | + |
| 2643 | + return 0; |
| 2644 | +} |
| 2645 | + |
| 2646 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
| 2647 | +{ |
| 2648 | + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) { |
| 2649 | + errno = EINVAL; |
| 2650 | + return -1; |
| 2651 | + } |
| 2652 | + |
| 2653 | + *permset |= perm; /* acl_add_perm() is broken on Tru64 */ |
| 2654 | + |
| 2655 | + return 0; |
| 2656 | +} |
| 2657 | + |
| 2658 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
| 2659 | +{ |
| 2660 | + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */ |
| 2661 | +} |
| 2662 | + |
| 2663 | +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) |
| 2664 | +{ |
| 2665 | + return acl_to_text( the_acl, plen); |
| 2666 | +} |
| 2667 | + |
| 2668 | +SMB_ACL_T sys_acl_init( int count) |
| 2669 | +{ |
| 2670 | + return acl_init(count); |
| 2671 | +} |
| 2672 | + |
| 2673 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
| 2674 | +{ |
| 2675 | + SMB_ACL_ENTRY_T entry; |
| 2676 | + |
| 2677 | + if ((entry = acl_create_entry(pacl)) == NULL) { |
| 2678 | + return -1; |
| 2679 | + } |
| 2680 | + |
| 2681 | + *pentry = entry; |
| 2682 | + return 0; |
| 2683 | +} |
| 2684 | + |
| 2685 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
| 2686 | +{ |
| 2687 | + return acl_set_tag_type(entry, tagtype); |
| 2688 | +} |
| 2689 | + |
| 2690 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
| 2691 | +{ |
| 2692 | + return acl_set_qualifier(entry, qual); |
| 2693 | +} |
| 2694 | + |
| 2695 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
| 2696 | +{ |
| 2697 | + return acl_set_permset(entry, permset); |
| 2698 | +} |
| 2699 | + |
| 2700 | +int sys_acl_valid( SMB_ACL_T theacl ) |
| 2701 | +{ |
| 2702 | + acl_entry_t entry; |
| 2703 | + |
| 2704 | + return acl_valid(theacl, &entry); |
| 2705 | +} |
| 2706 | + |
| 2707 | +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
| 2708 | +{ |
| 2709 | + return acl_set_file((char *)name, acltype, theacl); |
| 2710 | +} |
| 2711 | + |
| 2712 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
| 2713 | +{ |
| 2714 | + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl); |
| 2715 | +} |
| 2716 | + |
| 2717 | +int sys_acl_delete_def_file(const char *name) |
| 2718 | +{ |
| 2719 | + return acl_delete_def_file((char *)name); |
| 2720 | +} |
| 2721 | + |
| 2722 | +int sys_acl_free_text(char *text) |
| 2723 | +{ |
| 2724 | + /* |
| 2725 | + * (void) cast and explicit return 0 are for DEC UNIX |
| 2726 | + * which just #defines acl_free_text() to be free() |
| 2727 | + */ |
| 2728 | + (void) acl_free_text(text); |
| 2729 | + return 0; |
| 2730 | +} |
| 2731 | + |
| 2732 | +int sys_acl_free_acl(SMB_ACL_T the_acl) |
| 2733 | +{ |
| 2734 | + return acl_free(the_acl); |
| 2735 | +} |
| 2736 | + |
| 2737 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
| 2738 | +{ |
| 2739 | + return acl_free_qualifier(qual, tagtype); |
| 2740 | +} |
| 2741 | + |
| 2742 | +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) |
| 2743 | + |
| 2744 | +/* |
| 2745 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. |
| 2746 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. |
| 2747 | + */ |
| 2748 | + |
| 2749 | +/* |
| 2750 | + * Note that while this code implements sufficient functionality |
| 2751 | + * to support the sys_acl_* interfaces it does not provide all |
| 2752 | + * of the semantics of the POSIX ACL interfaces. |
| 2753 | + * |
| 2754 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned |
| 2755 | + * from a call to sys_acl_get_entry() should not be assumed to be |
| 2756 | + * valid after calling any of the following functions, which may |
| 2757 | + * reorder the entries in the ACL. |
| 2758 | + * |
| 2759 | + * sys_acl_valid() |
| 2760 | + * sys_acl_set_file() |
| 2761 | + * sys_acl_set_fd() |
| 2762 | + */ |
| 2763 | + |
| 2764 | +/* |
| 2765 | + * The only difference between Solaris and UnixWare / OpenUNIX is |
| 2766 | + * that the #defines for the ACL operations have different names |
| 2767 | + */ |
| 2768 | +#if defined(HAVE_UNIXWARE_ACLS) |
| 2769 | + |
| 2770 | +#define SETACL ACL_SET |
| 2771 | +#define GETACL ACL_GET |
| 2772 | +#define GETACLCNT ACL_CNT |
| 2773 | + |
| 2774 | +#endif |
| 2775 | + |
| 2776 | + |
| 2777 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 2778 | +{ |
| 2779 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { |
| 2780 | + errno = EINVAL; |
| 2781 | + return -1; |
| 2782 | + } |
| 2783 | + |
| 2784 | + if (entry_p == NULL) { |
| 2785 | + errno = EINVAL; |
| 2786 | + return -1; |
| 2787 | + } |
| 2788 | + |
| 2789 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { |
| 2790 | + acl_d->next = 0; |
| 2791 | + } |
| 2792 | + |
| 2793 | + if (acl_d->next < 0) { |
| 2794 | + errno = EINVAL; |
| 2795 | + return -1; |
| 2796 | + } |
| 2797 | + |
| 2798 | + if (acl_d->next >= acl_d->count) { |
| 2799 | + return 0; |
| 2800 | + } |
| 2801 | + |
| 2802 | + *entry_p = &acl_d->acl[acl_d->next++]; |
| 2803 | + |
| 2804 | + return 1; |
| 2805 | +} |
| 2806 | + |
| 2807 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
| 2808 | +{ |
| 2809 | + *type_p = entry_d->a_type; |
| 2810 | + |
| 2811 | + return 0; |
| 2812 | +} |
| 2813 | + |
| 2814 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
| 2815 | +{ |
| 2816 | + *permset_p = &entry_d->a_perm; |
| 2817 | + |
| 2818 | + return 0; |
| 2819 | +} |
| 2820 | + |
| 2821 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
| 2822 | +{ |
| 2823 | + if (entry_d->a_type != SMB_ACL_USER |
| 2824 | + && entry_d->a_type != SMB_ACL_GROUP) { |
| 2825 | + errno = EINVAL; |
| 2826 | + return NULL; |
| 2827 | + } |
| 2828 | + |
| 2829 | + return &entry_d->a_id; |
| 2830 | +} |
| 2831 | + |
| 2832 | +/* |
| 2833 | + * There is no way of knowing what size the ACL returned by |
| 2834 | + * GETACL will be unless you first call GETACLCNT which means |
| 2835 | + * making an additional system call. |
| 2836 | + * |
| 2837 | + * In the hope of avoiding the cost of the additional system |
| 2838 | + * call in most cases, we initially allocate enough space for |
| 2839 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to |
| 2840 | + * be too small then we use GETACLCNT to find out the actual |
| 2841 | + * size, reallocate the ACL buffer, and then call GETACL again. |
| 2842 | + */ |
| 2843 | + |
| 2844 | +#define INITIAL_ACL_SIZE 16 |
| 2845 | + |
| 2846 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 2847 | +{ |
| 2848 | + SMB_ACL_T acl_d; |
| 2849 | + int count; /* # of ACL entries allocated */ |
| 2850 | + int naccess; /* # of access ACL entries */ |
| 2851 | + int ndefault; /* # of default ACL entries */ |
| 2852 | + |
| 2853 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 2854 | + errno = EINVAL; |
| 2855 | + return NULL; |
| 2856 | + } |
| 2857 | + |
| 2858 | + count = INITIAL_ACL_SIZE; |
| 2859 | + if ((acl_d = sys_acl_init(count)) == NULL) { |
| 2860 | + return NULL; |
| 2861 | + } |
| 2862 | + |
| 2863 | + /* |
| 2864 | + * If there isn't enough space for the ACL entries we use |
| 2865 | + * GETACLCNT to determine the actual number of ACL entries |
| 2866 | + * reallocate and try again. This is in a loop because it |
| 2867 | + * is possible that someone else could modify the ACL and |
| 2868 | + * increase the number of entries between the call to |
| 2869 | + * GETACLCNT and the call to GETACL. |
| 2870 | + */ |
| 2871 | + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0 |
| 2872 | + && errno == ENOSPC) { |
| 2873 | + |
| 2874 | + sys_acl_free_acl(acl_d); |
| 2875 | + |
| 2876 | + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) { |
| 2877 | + return NULL; |
| 2878 | + } |
| 2879 | + |
| 2880 | + if ((acl_d = sys_acl_init(count)) == NULL) { |
| 2881 | + return NULL; |
| 2882 | + } |
| 2883 | + } |
| 2884 | + |
| 2885 | + if (count < 0) { |
| 2886 | + sys_acl_free_acl(acl_d); |
| 2887 | + return NULL; |
| 2888 | + } |
| 2889 | + |
| 2890 | + /* |
| 2891 | + * calculate the number of access and default ACL entries |
| 2892 | + * |
| 2893 | + * Note: we assume that the acl() system call returned a |
| 2894 | + * well formed ACL which is sorted so that all of the |
| 2895 | + * access ACL entries preceed any default ACL entries |
| 2896 | + */ |
| 2897 | + for (naccess = 0; naccess < count; naccess++) { |
| 2898 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) |
| 2899 | + break; |
| 2900 | + } |
| 2901 | + ndefault = count - naccess; |
| 2902 | + |
| 2903 | + /* |
| 2904 | + * if the caller wants the default ACL we have to copy |
| 2905 | + * the entries down to the start of the acl[] buffer |
| 2906 | + * and mask out the ACL_DEFAULT flag from the type field |
| 2907 | + */ |
| 2908 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
| 2909 | + int i, j; |
| 2910 | + |
| 2911 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { |
| 2912 | + acl_d->acl[i] = acl_d->acl[j]; |
| 2913 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; |
| 2914 | + } |
| 2915 | + |
| 2916 | + acl_d->count = ndefault; |
| 2917 | + } else { |
| 2918 | + acl_d->count = naccess; |
| 2919 | + } |
| 2920 | + |
| 2921 | + return acl_d; |
| 2922 | +} |
| 2923 | + |
| 2924 | +SMB_ACL_T sys_acl_get_fd(int fd) |
| 2925 | +{ |
| 2926 | + SMB_ACL_T acl_d; |
| 2927 | + int count; /* # of ACL entries allocated */ |
| 2928 | + int naccess; /* # of access ACL entries */ |
| 2929 | + |
| 2930 | + count = INITIAL_ACL_SIZE; |
| 2931 | + if ((acl_d = sys_acl_init(count)) == NULL) { |
| 2932 | + return NULL; |
| 2933 | + } |
| 2934 | + |
| 2935 | + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0 |
| 2936 | + && errno == ENOSPC) { |
| 2937 | + |
| 2938 | + sys_acl_free_acl(acl_d); |
| 2939 | + |
| 2940 | + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) { |
| 2941 | + return NULL; |
| 2942 | + } |
| 2943 | + |
| 2944 | + if ((acl_d = sys_acl_init(count)) == NULL) { |
| 2945 | + return NULL; |
| 2946 | + } |
| 2947 | + } |
| 2948 | + |
| 2949 | + if (count < 0) { |
| 2950 | + sys_acl_free_acl(acl_d); |
| 2951 | + return NULL; |
| 2952 | + } |
| 2953 | + |
| 2954 | + /* |
| 2955 | + * calculate the number of access ACL entries |
| 2956 | + */ |
| 2957 | + for (naccess = 0; naccess < count; naccess++) { |
| 2958 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) |
| 2959 | + break; |
| 2960 | + } |
| 2961 | + |
| 2962 | + acl_d->count = naccess; |
| 2963 | + |
| 2964 | + return acl_d; |
| 2965 | +} |
| 2966 | + |
| 2967 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
| 2968 | +{ |
| 2969 | + *permset_d = 0; |
| 2970 | + |
| 2971 | + return 0; |
| 2972 | +} |
| 2973 | + |
| 2974 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
| 2975 | +{ |
| 2976 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE |
| 2977 | + && perm != SMB_ACL_EXECUTE) { |
| 2978 | + errno = EINVAL; |
| 2979 | + return -1; |
| 2980 | + } |
| 2981 | + |
| 2982 | + if (permset_d == NULL) { |
| 2983 | + errno = EINVAL; |
| 2984 | + return -1; |
| 2985 | + } |
| 2986 | + |
| 2987 | + *permset_d |= perm; |
| 2988 | + |
| 2989 | + return 0; |
| 2990 | +} |
| 2991 | + |
| 2992 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
| 2993 | +{ |
| 2994 | + return *permset_d & perm; |
| 2995 | +} |
| 2996 | + |
| 2997 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
| 2998 | +{ |
| 2999 | + int i; |
| 3000 | + int len, maxlen; |
| 3001 | + char *text; |
| 3002 | + |
| 3003 | + /* |
| 3004 | + * use an initial estimate of 20 bytes per ACL entry |
| 3005 | + * when allocating memory for the text representation |
| 3006 | + * of the ACL |
| 3007 | + */ |
| 3008 | + len = 0; |
| 3009 | + maxlen = 20 * acl_d->count; |
| 3010 | + if ((text = SMB_MALLOC(maxlen)) == NULL) { |
| 3011 | + errno = ENOMEM; |
| 3012 | + return NULL; |
| 3013 | + } |
| 3014 | + |
| 3015 | + for (i = 0; i < acl_d->count; i++) { |
| 3016 | + struct acl *ap = &acl_d->acl[i]; |
| 3017 | + struct group *gr; |
| 3018 | + char tagbuf[12]; |
| 3019 | + char idbuf[12]; |
| 3020 | + char *tag; |
| 3021 | + char *id = ""; |
| 3022 | + char perms[4]; |
| 3023 | + int nbytes; |
| 3024 | + |
| 3025 | + switch (ap->a_type) { |
| 3026 | + /* |
| 3027 | + * for debugging purposes it's probably more |
| 3028 | + * useful to dump unknown tag types rather |
| 3029 | + * than just returning an error |
| 3030 | + */ |
| 3031 | + default: |
| 3032 | + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x", |
| 3033 | + ap->a_type); |
| 3034 | + tag = tagbuf; |
| 3035 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
| 3036 | + (long)ap->a_id); |
| 3037 | + id = idbuf; |
| 3038 | + break; |
| 3039 | + |
| 3040 | + case SMB_ACL_USER: |
| 3041 | + id = uidtoname(ap->a_id); |
| 3042 | + case SMB_ACL_USER_OBJ: |
| 3043 | + tag = "user"; |
| 3044 | + break; |
| 3045 | + |
| 3046 | + case SMB_ACL_GROUP: |
| 3047 | + if ((gr = getgrgid(ap->a_id)) == NULL) { |
| 3048 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
| 3049 | + (long)ap->a_id); |
| 3050 | + id = idbuf; |
| 3051 | + } else { |
| 3052 | + id = gr->gr_name; |
| 3053 | + } |
| 3054 | + case SMB_ACL_GROUP_OBJ: |
| 3055 | + tag = "group"; |
| 3056 | + break; |
| 3057 | + |
| 3058 | + case SMB_ACL_OTHER: |
| 3059 | + tag = "other"; |
| 3060 | + break; |
| 3061 | + |
| 3062 | + case SMB_ACL_MASK: |
| 3063 | + tag = "mask"; |
| 3064 | + break; |
| 3065 | + |
| 3066 | + } |
| 3067 | + |
| 3068 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; |
| 3069 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; |
| 3070 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; |
| 3071 | + perms[3] = '\0'; |
| 3072 | + |
| 3073 | + /* <tag> : <qualifier> : rwx \n \0 */ |
| 3074 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; |
| 3075 | + |
| 3076 | + /* |
| 3077 | + * If this entry would overflow the buffer |
| 3078 | + * allocate enough additional memory for this |
| 3079 | + * entry and an estimate of another 20 bytes |
| 3080 | + * for each entry still to be processed |
| 3081 | + */ |
| 3082 | + if ((len + nbytes) > maxlen) { |
| 3083 | + char *oldtext = text; |
| 3084 | + |
| 3085 | + maxlen += nbytes + 20 * (acl_d->count - i); |
| 3086 | + |
| 3087 | + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) { |
| 3088 | + SAFE_FREE(oldtext); |
| 3089 | + errno = ENOMEM; |
| 3090 | + return NULL; |
| 3091 | + } |
| 3092 | + } |
| 3093 | + |
| 3094 | + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); |
| 3095 | + len += nbytes - 1; |
| 3096 | + } |
| 3097 | + |
| 3098 | + if (len_p) |
| 3099 | + *len_p = len; |
| 3100 | + |
| 3101 | + return text; |
| 3102 | +} |
| 3103 | + |
| 3104 | +SMB_ACL_T sys_acl_init(int count) |
| 3105 | +{ |
| 3106 | + SMB_ACL_T a; |
| 3107 | + |
| 3108 | + if (count < 0) { |
| 3109 | + errno = EINVAL; |
| 3110 | + return NULL; |
| 3111 | + } |
| 3112 | + |
| 3113 | + /* |
| 3114 | + * note that since the definition of the structure pointed |
| 3115 | + * to by the SMB_ACL_T includes the first element of the |
| 3116 | + * acl[] array, this actually allocates an ACL with room |
| 3117 | + * for (count+1) entries |
| 3118 | + */ |
| 3119 | + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) { |
| 3120 | + errno = ENOMEM; |
| 3121 | + return NULL; |
| 3122 | + } |
| 3123 | + |
| 3124 | + a->size = count + 1; |
| 3125 | + a->count = 0; |
| 3126 | + a->next = -1; |
| 3127 | + |
| 3128 | + return a; |
| 3129 | +} |
| 3130 | + |
| 3131 | + |
| 3132 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
| 3133 | +{ |
| 3134 | + SMB_ACL_T acl_d; |
| 3135 | + SMB_ACL_ENTRY_T entry_d; |
| 3136 | + |
| 3137 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { |
| 3138 | + errno = EINVAL; |
| 3139 | + return -1; |
| 3140 | + } |
| 3141 | + |
| 3142 | + if (acl_d->count >= acl_d->size) { |
| 3143 | + errno = ENOSPC; |
| 3144 | + return -1; |
| 3145 | + } |
| 3146 | + |
| 3147 | + entry_d = &acl_d->acl[acl_d->count++]; |
| 3148 | + entry_d->a_type = 0; |
| 3149 | + entry_d->a_id = -1; |
| 3150 | + entry_d->a_perm = 0; |
| 3151 | + *entry_p = entry_d; |
| 3152 | + |
| 3153 | + return 0; |
| 3154 | +} |
| 3155 | + |
| 3156 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
| 3157 | +{ |
| 3158 | + switch (tag_type) { |
| 3159 | + case SMB_ACL_USER: |
| 3160 | + case SMB_ACL_USER_OBJ: |
| 3161 | + case SMB_ACL_GROUP: |
| 3162 | + case SMB_ACL_GROUP_OBJ: |
| 3163 | + case SMB_ACL_OTHER: |
| 3164 | + case SMB_ACL_MASK: |
| 3165 | + entry_d->a_type = tag_type; |
| 3166 | + break; |
| 3167 | + default: |
| 3168 | + errno = EINVAL; |
| 3169 | + return -1; |
| 3170 | + } |
| 3171 | + |
| 3172 | + return 0; |
| 3173 | +} |
| 3174 | + |
| 3175 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
| 3176 | +{ |
| 3177 | + if (entry_d->a_type != SMB_ACL_GROUP |
| 3178 | + && entry_d->a_type != SMB_ACL_USER) { |
| 3179 | + errno = EINVAL; |
| 3180 | + return -1; |
| 3181 | + } |
| 3182 | + |
| 3183 | + entry_d->a_id = *((id_t *)qual_p); |
| 3184 | + |
| 3185 | + return 0; |
| 3186 | +} |
| 3187 | + |
| 3188 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
| 3189 | +{ |
| 3190 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { |
| 3191 | + return EINVAL; |
| 3192 | + } |
| 3193 | + |
| 3194 | + entry_d->a_perm = *permset_d; |
| 3195 | + |
| 3196 | + return 0; |
| 3197 | +} |
| 3198 | + |
| 3199 | +/* |
| 3200 | + * sort the ACL and check it for validity |
| 3201 | + * |
| 3202 | + * if it's a minimal ACL with only 4 entries then we |
| 3203 | + * need to recalculate the mask permissions to make |
| 3204 | + * sure that they are the same as the GROUP_OBJ |
| 3205 | + * permissions as required by the UnixWare acl() system call. |
| 3206 | + * |
| 3207 | + * (note: since POSIX allows minimal ACLs which only contain |
| 3208 | + * 3 entries - ie there is no mask entry - we should, in theory, |
| 3209 | + * check for this and add a mask entry if necessary - however |
| 3210 | + * we "know" that the caller of this interface always specifies |
| 3211 | + * a mask so, in practice "this never happens" (tm) - if it *does* |
| 3212 | + * happen aclsort() will fail and return an error and someone will |
| 3213 | + * have to fix it ...) |
| 3214 | + */ |
| 3215 | + |
| 3216 | +static int acl_sort(SMB_ACL_T acl_d) |
| 3217 | +{ |
| 3218 | + int fixmask = (acl_d->count <= 4); |
| 3219 | + |
| 3220 | + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) { |
| 3221 | + errno = EINVAL; |
| 3222 | + return -1; |
| 3223 | + } |
| 3224 | + return 0; |
| 3225 | +} |
| 3226 | + |
| 3227 | +int sys_acl_valid(SMB_ACL_T acl_d) |
| 3228 | +{ |
| 3229 | + return acl_sort(acl_d); |
| 3230 | +} |
| 3231 | + |
| 3232 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
| 3233 | +{ |
| 3234 | + struct stat s; |
| 3235 | + struct acl *acl_p; |
| 3236 | + int acl_count; |
| 3237 | + struct acl *acl_buf = NULL; |
| 3238 | + int ret; |
| 3239 | + |
| 3240 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 3241 | + errno = EINVAL; |
| 3242 | + return -1; |
| 3243 | + } |
| 3244 | + |
| 3245 | + if (acl_sort(acl_d) != 0) { |
| 3246 | + return -1; |
| 3247 | + } |
| 3248 | + |
| 3249 | + acl_p = &acl_d->acl[0]; |
| 3250 | + acl_count = acl_d->count; |
| 3251 | + |
| 3252 | + /* |
| 3253 | + * if it's a directory there is extra work to do |
| 3254 | + * since the acl() system call will replace both |
| 3255 | + * the access ACLs and the default ACLs (if any) |
| 3256 | + */ |
| 3257 | + if (stat(name, &s) != 0) { |
| 3258 | + return -1; |
| 3259 | + } |
| 3260 | + if (S_ISDIR(s.st_mode)) { |
| 3261 | + SMB_ACL_T acc_acl; |
| 3262 | + SMB_ACL_T def_acl; |
| 3263 | + SMB_ACL_T tmp_acl; |
| 3264 | + int i; |
| 3265 | + |
| 3266 | + if (type == SMB_ACL_TYPE_ACCESS) { |
| 3267 | + acc_acl = acl_d; |
| 3268 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); |
| 3269 | + |
| 3270 | + } else { |
| 3271 | + def_acl = acl_d; |
| 3272 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); |
| 3273 | + } |
| 3274 | + |
| 3275 | + if (tmp_acl == NULL) { |
| 3276 | + return -1; |
| 3277 | + } |
| 3278 | + |
| 3279 | + /* |
| 3280 | + * allocate a temporary buffer for the complete ACL |
| 3281 | + */ |
| 3282 | + acl_count = acc_acl->count + def_acl->count; |
| 3283 | + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
| 3284 | + |
| 3285 | + if (acl_buf == NULL) { |
| 3286 | + sys_acl_free_acl(tmp_acl); |
| 3287 | + errno = ENOMEM; |
| 3288 | + return -1; |
| 3289 | + } |
| 3290 | + |
| 3291 | + /* |
| 3292 | + * copy the access control and default entries into the buffer |
| 3293 | + */ |
| 3294 | + memcpy(&acl_buf[0], &acc_acl->acl[0], |
| 3295 | + acc_acl->count * sizeof(acl_buf[0])); |
| 3296 | + |
| 3297 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], |
| 3298 | + def_acl->count * sizeof(acl_buf[0])); |
| 3299 | + |
| 3300 | + /* |
| 3301 | + * set the ACL_DEFAULT flag on the default entries |
| 3302 | + */ |
| 3303 | + for (i = acc_acl->count; i < acl_count; i++) { |
| 3304 | + acl_buf[i].a_type |= ACL_DEFAULT; |
| 3305 | + } |
| 3306 | + |
| 3307 | + sys_acl_free_acl(tmp_acl); |
| 3308 | + |
| 3309 | + } else if (type != SMB_ACL_TYPE_ACCESS) { |
| 3310 | + errno = EINVAL; |
| 3311 | + return -1; |
| 3312 | + } |
| 3313 | + |
| 3314 | + ret = acl(name, SETACL, acl_count, acl_p); |
| 3315 | + |
| 3316 | + SAFE_FREE(acl_buf); |
| 3317 | + |
| 3318 | + return ret; |
| 3319 | +} |
| 3320 | + |
| 3321 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
| 3322 | +{ |
| 3323 | + if (acl_sort(acl_d) != 0) { |
| 3324 | + return -1; |
| 3325 | + } |
| 3326 | + |
| 3327 | + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]); |
| 3328 | +} |
| 3329 | + |
| 3330 | +int sys_acl_delete_def_file(const char *path) |
| 3331 | +{ |
| 3332 | + SMB_ACL_T acl_d; |
| 3333 | + int ret; |
| 3334 | + |
| 3335 | + /* |
| 3336 | + * fetching the access ACL and rewriting it has |
| 3337 | + * the effect of deleting the default ACL |
| 3338 | + */ |
| 3339 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
| 3340 | + return -1; |
| 3341 | + } |
| 3342 | + |
| 3343 | + ret = acl(path, SETACL, acl_d->count, acl_d->acl); |
| 3344 | + |
| 3345 | + sys_acl_free_acl(acl_d); |
| 3346 | + |
| 3347 | + return ret; |
| 3348 | +} |
| 3349 | + |
| 3350 | +int sys_acl_free_text(char *text) |
| 3351 | +{ |
| 3352 | + SAFE_FREE(text); |
| 3353 | + return 0; |
| 3354 | +} |
| 3355 | + |
| 3356 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
| 3357 | +{ |
| 3358 | + SAFE_FREE(acl_d); |
| 3359 | + return 0; |
| 3360 | +} |
| 3361 | + |
| 3362 | +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) |
| 3363 | +{ |
| 3364 | + return 0; |
| 3365 | +} |
| 3366 | + |
| 3367 | +#elif defined(HAVE_HPUX_ACLS) |
| 3368 | +#include <dl.h> |
| 3369 | + |
| 3370 | +/* |
| 3371 | + * Based on the Solaris/SCO code - with modifications. |
| 3372 | + */ |
| 3373 | + |
| 3374 | +/* |
| 3375 | + * Note that while this code implements sufficient functionality |
| 3376 | + * to support the sys_acl_* interfaces it does not provide all |
| 3377 | + * of the semantics of the POSIX ACL interfaces. |
| 3378 | + * |
| 3379 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned |
| 3380 | + * from a call to sys_acl_get_entry() should not be assumed to be |
| 3381 | + * valid after calling any of the following functions, which may |
| 3382 | + * reorder the entries in the ACL. |
| 3383 | + * |
| 3384 | + * sys_acl_valid() |
| 3385 | + * sys_acl_set_file() |
| 3386 | + * sys_acl_set_fd() |
| 3387 | + */ |
| 3388 | + |
| 3389 | +/* This checks if the POSIX ACL system call is defined */ |
| 3390 | +/* which basically corresponds to whether JFS 3.3 or */ |
| 3391 | +/* higher is installed. If acl() was called when it */ |
| 3392 | +/* isn't defined, it causes the process to core dump */ |
| 3393 | +/* so it is important to check this and avoid acl() */ |
| 3394 | +/* calls if it isn't there. */ |
| 3395 | + |
| 3396 | +static BOOL hpux_acl_call_presence(void) |
| 3397 | +{ |
| 3398 | + |
| 3399 | + shl_t handle = NULL; |
| 3400 | + void *value; |
| 3401 | + int ret_val=0; |
| 3402 | + static BOOL already_checked=0; |
| 3403 | + |
| 3404 | + if(already_checked) |
| 3405 | + return True; |
| 3406 | + |
| 3407 | + |
| 3408 | + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value); |
| 3409 | + |
| 3410 | + if(ret_val != 0) { |
| 3411 | + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n", |
| 3412 | + ret_val, errno, strerror(errno))); |
| 3413 | + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n")); |
| 3414 | + return False; |
| 3415 | + } |
| 3416 | + |
| 3417 | + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n")); |
| 3418 | + |
| 3419 | + already_checked = True; |
| 3420 | + return True; |
| 3421 | +} |
| 3422 | + |
| 3423 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 3424 | +{ |
| 3425 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { |
| 3426 | + errno = EINVAL; |
| 3427 | + return -1; |
| 3428 | + } |
| 3429 | + |
| 3430 | + if (entry_p == NULL) { |
| 3431 | + errno = EINVAL; |
| 3432 | + return -1; |
| 3433 | + } |
| 3434 | + |
| 3435 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { |
| 3436 | + acl_d->next = 0; |
| 3437 | + } |
| 3438 | + |
| 3439 | + if (acl_d->next < 0) { |
| 3440 | + errno = EINVAL; |
| 3441 | + return -1; |
| 3442 | + } |
| 3443 | + |
| 3444 | + if (acl_d->next >= acl_d->count) { |
| 3445 | + return 0; |
| 3446 | + } |
| 3447 | + |
| 3448 | + *entry_p = &acl_d->acl[acl_d->next++]; |
| 3449 | + |
| 3450 | + return 1; |
| 3451 | +} |
| 3452 | + |
| 3453 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
| 3454 | +{ |
| 3455 | + *type_p = entry_d->a_type; |
| 3456 | + |
| 3457 | + return 0; |
| 3458 | +} |
| 3459 | + |
| 3460 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
| 3461 | +{ |
| 3462 | + *permset_p = &entry_d->a_perm; |
| 3463 | + |
| 3464 | + return 0; |
| 3465 | +} |
| 3466 | + |
| 3467 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
| 3468 | +{ |
| 3469 | + if (entry_d->a_type != SMB_ACL_USER |
| 3470 | + && entry_d->a_type != SMB_ACL_GROUP) { |
| 3471 | + errno = EINVAL; |
| 3472 | + return NULL; |
| 3473 | + } |
| 3474 | + |
| 3475 | + return &entry_d->a_id; |
| 3476 | +} |
| 3477 | + |
| 3478 | +/* |
| 3479 | + * There is no way of knowing what size the ACL returned by |
| 3480 | + * ACL_GET will be unless you first call ACL_CNT which means |
| 3481 | + * making an additional system call. |
| 3482 | + * |
| 3483 | + * In the hope of avoiding the cost of the additional system |
| 3484 | + * call in most cases, we initially allocate enough space for |
| 3485 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to |
| 3486 | + * be too small then we use ACL_CNT to find out the actual |
| 3487 | + * size, reallocate the ACL buffer, and then call ACL_GET again. |
| 3488 | + */ |
| 3489 | + |
| 3490 | +#define INITIAL_ACL_SIZE 16 |
| 3491 | + |
| 3492 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 3493 | +{ |
| 3494 | + SMB_ACL_T acl_d; |
| 3495 | + int count; /* # of ACL entries allocated */ |
| 3496 | + int naccess; /* # of access ACL entries */ |
| 3497 | + int ndefault; /* # of default ACL entries */ |
| 3498 | + |
| 3499 | + if(hpux_acl_call_presence() == False) { |
| 3500 | + /* Looks like we don't have the acl() system call on HPUX. |
| 3501 | + * May be the system doesn't have the latest version of JFS. |
| 3502 | + */ |
| 3503 | + return NULL; |
| 3504 | + } |
| 3505 | + |
| 3506 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 3507 | + errno = EINVAL; |
| 3508 | + return NULL; |
| 3509 | + } |
| 3510 | + |
| 3511 | + count = INITIAL_ACL_SIZE; |
| 3512 | + if ((acl_d = sys_acl_init(count)) == NULL) { |
| 3513 | + return NULL; |
| 3514 | + } |
| 3515 | + |
| 3516 | + /* |
| 3517 | + * If there isn't enough space for the ACL entries we use |
| 3518 | + * ACL_CNT to determine the actual number of ACL entries |
| 3519 | + * reallocate and try again. This is in a loop because it |
| 3520 | + * is possible that someone else could modify the ACL and |
| 3521 | + * increase the number of entries between the call to |
| 3522 | + * ACL_CNT and the call to ACL_GET. |
| 3523 | + */ |
| 3524 | + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) { |
| 3525 | + |
| 3526 | + sys_acl_free_acl(acl_d); |
| 3527 | + |
| 3528 | + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) { |
| 3529 | + return NULL; |
| 3530 | + } |
| 3531 | + |
| 3532 | + if ((acl_d = sys_acl_init(count)) == NULL) { |
| 3533 | + return NULL; |
| 3534 | + } |
| 3535 | + } |
| 3536 | + |
| 3537 | + if (count < 0) { |
| 3538 | + sys_acl_free_acl(acl_d); |
| 3539 | + return NULL; |
| 3540 | + } |
| 3541 | + |
| 3542 | + /* |
| 3543 | + * calculate the number of access and default ACL entries |
| 3544 | + * |
| 3545 | + * Note: we assume that the acl() system call returned a |
| 3546 | + * well formed ACL which is sorted so that all of the |
| 3547 | + * access ACL entries preceed any default ACL entries |
| 3548 | + */ |
| 3549 | + for (naccess = 0; naccess < count; naccess++) { |
| 3550 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) |
| 3551 | + break; |
| 3552 | + } |
| 3553 | + ndefault = count - naccess; |
| 3554 | + |
| 3555 | + /* |
| 3556 | + * if the caller wants the default ACL we have to copy |
| 3557 | + * the entries down to the start of the acl[] buffer |
| 3558 | + * and mask out the ACL_DEFAULT flag from the type field |
| 3559 | + */ |
| 3560 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
| 3561 | + int i, j; |
| 3562 | + |
| 3563 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { |
| 3564 | + acl_d->acl[i] = acl_d->acl[j]; |
| 3565 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; |
| 3566 | + } |
| 3567 | + |
| 3568 | + acl_d->count = ndefault; |
| 3569 | + } else { |
| 3570 | + acl_d->count = naccess; |
| 3571 | + } |
| 3572 | + |
| 3573 | + return acl_d; |
| 3574 | +} |
| 3575 | + |
| 3576 | +SMB_ACL_T sys_acl_get_fd(int fd) |
| 3577 | +{ |
| 3578 | + /* |
| 3579 | + * HPUX doesn't have the facl call. Fake it using the path.... JRA. |
| 3580 | + */ |
| 3581 | + |
| 3582 | + files_struct *fsp = file_find_fd(fd); |
| 3583 | + |
| 3584 | + if (fsp == NULL) { |
| 3585 | + errno = EBADF; |
| 3586 | + return NULL; |
| 3587 | + } |
| 3588 | + |
| 3589 | + /* |
| 3590 | + * We know we're in the same conn context. So we |
| 3591 | + * can use the relative path. |
| 3592 | + */ |
| 3593 | + |
| 3594 | + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS); |
| 3595 | +} |
| 3596 | + |
| 3597 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
| 3598 | +{ |
| 3599 | + *permset_d = 0; |
| 3600 | + |
| 3601 | + return 0; |
| 3602 | +} |
| 3603 | + |
| 3604 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
| 3605 | +{ |
| 3606 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE |
| 3607 | + && perm != SMB_ACL_EXECUTE) { |
| 3608 | + errno = EINVAL; |
| 3609 | + return -1; |
| 3610 | + } |
| 3611 | + |
| 3612 | + if (permset_d == NULL) { |
| 3613 | + errno = EINVAL; |
| 3614 | + return -1; |
| 3615 | + } |
| 3616 | + |
| 3617 | + *permset_d |= perm; |
| 3618 | + |
| 3619 | + return 0; |
| 3620 | +} |
| 3621 | + |
| 3622 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
| 3623 | +{ |
| 3624 | + return *permset_d & perm; |
| 3625 | +} |
| 3626 | + |
| 3627 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
| 3628 | +{ |
| 3629 | + int i; |
| 3630 | + int len, maxlen; |
| 3631 | + char *text; |
| 3632 | + |
| 3633 | + /* |
| 3634 | + * use an initial estimate of 20 bytes per ACL entry |
| 3635 | + * when allocating memory for the text representation |
| 3636 | + * of the ACL |
| 3637 | + */ |
| 3638 | + len = 0; |
| 3639 | + maxlen = 20 * acl_d->count; |
| 3640 | + if ((text = SMB_MALLOC(maxlen)) == NULL) { |
| 3641 | + errno = ENOMEM; |
| 3642 | + return NULL; |
| 3643 | + } |
| 3644 | + |
| 3645 | + for (i = 0; i < acl_d->count; i++) { |
| 3646 | + struct acl *ap = &acl_d->acl[i]; |
| 3647 | + struct group *gr; |
| 3648 | + char tagbuf[12]; |
| 3649 | + char idbuf[12]; |
| 3650 | + char *tag; |
| 3651 | + char *id = ""; |
| 3652 | + char perms[4]; |
| 3653 | + int nbytes; |
| 3654 | + |
| 3655 | + switch (ap->a_type) { |
| 3656 | + /* |
| 3657 | + * for debugging purposes it's probably more |
| 3658 | + * useful to dump unknown tag types rather |
| 3659 | + * than just returning an error |
| 3660 | + */ |
| 3661 | + default: |
| 3662 | + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x", |
| 3663 | + ap->a_type); |
| 3664 | + tag = tagbuf; |
| 3665 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
| 3666 | + (long)ap->a_id); |
| 3667 | + id = idbuf; |
| 3668 | + break; |
| 3669 | + |
| 3670 | + case SMB_ACL_USER: |
| 3671 | + id = uidtoname(ap->a_id); |
| 3672 | + case SMB_ACL_USER_OBJ: |
| 3673 | + tag = "user"; |
| 3674 | + break; |
| 3675 | + |
| 3676 | + case SMB_ACL_GROUP: |
| 3677 | + if ((gr = getgrgid(ap->a_id)) == NULL) { |
| 3678 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
| 3679 | + (long)ap->a_id); |
| 3680 | + id = idbuf; |
| 3681 | + } else { |
| 3682 | + id = gr->gr_name; |
| 3683 | + } |
| 3684 | + case SMB_ACL_GROUP_OBJ: |
| 3685 | + tag = "group"; |
| 3686 | + break; |
| 3687 | + |
| 3688 | + case SMB_ACL_OTHER: |
| 3689 | + tag = "other"; |
| 3690 | + break; |
| 3691 | + |
| 3692 | + case SMB_ACL_MASK: |
| 3693 | + tag = "mask"; |
| 3694 | + break; |
| 3695 | + |
| 3696 | + } |
| 3697 | + |
| 3698 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; |
| 3699 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; |
| 3700 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; |
| 3701 | + perms[3] = '\0'; |
| 3702 | + |
| 3703 | + /* <tag> : <qualifier> : rwx \n \0 */ |
| 3704 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; |
| 3705 | + |
| 3706 | + /* |
| 3707 | + * If this entry would overflow the buffer |
| 3708 | + * allocate enough additional memory for this |
| 3709 | + * entry and an estimate of another 20 bytes |
| 3710 | + * for each entry still to be processed |
| 3711 | + */ |
| 3712 | + if ((len + nbytes) > maxlen) { |
| 3713 | + char *oldtext = text; |
| 3714 | + |
| 3715 | + maxlen += nbytes + 20 * (acl_d->count - i); |
| 3716 | + |
| 3717 | + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) { |
| 3718 | + free(oldtext); |
| 3719 | + errno = ENOMEM; |
| 3720 | + return NULL; |
| 3721 | + } |
| 3722 | + } |
| 3723 | + |
| 3724 | + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); |
| 3725 | + len += nbytes - 1; |
| 3726 | + } |
| 3727 | + |
| 3728 | + if (len_p) |
| 3729 | + *len_p = len; |
| 3730 | + |
| 3731 | + return text; |
| 3732 | +} |
| 3733 | + |
| 3734 | +SMB_ACL_T sys_acl_init(int count) |
| 3735 | +{ |
| 3736 | + SMB_ACL_T a; |
| 3737 | + |
| 3738 | + if (count < 0) { |
| 3739 | + errno = EINVAL; |
| 3740 | + return NULL; |
| 3741 | + } |
| 3742 | + |
| 3743 | + /* |
| 3744 | + * note that since the definition of the structure pointed |
| 3745 | + * to by the SMB_ACL_T includes the first element of the |
| 3746 | + * acl[] array, this actually allocates an ACL with room |
| 3747 | + * for (count+1) entries |
| 3748 | + */ |
| 3749 | + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) { |
| 3750 | + errno = ENOMEM; |
| 3751 | + return NULL; |
| 3752 | + } |
| 3753 | + |
| 3754 | + a->size = count + 1; |
| 3755 | + a->count = 0; |
| 3756 | + a->next = -1; |
| 3757 | + |
| 3758 | + return a; |
| 3759 | +} |
| 3760 | + |
| 3761 | + |
| 3762 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
| 3763 | +{ |
| 3764 | + SMB_ACL_T acl_d; |
| 3765 | + SMB_ACL_ENTRY_T entry_d; |
| 3766 | + |
| 3767 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { |
| 3768 | + errno = EINVAL; |
| 3769 | + return -1; |
| 3770 | + } |
| 3771 | + |
| 3772 | + if (acl_d->count >= acl_d->size) { |
| 3773 | + errno = ENOSPC; |
| 3774 | + return -1; |
| 3775 | + } |
| 3776 | + |
| 3777 | + entry_d = &acl_d->acl[acl_d->count++]; |
| 3778 | + entry_d->a_type = 0; |
| 3779 | + entry_d->a_id = -1; |
| 3780 | + entry_d->a_perm = 0; |
| 3781 | + *entry_p = entry_d; |
| 3782 | + |
| 3783 | + return 0; |
| 3784 | +} |
| 3785 | + |
| 3786 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
| 3787 | +{ |
| 3788 | + switch (tag_type) { |
| 3789 | + case SMB_ACL_USER: |
| 3790 | + case SMB_ACL_USER_OBJ: |
| 3791 | + case SMB_ACL_GROUP: |
| 3792 | + case SMB_ACL_GROUP_OBJ: |
| 3793 | + case SMB_ACL_OTHER: |
| 3794 | + case SMB_ACL_MASK: |
| 3795 | + entry_d->a_type = tag_type; |
| 3796 | + break; |
| 3797 | + default: |
| 3798 | + errno = EINVAL; |
| 3799 | + return -1; |
| 3800 | + } |
| 3801 | + |
| 3802 | + return 0; |
| 3803 | +} |
| 3804 | + |
| 3805 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
| 3806 | +{ |
| 3807 | + if (entry_d->a_type != SMB_ACL_GROUP |
| 3808 | + && entry_d->a_type != SMB_ACL_USER) { |
| 3809 | + errno = EINVAL; |
| 3810 | + return -1; |
| 3811 | + } |
| 3812 | + |
| 3813 | + entry_d->a_id = *((id_t *)qual_p); |
| 3814 | + |
| 3815 | + return 0; |
| 3816 | +} |
| 3817 | + |
| 3818 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
| 3819 | +{ |
| 3820 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { |
| 3821 | + return EINVAL; |
| 3822 | + } |
| 3823 | + |
| 3824 | + entry_d->a_perm = *permset_d; |
| 3825 | + |
| 3826 | + return 0; |
| 3827 | +} |
| 3828 | + |
| 3829 | +/* Structure to capture the count for each type of ACE. */ |
| 3830 | + |
| 3831 | +struct hpux_acl_types { |
| 3832 | + int n_user; |
| 3833 | + int n_def_user; |
| 3834 | + int n_user_obj; |
| 3835 | + int n_def_user_obj; |
| 3836 | + |
| 3837 | + int n_group; |
| 3838 | + int n_def_group; |
| 3839 | + int n_group_obj; |
| 3840 | + int n_def_group_obj; |
| 3841 | + |
| 3842 | + int n_other; |
| 3843 | + int n_other_obj; |
| 3844 | + int n_def_other_obj; |
| 3845 | + |
| 3846 | + int n_class_obj; |
| 3847 | + int n_def_class_obj; |
| 3848 | + |
| 3849 | + int n_illegal_obj; |
| 3850 | +}; |
| 3851 | + |
| 3852 | +/* count_obj: |
| 3853 | + * Counts the different number of objects in a given array of ACL |
| 3854 | + * structures. |
| 3855 | + * Inputs: |
| 3856 | + * |
| 3857 | + * acl_count - Count of ACLs in the array of ACL strucutres. |
| 3858 | + * aclp - Array of ACL structures. |
| 3859 | + * acl_type_count - Pointer to acl_types structure. Should already be |
| 3860 | + * allocated. |
| 3861 | + * Output: |
| 3862 | + * |
| 3863 | + * acl_type_count - This structure is filled up with counts of various |
| 3864 | + * acl types. |
| 3865 | + */ |
| 3866 | + |
| 3867 | +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count) |
| 3868 | +{ |
| 3869 | + int i; |
| 3870 | + |
| 3871 | + memset(acl_type_count, 0, sizeof(struct hpux_acl_types)); |
| 3872 | + |
| 3873 | + for(i=0;i<acl_count;i++) { |
| 3874 | + switch(aclp[i].a_type) { |
| 3875 | + case USER: |
| 3876 | + acl_type_count->n_user++; |
| 3877 | + break; |
| 3878 | + case USER_OBJ: |
| 3879 | + acl_type_count->n_user_obj++; |
| 3880 | + break; |
| 3881 | + case DEF_USER_OBJ: |
| 3882 | + acl_type_count->n_def_user_obj++; |
| 3883 | + break; |
| 3884 | + case GROUP: |
| 3885 | + acl_type_count->n_group++; |
| 3886 | + break; |
| 3887 | + case GROUP_OBJ: |
| 3888 | + acl_type_count->n_group_obj++; |
| 3889 | + break; |
| 3890 | + case DEF_GROUP_OBJ: |
| 3891 | + acl_type_count->n_def_group_obj++; |
| 3892 | + break; |
| 3893 | + case OTHER_OBJ: |
| 3894 | + acl_type_count->n_other_obj++; |
| 3895 | + break; |
| 3896 | + case DEF_OTHER_OBJ: |
| 3897 | + acl_type_count->n_def_other_obj++; |
| 3898 | + break; |
| 3899 | + case CLASS_OBJ: |
| 3900 | + acl_type_count->n_class_obj++; |
| 3901 | + break; |
| 3902 | + case DEF_CLASS_OBJ: |
| 3903 | + acl_type_count->n_def_class_obj++; |
| 3904 | + break; |
| 3905 | + case DEF_USER: |
| 3906 | + acl_type_count->n_def_user++; |
| 3907 | + break; |
| 3908 | + case DEF_GROUP: |
| 3909 | + acl_type_count->n_def_group++; |
| 3910 | + break; |
| 3911 | + default: |
| 3912 | + acl_type_count->n_illegal_obj++; |
| 3913 | + break; |
| 3914 | + } |
| 3915 | + } |
| 3916 | +} |
| 3917 | + |
| 3918 | +/* swap_acl_entries: Swaps two ACL entries. |
| 3919 | + * |
| 3920 | + * Inputs: aclp0, aclp1 - ACL entries to be swapped. |
| 3921 | + */ |
| 3922 | + |
| 3923 | +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1) |
| 3924 | +{ |
| 3925 | + struct acl temp_acl; |
| 3926 | + |
| 3927 | + temp_acl.a_type = aclp0->a_type; |
| 3928 | + temp_acl.a_id = aclp0->a_id; |
| 3929 | + temp_acl.a_perm = aclp0->a_perm; |
| 3930 | + |
| 3931 | + aclp0->a_type = aclp1->a_type; |
| 3932 | + aclp0->a_id = aclp1->a_id; |
| 3933 | + aclp0->a_perm = aclp1->a_perm; |
| 3934 | + |
| 3935 | + aclp1->a_type = temp_acl.a_type; |
| 3936 | + aclp1->a_id = temp_acl.a_id; |
| 3937 | + aclp1->a_perm = temp_acl.a_perm; |
| 3938 | +} |
| 3939 | + |
| 3940 | +/* prohibited_duplicate_type |
| 3941 | + * Identifies if given ACL type can have duplicate entries or |
| 3942 | + * not. |
| 3943 | + * |
| 3944 | + * Inputs: acl_type - ACL Type. |
| 3945 | + * |
| 3946 | + * Outputs: |
| 3947 | + * |
| 3948 | + * Return.. |
| 3949 | + * |
| 3950 | + * True - If the ACL type matches any of the prohibited types. |
| 3951 | + * False - If the ACL type doesn't match any of the prohibited types. |
| 3952 | + */ |
| 3953 | + |
| 3954 | +static BOOL hpux_prohibited_duplicate_type(int acl_type) |
| 3955 | +{ |
| 3956 | + switch(acl_type) { |
| 3957 | + case USER: |
| 3958 | + case GROUP: |
| 3959 | + case DEF_USER: |
| 3960 | + case DEF_GROUP: |
| 3961 | + return True; |
| 3962 | + default: |
| 3963 | + return False; |
| 3964 | + } |
| 3965 | +} |
| 3966 | + |
| 3967 | +/* get_needed_class_perm |
| 3968 | + * Returns the permissions of a ACL structure only if the ACL |
| 3969 | + * type matches one of the pre-determined types for computing |
| 3970 | + * CLASS_OBJ permissions. |
| 3971 | + * |
| 3972 | + * Inputs: aclp - Pointer to ACL structure. |
| 3973 | + */ |
| 3974 | + |
| 3975 | +static int hpux_get_needed_class_perm(struct acl *aclp) |
| 3976 | +{ |
| 3977 | + switch(aclp->a_type) { |
| 3978 | + case USER: |
| 3979 | + case GROUP_OBJ: |
| 3980 | + case GROUP: |
| 3981 | + case DEF_USER_OBJ: |
| 3982 | + case DEF_USER: |
| 3983 | + case DEF_GROUP_OBJ: |
| 3984 | + case DEF_GROUP: |
| 3985 | + case DEF_CLASS_OBJ: |
| 3986 | + case DEF_OTHER_OBJ: |
| 3987 | + return aclp->a_perm; |
| 3988 | + default: |
| 3989 | + return 0; |
| 3990 | + } |
| 3991 | +} |
| 3992 | + |
| 3993 | +/* acl_sort for HPUX. |
| 3994 | + * Sorts the array of ACL structures as per the description in |
| 3995 | + * aclsort man page. Refer to aclsort man page for more details |
| 3996 | + * |
| 3997 | + * Inputs: |
| 3998 | + * |
| 3999 | + * acl_count - Count of ACLs in the array of ACL structures. |
| 4000 | + * calclass - If this is not zero, then we compute the CLASS_OBJ |
| 4001 | + * permissions. |
| 4002 | + * aclp - Array of ACL structures. |
| 4003 | + * |
| 4004 | + * Outputs: |
| 4005 | + * |
| 4006 | + * aclp - Sorted array of ACL structures. |
| 4007 | + * |
| 4008 | + * Outputs: |
| 4009 | + * |
| 4010 | + * Returns 0 for success -1 for failure. Prints a message to the Samba |
| 4011 | + * debug log in case of failure. |
| 4012 | + */ |
| 4013 | + |
| 4014 | +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp) |
| 4015 | +{ |
| 4016 | +#if !defined(HAVE_HPUX_ACLSORT) |
| 4017 | + /* |
| 4018 | + * The aclsort() system call is availabe on the latest HPUX General |
| 4019 | + * Patch Bundles. So for HPUX, we developed our version of acl_sort |
| 4020 | + * function. Because, we don't want to update to a new |
| 4021 | + * HPUX GR bundle just for aclsort() call. |
| 4022 | + */ |
| 4023 | + |
| 4024 | + struct hpux_acl_types acl_obj_count; |
| 4025 | + int n_class_obj_perm = 0; |
| 4026 | + int i, j; |
| 4027 | + |
| 4028 | + if(!acl_count) { |
| 4029 | + DEBUG(10,("Zero acl count passed. Returning Success\n")); |
| 4030 | + return 0; |
| 4031 | + } |
| 4032 | + |
| 4033 | + if(aclp == NULL) { |
| 4034 | + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n")); |
| 4035 | + return -1; |
| 4036 | + } |
| 4037 | + |
| 4038 | + /* Count different types of ACLs in the ACLs array */ |
| 4039 | + |
| 4040 | + hpux_count_obj(acl_count, aclp, &acl_obj_count); |
| 4041 | + |
| 4042 | + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ, |
| 4043 | + * CLASS_OBJ and OTHER_OBJ |
| 4044 | + */ |
| 4045 | + |
| 4046 | + if( (acl_obj_count.n_user_obj != 1) || |
| 4047 | + (acl_obj_count.n_group_obj != 1) || |
| 4048 | + (acl_obj_count.n_class_obj != 1) || |
| 4049 | + (acl_obj_count.n_other_obj != 1) |
| 4050 | + ) { |
| 4051 | + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \ |
| 4052 | +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n")); |
| 4053 | + return -1; |
| 4054 | + } |
| 4055 | + |
| 4056 | + /* If any of the default objects are present, there should be only |
| 4057 | + * one of them each. |
| 4058 | + */ |
| 4059 | + |
| 4060 | + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) || |
| 4061 | + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) { |
| 4062 | + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \ |
| 4063 | +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n")); |
| 4064 | + return -1; |
| 4065 | + } |
| 4066 | + |
| 4067 | + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl |
| 4068 | + * structures. |
| 4069 | + * |
| 4070 | + * Sorting crieteria - First sort by ACL type. If there are multiple entries of |
| 4071 | + * same ACL type, sort by ACL id. |
| 4072 | + * |
| 4073 | + * I am using the trival kind of sorting method here because, performance isn't |
| 4074 | + * really effected by the ACLs feature. More over there aren't going to be more |
| 4075 | + * than 17 entries on HPUX. |
| 4076 | + */ |
| 4077 | + |
| 4078 | + for(i=0; i<acl_count;i++) { |
| 4079 | + for (j=i+1; j<acl_count; j++) { |
| 4080 | + if( aclp[i].a_type > aclp[j].a_type ) { |
| 4081 | + /* ACL entries out of order, swap them */ |
| 4082 | + |
| 4083 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); |
| 4084 | + |
| 4085 | + } else if ( aclp[i].a_type == aclp[j].a_type ) { |
| 4086 | + |
| 4087 | + /* ACL entries of same type, sort by id */ |
| 4088 | + |
| 4089 | + if(aclp[i].a_id > aclp[j].a_id) { |
| 4090 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); |
| 4091 | + } else if (aclp[i].a_id == aclp[j].a_id) { |
| 4092 | + /* We have a duplicate entry. */ |
| 4093 | + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) { |
| 4094 | + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n", |
| 4095 | + aclp[i].a_type, aclp[i].a_id)); |
| 4096 | + return -1; |
| 4097 | + } |
| 4098 | + } |
| 4099 | + |
| 4100 | + } |
| 4101 | + } |
| 4102 | + } |
| 4103 | + |
| 4104 | + /* set the class obj permissions to the computed one. */ |
| 4105 | + if(calclass) { |
| 4106 | + int n_class_obj_index = -1; |
| 4107 | + |
| 4108 | + for(i=0;i<acl_count;i++) { |
| 4109 | + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i)); |
| 4110 | + |
| 4111 | + if(aclp[i].a_type == CLASS_OBJ) |
| 4112 | + n_class_obj_index = i; |
| 4113 | + } |
| 4114 | + aclp[n_class_obj_index].a_perm = n_class_obj_perm; |
| 4115 | + } |
| 4116 | + |
| 4117 | + return 0; |
| 4118 | +#else |
| 4119 | + return aclsort(acl_count, calclass, aclp); |
| 4120 | +#endif |
| 4121 | +} |
| 4122 | + |
| 4123 | +/* |
| 4124 | + * sort the ACL and check it for validity |
| 4125 | + * |
| 4126 | + * if it's a minimal ACL with only 4 entries then we |
| 4127 | + * need to recalculate the mask permissions to make |
| 4128 | + * sure that they are the same as the GROUP_OBJ |
| 4129 | + * permissions as required by the UnixWare acl() system call. |
| 4130 | + * |
| 4131 | + * (note: since POSIX allows minimal ACLs which only contain |
| 4132 | + * 3 entries - ie there is no mask entry - we should, in theory, |
| 4133 | + * check for this and add a mask entry if necessary - however |
| 4134 | + * we "know" that the caller of this interface always specifies |
| 4135 | + * a mask so, in practice "this never happens" (tm) - if it *does* |
| 4136 | + * happen aclsort() will fail and return an error and someone will |
| 4137 | + * have to fix it ...) |
| 4138 | + */ |
| 4139 | + |
| 4140 | +static int acl_sort(SMB_ACL_T acl_d) |
| 4141 | +{ |
| 4142 | + int fixmask = (acl_d->count <= 4); |
| 4143 | + |
| 4144 | + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) { |
| 4145 | + errno = EINVAL; |
| 4146 | + return -1; |
| 4147 | + } |
| 4148 | + return 0; |
| 4149 | +} |
| 4150 | + |
| 4151 | +int sys_acl_valid(SMB_ACL_T acl_d) |
| 4152 | +{ |
| 4153 | + return acl_sort(acl_d); |
| 4154 | +} |
| 4155 | + |
| 4156 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
| 4157 | +{ |
| 4158 | + struct stat s; |
| 4159 | + struct acl *acl_p; |
| 4160 | + int acl_count; |
| 4161 | + struct acl *acl_buf = NULL; |
| 4162 | + int ret; |
| 4163 | + |
| 4164 | + if(hpux_acl_call_presence() == False) { |
| 4165 | + /* Looks like we don't have the acl() system call on HPUX. |
| 4166 | + * May be the system doesn't have the latest version of JFS. |
| 4167 | + */ |
| 4168 | + errno=ENOSYS; |
| 4169 | + return -1; |
| 4170 | + } |
| 4171 | + |
| 4172 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { |
| 4173 | + errno = EINVAL; |
| 4174 | + return -1; |
| 4175 | + } |
| 4176 | + |
| 4177 | + if (acl_sort(acl_d) != 0) { |
| 4178 | + return -1; |
| 4179 | + } |
| 4180 | + |
| 4181 | + acl_p = &acl_d->acl[0]; |
| 4182 | + acl_count = acl_d->count; |
| 4183 | + |
| 4184 | + /* |
| 4185 | + * if it's a directory there is extra work to do |
| 4186 | + * since the acl() system call will replace both |
| 4187 | + * the access ACLs and the default ACLs (if any) |
| 4188 | + */ |
| 4189 | + if (stat(name, &s) != 0) { |
| 4190 | + return -1; |
| 4191 | + } |
| 4192 | + if (S_ISDIR(s.st_mode)) { |
| 4193 | + SMB_ACL_T acc_acl; |
| 4194 | + SMB_ACL_T def_acl; |
| 4195 | + SMB_ACL_T tmp_acl; |
| 4196 | + int i; |
| 4197 | + |
| 4198 | + if (type == SMB_ACL_TYPE_ACCESS) { |
| 4199 | + acc_acl = acl_d; |
| 4200 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); |
| 4201 | + |
| 4202 | + } else { |
| 4203 | + def_acl = acl_d; |
| 4204 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); |
| 4205 | + } |
| 4206 | + |
| 4207 | + if (tmp_acl == NULL) { |
| 4208 | + return -1; |
| 4209 | + } |
| 4210 | + |
| 4211 | + /* |
| 4212 | + * allocate a temporary buffer for the complete ACL |
| 4213 | + */ |
| 4214 | + acl_count = acc_acl->count + def_acl->count; |
| 4215 | + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
| 4216 | + |
| 4217 | + if (acl_buf == NULL) { |
| 4218 | + sys_acl_free_acl(tmp_acl); |
| 4219 | + errno = ENOMEM; |
| 4220 | + return -1; |
| 4221 | + } |
| 4222 | + |
| 4223 | + /* |
| 4224 | + * copy the access control and default entries into the buffer |
| 4225 | + */ |
| 4226 | + memcpy(&acl_buf[0], &acc_acl->acl[0], |
| 4227 | + acc_acl->count * sizeof(acl_buf[0])); |
| 4228 | + |
| 4229 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], |
| 4230 | + def_acl->count * sizeof(acl_buf[0])); |
| 4231 | + |
| 4232 | + /* |
| 4233 | + * set the ACL_DEFAULT flag on the default entries |
| 4234 | + */ |
| 4235 | + for (i = acc_acl->count; i < acl_count; i++) { |
| 4236 | + acl_buf[i].a_type |= ACL_DEFAULT; |
| 4237 | + } |
| 4238 | + |
| 4239 | + sys_acl_free_acl(tmp_acl); |
| 4240 | + |
| 4241 | + } else if (type != SMB_ACL_TYPE_ACCESS) { |
| 4242 | + errno = EINVAL; |
| 4243 | + return -1; |
| 4244 | + } |
| 4245 | + |
| 4246 | + ret = acl(name, ACL_SET, acl_count, acl_p); |
| 4247 | + |
| 4248 | + if (acl_buf) { |
| 4249 | + free(acl_buf); |
| 4250 | + } |
| 4251 | + |
| 4252 | + return ret; |
| 4253 | +} |
| 4254 | + |
| 4255 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
| 4256 | +{ |
| 4257 | + /* |
| 4258 | + * HPUX doesn't have the facl call. Fake it using the path.... JRA. |
| 4259 | + */ |
| 4260 | + |
| 4261 | + files_struct *fsp = file_find_fd(fd); |
| 4262 | + |
| 4263 | + if (fsp == NULL) { |
| 4264 | + errno = EBADF; |
| 4265 | + return NULL; |
| 4266 | + } |
| 4267 | + |
| 4268 | + if (acl_sort(acl_d) != 0) { |
| 4269 | + return -1; |
| 4270 | + } |
| 4271 | + |
| 4272 | + /* |
| 4273 | + * We know we're in the same conn context. So we |
| 4274 | + * can use the relative path. |
| 4275 | + */ |
| 4276 | + |
| 4277 | + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d); |
| 4278 | +} |
| 4279 | + |
| 4280 | +int sys_acl_delete_def_file(const char *path) |
| 4281 | +{ |
| 4282 | + SMB_ACL_T acl_d; |
| 4283 | + int ret; |
| 4284 | + |
| 4285 | + /* |
| 4286 | + * fetching the access ACL and rewriting it has |
| 4287 | + * the effect of deleting the default ACL |
| 4288 | + */ |
| 4289 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
| 4290 | + return -1; |
| 4291 | + } |
| 4292 | + |
| 4293 | + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl); |
| 4294 | + |
| 4295 | + sys_acl_free_acl(acl_d); |
| 4296 | + |
| 4297 | + return ret; |
| 4298 | +} |
| 4299 | + |
| 4300 | +int sys_acl_free_text(char *text) |
| 4301 | +{ |
| 4302 | + free(text); |
| 4303 | + return 0; |
| 4304 | +} |
| 4305 | + |
| 4306 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
| 4307 | +{ |
| 4308 | + free(acl_d); |
| 4309 | + return 0; |
| 4310 | +} |
| 4311 | + |
| 4312 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
| 4313 | +{ |
| 4314 | + return 0; |
| 4315 | +} |
| 4316 | + |
| 4317 | +#elif defined(HAVE_IRIX_ACLS) |
| 4318 | + |
| 4319 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 4320 | +{ |
| 4321 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { |
| 4322 | + errno = EINVAL; |
| 4323 | + return -1; |
| 4324 | + } |
| 4325 | + |
| 4326 | + if (entry_p == NULL) { |
| 4327 | + errno = EINVAL; |
| 4328 | + return -1; |
| 4329 | + } |
| 4330 | + |
| 4331 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { |
| 4332 | + acl_d->next = 0; |
| 4333 | + } |
| 4334 | + |
| 4335 | + if (acl_d->next < 0) { |
| 4336 | + errno = EINVAL; |
| 4337 | + return -1; |
| 4338 | + } |
| 4339 | + |
| 4340 | + if (acl_d->next >= acl_d->aclp->acl_cnt) { |
| 4341 | + return 0; |
| 4342 | + } |
| 4343 | + |
| 4344 | + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++]; |
| 4345 | + |
| 4346 | + return 1; |
| 4347 | +} |
| 4348 | + |
| 4349 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
| 4350 | +{ |
| 4351 | + *type_p = entry_d->ae_tag; |
| 4352 | + |
| 4353 | + return 0; |
| 4354 | +} |
| 4355 | + |
| 4356 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
| 4357 | +{ |
| 4358 | + *permset_p = entry_d; |
| 4359 | + |
| 4360 | + return 0; |
| 4361 | +} |
| 4362 | + |
| 4363 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
| 4364 | +{ |
| 4365 | + if (entry_d->ae_tag != SMB_ACL_USER |
| 4366 | + && entry_d->ae_tag != SMB_ACL_GROUP) { |
| 4367 | + errno = EINVAL; |
| 4368 | + return NULL; |
| 4369 | + } |
| 4370 | + |
| 4371 | + return &entry_d->ae_id; |
| 4372 | +} |
| 4373 | + |
| 4374 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
| 4375 | +{ |
| 4376 | + SMB_ACL_T a; |
| 4377 | + |
| 4378 | + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
| 4379 | + errno = ENOMEM; |
| 4380 | + return NULL; |
| 4381 | + } |
| 4382 | + if ((a->aclp = acl_get_file(path_p, type)) == NULL) { |
| 4383 | + SAFE_FREE(a); |
| 4384 | + return NULL; |
| 4385 | + } |
| 4386 | + a->next = -1; |
| 4387 | + a->freeaclp = True; |
| 4388 | + return a; |
| 4389 | +} |
| 4390 | + |
| 4391 | +SMB_ACL_T sys_acl_get_fd(int fd) |
| 4392 | +{ |
| 4393 | + SMB_ACL_T a; |
| 4394 | + |
| 4395 | + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
| 4396 | + errno = ENOMEM; |
| 4397 | + return NULL; |
| 4398 | + } |
| 4399 | + if ((a->aclp = acl_get_fd(fd)) == NULL) { |
| 4400 | + SAFE_FREE(a); |
| 4401 | + return NULL; |
| 4402 | + } |
| 4403 | + a->next = -1; |
| 4404 | + a->freeaclp = True; |
| 4405 | + return a; |
| 4406 | +} |
| 4407 | + |
| 4408 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
| 4409 | +{ |
| 4410 | + permset_d->ae_perm = 0; |
| 4411 | + |
| 4412 | + return 0; |
| 4413 | +} |
| 4414 | + |
| 4415 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
| 4416 | +{ |
| 4417 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE |
| 4418 | + && perm != SMB_ACL_EXECUTE) { |
| 4419 | + errno = EINVAL; |
| 4420 | + return -1; |
| 4421 | + } |
| 4422 | + |
| 4423 | + if (permset_d == NULL) { |
| 4424 | + errno = EINVAL; |
| 4425 | + return -1; |
| 4426 | + } |
| 4427 | + |
| 4428 | + permset_d->ae_perm |= perm; |
| 4429 | + |
| 4430 | + return 0; |
| 4431 | +} |
| 4432 | + |
| 4433 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
| 4434 | +{ |
| 4435 | + return permset_d->ae_perm & perm; |
| 4436 | +} |
| 4437 | + |
| 4438 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
| 4439 | +{ |
| 4440 | + return acl_to_text(acl_d->aclp, len_p); |
| 4441 | +} |
| 4442 | + |
| 4443 | +SMB_ACL_T sys_acl_init(int count) |
| 4444 | +{ |
| 4445 | + SMB_ACL_T a; |
| 4446 | + |
| 4447 | + if (count < 0) { |
| 4448 | + errno = EINVAL; |
| 4449 | + return NULL; |
| 4450 | + } |
| 4451 | + |
| 4452 | + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) { |
| 4453 | + errno = ENOMEM; |
| 4454 | + return NULL; |
| 4455 | + } |
| 4456 | + |
| 4457 | + a->next = -1; |
| 4458 | + a->freeaclp = False; |
| 4459 | + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *)); |
| 4460 | + a->aclp->acl_cnt = 0; |
| 4461 | + |
| 4462 | + return a; |
| 4463 | +} |
| 4464 | + |
| 4465 | + |
| 4466 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
| 4467 | +{ |
| 4468 | + SMB_ACL_T acl_d; |
| 4469 | + SMB_ACL_ENTRY_T entry_d; |
| 4470 | + |
| 4471 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { |
| 4472 | + errno = EINVAL; |
| 4473 | + return -1; |
| 4474 | + } |
| 4475 | + |
| 4476 | + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) { |
| 4477 | + errno = ENOSPC; |
| 4478 | + return -1; |
| 4479 | + } |
| 4480 | + |
| 4481 | + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++]; |
| 4482 | + entry_d->ae_tag = 0; |
| 4483 | + entry_d->ae_id = 0; |
| 4484 | + entry_d->ae_perm = 0; |
| 4485 | + *entry_p = entry_d; |
| 4486 | + |
| 4487 | + return 0; |
| 4488 | +} |
| 4489 | + |
| 4490 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
| 4491 | +{ |
| 4492 | + switch (tag_type) { |
| 4493 | + case SMB_ACL_USER: |
| 4494 | + case SMB_ACL_USER_OBJ: |
| 4495 | + case SMB_ACL_GROUP: |
| 4496 | + case SMB_ACL_GROUP_OBJ: |
| 4497 | + case SMB_ACL_OTHER: |
| 4498 | + case SMB_ACL_MASK: |
| 4499 | + entry_d->ae_tag = tag_type; |
| 4500 | + break; |
| 4501 | + default: |
| 4502 | + errno = EINVAL; |
| 4503 | + return -1; |
| 4504 | + } |
| 4505 | + |
| 4506 | + return 0; |
| 4507 | +} |
| 4508 | + |
| 4509 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
| 4510 | +{ |
| 4511 | + if (entry_d->ae_tag != SMB_ACL_GROUP |
| 4512 | + && entry_d->ae_tag != SMB_ACL_USER) { |
| 4513 | + errno = EINVAL; |
| 4514 | + return -1; |
| 4515 | + } |
| 4516 | + |
| 4517 | + entry_d->ae_id = *((id_t *)qual_p); |
| 4518 | + |
| 4519 | + return 0; |
| 4520 | +} |
| 4521 | + |
| 4522 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
| 4523 | +{ |
| 4524 | + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { |
| 4525 | + return EINVAL; |
| 4526 | + } |
| 4527 | + |
| 4528 | + entry_d->ae_perm = permset_d->ae_perm; |
| 4529 | + |
| 4530 | + return 0; |
| 4531 | +} |
| 4532 | + |
| 4533 | +int sys_acl_valid(SMB_ACL_T acl_d) |
| 4534 | +{ |
| 4535 | + return acl_valid(acl_d->aclp); |
| 4536 | +} |
| 4537 | + |
| 4538 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
| 4539 | +{ |
| 4540 | + return acl_set_file(name, type, acl_d->aclp); |
| 4541 | +} |
| 4542 | + |
| 4543 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
| 4544 | +{ |
| 4545 | + return acl_set_fd(fd, acl_d->aclp); |
| 4546 | +} |
| 4547 | + |
| 4548 | +int sys_acl_delete_def_file(const char *name) |
| 4549 | +{ |
| 4550 | + return acl_delete_def_file(name); |
| 4551 | +} |
| 4552 | + |
| 4553 | +int sys_acl_free_text(char *text) |
| 4554 | +{ |
| 4555 | + return acl_free(text); |
| 4556 | +} |
| 4557 | + |
| 4558 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
| 4559 | +{ |
| 4560 | + if (acl_d->freeaclp) { |
| 4561 | + acl_free(acl_d->aclp); |
| 4562 | + } |
| 4563 | + acl_free(acl_d); |
| 4564 | + return 0; |
| 4565 | +} |
| 4566 | + |
| 4567 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
| 4568 | +{ |
| 4569 | + return 0; |
| 4570 | +} |
| 4571 | + |
| 4572 | +#elif defined(HAVE_AIX_ACLS) |
| 4573 | + |
| 4574 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ |
| 4575 | + |
| 4576 | +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
| 4577 | +{ |
| 4578 | + struct acl_entry_link *link; |
| 4579 | + struct new_acl_entry *entry; |
| 4580 | + int keep_going; |
| 4581 | + |
| 4582 | + DEBUG(10,("This is the count: %d\n",theacl->count)); |
| 4583 | + |
| 4584 | + /* Check if count was previously set to -1. * |
| 4585 | + * If it was, that means we reached the end * |
| 4586 | + * of the acl last time. */ |
| 4587 | + if(theacl->count == -1) |
| 4588 | + return(0); |
| 4589 | + |
| 4590 | + link = theacl; |
| 4591 | + /* To get to the next acl, traverse linked list until index * |
| 4592 | + * of acl matches the count we are keeping. This count is * |
| 4593 | + * incremented each time we return an acl entry. */ |
| 4594 | + |
| 4595 | + for(keep_going = 0; keep_going < theacl->count; keep_going++) |
| 4596 | + link = link->nextp; |
| 4597 | + |
| 4598 | + entry = *entry_p = link->entryp; |
| 4599 | + |
| 4600 | + DEBUG(10,("*entry_p is %d\n",entry_p)); |
| 4601 | + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access)); |
| 4602 | + |
| 4603 | + /* Increment count */ |
| 4604 | + theacl->count++; |
| 4605 | + if(link->nextp == NULL) |
| 4606 | + theacl->count = -1; |
| 4607 | + |
| 4608 | + return(1); |
| 4609 | +} |
| 4610 | + |
| 4611 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
| 4612 | +{ |
| 4613 | + /* Initialize tag type */ |
| 4614 | + |
| 4615 | + *tag_type_p = -1; |
| 4616 | + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type)); |
| 4617 | + |
| 4618 | + /* Depending on what type of entry we have, * |
| 4619 | + * return tag type. */ |
| 4620 | + switch(entry_d->ace_id->id_type) { |
| 4621 | + case ACEID_USER: |
| 4622 | + *tag_type_p = SMB_ACL_USER; |
| 4623 | + break; |
| 4624 | + case ACEID_GROUP: |
| 4625 | + *tag_type_p = SMB_ACL_GROUP; |
| 4626 | + break; |
| 4627 | + |
| 4628 | + case SMB_ACL_USER_OBJ: |
| 4629 | + case SMB_ACL_GROUP_OBJ: |
| 4630 | + case SMB_ACL_OTHER: |
| 4631 | + *tag_type_p = entry_d->ace_id->id_type; |
| 4632 | + break; |
| 4633 | + |
| 4634 | + default: |
| 4635 | + return(-1); |
| 4636 | + } |
| 4637 | + |
| 4638 | + return(0); |
| 4639 | +} |
| 4640 | + |
| 4641 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
| 4642 | +{ |
| 4643 | + DEBUG(10,("Starting AIX sys_acl_get_permset\n")); |
| 4644 | + *permset_p = &entry_d->ace_access; |
| 4645 | + DEBUG(10,("**permset_p is %d\n",**permset_p)); |
| 4646 | + if(!(**permset_p & S_IXUSR) && |
| 4647 | + !(**permset_p & S_IWUSR) && |
| 4648 | + !(**permset_p & S_IRUSR) && |
| 4649 | + (**permset_p != 0)) |
| 4650 | + return(-1); |
| 4651 | + |
| 4652 | + DEBUG(10,("Ending AIX sys_acl_get_permset\n")); |
| 4653 | + return(0); |
| 4654 | +} |
| 4655 | + |
| 4656 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
| 4657 | +{ |
| 4658 | + return(entry_d->ace_id->id_data); |
| 4659 | +} |
| 4660 | + |
| 4661 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
| 4662 | +{ |
| 4663 | + struct acl *file_acl = (struct acl *)NULL; |
| 4664 | + struct acl_entry *acl_entry; |
| 4665 | + struct new_acl_entry *new_acl_entry; |
| 4666 | + struct ace_id *idp; |
| 4667 | + struct acl_entry_link *acl_entry_link; |
| 4668 | + struct acl_entry_link *acl_entry_link_head; |
| 4669 | + int i; |
| 4670 | + int rc = 0; |
| 4671 | + uid_t user_id; |
| 4672 | + |
| 4673 | + /* AIX has no DEFAULT */ |
| 4674 | + if ( type == SMB_ACL_TYPE_DEFAULT ) { |
| 4675 | + errno = ENOTSUP; |
| 4676 | + return NULL; |
| 4677 | + } |
| 4678 | + |
| 4679 | + /* Get the acl using statacl */ |
| 4680 | + |
| 4681 | + DEBUG(10,("Entering sys_acl_get_file\n")); |
| 4682 | + DEBUG(10,("path_p is %s\n",path_p)); |
| 4683 | + |
| 4684 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
| 4685 | + |
| 4686 | + if(file_acl == NULL) { |
| 4687 | + errno=ENOMEM; |
| 4688 | + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno)); |
| 4689 | + return(NULL); |
| 4690 | + } |
| 4691 | + |
| 4692 | + memset(file_acl,0,BUFSIZ); |
| 4693 | + |
| 4694 | + rc = statacl((char *)path_p,0,file_acl,BUFSIZ); |
| 4695 | + if(rc == -1) { |
| 4696 | + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno)); |
| 4697 | + SAFE_FREE(file_acl); |
| 4698 | + return(NULL); |
| 4699 | + } |
| 4700 | + |
| 4701 | + DEBUG(10,("Got facl and returned it\n")); |
| 4702 | + |
| 4703 | + /* Point to the first acl entry in the acl */ |
| 4704 | + acl_entry = file_acl->acl_ext; |
| 4705 | + |
| 4706 | + /* Begin setting up the head of the linked list * |
| 4707 | + * that will be used for the storing the acl * |
| 4708 | + * in a way that is useful for the posix_acls.c * |
| 4709 | + * code. */ |
| 4710 | + |
| 4711 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); |
| 4712 | + if(acl_entry_link_head == NULL) |
| 4713 | + return(NULL); |
| 4714 | + |
| 4715 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 4716 | + if(acl_entry_link->entryp == NULL) { |
| 4717 | + SAFE_FREE(file_acl); |
| 4718 | + errno = ENOMEM; |
| 4719 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); |
| 4720 | + return(NULL); |
| 4721 | + } |
| 4722 | + |
| 4723 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); |
| 4724 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); |
| 4725 | + |
| 4726 | + /* Check if the extended acl bit is on. * |
| 4727 | + * If it isn't, do not show the * |
| 4728 | + * contents of the acl since AIX intends * |
| 4729 | + * the extended info to remain unused */ |
| 4730 | + |
| 4731 | + if(file_acl->acl_mode & S_IXACL){ |
| 4732 | + /* while we are not pointing to the very end */ |
| 4733 | + while(acl_entry < acl_last(file_acl)) { |
| 4734 | + /* before we malloc anything, make sure this is */ |
| 4735 | + /* a valid acl entry and one that we want to map */ |
| 4736 | + idp = id_nxt(acl_entry->ace_id); |
| 4737 | + if((acl_entry->ace_type == ACC_SPECIFY || |
| 4738 | + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { |
| 4739 | + acl_entry = acl_nxt(acl_entry); |
| 4740 | + continue; |
| 4741 | + } |
| 4742 | + |
| 4743 | + idp = acl_entry->ace_id; |
| 4744 | + |
| 4745 | + /* Check if this is the first entry in the linked list. * |
| 4746 | + * The first entry needs to keep prevp pointing to NULL * |
| 4747 | + * and already has entryp allocated. */ |
| 4748 | + |
| 4749 | + if(acl_entry_link_head->count != 0) { |
| 4750 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
| 4751 | + |
| 4752 | + if(acl_entry_link->nextp == NULL) { |
| 4753 | + SAFE_FREE(file_acl); |
| 4754 | + errno = ENOMEM; |
| 4755 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); |
| 4756 | + return(NULL); |
| 4757 | + } |
| 4758 | + |
| 4759 | + acl_entry_link->nextp->prevp = acl_entry_link; |
| 4760 | + acl_entry_link = acl_entry_link->nextp; |
| 4761 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 4762 | + if(acl_entry_link->entryp == NULL) { |
| 4763 | + SAFE_FREE(file_acl); |
| 4764 | + errno = ENOMEM; |
| 4765 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); |
| 4766 | + return(NULL); |
| 4767 | + } |
| 4768 | + acl_entry_link->nextp = NULL; |
| 4769 | + } |
| 4770 | + |
| 4771 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; |
| 4772 | + |
| 4773 | + /* Don't really need this since all types are going * |
| 4774 | + * to be specified but, it's better than leaving it 0 */ |
| 4775 | + |
| 4776 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; |
| 4777 | + |
| 4778 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
| 4779 | + |
| 4780 | + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id)); |
| 4781 | + |
| 4782 | + /* The access in the acl entries must be left shifted by * |
| 4783 | + * three bites, because they will ultimately be compared * |
| 4784 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ |
| 4785 | + |
| 4786 | + switch(acl_entry->ace_type){ |
| 4787 | + case ACC_PERMIT: |
| 4788 | + case ACC_SPECIFY: |
| 4789 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
| 4790 | + acl_entry_link->entryp->ace_access <<= 6; |
| 4791 | + acl_entry_link_head->count++; |
| 4792 | + break; |
| 4793 | + case ACC_DENY: |
| 4794 | + /* Since there is no way to return a DENY acl entry * |
| 4795 | + * change to PERMIT and then shift. */ |
| 4796 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); |
| 4797 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; |
| 4798 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); |
| 4799 | + acl_entry_link->entryp->ace_access <<= 6; |
| 4800 | + acl_entry_link_head->count++; |
| 4801 | + break; |
| 4802 | + default: |
| 4803 | + return(0); |
| 4804 | + } |
| 4805 | + |
| 4806 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); |
| 4807 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); |
| 4808 | + |
| 4809 | + acl_entry = acl_nxt(acl_entry); |
| 4810 | + } |
| 4811 | + } /* end of if enabled */ |
| 4812 | + |
| 4813 | + /* Since owner, group, other acl entries are not * |
| 4814 | + * part of the acl entries in an acl, they must * |
| 4815 | + * be dummied up to become part of the list. */ |
| 4816 | + |
| 4817 | + for( i = 1; i < 4; i++) { |
| 4818 | + DEBUG(10,("i is %d\n",i)); |
| 4819 | + if(acl_entry_link_head->count != 0) { |
| 4820 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
| 4821 | + if(acl_entry_link->nextp == NULL) { |
| 4822 | + SAFE_FREE(file_acl); |
| 4823 | + errno = ENOMEM; |
| 4824 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); |
| 4825 | + return(NULL); |
| 4826 | + } |
| 4827 | + |
| 4828 | + acl_entry_link->nextp->prevp = acl_entry_link; |
| 4829 | + acl_entry_link = acl_entry_link->nextp; |
| 4830 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 4831 | + if(acl_entry_link->entryp == NULL) { |
| 4832 | + SAFE_FREE(file_acl); |
| 4833 | + errno = ENOMEM; |
| 4834 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); |
| 4835 | + return(NULL); |
| 4836 | + } |
| 4837 | + } |
| 4838 | + |
| 4839 | + acl_entry_link->nextp = NULL; |
| 4840 | + |
| 4841 | + new_acl_entry = acl_entry_link->entryp; |
| 4842 | + idp = new_acl_entry->ace_id; |
| 4843 | + |
| 4844 | + new_acl_entry->ace_len = sizeof(struct acl_entry); |
| 4845 | + new_acl_entry->ace_type = ACC_PERMIT; |
| 4846 | + idp->id_len = sizeof(struct ace_id); |
| 4847 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); |
| 4848 | + memset(idp->id_data,0,sizeof(uid_t)); |
| 4849 | + |
| 4850 | + switch(i) { |
| 4851 | + case 2: |
| 4852 | + new_acl_entry->ace_access = file_acl->g_access << 6; |
| 4853 | + idp->id_type = SMB_ACL_GROUP_OBJ; |
| 4854 | + break; |
| 4855 | + |
| 4856 | + case 3: |
| 4857 | + new_acl_entry->ace_access = file_acl->o_access << 6; |
| 4858 | + idp->id_type = SMB_ACL_OTHER; |
| 4859 | + break; |
| 4860 | + |
| 4861 | + case 1: |
| 4862 | + new_acl_entry->ace_access = file_acl->u_access << 6; |
| 4863 | + idp->id_type = SMB_ACL_USER_OBJ; |
| 4864 | + break; |
| 4865 | + |
| 4866 | + default: |
| 4867 | + return(NULL); |
| 4868 | + |
| 4869 | + } |
| 4870 | + |
| 4871 | + acl_entry_link_head->count++; |
| 4872 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); |
| 4873 | + } |
| 4874 | + |
| 4875 | + acl_entry_link_head->count = 0; |
| 4876 | + SAFE_FREE(file_acl); |
| 4877 | + |
| 4878 | + return(acl_entry_link_head); |
| 4879 | +} |
| 4880 | + |
| 4881 | +SMB_ACL_T sys_acl_get_fd(int fd) |
| 4882 | +{ |
| 4883 | + struct acl *file_acl = (struct acl *)NULL; |
| 4884 | + struct acl_entry *acl_entry; |
| 4885 | + struct new_acl_entry *new_acl_entry; |
| 4886 | + struct ace_id *idp; |
| 4887 | + struct acl_entry_link *acl_entry_link; |
| 4888 | + struct acl_entry_link *acl_entry_link_head; |
| 4889 | + int i; |
| 4890 | + int rc = 0; |
| 4891 | + uid_t user_id; |
| 4892 | + |
| 4893 | + /* Get the acl using fstatacl */ |
| 4894 | + |
| 4895 | + DEBUG(10,("Entering sys_acl_get_fd\n")); |
| 4896 | + DEBUG(10,("fd is %d\n",fd)); |
| 4897 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
| 4898 | + |
| 4899 | + if(file_acl == NULL) { |
| 4900 | + errno=ENOMEM; |
| 4901 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); |
| 4902 | + return(NULL); |
| 4903 | + } |
| 4904 | + |
| 4905 | + memset(file_acl,0,BUFSIZ); |
| 4906 | + |
| 4907 | + rc = fstatacl(fd,0,file_acl,BUFSIZ); |
| 4908 | + if(rc == -1) { |
| 4909 | + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno)); |
| 4910 | + SAFE_FREE(file_acl); |
| 4911 | + return(NULL); |
| 4912 | + } |
| 4913 | + |
| 4914 | + DEBUG(10,("Got facl and returned it\n")); |
| 4915 | + |
| 4916 | + /* Point to the first acl entry in the acl */ |
| 4917 | + |
| 4918 | + acl_entry = file_acl->acl_ext; |
| 4919 | + /* Begin setting up the head of the linked list * |
| 4920 | + * that will be used for the storing the acl * |
| 4921 | + * in a way that is useful for the posix_acls.c * |
| 4922 | + * code. */ |
| 4923 | + |
| 4924 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); |
| 4925 | + if(acl_entry_link_head == NULL){ |
| 4926 | + SAFE_FREE(file_acl); |
| 4927 | + return(NULL); |
| 4928 | + } |
| 4929 | + |
| 4930 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 4931 | + |
| 4932 | + if(acl_entry_link->entryp == NULL) { |
| 4933 | + errno = ENOMEM; |
| 4934 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); |
| 4935 | + SAFE_FREE(file_acl); |
| 4936 | + return(NULL); |
| 4937 | + } |
| 4938 | + |
| 4939 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); |
| 4940 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); |
| 4941 | + |
| 4942 | + /* Check if the extended acl bit is on. * |
| 4943 | + * If it isn't, do not show the * |
| 4944 | + * contents of the acl since AIX intends * |
| 4945 | + * the extended info to remain unused */ |
| 4946 | + |
| 4947 | + if(file_acl->acl_mode & S_IXACL){ |
| 4948 | + /* while we are not pointing to the very end */ |
| 4949 | + while(acl_entry < acl_last(file_acl)) { |
| 4950 | + /* before we malloc anything, make sure this is */ |
| 4951 | + /* a valid acl entry and one that we want to map */ |
| 4952 | + |
| 4953 | + idp = id_nxt(acl_entry->ace_id); |
| 4954 | + if((acl_entry->ace_type == ACC_SPECIFY || |
| 4955 | + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { |
| 4956 | + acl_entry = acl_nxt(acl_entry); |
| 4957 | + continue; |
| 4958 | + } |
| 4959 | + |
| 4960 | + idp = acl_entry->ace_id; |
| 4961 | + |
| 4962 | + /* Check if this is the first entry in the linked list. * |
| 4963 | + * The first entry needs to keep prevp pointing to NULL * |
| 4964 | + * and already has entryp allocated. */ |
| 4965 | + |
| 4966 | + if(acl_entry_link_head->count != 0) { |
| 4967 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
| 4968 | + if(acl_entry_link->nextp == NULL) { |
| 4969 | + errno = ENOMEM; |
| 4970 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); |
| 4971 | + SAFE_FREE(file_acl); |
| 4972 | + return(NULL); |
| 4973 | + } |
| 4974 | + acl_entry_link->nextp->prevp = acl_entry_link; |
| 4975 | + acl_entry_link = acl_entry_link->nextp; |
| 4976 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 4977 | + if(acl_entry_link->entryp == NULL) { |
| 4978 | + errno = ENOMEM; |
| 4979 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); |
| 4980 | + SAFE_FREE(file_acl); |
| 4981 | + return(NULL); |
| 4982 | + } |
| 4983 | + |
| 4984 | + acl_entry_link->nextp = NULL; |
| 4985 | + } |
| 4986 | + |
| 4987 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; |
| 4988 | + |
| 4989 | + /* Don't really need this since all types are going * |
| 4990 | + * to be specified but, it's better than leaving it 0 */ |
| 4991 | + |
| 4992 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; |
| 4993 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
| 4994 | + |
| 4995 | + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id)); |
| 4996 | + |
| 4997 | + /* The access in the acl entries must be left shifted by * |
| 4998 | + * three bites, because they will ultimately be compared * |
| 4999 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ |
| 5000 | + |
| 5001 | + switch(acl_entry->ace_type){ |
| 5002 | + case ACC_PERMIT: |
| 5003 | + case ACC_SPECIFY: |
| 5004 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
| 5005 | + acl_entry_link->entryp->ace_access <<= 6; |
| 5006 | + acl_entry_link_head->count++; |
| 5007 | + break; |
| 5008 | + case ACC_DENY: |
| 5009 | + /* Since there is no way to return a DENY acl entry * |
| 5010 | + * change to PERMIT and then shift. */ |
| 5011 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); |
| 5012 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; |
| 5013 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); |
| 5014 | + acl_entry_link->entryp->ace_access <<= 6; |
| 5015 | + acl_entry_link_head->count++; |
| 5016 | + break; |
| 5017 | + default: |
| 5018 | + return(0); |
| 5019 | + } |
| 5020 | + |
| 5021 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); |
| 5022 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); |
| 5023 | + |
| 5024 | + acl_entry = acl_nxt(acl_entry); |
| 5025 | + } |
| 5026 | + } /* end of if enabled */ |
| 5027 | + |
| 5028 | + /* Since owner, group, other acl entries are not * |
| 5029 | + * part of the acl entries in an acl, they must * |
| 5030 | + * be dummied up to become part of the list. */ |
| 5031 | + |
| 5032 | + for( i = 1; i < 4; i++) { |
| 5033 | + DEBUG(10,("i is %d\n",i)); |
| 5034 | + if(acl_entry_link_head->count != 0){ |
| 5035 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
| 5036 | + if(acl_entry_link->nextp == NULL) { |
| 5037 | + errno = ENOMEM; |
| 5038 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); |
| 5039 | + SAFE_FREE(file_acl); |
| 5040 | + return(NULL); |
| 5041 | + } |
| 5042 | + |
| 5043 | + acl_entry_link->nextp->prevp = acl_entry_link; |
| 5044 | + acl_entry_link = acl_entry_link->nextp; |
| 5045 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 5046 | + |
| 5047 | + if(acl_entry_link->entryp == NULL) { |
| 5048 | + SAFE_FREE(file_acl); |
| 5049 | + errno = ENOMEM; |
| 5050 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); |
| 5051 | + return(NULL); |
| 5052 | + } |
| 5053 | + } |
| 5054 | + |
| 5055 | + acl_entry_link->nextp = NULL; |
| 5056 | + |
| 5057 | + new_acl_entry = acl_entry_link->entryp; |
| 5058 | + idp = new_acl_entry->ace_id; |
| 5059 | + |
| 5060 | + new_acl_entry->ace_len = sizeof(struct acl_entry); |
| 5061 | + new_acl_entry->ace_type = ACC_PERMIT; |
| 5062 | + idp->id_len = sizeof(struct ace_id); |
| 5063 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); |
| 5064 | + memset(idp->id_data,0,sizeof(uid_t)); |
| 5065 | + |
| 5066 | + switch(i) { |
| 5067 | + case 2: |
| 5068 | + new_acl_entry->ace_access = file_acl->g_access << 6; |
| 5069 | + idp->id_type = SMB_ACL_GROUP_OBJ; |
| 5070 | + break; |
| 5071 | + |
| 5072 | + case 3: |
| 5073 | + new_acl_entry->ace_access = file_acl->o_access << 6; |
| 5074 | + idp->id_type = SMB_ACL_OTHER; |
| 5075 | + break; |
| 5076 | + |
| 5077 | + case 1: |
| 5078 | + new_acl_entry->ace_access = file_acl->u_access << 6; |
| 5079 | + idp->id_type = SMB_ACL_USER_OBJ; |
| 5080 | + break; |
| 5081 | + |
| 5082 | + default: |
| 5083 | + return(NULL); |
| 5084 | + } |
| 5085 | + |
| 5086 | + acl_entry_link_head->count++; |
| 5087 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); |
| 5088 | + } |
| 5089 | + |
| 5090 | + acl_entry_link_head->count = 0; |
| 5091 | + SAFE_FREE(file_acl); |
| 5092 | + |
| 5093 | + return(acl_entry_link_head); |
| 5094 | +} |
| 5095 | + |
| 5096 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
| 5097 | +{ |
| 5098 | + *permset = *permset & ~0777; |
| 5099 | + return(0); |
| 5100 | +} |
| 5101 | + |
| 5102 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
| 5103 | +{ |
| 5104 | + if((perm != 0) && |
| 5105 | + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0) |
| 5106 | + return(-1); |
| 5107 | + |
| 5108 | + *permset |= perm; |
| 5109 | + DEBUG(10,("This is the permset now: %d\n",*permset)); |
| 5110 | + return(0); |
| 5111 | +} |
| 5112 | + |
| 5113 | +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) |
| 5114 | +{ |
| 5115 | + return(NULL); |
| 5116 | +} |
| 5117 | + |
| 5118 | +SMB_ACL_T sys_acl_init( int count) |
| 5119 | +{ |
| 5120 | + struct acl_entry_link *theacl = NULL; |
| 5121 | + |
| 5122 | + DEBUG(10,("Entering sys_acl_init\n")); |
| 5123 | + |
| 5124 | + theacl = SMB_MALLOC_P(struct acl_entry_link); |
| 5125 | + if(theacl == NULL) { |
| 5126 | + errno = ENOMEM; |
| 5127 | + DEBUG(0,("Error in sys_acl_init is %d\n",errno)); |
| 5128 | + return(NULL); |
| 5129 | + } |
| 5130 | + |
| 5131 | + theacl->count = 0; |
| 5132 | + theacl->nextp = NULL; |
| 5133 | + theacl->prevp = NULL; |
| 5134 | + theacl->entryp = NULL; |
| 5135 | + DEBUG(10,("Exiting sys_acl_init\n")); |
| 5136 | + return(theacl); |
| 5137 | +} |
| 5138 | + |
| 5139 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
| 5140 | +{ |
| 5141 | + struct acl_entry_link *theacl; |
| 5142 | + struct acl_entry_link *acl_entryp; |
| 5143 | + struct acl_entry_link *temp_entry; |
| 5144 | + int counting; |
| 5145 | + |
| 5146 | + DEBUG(10,("Entering the sys_acl_create_entry\n")); |
| 5147 | + |
| 5148 | + theacl = acl_entryp = *pacl; |
| 5149 | + |
| 5150 | + /* Get to the end of the acl before adding entry */ |
| 5151 | + |
| 5152 | + for(counting=0; counting < theacl->count; counting++){ |
| 5153 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); |
| 5154 | + temp_entry = acl_entryp; |
| 5155 | + acl_entryp = acl_entryp->nextp; |
| 5156 | + } |
| 5157 | + |
| 5158 | + if(theacl->count != 0){ |
| 5159 | + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link); |
| 5160 | + if(acl_entryp == NULL) { |
| 5161 | + errno = ENOMEM; |
| 5162 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); |
| 5163 | + return(-1); |
| 5164 | + } |
| 5165 | + |
| 5166 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); |
| 5167 | + acl_entryp->prevp = temp_entry; |
| 5168 | + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp)); |
| 5169 | + } |
| 5170 | + |
| 5171 | + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry); |
| 5172 | + if(*pentry == NULL) { |
| 5173 | + errno = ENOMEM; |
| 5174 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); |
| 5175 | + return(-1); |
| 5176 | + } |
| 5177 | + |
| 5178 | + memset(*pentry,0,sizeof(struct new_acl_entry)); |
| 5179 | + acl_entryp->entryp->ace_len = sizeof(struct acl_entry); |
| 5180 | + acl_entryp->entryp->ace_type = ACC_PERMIT; |
| 5181 | + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id); |
| 5182 | + acl_entryp->nextp = NULL; |
| 5183 | + theacl->count++; |
| 5184 | + DEBUG(10,("Exiting sys_acl_create_entry\n")); |
| 5185 | + return(0); |
| 5186 | +} |
| 5187 | + |
| 5188 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
| 5189 | +{ |
| 5190 | + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n")); |
| 5191 | + entry->ace_id->id_type = tagtype; |
| 5192 | + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type)); |
| 5193 | + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n")); |
| 5194 | +} |
| 5195 | + |
| 5196 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
| 5197 | +{ |
| 5198 | + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n")); |
| 5199 | + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t)); |
| 5200 | + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n")); |
| 5201 | + return(0); |
| 5202 | +} |
| 5203 | + |
| 5204 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
| 5205 | +{ |
| 5206 | + DEBUG(10,("Starting AIX sys_acl_set_permset\n")); |
| 5207 | + if(!(*permset & S_IXUSR) && |
| 5208 | + !(*permset & S_IWUSR) && |
| 5209 | + !(*permset & S_IRUSR) && |
| 5210 | + (*permset != 0)) |
| 5211 | + return(-1); |
| 5212 | + |
| 5213 | + entry->ace_access = *permset; |
| 5214 | + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access)); |
| 5215 | + DEBUG(10,("Ending AIX sys_acl_set_permset\n")); |
| 5216 | + return(0); |
| 5217 | +} |
| 5218 | + |
| 5219 | +int sys_acl_valid( SMB_ACL_T theacl ) |
| 5220 | +{ |
| 5221 | + int user_obj = 0; |
| 5222 | + int group_obj = 0; |
| 5223 | + int other_obj = 0; |
| 5224 | + struct acl_entry_link *acl_entry; |
| 5225 | + |
| 5226 | + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) { |
| 5227 | + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ); |
| 5228 | + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ); |
| 5229 | + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER); |
| 5230 | + } |
| 5231 | + |
| 5232 | + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj)); |
| 5233 | + |
| 5234 | + if(user_obj != 1 || group_obj != 1 || other_obj != 1) |
| 5235 | + return(-1); |
| 5236 | + |
| 5237 | + return(0); |
| 5238 | +} |
| 5239 | + |
| 5240 | +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
| 5241 | +{ |
| 5242 | + struct acl_entry_link *acl_entry_link = NULL; |
| 5243 | + struct acl *file_acl = NULL; |
| 5244 | + struct acl *file_acl_temp = NULL; |
| 5245 | + struct acl_entry *acl_entry = NULL; |
| 5246 | + struct ace_id *ace_id = NULL; |
| 5247 | + uint id_type; |
| 5248 | + uint ace_access; |
| 5249 | + uint user_id; |
| 5250 | + uint acl_length; |
| 5251 | + uint rc; |
| 5252 | + |
| 5253 | + DEBUG(10,("Entering sys_acl_set_file\n")); |
| 5254 | + DEBUG(10,("File name is %s\n",name)); |
| 5255 | + |
| 5256 | + /* AIX has no default ACL */ |
| 5257 | + if(acltype == SMB_ACL_TYPE_DEFAULT) |
| 5258 | + return(0); |
| 5259 | + |
| 5260 | + acl_length = BUFSIZ; |
| 5261 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
| 5262 | + |
| 5263 | + if(file_acl == NULL) { |
| 5264 | + errno = ENOMEM; |
| 5265 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); |
| 5266 | + return(-1); |
| 5267 | + } |
| 5268 | + |
| 5269 | + memset(file_acl,0,BUFSIZ); |
| 5270 | + |
| 5271 | + file_acl->acl_len = ACL_SIZ; |
| 5272 | + file_acl->acl_mode = S_IXACL; |
| 5273 | + |
| 5274 | + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
| 5275 | + acl_entry_link->entryp->ace_access >>= 6; |
| 5276 | + id_type = acl_entry_link->entryp->ace_id->id_type; |
| 5277 | + |
| 5278 | + switch(id_type) { |
| 5279 | + case SMB_ACL_USER_OBJ: |
| 5280 | + file_acl->u_access = acl_entry_link->entryp->ace_access; |
| 5281 | + continue; |
| 5282 | + case SMB_ACL_GROUP_OBJ: |
| 5283 | + file_acl->g_access = acl_entry_link->entryp->ace_access; |
| 5284 | + continue; |
| 5285 | + case SMB_ACL_OTHER: |
| 5286 | + file_acl->o_access = acl_entry_link->entryp->ace_access; |
| 5287 | + continue; |
| 5288 | + case SMB_ACL_MASK: |
| 5289 | + continue; |
| 5290 | + } |
| 5291 | + |
| 5292 | + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { |
| 5293 | + acl_length += sizeof(struct acl_entry); |
| 5294 | + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
| 5295 | + if(file_acl_temp == NULL) { |
| 5296 | + SAFE_FREE(file_acl); |
| 5297 | + errno = ENOMEM; |
| 5298 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); |
| 5299 | + return(-1); |
| 5300 | + } |
| 5301 | + |
| 5302 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); |
| 5303 | + SAFE_FREE(file_acl); |
| 5304 | + file_acl = file_acl_temp; |
| 5305 | + } |
| 5306 | + |
| 5307 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); |
| 5308 | + file_acl->acl_len += sizeof(struct acl_entry); |
| 5309 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
| 5310 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; |
| 5311 | + |
| 5312 | + /* In order to use this, we'll need to wait until we can get denies */ |
| 5313 | + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) |
| 5314 | + acl_entry->ace_type = ACC_SPECIFY; */ |
| 5315 | + |
| 5316 | + acl_entry->ace_type = ACC_SPECIFY; |
| 5317 | + |
| 5318 | + ace_id = acl_entry->ace_id; |
| 5319 | + |
| 5320 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
| 5321 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); |
| 5322 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; |
| 5323 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t)); |
| 5324 | + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t)); |
| 5325 | + } |
| 5326 | + |
| 5327 | + rc = chacl(name,file_acl,file_acl->acl_len); |
| 5328 | + DEBUG(10,("errno is %d\n",errno)); |
| 5329 | + DEBUG(10,("return code is %d\n",rc)); |
| 5330 | + SAFE_FREE(file_acl); |
| 5331 | + DEBUG(10,("Exiting the sys_acl_set_file\n")); |
| 5332 | + return(rc); |
| 5333 | +} |
| 5334 | + |
| 5335 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
| 5336 | +{ |
| 5337 | + struct acl_entry_link *acl_entry_link = NULL; |
| 5338 | + struct acl *file_acl = NULL; |
| 5339 | + struct acl *file_acl_temp = NULL; |
| 5340 | + struct acl_entry *acl_entry = NULL; |
| 5341 | + struct ace_id *ace_id = NULL; |
| 5342 | + uint id_type; |
| 5343 | + uint user_id; |
| 5344 | + uint acl_length; |
| 5345 | + uint rc; |
| 5346 | + |
| 5347 | + DEBUG(10,("Entering sys_acl_set_fd\n")); |
| 5348 | + acl_length = BUFSIZ; |
| 5349 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
| 5350 | + |
| 5351 | + if(file_acl == NULL) { |
| 5352 | + errno = ENOMEM; |
| 5353 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); |
| 5354 | + return(-1); |
| 5355 | + } |
| 5356 | + |
| 5357 | + memset(file_acl,0,BUFSIZ); |
| 5358 | + |
| 5359 | + file_acl->acl_len = ACL_SIZ; |
| 5360 | + file_acl->acl_mode = S_IXACL; |
| 5361 | + |
| 5362 | + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
| 5363 | + acl_entry_link->entryp->ace_access >>= 6; |
| 5364 | + id_type = acl_entry_link->entryp->ace_id->id_type; |
| 5365 | + DEBUG(10,("The id_type is %d\n",id_type)); |
| 5366 | + |
| 5367 | + switch(id_type) { |
| 5368 | + case SMB_ACL_USER_OBJ: |
| 5369 | + file_acl->u_access = acl_entry_link->entryp->ace_access; |
| 5370 | + continue; |
| 5371 | + case SMB_ACL_GROUP_OBJ: |
| 5372 | + file_acl->g_access = acl_entry_link->entryp->ace_access; |
| 5373 | + continue; |
| 5374 | + case SMB_ACL_OTHER: |
| 5375 | + file_acl->o_access = acl_entry_link->entryp->ace_access; |
| 5376 | + continue; |
| 5377 | + case SMB_ACL_MASK: |
| 5378 | + continue; |
| 5379 | + } |
| 5380 | + |
| 5381 | + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { |
| 5382 | + acl_length += sizeof(struct acl_entry); |
| 5383 | + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
| 5384 | + if(file_acl_temp == NULL) { |
| 5385 | + SAFE_FREE(file_acl); |
| 5386 | + errno = ENOMEM; |
| 5387 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); |
| 5388 | + return(-1); |
| 5389 | + } |
| 5390 | + |
| 5391 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); |
| 5392 | + SAFE_FREE(file_acl); |
| 5393 | + file_acl = file_acl_temp; |
| 5394 | + } |
| 5395 | + |
| 5396 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); |
| 5397 | + file_acl->acl_len += sizeof(struct acl_entry); |
| 5398 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
| 5399 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; |
| 5400 | + |
| 5401 | + /* In order to use this, we'll need to wait until we can get denies */ |
| 5402 | + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) |
| 5403 | + acl_entry->ace_type = ACC_SPECIFY; */ |
| 5404 | + |
| 5405 | + acl_entry->ace_type = ACC_SPECIFY; |
| 5406 | + |
| 5407 | + ace_id = acl_entry->ace_id; |
| 5408 | + |
| 5409 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
| 5410 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); |
| 5411 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; |
| 5412 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t)); |
| 5413 | + memcpy(ace_id->id_data, &user_id, sizeof(uid_t)); |
| 5414 | + } |
| 5415 | + |
| 5416 | + rc = fchacl(fd,file_acl,file_acl->acl_len); |
| 5417 | + DEBUG(10,("errno is %d\n",errno)); |
| 5418 | + DEBUG(10,("return code is %d\n",rc)); |
| 5419 | + SAFE_FREE(file_acl); |
| 5420 | + DEBUG(10,("Exiting sys_acl_set_fd\n")); |
| 5421 | + return(rc); |
| 5422 | +} |
| 5423 | + |
| 5424 | +int sys_acl_delete_def_file(const char *name) |
| 5425 | +{ |
| 5426 | + /* AIX has no default ACL */ |
| 5427 | + return 0; |
| 5428 | +} |
| 5429 | + |
| 5430 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
| 5431 | +{ |
| 5432 | + return(*permset & perm); |
| 5433 | +} |
| 5434 | + |
| 5435 | +int sys_acl_free_text(char *text) |
| 5436 | +{ |
| 5437 | + return(0); |
| 5438 | +} |
| 5439 | + |
| 5440 | +int sys_acl_free_acl(SMB_ACL_T posix_acl) |
| 5441 | +{ |
| 5442 | + struct acl_entry_link *acl_entry_link; |
| 5443 | + |
| 5444 | + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) { |
| 5445 | + SAFE_FREE(acl_entry_link->prevp->entryp); |
| 5446 | + SAFE_FREE(acl_entry_link->prevp); |
| 5447 | + } |
| 5448 | + |
| 5449 | + SAFE_FREE(acl_entry_link->prevp->entryp); |
| 5450 | + SAFE_FREE(acl_entry_link->prevp); |
| 5451 | + SAFE_FREE(acl_entry_link->entryp); |
| 5452 | + SAFE_FREE(acl_entry_link); |
| 5453 | + |
| 5454 | + return(0); |
| 5455 | +} |
| 5456 | + |
| 5457 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
| 5458 | +{ |
| 5459 | + return(0); |
| 5460 | +} |
| 5461 | + |
| 5462 | +#else /* No ACLs. */ |
| 5463 | + |
| 5464 | +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p)) |
| 5465 | +{ |
| 5466 | + errno = ENOSYS; |
| 5467 | + return -1; |
| 5468 | +} |
| 5469 | + |
| 5470 | +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p)) |
| 5471 | +{ |
| 5472 | + errno = ENOSYS; |
| 5473 | + return -1; |
| 5474 | +} |
| 5475 | + |
| 5476 | +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p)) |
| 5477 | +{ |
| 5478 | + errno = ENOSYS; |
| 5479 | + return -1; |
| 5480 | +} |
| 5481 | + |
| 5482 | +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d)) |
| 5483 | +{ |
| 5484 | + errno = ENOSYS; |
| 5485 | + return NULL; |
| 5486 | +} |
| 5487 | + |
| 5488 | +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type)) |
| 5489 | +{ |
| 5490 | + errno = ENOSYS; |
| 5491 | + return (SMB_ACL_T)NULL; |
| 5492 | +} |
| 5493 | + |
| 5494 | +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd)) |
| 5495 | +{ |
| 5496 | + errno = ENOSYS; |
| 5497 | + return (SMB_ACL_T)NULL; |
| 5498 | +} |
| 5499 | + |
| 5500 | +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset)) |
| 5501 | +{ |
| 5502 | + errno = ENOSYS; |
| 5503 | + return -1; |
| 5504 | +} |
| 5505 | + |
| 5506 | +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm)) |
| 5507 | +{ |
| 5508 | + errno = ENOSYS; |
| 5509 | + return -1; |
| 5510 | +} |
| 5511 | + |
| 5512 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
| 5513 | +{ |
| 5514 | + errno = ENOSYS; |
| 5515 | + return (permset & perm) ? 1 : 0; |
| 5516 | +} |
| 5517 | + |
| 5518 | +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen)) |
| 5519 | +{ |
| 5520 | + errno = ENOSYS; |
| 5521 | + return NULL; |
| 5522 | +} |
| 5523 | + |
| 5524 | +int sys_acl_free_text(UNUSED(char *text)) |
| 5525 | +{ |
| 5526 | + errno = ENOSYS; |
| 5527 | + return -1; |
| 5528 | +} |
| 5529 | + |
| 5530 | +SMB_ACL_T sys_acl_init(UNUSED(int count)) |
| 5531 | +{ |
| 5532 | + errno = ENOSYS; |
| 5533 | + return NULL; |
| 5534 | +} |
| 5535 | + |
| 5536 | +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry)) |
| 5537 | +{ |
| 5538 | + errno = ENOSYS; |
| 5539 | + return -1; |
| 5540 | +} |
| 5541 | + |
| 5542 | +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype)) |
| 5543 | +{ |
| 5544 | + errno = ENOSYS; |
| 5545 | + return -1; |
| 5546 | +} |
| 5547 | + |
| 5548 | +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual)) |
| 5549 | +{ |
| 5550 | + errno = ENOSYS; |
| 5551 | + return -1; |
| 5552 | +} |
| 5553 | + |
| 5554 | +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset)) |
| 5555 | +{ |
| 5556 | + errno = ENOSYS; |
| 5557 | + return -1; |
| 5558 | +} |
| 5559 | + |
| 5560 | +int sys_acl_valid(UNUSED(SMB_ACL_T theacl)) |
| 5561 | +{ |
| 5562 | + errno = ENOSYS; |
| 5563 | + return -1; |
| 5564 | +} |
| 5565 | + |
| 5566 | +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl)) |
| 5567 | +{ |
| 5568 | + errno = ENOSYS; |
| 5569 | + return -1; |
| 5570 | +} |
| 5571 | + |
| 5572 | +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl)) |
| 5573 | +{ |
| 5574 | + errno = ENOSYS; |
| 5575 | + return -1; |
| 5576 | +} |
| 5577 | + |
| 5578 | +int sys_acl_delete_def_file(UNUSED(const char *name)) |
| 5579 | +{ |
| 5580 | + errno = ENOSYS; |
| 5581 | + return -1; |
| 5582 | +} |
| 5583 | + |
| 5584 | +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl)) |
| 5585 | +{ |
| 5586 | + errno = ENOSYS; |
| 5587 | + return -1; |
| 5588 | +} |
| 5589 | + |
| 5590 | +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) |
| 5591 | +{ |
| 5592 | + errno = ENOSYS; |
| 5593 | + return -1; |
| 5594 | +} |
| 5595 | + |
| 5596 | +#endif /* No ACLs. */ |
| 5597 | + |
| 5598 | +/************************************************************************ |
| 5599 | + Deliberately outside the ACL defines. Return 1 if this is a "no acls" |
| 5600 | + errno, 0 if not. |
| 5601 | +************************************************************************/ |
| 5602 | + |
| 5603 | +int no_acl_syscall_error(int err) |
| 5604 | +{ |
| 5605 | +#if defined(ENOSYS) |
| 5606 | + if (err == ENOSYS) { |
| 5607 | + return 1; |
| 5608 | + } |
| 5609 | +#endif |
| 5610 | +#if defined(ENOTSUP) |
| 5611 | + if (err == ENOTSUP) { |
| 5612 | + return 1; |
| 5613 | + } |
| 5614 | +#endif |
| 5615 | + return 0; |
| 5616 | +} |
| 5617 | + |
| 5618 | +#endif /* SUPPORT_ACLS */ |
| 5619 | --- old/lib/sysacls.h |
| 5620 | +++ new/lib/sysacls.h |
| 5621 | @@ -0,0 +1,40 @@ |
| 5622 | +#ifdef SUPPORT_ACLS |
| 5623 | + |
| 5624 | +#ifdef HAVE_SYS_ACL_H |
| 5625 | +#include <sys/acl.h> |
| 5626 | +#endif |
| 5627 | +#ifdef HAVE_ACL_LIBACL_H |
| 5628 | +#include <acl/libacl.h> |
| 5629 | +#endif |
| 5630 | +#include "smb_acls.h" |
| 5631 | + |
| 5632 | +#define SMB_MALLOC(cnt) new_array(char, cnt) |
| 5633 | +#define SMB_MALLOC_P(obj) new_array(obj, 1) |
| 5634 | +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt) |
| 5635 | +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt) |
| 5636 | +#define slprintf snprintf |
| 5637 | + |
| 5638 | +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p); |
| 5639 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p); |
| 5640 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p); |
| 5641 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d); |
| 5642 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type); |
| 5643 | +SMB_ACL_T sys_acl_get_fd(int fd); |
| 5644 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); |
| 5645 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); |
| 5646 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); |
| 5647 | +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen); |
| 5648 | +SMB_ACL_T sys_acl_init(int count); |
| 5649 | +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry); |
| 5650 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype); |
| 5651 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual); |
| 5652 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset); |
| 5653 | +int sys_acl_valid(SMB_ACL_T theacl); |
| 5654 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); |
| 5655 | +int sys_acl_set_fd(int fd, SMB_ACL_T theacl); |
| 5656 | +int sys_acl_delete_def_file(const char *name); |
| 5657 | +int sys_acl_free_text(char *text); |
| 5658 | +int sys_acl_free_acl(SMB_ACL_T the_acl); |
| 5659 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype); |
| 5660 | + |
| 5661 | +#endif /* SUPPORT_ACLS */ |
| 5662 | --- old/log.c |
| 5663 | +++ new/log.c |
| 5664 | @@ -624,8 +624,10 @@ static void log_formatted(enum logcode c |
| 5665 | c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p'; |
| 5666 | c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o'; |
| 5667 | c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g'; |
| 5668 | - c[8] = '.'; |
| 5669 | - c[9] = '\0'; |
| 5670 | + c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u'; |
| 5671 | + c[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a'; |
| 5672 | + c[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x'; |
| 5673 | + c[11] = '\0'; |
| 5674 | |
| 5675 | if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) { |
| 5676 | char ch = iflags & ITEM_IS_NEW ? '+' : '?'; |
| 5677 | --- old/options.c |
| 5678 | +++ new/options.c |
| 5679 | @@ -46,6 +46,7 @@ int copy_dirlinks = 0; |
| 5680 | int copy_links = 0; |
| 5681 | int preserve_links = 0; |
| 5682 | int preserve_hard_links = 0; |
| 5683 | +int preserve_acls = 0; |
| 5684 | int preserve_perms = 0; |
| 5685 | int preserve_executability = 0; |
| 5686 | int preserve_devices = 0; |
| 5687 | @@ -198,6 +199,7 @@ static void print_rsync_version(enum log |
| 5688 | char const *got_socketpair = "no "; |
| 5689 | char const *have_inplace = "no "; |
| 5690 | char const *hardlinks = "no "; |
| 5691 | + char const *acls = "no "; |
| 5692 | char const *links = "no "; |
| 5693 | char const *ipv6 = "no "; |
| 5694 | STRUCT_STAT *dumstat; |
| 5695 | @@ -214,6 +216,10 @@ static void print_rsync_version(enum log |
| 5696 | hardlinks = ""; |
| 5697 | #endif |
| 5698 | |
| 5699 | +#ifdef SUPPORT_ACLS |
| 5700 | + acls = ""; |
| 5701 | +#endif |
| 5702 | + |
| 5703 | #ifdef SUPPORT_LINKS |
| 5704 | links = ""; |
| 5705 | #endif |
| 5706 | @@ -232,8 +238,8 @@ static void print_rsync_version(enum log |
| 5707 | (int)(sizeof (int64) * 8)); |
| 5708 | rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n", |
| 5709 | got_socketpair, hardlinks, links, ipv6, have_inplace); |
| 5710 | - rprintf(f, " %sappend\n", |
| 5711 | - have_inplace); |
| 5712 | + rprintf(f, " %sappend, %sACLs\n", |
| 5713 | + have_inplace, acls); |
| 5714 | |
| 5715 | #ifdef MAINTAINER_MODE |
| 5716 | rprintf(f, "Panic Action: \"%s\"\n", get_panic_action()); |
| 5717 | @@ -279,7 +285,7 @@ void usage(enum logcode F) |
| 5718 | rprintf(F," -q, --quiet suppress non-error messages\n"); |
| 5719 | rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n"); |
| 5720 | rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n"); |
| 5721 | - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n"); |
| 5722 | + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n"); |
| 5723 | rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n"); |
| 5724 | rprintf(F," -r, --recursive recurse into directories\n"); |
| 5725 | rprintf(F," -R, --relative use relative path names\n"); |
| 5726 | @@ -301,6 +307,9 @@ void usage(enum logcode F) |
| 5727 | rprintf(F," -p, --perms preserve permissions\n"); |
| 5728 | rprintf(F," -E, --executability preserve the file's executability\n"); |
| 5729 | rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n"); |
| 5730 | +#ifdef SUPPORT_ACLS |
| 5731 | + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n"); |
| 5732 | +#endif |
| 5733 | rprintf(F," -o, --owner preserve owner (super-user only)\n"); |
| 5734 | rprintf(F," -g, --group preserve group\n"); |
| 5735 | rprintf(F," --devices preserve device files (super-user only)\n"); |
| 5736 | @@ -421,6 +430,9 @@ static struct poptOption long_options[] |
| 5737 | {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, |
| 5738 | {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, |
| 5739 | {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 }, |
| 5740 | + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
| 5741 | + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, |
| 5742 | + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, |
| 5743 | {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 }, |
| 5744 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, |
| 5745 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, |
| 5746 | @@ -1092,6 +1104,24 @@ int parse_arguments(int *argc, const cha |
| 5747 | usage(FINFO); |
| 5748 | exit_cleanup(0); |
| 5749 | |
| 5750 | + case 'A': |
| 5751 | +#ifdef SUPPORT_ACLS |
| 5752 | + preserve_acls = 1; |
| 5753 | + preserve_perms = 1; |
| 5754 | + break; |
| 5755 | +#else |
| 5756 | + /* FIXME: this should probably be ignored with a |
| 5757 | + * warning and then countermeasures taken to |
| 5758 | + * restrict group and other access in the presence |
| 5759 | + * of any more restrictive ACLs, but this is safe |
| 5760 | + * for now */ |
| 5761 | + snprintf(err_buf,sizeof(err_buf), |
| 5762 | + "ACLs are not supported on this %s\n", |
| 5763 | + am_server ? "server" : "client"); |
| 5764 | + return 0; |
| 5765 | +#endif |
| 5766 | + |
| 5767 | + |
| 5768 | default: |
| 5769 | /* A large opt value means that set_refuse_options() |
| 5770 | * turned this option off. */ |
| 5771 | @@ -1547,6 +1577,10 @@ void server_options(char **args,int *arg |
| 5772 | argstr[x++] = 'p'; |
| 5773 | else if (preserve_executability && am_sender) |
| 5774 | argstr[x++] = 'E'; |
| 5775 | +#ifdef SUPPORT_ACLS |
| 5776 | + if (preserve_acls) |
| 5777 | + argstr[x++] = 'A'; |
| 5778 | +#endif |
| 5779 | if (recurse) |
| 5780 | argstr[x++] = 'r'; |
| 5781 | if (always_checksum) |
| 5782 | --- old/receiver.c |
| 5783 | +++ new/receiver.c |
| 5784 | @@ -47,6 +47,7 @@ extern int keep_partial; |
| 5785 | extern int checksum_seed; |
| 5786 | extern int inplace; |
| 5787 | extern int delay_updates; |
| 5788 | +extern mode_t orig_umask; |
| 5789 | extern struct stats stats; |
| 5790 | extern char *tmpdir; |
| 5791 | extern char *partial_dir; |
| 5792 | @@ -347,6 +348,10 @@ int recv_files(int f_in, char *local_nam |
| 5793 | int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i; |
| 5794 | enum logcode log_code = log_before_transfer ? FLOG : FINFO; |
| 5795 | int max_phase = protocol_version >= 29 ? 2 : 1; |
| 5796 | + int dflt_perms = (ACCESSPERMS & ~orig_umask); |
| 5797 | +#ifdef SUPPORT_ACLS |
| 5798 | + const char *parent_dirname = ""; |
| 5799 | +#endif |
| 5800 | int ndx, recv_ok; |
| 5801 | |
| 5802 | if (verbose > 2) |
| 5803 | @@ -562,7 +567,16 @@ int recv_files(int f_in, char *local_nam |
| 5804 | * mode based on the local permissions and some heuristics. */ |
| 5805 | if (!preserve_perms) { |
| 5806 | int exists = fd1 != -1; |
| 5807 | - file->mode = dest_mode(file->mode, st.st_mode, exists); |
| 5808 | +#ifdef SUPPORT_ACLS |
| 5809 | + const char *dn = file->dirname ? file->dirname : "."; |
| 5810 | + if (parent_dirname != dn |
| 5811 | + && strcmp(parent_dirname, dn) != 0) { |
| 5812 | + dflt_perms = default_perms_for_dir(dn); |
| 5813 | + parent_dirname = dn; |
| 5814 | + } |
| 5815 | +#endif |
| 5816 | + file->mode = dest_mode(file->mode, st.st_mode, |
| 5817 | + dflt_perms, exists); |
| 5818 | } |
| 5819 | |
| 5820 | /* We now check to see if we are writing the file "inplace" */ |
| 5821 | --- old/rsync.c |
| 5822 | +++ new/rsync.c |
| 5823 | @@ -31,6 +31,7 @@ |
| 5824 | |
| 5825 | extern int verbose; |
| 5826 | extern int dry_run; |
| 5827 | +extern int preserve_acls; |
| 5828 | extern int preserve_perms; |
| 5829 | extern int preserve_executability; |
| 5830 | extern int preserve_times; |
| 5831 | @@ -49,7 +50,6 @@ extern int inplace; |
| 5832 | extern int flist_eof; |
| 5833 | extern int keep_dirlinks; |
| 5834 | extern int make_backups; |
| 5835 | -extern mode_t orig_umask; |
| 5836 | extern struct file_list *cur_flist, *first_flist, *dir_flist; |
| 5837 | extern struct chmod_mode_struct *daemon_chmod_modes; |
| 5838 | |
| 5839 | @@ -203,7 +203,8 @@ void free_sums(struct sum_struct *s) |
| 5840 | |
| 5841 | /* This is only called when we aren't preserving permissions. Figure out what |
| 5842 | * the permissions should be and return them merged back into the mode. */ |
| 5843 | -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists) |
| 5844 | +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms, |
| 5845 | + int exists) |
| 5846 | { |
| 5847 | int new_mode; |
| 5848 | /* If the file already exists, we'll return the local permissions, |
| 5849 | @@ -220,56 +221,65 @@ mode_t dest_mode(mode_t flist_mode, mode |
| 5850 | new_mode |= (new_mode & 0444) >> 2; |
| 5851 | } |
| 5852 | } else { |
| 5853 | - /* Apply the umask and turn off special permissions. */ |
| 5854 | - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask)); |
| 5855 | + /* Apply destination default permissions and turn |
| 5856 | + * off special permissions. */ |
| 5857 | + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms); |
| 5858 | } |
| 5859 | return new_mode; |
| 5860 | } |
| 5861 | |
| 5862 | -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st, |
| 5863 | +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp, |
| 5864 | int flags) |
| 5865 | { |
| 5866 | int updated = 0; |
| 5867 | - STRUCT_STAT st2; |
| 5868 | + statx sx2; |
| 5869 | int change_uid, change_gid; |
| 5870 | mode_t new_mode = file->mode; |
| 5871 | |
| 5872 | - if (!st) { |
| 5873 | + if (!sxp) { |
| 5874 | if (dry_run) |
| 5875 | return 1; |
| 5876 | - if (link_stat(fname, &st2, 0) < 0) { |
| 5877 | + if (link_stat(fname, &sx2.st, 0) < 0) { |
| 5878 | rsyserr(FERROR, errno, "stat %s failed", |
| 5879 | full_fname(fname)); |
| 5880 | return 0; |
| 5881 | } |
| 5882 | - st = &st2; |
| 5883 | +#ifdef SUPPORT_ACLS |
| 5884 | + sx2.acc_acl = sx2.def_acl = NULL; |
| 5885 | +#endif |
| 5886 | if (!preserve_perms && S_ISDIR(new_mode) |
| 5887 | - && st->st_mode & S_ISGID) { |
| 5888 | + && sx2.st.st_mode & S_ISGID) { |
| 5889 | /* We just created this directory and its setgid |
| 5890 | * bit is on, so make sure it stays on. */ |
| 5891 | new_mode |= S_ISGID; |
| 5892 | } |
| 5893 | + sxp = &sx2; |
| 5894 | } |
| 5895 | |
| 5896 | - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times)) |
| 5897 | +#ifdef SUPPORT_ACLS |
| 5898 | + if (preserve_acls && !ACL_READY(*sxp)) |
| 5899 | + get_acl(fname, sxp); |
| 5900 | +#endif |
| 5901 | + |
| 5902 | + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times)) |
| 5903 | flags |= ATTRS_SKIP_MTIME; |
| 5904 | if (!(flags & ATTRS_SKIP_MTIME) |
| 5905 | - && cmp_time(st->st_mtime, file->modtime) != 0) { |
| 5906 | - int ret = set_modtime(fname, file->modtime, st->st_mode); |
| 5907 | + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) { |
| 5908 | + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode); |
| 5909 | if (ret < 0) { |
| 5910 | rsyserr(FERROR, errno, "failed to set times on %s", |
| 5911 | full_fname(fname)); |
| 5912 | - return 0; |
| 5913 | + goto cleanup; |
| 5914 | } |
| 5915 | if (ret == 0) /* ret == 1 if symlink could not be set */ |
| 5916 | updated = 1; |
| 5917 | } |
| 5918 | |
| 5919 | - change_uid = am_root && preserve_uid && st->st_uid != F_UID(file); |
| 5920 | + change_uid = am_root && preserve_uid && sxp->st.st_uid != F_UID(file); |
| 5921 | change_gid = preserve_gid && F_GID(file) != GID_NONE |
| 5922 | - && st->st_gid != F_GID(file); |
| 5923 | + && sxp->st.st_gid != F_GID(file); |
| 5924 | #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK |
| 5925 | - if (S_ISLNK(st->st_mode)) |
| 5926 | + if (S_ISLNK(sxp->st.st_mode)) |
| 5927 | ; |
| 5928 | else |
| 5929 | #endif |
| 5930 | @@ -279,45 +289,57 @@ int set_file_attrs(char *fname, struct f |
| 5931 | rprintf(FINFO, |
| 5932 | "set uid of %s from %ld to %ld\n", |
| 5933 | fname, |
| 5934 | - (long)st->st_uid, (long)F_UID(file)); |
| 5935 | + (long)sxp->st.st_uid, (long)F_UID(file)); |
| 5936 | } |
| 5937 | if (change_gid) { |
| 5938 | rprintf(FINFO, |
| 5939 | "set gid of %s from %ld to %ld\n", |
| 5940 | fname, |
| 5941 | - (long)st->st_gid, (long)F_GID(file)); |
| 5942 | + (long)sxp->st.st_gid, (long)F_GID(file)); |
| 5943 | } |
| 5944 | } |
| 5945 | if (do_lchown(fname, |
| 5946 | - change_uid ? F_UID(file) : st->st_uid, |
| 5947 | - change_gid ? F_GID(file) : st->st_gid) != 0) { |
| 5948 | + change_uid ? F_UID(file) : sxp->st.st_uid, |
| 5949 | + change_gid ? F_GID(file) : sxp->st.st_gid) != 0) { |
| 5950 | /* shouldn't have attempted to change uid or gid |
| 5951 | * unless have the privilege */ |
| 5952 | rsyserr(FERROR, errno, "%s %s failed", |
| 5953 | change_uid ? "chown" : "chgrp", |
| 5954 | full_fname(fname)); |
| 5955 | - return 0; |
| 5956 | + goto cleanup; |
| 5957 | } |
| 5958 | /* a lchown had been done - we have to re-stat if the |
| 5959 | * destination had the setuid or setgid bits set due |
| 5960 | * to the side effect of the chown call */ |
| 5961 | - if (st->st_mode & (S_ISUID | S_ISGID)) { |
| 5962 | - link_stat(fname, st, |
| 5963 | - keep_dirlinks && S_ISDIR(st->st_mode)); |
| 5964 | + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) { |
| 5965 | + link_stat(fname, &sxp->st, |
| 5966 | + keep_dirlinks && S_ISDIR(sxp->st.st_mode)); |
| 5967 | } |
| 5968 | updated = 1; |
| 5969 | } |
| 5970 | |
| 5971 | if (daemon_chmod_modes && !S_ISLNK(new_mode)) |
| 5972 | new_mode = tweak_mode(new_mode, daemon_chmod_modes); |
| 5973 | + |
| 5974 | +#ifdef SUPPORT_ACLS |
| 5975 | + /* It's OK to call set_acl() now, even for a dir, as the generator |
| 5976 | + * will enable owner-writability using chmod, if necessary. |
| 5977 | + * |
| 5978 | + * If set_acl() changes permission bits in the process of setting |
| 5979 | + * an access ACL, it changes sxp->st.st_mode so we know whether we |
| 5980 | + * need to chmod(). */ |
| 5981 | + if (preserve_acls && set_acl(fname, file, sxp) == 0) |
| 5982 | + updated = 1; |
| 5983 | +#endif |
| 5984 | + |
| 5985 | #ifdef HAVE_CHMOD |
| 5986 | - if (!BITS_EQUAL(st->st_mode, new_mode, CHMOD_BITS)) { |
| 5987 | + if (!BITS_EQUAL(sxp->st.st_mode, new_mode, CHMOD_BITS)) { |
| 5988 | int ret = do_chmod(fname, new_mode); |
| 5989 | if (ret < 0) { |
| 5990 | rsyserr(FERROR, errno, |
| 5991 | "failed to set permissions on %s", |
| 5992 | full_fname(fname)); |
| 5993 | - return 0; |
| 5994 | + goto cleanup; |
| 5995 | } |
| 5996 | if (ret == 0) /* ret == 1 if symlink could not be set */ |
| 5997 | updated = 1; |
| 5998 | @@ -330,6 +352,11 @@ int set_file_attrs(char *fname, struct f |
| 5999 | else |
| 6000 | rprintf(FCLIENT, "%s is uptodate\n", fname); |
| 6001 | } |
| 6002 | + cleanup: |
| 6003 | +#ifdef SUPPORT_ACLS |
| 6004 | + if (preserve_acls && sxp == &sx2) |
| 6005 | + free_acl(&sx2); |
| 6006 | +#endif |
| 6007 | return updated; |
| 6008 | } |
| 6009 | |
| 6010 | --- old/rsync.h |
| 6011 | +++ new/rsync.h |
| 6012 | @@ -547,6 +547,14 @@ struct idev_node { |
| 6013 | #define IN_LOOPBACKNET 127 |
| 6014 | #endif |
| 6015 | |
| 6016 | +#ifndef HAVE_NO_ACLS |
| 6017 | +#define SUPPORT_ACLS 1 |
| 6018 | +#endif |
| 6019 | + |
| 6020 | +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS |
| 6021 | +#define ACLS_NEED_MASK 1 |
| 6022 | +#endif |
| 6023 | + |
| 6024 | #define GID_NONE ((gid_t)-1) |
| 6025 | |
| 6026 | union file_extras { |
| 6027 | @@ -566,6 +574,7 @@ struct file_struct { |
| 6028 | extern int file_extra_cnt; |
| 6029 | extern int preserve_uid; |
| 6030 | extern int preserve_gid; |
| 6031 | +extern int preserve_acls; |
| 6032 | |
| 6033 | #define FILE_STRUCT_LEN (offsetof(struct file_struct, basename)) |
| 6034 | #define EXTRA_LEN (sizeof (union file_extras)) |
| 6035 | @@ -598,10 +607,12 @@ extern int preserve_gid; |
| 6036 | /* When the associated option is on, all entries will have these present: */ |
| 6037 | #define F_OWNER(f) REQ_EXTRA(f, preserve_uid)->unum |
| 6038 | #define F_GROUP(f) REQ_EXTRA(f, preserve_gid)->unum |
| 6039 | +#define F_ACL(f) REQ_EXTRA(f, preserve_acls)->unum |
| 6040 | |
| 6041 | /* These items are per-entry optional and mutally exclusive: */ |
| 6042 | #define F_HL_GNUM(f) OPT_EXTRA(f, LEN64_BUMP(f))->num |
| 6043 | #define F_HL_PREV(f) OPT_EXTRA(f, LEN64_BUMP(f))->num |
| 6044 | +#define F_DEF_ACL(f) OPT_EXTRA(f, LEN64_BUMP(f))->unum |
| 6045 | #define F_DIRDEV_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + 2 - 1)->unum) |
| 6046 | #define F_DIRNODE_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + 3 - 1)->num) |
| 6047 | |
| 6048 | @@ -753,6 +764,17 @@ struct stats { |
| 6049 | |
| 6050 | struct chmod_mode_struct; |
| 6051 | |
| 6052 | +#define EMPTY_ITEM_LIST {NULL, 0, 0} |
| 6053 | + |
| 6054 | +typedef struct { |
| 6055 | + void *items; |
| 6056 | + size_t count; |
| 6057 | + size_t malloced; |
| 6058 | +} item_list; |
| 6059 | + |
| 6060 | +#define EXPAND_ITEM_LIST(lp, type, incr) \ |
| 6061 | + (type*)expand_item_list(lp, sizeof (type), #type, incr) |
| 6062 | + |
| 6063 | #include "byteorder.h" |
| 6064 | #include "lib/mdfour.h" |
| 6065 | #include "lib/wildmatch.h" |
| 6066 | @@ -771,6 +793,16 @@ struct chmod_mode_struct; |
| 6067 | #define NORETURN __attribute__((__noreturn__)) |
| 6068 | #endif |
| 6069 | |
| 6070 | +typedef struct { |
| 6071 | + STRUCT_STAT st; |
| 6072 | +#ifdef SUPPORT_ACLS |
| 6073 | + struct rsync_acl *acc_acl; /* access ACL */ |
| 6074 | + struct rsync_acl *def_acl; /* default ACL */ |
| 6075 | +#endif |
| 6076 | +} statx; |
| 6077 | + |
| 6078 | +#define ACL_READY(sx) ((sx).acc_acl != NULL) |
| 6079 | + |
| 6080 | #include "proto.h" |
| 6081 | |
| 6082 | /* We have replacement versions of these if they're missing. */ |
| 6083 | --- old/rsync.yo |
| 6084 | +++ new/rsync.yo |
| 6085 | @@ -301,7 +301,7 @@ to the detailed description below for a |
| 6086 | -q, --quiet suppress non-error messages |
| 6087 | --no-motd suppress daemon-mode MOTD (see caveat) |
| 6088 | -c, --checksum skip based on checksum, not mod-time & size |
| 6089 | - -a, --archive archive mode; same as -rlptgoD (no -H) |
| 6090 | + -a, --archive archive mode; same as -rlptgoD (no -H, -A) |
| 6091 | --no-OPTION turn off an implied OPTION (e.g. --no-D) |
| 6092 | -r, --recursive recurse into directories |
| 6093 | -R, --relative use relative path names |
| 6094 | @@ -323,6 +323,7 @@ to the detailed description below for a |
| 6095 | -p, --perms preserve permissions |
| 6096 | -E, --executability preserve executability |
| 6097 | --chmod=CHMOD affect file and/or directory permissions |
| 6098 | + -A, --acls preserve ACLs (implies -p) [non-standard] |
| 6099 | -o, --owner preserve owner (super-user only) |
| 6100 | -g, --group preserve group |
| 6101 | --devices preserve device files (super-user only) |
| 6102 | @@ -771,7 +772,9 @@ quote(itemization( |
| 6103 | permissions, though the bf(--executability) option might change just |
| 6104 | the execute permission for the file. |
| 6105 | it() New files get their "normal" permission bits set to the source |
| 6106 | - file's permissions masked with the receiving end's umask setting, and |
| 6107 | + file's permissions masked with the receiving directory's default |
| 6108 | + permissions (either the receiving process's umask, or the permissions |
| 6109 | + specified via the destination directory's default ACL), and |
| 6110 | their special permission bits disabled except in the case where a new |
| 6111 | directory inherits a setgid bit from its parent directory. |
| 6112 | )) |
| 6113 | @@ -802,9 +805,11 @@ The preservation of the destination's se |
| 6114 | directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync |
| 6115 | versions erroneously preserved the three special permission bits for |
| 6116 | newly-created files when bf(--perms) was off, while overriding the |
| 6117 | -destination's setgid bit setting on a newly-created directory. (Keep in |
| 6118 | -mind that it is the version of the receiving rsync that affects this |
| 6119 | -behavior.) |
| 6120 | +destination's setgid bit setting on a newly-created directory. Default ACL |
| 6121 | +observance was added to the ACL patch for rsync 2.6.7, so older (or |
| 6122 | +non-ACL-enabled) rsyncs use the umask even if default ACLs are present. |
| 6123 | +(Keep in mind that it is the version of the receiving rsync that affects |
| 6124 | +these behaviors.) |
| 6125 | |
| 6126 | dit(bf(-E, --executability)) This option causes rsync to preserve the |
| 6127 | executability (or non-executability) of regular files when bf(--perms) is |
| 6128 | @@ -822,6 +827,14 @@ quote(itemization( |
| 6129 | |
| 6130 | If bf(--perms) is enabled, this option is ignored. |
| 6131 | |
| 6132 | +dit(bf(-A, --acls)) This option causes rsync to update the destination |
| 6133 | +ACLs to be the same as the source ACLs. This nonstandard option only |
| 6134 | +works if the remote rsync also supports it. bf(--acls) implies bf(--perms). |
| 6135 | + |
| 6136 | +The ACL-sending protocol used by this version was first introduced in |
| 6137 | +the patch that was shipped with 2.6.8. Sending ACLs to an older version |
| 6138 | +of the ACL patch is not supported. |
| 6139 | + |
| 6140 | dit(bf(--chmod)) This option tells rsync to apply one or more |
| 6141 | comma-separated "chmod" strings to the permission of the files in the |
| 6142 | transfer. The resulting value is treated as though it was the permissions |
| 6143 | @@ -1432,8 +1445,8 @@ if the receiving rsync is at least versi |
| 6144 | with older versions of rsync, but that also turns on the output of other |
| 6145 | verbose messages). |
| 6146 | |
| 6147 | -The "%i" escape has a cryptic output that is 9 letters long. The general |
| 6148 | -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the |
| 6149 | +The "%i" escape has a cryptic output that is 11 letters long. The general |
| 6150 | +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the |
| 6151 | type of update being done, bf(X) is replaced by the file-type, and the |
| 6152 | other letters represent attributes that may be output if they are being |
| 6153 | modified. |
| 6154 | @@ -1482,7 +1495,11 @@ quote(itemization( |
| 6155 | sender's value (requires bf(--owner) and super-user privileges). |
| 6156 | it() A bf(g) means the group is different and is being updated to the |
| 6157 | sender's value (requires bf(--group) and the authority to set the group). |
| 6158 | - it() The bf(z) slot is reserved for future use. |
| 6159 | + it() The bf(u) slot is reserved for reporting update (access) time changes |
| 6160 | + (a feature that is not yet released). |
| 6161 | + it() The bf(a) means that the ACL information changed. |
| 6162 | + it() The bf(x) slot is reserved for reporting extended attribute changes |
| 6163 | + (a feature that is not yet released). |
| 6164 | )) |
| 6165 | |
| 6166 | One other output is possible: when deleting files, the "%i" will output |
| 6167 | --- old/smb_acls.h |
| 6168 | +++ new/smb_acls.h |
| 6169 | @@ -0,0 +1,281 @@ |
| 6170 | +/* |
| 6171 | + Unix SMB/Netbios implementation. |
| 6172 | + Version 2.2.x |
| 6173 | + Portable SMB ACL interface |
| 6174 | + Copyright (C) Jeremy Allison 2000 |
| 6175 | + |
| 6176 | + This program is free software; you can redistribute it and/or modify |
| 6177 | + it under the terms of the GNU General Public License as published by |
| 6178 | + the Free Software Foundation; either version 2 of the License, or |
| 6179 | + (at your option) any later version. |
| 6180 | + |
| 6181 | + This program is distributed in the hope that it will be useful, |
| 6182 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6183 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 6184 | + GNU General Public License for more details. |
| 6185 | + |
| 6186 | + You should have received a copy of the GNU General Public License |
| 6187 | + along with this program; if not, write to the Free Software |
| 6188 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 6189 | +*/ |
| 6190 | + |
| 6191 | +#ifndef _SMB_ACLS_H |
| 6192 | +#define _SMB_ACLS_H |
| 6193 | + |
| 6194 | +#if defined HAVE_POSIX_ACLS |
| 6195 | + |
| 6196 | +/* This is an identity mapping (just remove the SMB_). */ |
| 6197 | + |
| 6198 | +#define SMB_ACL_TAG_T acl_tag_t |
| 6199 | +#define SMB_ACL_TYPE_T acl_type_t |
| 6200 | +#define SMB_ACL_PERMSET_T acl_permset_t |
| 6201 | +#define SMB_ACL_PERM_T acl_perm_t |
| 6202 | +#define SMB_ACL_READ ACL_READ |
| 6203 | +#define SMB_ACL_WRITE ACL_WRITE |
| 6204 | +#define SMB_ACL_EXECUTE ACL_EXECUTE |
| 6205 | + |
| 6206 | +/* Types of ACLs. */ |
| 6207 | +#define SMB_ACL_USER ACL_USER |
| 6208 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ |
| 6209 | +#define SMB_ACL_GROUP ACL_GROUP |
| 6210 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ |
| 6211 | +#define SMB_ACL_OTHER ACL_OTHER |
| 6212 | +#define SMB_ACL_MASK ACL_MASK |
| 6213 | + |
| 6214 | +#define SMB_ACL_T acl_t |
| 6215 | + |
| 6216 | +#define SMB_ACL_ENTRY_T acl_entry_t |
| 6217 | + |
| 6218 | +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY |
| 6219 | +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY |
| 6220 | + |
| 6221 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS |
| 6222 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT |
| 6223 | + |
| 6224 | +#elif defined HAVE_TRU64_ACLS |
| 6225 | + |
| 6226 | +/* This is for DEC/Compaq Tru64 UNIX */ |
| 6227 | + |
| 6228 | +#define SMB_ACL_TAG_T acl_tag_t |
| 6229 | +#define SMB_ACL_TYPE_T acl_type_t |
| 6230 | +#define SMB_ACL_PERMSET_T acl_permset_t |
| 6231 | +#define SMB_ACL_PERM_T acl_perm_t |
| 6232 | +#define SMB_ACL_READ ACL_READ |
| 6233 | +#define SMB_ACL_WRITE ACL_WRITE |
| 6234 | +#define SMB_ACL_EXECUTE ACL_EXECUTE |
| 6235 | + |
| 6236 | +/* Types of ACLs. */ |
| 6237 | +#define SMB_ACL_USER ACL_USER |
| 6238 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ |
| 6239 | +#define SMB_ACL_GROUP ACL_GROUP |
| 6240 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ |
| 6241 | +#define SMB_ACL_OTHER ACL_OTHER |
| 6242 | +#define SMB_ACL_MASK ACL_MASK |
| 6243 | + |
| 6244 | +#define SMB_ACL_T acl_t |
| 6245 | + |
| 6246 | +#define SMB_ACL_ENTRY_T acl_entry_t |
| 6247 | + |
| 6248 | +#define SMB_ACL_FIRST_ENTRY 0 |
| 6249 | +#define SMB_ACL_NEXT_ENTRY 1 |
| 6250 | + |
| 6251 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS |
| 6252 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT |
| 6253 | + |
| 6254 | +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS |
| 6255 | +/* |
| 6256 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. |
| 6257 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. |
| 6258 | + */ |
| 6259 | + |
| 6260 | +/* SVR4.2 ES/MP ACLs */ |
| 6261 | +typedef int SMB_ACL_TAG_T; |
| 6262 | +typedef int SMB_ACL_TYPE_T; |
| 6263 | +typedef ushort *SMB_ACL_PERMSET_T; |
| 6264 | +typedef ushort SMB_ACL_PERM_T; |
| 6265 | +#define SMB_ACL_READ 4 |
| 6266 | +#define SMB_ACL_WRITE 2 |
| 6267 | +#define SMB_ACL_EXECUTE 1 |
| 6268 | + |
| 6269 | +/* Types of ACLs. */ |
| 6270 | +#define SMB_ACL_USER USER |
| 6271 | +#define SMB_ACL_USER_OBJ USER_OBJ |
| 6272 | +#define SMB_ACL_GROUP GROUP |
| 6273 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ |
| 6274 | +#define SMB_ACL_OTHER OTHER_OBJ |
| 6275 | +#define SMB_ACL_MASK CLASS_OBJ |
| 6276 | + |
| 6277 | +typedef struct SMB_ACL_T { |
| 6278 | + int size; |
| 6279 | + int count; |
| 6280 | + int next; |
| 6281 | + struct acl acl[1]; |
| 6282 | +} *SMB_ACL_T; |
| 6283 | + |
| 6284 | +typedef struct acl *SMB_ACL_ENTRY_T; |
| 6285 | + |
| 6286 | +#define SMB_ACL_FIRST_ENTRY 0 |
| 6287 | +#define SMB_ACL_NEXT_ENTRY 1 |
| 6288 | + |
| 6289 | +#define SMB_ACL_TYPE_ACCESS 0 |
| 6290 | +#define SMB_ACL_TYPE_DEFAULT 1 |
| 6291 | + |
| 6292 | +#ifdef __CYGWIN__ |
| 6293 | +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS |
| 6294 | +#endif |
| 6295 | + |
| 6296 | +#elif defined HAVE_HPUX_ACLS |
| 6297 | + |
| 6298 | +/* |
| 6299 | + * Based on the Solaris & UnixWare code. |
| 6300 | + */ |
| 6301 | + |
| 6302 | +#undef GROUP |
| 6303 | +#include <sys/aclv.h> |
| 6304 | + |
| 6305 | +/* SVR4.2 ES/MP ACLs */ |
| 6306 | +typedef int SMB_ACL_TAG_T; |
| 6307 | +typedef int SMB_ACL_TYPE_T; |
| 6308 | +typedef ushort *SMB_ACL_PERMSET_T; |
| 6309 | +typedef ushort SMB_ACL_PERM_T; |
| 6310 | +#define SMB_ACL_READ 4 |
| 6311 | +#define SMB_ACL_WRITE 2 |
| 6312 | +#define SMB_ACL_EXECUTE 1 |
| 6313 | + |
| 6314 | +/* Types of ACLs. */ |
| 6315 | +#define SMB_ACL_USER USER |
| 6316 | +#define SMB_ACL_USER_OBJ USER_OBJ |
| 6317 | +#define SMB_ACL_GROUP GROUP |
| 6318 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ |
| 6319 | +#define SMB_ACL_OTHER OTHER_OBJ |
| 6320 | +#define SMB_ACL_MASK CLASS_OBJ |
| 6321 | + |
| 6322 | +typedef struct SMB_ACL_T { |
| 6323 | + int size; |
| 6324 | + int count; |
| 6325 | + int next; |
| 6326 | + struct acl acl[1]; |
| 6327 | +} *SMB_ACL_T; |
| 6328 | + |
| 6329 | +typedef struct acl *SMB_ACL_ENTRY_T; |
| 6330 | + |
| 6331 | +#define SMB_ACL_FIRST_ENTRY 0 |
| 6332 | +#define SMB_ACL_NEXT_ENTRY 1 |
| 6333 | + |
| 6334 | +#define SMB_ACL_TYPE_ACCESS 0 |
| 6335 | +#define SMB_ACL_TYPE_DEFAULT 1 |
| 6336 | + |
| 6337 | +#elif defined HAVE_IRIX_ACLS |
| 6338 | + |
| 6339 | +#define SMB_ACL_TAG_T acl_tag_t |
| 6340 | +#define SMB_ACL_TYPE_T acl_type_t |
| 6341 | +#define SMB_ACL_PERMSET_T acl_permset_t |
| 6342 | +#define SMB_ACL_PERM_T acl_perm_t |
| 6343 | +#define SMB_ACL_READ ACL_READ |
| 6344 | +#define SMB_ACL_WRITE ACL_WRITE |
| 6345 | +#define SMB_ACL_EXECUTE ACL_EXECUTE |
| 6346 | + |
| 6347 | +/* Types of ACLs. */ |
| 6348 | +#define SMB_ACL_USER ACL_USER |
| 6349 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ |
| 6350 | +#define SMB_ACL_GROUP ACL_GROUP |
| 6351 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ |
| 6352 | +#define SMB_ACL_OTHER ACL_OTHER_OBJ |
| 6353 | +#define SMB_ACL_MASK ACL_MASK |
| 6354 | + |
| 6355 | +typedef struct SMB_ACL_T { |
| 6356 | + int next; |
| 6357 | + BOOL freeaclp; |
| 6358 | + struct acl *aclp; |
| 6359 | +} *SMB_ACL_T; |
| 6360 | + |
| 6361 | +#define SMB_ACL_ENTRY_T acl_entry_t |
| 6362 | + |
| 6363 | +#define SMB_ACL_FIRST_ENTRY 0 |
| 6364 | +#define SMB_ACL_NEXT_ENTRY 1 |
| 6365 | + |
| 6366 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS |
| 6367 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT |
| 6368 | + |
| 6369 | +#elif defined HAVE_AIX_ACLS |
| 6370 | + |
| 6371 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ |
| 6372 | + |
| 6373 | +#include "/usr/include/acl.h" |
| 6374 | + |
| 6375 | +typedef uint *SMB_ACL_PERMSET_T; |
| 6376 | + |
| 6377 | +struct acl_entry_link{ |
| 6378 | + struct acl_entry_link *prevp; |
| 6379 | + struct new_acl_entry *entryp; |
| 6380 | + struct acl_entry_link *nextp; |
| 6381 | + int count; |
| 6382 | +}; |
| 6383 | + |
| 6384 | +struct new_acl_entry{ |
| 6385 | + unsigned short ace_len; |
| 6386 | + unsigned short ace_type; |
| 6387 | + unsigned int ace_access; |
| 6388 | + struct ace_id ace_id[1]; |
| 6389 | +}; |
| 6390 | + |
| 6391 | +#define SMB_ACL_ENTRY_T struct new_acl_entry* |
| 6392 | +#define SMB_ACL_T struct acl_entry_link* |
| 6393 | + |
| 6394 | +#define SMB_ACL_TAG_T unsigned short |
| 6395 | +#define SMB_ACL_TYPE_T int |
| 6396 | +#define SMB_ACL_PERM_T uint |
| 6397 | +#define SMB_ACL_READ S_IRUSR |
| 6398 | +#define SMB_ACL_WRITE S_IWUSR |
| 6399 | +#define SMB_ACL_EXECUTE S_IXUSR |
| 6400 | + |
| 6401 | +/* Types of ACLs. */ |
| 6402 | +#define SMB_ACL_USER ACEID_USER |
| 6403 | +#define SMB_ACL_USER_OBJ 3 |
| 6404 | +#define SMB_ACL_GROUP ACEID_GROUP |
| 6405 | +#define SMB_ACL_GROUP_OBJ 4 |
| 6406 | +#define SMB_ACL_OTHER 5 |
| 6407 | +#define SMB_ACL_MASK 6 |
| 6408 | + |
| 6409 | + |
| 6410 | +#define SMB_ACL_FIRST_ENTRY 1 |
| 6411 | +#define SMB_ACL_NEXT_ENTRY 2 |
| 6412 | + |
| 6413 | +#define SMB_ACL_TYPE_ACCESS 0 |
| 6414 | +#define SMB_ACL_TYPE_DEFAULT 1 |
| 6415 | + |
| 6416 | +#else /* No ACLs. */ |
| 6417 | + |
| 6418 | +/* No ACLS - fake it. */ |
| 6419 | +#define SMB_ACL_TAG_T int |
| 6420 | +#define SMB_ACL_TYPE_T int |
| 6421 | +#define SMB_ACL_PERMSET_T mode_t |
| 6422 | +#define SMB_ACL_PERM_T mode_t |
| 6423 | +#define SMB_ACL_READ S_IRUSR |
| 6424 | +#define SMB_ACL_WRITE S_IWUSR |
| 6425 | +#define SMB_ACL_EXECUTE S_IXUSR |
| 6426 | + |
| 6427 | +/* Types of ACLs. */ |
| 6428 | +#define SMB_ACL_USER 0 |
| 6429 | +#define SMB_ACL_USER_OBJ 1 |
| 6430 | +#define SMB_ACL_GROUP 2 |
| 6431 | +#define SMB_ACL_GROUP_OBJ 3 |
| 6432 | +#define SMB_ACL_OTHER 4 |
| 6433 | +#define SMB_ACL_MASK 5 |
| 6434 | + |
| 6435 | +typedef struct SMB_ACL_T { |
| 6436 | + int dummy; |
| 6437 | +} *SMB_ACL_T; |
| 6438 | + |
| 6439 | +typedef struct SMB_ACL_ENTRY_T { |
| 6440 | + int dummy; |
| 6441 | +} *SMB_ACL_ENTRY_T; |
| 6442 | + |
| 6443 | +#define SMB_ACL_FIRST_ENTRY 0 |
| 6444 | +#define SMB_ACL_NEXT_ENTRY 1 |
| 6445 | + |
| 6446 | +#define SMB_ACL_TYPE_ACCESS 0 |
| 6447 | +#define SMB_ACL_TYPE_DEFAULT 1 |
| 6448 | + |
| 6449 | +#endif /* No ACLs. */ |
| 6450 | +#endif /* _SMB_ACLS_H */ |
| 6451 | --- old/testsuite/acls.test |
| 6452 | +++ new/testsuite/acls.test |
| 6453 | @@ -0,0 +1,34 @@ |
| 6454 | +#! /bin/sh |
| 6455 | + |
| 6456 | +# This program is distributable under the terms of the GNU GPL (see |
| 6457 | +# COPYING). |
| 6458 | + |
| 6459 | +# Test that rsync handles basic ACL preservation. |
| 6460 | + |
| 6461 | +. $srcdir/testsuite/rsync.fns |
| 6462 | + |
| 6463 | +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support" |
| 6464 | +case "$setfacl_nodef" in |
| 6465 | +true) test_skipped "I don't know how to use your setfacl command" ;; |
| 6466 | +esac |
| 6467 | + |
| 6468 | +makepath "$fromdir/foo" |
| 6469 | +echo something >"$fromdir/file1" |
| 6470 | +echo else >"$fromdir/file2" |
| 6471 | + |
| 6472 | +files='foo file1 file2' |
| 6473 | + |
| 6474 | +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled" |
| 6475 | +setfacl -m u:0:5 "$fromdir/file1" |
| 6476 | +setfacl -m u:0:5 "$fromdir/file2" |
| 6477 | + |
| 6478 | +$RSYNC -avvA "$fromdir/" "$todir/" |
| 6479 | + |
| 6480 | +cd "$fromdir" |
| 6481 | +getfacl $files >"$scratchdir/acls.txt" |
| 6482 | + |
| 6483 | +cd "$todir" |
| 6484 | +getfacl $files | diff $diffopt "$scratchdir/acls.txt" - |
| 6485 | + |
| 6486 | +# The script would have aborted on error, so getting here means we've won. |
| 6487 | +exit 0 |
| 6488 | --- old/testsuite/default-acls.test |
| 6489 | +++ new/testsuite/default-acls.test |
| 6490 | @@ -0,0 +1,65 @@ |
| 6491 | +#! /bin/sh |
| 6492 | + |
| 6493 | +# This program is distributable under the terms of the GNU GPL (see |
| 6494 | +# COPYING). |
| 6495 | + |
| 6496 | +# Test that rsync obeys default ACLs. -- Matt McCutchen |
| 6497 | + |
| 6498 | +. $srcdir/testsuite/rsync.fns |
| 6499 | + |
| 6500 | +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support" |
| 6501 | +case "$setfacl_nodef" in |
| 6502 | +true) test_skipped "I don't know how to use your setfacl command" ;; |
| 6503 | +*-k*) opts='-dm u::7,g::5,o:5' ;; |
| 6504 | +*) opts='-m d:u::7,d:g::5,d:o:5' ;; |
| 6505 | +esac |
| 6506 | +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled" |
| 6507 | + |
| 6508 | +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected> |
| 6509 | +testit() { |
| 6510 | + todir="$scratchdir/$1" |
| 6511 | + mkdir "$todir" |
| 6512 | + $setfacl_nodef "$todir" |
| 6513 | + if [ "$2" ]; then |
| 6514 | + case "$setfacl_nodef" in |
| 6515 | + *-k*) opts="-dm $2" ;; |
| 6516 | + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`" |
| 6517 | + esac |
| 6518 | + setfacl $opts "$todir" |
| 6519 | + fi |
| 6520 | + # Make sure we obey ACLs when creating a directory to hold multiple transferred files, |
| 6521 | + # even though the directory itself is outside the transfer |
| 6522 | + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/" |
| 6523 | + check_perms "$todir/to" $4 "Target $1" |
| 6524 | + check_perms "$todir/to/dir" $4 "Target $1" |
| 6525 | + check_perms "$todir/to/file" $3 "Target $1" |
| 6526 | + check_perms "$todir/to/program" $4 "Target $1" |
| 6527 | + # Make sure get_local_name doesn't mess us up when transferring only one file |
| 6528 | + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile" |
| 6529 | + check_perms "$todir/to/anotherfile" $3 "Target $1" |
| 6530 | + # Make sure we obey default ACLs when not transferring a regular file |
| 6531 | + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/" |
| 6532 | + check_perms "$todir/to/anotherdir" $4 "Target $1" |
| 6533 | +} |
| 6534 | + |
| 6535 | +mkdir "$scratchdir/dir" |
| 6536 | +echo "File!" >"$scratchdir/file" |
| 6537 | +echo "#!/bin/sh" >"$scratchdir/program" |
| 6538 | +chmod 777 "$scratchdir/dir" |
| 6539 | +chmod 666 "$scratchdir/file" |
| 6540 | +chmod 777 "$scratchdir/program" |
| 6541 | + |
| 6542 | +# Test some target directories |
| 6543 | +umask 0077 |
| 6544 | +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx |
| 6545 | +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x |
| 6546 | +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x--- |
| 6547 | +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx--- |
| 6548 | +testit noda1 '' rw------- rwx------ |
| 6549 | +umask 0000 |
| 6550 | +testit noda2 '' rw-rw-rw- rwxrwxrwx |
| 6551 | +umask 0022 |
| 6552 | +testit noda3 '' rw-r--r-- rwxr-xr-x |
| 6553 | + |
| 6554 | +# Hooray |
| 6555 | +exit 0 |
| 6556 | --- old/testsuite/devices.test |
| 6557 | +++ new/testsuite/devices.test |
| 6558 | @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc |
| 6559 | $RSYNC -ai "$fromdir/block" "$todir/block2" \ |
| 6560 | | tee "$outfile" |
| 6561 | cat <<EOT >"$chkfile" |
| 6562 | -cD+++++++ block |
| 6563 | +cD+++++++++ block |
| 6564 | EOT |
| 6565 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" |
| 6566 | |
| 6567 | $RSYNC -ai "$fromdir/block2" "$todir/block" \ |
| 6568 | | tee "$outfile" |
| 6569 | cat <<EOT >"$chkfile" |
| 6570 | -cD+++++++ block2 |
| 6571 | +cD+++++++++ block2 |
| 6572 | EOT |
| 6573 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" |
| 6574 | |
| 6575 | @@ -58,7 +58,7 @@ sleep 1 |
| 6576 | $RSYNC -Di "$fromdir/block3" "$todir/block" \ |
| 6577 | | tee "$outfile" |
| 6578 | cat <<EOT >"$chkfile" |
| 6579 | -cD..T.... block3 |
| 6580 | +cD..T...... block3 |
| 6581 | EOT |
| 6582 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" |
| 6583 | |
| 6584 | @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \ |
| 6585 | | tee "$outfile" |
| 6586 | filter_outfile |
| 6587 | cat <<EOT >"$chkfile" |
| 6588 | -.d..t.... ./ |
| 6589 | -cD..t.... block |
| 6590 | -cD block2 |
| 6591 | -cD+++++++ block3 |
| 6592 | -hD+++++++ block2.5 => block3 |
| 6593 | -cD+++++++ char |
| 6594 | -cD+++++++ char2 |
| 6595 | -cD+++++++ char3 |
| 6596 | -cS+++++++ fifo |
| 6597 | +.d..t...... ./ |
| 6598 | +cD..t...... block |
| 6599 | +cD block2 |
| 6600 | +cD+++++++++ block3 |
| 6601 | +hD+++++++++ block2.5 => block3 |
| 6602 | +cD+++++++++ char |
| 6603 | +cD+++++++++ char2 |
| 6604 | +cD+++++++++ char3 |
| 6605 | +cS+++++++++ fifo |
| 6606 | EOT |
| 6607 | if test ! -b "$fromdir/block2.5"; then |
| 6608 | sed -e '/block2\.5/d' \ |
| 6609 | @@ -94,15 +94,15 @@ if test -b "$fromdir/block2.5"; then |
| 6610 | $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \ |
| 6611 | | tee "$outfile" |
| 6612 | cat <<EOT >"$chkfile" |
| 6613 | -cd ./ |
| 6614 | -hD block |
| 6615 | -hD block2 |
| 6616 | -hD block2.5 |
| 6617 | -hD block3 |
| 6618 | -hD char |
| 6619 | -hD char2 |
| 6620 | -hD char3 |
| 6621 | -hS fifo |
| 6622 | +cd ./ |
| 6623 | +hD block |
| 6624 | +hD block2 |
| 6625 | +hD block2.5 |
| 6626 | +hD block3 |
| 6627 | +hD char |
| 6628 | +hD char2 |
| 6629 | +hD char3 |
| 6630 | +hS fifo |
| 6631 | EOT |
| 6632 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" |
| 6633 | fi |
| 6634 | --- old/testsuite/itemize.test |
| 6635 | +++ new/testsuite/itemize.test |
| 6636 | @@ -47,16 +47,16 @@ rm -f "$to2dir" "$to2dir.test" |
| 6637 | $RSYNC -iplr "$fromdir/" "$todir/" \ |
| 6638 | | tee "$outfile" |
| 6639 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6640 | -cd+++++++ ./ |
| 6641 | -cd+++++++ bar/ |
| 6642 | -cd+++++++ foo/_P30_ |
| 6643 | -cd+++++++ bar/baz/ |
| 6644 | ->f+++++++ bar/baz/rsync |
| 6645 | -cd+++++++ foo/_P29_ |
| 6646 | ->f+++++++ foo/config1 |
| 6647 | ->f+++++++ foo/config2 |
| 6648 | ->f+++++++ foo/extra |
| 6649 | -cL+++++++ foo/sym -> ../bar/baz/rsync |
| 6650 | +cd+++++++++ ./ |
| 6651 | +cd+++++++++ bar/ |
| 6652 | +cd+++++++++ foo/_P30_ |
| 6653 | +cd+++++++++ bar/baz/ |
| 6654 | +>f+++++++++ bar/baz/rsync |
| 6655 | +cd+++++++++ foo/_P29_ |
| 6656 | +>f+++++++++ foo/config1 |
| 6657 | +>f+++++++++ foo/config2 |
| 6658 | +>f+++++++++ foo/extra |
| 6659 | +cL+++++++++ foo/sym -> ../bar/baz/rsync |
| 6660 | EOT |
| 6661 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" |
| 6662 | |
| 6663 | @@ -68,10 +68,10 @@ chmod 601 "$fromdir/foo/config2" |
| 6664 | $RSYNC -iplrH "$fromdir/" "$todir/" \ |
| 6665 | | tee "$outfile" |
| 6666 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6667 | ->f..T.... bar/baz/rsync |
| 6668 | ->f..T.... foo/config1 |
| 6669 | ->f.sTp... foo/config2 |
| 6670 | -hf..T.... foo/extra => foo/config1 |
| 6671 | +>f..T...... bar/baz/rsync |
| 6672 | +>f..T...... foo/config1 |
| 6673 | +>f.sTp..... foo/config2 |
| 6674 | +hf..T...... foo/extra => foo/config1 |
| 6675 | EOT |
| 6676 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" |
| 6677 | |
| 6678 | @@ -88,12 +88,12 @@ chmod 777 "$todir/bar/baz/rsync" |
| 6679 | $RSYNC -iplrtc "$fromdir/" "$todir/" \ |
| 6680 | | tee "$outfile" |
| 6681 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6682 | -.d..t.... foo/_P30_ |
| 6683 | -.f..tp... bar/baz/rsync |
| 6684 | -.d..t.... foo/_P29_ |
| 6685 | -.f..t.... foo/config1 |
| 6686 | ->fcstp... foo/config2 |
| 6687 | -cL..T.... foo/sym -> ../bar/baz/rsync |
| 6688 | +.d..t...... foo/_P30_ |
| 6689 | +.f..tp..... bar/baz/rsync |
| 6690 | +.d..t...... foo/_P29_ |
| 6691 | +.f..t...... foo/config1 |
| 6692 | +>fcstp..... foo/config2 |
| 6693 | +cL..T...... foo/sym -> ../bar/baz/rsync |
| 6694 | EOT |
| 6695 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" |
| 6696 | |
| 6697 | @@ -118,15 +118,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \ |
| 6698 | | tee "$outfile" |
| 6699 | filter_outfile |
| 6700 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6701 | -.d ./ |
| 6702 | -.d bar/ |
| 6703 | -.d bar/baz/ |
| 6704 | -.f...p... bar/baz/rsync |
| 6705 | -.d foo/ |
| 6706 | -.f foo/config1 |
| 6707 | ->f..t.... foo/config2 |
| 6708 | -hf foo/extra |
| 6709 | -.L foo/sym -> ../bar/baz/rsync |
| 6710 | +.d ./ |
| 6711 | +.d bar/ |
| 6712 | +.d bar/baz/ |
| 6713 | +.f...p..... bar/baz/rsync |
| 6714 | +.d foo/ |
| 6715 | +.f foo/config1 |
| 6716 | +>f..t...... foo/config2 |
| 6717 | +hf foo/extra |
| 6718 | +.L foo/sym -> ../bar/baz/rsync |
| 6719 | EOT |
| 6720 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed" |
| 6721 | |
| 6722 | @@ -145,8 +145,8 @@ touch "$todir/foo/config2" |
| 6723 | $RSYNC -iplrtH "$fromdir/" "$todir/" \ |
| 6724 | | tee "$outfile" |
| 6725 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6726 | -.f...p... foo/config1 |
| 6727 | ->f..t.... foo/config2 |
| 6728 | +.f...p..... foo/config1 |
| 6729 | +>f..t...... foo/config2 |
| 6730 | EOT |
| 6731 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed" |
| 6732 | |
| 6733 | @@ -154,15 +154,15 @@ $RSYNC -ivvplrtH --copy-dest=../to "$fro |
| 6734 | | tee "$outfile" |
| 6735 | filter_outfile |
| 6736 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6737 | -cd ./ |
| 6738 | -cd bar/ |
| 6739 | -cd bar/baz/ |
| 6740 | -cf bar/baz/rsync |
| 6741 | -cd foo/ |
| 6742 | -cf foo/config1 |
| 6743 | -cf foo/config2 |
| 6744 | -hf foo/extra => foo/config1 |
| 6745 | -cL foo/sym -> ../bar/baz/rsync |
| 6746 | +cd ./ |
| 6747 | +cd bar/ |
| 6748 | +cd bar/baz/ |
| 6749 | +cf bar/baz/rsync |
| 6750 | +cd foo/ |
| 6751 | +cf foo/config1 |
| 6752 | +cf foo/config2 |
| 6753 | +hf foo/extra => foo/config1 |
| 6754 | +cL foo/sym -> ../bar/baz/rsync |
| 6755 | EOT |
| 6756 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed" |
| 6757 | |
| 6758 | @@ -170,7 +170,7 @@ rm -rf "$to2dir" |
| 6759 | $RSYNC -iplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \ |
| 6760 | | tee "$outfile" |
| 6761 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6762 | -hf foo/extra => foo/config1 |
| 6763 | +hf foo/extra => foo/config1 |
| 6764 | EOT |
| 6765 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed" |
| 6766 | |
| 6767 | @@ -196,15 +196,15 @@ $RSYNC -ivvplrtH --link-dest="$todir" "$ |
| 6768 | | tee "$outfile" |
| 6769 | filter_outfile |
| 6770 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6771 | -cd ./ |
| 6772 | -cd bar/ |
| 6773 | -cd bar/baz/ |
| 6774 | -hf bar/baz/rsync |
| 6775 | -cd foo/ |
| 6776 | -hf foo/config1 |
| 6777 | -hf foo/config2 |
| 6778 | -hf foo/extra => foo/config1 |
| 6779 | -$L foo/sym -> ../bar/baz/rsync |
| 6780 | +cd ./ |
| 6781 | +cd bar/ |
| 6782 | +cd bar/baz/ |
| 6783 | +hf bar/baz/rsync |
| 6784 | +cd foo/ |
| 6785 | +hf foo/config1 |
| 6786 | +hf foo/config2 |
| 6787 | +hf foo/extra => foo/config1 |
| 6788 | +$L foo/sym -> ../bar/baz/rsync |
| 6789 | EOT |
| 6790 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed" |
| 6791 | |
| 6792 | @@ -244,15 +244,15 @@ $RSYNC -ivvplrtH --compare-dest="$todir" |
| 6793 | | tee "$outfile" |
| 6794 | filter_outfile |
| 6795 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
| 6796 | -cd ./ |
| 6797 | -cd bar/ |
| 6798 | -cd bar/baz/ |
| 6799 | -.f bar/baz/rsync |
| 6800 | -cd foo/ |
| 6801 | -.f foo/config1 |
| 6802 | -.f foo/config2 |
| 6803 | -.f foo/extra |
| 6804 | -.L foo/sym -> ../bar/baz/rsync |
| 6805 | +cd ./ |
| 6806 | +cd bar/ |
| 6807 | +cd bar/baz/ |
| 6808 | +.f bar/baz/rsync |
| 6809 | +cd foo/ |
| 6810 | +.f foo/config1 |
| 6811 | +.f foo/config2 |
| 6812 | +.f foo/extra |
| 6813 | +.L foo/sym -> ../bar/baz/rsync |
| 6814 | EOT |
| 6815 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed" |
| 6816 | |
| 6817 | --- old/uidlist.c |
| 6818 | +++ new/uidlist.c |
| 6819 | @@ -35,6 +35,7 @@ extern int verbose; |
| 6820 | extern int am_root; |
| 6821 | extern int preserve_uid; |
| 6822 | extern int preserve_gid; |
| 6823 | +extern int preserve_acls; |
| 6824 | extern int numeric_ids; |
| 6825 | |
| 6826 | struct idlist { |
| 6827 | @@ -271,7 +272,7 @@ void send_uid_list(int f) |
| 6828 | { |
| 6829 | struct idlist *list; |
| 6830 | |
| 6831 | - if (preserve_uid) { |
| 6832 | + if (preserve_uid || preserve_acls) { |
| 6833 | int len; |
| 6834 | /* we send sequences of uid/byte-length/name */ |
| 6835 | for (list = uidlist; list; list = list->next) { |
| 6836 | @@ -288,7 +289,7 @@ void send_uid_list(int f) |
| 6837 | write_int(f, 0); |
| 6838 | } |
| 6839 | |
| 6840 | - if (preserve_gid) { |
| 6841 | + if (preserve_gid || preserve_acls) { |
| 6842 | int len; |
| 6843 | for (list = gidlist; list; list = list->next) { |
| 6844 | if (!list->name) |
| 6845 | @@ -328,18 +329,28 @@ void recv_uid_list(int f, struct file_li |
| 6846 | { |
| 6847 | int id, i; |
| 6848 | |
| 6849 | - if (preserve_uid && !numeric_ids) { |
| 6850 | + if ((preserve_uid || preserve_acls) && !numeric_ids) { |
| 6851 | /* read the uid list */ |
| 6852 | while ((id = read_int(f)) != 0) |
| 6853 | recv_user_name(f, (uid_t)id); |
| 6854 | } |
| 6855 | |
| 6856 | - if (preserve_gid && !numeric_ids) { |
| 6857 | + if ((preserve_gid || preserve_acls) && !numeric_ids) { |
| 6858 | /* read the gid list */ |
| 6859 | while ((id = read_int(f)) != 0) |
| 6860 | recv_group_name(f, (gid_t)id); |
| 6861 | } |
| 6862 | |
| 6863 | +#ifdef SUPPORT_ACLS |
| 6864 | + if (preserve_acls && !numeric_ids) { |
| 6865 | + id_t *id; |
| 6866 | + while ((id = next_acl_uid(flist)) != NULL) |
| 6867 | + *id = match_uid(*id); |
| 6868 | + while ((id = next_acl_gid(flist)) != NULL) |
| 6869 | + *id = match_gid(*id); |
| 6870 | + } |
| 6871 | +#endif |
| 6872 | + |
| 6873 | /* Now convert all the uids/gids from sender values to our values. */ |
| 6874 | if (am_root && preserve_uid && !numeric_ids) { |
| 6875 | for (i = 0; i < flist->count; i++) |
| 6876 | --- old/util.c |
| 6877 | +++ new/util.c |
| 6878 | @@ -1466,3 +1466,31 @@ int bitbag_next_bit(struct bitbag *bb, i |
| 6879 | |
| 6880 | return -1; |
| 6881 | } |
| 6882 | + |
| 6883 | +void *expand_item_list(item_list *lp, size_t item_size, |
| 6884 | + const char *desc, int incr) |
| 6885 | +{ |
| 6886 | + /* First time through, 0 <= 0, so list is expanded. */ |
| 6887 | + if (lp->malloced <= lp->count) { |
| 6888 | + void *new_ptr; |
| 6889 | + size_t new_size = lp->malloced; |
| 6890 | + if (incr < 0) |
| 6891 | + new_size -= incr; /* increase slowly */ |
| 6892 | + else if (new_size < (size_t)incr) |
| 6893 | + new_size += incr; |
| 6894 | + else |
| 6895 | + new_size *= 2; |
| 6896 | + new_ptr = realloc_array(lp->items, char, new_size * item_size); |
| 6897 | + if (verbose >= 4) { |
| 6898 | + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n", |
| 6899 | + who_am_i(), desc, (double)new_size * item_size, |
| 6900 | + new_ptr == lp->items ? " not" : ""); |
| 6901 | + } |
| 6902 | + if (!new_ptr) |
| 6903 | + out_of_memory("expand_item_list"); |
| 6904 | + |
| 6905 | + lp->items = new_ptr; |
| 6906 | + lp->malloced = new_size; |
| 6907 | + } |
| 6908 | + return (char*)lp->items + (lp->count++ * item_size); |
| 6909 | +} |