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 534187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:35:09+00:00 2026-05-13T09:35:09+00:00

I have written a program in c, that do some calculations then creates a

  • 0

I have written a program in c, that do some calculations then creates a folder. That folder’s owner is the root user. With an other user I am trying to run this c application. I’ve got this error:

mkdir: lol: Permission denied

Ok, I know this error is ok, because I don’t have rights for it, but I have read on the internet, that if I set the suid bit on the file, then this file will run with the owner’s rights.
I’ve used this command:

chmod +s filename

But it isn’t working… 🙁 Any ideas?

EDIT:
So, first of all, my Unix distribution is a Mac OS X 10.5.8. And my filename is a.out, since I have compiled it from ic.c with the command: gcc ic.c
And I am running the chmod command with the root user.

  • 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-13T09:35:09+00:00Added an answer on May 13, 2026 at 9:35 am

    I think you also will need to setuid(0); in your program to become root. Only setting the s-bit is not sufficient.

    I agree with all others, that doing all these things is very risky…

    Edit

    Jonathan Leffler is right in the comments. setuid(0); should probably not be necessary in this case. The necessary steps for ie creating a file under /etc

    create_file_under_etc.c

    #include <stdio.h>
    int main() {
      FILE *fp = fopen("/etc/so-su-test.txt", "wt");
      if (fp) {
        fprintf(fp, "I'll be back\n");
        fclose(fp);
        printf("File created.\n");
      } else {
        printf("File not created.\n");
      }
      return 0;
    }
    

    …and to test and compile

    cc create_file_under_etc.c
    sudo chmod +s a.out
    sudo chown root:staff a.out
    ./a.out
    

    …you better clean up also

    sudo rm a.out
    sudo rm /etc/so-su-test.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run a single-threaded program that i have written on my quad core
I have written a simple program that use some classes and procol buffers. These
I have written a program that generates random expressions and then uses genetic techniques
I have written a small 16-bit assembly program that writes some values in some
I have written a program that uses widgets as container (for other widgets). Because
Assume that i have written a program in C++ without using RTTI and run-time
In my current Java project, I have written a Java program that copies some
I have written a program that uses qhttp to get a webpage. This works
I have written a java program that is actually works as a gui to
I have written a c# program that calls a c++ dll that echoes the

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.