Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow special characters in credential login names (8.0) #475

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -22264,8 +22264,8 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_credential",
"Login may only contain alphanumeric"
" characters if autogenerating"
" credential"));
" characters or the following:"
" - _ \\ . @"));
break;
case 3:
SEND_TO_CLIENT_OR_FAIL
Expand Down Expand Up @@ -26161,8 +26161,9 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
case 4:
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("modify_credential",
"Login name must not be empty and contain"
" only alphanumeric characters"));
"Login name must not be empty and may"
" contain only alphanumeric characters"
" or the following: - _ \\ . @"));
log_event_fail ("credential", "Credential",
modify_credential_data->credential_id,
"modified");
Expand Down
81 changes: 51 additions & 30 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -41582,6 +41582,31 @@ set_credential_data (credential_t credential,
return 0;
}

/**
* @brief Test if a username is valid to use in a credential.
*
* Valid usernames may only contain alphanumeric characters and a few
* special ones to avoid problems with installer package generation.
*
* @param[in] username The username string to test.
*
* @return Whether the username is valid.
*/
static int
validate_credential_username (const gchar *username)
{
const char *s;
s = username;
while (*s)
if (isalnum (*s)
|| strchr ("-_\\.@", *s))
s++;
else
return 0;

return 1;
}

/**
* @brief Test if a username is valid for a credential export format.
*
Expand Down Expand Up @@ -41655,7 +41680,7 @@ validate_credential_username_for_format (const gchar *username,
* @param[in] allow_insecure Whether to allow insecure uses.
* @param[out] credential Created Credential.
*
* @return 0 success, 1 LSC credential exists already, 2 name contains space,
* @return 0 success, 1 LSC credential exists already, 2 invalid username,
* 3 Failed to create public key from private key/password,
* 4 Invalid credential type, 5 login username missing,
* 6 password missing, 7 private key missing, 8 certificate missing,
Expand Down Expand Up @@ -41839,8 +41864,21 @@ create_credential (const char* name, const char* comment, const char* login,

/* Add non-secret data */
if (login)
set_credential_data (new_credential,
"username", login);
{
/*
* Ensure the login does not contain characters that cause problems
* with package generation.
*/
if (validate_credential_username (login) == 0)
{
sql_rollback ();
return 2;
}

set_credential_data (new_credential,
"username", login);
}

if (key_public)
set_credential_data (new_credential, "public_key", key_public);

Expand All @@ -41852,7 +41890,10 @@ create_credential (const char* name, const char* comment, const char* login,
set_credential_data (new_credential,
"certificate", certificate_truncated);
else
return 17;
{
sql_rollback();
return 17;
}
g_free (certificate_truncated);
}
if (auth_algorithm)
Expand Down Expand Up @@ -42009,23 +42050,6 @@ create_credential (const char* name, const char* comment, const char* login,
* Auto-generate credential
*/

/* Ensure the login is alphanumeric, to help the package generation. */

if (login)
{
const char *s;
s = login;
while (*s)
if (isalnum (*s))
s++;
else
{
g_free (quoted_name);
sql_rollback ();
return 2;
}
}

/* Create the keys and packages. */

rand = g_rand_new ();
Expand Down Expand Up @@ -42232,16 +42256,13 @@ modify_credential (const char *credential_id,

if (login && ret == 0)
{
const char *s;
s = login;
// Check if login contains only alphanumeric characters
if (strcmp (login, "") == 0)
/*
* Ensure the login is not empty and does not contain characters that
* cause problems with package generation.
*/
if (strcmp (login, "") == 0
|| validate_credential_username (login) == 0)
ret = 4;
while (*s && ret == 0)
if (isalnum (*s))
s++;
else
ret = 4;

if (ret == 0)
set_credential_login (credential, login);
Expand Down