/*
- Copyright (C) 2010 Proxmox Server Solutions GmbH
+ Copyright (C) 2010 - 2020 Proxmox Server Solutions GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
{ .path = "user.cfg" },
{ .path = "domains.cfg" },
{ .path = "priv/shadow.cfg" },
+ { .path = "priv/acme/plugins.cfg" },
{ .path = "priv/tfa.cfg" },
+ { .path = "priv/token.cfg" },
+ { .path = "priv/ipam.db" },
{ .path = "datacenter.cfg" },
{ .path = "vzdump.cron" },
+ { .path = "jobs.cfg" },
{ .path = "ha/crm_commands" },
{ .path = "ha/manager_status" },
{ .path = "ha/resources.cfg" },
{ .path = "status.cfg" },
{ .path = "replication.cfg" },
{ .path = "ceph.conf" },
- { .path = "sdn.cfg" },
- { .path = "sdn.cfg.new" },
+ { .path = "sdn/vnets.cfg" },
+ { .path = "sdn/zones.cfg" },
+ { .path = "sdn/controllers.cfg" },
+ { .path = "sdn/subnets.cfg" },
+ { .path = "sdn/ipams.cfg" },
+ { .path = "sdn/dns.cfg" },
+ { .path = "sdn/.running-config" },
+ { .path = "virtual-guest/cpu-models.conf" },
+ { .path = "nodes/hardware-map.conf" },
};
static GMutex mutex;
if (vminfo->vmtype == VMTYPE_QEMU) {
return "qemu";
} else if (vminfo->vmtype == VMTYPE_OPENVZ) {
+ // FIXME: remove openvz stuff for 7.x
return "openvz";
} else if (vminfo->vmtype == VMTYPE_LXC) {
return "lxc";
g_return_val_if_fail(vmlist != NULL, FALSE);
g_return_val_if_fail(nodename != NULL, FALSE);
g_return_val_if_fail(vmid != 0, FALSE);
+ // FIXME: remove openvz stuff for 7.x
g_return_val_if_fail(vmtype == VMTYPE_QEMU || vmtype == VMTYPE_OPENVZ ||
vmtype == VMTYPE_LXC, FALSE);
g_return_if_fail(cfs_status.vmlist != NULL);
g_return_if_fail(nodename != NULL);
g_return_if_fail(vmid != 0);
+ // FIXME: remove openvz stuff for 7.x
g_return_if_fail(vmtype == VMTYPE_QEMU || vmtype == VMTYPE_OPENVZ ||
vmtype == VMTYPE_LXC);
// currently we only look at the current configuration in place, i.e., *no*
// snapshort and *no* pending changes
static char *
-_get_property_value(char *conf, const char *prop, int prop_len)
+_get_property_value(char *conf, int conf_size, const char *prop, int prop_len)
{
- char *line = NULL, *temp = NULL;
+ const char *const conf_end = conf + conf_size;
+ char *line = conf;
+ size_t remaining_size;
+
+ char *next_newline = memchr(conf, '\n', conf_size);
+ if (next_newline == NULL) {
+ return NULL; // valid property lines end with \n, but none in the config
+ }
+ *next_newline = '\0';
- line = strtok_r(conf, "\n", &temp);
while (line != NULL) {
if (!line[0]) goto next;
- // snapshot or pending section start and nothing found yet
+ // snapshot or pending section start, but nothing found yet -> not found
if (line[0] == '[') return NULL;
// properties start with /^[a-z]/, so continue early if not
if (line[0] < 'a' || line[0] > 'z') goto next;
return v_start;
}
next:
- line = strtok_r(NULL, "\n", &temp);
+ line = next_newline + 1;
+ remaining_size = conf_end - line;
+ if (remaining_size <= prop_len) {
+ return NULL;
+ }
+ next_newline = memchr(line, '\n', remaining_size);
+ if (next_newline == NULL) {
+ return NULL; // valid property lines end with \n, but none in the config
+ }
+ *next_newline = '\0';
}
return NULL; // not found
int res = 0;
GString *path = NULL;
+ // Prelock &memdb->mutex in order to enable the usage of memdb_read_nolock
+ // to prevent Deadlocks as in #2553
+ g_mutex_lock (&memdb->mutex);
g_mutex_lock (&mutex);
g_string_printf(str,"{\n");
goto ret;
}
- path = g_string_sized_new(256);
+ if ((path = g_string_sized_new(256)) == NULL) {
+ res = -ENOMEM;
+ goto ret;
+ }
+
if (vmid >= 100) {
vminfo_t *vminfo = (vminfo_t *) g_hash_table_lookup(cfs_status.vmlist, &vmid);
if (vminfo == NULL) goto enoent;
if (!vminfo_to_path(vminfo, path)) goto err;
- int size = memdb_read(memdb, path->str, &tmp);
+ // use memdb_read_nolock because lock is handled here
+ int size = memdb_read_nolock(memdb, path->str, &tmp);
if (tmp == NULL) goto err;
if (size <= prop_len) goto ret;
- char *val = _get_property_value(tmp, prop, prop_len);
+ char *val = _get_property_value(tmp, size, prop, prop_len);
if (val == NULL) goto ret;
g_string_append_printf(str, "\"%u\":{", vmid);
g_free(tmp); // no-op if already null
tmp = NULL;
- int size = memdb_read(memdb, path->str, &tmp);
+ // use memdb_read_nolock because lock is handled here
+ int size = memdb_read_nolock(memdb, path->str, &tmp);
if (tmp == NULL || size <= prop_len) continue;
- char *val = _get_property_value(tmp, prop, prop_len);
+ char *val = _get_property_value(tmp, size, prop, prop_len);
if (val == NULL) continue;
if (!first) g_string_append_printf(str, ",\n");
}
g_string_append_printf(str,"\n}\n");
g_mutex_unlock (&mutex);
-
+ g_mutex_unlock (&memdb->mutex);
return res;
err:
res = -EIO;