Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

macOS-SMJobBless-Lazarus-Pascal

How to create an privileged Helper Tool under macOS, with Lazarus Pascal, to get root acces in your application.

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

macOS-SMJobBless-Lazarus-Pascal

How to create an privileged Helper Tool under macOS, with Lazarus Pascal, to get root acces in your application.

A full description and a ton of related information can be found on my homepage:

English: MacOS - SMJobBless: Elevated Privileges in Lazarus Pascal

Dutch: MacOS - SMJobBless: Elevated Privileges met Lazarus Pascal

SmJoBBless and Elevated Privileges Helper Tool Example

Purpose:

Simple example on how to create a Privileged Helper Tool using Lazarus Pascal, so your application can get root access by using such a Helper Tool.

Requirement:

A valid Apple Developer ID in order to sign the app bundle and the Helper Tool.

Tested and created with:

Lazarus 2.1.0 r60620M FPC 3.0.4 x86_64-darwin-cocoa (alpha) from SVN.

Before you start

I've uploaded a ZIP file that holds all files. Not the way GitHub should work, I know. Unfortunately, the project1.app structure seems to get lost when uploading empty directories, and we need those directories for things to work. I recommend downloading the zip file, and extracting that instead of cloning all files.

  1. Replace "XXXXXXXXXX" with your Developer ID in these files:
pascal
SMJobBlessTest/project1.app/Contents/Info.plist
SMJobBlessTest/Helper/SMJobBlessHelper-Info.plist
  1. Replace "John Doe (XXXXXXXXXX)" with your Developer name and ID in this file:
pascal
SMJobBlessTest/prepareproject1.sh
  1. Open the Helper Tool project com.tweaking4all.SMJobBlessHelper.lpi in Lazarus and compile it with "Build".

  2. Open the Main Application project project1.lpi in Lazarus and compile it with "Build".

  3. in Terminal, go to the "SMJobBlessTest" directory and run "./prepareproject.sh"

    Optionally verify with

bash
./SMJobBlessUtil.py check project1.app
  1. Open Console (Applications/Utilities) and set the filter to "SMJOBBLESS"
  2. Run project1.app (or project1) from the "SMJobBlessTest" directory.
  • "Initialize" will initialze and optionally install the Helper Tool
  • "Start Complicated" will start a process that keeps putting timestamps in the log
  • "Is Active?" will show if it's active or not
  • "Abort Complicated" will stop the time stamping
  • "Last Error" will just show a dummy message
  • "Get Version" will show the current Helper Version
  • "Quit Helper" will terminate the Helper tool

Clean up:

Remove Helper Tool

(Caution: this may not be the appropriate method)

bash
sudo rm /Library/PrivilegedHelperTools/com.tweaking4all.SMJobBlessHelper

Kill running Helper Tool

(Caution: this may not be the appropriate method)

bash
ps -ax | grep com.tweaking4all
sudo kill -9 <PID>

Where <PID> is the PID from the "ps" line that had "com.tweaking4all.SMJobBlessHelper" in it.