Running shell script as root via external binary
This is an ambitious thing to try, with many pitfalls - especially for environments which are Web-accessible.  I urge you to learn how to configure and use sudo instead - that's not foolproof, but it is a good deal safer than rolling your own.

That said, I'll make some observations:


We're using argv[1] without checking whether any arguments were supplied (we should test argc &gt;= 2 before using argv[1] - possibly check argc == 2, since we ignore any extra arguments).
There's a time-of-check/time-of-use (TOCTOU) race, because we examine the supplied file and later assume the properties haven't changed (we we get to running it).
Using system causes the supplied argument to be parsed as a shell command, which will do word splitting, expand variables and globs, and more.
Using a shell script from a privileged program is vulnerable to the script being changed between the interpreter being started and it opening the script to read commands (e.g. by switching symlinks).


It's quite easy to exploit this script to execute anything I want on your system, if there's a directory I can write to:




ln -s /bin/true 'ls -l ~root; id; cd; echo rm -rf; true .sh'

/some/path/run-as ls*.sh



We can avoid using system() (and accept extra arguments if we choose), by using execv() instead:

            if (match &amp;&amp; !strcasecmp(match, ".sh"))
            {
                execv(argv[1], argv+1);
                /* if we got here, exec failed */
                /* so fall through to return 1 */
            }


This does still leave us vulnerable to a user creating a symbolic link to a root-owned file and rewriting it to point to the user's file between the access check and the exec(), though.



In short: please use sudo if you really have to run some things as root.  Configured properly, it can give tight control on the commands you can execute with elevated privileges.  It's not completely attack-proof, but it is much better than writing your own (it has had decades of scrutiny to improve it).