Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5945273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:39:29+00:00 2026-05-22T16:39:29+00:00

I am wondering if it is possible for a command line application to request

  • 0

I am wondering if it is possible for a command line application to request root access, like trying to call itself with sudo.

I am looking for a solution that would allow to write applications that require sudo privileges if it is needed.

It doesn’t have to request root access always, only if needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:39:30+00:00Added an answer on May 22, 2026 at 4:39 pm

    The options:

    • it could setuid(0), but only if it already has been invoked by root and so has a real UID of 0 and an effective UID of somebody else.
    • it could try to exec the sudo or su command and have itself run under UID 0, but only if sudo is configured to allow that (which normally requires that the user submit to authentication, as there will be an authorization check).
    • it could try to launch a new copy of itself via AuthorizationExecWithPrivileges(), but this again requires that the user submit to authn.
    • it could have been installed with a launchd job that it can communicate with in the system launchd context. Communicating with that job would cause launchd to invoke it, and presumably it’s configured to run under the root user. Now for this to come about, the job needs to have already been deployed: either via an installer (in which case the user authenticated) or via the Service Management framework’s SMJobBless() API (again, the user will need authentication to approve that).
    • it could make use of someone else’s badly-written launchd job to have that job execute itself with UID 0. As noted, this involves having a badly-written launchd job knocking around.

    So essentially it is possible, through a number of options, but all of the reliable ones require that the user authenticate and that the tool already be deployed in such a way as it can run in the root context. I actually wrote a whole book about this stuff…see particularly Chapter 6 of Professional Cocoa Application Security.

    Notice that all of the options except setuid (which I don’t recommend you use) actually involved a fork() to create a separate process, whether by the calling process or by launchd. That means you can actually have two separate executables: one that the user interacts with, and one that performs privileged tasks. That’s a better design than putting all of the functionality in one application so I’d recommend that approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering whether it is possible to add fields to objects dynamically. For
In Python one can say this: python script.py from the command line and receive
Suppose you have a script that takes a couple of command-line arguments and dumps
Possible Duplicate: Have you used any of the C++ interpreters (not compilers)? Hi, I
Is it possible to define a function in commandline window of Matlab? Looks no
I'm writing a simple script to generate all combinations of a and b of
In my project we use UnitTests (MsTest). We run them manually and in the
If I want to pass a program data files how can I distinguish the
So i am designing an art project that will print to a dot matrix
EDIT: I have started a bounty of 50 on this question to who ever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.