]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - repo_shell.c
Properly handle wrong arg count when -t
[repo_shell.git] / repo_shell.c
index 9d775593d7b3f039a0a62ddad71be41e0bd2f939..dc9b8d611e6aa808c7a369671fa3b2784f15295e 100644 (file)
@@ -186,24 +186,29 @@ int main(int argc, char **argv)
     die("opening /dev/null failed");
   close (devnull_fd);
 
-  if (argc == 2 && (!strcmp(argv[1], "-v") ||
-      !strcmp(argv[1], "--version"))) {
+  if (argc == 2 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
     fprintf(stderr, "%s\n", version);
     return 0;
   }
 
-  if (argc == 1 && check_ssh_interactive(getuid())) {
+  if (argc == 1) {
+    if (!check_ssh_interactive(getuid()))
+      die("only repository access is allowed");
     setuid(getuid());
     argv[0] = SHELL;
     execvp(argv[0], (char *const *) argv);
+    return 1;
   }
 
   if (ini_parse(CFG_FILE, ini_handler, &cfg) < 0)
     die("cannot read config file %s", CFG_FILE);
 
-  if (argc == 4 && (!strcmp(argv[1], "-t") ||
-      !strcmp(argv[1], "--test"))) {
-    perms_t p = git_acl(argv[2], argv[3], cfg.git_acl_file);
+  if ((!strcmp(argv[1], "-t") || !strcmp(argv[1], "--test"))) {
+    perms_t p;
+
+    if (argc !=4)
+      die("usage: %s -t <user> <repo>", argv[0]);
+    p = git_acl(argv[2], argv[3], cfg.git_acl_file);
     fprintf(stderr,
         "user '%s' repo '%s' perms '%s'\n  via userid '%s' repoid '%s'\n",
         argv[2], argv[3], git_acl_perms_as_str(p), git_acl_last_userid(),