Project

General

Profile

Bug #948 » chmod.diff

Yuri Pankov, 2011-04-22 09:44 PM

View differences:

usr/src/cmd/chmod/chmod.c Thu Apr 21 09:14:24 2011 -0700 → usr/src/cmd/chmod/chmod.c Sat Apr 23 09:37:07 2011 +0400
145 145

  
146 146
static int chmodr(char *dir, char *path, mode_t mode, mode_t umsk,
147 147
    sec_args_t *secp, attr_name_t *attrname);
148
static int doacl(char *file, struct stat *st, acl_args_t *aclp);
148
static int doacl(char *file, char *path, struct stat *st, acl_args_t *aclp);
149 149
static int dochmod(char *name, char *path, mode_t umsk, sec_args_t *secp,
150 150
    attr_name_t *attrnames);
151 151
static void handle_acl(char *name, o_mode_t group_clear_bits,
......
297 297

  
298 298
	if (secp != NULL) {
299 299
		if (secp->sec_type == SEC_ACL) {
300
			return (doacl(name, &st, secp->sec_acls));
300
			return (doacl(name, path, &st, secp->sec_acls));
301 301
		} else if (secp->sec_type == SEC_ATTR) {
302 302
			return (set_attrs(name, attrnames, secp->sec_attrs));
303 303
		} else {
......
351 351
			return (1);
352 352
		}
353 353
		if (secp->sec_type == SEC_ACL) {
354
			(void) doacl(dir, &st, secp->sec_acls);
354
			(void) doacl(dir, path, &st, secp->sec_acls);
355 355
		} else if (secp->sec_type == SEC_ATTR) {
356 356
			(void) set_attrs(dir, attrnames, secp->sec_attrs);
357 357
		} else {
......
377 377
	}
378 378

  
379 379
	if (chdir(dir) < 0) {
380
		errmsg(2, 0, "%s/%s: %s\n", savedir, dir, strerror(errno));
380
		errmsg(1, 0, "%s: %s\n", path, strerror(errno));
381 381
		return (1);
382 382
	}
383 383
	if ((dirp = opendir(".")) == NULL) {
......
450 450
	va_start(ap, format);
451 451

  
452 452
	/*
453
	 * Always print error message if this is a fatal error (code == 0);
453
	 * Always print error message if this is a fatal error (code != 0);
454 454
	 * otherwise, print message if fflag == 0 (no -f option specified)
455 455
	 */
456 456
	if (!fflag || (code != 0)) {
......
716 716
}
717 717

  
718 718
static int
719
doacl(char *file, struct stat *st, acl_args_t *acl_args)
719
doacl(char *file, char *path, struct stat *st, acl_args_t *acl_args)
720 720
{
721 721
	acl_t *aclp;
722 722
	acl_t *set_aclp;
723
	int error = 0;
723
	int error;
724 724
	void *to, *from;
725 725
	int len;
726 726
	int isdir;
727 727
	isdir = S_ISDIR(st->st_mode);
728 728

  
729
	error = acl_get(file, 0, &aclp);
730

  
731
	if (error != 0) {
732
		errmsg(1, 1, "%s\n", acl_strerror(error));
729
	if ((error = acl_get(file, 0, &aclp)) != 0) {
730
		errmsg(1, 0, "%s: %s\n", path, acl_strerror(error));
733 731
		return (1);
734 732
	}
735 733
	switch (acl_args->acl_action) {
736 734
	case ACL_ADD:
737 735
		if ((error = acl_addentries(aclp,
738 736
		    acl_args->acl_aclp, acl_args->acl_slot)) != 0) {
739
			errmsg(1, 1, "%s\n", acl_strerror(error));
737
			errmsg(1, 0, "%s: %s\n", path, acl_strerror(error));
740 738
			acl_free(aclp);
741 739
			return (1);
742 740
		}
......
744 742
		break;
745 743
	case ACL_SLOT_DELETE:
746 744
		if (acl_args->acl_slot + 1 > aclp->acl_cnt) {
747
			errmsg(1, 1,
748
			    gettext("Invalid slot specified for removal\n"));
745
			errmsg(1, 0,
746
			    gettext("%s: Invalid slot specified for removal\n"),
747
			    path);
749 748
			acl_free(aclp);
750 749
			return (1);
751 750
		}
752 751

  
753 752
		if (acl_args->acl_slot == 0 && aclp->acl_cnt == 1) {
754
			errmsg(1, 1,
755
			    gettext("Can't remove all ACL "
756
			    "entries from a file\n"));
753
			errmsg(1, 0, gettext("%s: Can't remove all ACEs\n"),
754
			    path);
757 755
			acl_free(aclp);
758 756
			return (1);
759 757
		}
......
781 779
	case ACL_DELETE:
782 780
		if ((error = acl_removeentries(aclp, acl_args->acl_aclp,
783 781
		    acl_args->acl_slot, ACL_REMOVE_ALL)) != 0) {
784
			errmsg(1, 1, "%s\n", acl_strerror(error));
782
			errmsg(1, 0, "%s: %s\n", path, acl_strerror(error));
785 783
			acl_free(aclp);
786 784
			return (1);
787 785
		}
788 786

  
789 787
		if (aclp->acl_cnt == 0) {
790
			errmsg(1, 1,
791
			    gettext("Can't remove all ACL "
792
			    "entries from a file\n"));
788
			errmsg(1, 0, gettext("%s: Can't remove all ACEs\n"),
789
			    path);
793 790
			acl_free(aclp);
794 791
			return (1);
795 792
		}
......
801 798
			error = acl_modifyentries(aclp, acl_args->acl_aclp,
802 799
			    acl_args->acl_slot);
803 800
			if (error) {
804
				errmsg(1, 1, "%s\n", acl_strerror(error));
801
				errmsg(1, 0, "%s: %s\n", path,
802
				    acl_strerror(error));
805 803
				acl_free(aclp);
806 804
				return (1);
807 805
			}
......
813 811
	case ACL_STRIP:
814 812
		error = acl_strip(file, st->st_uid, st->st_gid, st->st_mode);
815 813
		if (error) {
816
			errmsg(1, 1, "%s\n", acl_strerror(error));
814
			errmsg(1, 0, "%s: %s\n", path, acl_strerror(error));
817 815
			return (1);
818 816
		}
819 817
		acl_free(aclp);
820 818
		return (0);
821 819
		/*NOTREACHED*/
822 820
	default:
823
		errmsg(1, 0, gettext("Unknown ACL action requested\n"));
821
		errmsg(1, 2, gettext("Unknown ACL action requested\n"));
824 822
		return (1);
825 823
		break;
826 824
	}
827 825
	error = acl_check(set_aclp, isdir);
828 826

  
829 827
	if (error) {
830
		errmsg(1, 0, "%s\n%s", acl_strerror(error),
828
		errmsg(1, 2, "%s\n%s", acl_strerror(error),
831 829
		    gettext("See chmod(1) for more information on "
832 830
		    "valid ACL syntax\n"));
833 831
		return (1);
834 832
	}
835 833
	if ((error = acl_set(file, set_aclp)) != 0) {
836
			errmsg(1, 0, gettext("Failed to set ACL: %s\n"),
837
			    acl_strerror(error));
834
			errmsg(1, 0, gettext("%s: Failed to set ACL: %s\n"),
835
			    path, acl_strerror(error));
838 836
			acl_free(aclp);
839 837
			return (1);
840 838
	}
    (1-1/1)