Created
October 18, 2014 12:17
-
-
Save aont/4bbbb30fa8d1bd8a19fb to your computer and use it in GitHub Desktop.
dispatch root command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdio> | |
| #include <cstring> | |
| int main() | |
| { | |
| FILE* const sudo = popen("sudo -H -s", "r+"); | |
| fprintf(sudo, "echo login_test\n"); | |
| fflush(sudo); | |
| char line[256]; | |
| char* const fgets_ret = fgets(line, sizeof(line), sudo); | |
| if(fgets_ret==NULL) { | |
| fprintf(stderr, "failed!\n"); | |
| } else { | |
| fprintf(stderr, "%s\n", line); | |
| if(strcmp(line, "login_test\n")==0) { | |
| fprintf(stderr, "success!\n"); | |
| fprintf(sudo, "echo logined! >&2\n"); | |
| } | |
| } | |
| fclose(sudo); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment