Created
June 30, 2015 06:20
Revisions
-
mdippery created this gist
Jun 30, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #import <Foundation/Foundation.h> #include <grp.h> #include <string.h> #include <sys/stat.h> @interface FileOwnerManager : NSObject - (BOOL)isWheelPresent:(NSString *)path; @end @implementation FileOwnerManager - (BOOL)isWheelPresent:(NSString *)path { struct stat f_stat; int res = stat([path UTF8String], &f_stat); if (res != 0) { NSLog(@"Error!"); return NO; } struct group *group = getgrgid(f_stat.st_gid); NSLog(@"%@: %s", path, group->gr_name); return strcmp(group->gr_name, "wheel") == 0; } @end int main(int argc, char **argv) { BOOL res = NO; @autoreleasepool { FileOwnerManager *fom = [[FileOwnerManager alloc] init]; res = [fom isWheelPresent:[NSString stringWithUTF8String:argv[1]]]; [fom release]; } return res ? 0 : 1; }