files.c revision 48130eef6c5c64a07094b9e8582ba358b2048f24
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher Jakub Hrozek <jhrozek@redhat.com>
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher Copyright (C) 2009 Red Hat
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher This program is free software; you can redistribute it and/or modify
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher it under the terms of the GNU General Public License as published by
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher the Free Software Foundation; either version 3 of the License, or
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher (at your option) any later version.
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher This program is distributed in the hope that it will be useful,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee359fe1384507fed6c2274e7bfe81d288de4542Stephen Gallagher GNU General Public License for more details.
ee359fe1384507fed6c2274e7bfe81d288de4542Stephen Gallagher You should have received a copy of the GNU General Public License
33396dc46ea52c18f47db1b5d590880806521005Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
84ae5edab16ad6be5e3be956cb6fa031c1428eb5Stephen Gallagher * This file incorporates work covered by the following copyright and
84ae5edab16ad6be5e3be956cb6fa031c1428eb5Stephen Gallagher * permission notice:
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Copyright (c) 1991 - 1994, Julianne Frances Haugh
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Copyright (c) 1996 - 2001, Marek Michałkiewicz
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Copyright (c) 2003 - 2006, Tomasz Kłoczko
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Copyright (c) 2007 - 2008, Nicolas François
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * All rights reserved.
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Redistribution and use in source and binary forms, with or without
84ae5edab16ad6be5e3be956cb6fa031c1428eb5Stephen Gallagher * modification, are permitted provided that the following conditions
ee359fe1384507fed6c2274e7bfe81d288de4542Stephen Gallagher * 1. Redistributions of source code must retain the above copyright
cc98edd9479d4622634a1275c98058916c14059aStephen Gallagher * notice, this list of conditions and the following disclaimer.
1183d29d87c5c7439cf2364b7d7324d4a13b6e35Stephen Gallagher * 2. Redistributions in binary form must reproduce the above copyright
1183d29d87c5c7439cf2364b7d7324d4a13b6e35Stephen Gallagher * notice, this list of conditions and the following disclaimer in the
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * documentation and/or other materials provided with the distribution.
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * 3. The name of the copyright holders or contributors may not be used to
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * endorse or promote products derived from this software without
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * specific prior written permission.
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
c89589fa349f38214c9cb8d9389c0fd557e5dca2Simo Sorce * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
c89589fa349f38214c9cb8d9389c0fd557e5dca2Simo Sorce * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
c89589fa349f38214c9cb8d9389c0fd557e5dca2Simo Sorce * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
d921c1eba437662437847279f251a0a5d8f70127Maxim const char *src_orig;
d921c1eba437662437847279f251a0a5d8f70127Maxim const char *dst_orig;
327127bb7fcc07f882209f029e14026de1b23c94Maximstatic int open_cloexec(const char *pathname, int flags, int *ret)
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* we ignore an error, it's not fatal and there is nothing we
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * can do about it anyways */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic int openat_cloexec(int dir_fd, const char *pathname, int flags, int *ret)
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* we ignore an error, it's not fatal and there is nothing we
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * can do about it anyways */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic int sss_timeat_set(int dir_fd, const char *path,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ret = utimensat(dir_fd, path, timebuf, flags);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic int sss_futime_set(int fd, const struct stat *statp)
return EOK;
int parent_fd,
const char *dir_name,
int ret;
if (!tmp_ctx) {
return ENOMEM;
return ret;
int parent_fd,
const char *dir_name,
int dir_fd;
return ret;
goto fail;
if (ret != 0) {
goto fail;
goto fail;
goto fail;
if (ret != 0) {
goto fail;
if (ret != 0) {
goto fail;
fail:
if (err) {
return ret;
const char *filename)
char *buffer;
char *new_buffer;
if (!buffer) {
return NULL;
if (nchars < 0) {
return NULL;
if (!new_buffer) {
return NULL;
return buffer;
int dst_dir_fd,
const char *file_name,
const char *full_path,
char *buf;
if (!buf) {
return ENOMEM;
if (ret != 0) {
return EOK;
return ret;
return ret;
return EOK;
const char *file_name,
const char *full_path,
int ret;
if (ret != 0) {
if (ret != 0) {
return ret;
if (ret != 0) {
return ret;
if (ret != 0) {
return ret;
return EOK;
int dest_dir_fd,
const char *file_name,
const char *full_path,
if (ret != 0) {
goto done;
goto done;
errno = 0;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
static errno_t
const char *dest_dir_path,
static errno_t
int src_dir_fd,
const char *src_dir_path,
int dest_dir_fd,
const char *dest_dir_path,
const char *ent_name)
goto done;
goto done;
goto done;
goto done;
if (ret != 0) {
goto done;
&st);
goto done;
if (ret) {
goto done;
if (ret) {
goto done;
done:
return ret;
static errno_t
const char *dest_dir_path,
if (!dest_dir_path) {
return EINVAL;
goto done;
errno = 0;
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
goto fail;
goto fail;
if (!cctx) {
goto fail;
goto fail;
fail:
return ret;