summaryrefslogtreecommitdiffabout
path: root/shared.c
authorLars Hjemli <hjemli@gmail.com>2007-02-03 14:02:55 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-02-04 20:47:46 (UTC)
commitce1c7336e5b3e3ebe8f8c9029c405aedec98c208 (patch) (unidiff)
treeb51a59a9552b32519cf694c0f5dc68c5a739069c /shared.c
parentebd7b0fbc378e9beca0b275c5cd9150c930bde56 (diff)
downloadcgit-ce1c7336e5b3e3ebe8f8c9029c405aedec98c208.zip
cgit-ce1c7336e5b3e3ebe8f8c9029c405aedec98c208.tar.gz
cgit-ce1c7336e5b3e3ebe8f8c9029c405aedec98c208.tar.bz2
Read repo-info from /etc/cgitrc
This makes cgit read all repo-info from the configfile, instead of scanning for possible git-dirs below a common root path. This is primarily done to get better security (separate physical path from logical repo-name). In /etc/cgitrc each repo is registered with the following keys: repo.url repo.name repo.path repo.desc repo.owner Note: *Required keys are repo.url and repo.path, all others are optional *Each occurrence of repo.url starts a new repository registration *Default value for repo.name is taken from repo.url *The value of repo.url cannot contain characters with special meaning for urls (i.e. one of /?%&), while repo.name can contain anything. Example: repo.url=cgit-pub repo.name=cgit/public repo.path=/pub/git/cgit repo.desc=My public cgit repo repo.owner=Lars Hjemli repo.url=cgit-priv repo.name=cgit/private repo.path=/home/larsh/src/cgit/.git repo.desc=My private cgit repo repo.owner=Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/shared.c b/shared.c
index 8e6df31..6fd70a8 100644
--- a/shared.c
+++ b/shared.c
@@ -8,7 +8,9 @@
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11char *cgit_root = "/usr/src/git"; 11struct repolist cgit_repolist;
12struct repoinfo *cgit_repo;
13
12char *cgit_root_title = "Git repository browser"; 14char *cgit_root_title = "Git repository browser";
13char *cgit_css = "/cgit.css"; 15char *cgit_css = "/cgit.css";
14char *cgit_logo = "/git-logo.png"; 16char *cgit_logo = "/git-logo.png";
@@ -46,11 +48,32 @@ int cgit_query_ofs = 0;
46 48
47int htmlfd = 0; 49int htmlfd = 0;
48 50
51struct repoinfo *add_repo(const char *url)
52{
53 struct repoinfo *ret;
54
55 if (++cgit_repolist.count > cgit_repolist.length) {
56 if (cgit_repolist.length == 0)
57 cgit_repolist.length = 8;
58 else
59 cgit_repolist.length *= 2;
60 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
61 cgit_repolist.length *
62 sizeof(struct repoinfo));
63 }
64
65 ret = &cgit_repolist.repos[cgit_repolist.count-1];
66 ret->url = xstrdup(url);
67 ret->name = ret->url;
68 ret->path = NULL;
69 ret->desc = NULL;
70 ret->owner = NULL;
71 return ret;
72}
73
49void cgit_global_config_cb(const char *name, const char *value) 74void cgit_global_config_cb(const char *name, const char *value)
50{ 75{
51 if (!strcmp(name, "root")) 76 if (!strcmp(name, "root-title"))
52 cgit_root = xstrdup(value);
53 else if (!strcmp(name, "root-title"))
54 cgit_root_title = xstrdup(value); 77 cgit_root_title = xstrdup(value);
55 else if (!strcmp(name, "css")) 78 else if (!strcmp(name, "css"))
56 cgit_css = xstrdup(value); 79 cgit_css = xstrdup(value);
@@ -74,6 +97,16 @@ void cgit_global_config_cb(const char *name, const char *value)
74 cgit_cache_dynamic_ttl = atoi(value); 97 cgit_cache_dynamic_ttl = atoi(value);
75 else if (!strcmp(name, "max-message-length")) 98 else if (!strcmp(name, "max-message-length"))
76 cgit_max_msg_len = atoi(value); 99 cgit_max_msg_len = atoi(value);
100 else if (!strcmp(name, "repo.url"))
101 cgit_repo = add_repo(value);
102 else if (!strcmp(name, "repo.name"))
103 cgit_repo->name = xstrdup(value);
104 else if (cgit_repo && !strcmp(name, "repo.path"))
105 cgit_repo->path = xstrdup(value);
106 else if (cgit_repo && !strcmp(name, "repo.desc"))
107 cgit_repo->desc = xstrdup(value);
108 else if (cgit_repo && !strcmp(name, "repo.owner"))
109 cgit_repo->owner = xstrdup(value);
77} 110}
78 111
79void cgit_repo_config_cb(const char *name, const char *value) 112void cgit_repo_config_cb(const char *name, const char *value)