help-cmd.c revision 299742
144743Smarkm/*
244743Smarkm * help-cmd.c -- Provide help
344743Smarkm *
444743Smarkm * ====================================================================
544743Smarkm *    Licensed to the Apache Software Foundation (ASF) under one
644743Smarkm *    or more contributor license agreements.  See the NOTICE file
744743Smarkm *    distributed with this work for additional information
844743Smarkm *    regarding copyright ownership.  The ASF licenses this file
944743Smarkm *    to you under the Apache License, Version 2.0 (the
1044743Smarkm *    "License"); you may not use this file except in compliance
1144743Smarkm *    with the License.  You may obtain a copy of the License at
1244743Smarkm *
1344743Smarkm *      http://www.apache.org/licenses/LICENSE-2.0
1444743Smarkm *
1544743Smarkm *    Unless required by applicable law or agreed to in writing,
1644743Smarkm *    software distributed under the License is distributed on an
1744743Smarkm *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1844743Smarkm *    KIND, either express or implied.  See the License for the
1944743Smarkm *    specific language governing permissions and limitations
2044743Smarkm *    under the License.
2144743Smarkm * ====================================================================
2244743Smarkm */
2344743Smarkm
2444743Smarkm/* ==================================================================== */
2544743Smarkm
2644743Smarkm
2744743Smarkm
2844743Smarkm/*** Includes. ***/
2944743Smarkm
3044743Smarkm#include "svn_hash.h"
3144743Smarkm#include "svn_string.h"
3244743Smarkm#include "svn_config.h"
3344743Smarkm#include "svn_dirent_uri.h"
3444743Smarkm#include "svn_error.h"
3544743Smarkm#include "cl.h"
3644743Smarkm
3744743Smarkm#include "svn_private_config.h"
3844743Smarkm
3944743Smarkm
4044743Smarkm/*** Code. ***/
4144743Smarkm
4244743Smarkm/* This implements the `svn_opt_subcommand_t' interface. */
4344743Smarkmsvn_error_t *
4444743Smarkmsvn_cl__help(apr_getopt_t *os,
4544743Smarkm             void *baton,
4644743Smarkm             apr_pool_t *pool)
4744743Smarkm{
4844743Smarkm  svn_cl__opt_state_t *opt_state = NULL;
4944743Smarkm  svn_stringbuf_t *version_footer = NULL;
5044743Smarkm  const char *config_path;
5144743Smarkm
5244743Smarkm  char help_header[] =
5344743Smarkm  N_("usage: svn <subcommand> [options] [args]\n"
5444743Smarkm     "Subversion command-line client.\n"
5544743Smarkm     "Type 'svn help <subcommand>' for help on a specific subcommand.\n"
5644743Smarkm     "Type 'svn --version' to see the program version and RA modules\n"
5744743Smarkm     "  or 'svn --version --quiet' to see just the version number.\n"
5844743Smarkm     "\n"
5944743Smarkm     "Most subcommands take file and/or directory arguments, recursing\n"
6044743Smarkm     "on the directories.  If no arguments are supplied to such a\n"
6144743Smarkm     "command, it recurses on the current directory (inclusive) by default.\n"
6244743Smarkm     "\n"
6344743Smarkm     "Available subcommands:\n");
6444743Smarkm
6544743Smarkm  char help_footer[] =
6644743Smarkm  N_("Subversion is a tool for version control.\n"
6744743Smarkm     "For additional information, see http://subversion.apache.org/\n");
6844743Smarkm
6944743Smarkm  const char *ra_desc_start
70    = _("The following repository access (RA) modules are available:\n\n");
71
72  if (baton)
73    {
74      svn_cl__cmd_baton_t *const cmd_baton = baton;
75#ifndef SVN_DISABLE_PLAINTEXT_PASSWORD_STORAGE
76      /* Windows never actually stores plaintext passwords, it
77         encrypts the contents using CryptoAPI. ...
78
79         ... If CryptoAPI is available ... but it should be on all
80         versions of Windows that are even remotely interesting two
81         days before the scheduled end of the world, when this comment
82         is being written. */
83#  ifndef WIN32
84      svn_boolean_t store_auth_creds =
85        SVN_CONFIG_DEFAULT_OPTION_STORE_AUTH_CREDS;
86      svn_boolean_t store_passwords =
87        SVN_CONFIG_DEFAULT_OPTION_STORE_PASSWORDS;
88      svn_boolean_t store_plaintext_passwords = FALSE;
89      svn_config_t *cfg;
90
91      if (cmd_baton->ctx->config)
92        {
93          cfg = svn_hash_gets(cmd_baton->ctx->config,
94                              SVN_CONFIG_CATEGORY_CONFIG);
95          if (cfg)
96            {
97              SVN_ERR(svn_config_get_bool(cfg, &store_auth_creds,
98                                          SVN_CONFIG_SECTION_AUTH,
99                                          SVN_CONFIG_OPTION_STORE_AUTH_CREDS,
100                                          store_auth_creds));
101              SVN_ERR(svn_config_get_bool(cfg, &store_passwords,
102                                          SVN_CONFIG_SECTION_AUTH,
103                                          SVN_CONFIG_OPTION_STORE_PASSWORDS,
104                                          store_passwords));
105            }
106          cfg = svn_hash_gets(cmd_baton->ctx->config,
107                              SVN_CONFIG_CATEGORY_SERVERS);
108          if (cfg)
109            {
110              const char *value;
111              SVN_ERR(svn_config_get_yes_no_ask
112                      (cfg, &value,
113                       SVN_CONFIG_SECTION_GLOBAL,
114                       SVN_CONFIG_OPTION_STORE_PLAINTEXT_PASSWORDS,
115                       SVN_CONFIG_DEFAULT_OPTION_STORE_PLAINTEXT_PASSWORDS));
116              if (0 == svn_cstring_casecmp(value, SVN_CONFIG_TRUE))
117                store_plaintext_passwords = TRUE;
118            }
119        }
120
121      if (store_plaintext_passwords && store_auth_creds && store_passwords)
122        {
123          version_footer = svn_stringbuf_create(
124              _("WARNING: Plaintext password storage is enabled!\n\n"),
125              pool);
126          svn_stringbuf_appendcstr(version_footer, ra_desc_start);
127        }
128#  endif /* !WIN32 */
129#endif /* !SVN_DISABLE_PLAINTEXT_PASSWORD_STORAGE */
130
131      opt_state = cmd_baton->opt_state;
132    }
133
134  if (!version_footer)
135    version_footer = svn_stringbuf_create(ra_desc_start, pool);
136  SVN_ERR(svn_ra_print_modules(version_footer, pool));
137
138  /*
139   * Show auth creds storage providers.
140   */
141  SVN_ERR(svn_config_get_user_config_path(&config_path,
142                                          opt_state ? opt_state->config_dir
143                                                    : NULL,
144                                          NULL,
145                                          pool));
146  svn_stringbuf_appendcstr(version_footer,
147                           _("\nThe following authentication credential caches are available:\n\n"));
148
149  /*### There is no API to query available providers at run time. */
150#if (defined(WIN32) && !defined(__MINGW32__))
151  version_footer =
152    svn_stringbuf_create(apr_psprintf(pool, _("%s* Wincrypt cache in %s\n"),
153                                      version_footer->data,
154                                      svn_dirent_local_style(config_path,
155                                                             pool)),
156                         pool);
157#elif !defined(SVN_DISABLE_PLAINTEXT_PASSWORD_STORAGE)
158  version_footer =
159    svn_stringbuf_create(apr_psprintf(pool, _("%s* Plaintext cache in %s\n"),
160                                      version_footer->data,
161                                      svn_dirent_local_style(config_path,
162                                                             pool)),
163                         pool);
164#endif
165#ifdef SVN_HAVE_GNOME_KEYRING
166  svn_stringbuf_appendcstr(version_footer, "* Gnome Keyring\n");
167#endif
168#ifdef SVN_HAVE_GPG_AGENT
169  svn_stringbuf_appendcstr(version_footer, "* GPG-Agent\n");
170#endif
171#ifdef SVN_HAVE_KEYCHAIN_SERVICES
172  svn_stringbuf_appendcstr(version_footer, "* Mac OS X Keychain\n");
173#endif
174#ifdef SVN_HAVE_KWALLET
175  svn_stringbuf_appendcstr(version_footer, "* KWallet (KDE)\n");
176#endif
177
178  return svn_opt_print_help4(os,
179                             "svn",   /* ### erm, derive somehow? */
180                             opt_state ? opt_state->version : FALSE,
181                             opt_state ? opt_state->quiet : FALSE,
182                             opt_state ? opt_state->verbose : FALSE,
183                             version_footer->data,
184                             help_header,   /* already gettext()'d */
185                             svn_cl__cmd_table,
186                             svn_cl__options,
187                             svn_cl__global_options,
188                             _(help_footer),
189                             pool);
190}
191