You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by da...@apache.org on 2012/09/05 13:20:36 UTC
svn commit: r1381147 -
/subversion/trunk/tools/server-side/svnauthz-validate.c
Author: danielsh
Date: Wed Sep 5 11:20:35 2012
New Revision: 1381147
URL: http://svn.apache.org/viewvc?rev=1381147&view=rev
Log:
svnauthz-validate: change the UI of the "print USER's access" mode. The change
adds mandatory --repository/--path option to make it clear which argument is what,
especially in light of r1380694 which made the output less verbose.
Discussed with: philip
* tools/server-side/svnauthz-validate.c
(svn_opt.h): Include.
(OPT_USERNAME, OPT_PATH, OPT_REPOS): New enumerators.
(usage): Update the synopsis, tweak the prose.
(main): Add and use apr_getopt_t.
Modified:
subversion/trunk/tools/server-side/svnauthz-validate.c
Modified: subversion/trunk/tools/server-side/svnauthz-validate.c
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/server-side/svnauthz-validate.c?rev=1381147&r1=1381146&r2=1381147&view=diff
==============================================================================
--- subversion/trunk/tools/server-side/svnauthz-validate.c (original)
+++ subversion/trunk/tools/server-side/svnauthz-validate.c Wed Sep 5 11:20:35 2012
@@ -30,17 +30,25 @@
#include "svn_cmdline.h"
#include "svn_dirent_uri.h"
+#include "svn_opt.h"
#include "svn_pools.h"
#include "svn_repos.h"
#include "svn_utf.h"
+enum {
+ OPT_USERNAME = SVN_OPT_FIRST_LONGOPT_ID,
+ OPT_PATH,
+ OPT_REPOS
+};
+
static int
usage(const char *argv0)
{
- printf("Usage: %s FILE [USER PATH [REPOS_NAME]]\n\n", argv0);
+ printf("Usage: %s FILE [--username USER [--path FSPATH] [--repository REPOS_NAME]]\n\n", argv0);
printf("Loads the authz file at FILE and validates its syntax.\n"
"Optionally prints the access available to USER for PATH in\n"
- "repository REPOS_NAME.\n"
+ "repository with authz name REPOS_NAME. If PATH is omitted, reports\n"
+ "whether USER has any access at all.\n"
"Returns:\n"
" 0 when syntax is OK.\n"
" 1 when syntax is invalid.\n"
@@ -53,11 +61,23 @@ main(int argc, const char **argv)
{
apr_pool_t *pool;
svn_error_t *err;
+ apr_status_t apr_err;
svn_authz_t *authz;
- const char *authz_file;
-
- if (argc != 2 && argc != 4 && argc != 5)
- return usage(argv[0]);
+ apr_getopt_t *os;
+ const apr_getopt_option_t options[] =
+ {
+ {"username", OPT_USERNAME, 1, ("the authenticated username")},
+ {"path", OPT_PATH, 1, ("path within the repository")},
+ {"repository", OPT_REPOS, 1, ("repository authz name")},
+ {0, 0, 0, 0}
+ };
+ struct {
+ const char *authz_file;
+ const char *username;
+ const char *fspath;
+ const char *repos_name;
+ } opts;
+ opts.username = opts.fspath = opts.repos_name = NULL;
/* Initialize the app. Send all error messages to 'stderr'. */
if (svn_cmdline_init(argv[0], stderr) != EXIT_SUCCESS)
@@ -65,21 +85,69 @@ main(int argc, const char **argv)
pool = svn_pool_create(NULL);
+ /* Repeat svn_cmdline__getopt_init() inline. */
+ apr_err = apr_getopt_init(&os, pool, argc, argv);
+ if (apr_err)
+ return svn_cmdline_handle_exit_error(
+ svn_error_wrap_apr(apr_err,
+ ("Error initializing command line arguments")),
+ pool, "svn-rep-sharing-stats: ");
+
+ os->interleave = 1;
+ while (1)
+ {
+ int opt;
+ const char *arg;
+ apr_status_t status = apr_getopt_long(os, options, &opt, &arg);
+ if (APR_STATUS_IS_EOF(status))
+ break;
+ if (status != APR_SUCCESS)
+ {
+ return usage(argv[0]);
+ }
+ switch (opt)
+ {
+ case OPT_USERNAME:
+ /* ### TODO: UTF-8? */
+ opts.username = arg;
+ break;
+ case OPT_PATH:
+ /* ### TODO: UTF-8? */
+ opts.fspath = arg;
+ break;
+ case OPT_REPOS:
+ opts.repos_name = arg;
+ break;
+ default:
+ return usage(argv[0]);
+ }
+ }
+
+ /* Exactly 1 non-option argument, and no --repository/--path
+ unless --username. */
+ if (os->ind + 1 != argc || (!opts.username && (opts.fspath || opts.repos_name)))
+ {
+ return usage(argv[0]);
+ }
+
/* Grab AUTHZ_FILE from argv. */
- SVN_INT_ERR(svn_utf_cstring_to_utf8(&authz_file, argv[1], pool));
- authz_file = svn_dirent_internal_style(authz_file, pool);
+ SVN_INT_ERR(svn_utf_cstring_to_utf8(&opts.authz_file, os->argv[os->ind],
+ pool));
+ opts.authz_file = svn_dirent_internal_style(opts.authz_file, pool);
/* Read the access file and validate it. */
- err = svn_repos_authz_read(&authz, authz_file, TRUE, pool);
+ err = svn_repos_authz_read(&authz, opts.authz_file, TRUE, pool);
- if (!err && (argc == 4 || argc == 5))
+ /* Optionally, print the access a USER has to a given PATH in REPOS.
+ PATH and REPOS may be NULL. */
+ if (!err && opts.username)
{
- const char *user = argv[2];
- const char *path = argv[3];
- const char *repos = (argc == 5 ? argv[4] : "");
+ const char *user = opts.username;
+ const char *path = opts.fspath;
+ const char *repos = opts.repos_name;
svn_boolean_t read_access, write_access;
- if (path[0] != '/')
+ if (path && path[0] != '/')
path = apr_pstrcat(pool, "/", path, NULL);
err = svn_repos_authz_check_access(authz, repos, path, user,