ifcfg-rh: merge branch 'th/ifcfg-rh-shell-parsing-rh1369380'

https://bugzilla.redhat.com/show_bug.cgi?id=1369380
This commit is contained in:
Thomas Haller
2016-11-09 12:21:18 +01:00
25 changed files with 2156 additions and 1964 deletions

View File

@@ -1926,7 +1926,15 @@ EXTRA_DIST += \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dns-options \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-wake-on-lan \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only-1
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only-1 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected
# make target dependencies can't have colons in their names, which ends up
# meaning that we can't add the alias files to EXTRA_DIST. They are instead

View File

@@ -771,13 +771,12 @@ crypto_md5_hash (const char *salt,
gsize buflen)
{
GChecksum *ctx;
int nkey = buflen;
gsize digest_len;
int count = 0;
char digest[16];
char *p = buffer;
gsize bufidx = 0;
int i;
g_assert_cmpint (g_checksum_type_get_length (G_CHECKSUM_MD5), ==, sizeof (digest));
nm_assert (g_checksum_type_get_length (G_CHECKSUM_MD5) == sizeof (digest));
g_return_if_fail (password_len == 0 || password);
g_return_if_fail (buffer != NULL);
@@ -791,12 +790,7 @@ crypto_md5_hash (const char *salt,
if (password_len < 0)
password_len = strlen (password);
while (nkey > 0) {
int i = 0;
g_checksum_reset (ctx);
if (count++)
g_checksum_update (ctx, (const guchar *) digest, sizeof (digest));
for (;;) {
if (password_len > 0)
g_checksum_update (ctx, (const guchar *) password, password_len);
if (salt_len > 0)
@@ -804,14 +798,19 @@ crypto_md5_hash (const char *salt,
digest_len = sizeof (digest);
g_checksum_get_digest (ctx, (guchar *) digest, &digest_len);
g_assert (digest_len == sizeof (digest));
nm_assert (digest_len == sizeof (digest));
while (nkey && (i < sizeof (digest))) {
*(p++) = digest[i++];
nkey--;
for (i = 0; i < sizeof (digest); i++) {
if (bufidx >= buflen)
goto done;
buffer[bufidx++] = digest[i];
}
g_checksum_reset (ctx);
g_checksum_update (ctx, (const guchar *) digest, sizeof (digest));
}
done:
memset (digest, 0, sizeof (digest));
g_checksum_free (ctx);
}

View File

@@ -194,6 +194,14 @@ char *nm_utils_uuid_generate_from_string (const char *s, gssize slen, int uuid_t
char *_nm_utils_uuid_generate_from_strings (const char *string1, ...) G_GNUC_NULL_TERMINATED;
char *nm_utils_uuid_generate_buf_ (char *buf);
#define nm_utils_uuid_generate_buf(buf) \
({ \
G_STATIC_ASSERT (sizeof (buf) == G_N_ELEMENTS (buf) && sizeof (buf) >= 37); \
nm_utils_uuid_generate_buf_ (buf); \
})
#define nm_utils_uuid_generate_a() (nm_utils_uuid_generate_buf_ (g_alloca (37)))
void _nm_dbus_errors_init (void);
extern gboolean _nm_utils_is_manager_process;

View File

@@ -2146,6 +2146,22 @@ next:
/*****************************************************************************/
/**
* nm_utils_uuid_generate_buf_:
* @buf: input buffer, must contain at least 37 bytes
*
* Returns: generates a new random UUID, writes it to @buf and returns @buf.
**/
char *
nm_utils_uuid_generate_buf_ (char *buf)
{
uuid_t uuid;
uuid_generate_random (uuid);
uuid_unparse_lower (uuid, buf);
return buf;
}
/**
* nm_utils_uuid_generate:
*
@@ -2155,13 +2171,7 @@ next:
char *
nm_utils_uuid_generate (void)
{
uuid_t uuid;
char *buf;
buf = g_malloc0 (37);
uuid_generate_random (uuid);
uuid_unparse_lower (uuid, &buf[0]);
return buf;
return nm_utils_uuid_generate_buf_ (g_malloc (37));
}
/**
@@ -2212,7 +2222,7 @@ nm_utils_uuid_generate_from_string (const char *s, gssize slen, int uuid_type, g
g_return_val_if_reached (NULL);
}
buf = g_malloc0 (37);
buf = g_malloc (37);
uuid_unparse_lower (uuid, &buf[0]);
return buf;

View File

@@ -258,6 +258,52 @@ _NM_IN_STRSET_streq (const char *x, const char *s)
* side-effects. */
#define NM_IN_STRSET_SE(x, ...) _NM_IN_STRSET_EVAL_N(|, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
#define NM_STRCHAR_ALL(str, ch_iter, predicate) \
({ \
gboolean _val = TRUE; \
const char *_str = (str); \
\
if (_str) { \
for (;;) { \
const char ch_iter = _str[0]; \
\
if (ch_iter != '\0') { \
if (predicate) {\
_str++; \
continue; \
} \
_val = FALSE; \
} \
break; \
} \
} \
_val; \
})
#define NM_STRCHAR_ANY(str, ch_iter, predicate) \
({ \
gboolean _val = FALSE; \
const char *_str = (str); \
\
if (_str) { \
for (;;) { \
const char ch_iter = _str[0]; \
\
if (ch_iter != '\0') { \
if (predicate) { \
; \
} else { \
_str++; \
continue; \
} \
_val = TRUE; \
} \
break; \
} \
} \
_val; \
})
/*****************************************************************************/
#define nm_streq(s1, s2) (strcmp (s1, s2) == 0)

View File

@@ -1144,6 +1144,62 @@ nmtst_file_resolve_relative_path (const char *rel, const char *cwd)
return g_build_filename (cwd, rel, NULL);
}
inline static char *
nmtst_file_get_contents (const char *filename)
{
GError *error = NULL;
gboolean success;
char *contents = NULL;
gsize len;
success = g_file_get_contents (filename, &contents, &len, &error);
nmtst_assert_success (success && contents, error);
g_assert_cmpint (strlen (contents), ==, len);
return contents;
}
/*****************************************************************************/
inline static void
nmtst_file_unlink_if_exists (const char *name)
{
int errsv;
g_assert (name && name[0]);
if (unlink (name) != 0) {
errsv = errno;
if (errsv != ENOENT)
g_error ("nmtst_file_unlink_if_exists(%s): failed with %s", name, strerror (errsv));
}
}
inline static void
nmtst_file_unlink (const char *name)
{
int errsv;
g_assert (name && name[0]);
if (unlink (name) != 0) {
errsv = errno;
g_error ("nmtst_file_unlink(%s): failed with %s", name, strerror (errsv));
}
}
inline static void
_nmtst_auto_unlinkfile (char **p_name)
{
if (*p_name) {
nmtst_file_unlink (*p_name);
nm_clear_g_free (p_name);
}
}
#define nmtst_auto_unlinkfile nm_auto(_nmtst_auto_unlinkfile)
/*****************************************************************************/
inline static void
_nmtst_assert_resolve_relative_path_equals (const char *f1, const char *f2, const char *file, int line)
{

View File

@@ -335,7 +335,6 @@ commit_changes (NMSettingsConnection *connection,
NMSettingsConnectionCommitFunc callback,
gpointer user_data)
{
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) connection);
GError *error = NULL;
NMConnection *reread;
gboolean same = FALSE, success = FALSE;
@@ -369,7 +368,6 @@ commit_changes (NMSettingsConnection *connection,
success = writer_update_connection (NM_CONNECTION (connection),
IFCFG_DIR,
filename,
priv->keyfile,
&error);
} else {
success = writer_new_connection (NM_CONNECTION (connection),

File diff suppressed because it is too large Load Diff

View File

@@ -30,87 +30,6 @@
#include "nms-ifcfg-rh-common.h"
/*
* utils_single_quote_string
*
* Put string inside single quotes and remove CR, LF characters. If single quote
* is present, escape it with a backslash and prepend the whole string with $
* in order to have $'string'. That allows us to use single quote inside
* single quotes without breaking bash syntax. (man bash, section QUOTING).
*
* Caller is responsible for freeing the returned string.
*/
char *
utils_single_quote_string (const char *str)
{
static const char *drop_chars = "\r\n"; /* drop CR and LF */
static const char escape_char = '\\'; /* escape char is backslash */
static const char quote_char = '\''; /* quote char is single quote */
size_t i, slen, j = 0;
size_t drop = 0, extra = 0;
char *new_str;
slen = strlen (str);
for (i = 0; i < slen; i++) {
if (str[i] == quote_char)
extra++;
if (strchr (drop_chars, str[i]))
drop++;
}
new_str = g_malloc0 (slen + extra - drop + 4); /* 4 is for $''\0*/
if (extra > 0)
new_str[j++] = '$';
new_str[j++] = quote_char;
for (i = 0; i < slen; i++) {
if (strchr (drop_chars, str[i]))
continue;
if (str[i] == quote_char)
new_str[j++] = escape_char;
new_str[j++] = str[i];
}
new_str[j] = quote_char;
return new_str;
}
/*
* utils_single_unquote_string
*
* Remove string from single (or double) quotes, and remove escaping of '.
* Also remove first $ if the string is in the form of $'string'.
*
* Caller is responsible for freeing the returned string.
*/
char *
utils_single_unquote_string (const char *str)
{
static const char escape_char = '\\'; /* escape char is backslash */
static const char q_char = '\''; /* quote char is single quote */
static const char dq_char = '"'; /* double quote char */
size_t i, slen, j = 0, quote = 0, dollar = 0;
char *new_str;
slen = strlen (str);
new_str = g_malloc0 (slen + 1);
if ( (slen >= 2 && (str[0] == dq_char || str[0] == q_char) && str[0] == str[slen-1])
|| (slen >= 3 && str[0] == '$' && str[1] == q_char && str[1] == str[slen-1])) {
quote = 1;
if (str[0] == '$') dollar = 1;
}
i = quote + dollar;
while (i < slen - quote) {
if (str[i] == escape_char && str[i+1] == q_char && i+1 < slen-quote)
i++;
new_str[j++] = str[i++];
}
new_str[j] = '\0';
return new_str;
}
/*
* Check ';[a-fA-F0-9]{8}' file suffix used for temporary files by rpm when
* installing packages.

View File

@@ -31,10 +31,6 @@
#define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
char *utils_single_quote_string (const char *str);
char *utils_single_unquote_string (const char *str);
char *utils_cert_path (const char *parent, const char *suffix);
const char *utils_get_ifcfg_name (const char *file, gboolean only_ifcfg);

File diff suppressed because it is too large Load Diff

View File

@@ -34,7 +34,6 @@ gboolean writer_new_connection (NMConnection *connection,
gboolean writer_update_connection (NMConnection *connection,
const char *ifcfg_dir,
const char *filename,
const char *keyfile,
GError **error);
#endif /* _WRITER_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -34,6 +34,9 @@
typedef struct _shvarFile shvarFile;
const char *svFileGetName (const shvarFile *s);
void svFileSetName (shvarFile *s, const char *fileName);
void svFileSetModified (shvarFile *s);
/* Create the file <name>, return a shvarFile (never fails) */
shvarFile *svCreateFile (const char *name);
@@ -45,8 +48,8 @@ shvarFile *svOpenFile (const char *name, GError **error);
* pointing at the line containing the value. The char* returned MUST
* be freed by the caller.
*/
char *svGetValue (shvarFile *s, const char *key, gboolean verbatim);
char *svGetValueFull (shvarFile *s, const char *key, gboolean verbatim);
const char *svGetValue (shvarFile *s, const char *key, char **to_free);
char *svGetValueString (shvarFile *s, const char *key);
gint svParseBoolean (const char *value, gint def);
@@ -63,8 +66,9 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g
* the key=value pair after that line. Otherwise, prepend the pair
* to the top of the file.
*/
void svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim);
void svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim);
void svSetValueString (shvarFile *s, const char *key, const char *value);
void svSetValue (shvarFile *s, const char *key, const char *value);
void svSetValueBoolean (shvarFile *s, const char *key, gboolean value);
void svSetValueInt64 (shvarFile *s, const char *key, gint64 value);
void svUnsetValue (shvarFile *s, const char *key);
@@ -80,10 +84,7 @@ gboolean svWriteFile (shvarFile *s, int mode, GError **error);
/* Close the file descriptor (if open) and free the shvarFile. */
void svCloseFile (shvarFile *s);
/* Return @s unmodified or an escaped string */
const char *svEscape (const char *s, char **to_free);
/* Unescape a string in-place */
void svUnescape (char *s);
const char *svUnescape (const char *s, char **to_free);
#endif /* _SHVAR_H */

View File

@@ -16,4 +16,4 @@ CIPHER_GROUP="TKIP CCMP WEP40 WEP104"
KEY_MGMT=WPA-PSK
WPA_ALLOW_WPA=yes
WPA_ALLOW_WPA2=yes
LAST_ENTRY=no-newline

View File

@@ -0,0 +1,8 @@
FOO='val
bar=3'
wrong line
F2=b
F3='b
XXX=adf'
XXX2=val2
'

View File

@@ -0,0 +1,12 @@
FOO=
#NM: FOO='val
bar=
#NM: bar=3'
#NM: wrong line
F2=b
F3=
#NM: F3='b
XXX=
#NM: XXX=adf'
XXX2=val2
#NM: '

View File

@@ -0,0 +1,3 @@
FOO='
BAR=a
'

View File

@@ -0,0 +1,4 @@
FOO=
#NM: FOO='
BAR=a
#NM: '

View File

@@ -0,0 +1,3 @@
FOO='
BAR="
'

View File

@@ -0,0 +1,5 @@
FOO=
#NM: FOO='
BAR=
#NM: BAR="
#NM: '

View File

@@ -0,0 +1,32 @@
# test what happens with multiple defines of a name.
#
# Note that svGetValue() will return "l4x", which
# isn't correct in terms of shell-parsing. But we
# don't consider only line-by-line, thus this is
# expected.
#
# Also note that setting NAME will replace the last
# occurance, and delete all previous once.
#L1
NAME=l2
#L2
NAME=l3
#L4
NAME='
NAME=l4x
'
#Lx-1
NAME2=not-visible
#Lx-2
NAME2='invalid
#Lx-3
#Ly-1
NAME3='invalid
#Ly-2
NAME3=name3-value
#Ly-3

View File

@@ -0,0 +1,27 @@
# test what happens with multiple defines of a name.
#
# Note that svGetValue() will return "l4x", which
# isn't correct in terms of shell-parsing. But we
# don't consider only line-by-line, thus this is
# expected.
#
# Also note that setting NAME will replace the last
# occurance, and delete all previous once.
#L1
#L2
#L4
NAME=set-by-test1
#NM: '
#Lx-1
#Lx-2
NAME2=set-by-test2
#Lx-3
#Ly-1
#Ly-2
NAME3=set-by-test3
#Ly-3

View File

@@ -1,2 +1,2 @@
WPA_PSK=$'They\'re really saying I love you. >>`<< \'
WPA_PSK="They're really saying I love you. >>\`<< '"

File diff suppressed because it is too large Load Diff