summaryrefslogtreecommitdiff
path: root/tools/server-side/svnauthz.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/server-side/svnauthz.c')
-rw-r--r--tools/server-side/svnauthz.c109
1 files changed, 73 insertions, 36 deletions
diff --git a/tools/server-side/svnauthz.c b/tools/server-side/svnauthz.c
index fc6cd89..310757c 100644
--- a/tools/server-side/svnauthz.c
+++ b/tools/server-side/svnauthz.c
@@ -31,6 +31,7 @@
#include "private/svn_fspath.h"
#include "private/svn_cmdline_private.h"
+#include "svn_private_config.h"
/*** Option Processing. ***/
@@ -99,6 +100,9 @@ struct svnauthz_opt_state
/* Libtool command prefix */
#define SVNAUTHZ_LT_PREFIX "lt-"
+/* The prefix for handling errors and warnings. */
+#define SVNAUTHZ_ERR_PREFIX "svnauthz: "
+
/*** Subcommands. */
@@ -110,29 +114,34 @@ static svn_opt_subcommand_t
/* Array of available subcommands.
* The entire list must be terminated with an entry of nulls.
*/
-static const svn_opt_subcommand_desc2_t cmd_table[] =
+static const svn_opt_subcommand_desc3_t cmd_table[] =
{
- {"help", subcommand_help, {"?", "h"},
- ("usage: svnauthz help [SUBCOMMAND...]\n\n"
- "Describe the usage of this program or its subcommands.\n"),
+ {"help", subcommand_help, {"?", "h"}, {(
+ "usage: svnauthz help [SUBCOMMAND...]\n"
+ "\n"
+ "Describe the usage of this program or its subcommands.\n"
+ )},
{0} },
- {"validate", subcommand_validate, {0} /* no aliases */,
- ("Checks the syntax of an authz file.\n"
+ {"validate", subcommand_validate, {0} /* no aliases */, {(
+ "Checks the syntax of an authz file.\n"
"usage: 1. svnauthz validate TARGET\n"
- " 2. svnauthz validate --transaction TXN REPOS_PATH FILE_PATH\n\n"
+ " 2. svnauthz validate --transaction TXN REPOS_PATH FILE_PATH\n"
+ "\n"
" 1. Loads and validates the syntax of the authz file at TARGET.\n"
" TARGET can be a path to a file or an absolute file:// URL to an authz\n"
- " file in a repository, but cannot be a repository relative URL (^/).\n\n"
+ " file in a repository, but cannot be a repository relative URL (^/).\n"
+ "\n"
" 2. Loads and validates the syntax of the authz file at FILE_PATH in the\n"
- " transaction TXN in the repository at REPOS_PATH.\n\n"
+ " transaction TXN in the repository at REPOS_PATH.\n"
+ "\n"
"Returns:\n"
" 0 when syntax is OK.\n"
" 1 when syntax is invalid.\n"
" 2 operational error\n"
- ),
+ )},
{'t'} },
- {"accessof", subcommand_accessof, {0} /* no aliases */,
- ("Print or test the permissions set by an authz file.\n"
+ {"accessof", subcommand_accessof, {0} /* no aliases */, {(
+ "Print or test the permissions set by an authz file.\n"
"usage: 1. svnauthz accessof TARGET\n"
" 2. svnauthz accessof -t TXN REPOS_PATH FILE_PATH\n"
"\n"
@@ -159,10 +168,10 @@ static const svn_opt_subcommand_desc2_t cmd_table[] =
" 1 when syntax is invalid.\n"
" 2 operational error\n"
" 3 when '--is' argument doesn't match\n"
- ),
+ )},
{'t', svnauthz__username, svnauthz__path, svnauthz__repos, svnauthz__is,
svnauthz__groups_file, 'R'} },
- { NULL, NULL, {0}, NULL, {0} }
+ { NULL, NULL, {0}, {NULL}, {0} }
};
static svn_error_t *
@@ -171,11 +180,14 @@ subcommand_help(apr_getopt_t *os, void *baton, apr_pool_t *pool)
struct svnauthz_opt_state *opt_state = baton;
const char *header =
("general usage: svnauthz SUBCOMMAND TARGET [ARGS & OPTIONS ...]\n"
- " " SVNAUTHZ_COMPAT_NAME " TARGET\n\n"
+ " " SVNAUTHZ_COMPAT_NAME " TARGET\n"
+ "\n"
"If the command name starts with '" SVNAUTHZ_COMPAT_NAME "', runs in\n"
- "pre-1.8 compatibility mode: run the 'validate' subcommand on TARGET.\n\n"
+ "pre-1.8 compatibility mode: run the 'validate' subcommand on TARGET.\n"
+ "\n"
"Type 'svnauthz help <subcommand>' for help on a specific subcommand.\n"
- "Type 'svnauthz --version' to see the program version.\n\n"
+ "Type 'svnauthz --version' to see the program version.\n"
+ "\n"
"Available subcommands:\n");
const char *fs_desc_start
@@ -186,7 +198,7 @@ subcommand_help(apr_getopt_t *os, void *baton, apr_pool_t *pool)
version_footer = svn_stringbuf_create(fs_desc_start, pool);
SVN_ERR(svn_fs_print_modules(version_footer, pool));
- SVN_ERR(svn_opt_print_help4(os, "svnauthz",
+ SVN_ERR(svn_opt_print_help5(os, "svnauthz",
opt_state ? opt_state->version : FALSE,
FALSE, /* quiet */
FALSE, /* verbose */
@@ -216,6 +228,18 @@ read_file_contents(svn_stream_t **contents, const char *filename,
return SVN_NO_ERROR;
}
+/* Handles warning emitted by the authz parser. */
+static void
+handle_parser_warning(void *baton,
+ const svn_error_t *err,
+ apr_pool_t *scratch_pool)
+{
+ svn_handle_warning2(stderr, err, SVNAUTHZ_ERR_PREFIX);
+ SVN_UNUSED(baton);
+ SVN_UNUSED(scratch_pool);
+}
+
+
/* Loads the authz config into *AUTHZ from the file at AUTHZ_FILE
in repository at REPOS_PATH from the transaction TXN_NAME. If GROUPS_FILE
is set, the resulting *AUTHZ will be constructed from AUTHZ_FILE with
@@ -248,7 +272,8 @@ get_authz_from_txn(svn_authz_t **authz, const char *repos_path,
else
groups_contents = NULL;
- err = svn_repos_authz_parse(authz, authz_contents, groups_contents, pool);
+ err = svn_repos_authz_parse2(authz, authz_contents, groups_contents,
+ handle_parser_warning, NULL, pool, pool);
/* Add the filename to the error stack since the parser doesn't have it. */
if (err != SVN_NO_ERROR)
@@ -275,9 +300,11 @@ get_authz(svn_authz_t **authz, struct svnauthz_opt_state *opt_state,
opt_state->txn, pool);
/* Else */
- return svn_repos_authz_read3(authz, opt_state->authz_file,
+ return svn_repos_authz_read4(authz, opt_state->authz_file,
opt_state->groups_file,
- TRUE, NULL, pool, pool);
+ TRUE, NULL,
+ handle_parser_warning, NULL,
+ pool, pool);
}
static svn_error_t *
@@ -387,7 +414,12 @@ subcommand_accessof(apr_getopt_t *os, void *baton, apr_pool_t *pool)
static svn_boolean_t
use_compat_mode(const char *cmd, apr_pool_t *pool)
{
- cmd = svn_dirent_internal_style(cmd, pool);
+ svn_error_t *err = svn_dirent_internal_style_safe(&cmd, NULL, cmd, pool, pool);
+ if (err)
+ {
+ svn_error_clear(err);
+ return FALSE;
+ }
cmd = svn_dirent_basename(cmd, NULL);
/* Skip over the Libtool command prefix if it exists on the command. */
@@ -429,7 +461,9 @@ canonicalize_access_file(const char **canonicalized_access_file,
access_file);
}
- *canonicalized_access_file = svn_uri_canonicalize(access_file, pool);
+ SVN_ERR(svn_uri_canonicalize_safe(
+ canonicalized_access_file, NULL,
+ access_file, pool, pool));
}
else if (within_txn)
{
@@ -442,8 +476,9 @@ canonicalize_access_file(const char **canonicalized_access_file,
{
/* If it isn't a URL and there's no transaction flag then it's a
* dirent to the access file on local disk. */
- *canonicalized_access_file =
- svn_dirent_internal_style(access_file, pool);
+ SVN_ERR(svn_dirent_internal_style_safe(
+ canonicalized_access_file, NULL,
+ access_file, pool, pool));
}
return SVN_NO_ERROR;
@@ -459,7 +494,7 @@ sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
{
svn_error_t *err;
- const svn_opt_subcommand_desc2_t *subcommand = NULL;
+ const svn_opt_subcommand_desc3_t *subcommand = NULL;
struct svnauthz_opt_state opt_state = { 0 };
apr_getopt_t *os;
apr_array_header_t *received_opts;
@@ -545,9 +580,9 @@ sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
{
/* Pre 1.8 compatibility mode. */
if (argc == 1) /* No path argument */
- subcommand = svn_opt_get_canonical_subcommand2(cmd_table, "help");
+ subcommand = svn_opt_get_canonical_subcommand3(cmd_table, "help");
else
- subcommand = svn_opt_get_canonical_subcommand2(cmd_table, "validate");
+ subcommand = svn_opt_get_canonical_subcommand3(cmd_table, "validate");
}
/* If the user asked for help, then the rest of the arguments are
@@ -555,7 +590,7 @@ sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
just typos/mistakes. Whatever the case, the subcommand to
actually run is subcommand_help(). */
if (opt_state.help)
- subcommand = svn_opt_get_canonical_subcommand2(cmd_table, "help");
+ subcommand = svn_opt_get_canonical_subcommand3(cmd_table, "help");
if (subcommand == NULL)
{
@@ -564,8 +599,8 @@ sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
if (opt_state.version)
{
/* Use the "help" subcommand to handle the "--version" option. */
- static const svn_opt_subcommand_desc2_t pseudo_cmd =
- { "--version", subcommand_help, {0}, "",
+ static const svn_opt_subcommand_desc3_t pseudo_cmd =
+ { "--version", subcommand_help, {0}, {""},
{svnauthz__version /* must accept its own option */ } };
subcommand = &pseudo_cmd;
@@ -585,7 +620,7 @@ sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
SVN_ERR(svn_utf_cstring_to_utf8(&first_arg, os->argv[os->ind++],
pool));
- subcommand = svn_opt_get_canonical_subcommand2(cmd_table, first_arg);
+ subcommand = svn_opt_get_canonical_subcommand3(cmd_table, first_arg);
if (subcommand == NULL)
{
os->ind++;
@@ -618,7 +653,9 @@ sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
pool));
os->ind++;
- opt_state.repos_path = svn_dirent_internal_style(opt_state.repos_path, pool);
+ SVN_ERR(svn_dirent_internal_style_safe(&opt_state.repos_path, NULL,
+ opt_state.repos_path,
+ pool, pool));
}
/* Exactly 1 non-option argument */
@@ -658,11 +695,11 @@ sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
if (opt_id == 'h' || opt_id == '?')
continue;
- if (! svn_opt_subcommand_takes_option3(subcommand, opt_id, NULL))
+ if (! svn_opt_subcommand_takes_option4(subcommand, opt_id, NULL))
{
const char *optstr;
const apr_getopt_option_t *badopt =
- svn_opt_get_option_from_code2(opt_id, options_table, subcommand,
+ svn_opt_get_option_from_code3(opt_id, options_table, subcommand,
pool);
svn_opt_format_option(&optstr, badopt, FALSE, pool);
if (subcommand->name[0] == '-')
@@ -737,7 +774,7 @@ main(int argc, const char *argv[])
{
if (exit_code == 0)
exit_code = EXIT_FAILURE;
- svn_cmdline_handle_exit_error(err, NULL, "svnauthz: ");
+ svn_cmdline_handle_exit_error(err, NULL, SVNAUTHZ_ERR_PREFIX);
}
svn_pool_destroy(pool);