Changeset 68 for trunk/src/sh_unix.c
- Timestamp:
- Oct 30, 2006, 12:03:44 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_unix.c
r65 r68 2863 2863 alert_timeout), 2864 2864 KEY_LEN+1); 2865 2865 2866 2866 /* return */ 2867 2867 SL_RETURN( 0, _("sh_unix_checksum_size")); … … 2874 2874 SL_RETURN( -1, _("sh_unix_checksum_size")); 2875 2875 } 2876 2877 int sh_unix_check_selinux = S_FALSE; 2878 int sh_unix_check_acl = S_FALSE; 2879 2880 #ifdef USE_ACL 2881 2882 #include <sys/acl.h> 2883 static char * sh_unix_getinfo_acl (char * path, int fd, struct stat * buf) 2884 { 2885 /* system.posix_acl_access, system.posix_acl_default 2886 */ 2887 char * out = NULL; 2888 char * collect = NULL; 2889 char * tmp; 2890 char * out_compact; 2891 ssize_t len; 2892 acl_t result; 2893 2894 SL_ENTER(_("sh_unix_getinfo_acl")); 2895 2896 result = (fd == -1) ? 2897 acl_get_file (path, ACL_TYPE_ACCESS) : 2898 acl_get_fd (fd); 2899 2900 if (result) 2901 { 2902 out = acl_to_text (result, &len); 2903 if (out && (len > 0)) { 2904 out_compact = sh_util_acl_compact (out, len); 2905 acl_free(out); 2906 if (out_compact) 2907 { 2908 collect = sh_util_strconcat (_("acl_access:"), out_compact, NULL); 2909 SH_FREE(out_compact); 2910 } 2911 } 2912 acl_free(result); 2913 } 2914 2915 2916 if ( S_ISDIR(buf->st_mode) ) 2917 { 2918 result = acl_get_file (path, ACL_TYPE_DEFAULT); 2919 2920 if (result) 2921 { 2922 out = acl_to_text (result, &len); 2923 if (out && (len > 0)) { 2924 out_compact = sh_util_acl_compact (out, len); 2925 acl_free(out); 2926 if (out_compact) { 2927 if (collect) { 2928 tmp = sh_util_strconcat (_("acl_default:"), 2929 out_compact, ":", collect, NULL); 2930 SH_FREE(collect); 2931 } 2932 else { 2933 tmp = sh_util_strconcat (_("acl_default:"), out_compact, NULL); 2934 } 2935 SH_FREE(out_compact); 2936 collect = tmp; 2937 } 2938 } 2939 acl_free(result); 2940 } 2941 } 2942 2943 SL_RETURN((collect),_("sh_unix_getinfo_acl")); 2944 } 2945 #endif 2946 2947 #ifdef USE_XATTR 2948 2949 #include <attr/xattr.h> 2950 static char * sh_unix_getinfo_xattr_int (char * path, int fd, char * name) 2951 { 2952 char * out = NULL; 2953 char * tmp = NULL; 2954 size_t size = 256; 2955 ssize_t result; 2956 2957 SL_ENTER(_("sh_unix_getinfo_xattr_int")); 2958 2959 out = SH_ALLOC(size); 2960 2961 result = (fd == -1) ? 2962 lgetxattr (path, name, out, size-1) : 2963 fgetxattr (fd, name, out, size-1); 2964 2965 if (result == -1 && errno == ERANGE) 2966 { 2967 SH_FREE(out); 2968 result = (fd == -1) ? 2969 lgetxattr (path, name, NULL, 0) : 2970 fgetxattr (fd, name, NULL, 0); 2971 size = result + 1; 2972 out = SH_ALLOC(size); 2973 result = (fd == -1) ? 2974 lgetxattr (path, name, out, size-1) : 2975 fgetxattr (fd, name, out, size-1); 2976 } 2977 2978 if ((result > 0) && ((size_t)result < size)) 2979 { 2980 out[size-1] = '\0'; 2981 tmp = out; 2982 } 2983 else 2984 { 2985 SH_FREE(out); 2986 } 2987 2988 SL_RETURN((tmp),_("sh_unix_getinfo_xattr_int")); 2989 } 2990 2991 2992 static char * sh_unix_getinfo_xattr (char * path, int fd, struct stat * buf) 2993 { 2994 /* system.posix_acl_access, system.posix_acl_default, security.selinux 2995 */ 2996 char * tmp; 2997 char * out = NULL; 2998 char * collect = NULL; 2999 3000 SL_ENTER(_("sh_unix_getinfo_xattr")); 3001 3002 #ifdef USE_ACL 3003 /* 3004 * we need the acl_get_fd/acl_get_file functions, getxattr will only 3005 * yield the raw bytes 3006 */ 3007 if (sh_unix_check_acl == S_TRUE) 3008 { 3009 out = sh_unix_getinfo_acl(path, fd, buf); 3010 3011 if (out) 3012 { 3013 collect = out; 3014 } 3015 } 3016 #endif 3017 3018 out = sh_unix_getinfo_xattr_int(path, fd, _("security.selinux")); 3019 3020 if (out) 3021 { 3022 if (collect) { 3023 tmp = sh_util_strconcat(_("selinux:"), out, ":", collect, NULL); 3024 SH_FREE(collect); 3025 } 3026 else { 3027 tmp = sh_util_strconcat(_("selinux:"), out, NULL); 3028 } 3029 SH_FREE(out); 3030 collect = tmp; 3031 } 3032 3033 SL_RETURN((collect),_("sh_unix_getinfo_xattr")); 3034 } 3035 #endif 3036 3037 #ifdef USE_XATTR 3038 int sh_unix_setcheckselinux (const char * c) 3039 { 3040 int i; 3041 SL_ENTER(_("sh_unix_setcheckselinux")); 3042 i = sh_util_flagval(c, &(sh_unix_check_selinux)); 3043 3044 SL_RETURN(i, _("sh_unix_setcheckselinux")); 3045 } 3046 #endif 3047 3048 #ifdef USE_ACL 3049 int sh_unix_setcheckacl (const char * c) 3050 { 3051 int i; 3052 SL_ENTER(_("sh_unix_setcheckacl")); 3053 i = sh_util_flagval(c, &(sh_unix_check_acl)); 3054 3055 SL_RETURN(i, _("sh_unix_setcheckacl")); 3056 } 3057 #endif 3058 2876 3059 2877 3060 int sh_unix_getinfo (int level, char * filename, file_type * theFile, … … 3124 3307 &theFile->attributes, theFile->c_attributes, 3125 3308 fd, &buf); 3309 #endif 3310 3311 #if defined(USE_XATTR) 3312 if (sh_unix_check_selinux == S_TRUE) 3313 theFile->attr_string = sh_unix_getinfo_xattr (theFile->fullpath, fd, &buf); 3314 #elif defined(USE_ACL) 3315 if (sh_unix_check_acl == S_TRUE) 3316 theFile->attr_string = sh_unix_getinfo_acl (theFile->fullpath, fd, &buf); 3317 #else 3318 theFile->attr_string = NULL; 3126 3319 #endif 3127 3320
Note:
See TracChangeset
for help on using the changeset viewer.