Skip to content

Instantly share code, notes, and snippets.

@gwpl
Last active April 30, 2016 21:37
Show Gist options
  • Save gwpl/abcbc74c2bf377945a49097237edfb9b to your computer and use it in GitHub Desktop.
Save gwpl/abcbc74c2bf377945a49097237edfb9b to your computer and use it in GitHub Desktop.
It is "pseudo-shell" that will only execute provided -c command. Might be helpful for sshd users configured with "ForcedCommand" and "ChrootDirectory". (example with further references: https://goo.gl/TjhrWd ). License: This is trivial code snippet directly based on documentation and C specification, please consider it public domain.
#include <unistd.h>
// compile with: gcc only_exec_command.c -static -o only_exec_command
// It is "pseudo-shell" that will only execute provided -c command.
// Usage : ./only_exec_command -c /bin/echo This is test
// Please note that this is far from perfect. It should actually parse and split string
// provided in argv[2], like shlex.Split in python. However, it's enought for my application
// of running one binary specified in ForceCommand sshd_config option.
int main(int argc, char **argv){
if (argc<3) return -1;
if (argv[1][0] != '-' || argv[1][1] != 'c' || argv[1][2] != '\0')
return -1;
execv(argv[2], &(argv[2]));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment