diff options
author | Aaron Ball <nullspoon@oper.io> | 2021-07-11 15:34:29 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2021-07-11 15:34:29 -0600 |
commit | 4aac31c788be61de0c1ee5d2d5bf0df723336838 (patch) | |
tree | 83a44463455ff9fb8ef64beca21684cf76e3734e | |
parent | 9aa89ac1ca1437a5058479b5f7917c22d8e60ca7 (diff) | |
download | gitaccess-4aac31c788be61de0c1ee5d2d5bf0df723336838.tar.gz gitaccess-4aac31c788be61de0c1ee5d2d5bf0df723336838.tar.xz |
Improve main function efficiency
There already existed a string buffer for the original ssh command
string, but this still made repeated calls to get that environment
variable. Now we only use the `cmd` buffer.
This also prints "No soup for you!" to stderr, rather than stdout.
-rw-r--r-- | src/main.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -228,14 +228,14 @@ int main(int argc, char* argv[]) { return 1; } user = argv[1]; - // Read the USERNAME variable + // Set the USERNAME environment variable setenv("USERNAME", user, 1); // Ensure a command was specified if(! getenv("SSH_ORIGINAL_COMMAND")) { sprintf(msg, "[%s] logged in without specifying a command", user); logmsg(msg); - printf("No soup for you!\n"); + fprintf(stderr, "No soup for you!\n"); return 1; } @@ -245,22 +245,20 @@ int main(int argc, char* argv[]) { if(is_git_cmd(cmd)) { // Read the repo path (command argument) if(!validate_git(user)) { - sprintf(msg, "[%s] attempted invalid git command \"%s\"", - user, getenv("SSH_ORIGINAL_COMMAND")); + sprintf(msg, "[%s] attempted invalid git command \"%s\"", user, cmd); logmsg(msg); return 1; } } else if(! is_allowed_cmd(cmd)) { - sprintf(msg, "[%s] attempted disallowed command \"%s\"", - user, getenv("SSH_ORIGINAL_COMMAND")); + sprintf(msg, "[%s] attempted disallowed command \"%s\"", user, cmd); logmsg(msg); fprintf(stderr, "Command '%s' is not allowed\n", cmd); return 1; } - sprintf(msg, "[%s] executed \"%s\"", user, getenv("SSH_ORIGINAL_COMMAND")); + sprintf(msg, "[%s] executed \"%s\"", user, cmd); logmsg(msg); - sprintf(gitsh, "/usr/bin/env git-shell -c \"%s\"", getenv("SSH_ORIGINAL_COMMAND")); + sprintf(gitsh, "/usr/bin/env git-shell -c \"%s\"", cmd); system(gitsh); return 0; |