1d514b0f3Smrg/* 2d514b0f3Smrg * Copyright 2013 Red Hat, Inc. 3d514b0f3Smrg * 4d514b0f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5d514b0f3Smrg * copy of this software and associated documentation files (the "Software"), 6d514b0f3Smrg * to deal in the Software without restriction, including without limitation 7d514b0f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 8d514b0f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom 9d514b0f3Smrg * the Software is furnished to do so, subject to the following conditions: 10d514b0f3Smrg * 11d514b0f3Smrg * The above copyright notice and this permission notice (including the next 12d514b0f3Smrg * paragraph) shall be included in all copies or substantial portions of the 13d514b0f3Smrg * Software. 14d514b0f3Smrg * 15d514b0f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16d514b0f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17d514b0f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18d514b0f3Smrg * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19d514b0f3Smrg * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20d514b0f3Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21d514b0f3Smrg */ 22d514b0f3Smrg 23d514b0f3Smrg#include "config.h" 24d514b0f3Smrg 25d514b0f3Smrg#include <unistd.h> 26d514b0f3Smrg#include <string.h> 27d514b0f3Smrg#include <errno.h> 28d514b0f3Smrg 29d514b0f3Smrg#include "qxl_option_helpers.h" 30d514b0f3Smrg#include "spiceqxl_util.h" 31d514b0f3Smrg 32d514b0f3Smrgvoid spiceqxl_chown_agent_file(qxl_screen_t *qxl, const char *filename) 33d514b0f3Smrg{ 34d514b0f3Smrg int uid, gid; 35d514b0f3Smrg 36d514b0f3Smrg uid = get_int_option(qxl->options, OPTION_SPICE_VDAGENT_UID, "XSPICE_VDAGENT_UID"); 37d514b0f3Smrg gid = get_int_option(qxl->options, OPTION_SPICE_VDAGENT_GID, "XSPICE_VDAGENT_GID"); 38d514b0f3Smrg if (uid && gid) { 39d514b0f3Smrg if (chown(filename, uid, gid) != 0) { 40d514b0f3Smrg fprintf(stderr, "spice: failed to chain ownership of '%s' to %d/%d: %s\n", 41d514b0f3Smrg filename, uid, gid, strerror(errno)); 42d514b0f3Smrg } 43d514b0f3Smrg } 44d514b0f3Smrg} 45