summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-09-27 11:20:11 +0200
committerThomas Haller <thaller@redhat.com>2016-09-27 12:06:46 +0200
commitf4e4afef2c5834cdf24a3cc5e81381ef8e1c4565 (patch)
tree36201a62da469e39e8ab867073b873ab41d7e4e8
parent90952a85b9556287d6c296aae23ac54df68b13a0 (diff)
downloadNetworkManager-th/proxy.tar.gz
cli: support qualifying proxy.pac-script with "file://" or "js://"th/proxy
-rw-r--r--clients/cli/common.c64
-rw-r--r--man/nmcli.xml13
2 files changed, 61 insertions, 16 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c
index d3c118e16d..8e25dbffd3 100644
--- a/clients/cli/common.c
+++ b/clients/cli/common.c
@@ -913,33 +913,65 @@ nmc_team_check_config (const char *config, char **out_config, GError **error)
gboolean
nmc_proxy_check_script (const char *script, char **out_script, GError **error)
{
- char *contents = NULL;
+ enum {
+ _PAC_SCRIPT_TYPE_GUESS,
+ _PAC_SCRIPT_TYPE_FILE,
+ _PAC_SCRIPT_TYPE_JSON,
+ } desired_type = _PAC_SCRIPT_TYPE_GUESS;
+ const char *filename = NULL;
size_t c_len = 0;
+ gs_free char *script_clone = NULL;
*out_script = NULL;
- if (!script || strlen (script) == strspn (script, " \t"))
+ if (!script || !script[0])
return TRUE;
- /* 'script' can be either a file name or raw PAC Script data */
- if (g_file_test (script, G_FILE_TEST_EXISTS))
- (void) g_file_get_contents (script, &contents, NULL, NULL);
- else
- contents = g_strdup (script);
+ if (g_str_has_prefix (script, "file://")) {
+ script += NM_STRLEN ("file://");
+ desired_type = _PAC_SCRIPT_TYPE_FILE;
+ } else if (g_str_has_prefix (script, "js://")) {
+ script += NM_STRLEN ("js://");
+ desired_type = _PAC_SCRIPT_TYPE_JSON;
+ }
+
+ if (NM_IN_SET (desired_type, _PAC_SCRIPT_TYPE_FILE, _PAC_SCRIPT_TYPE_GUESS)) {
+ gs_free char *contents = NULL;
- if (contents) {
- g_strstrip (contents);
- c_len = strlen (contents);
+ if (!g_file_get_contents (script, &contents, &c_len, NULL)) {
+ if (desired_type == _PAC_SCRIPT_TYPE_FILE) {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("cannot read pac-script from file '%s'"),
+ script);
+ return FALSE;
+ }
+ } else {
+ if (c_len != strlen (contents)) {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("file '%s' contains non-valid utf-8"),
+ script);
+ return FALSE;
+ }
+ filename = script;
+ script = script_clone = g_steal_pointer (&contents);
+ }
}
- /* Do a simple validity check */
- if (!contents || !contents[0] || c_len > 100000 || !strstr (contents, "FindProxyForURL")) {
- g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
- _("'%s' is not a valid PAC Script or file name."), script);
- g_free (contents);
+ if ( !strstr (script, "FindProxyForURL")
+ || !g_utf8_validate (script, -1, NULL)) {
+ if (filename) {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("'%s' does not contain a valid PAC Script"), filename);
+ } else {
+ g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
+ _("Not a valid PAC Script"));
+ }
return FALSE;
}
- *out_script = g_strdelimit (contents, "\t\r\n", ' ');
+
+ *out_script = (script == script_clone)
+ ? g_steal_pointer (&script_clone)
+ : g_strdup (script);
return TRUE;
}
diff --git a/man/nmcli.xml b/man/nmcli.xml
index 965c05f955..3b6cc9ff3e 100644
--- a/man/nmcli.xml
+++ b/man/nmcli.xml
@@ -1983,6 +1983,19 @@ It's equivalent of using <literal>+ipv6.addresses</literal> syntax.</entry>
</tbody>
</tgroup></table>
+ <table><title>Proxy options</title><tgroup cols="3">
+ <thead>
+ <row><entry>Alias</entry><entry>Property</entry><entry>Note</entry></row>
+ </thead>
+ <tbody>
+ <row>
+ <entry align="left"></entry>
+ <entry align="left"><link linkend="nm-settings.property.proxy.pac-script">proxy.pac-script</link></entry>
+ <entry align="left" valign="top">Read the java script pac-script from file or pass it directly on the command line. Prefix the value with "file://" or "js://" to force one or the other.</entry>
+ </row>
+ </tbody>
+ </tgroup></table>
+
</refsect1>
<refsect1 id='environment_variables'><title>Environment Variables</title>