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