Show
Ignore:
Timestamp:
05/17/08 07:40:39 (3 months ago)
Author:
takkaria
Message:

Fix the UID issue on OS X again. (Thanks to Rowan Beentje, Aerdan, and Neil Stevens from ToME)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/z-file.c

    r894 r910  
    3131 
    3232#ifdef MACH_O_CARBON 
    33 # include <SystemConfiguration/SCDynamicStoreCopySpecific.h> 
     33# include <Carbon/Carbon.h> 
    3434#endif 
    3535 
     
    148148                } 
    149149 
     150#ifndef MACH_O_CARBON 
     151 
    150152                /* Fallback -- try the "current" user */ 
    151153                if (username[0] == '\0') 
     
    153155 
    154156                /* Look up a user (or "current" user) */ 
    155 #ifndef MACH_O_CARBON 
    156157                if (username) pw = getpwnam(username); 
    157158                else          pw = getpwuid(getuid()); 
    158  
    159159#else /* MACH_O_CARBON */ 
    160160 
    161                 /* On Macs look up the console user to avoid problems with invalid root detection */ 
    162                 uid_t uid; 
    163                 SCDynamicStoreCopyConsoleUser(NULL, &uid, NULL); 
    164                 pw = getpwuid(uid); 
     161                /* On Macs getlogin() can incorrectly return root, so get the username via system frameworks */ 
     162                CFStringRef cfusername = CSCopyUserName(TRUE); 
     163                CFIndex cfbufferlength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfusername), kCFStringEncodingUTF8) + 1; 
     164                char *macusername = mem_alloc(cfbufferlength); 
     165                CFStringGetCString(cfusername, macusername, cfbufferlength, kCFStringEncodingUTF8); 
     166                CFRelease(cfusername); 
     167 
     168                /* Look up the user */ 
     169                pw = getpwnam(macusername); 
     170                mem_free(macusername); 
    165171#endif /* !MACH_O_CARBON */ 
    166                  
     172 
    167173                if (!pw) return; 
    168174