1*8329232eSGordon Ross /*
2*8329232eSGordon Ross  * CDDL HEADER START
3*8329232eSGordon Ross  *
4*8329232eSGordon Ross  * The contents of this file are subject to the terms of the
5*8329232eSGordon Ross  * Common Development and Distribution License (the "License").
6*8329232eSGordon Ross  * You may not use this file except in compliance with the License.
7*8329232eSGordon Ross  *
8*8329232eSGordon Ross  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*8329232eSGordon Ross  * or http://www.opensolaris.org/os/licensing.
10*8329232eSGordon Ross  * See the License for the specific language governing permissions
11*8329232eSGordon Ross  * and limitations under the License.
12*8329232eSGordon Ross  *
13*8329232eSGordon Ross  * When distributing Covered Code, include this CDDL HEADER in each
14*8329232eSGordon Ross  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*8329232eSGordon Ross  * If applicable, add the following below this CDDL HEADER, with the
16*8329232eSGordon Ross  * fields enclosed by brackets "[]" replaced with your own identifying
17*8329232eSGordon Ross  * information: Portions Copyright [yyyy] [name of copyright owner]
18*8329232eSGordon Ross  *
19*8329232eSGordon Ross  * CDDL HEADER END
20*8329232eSGordon Ross  */
21*8329232eSGordon Ross 
22*8329232eSGordon Ross /*
23*8329232eSGordon Ross  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
24*8329232eSGordon Ross  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
25*8329232eSGordon Ross  */
26*8329232eSGordon Ross 
27*8329232eSGordon Ross /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28*8329232eSGordon Ross /*	  All Rights Reserved	*/
29*8329232eSGordon Ross 
30*8329232eSGordon Ross /*
31*8329232eSGordon Ross  * Portions of this source code were derived from Berkeley 4.3 BSD
32*8329232eSGordon Ross  * under license from the Regents of the University of California.
33*8329232eSGordon Ross  */
34*8329232eSGordon Ross 
35*8329232eSGordon Ross /*
36*8329232eSGordon Ross  * Modified version of syscall/unlink.c
37*8329232eSGordon Ross  */
38*8329232eSGordon Ross 
39*8329232eSGordon Ross #include <sys/param.h>
40*8329232eSGordon Ross #include <sys/isa_defs.h>
41*8329232eSGordon Ross #include <sys/types.h>
42*8329232eSGordon Ross #include <sys/sysmacros.h>
43*8329232eSGordon Ross #include <sys/systm.h>
44*8329232eSGordon Ross #include <sys/errno.h>
45*8329232eSGordon Ross #include <sys/vnode.h>
46*8329232eSGordon Ross #include <sys/vfs.h>
47*8329232eSGordon Ross #include <sys/uio.h>
48*8329232eSGordon Ross #include <sys/debug.h>
49*8329232eSGordon Ross #include <sys/file.h>
50*8329232eSGordon Ross #include <sys/fcntl.h>
51*8329232eSGordon Ross 
52*8329232eSGordon Ross #include <libfksmbfs.h>
53*8329232eSGordon Ross 
54*8329232eSGordon Ross /*
55*8329232eSGordon Ross  * Unlink a file from a directory
56*8329232eSGordon Ross  * Like syscall/unlinkat.c
57*8329232eSGordon Ross  */
58*8329232eSGordon Ross int
fake_unlink(char * path,int flags)59*8329232eSGordon Ross fake_unlink(char *path, int flags)
60*8329232eSGordon Ross {
61*8329232eSGordon Ross 	vnode_t *dvp = NULL;
62*8329232eSGordon Ross 	char *lastcomp = NULL;
63*8329232eSGordon Ross 	int error;
64*8329232eSGordon Ross 
65*8329232eSGordon Ross 	if (path == NULL)
66*8329232eSGordon Ross 		return (EFAULT);
67*8329232eSGordon Ross 
68*8329232eSGordon Ross 	error = fake_lookup_dir(path, &dvp, &lastcomp);
69*8329232eSGordon Ross 	if (error != 0)
70*8329232eSGordon Ross 		return (error);
71*8329232eSGordon Ross 
72*8329232eSGordon Ross 	/*
73*8329232eSGordon Ross 	 * Some logic from vn_removeat() here
74*8329232eSGordon Ross 	 */
75*8329232eSGordon Ross 	if (dvp->v_vfsp->vfs_flag & VFS_RDONLY) {
76*8329232eSGordon Ross 		error = EROFS;
77*8329232eSGordon Ross 		goto out;
78*8329232eSGordon Ross 	}
79*8329232eSGordon Ross 
80*8329232eSGordon Ross 	if (flags == AT_REMOVEDIR) {
81*8329232eSGordon Ross 		error = VOP_RMDIR(dvp, lastcomp, NULL, CRED(), NULL, 0);
82*8329232eSGordon Ross 	} else {
83*8329232eSGordon Ross 		error = VOP_REMOVE(dvp, lastcomp, CRED(), NULL, 0);
84*8329232eSGordon Ross 	}
85*8329232eSGordon Ross 
86*8329232eSGordon Ross out:
87*8329232eSGordon Ross 	if (dvp != NULL)
88*8329232eSGordon Ross 		VN_RELE(dvp);
89*8329232eSGordon Ross 
90*8329232eSGordon Ross 	return (error);
91*8329232eSGordon Ross }