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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:45:32+00:00 2026-05-22T23:45:32+00:00

I have a program running in C. This needs to execute an iptables command

  • 0

I have a program running in C. This needs to execute an “iptables” command using system.

I tried

setuid(0); 
system("iptables .... ");

setuid and system do not coexist. from the system man page

Do not use system() from a program
with set-user-ID or set-group-ID
privileges, because strange values
for some
environment variables might be used to subvert system integrity.
Use the exec(3) family of functions
instead,
but not execlp(3) or execvp(3). system() will not, in fact, work
properly from programs with
set-user-ID or set-
group-ID privileges on systems on which /bin/sh is bash
version 2, since bash 2 drops
privileges on startup.
(Debian uses a modified bash which does not do this when invoked as
sh.)

how can I overcome my problem?

Thanks

  • 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-22T23:45:33+00:00Added an answer on May 22, 2026 at 11:45 pm

    Something like this might help. It’s untested but should work.

        char * const argv[] = {"/sbin/iptables", "-L", NULL};
    
        pid = fork();
        switch (pid) {
                case -1:
                        /* handle error */
                case 0:
                        execv("/sbin/iptables", argv);
                        /* handle error if you get here */
                break;
                default:
                        waitpid(pid, &status, 0);
                        /* check waitpid return code */
                break;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the System.Diagnostics.Process class to execute a command line program. I am using
I have a program in C++, using the standard socket API, running on Ubuntu
I have a Java program which runs in Tomcat and which needs to execute
I have a program 'foo' running different threads, fooT1, fooT2, .. fooTn. Now if
I have a .NET CF program (running on a Smartphone) and I have written
I have a situation where I might have multiple instances of a program running
What is the best way to have my C# Compact Framework program running in
I have a Matlab program that is running longer than I'd like it to.
I have a program in Octave that has a loop - running a function
I am looking for a method to monitor a running program that I have

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.