static int local_symlink(FsContext *fs_ctx, const char *oldpath,

        const char *newpath, FsCred *credp)

{

    int err = -1;

    int serrno = 0;



    /* Determine the security model */

    if (fs_ctx->fs_sm == SM_MAPPED) {

        int fd;

        ssize_t oldpath_size, write_size;

        fd = open(rpath(fs_ctx, newpath), O_CREAT|O_EXCL|O_RDWR,

                SM_LOCAL_MODE_BITS);

        if (fd == -1) {

            return fd;

        }

        /* Write the oldpath (target) to the file. */

        oldpath_size = strlen(oldpath) + 1;

        do {

            write_size = write(fd, (void *)oldpath, oldpath_size);

        } while (write_size == -1 && errno == EINTR);



        if (write_size != oldpath_size) {

            serrno = errno;

            close(fd);

            err = -1;

            goto err_end;

        }

        close(fd);

        /* Set cleint credentials in symlink's xattr */

        credp->fc_mode = credp->fc_mode|S_IFLNK;

        err = local_set_xattr(rpath(fs_ctx, newpath), credp);

        if (err == -1) {

            serrno = errno;

            goto err_end;

        }

    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||

               (fs_ctx->fs_sm == SM_NONE)) {

        err = symlink(oldpath, rpath(fs_ctx, newpath));

        if (err) {

            return err;

        }

        err = lchown(rpath(fs_ctx, newpath), credp->fc_uid, credp->fc_gid);

        if (err == -1) {

            /*

             * If we fail to change ownership and if we are

             * using security model none. Ignore the error

             */

            if (fs_ctx->fs_sm != SM_NONE) {

                serrno = errno;

                goto err_end;

            } else

                err = 0;

        }

    }

    return err;



err_end:

    remove(rpath(fs_ctx, newpath));

    errno = serrno;

    return err;

}

static int local_symlink(FsContext *fs_ctx, const char *oldpath,

        const char *newpath, FsCred *credp)

{

    int err = -1;

    int serrno = 0;



    

    if (fs_ctx->fs_sm == SM_MAPPED) {

        int fd;

        ssize_t oldpath_size, write_size;

        fd = open(rpath(fs_ctx, newpath), O_CREAT|O_EXCL|O_RDWR,

                SM_LOCAL_MODE_BITS);

        if (fd == -1) {

            return fd;

        }

        

        oldpath_size = strlen(oldpath) + 1;

        do {

            write_size = write(fd, (void *)oldpath, oldpath_size);

        } while (write_size == -1 && errno == EINTR);



        if (write_size != oldpath_size) {

            serrno = errno;

            close(fd);

            err = -1;

            goto err_end;

        }

        close(fd);

        

        credp->fc_mode = credp->fc_mode|S_IFLNK;

        err = local_set_xattr(rpath(fs_ctx, newpath), credp);

        if (err == -1) {

            serrno = errno;

            goto err_end;

        }

    } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||

               (fs_ctx->fs_sm == SM_NONE)) {

        err = symlink(oldpath, rpath(fs_ctx, newpath));

        if (err) {

            return err;

        }

        err = lchown(rpath(fs_ctx, newpath), credp->fc_uid, credp->fc_gid);

        if (err == -1) {

            







            if (fs_ctx->fs_sm != SM_NONE) {

                serrno = errno;

                goto err_end;

            } else

                err = 0;

        }

    }

    return err;



err_end:

    remove(rpath(fs_ctx, newpath));

    errno = serrno;

    return err;

}

        oldpath_size = strlen(oldpath) + 1;
static int FUNC_0(FsContext *VAR_0, const char *VAR_1,

        const char *VAR_2, FsCred *VAR_3)

{

    int VAR_4 = -1;

    int VAR_5 = 0;



    

    if (VAR_0->fs_sm == SM_MAPPED) {

        int VAR_6;

        ssize_t oldpath_size, write_size;

        VAR_6 = open(rpath(VAR_0, VAR_2), O_CREAT|O_EXCL|O_RDWR,

                SM_LOCAL_MODE_BITS);

        if (VAR_6 == -1) {

            return VAR_6;

        }

        

        oldpath_size = strlen(VAR_1) + 1;

        do {

            write_size = write(VAR_6, (void *)VAR_1, oldpath_size);

        } while (write_size == -1 && errno == EINTR);



        if (write_size != oldpath_size) {

            VAR_5 = errno;

            close(VAR_6);

            VAR_4 = -1;

            goto err_end;

        }

        close(VAR_6);

        

        VAR_3->fc_mode = VAR_3->fc_mode|S_IFLNK;

        VAR_4 = local_set_xattr(rpath(VAR_0, VAR_2), VAR_3);

        if (VAR_4 == -1) {

            VAR_5 = errno;

            goto err_end;

        }

    } else if ((VAR_0->fs_sm == SM_PASSTHROUGH) ||

               (VAR_0->fs_sm == SM_NONE)) {

        VAR_4 = symlink(VAR_1, rpath(VAR_0, VAR_2));

        if (VAR_4) {

            return VAR_4;

        }

        VAR_4 = lchown(rpath(VAR_0, VAR_2), VAR_3->fc_uid, VAR_3->fc_gid);

        if (VAR_4 == -1) {

            







            if (VAR_0->fs_sm != SM_NONE) {

                VAR_5 = errno;

                goto err_end;

            } else

                VAR_4 = 0;

        }

    }

    return VAR_4;



err_end:

    remove(rpath(VAR_0, VAR_2));

    errno = VAR_5;

    return VAR_4;

}

static int FUNC_0(FsContext *VAR_0, const char *VAR_1,
const char *VAR_2, FsCred *VAR_3)
{ int VAR_4 = -1; int VAR_5 = 0; if (VAR_0->fs_sm == SM_MAPPED) { int VAR_6; ssize_t oldpath_size, write_size; VAR_6 = open(rpath(VAR_0, VAR_2), O_CREAT|O_EXCL|O_RDWR,
SM_LOCAL_MODE_BITS); if (VAR_6 == -1) { return VAR_6; } oldpath_size = strlen(VAR_1) + 1; do { write_size = write(VAR_6, (void *)VAR_1, oldpath_size); } while (write_size == -1 && errno == EINTR); if (write_size != oldpath_size) { VAR_5 = errno; close(VAR_6); VAR_4 = -1; goto err_end; } close(VAR_6); VAR_3->fc_mode = VAR_3->fc_mode|S_IFLNK; VAR_4 = local_set_xattr(rpath(VAR_0, VAR_2), VAR_3); if (VAR_4 == -1) { VAR_5 = errno; goto err_end; } } else if ((VAR_0->fs_sm == SM_PASSTHROUGH) || (VAR_0->fs_sm == SM_NONE)) { VAR_4 = symlink(VAR_1, rpath(VAR_0, VAR_2)); if (VAR_4) { return VAR_4; } VAR_4 = lchown(rpath(VAR_0, VAR_2), VAR_3->fc_uid, VAR_3->fc_gid); if (VAR_4 == -1) { if (VAR_0->fs_sm != SM_NONE) { VAR_5 = errno; goto err_end; } else VAR_4 = 0; } } return VAR_4; err_end:
remove(rpath(VAR_0, VAR_2)); errno = VAR_5; return VAR_4; }