]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - repo_shell.c
Add version option, derived from repository tags
[repo_shell.git] / repo_shell.c
index 35edbe7c790f9cf1ff864a2a7250699464f22c47..b51c0add25039ca49e31b232a50a9f3add431fa8 100644 (file)
@@ -8,8 +8,10 @@
 #include <pwd.h>
 #include <string.h>
 #include "ini.h"
+#include "version.h"
 
 #define CFG_FILE "/etc/repo_shell.cfg"
+#define GIT_ACL_FILE "git_acl.cfg"
 
 typedef struct {
        char *svn_root;
@@ -146,17 +148,39 @@ static int check_ssh_interactive(uid_t uid)
        return 1; /* for now */
 }
 
-static int git_check_access(const char *cmd, const char *arg, const char *user)
+static int git_acl(const char *user, const char *repo)
 {
-       /* TODO: Read some configuration file which maps users and access
-        * to a boolean true/false value.
-        *
-        * The git command can support read and write.
-        * git-receive-pack is ok for readers and writers
-        * git-upload-pack is ok only for writers
-        * git-upload-archive is ok only for writers
+       /* TODO: Read GIT_ACL_FILE from cfg.owner's home directory.  Look for
+        * the access level afforded user for repo.  A return of 0 means no
+        * access, a return of 1 means read only, and a return of 2 means
+        * read/write.
         */
-       return 1; /* assume OK for now */
+       struct passwd *pw;
+       char *file;
+       int len = strlen(cfg.owner) + strlen(GIT_ACL_FILE) + 8;
+
+       pw = getpwnam(cfg.owner);
+       if (!pw)
+               die("owner %s has no passwd entry?", cfg.owner);
+       len = strlen(pw->pw_dir) + strlen(GIT_ACL_FILE) + 2;
+       file = xmalloc(sizeof(char) * len);
+       sprintf(file, "%s/%s", pw->pw_dir, GIT_ACL_FILE);
+       fprintf(stderr, "[someday check %s]\n", file);
+       free(file);
+       return 2; /* assume read/write for now */
+}
+
+static int git_check_access(const char *cmd, const char *repo, const char *user)
+{
+       int rw = 1; /* 0=no access, 1=read only, 2=read/write */
+
+       /* What access is required per the incoming command? */
+       if (!strcmp(cmd, "git-upload-pack") ||
+                       !strcmp(cmd, "git-upload-archive"))
+               rw = 2;
+
+       /* Return true (1) if the user permissions >= those required */
+       return (git_acl(user, repo) >= rw) ? 1 : 0;
 }
 
 static int do_git_cmd(const char *cmd, char *arg, char *user)
@@ -280,7 +304,7 @@ static struct commands {
 };
 
 static int handler(void* user, const char* section, const char* name,
-                   const char* value)
+               const char* value)
 {
        cfg_t* pconfig = (cfg_t*)user;
 
@@ -316,6 +340,11 @@ 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"))) {
+               fprintf(stderr, "%s\n", version);
+               return 0;
+        }
        if (argc < 3)
                die("invalid arguments");