0

so im trying to make an app that requires root privileges and i found this function but i keep getting an error, "No matching member function for call to 'push_back'", I tried changing the vector to string then converting it to a char* but then I got segmentation fault 11,

static bool execute(const string &program, const vector<string> &arguments) {
    AuthorizationRef ref;
    if (AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &ref) != errAuthorizationSuccess) {
        return false;
    }

    AuthorizationItem item = {
        kAuthorizationRightExecute, 0, 0, 0
    };
    AuthorizationRights rights = { 1, &item };
    const AuthorizationFlags flags = kAuthorizationFlagDefaults
    | kAuthorizationFlagInteractionAllowed
    | kAuthorizationFlagPreAuthorize
    | kAuthorizationFlagExtendRights;

    if (AuthorizationCopyRights(ref, &rights, kAuthorizationEmptyEnvironment, flags, 0) != errAuthorizationSuccess) {
        AuthorizationFree(ref, kAuthorizationFlagDestroyRights);
        return false;
    }

    vector<char*> args;
    for (vector<string>::const_iterator it = arguments.begin(); it != arguments.end(); ++it) {
        args.push_back(it->c_str()); // Error here, "No matching member function for call to 'push_back'"
    }
    args.push_back(0);

    OSStatus status = AuthorizationExecuteWithPrivileges(ref, program.c_str(), kAuthorizationFlagDefaults, &args[0], 0);

    AuthorizationFree(ref, kAuthorizationFlagDestroyRights);
    return status == errAuthorizationSuccess;
}
meme
  • 27
  • 8

0 Answers0