aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2014-03-10 11:21:07 +0200
committerSergey Poznyakoff <gray@gnu.org>2014-03-10 11:21:07 +0200
commit782c3262b1f479e33ae1b6423fc633616b83a925 (patch)
tree6213a31386e690cd973749d664889156eefce6df
parentd4ed5e15b15b2f5038a0c5c9ed7c4dd412806011 (diff)
downloadvcsync-782c3262b1f479e33ae1b6423fc633616b83a925.tar.gz
vcsync-782c3262b1f479e33ae1b6423fc633616b83a925.tar.bz2
Make access file creation more configurable
* doc/vcsync.conf.5: Update. * src/checkoutrc.c (access_file_name) (access_file_text): New globals. (open_htaccess): Write access_file_text to the newly created file. (write_htaccess,kwf_unlink): Use access_file_name instead of the hardcoded HTACCESS_FILE. (checkoutrc): Likewise. Initialize access_file_name, if it is not defined. * src/config.c: New statements access-file-name and access-file-text * src/vcsync.h (access_file_name,access_file_text): New externs. * tests/checkoutrc.at: Test access-file-text.
-rw-r--r--doc/vcsync.conf.59
-rw-r--r--src/checkoutrc.c22
-rw-r--r--src/config.c8
-rw-r--r--src/vcsync.h2
-rw-r--r--tests/checkoutrc.at9
5 files changed, 42 insertions, 8 deletions
diff --git a/doc/vcsync.conf.5 b/doc/vcsync.conf.5
index 3fe893c..aa986af 100644
--- a/doc/vcsync.conf.5
+++ b/doc/vcsync.conf.5
@@ -13,7 +13,7 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with Vcsync. If not, see <http://www.gnu.org/licenses/>.
-.TH VCSYNC.CONF 5 "March 7, 2014" "VCSYNC.CONF"
+.TH VCSYNC.CONF 5 "March 10, 2014" "VCSYNC.CONF"
.SH NAME
vcsync.conf \- configuration file for vcsync
.SH DESCRIPTION
@@ -287,6 +287,13 @@ as follows:
vcsync --name alt [\fIother arguments\fR]
.EE
.RE
+.SS Access file
+.TP
+\fBaccess\-file\-name\fR \fIname\fB;\fR
+Create files \fIname\fR, instead of the default \fB.htaccess\fR.
+.TP
+\fBaccess\-file\-text\fR \fItext\fB;\fR
+Add \fItext\fR to the beginning of each created access file.
.SS Checkoutrc keywords
The syntax of \fB.checkoutrc\fR files can be expanded with new keywords,
if the need be. There are two kinds of keywords: \fBverbatim\fR
diff --git a/src/checkoutrc.c b/src/checkoutrc.c
index 38046c4..b7af261 100644
--- a/src/checkoutrc.c
+++ b/src/checkoutrc.c
@@ -24,6 +24,9 @@
#define CHECKOUTRC_NAME ".checkoutrc"
#define HTACCESS_FILE ".htaccess"
+char *access_file_name;
+char *access_file_text;
+
#define KW_HANDLER 0
#define KW_VERBATIM 1
#define KW_TEXT 2
@@ -47,14 +50,18 @@ struct keyword {
} v;
};
+static int write_htaccess(struct stmt_env *env, const char *fmt, ...);
+
static FILE *
open_htaccess(struct stmt_env *env)
{
if (!env->fp) {
- env->fp = fopen(HTACCESS_FILE, "w");
+ env->fp = fopen(access_file_name, "w");
if (!env->fp)
diag(LOG_ERR, "cannot open file %s/%s: %s",
- env->dirname, HTACCESS_FILE, strerror(errno));
+ env->dirname, access_file_name, strerror(errno));
+ if (access_file_text)
+ write_htaccess(env, "%s", access_file_text);
}
return env->fp;
}
@@ -72,7 +79,7 @@ write_htaccess(struct stmt_env *env, const char *fmt, ...)
va_list aq;
va_copy(aq, ap);
diag(LOG_DEBUG, "%s:%u: write to %s/%s",
- env->filename, env->line, env->dirname, HTACCESS_FILE);
+ env->filename, env->line, env->dirname, access_file_name);
vdiag(LOG_DEBUG, fmt, aq);
va_end(aq);
}
@@ -173,8 +180,8 @@ kwf_unlink(struct stmt_env *env)
return 1;
}
if (!S_ISLNK(st.st_mode) &&
- strcmp(filename + strlen(filename) - sizeof(HTACCESS_FILE) + 1,
- HTACCESS_FILE)) {
+ strcmp(filename + strlen(filename) - strlen(access_file_name),
+ access_file_name)) {
diag(LOG_ERR, "won't unlink %s", filename);
return 1;
}
@@ -393,6 +400,9 @@ checkoutrc(const char *root_dir, const char *dir)
int err = 0;
FILE *fp;
int i;
+
+ if (!access_file_name)
+ access_file_name = estrdup(HTACCESS_FILE);
memset(&env, 0, sizeof env);
env.buf = buf;
@@ -403,7 +413,7 @@ checkoutrc(const char *root_dir, const char *dir)
if (root_dir)
a[i++] = root_dir;
a[i++] = dir;
- a[i++] = HTACCESS_FILE;
+ a[i++] = access_file_name;
a[i++] = NULL;
env.filename = pathcat(a);
diff --git a/src/config.c b/src/config.c
index 62bf189..559354c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -343,6 +343,14 @@ static struct grecs_keyword vcsync_kw[] = {
"Define checkoutrc keyword",
grecs_type_string, GRECS_DFLT,
NULL, 0, cb_define },
+
+ { "access-file-name", "name", "Name of the access file",
+ grecs_type_string, GRECS_DFLT,
+ &access_file_name },
+ { "access-file-text", "text",
+ "Static text to add to each created access file",
+ grecs_type_string, GRECS_DFLT,
+ &access_file_text },
{ "syslog", NULL, "Configure syslog logging",
grecs_type_section, GRECS_DFLT, NULL, 0, NULL, NULL, syslog_kw },
diff --git a/src/vcsync.h b/src/vcsync.h
index 48cd9a9..2cf2c26 100644
--- a/src/vcsync.h
+++ b/src/vcsync.h
@@ -65,6 +65,8 @@ extern char *config_name;
extern int cfg_facility;
extern int cfg_print_priority;
extern char *cfg_tag;
+extern char *access_file_name;
+extern char *access_file_text;
void config_help(void);
void config_init(void);
diff --git a/tests/checkoutrc.at b/tests/checkoutrc.at
index 4750410..5c062fb 100644
--- a/tests/checkoutrc.at
+++ b/tests/checkoutrc.at
@@ -38,7 +38,13 @@ EOT
cd ../..
set -e
-vcsync -e -c $DFL_VCSYNC_CONF -w $cwd/home -D test -d 2>err
+cat $DFL_VCSYNC_CONF - > vcsync.conf <<EOT
+access-file-text <<__EOT__
+# HTTPD access file created by vcsync
+__EOT__;
+EOT
+
+vcsync -e -c ./vcsync.conf -w $cwd/home -D test -d 2>err
sed "s|$cwd/||" err >&2
test -x home/test/x && echo "x OK"
@@ -54,6 +60,7 @@ cat home/test/.htaccess
b OK
file a
# .htaccess
+# HTTPD access file created by vcsync
Options +IncludesNOEXEC
XBitHack On
redirect permanent /manual http://example.net

Return to:

Send suggestions and report system problems to the System administrator.