Projects
Browse Source     Search     Timeline     Wiki

Changeset 23457

Show
Ignore:
Timestamp:
2007-12-07 12:59:53 (9 months ago)
Author:
zarzycki@…
Message:

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/SULeopard/launchd/src/launchctl.c

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