Skip to content

Instantly share code, notes, and snippets.

@mdippery
Created June 30, 2015 06:20

Revisions

  1. mdippery created this gist Jun 30, 2015.
    36 changes: 36 additions & 0 deletions group.m
    Original 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;
    }