comparison src/os_unix.c @ 5788:410ef4f1a3d2 v7.4.238

updated for version 7.4.238 Problem: Vim does not support the smack library. Solution: Add smack support (Jose Bollo)
author Bram Moolenaar <bram@vim.org>
date Wed, 02 Apr 2014 14:05:38 +0200
parents 5ab2946f7ce5
children da17c7de616e
comparison
equal deleted inserted replaced
5787:3a368abed51c 5788:410ef4f1a3d2
42 #endif 42 #endif
43 43
44 #ifdef HAVE_SELINUX 44 #ifdef HAVE_SELINUX
45 # include <selinux/selinux.h> 45 # include <selinux/selinux.h>
46 static int selinux_enabled = -1; 46 static int selinux_enabled = -1;
47 #endif
48
49 #ifdef HAVE_SMACK
50 # include <attr/xattr.h>
51 # include <linux/xattr.h>
52 # ifndef SMACK_LABEL_LEN
53 # define SMACK_LABEL_LEN 1024
54 # endif
47 #endif 55 #endif
48 56
49 /* 57 /*
50 * Use this prototype for select, some include files have a wrong prototype 58 * Use this prototype for select, some include files have a wrong prototype
51 */ 59 */
2795 freecon(to_context); 2803 freecon(to_context);
2796 freecon(from_context); 2804 freecon(from_context);
2797 } 2805 }
2798 } 2806 }
2799 #endif /* HAVE_SELINUX */ 2807 #endif /* HAVE_SELINUX */
2808
2809 #if defined(HAVE_SMACK) && !defined(PROTO)
2810 /*
2811 * Copy security info from "from_file" to "to_file".
2812 */
2813 void
2814 mch_copy_sec(from_file, to_file)
2815 char_u *from_file;
2816 char_u *to_file;
2817 {
2818 static const char const *smack_copied_attributes[] =
2819 {
2820 XATTR_NAME_SMACK,
2821 XATTR_NAME_SMACKEXEC,
2822 XATTR_NAME_SMACKMMAP
2823 };
2824
2825 char buffer[SMACK_LABEL_LEN];
2826 const char *name;
2827 int index;
2828 int ret;
2829 ssize_t size;
2830
2831 if (from_file == NULL)
2832 return;
2833
2834 for (index = 0 ; index < (int)(sizeof(smack_copied_attributes)
2835 / sizeof(smack_copied_attributes)[0]) ; index++)
2836 {
2837 /* get the name of the attribute to copy */
2838 name = smack_copied_attributes[index];
2839
2840 /* get the value of the attribute in buffer */
2841 size = getxattr((char*)from_file, name, buffer, sizeof(buffer));
2842 if (size >= 0)
2843 {
2844 /* copy the attribute value of buffer */
2845 ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0);
2846 if (ret < 0)
2847 {
2848 MSG_PUTS(_("Could not set security context "));
2849 MSG_PUTS(name);
2850 MSG_PUTS(_(" for "));
2851 msg_outtrans(to_file);
2852 msg_putchar('\n');
2853 }
2854 }
2855 else
2856 {
2857 /* what reason of not having the attribute value? */
2858 switch (errno)
2859 {
2860 case ENOTSUP:
2861 /* extended attributes aren't supported or enabled */
2862 /* should a message be echoed? not sure... */
2863 return; /* leave because it isn't usefull to continue */
2864
2865 case ERANGE:
2866 default:
2867 /* no enough size OR unexpected error */
2868 MSG_PUTS(_("Could not get security context "));
2869 MSG_PUTS(name);
2870 MSG_PUTS(_(" for "));
2871 msg_outtrans(from_file);
2872 MSG_PUTS(_(". Removing it!\n"));
2873 /* FALLTHROUGH to remove the attribute */
2874
2875 case ENODATA:
2876 /* no attribute of this name */
2877 ret = removexattr((char*)to_file, name);
2878 if (ret < 0 && errno != ENODATA)
2879 {
2880 MSG_PUTS(_("Could not remove security context "));
2881 MSG_PUTS(name);
2882 MSG_PUTS(_(" for "));
2883 msg_outtrans(to_file);
2884 msg_putchar('\n');
2885 }
2886 break;
2887 }
2888 }
2889 }
2890 }
2891 #endif /* HAVE_SMACK */
2800 2892
2801 /* 2893 /*
2802 * Return a pointer to the ACL of file "fname" in allocated memory. 2894 * Return a pointer to the ACL of file "fname" in allocated memory.
2803 * Return NULL if the ACL is not available for whatever reason. 2895 * Return NULL if the ACL is not available for whatever reason.
2804 */ 2896 */