aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-03 13:20:06 +0100
committerMax Kellermann <max@duempel.org>2009-01-03 13:20:06 +0100
commit6507bcccd3cf8bce201ca2cde3bed26f3599027a (patch)
tree608c2d802fc50dbc5598119ce588d2d351bf92cf
parent3cb3baa1e2ff107e96241c5c3d75b0013c684e40 (diff)
downloadmpd-6507bcccd3cf8bce201ca2cde3bed26f3599027a.tar.gz
mpd-6507bcccd3cf8bce201ca2cde3bed26f3599027a.tar.xz
mpd-6507bcccd3cf8bce201ca2cde3bed26f3599027a.zip
permission: parse password without strtok_r()
Use strchr()/g_strndup() to extract the password.
-rw-r--r--src/permission.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/permission.c b/src/permission.c
index e65561ec5..260d2669a 100644
--- a/src/permission.c
+++ b/src/permission.c
@@ -26,7 +26,7 @@
#include <stdbool.h>
#include <string.h>
-#define PERMISSION_PASSWORD_CHAR "@"
+#define PERMISSION_PASSWORD_CHAR '@'
#define PERMISSION_SEPERATOR ","
#define PERMISSION_READ_STRING "read"
@@ -69,8 +69,6 @@ static unsigned parsePermissions(char *string)
void initPermissions(void)
{
- char *temp;
- char *cp2;
char *password;
unsigned permission;
ConfigParam *param;
@@ -87,26 +85,22 @@ void initPermissions(void)
permission_default = 0;
do {
- if (!strstr(param->value, PERMISSION_PASSWORD_CHAR)) {
- FATAL("\"%s\" not found in password string "
+ char *separator =
+ strchr(param->value, PERMISSION_PASSWORD_CHAR);
+
+ if (separator == NULL)
+ FATAL("\"%c\" not found in password string "
"\"%s\", line %i\n",
PERMISSION_PASSWORD_CHAR,
param->value, param->line);
- }
-
- if (!(temp = strtok_r(param->value,
- PERMISSION_PASSWORD_CHAR,
- &cp2))) {
- FATAL("something weird just happened in permission.c\n");
- }
- password = temp;
+ password = g_strndup(param->value,
+ separator - param->value);
- permission =
- parsePermissions(strtok_r(NULL, "", &cp2));
+ permission = parsePermissions(separator + 1);
g_hash_table_replace(permission_passwords,
- g_strdup(password),
+ password,
GINT_TO_POINTER(permission));
} while ((param = getNextConfigParam(CONF_PASSWORD, param)));
}