summaryrefslogtreecommitdiffabout
authorFelix Hanley <felix@seconddrawer.com.au>2010-11-08 18:41:13 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-11-08 18:41:13 (UTC)
commite0c6f23789e4893781bcd5af2281d468991ccf3a (patch) (unidiff)
tree1cffe4d35b6404dd59cd0f0a314e11944e37d0f2
parent49d09d4fd1b0cab8189cf1809a1b1241f54c2e48 (diff)
downloadcgit-e0c6f23789e4893781bcd5af2281d468991ccf3a.zip
cgit-e0c6f23789e4893781bcd5af2281d468991ccf3a.tar.gz
cgit-e0c6f23789e4893781bcd5af2281d468991ccf3a.tar.bz2
Add `strict-export` option
This option is used to specify a filename which needs to be present in the repositories found during `scan-path` processing. By setting this option to 'git-daemon-export-ok', only repositories explicitly marked for git daemon export will be included in the cgit configuration. Signed-off-by: Felix Hanley <felix@seconddrawer.com.au> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
-rw-r--r--cgit.h1
-rw-r--r--cgitrc.5.txt7
-rw-r--r--scan-tree.c4
4 files changed, 14 insertions, 0 deletions
diff --git a/cgit.c b/cgit.c
index 96900bb..412fbf0 100644
--- a/cgit.c
+++ b/cgit.c
@@ -92,64 +92,66 @@ void config_cb(const char *name, const char *value)
92 else if (ctx.repo && !strcmp(name, "repo.path")) 92 else if (ctx.repo && !strcmp(name, "repo.path"))
93 ctx.repo->path = trim_end(value, '/'); 93 ctx.repo->path = trim_end(value, '/');
94 else if (ctx.repo && !prefixcmp(name, "repo.")) 94 else if (ctx.repo && !prefixcmp(name, "repo."))
95 repo_config(ctx.repo, name + 5, value); 95 repo_config(ctx.repo, name + 5, value);
96 else if (!strcmp(name, "readme")) 96 else if (!strcmp(name, "readme"))
97 ctx.cfg.readme = xstrdup(value); 97 ctx.cfg.readme = xstrdup(value);
98 else if (!strcmp(name, "root-title")) 98 else if (!strcmp(name, "root-title"))
99 ctx.cfg.root_title = xstrdup(value); 99 ctx.cfg.root_title = xstrdup(value);
100 else if (!strcmp(name, "root-desc")) 100 else if (!strcmp(name, "root-desc"))
101 ctx.cfg.root_desc = xstrdup(value); 101 ctx.cfg.root_desc = xstrdup(value);
102 else if (!strcmp(name, "root-readme")) 102 else if (!strcmp(name, "root-readme"))
103 ctx.cfg.root_readme = xstrdup(value); 103 ctx.cfg.root_readme = xstrdup(value);
104 else if (!strcmp(name, "css")) 104 else if (!strcmp(name, "css"))
105 ctx.cfg.css = xstrdup(value); 105 ctx.cfg.css = xstrdup(value);
106 else if (!strcmp(name, "favicon")) 106 else if (!strcmp(name, "favicon"))
107 ctx.cfg.favicon = xstrdup(value); 107 ctx.cfg.favicon = xstrdup(value);
108 else if (!strcmp(name, "footer")) 108 else if (!strcmp(name, "footer"))
109 ctx.cfg.footer = xstrdup(value); 109 ctx.cfg.footer = xstrdup(value);
110 else if (!strcmp(name, "head-include")) 110 else if (!strcmp(name, "head-include"))
111 ctx.cfg.head_include = xstrdup(value); 111 ctx.cfg.head_include = xstrdup(value);
112 else if (!strcmp(name, "header")) 112 else if (!strcmp(name, "header"))
113 ctx.cfg.header = xstrdup(value); 113 ctx.cfg.header = xstrdup(value);
114 else if (!strcmp(name, "logo")) 114 else if (!strcmp(name, "logo"))
115 ctx.cfg.logo = xstrdup(value); 115 ctx.cfg.logo = xstrdup(value);
116 else if (!strcmp(name, "index-header")) 116 else if (!strcmp(name, "index-header"))
117 ctx.cfg.index_header = xstrdup(value); 117 ctx.cfg.index_header = xstrdup(value);
118 else if (!strcmp(name, "index-info")) 118 else if (!strcmp(name, "index-info"))
119 ctx.cfg.index_info = xstrdup(value); 119 ctx.cfg.index_info = xstrdup(value);
120 else if (!strcmp(name, "logo-link")) 120 else if (!strcmp(name, "logo-link"))
121 ctx.cfg.logo_link = xstrdup(value); 121 ctx.cfg.logo_link = xstrdup(value);
122 else if (!strcmp(name, "module-link")) 122 else if (!strcmp(name, "module-link"))
123 ctx.cfg.module_link = xstrdup(value); 123 ctx.cfg.module_link = xstrdup(value);
124 else if (!strcmp(name, "strict-export"))
125 ctx.cfg.strict_export = xstrdup(value);
124 else if (!strcmp(name, "virtual-root")) { 126 else if (!strcmp(name, "virtual-root")) {
125 ctx.cfg.virtual_root = trim_end(value, '/'); 127 ctx.cfg.virtual_root = trim_end(value, '/');
126 if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) 128 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
127 ctx.cfg.virtual_root = ""; 129 ctx.cfg.virtual_root = "";
128 } else if (!strcmp(name, "nocache")) 130 } else if (!strcmp(name, "nocache"))
129 ctx.cfg.nocache = atoi(value); 131 ctx.cfg.nocache = atoi(value);
130 else if (!strcmp(name, "noplainemail")) 132 else if (!strcmp(name, "noplainemail"))
131 ctx.cfg.noplainemail = atoi(value); 133 ctx.cfg.noplainemail = atoi(value);
132 else if (!strcmp(name, "noheader")) 134 else if (!strcmp(name, "noheader"))
133 ctx.cfg.noheader = atoi(value); 135 ctx.cfg.noheader = atoi(value);
134 else if (!strcmp(name, "snapshots")) 136 else if (!strcmp(name, "snapshots"))
135 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 137 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
136 else if (!strcmp(name, "enable-filter-overrides")) 138 else if (!strcmp(name, "enable-filter-overrides"))
137 ctx.cfg.enable_filter_overrides = atoi(value); 139 ctx.cfg.enable_filter_overrides = atoi(value);
138 else if (!strcmp(name, "enable-gitweb-owner")) 140 else if (!strcmp(name, "enable-gitweb-owner"))
139 ctx.cfg.enable_gitweb_owner = atoi(value); 141 ctx.cfg.enable_gitweb_owner = atoi(value);
140 else if (!strcmp(name, "enable-index-links")) 142 else if (!strcmp(name, "enable-index-links"))
141 ctx.cfg.enable_index_links = atoi(value); 143 ctx.cfg.enable_index_links = atoi(value);
142 else if (!strcmp(name, "enable-log-filecount")) 144 else if (!strcmp(name, "enable-log-filecount"))
143 ctx.cfg.enable_log_filecount = atoi(value); 145 ctx.cfg.enable_log_filecount = atoi(value);
144 else if (!strcmp(name, "enable-log-linecount")) 146 else if (!strcmp(name, "enable-log-linecount"))
145 ctx.cfg.enable_log_linecount = atoi(value); 147 ctx.cfg.enable_log_linecount = atoi(value);
146 else if (!strcmp(name, "enable-remote-branches")) 148 else if (!strcmp(name, "enable-remote-branches"))
147 ctx.cfg.enable_remote_branches = atoi(value); 149 ctx.cfg.enable_remote_branches = atoi(value);
148 else if (!strcmp(name, "enable-subject-links")) 150 else if (!strcmp(name, "enable-subject-links"))
149 ctx.cfg.enable_subject_links = atoi(value); 151 ctx.cfg.enable_subject_links = atoi(value);
150 else if (!strcmp(name, "enable-tree-linenumbers")) 152 else if (!strcmp(name, "enable-tree-linenumbers"))
151 ctx.cfg.enable_tree_linenumbers = atoi(value); 153 ctx.cfg.enable_tree_linenumbers = atoi(value);
152 else if (!strcmp(name, "max-stats")) 154 else if (!strcmp(name, "max-stats"))
153 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); 155 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
154 else if (!strcmp(name, "cache-size")) 156 else if (!strcmp(name, "cache-size"))
155 ctx.cfg.cache_size = atoi(value); 157 ctx.cfg.cache_size = atoi(value);
diff --git a/cgit.h b/cgit.h
index 8f5dd2a..a9896cf 100644
--- a/cgit.h
+++ b/cgit.h
@@ -147,64 +147,65 @@ struct cgit_query {
147 char *sort; 147 char *sort;
148 int showmsg; 148 int showmsg;
149 int ssdiff; 149 int ssdiff;
150 int show_all; 150 int show_all;
151 int context; 151 int context;
152 int ignorews; 152 int ignorews;
153 char *vpath; 153 char *vpath;
154}; 154};
155 155
156struct cgit_config { 156struct cgit_config {
157 char *agefile; 157 char *agefile;
158 char *cache_root; 158 char *cache_root;
159 char *clone_prefix; 159 char *clone_prefix;
160 char *css; 160 char *css;
161 char *favicon; 161 char *favicon;
162 char *footer; 162 char *footer;
163 char *head_include; 163 char *head_include;
164 char *header; 164 char *header;
165 char *index_header; 165 char *index_header;
166 char *index_info; 166 char *index_info;
167 char *logo; 167 char *logo;
168 char *logo_link; 168 char *logo_link;
169 char *module_link; 169 char *module_link;
170 char *project_list; 170 char *project_list;
171 char *readme; 171 char *readme;
172 char *robots; 172 char *robots;
173 char *root_title; 173 char *root_title;
174 char *root_desc; 174 char *root_desc;
175 char *root_readme; 175 char *root_readme;
176 char *script_name; 176 char *script_name;
177 char *section; 177 char *section;
178 char *virtual_root; 178 char *virtual_root;
179 char *strict_export;
179 int cache_size; 180 int cache_size;
180 int cache_dynamic_ttl; 181 int cache_dynamic_ttl;
181 int cache_max_create_time; 182 int cache_max_create_time;
182 int cache_repo_ttl; 183 int cache_repo_ttl;
183 int cache_root_ttl; 184 int cache_root_ttl;
184 int cache_scanrc_ttl; 185 int cache_scanrc_ttl;
185 int cache_static_ttl; 186 int cache_static_ttl;
186 int embedded; 187 int embedded;
187 int enable_filter_overrides; 188 int enable_filter_overrides;
188 int enable_gitweb_owner; 189 int enable_gitweb_owner;
189 int enable_index_links; 190 int enable_index_links;
190 int enable_log_filecount; 191 int enable_log_filecount;
191 int enable_log_linecount; 192 int enable_log_linecount;
192 int enable_remote_branches; 193 int enable_remote_branches;
193 int enable_subject_links; 194 int enable_subject_links;
194 int enable_tree_linenumbers; 195 int enable_tree_linenumbers;
195 int local_time; 196 int local_time;
196 int max_atom_items; 197 int max_atom_items;
197 int max_repo_count; 198 int max_repo_count;
198 int max_commit_count; 199 int max_commit_count;
199 int max_lock_attempts; 200 int max_lock_attempts;
200 int max_msg_len; 201 int max_msg_len;
201 int max_repodesc_len; 202 int max_repodesc_len;
202 int max_blob_size; 203 int max_blob_size;
203 int max_stats; 204 int max_stats;
204 int nocache; 205 int nocache;
205 int noplainemail; 206 int noplainemail;
206 int noheader; 207 int noheader;
207 int renamelimit; 208 int renamelimit;
208 int remove_suffix; 209 int remove_suffix;
209 int section_from_path; 210 int section_from_path;
210 int snapshots; 211 int snapshots;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index ce78d41..75b6584 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -288,64 +288,71 @@ section-from-path::
288 If negative, cgit will discard the specified number of path elements 288 If negative, cgit will discard the specified number of path elements
289 above the repo directory. Default value: 0. 289 above the repo directory. Default value: 0.
290 290
291side-by-side-diffs:: 291side-by-side-diffs::
292 If set to "1" shows side-by-side diffs instead of unidiffs per 292 If set to "1" shows side-by-side diffs instead of unidiffs per
293 default. Default value: "0". 293 default. Default value: "0".
294 294
295snapshots:: 295snapshots::
296 Text which specifies the default set of snapshot formats generated by 296 Text which specifies the default set of snapshot formats generated by
297 cgit. The value is a space-separated list of zero or more of the 297 cgit. The value is a space-separated list of zero or more of the
298 values "tar", "tar.gz", "tar.bz2" and "zip". Default value: none. 298 values "tar", "tar.gz", "tar.bz2" and "zip". Default value: none.
299 299
300source-filter:: 300source-filter::
301 Specifies a command which will be invoked to format plaintext blobs 301 Specifies a command which will be invoked to format plaintext blobs
302 in the tree view. The command will get the blob content on its STDIN 302 in the tree view. The command will get the blob content on its STDIN
303 and the name of the blob as its only command line argument. The STDOUT 303 and the name of the blob as its only command line argument. The STDOUT
304 from the command will be included verbatim as the blob contents, i.e. 304 from the command will be included verbatim as the blob contents, i.e.
305 this can be used to implement e.g. syntax highlighting. Default value: 305 this can be used to implement e.g. syntax highlighting. Default value:
306 none. 306 none.
307 307
308summary-branches:: 308summary-branches::
309 Specifies the number of branches to display in the repository "summary" 309 Specifies the number of branches to display in the repository "summary"
310 view. Default value: "10". 310 view. Default value: "10".
311 311
312summary-log:: 312summary-log::
313 Specifies the number of log entries to display in the repository 313 Specifies the number of log entries to display in the repository
314 "summary" view. Default value: "10". 314 "summary" view. Default value: "10".
315 315
316summary-tags:: 316summary-tags::
317 Specifies the number of tags to display in the repository "summary" 317 Specifies the number of tags to display in the repository "summary"
318 view. Default value: "10". 318 view. Default value: "10".
319 319
320strict-export::
321 Filename which, if specified, needs to be present within the repository
322 for cgit to allow access to that repository. This can be used to emulate
323 gitweb's EXPORT_OK and STRICT_EXPORT functionality and limit cgit's
324 repositories to match those exported by git-daemon. This option MUST come
325 before 'scan-path'.
326
320virtual-root:: 327virtual-root::
321 Url which, if specified, will be used as root for all cgit links. It 328 Url which, if specified, will be used as root for all cgit links. It
322 will also cause cgit to generate 'virtual urls', i.e. urls like 329 will also cause cgit to generate 'virtual urls', i.e. urls like
323 '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default 330 '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default
324 value: none. 331 value: none.
325 NOTE: cgit has recently learned how to use PATH_INFO to achieve the 332 NOTE: cgit has recently learned how to use PATH_INFO to achieve the
326 same kind of virtual urls, so this option will probably be deprecated. 333 same kind of virtual urls, so this option will probably be deprecated.
327 334
328REPOSITORY SETTINGS 335REPOSITORY SETTINGS
329------------------- 336-------------------
330repo.about-filter:: 337repo.about-filter::
331 Override the default about-filter. Default value: none. See also: 338 Override the default about-filter. Default value: none. See also:
332 "enable-filter-overrides". 339 "enable-filter-overrides".
333 340
334repo.clone-url:: 341repo.clone-url::
335 A list of space-separated urls which can be used to clone this repo. 342 A list of space-separated urls which can be used to clone this repo.
336 Default value: none. 343 Default value: none.
337 344
338repo.commit-filter:: 345repo.commit-filter::
339 Override the default commit-filter. Default value: none. See also: 346 Override the default commit-filter. Default value: none. See also:
340 "enable-filter-overrides". 347 "enable-filter-overrides".
341 348
342repo.defbranch:: 349repo.defbranch::
343 The name of the default branch for this repository. If no such branch 350 The name of the default branch for this repository. If no such branch
344 exists in the repository, the first branch name (when sorted) is used 351 exists in the repository, the first branch name (when sorted) is used
345 as default instead. Default value: "master". 352 as default instead. Default value: "master".
346 353
347repo.desc:: 354repo.desc::
348 The value to show as repository description. Default value: none. 355 The value to show as repository description. Default value: none.
349 356
350repo.enable-log-filecount:: 357repo.enable-log-filecount::
351 A flag which can be used to disable the global setting 358 A flag which can be used to disable the global setting
diff --git a/scan-tree.c b/scan-tree.c
index b5b50f3..a0e09ce 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -52,64 +52,68 @@ char *owner;
52static void repo_config(const char *name, const char *value) 52static void repo_config(const char *name, const char *value)
53{ 53{
54 config_fn(repo, name, value); 54 config_fn(repo, name, value);
55} 55}
56 56
57static int git_owner_config(const char *key, const char *value, void *cb) 57static int git_owner_config(const char *key, const char *value, void *cb)
58{ 58{
59 if (!strcmp(key, "gitweb.owner")) 59 if (!strcmp(key, "gitweb.owner"))
60 owner = xstrdup(value); 60 owner = xstrdup(value);
61 return 0; 61 return 0;
62} 62}
63 63
64static char *xstrrchr(char *s, char *from, int c) 64static char *xstrrchr(char *s, char *from, int c)
65{ 65{
66 while (from >= s && *from != c) 66 while (from >= s && *from != c)
67 from--; 67 from--;
68 return from < s ? NULL : from; 68 return from < s ? NULL : from;
69} 69}
70 70
71static void add_repo(const char *base, const char *path, repo_config_fn fn) 71static void add_repo(const char *base, const char *path, repo_config_fn fn)
72{ 72{
73 struct stat st; 73 struct stat st;
74 struct passwd *pwd; 74 struct passwd *pwd;
75 char *rel, *p, *slash; 75 char *rel, *p, *slash;
76 int n; 76 int n;
77 size_t size; 77 size_t size;
78 78
79 if (stat(path, &st)) { 79 if (stat(path, &st)) {
80 fprintf(stderr, "Error accessing %s: %s (%d)\n", 80 fprintf(stderr, "Error accessing %s: %s (%d)\n",
81 path, strerror(errno), errno); 81 path, strerror(errno), errno);
82 return; 82 return;
83 } 83 }
84
85 if (ctx.cfg.strict_export && stat(fmt("%s/%s", path, ctx.cfg.strict_export), &st))
86 return;
87
84 if (!stat(fmt("%s/noweb", path), &st)) 88 if (!stat(fmt("%s/noweb", path), &st))
85 return; 89 return;
86 90
87 owner = NULL; 91 owner = NULL;
88 if (ctx.cfg.enable_gitweb_owner) 92 if (ctx.cfg.enable_gitweb_owner)
89 git_config_from_file(git_owner_config, fmt("%s/config", path), NULL); 93 git_config_from_file(git_owner_config, fmt("%s/config", path), NULL);
90 if (base == path) 94 if (base == path)
91 rel = xstrdup(fmt("%s", path)); 95 rel = xstrdup(fmt("%s", path));
92 else 96 else
93 rel = xstrdup(fmt("%s", path + strlen(base) + 1)); 97 rel = xstrdup(fmt("%s", path + strlen(base) + 1));
94 98
95 if (!strcmp(rel + strlen(rel) - 5, "/.git")) 99 if (!strcmp(rel + strlen(rel) - 5, "/.git"))
96 rel[strlen(rel) - 5] = '\0'; 100 rel[strlen(rel) - 5] = '\0';
97 101
98 repo = cgit_add_repo(rel); 102 repo = cgit_add_repo(rel);
99 if (ctx.cfg.remove_suffix) 103 if (ctx.cfg.remove_suffix)
100 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) 104 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
101 *p = '\0'; 105 *p = '\0';
102 repo->name = repo->url; 106 repo->name = repo->url;
103 repo->path = xstrdup(path); 107 repo->path = xstrdup(path);
104 while (!owner) { 108 while (!owner) {
105 if ((pwd = getpwuid(st.st_uid)) == NULL) { 109 if ((pwd = getpwuid(st.st_uid)) == NULL) {
106 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", 110 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
107 path, strerror(errno), errno); 111 path, strerror(errno), errno);
108 break; 112 break;
109 } 113 }
110 if (pwd->pw_gecos) 114 if (pwd->pw_gecos)
111 if ((p = strchr(pwd->pw_gecos, ','))) 115 if ((p = strchr(pwd->pw_gecos, ',')))
112 *p = '\0'; 116 *p = '\0';
113 owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); 117 owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
114 } 118 }
115 repo->owner = owner; 119 repo->owner = owner;