summaryrefslogtreecommitdiff
path: root/net/samba419/files/0100-Fix-pathref-handling-for-FreeBSD-13plus.patch
blob: 601a1c1c79d8713a54839d7d579b64a0d7ecf929 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
https://bugzilla.samba.org/show_bug.cgi?id=15376

--- source3/modules/vfs_zfsacl.c	2023-11-27 13:09:10.612012900 +0100
+++ source3/modules/vfs_zfsacl.c	2025-01-07 18:53:05.292522000 +0100
@@ -169,6 +169,7 @@ 
 	bool must_add_empty_ace = false;
 	struct zfsacl_config_data *config = NULL;
 	int fd;
+	char buf[PATH_MAX];
 
 	SMB_VFS_HANDLE_GET_DATA(handle, config,
 				struct zfsacl_config_data,
@@ -235,22 +236,49 @@ 
 	SMB_ASSERT(i == naces);
 
 	/* store acl */
-	fd = fsp_get_pathref_fd(fsp);
-	if (fd == -1) {
+	if (!fsp->fsp_flags.is_pathref) {
+	    fd = fsp_get_io_fd(fsp);
+	    
+	    rv = facl(fd, ACE_SETACL, naces, acebuf);
+	    if (rv != 0) {
+		DEBUG(8, ("zfs_process_smbacl(%s): Not PATHREF: facl(ACE_SETACL, %d): %s\n",
+			  fsp_str_dbg(fsp), naces,
+			  strerror(errno)));
+		return false;
+	    }
+	    DEBUG(10, ("zfs_process_smbacl(%s): Not PATHREF: facl(ACE_SETACL, %d) -> %d\n",
+		      fsp_str_dbg(fsp), naces,
+		      rv));
+	    
+	} else if (fsp->fsp_flags.have_proc_fds) {
+	    fd = fsp_get_pathref_fd(fsp);
+	    if (fd == -1) {
+		DEBUG(8, ("zfs_process_smbacl(%s): PATHREF(proc_fd): fsp_get_pathref_fd=-1: %s\n",
+			  fsp_str_dbg(fsp), strerror(errno)));
 		errno = EBADF;
 		return false;
-	}
-	rv = facl(fd, ACE_SETACL, naces, acebuf);
-	if (rv != 0) {
-		if(errno == ENOSYS) {
-			DEBUG(9, ("acl(ACE_SETACL, %s): Operation is not "
-				  "supported on the filesystem where the file "
-				  "reside", fsp_str_dbg(fsp)));
-		} else {
-			DEBUG(9, ("acl(ACE_SETACL, %s): %s ", fsp_str_dbg(fsp),
-				  strerror(errno)));
-		}
+	    }
+	    rv = acl(sys_proc_fd_path(fd, buf, sizeof(buf)), ACE_SETACL, naces, acebuf);
+	    if (rv != 0) {
+		DEBUG(8, ("zfs_process_smbacl(%s): acl(ACE_SETACL, %d): %s\n",
+			  fsp_str_dbg(fsp), naces,
+			  strerror(errno)));
 		return false;
+	    }
+	    DEBUG(10, ("zfs_process_smbacl(%s): PATHREF(proc_fd): acl(ACE_SETACL, %d) -> %d\n",
+		      fsp_str_dbg(fsp), naces,
+		      rv));
+	} else {
+	    rv = acl(fsp->fsp_name->base_name, ACE_SETACL, naces, acebuf);
+	    if (rv != 0) {
+		DEBUG(8, ("zfs_process_smbacl(%s): PATHREF(base_name): acl(ACE_SETACL, %d): %s\n",
+			  fsp_str_dbg(fsp), naces,
+			  strerror(errno)));
+		return false;
+	    }
+	    DEBUG(10, ("zfs_process_smbacl(%s): PATHREF(base_name): facl(ACE_SETACL, %d) -> %d\n",
+		      fsp_str_dbg(fsp), naces,
+		      rv));
 	}
 
 	return True;
@@ -282,25 +310,48 @@ 
 		       struct files_struct *fsp,
 		       ace_t **outbuf)
 {
-	int naces, rv;
+	int naces, rv = -1, fd = -1;
 	ace_t *acebuf = NULL;
-	int fd;
 
-	fd = fsp_get_pathref_fd(fsp);
-	if (fd == -1) {
+
+	char buf[PATH_MAX];
+
+
+	if (!fsp->fsp_flags.is_pathref) {
+	    fd = fsp_get_io_fd(fsp);
+	    if (fd == -1) {
+		DEBUG(8, ("fget_zfsacl(%s): Not PATHREF: fsp_get_io_fd=-1: %s\n",
+				  fsp_str_dbg(fsp), strerror(errno)));
 		errno = EBADF;
 		return -1;
-	}
-	naces = facl(fd, ACE_GETACLCNT, 0, NULL);
-	if (naces == -1) {
-		int dbg_level = 10;
-
-		if (errno == ENOSYS) {
-			dbg_level = 1;
-		}
-		DEBUG(dbg_level, ("facl(ACE_GETACLCNT, %s): %s ",
+	    }
+	    naces = facl(fd, ACE_GETACLCNT, 0, NULL);
+	    if (naces == -1) {
+		DEBUG(8, ("fget_zfsacl(%s): Not PATHREF: facl(ACE_GETACLCNT): %s\n",
+			  fsp_str_dbg(fsp), strerror(errno)));
+		return -1;
+	    }
+	} else if (fsp->fsp_flags.have_proc_fds) {
+	    fd = fsp_get_pathref_fd(fsp);
+	    if (fd == -1) {
+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(proc_fd): fsp_get_pathref_fd=-1: %s\n",
+			  fsp_str_dbg(fsp), strerror(errno)));
+		errno = EBADF;
+		return -1;
+	    }
+	    naces = acl(sys_proc_fd_path(fd, buf, sizeof(buf)), ACE_GETACLCNT, 0, NULL);
+	    if (naces == -1) {
+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(proc_fd): acl(ACE_GETACLCNT): %s\n",
 				  fsp_str_dbg(fsp), strerror(errno)));
-		return naces;
+		return -1;
+	    }
+	} else {
+	    naces = acl(fsp->fsp_name->base_name, ACE_GETACLCNT, 0, NULL);
+	    if (naces == -1) {
+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(base_name): acl(ACE_GETACLCNT): %s\n",
+				  fsp_str_dbg(fsp), strerror(errno)));
+		return -1;
+	    }
 	}
 
 	acebuf = talloc_size(mem_ctx, sizeof(ace_t)*naces);
@@ -309,15 +360,37 @@ 
 		return -1;
 	}
 
-	rv = facl(fd, ACE_GETACL, naces, acebuf);
-	if (rv == -1) {
-		DBG_DEBUG("acl(ACE_GETACL, %s): %s ",
-			  fsp_str_dbg(fsp), strerror(errno));
+	if (!fsp->fsp_flags.is_pathref) {
+	    rv = facl(fd, ACE_GETACL, naces, acebuf);
+	    if (rv == -1) {
+		DEBUG(8, ("fget_zfsacl(%s): Not PATHREF: facl(ACE_GETACL): %s\n",
+			  fsp_str_dbg(fsp), strerror(errno)));
 		return -1;
+	    }
+	    DEBUG(10, ("fget_zfsacl(%s): Not PATHREF: facl(ACE_GETACL) -> %d entries\n",
+		      fsp_str_dbg(fsp), rv));
+	} else if (fsp->fsp_flags.have_proc_fds) {
+	    rv = acl(sys_proc_fd_path(fd, buf, sizeof(buf)), ACE_GETACL, naces, acebuf);
+	    if (rv == -1) {
+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(proc_fd): acl(ACE_GETACL): %s\n",
+			  fsp_str_dbg(fsp), strerror(errno)));
+		return -1;
+	    }
+	    DEBUG(10, ("fget_zfsacl(%s): PATHREF(proc_fd): acl(ACE_GETACL) -> %d entries\n",
+		      fsp_str_dbg(fsp), rv));
+	} else {
+	    rv = acl(fsp->fsp_name->base_name, ACE_GETACL, naces, acebuf);
+	    if (rv == -1) {
+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(base_name): acl(ACE_GETACL): %s\n",
+			  fsp_str_dbg(fsp), strerror(errno)));
+		return -1;
+	    }
+	    DEBUG(10, ("fget_zfsacl(%s): PATHREF(base_name): acl(ACE_GETACL) -> %d entries\n",
+		      fsp_str_dbg(fsp), rv));
 	}
-
+
 	*outbuf = acebuf;
-	return naces;
+	return rv;
 }
 
 static NTSTATUS zfsacl_fget_nt_acl(struct vfs_handle_struct *handle,