]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - git_acl.c
gitcreate: add option to set description
[repo_shell.git] / git_acl.c
index 796f5e96bd935b540e23196780b509917b3a658f..8783874b8472310f923ef85377b96fde0e35ee34 100644 (file)
--- a/git_acl.c
+++ b/git_acl.c
@@ -18,6 +18,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include "ini.h"
 #include "utility.h"
 #include "stringutils.h"
@@ -36,9 +37,7 @@ typedef struct {
   perms_t perms;
 } acl_t;
 
-const char* perm_str[PERMS_COUNT] = {
-  "NOTFOUND", "NONE", "READ", "READ_WRITE"
-};
+const char* perms_str[PERMS_COUNT] = { "", "", "r", "rw" };
 
 const char* lm_none = "<none>";
 static char *lm_repoid = NULL;
@@ -75,7 +74,7 @@ static const char *perms_as_str(perms_t p)
 {
   if (p < PERMS_NOTFOUND || p >= PERMS_COUNT)
     die("perms_as_str: invalid perm %u", p);
-  return perm_str[p];
+  return perms_str[p];
 }
 
 static perms_t perms_from_str(const char *str)
@@ -84,11 +83,11 @@ static perms_t perms_from_str(const char *str)
 
   if (!str)
     return PERMS_NOTFOUND;
-  else if (!*str)
+  else if (!strcmp(str, perms_str[PERMS_NONE]))
     return PERMS_NONE;
-  else if (!strcmp(str, "r"))
+  else if (!strcmp(str, perms_str[PERMS_READ]))
     return PERMS_READ;
-  else if (!strcmp(str, "rw"))
+  else if (!strcmp(str, perms_str[PERMS_READ_WRITE]))
     return PERMS_READ_WRITE;
   else
     die("Invalid perms value '%s'", str);
@@ -124,14 +123,14 @@ static int acl_handler(void* user, const char* section, const char* name,
       stra_add(&acl->userids, name);
     }
   } else if (!strcmp(section, "repo_groups")) {
-    if (str_has_word(value, acl->repo)) {
+    if (str_has_repo(value, acl->repo)) {
       //debug("repoids += '%s'", name);
       stra_add(&acl->repoids, name);
     }
   } else if (!strncmp(section, "repo", 4)) {
     char *_p = xstrdup(section + 4);
     char *p = _p;
-    char *repo = my_strtok(&p, " \t\n");
+    char *repo = strip_repo(my_strtok(&p, " \t\n"));
 
     if (!repo || my_strtok(&p, " \t\n"))
       die("acl_handler: badly formatted section '%s'", section);
@@ -145,6 +144,7 @@ static int acl_handler(void* user, const char* section, const char* name,
       //debug("match: repoid='%s', userid='%s', perms='%s'(%u)", repo, name,
       //    value, acl->perms);
     }
+    free(repo);
     free(_p);
   } else
     die("acl_handler: unknown section='%s' name='%s'", section, name);
@@ -154,6 +154,7 @@ static int acl_handler(void* user, const char* section, const char* name,
 int git_acl(const char *user, const char *repo, const char *file)
 {
   acl_t acl;
+  char *r;
 
   if (!file || !*file || !user || !*user || !repo || !*repo) {
     die("git_acl: invalid args user='%s', repo='%s', file='%s'", user, repo,
@@ -167,7 +168,9 @@ int git_acl(const char *user, const char *repo, const char *file)
   acl.user = (char*)user;
   acl.repo = (char*)repo;
   stra_add(&acl.userids, acl.user);
-  stra_add(&acl.repoids, acl.repo);
+  r = strip_repo(acl.repo);
+  stra_add(&acl.repoids, r);
+  free(r);
 
   //debug("Searching for '%s'@'%s'", acl.user, acl.repo);
   if (ini_parse(file, acl_handler, &acl) < 0)