permission: parse password without strtok_r()
Use strchr()/g_strndup() to extract the password.
This commit is contained in:
parent
3cb3baa1e2
commit
6507bcccd3
@ -26,7 +26,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define PERMISSION_PASSWORD_CHAR "@"
|
#define PERMISSION_PASSWORD_CHAR '@'
|
||||||
#define PERMISSION_SEPERATOR ","
|
#define PERMISSION_SEPERATOR ","
|
||||||
|
|
||||||
#define PERMISSION_READ_STRING "read"
|
#define PERMISSION_READ_STRING "read"
|
||||||
@ -69,8 +69,6 @@ static unsigned parsePermissions(char *string)
|
|||||||
|
|
||||||
void initPermissions(void)
|
void initPermissions(void)
|
||||||
{
|
{
|
||||||
char *temp;
|
|
||||||
char *cp2;
|
|
||||||
char *password;
|
char *password;
|
||||||
unsigned permission;
|
unsigned permission;
|
||||||
ConfigParam *param;
|
ConfigParam *param;
|
||||||
@ -87,26 +85,22 @@ void initPermissions(void)
|
|||||||
permission_default = 0;
|
permission_default = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!strstr(param->value, PERMISSION_PASSWORD_CHAR)) {
|
char *separator =
|
||||||
FATAL("\"%s\" not found in password string "
|
strchr(param->value, PERMISSION_PASSWORD_CHAR);
|
||||||
|
|
||||||
|
if (separator == NULL)
|
||||||
|
FATAL("\"%c\" not found in password string "
|
||||||
"\"%s\", line %i\n",
|
"\"%s\", line %i\n",
|
||||||
PERMISSION_PASSWORD_CHAR,
|
PERMISSION_PASSWORD_CHAR,
|
||||||
param->value, param->line);
|
param->value, param->line);
|
||||||
}
|
|
||||||
|
|
||||||
if (!(temp = strtok_r(param->value,
|
password = g_strndup(param->value,
|
||||||
PERMISSION_PASSWORD_CHAR,
|
separator - param->value);
|
||||||
&cp2))) {
|
|
||||||
FATAL("something weird just happened in permission.c\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
password = temp;
|
permission = parsePermissions(separator + 1);
|
||||||
|
|
||||||
permission =
|
|
||||||
parsePermissions(strtok_r(NULL, "", &cp2));
|
|
||||||
|
|
||||||
g_hash_table_replace(permission_passwords,
|
g_hash_table_replace(permission_passwords,
|
||||||
g_strdup(password),
|
password,
|
||||||
GINT_TO_POINTER(permission));
|
GINT_TO_POINTER(permission));
|
||||||
} while ((param = getNextConfigParam(CONF_PASSWORD, param)));
|
} while ((param = getNextConfigParam(CONF_PASSWORD, param)));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user