Projects
Browse Source     Search     Timeline     Wiki

Changeset 23458

Show
Ignore:
Timestamp:
12/07/07 13:06:19 (12 months ago)
Author:
zarzycki@…
Message:

<rdar://problem/5619757> SULeoCeto: Detect and fix bogus permissions on /sbin/launchd

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/launchd/src/launchctl.c

    r23452 r23458  
    152152static void read_launchd_conf(void); 
    153153static bool job_disabled_logic(launch_data_t obj); 
     154static void fix_bogus_file_metadata(void); 
    154155 
    155156typedef enum { 
     
    27822783 
    27832784        assumes(fwexec(remount_tool, NULL) != -1); 
    2784 } 
     2785 
     2786        fix_bogus_file_metadata(); 
     2787} 
     2788 
     2789void 
     2790fix_bogus_file_metadata(void) 
     2791{ 
     2792        static const struct { 
     2793                const char *path; 
     2794                const uid_t owner; 
     2795                const gid_t group; 
     2796                const mode_t needed_bits; 
     2797                const mode_t bad_bits; 
     2798        } f[] = { 
     2799                { "/sbin/launchd", 0, 0, S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, S_ISUID|S_ISGID|S_ISVTX|S_IWOTH }, 
     2800                { _PATH_TMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID }, 
     2801                { _PATH_VARTMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID }, 
     2802        }; 
     2803        struct stat sb; 
     2804        size_t i; 
     2805 
     2806        for (i = 0; i < (sizeof(f) / sizeof(f[0])); i++) { 
     2807                mode_t i_needed_bits; 
     2808                mode_t i_bad_bits; 
     2809                bool fix_mode = false; 
     2810                bool fix_id = false; 
     2811 
     2812                if (!assumes(stat(f[i].path, &sb) != -1)) { 
     2813                        continue; 
     2814                } 
     2815 
     2816                i_needed_bits = ~sb.st_mode & f[i].needed_bits; 
     2817                i_bad_bits = sb.st_mode & f[i].bad_bits; 
     2818 
     2819                if (i_bad_bits) { 
     2820                        fprintf(stderr, "Crucial filesystem check: Removing bogus mode bits 0%o on path: %s\n", i_bad_bits, f[i].path); 
     2821                        fix_mode = true; 
     2822                } 
     2823                if (i_needed_bits) { 
     2824                        fprintf(stderr, "Crucial filesystem check: Adding missing mode bits 0%o on path: %s\n", i_needed_bits, f[i].path); 
     2825                        fix_mode = true; 
     2826                } 
     2827                if (sb.st_uid != f[i].owner) { 
     2828                        fprintf(stderr, "Crucial filesystem check: Fixing bogus UID %u on path: %s\n", sb.st_uid, f[i].path); 
     2829                        fix_id = true; 
     2830                } 
     2831                if (sb.st_gid != f[i].group) { 
     2832                        fprintf(stderr, "Crucial filesystem check: Fixing bogus GID %u on path: %s\n", sb.st_gid, f[i].path); 
     2833                        fix_id = true; 
     2834                } 
     2835 
     2836                if (fix_mode) { 
     2837                        assumes(chmod(f[i].path, (sb.st_mode & ~i_bad_bits) | i_needed_bits) != -1); 
     2838                } 
     2839                if (fix_id) { 
     2840                        assumes(chown(f[i].path, f[i].owner, f[i].group) != -1); 
     2841                } 
     2842        } 
     2843} 
     2844 
    27852845 
    27862846bool