image-dbus.c revision a90fb858ac91de4c14c9b68da6060731954515b7
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "alloc-util.h"
#include "bus-label.h"
#include "bus-util.h"
#include "image-dbus.h"
#include "io-util.h"
#include "machine-image.h"
#include "strv.h"
#include "user-util.h"
void *userdata,
sd_bus_error *error) {
int r;
"org.freedesktop.machine1.manage-images",
NULL,
false,
&m->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
r = image_remove(image);
if (r < 0)
return r;
}
void *userdata,
sd_bus_error *error) {
const char *new_name;
int r;
if (r < 0)
return r;
if (!image_name_is_valid(new_name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", new_name);
"org.freedesktop.machine1.manage-images",
NULL,
false,
&m->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
if (r < 0)
return r;
}
void *userdata,
sd_bus_error *error) {
const char *new_name;
int r, read_only;
if (r < 0)
return r;
if (!image_name_is_valid(new_name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", new_name);
"org.freedesktop.machine1.manage-images",
NULL,
false,
&m->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
if (r < 0)
return r;
}
void *userdata,
sd_bus_error *error) {
int r, read_only;
if (r < 0)
return r;
"org.freedesktop.machine1.manage-images",
NULL,
false,
&m->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
if (r < 0)
return r;
}
void *userdata,
sd_bus_error *error) {
int r;
if (r < 0)
return r;
if (!FILE_SIZE_VALID_OR_INFINITY(limit))
"org.freedesktop.machine1.manage-images",
NULL,
false,
&m->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
if (r < 0)
return r;
}
const sd_bus_vtable image_vtable[] = {
SD_BUS_METHOD("MarkReadOnly", "b", NULL, bus_image_method_mark_read_only, SD_BUS_VTABLE_UNPRIVILEGED),
};
Image *i;
assert(s);
assert(m);
while ((i = hashmap_steal_first(m->image_cache)))
image_unref(i);
return 0;
}
int image_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
_cleanup_free_ char *e = NULL;
const char *p;
int r;
if (!p)
return 0;
e = bus_label_unescape(p);
if (!e)
return -ENOMEM;
if (image) {
return 1;
}
if (r < 0)
return r;
if (!m->image_cache_defer_event) {
if (r < 0)
return r;
if (r < 0)
return r;
}
if (r < 0)
return r;
r = image_find(e, &image);
if (r <= 0)
return r;
if (r < 0) {
return r;
}
return 1;
}
char *image_bus_path(const char *name) {
_cleanup_free_ char *e = NULL;
e = bus_label_escape(name);
if (!e)
return NULL;
return strappend("/org/freedesktop/machine1/image/", e);
}
int image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
Iterator i;
int r;
if (!images)
return -ENOMEM;
r = image_discover(images);
if (r < 0)
return r;
char *p;
if (!p)
return -ENOMEM;
r = strv_consume(&l, p);
if (r < 0)
return r;
}
*nodes = l;
l = NULL;
return 1;
}