static void set_default_configurations(void)
{
int i;
+#ifdef MPD
+ char *mpd_env_host;
+ char *mpd_env_port;
+#endif
update_uname();
fork_to_background = 0;
total_run_times = 0;
top_io = 0;
#endif
#ifdef MPD
- mpd_set_host("localhost");
- mpd_set_port("6600");
+ mpd_env_host = getenv("MPD_HOST");
+ mpd_env_port = getenv("MPD_PORT");
+
+ if (!mpd_env_host || !strlen(mpd_env_host)) {
+ mpd_set_host("localhost");
+ } else {
+ /* MPD_HOST environment variable is set */
+ char *mpd_hostpart = strchr(mpd_env_host, '@');
+ if (!mpd_hostpart) {
+ mpd_set_host(mpd_env_host);
+ } else {
+ /* MPD_HOST contains a password */
+ char mpd_password[mpd_hostpart - mpd_env_host + 1];
+ snprintf(mpd_password, mpd_hostpart - mpd_env_host + 1, "%s", mpd_env_host);
+
+ if (!strlen(mpd_hostpart + 1)) {
+ mpd_set_host("localhost");
+ } else {
+ mpd_set_host(mpd_hostpart + 1);
+ }
+
+ mpd_set_password(mpd_password, 1);
+ }
+ }
+
+
+ if (!mpd_env_port || mpd_set_port(mpd_env_port)) {
+ /* failed to set port from environment variable */
+ mpd_set_port("6600");
+ }
#endif
#ifdef XMMS2
info.xmms2.artist = NULL;
}
CONF("mpd_password") {
if (value) {
- mpd_set_password(value);
+ mpd_set_password(value, 0);
} else {
CONF_ERR;
}
static char mpd_password[128];
static int mpd_port;
+/* this is >0 if the current password was set from MPD_HOST */
+static int mpd_environment_password = 0;
+
/* global mpd information */
static struct mpd_s mpd_info;
void mpd_set_host(const char *host)
{
snprintf(mpd_host, 128, "%s", host);
+
+ if (mpd_environment_password) {
+ /* for security, dont use environment password when user specifies host in config */
+ mpd_clear_password();
+ }
}
-void mpd_set_password(const char *password)
+void mpd_set_password(const char *password, int from_environment)
{
snprintf(mpd_password, 128, "%s", password);
+ mpd_environment_password = from_environment;
}
void mpd_clear_password(void)
{
*mpd_password = '\0';
+ mpd_environment_password = 0;
}
int mpd_set_port(const char *port)
{
/* functions for setting the configuration values */
void mpd_set_host(const char *);
-void mpd_set_password(const char *);
+void mpd_set_password(const char *, int);
void mpd_clear_password(void);
int mpd_set_port(const char *);