]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - repo_shell.c
Document gitcreate -y option
[repo_shell.git] / repo_shell.c
index 887c4d3430350c1025e32cc60066182ee92d49b4..7d34e576e7e122782ed7eef5229eef23b82f18c2 100644 (file)
@@ -14,8 +14,9 @@
 #include "git_acl.h"
 #include "stringutils.h"
 
-#define CFG_FILE "/etc/repo_shell.cfg"
+#define CFG_FILE "/etc/repo_shell.conf"
 #define SHELL "/bin/bash"
+#define GIT_ACL_FILE ".gitacls"
 
 typedef struct {
   char *user;
@@ -34,7 +35,7 @@ static void change_user(char *user)
   struct passwd *pw = getpwnam(user);
 
   if (!pw)
-    die("invalid user %s", pw->pw_name);
+    die("invalid user %s", user);
   setuid(pw->pw_uid);
 }
 
@@ -53,9 +54,9 @@ static char *dequote(char *arg)
   return narg;
 }
 
-static char *add_prefix(char *prefix, char* arg)
+static char *add_prefix(const char *prefix, const char* arg)
 {
-  char *narg = arg;
+  char *narg;
   int i;
 
   if (arg && prefix && (i = strlen(prefix))) {
@@ -145,12 +146,11 @@ static int ini_handler(void* user, const char* section, const char* name,
 
   if (!strcmp(name, "svn_root"))
     pconfig->svn_root = xstrdup(value);
-  else if (!strcmp(name, "git_root"))
+  else if (!strcmp(name, "git_root")) {
     pconfig->git_root = xstrdup(value);
-  else if (!strcmp(name, "owner"))
+    pconfig->git_acl_file = add_prefix(value, GIT_ACL_FILE);
+  } else if (!strcmp(name, "owner"))
     pconfig->owner = xstrdup(value);
-  else if (!strcmp(name, "git_acl_file"))
-    pconfig->git_acl_file = xstrdup(value);
   else if (!strcmp(name, "allow_interactive"))
     pconfig->allow_interactive = str_has_word(value, pconfig->user);
   else
@@ -179,6 +179,17 @@ int main(int argc, char **argv)
     die("opening /dev/null failed");
   close (devnull_fd);
 
+  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
+    fprintf(stderr, "%s is a replacement login shell.\n"
+        "  May be ran from the command line with one of these options:\n"
+        "    -h|--help                 this text\n"
+        "    -v|--version              program version string\n"
+        "    -t|--test <user> <repo>   test access\n"
+        "    -d|--detail <user> <repo> test access, outputting more detail\n"
+        , argv[0]);
+    return 0;
+  }
+
   if (argc == 2 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
     fprintf(stderr, "%s\n", version);
     return 0;
@@ -200,11 +211,11 @@ int main(int argc, char **argv)
     return 1;
   }
 
-  if ((!strcmp(argv[1], "-t") || !strcmp(argv[1], "--test"))) {
+  if ((!strcmp(argv[1], "-d") || !strcmp(argv[1], "--detail"))) {
     perms_t p;
 
     if (argc !=4)
-      die("usage: %s -t <user> <repo>", argv[0]);
+      die("usage: %s -d|--detail <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",
@@ -213,6 +224,16 @@ int main(int argc, char **argv)
     return 0;
   }
 
+  if ((!strcmp(argv[1], "-t") || !strcmp(argv[1], "--test"))) {
+    perms_t p;
+
+    if (argc !=4)
+      die("usage: %s -t|--test <user> <repo>", argv[0]);
+    p = git_acl(argv[2], argv[3], cfg.git_acl_file);
+    printf("%s\n", git_acl_perms_as_str(p));
+    return 0;
+  }
+
   if (argc == 3) {
     /* argv[0] = repo_shell, argv[1] = -c, argv[2] = cmd
      * cmd = "svnserve -t" or "git-xxx '/path/to/repo.git'"