4 * Copyright (C) Jim McDonough, 2006
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "nfs4_acls.h"
24 #define DBGC_CLASS DBGC_ACLS
26 #define SMBACL4_PARAM_TYPE_NAME "nfs4"
28 extern const struct generic_mapping file_generic_mapping
;
30 #define SMB_ACE4_INT_MAGIC 0x76F8A967
31 typedef struct _SMB_ACE4_INT_T
38 #define SMB_ACL4_INT_MAGIC 0x29A3E792
39 typedef struct _SMB_ACL4_INT_T
43 SMB_ACE4_INT_T
*first
;
47 extern struct current_user current_user
;
48 extern int try_chown(connection_struct
*conn
, const char *fname
, uid_t uid
, gid_t gid
);
49 extern NTSTATUS
unpack_nt_owners(int snum
, uid_t
*puser
, gid_t
*pgrp
,
50 uint32 security_info_sent
, SEC_DESC
*psd
);
52 static SMB_ACL4_INT_T
*get_validated_aclint(SMB4ACL_T
*acl
)
54 SMB_ACL4_INT_T
*aclint
= (SMB_ACL4_INT_T
*)acl
;
57 DEBUG(2, ("acl is NULL\n"));
61 if (aclint
->magic
!=SMB_ACL4_INT_MAGIC
)
63 DEBUG(2, ("aclint bad magic 0x%x\n", aclint
->magic
));
70 static SMB_ACE4_INT_T
*get_validated_aceint(SMB4ACE_T
*ace
)
72 SMB_ACE4_INT_T
*aceint
= (SMB_ACE4_INT_T
*)ace
;
75 DEBUG(2, ("ace is NULL\n"));
79 if (aceint
->magic
!=SMB_ACE4_INT_MAGIC
)
81 DEBUG(2, ("aceint bad magic 0x%x\n", aceint
->magic
));
88 SMB4ACL_T
*smb_create_smb4acl(void)
90 TALLOC_CTX
*mem_ctx
= talloc_tos();
91 SMB_ACL4_INT_T
*acl
= (SMB_ACL4_INT_T
*)TALLOC_ZERO_SIZE(mem_ctx
, sizeof(SMB_ACL4_INT_T
));
94 DEBUG(0, ("TALLOC_SIZE failed\n"));
98 acl
->magic
= SMB_ACL4_INT_MAGIC
;
99 /* acl->first, last = NULL not needed */
100 return (SMB4ACL_T
*)acl
;
103 SMB4ACE_T
*smb_add_ace4(SMB4ACL_T
*acl
, SMB_ACE4PROP_T
*prop
)
105 SMB_ACL4_INT_T
*aclint
= get_validated_aclint(acl
);
106 TALLOC_CTX
*mem_ctx
= talloc_tos();
109 ace
= (SMB_ACE4_INT_T
*)TALLOC_ZERO_SIZE(mem_ctx
, sizeof(SMB_ACE4_INT_T
));
112 DEBUG(0, ("TALLOC_SIZE failed\n"));
116 ace
->magic
= SMB_ACE4_INT_MAGIC
;
117 /* ace->next = NULL not needed */
118 memcpy(&ace
->prop
, prop
, sizeof(SMB_ACE4PROP_T
));
120 if (aclint
->first
==NULL
)
125 aclint
->last
->next
= (void *)ace
;
130 return (SMB4ACE_T
*)ace
;
133 SMB_ACE4PROP_T
*smb_get_ace4(SMB4ACE_T
*ace
)
135 SMB_ACE4_INT_T
*aceint
= get_validated_aceint(ace
);
139 return &aceint
->prop
;
142 SMB4ACE_T
*smb_next_ace4(SMB4ACE_T
*ace
)
144 SMB_ACE4_INT_T
*aceint
= get_validated_aceint(ace
);
148 return (SMB4ACE_T
*)aceint
->next
;
151 SMB4ACE_T
*smb_first_ace4(SMB4ACL_T
*acl
)
153 SMB_ACL4_INT_T
*aclint
= get_validated_aclint(acl
);
157 return (SMB4ACE_T
*)aclint
->first
;
160 uint32
smb_get_naces(SMB4ACL_T
*acl
)
162 SMB_ACL4_INT_T
*aclint
= get_validated_aclint(acl
);
166 return aclint
->naces
;
169 static int smbacl4_GetFileOwner(struct connection_struct
*conn
,
170 const char *filename
,
171 SMB_STRUCT_STAT
*psbuf
)
173 memset(psbuf
, 0, sizeof(SMB_STRUCT_STAT
));
175 /* Get the stat struct for the owner info. */
176 if (SMB_VFS_STAT(conn
, filename
, psbuf
) != 0)
178 DEBUG(8, ("SMB_VFS_STAT failed with error %s\n",
186 static int smbacl4_fGetFileOwner(files_struct
*fsp
, SMB_STRUCT_STAT
*psbuf
)
188 memset(psbuf
, 0, sizeof(SMB_STRUCT_STAT
));
190 if (fsp
->is_directory
|| fsp
->fh
->fd
== -1) {
191 return smbacl4_GetFileOwner(fsp
->conn
, fsp
->fsp_name
, psbuf
);
193 if (SMB_VFS_FSTAT(fsp
, psbuf
) != 0)
195 DEBUG(8, ("SMB_VFS_FSTAT failed with error %s\n",
203 static bool smbacl4_nfs42win(TALLOC_CTX
*mem_ctx
, SMB4ACL_T
*acl
, /* in */
204 DOM_SID
*psid_owner
, /* in */
205 DOM_SID
*psid_group
, /* in */
206 SEC_ACE
**ppnt_ace_list
, /* out */
207 int *pgood_aces
/* out */
210 SMB_ACL4_INT_T
*aclint
= (SMB_ACL4_INT_T
*)acl
;
211 SMB_ACE4_INT_T
*aceint
;
212 SEC_ACE
*nt_ace_list
= NULL
;
215 DEBUG(10, ("smbacl_nfs42win entered"));
217 aclint
= get_validated_aclint(acl
);
218 /* We do not check for naces being 0 or acl being NULL here because it is done upstream */
219 /* in smb_get_nt_acl_nfs4(). */
220 nt_ace_list
= (SEC_ACE
*)TALLOC_ZERO_SIZE(mem_ctx
, aclint
->naces
* sizeof(SEC_ACE
));
221 if (nt_ace_list
==NULL
)
223 DEBUG(10, ("talloc error"));
228 for (aceint
=aclint
->first
; aceint
!=NULL
; aceint
=(SMB_ACE4_INT_T
*)aceint
->next
) {
231 SMB_ACE4PROP_T
*ace
= &aceint
->prop
;
233 DEBUG(10, ("magic: 0x%x, type: %d, iflags: %x, flags: %x, mask: %x, "
234 "who: %d\n", aceint
->magic
, ace
->aceType
, ace
->flags
,
235 ace
->aceFlags
, ace
->aceMask
, ace
->who
.id
));
237 SMB_ASSERT(aceint
->magic
==SMB_ACE4_INT_MAGIC
);
239 if (ace
->flags
& SMB_ACE4_ID_SPECIAL
) {
240 switch (ace
->who
.special_id
) {
241 case SMB_ACE4_WHO_OWNER
:
242 sid_copy(&sid
, psid_owner
);
244 case SMB_ACE4_WHO_GROUP
:
245 sid_copy(&sid
, psid_group
);
247 case SMB_ACE4_WHO_EVERYONE
:
248 sid_copy(&sid
, &global_sid_World
);
251 DEBUG(8, ("invalid special who id %d "
252 "ignored\n", ace
->who
.special_id
));
255 if (ace
->aceFlags
& SMB_ACE4_IDENTIFIER_GROUP
) {
256 gid_to_sid(&sid
, ace
->who
.gid
);
258 uid_to_sid(&sid
, ace
->who
.uid
);
261 DEBUG(10, ("mapped %d to %s\n", ace
->who
.id
,
262 sid_string_dbg(&sid
)));
264 init_sec_access(&mask
, ace
->aceMask
);
265 init_sec_ace(&nt_ace_list
[good_aces
++], &sid
,
267 ace
->aceFlags
& 0xf);
270 *ppnt_ace_list
= nt_ace_list
;
271 *pgood_aces
= good_aces
;
276 static NTSTATUS
smb_get_nt_acl_nfs4_common(const SMB_STRUCT_STAT
*sbuf
,
277 uint32 security_info
,
278 SEC_DESC
**ppdesc
, SMB4ACL_T
*acl
)
281 DOM_SID sid_owner
, sid_group
;
283 SEC_ACE
*nt_ace_list
= NULL
;
285 TALLOC_CTX
*mem_ctx
= talloc_tos();
287 if (acl
==NULL
|| smb_get_naces(acl
)==0)
288 return NT_STATUS_ACCESS_DENIED
; /* special because we
289 * shouldn't alloc 0 for
292 uid_to_sid(&sid_owner
, sbuf
->st_uid
);
293 gid_to_sid(&sid_group
, sbuf
->st_gid
);
295 if (smbacl4_nfs42win(mem_ctx
, acl
, &sid_owner
, &sid_group
, &nt_ace_list
, &good_aces
)==False
) {
296 DEBUG(8,("smbacl4_nfs42win failed\n"));
297 return map_nt_error_from_unix(errno
);
300 psa
= make_sec_acl(mem_ctx
, NT4_ACL_REVISION
, good_aces
, nt_ace_list
);
302 DEBUG(2,("make_sec_acl failed\n"));
303 return NT_STATUS_NO_MEMORY
;
306 DEBUG(10,("after make sec_acl\n"));
307 *ppdesc
= make_sec_desc(mem_ctx
, SEC_DESC_REVISION
, SEC_DESC_SELF_RELATIVE
,
308 (security_info
& OWNER_SECURITY_INFORMATION
) ? &sid_owner
: NULL
,
309 (security_info
& GROUP_SECURITY_INFORMATION
) ? &sid_group
: NULL
,
310 NULL
, psa
, &sd_size
);
312 DEBUG(2,("make_sec_desc failed\n"));
313 return NT_STATUS_NO_MEMORY
;
316 DEBUG(10, ("smb_get_nt_acl_nfs4_common successfully exited with sd_size %d\n",
317 ndr_size_security_descriptor(*ppdesc
, 0)));
322 NTSTATUS
smb_fget_nt_acl_nfs4(files_struct
*fsp
,
323 uint32 security_info
,
324 SEC_DESC
**ppdesc
, SMB4ACL_T
*acl
)
326 SMB_STRUCT_STAT sbuf
;
328 DEBUG(10, ("smb_fget_nt_acl_nfs4 invoked for %s\n", fsp
->fsp_name
));
330 if (smbacl4_fGetFileOwner(fsp
, &sbuf
)) {
331 return map_nt_error_from_unix(errno
);
334 return smb_get_nt_acl_nfs4_common(&sbuf
, security_info
, ppdesc
, acl
);
337 NTSTATUS
smb_get_nt_acl_nfs4(struct connection_struct
*conn
,
339 uint32 security_info
,
340 SEC_DESC
**ppdesc
, SMB4ACL_T
*acl
)
342 SMB_STRUCT_STAT sbuf
;
344 DEBUG(10, ("smb_get_nt_acl_nfs4 invoked for %s\n", name
));
346 if (smbacl4_GetFileOwner(conn
, name
, &sbuf
)) {
347 return map_nt_error_from_unix(errno
);
350 return smb_get_nt_acl_nfs4_common(&sbuf
, security_info
, ppdesc
, acl
);
353 enum smbacl4_mode_enum
{e_simple
=0, e_special
=1};
354 enum smbacl4_acedup_enum
{e_dontcare
=0, e_reject
=1, e_ignore
=2, e_merge
=3};
356 typedef struct _smbacl4_vfs_params
{
357 enum smbacl4_mode_enum mode
;
359 enum smbacl4_acedup_enum acedup
;
360 struct db_context
*sid_mapping_table
;
361 } smbacl4_vfs_params
;
364 * Gather special parameters for NFS4 ACL handling
366 static int smbacl4_get_vfs_params(
367 const char *type_name
,
369 smbacl4_vfs_params
*params
372 static const struct enum_list enum_smbacl4_modes
[] = {
373 { e_simple
, "simple" },
374 { e_special
, "special" }
376 static const struct enum_list enum_smbacl4_acedups
[] = {
377 { e_dontcare
, "dontcare" },
378 { e_reject
, "reject" },
379 { e_ignore
, "ignore" },
380 { e_merge
, "merge" },
383 memset(params
, 0, sizeof(smbacl4_vfs_params
));
384 params
->mode
= (enum smbacl4_mode_enum
)lp_parm_enum(
385 SNUM(fsp
->conn
), type_name
,
386 "mode", enum_smbacl4_modes
, e_simple
);
387 params
->do_chown
= lp_parm_bool(SNUM(fsp
->conn
), type_name
,
389 params
->acedup
= (enum smbacl4_acedup_enum
)lp_parm_enum(
390 SNUM(fsp
->conn
), type_name
,
391 "acedup", enum_smbacl4_acedups
, e_dontcare
);
393 DEBUG(10, ("mode:%s, do_chown:%s, acedup: %s\n",
394 enum_smbacl4_modes
[params
->mode
].name
,
395 params
->do_chown
? "true" : "false",
396 enum_smbacl4_acedups
[params
->acedup
].name
));
401 static void smbacl4_dump_nfs4acl(int level
, SMB4ACL_T
*acl
)
403 SMB_ACL4_INT_T
*aclint
= get_validated_aclint(acl
);
404 SMB_ACE4_INT_T
*aceint
;
406 DEBUG(level
, ("NFS4ACL: size=%d\n", aclint
->naces
));
408 for(aceint
= aclint
->first
; aceint
!=NULL
; aceint
=(SMB_ACE4_INT_T
*)aceint
->next
) {
409 SMB_ACE4PROP_T
*ace
= &aceint
->prop
;
411 DEBUG(level
, ("\tACE: type=%d, flags=0x%x, fflags=0x%x, mask=0x%x, id=%d\n",
413 ace
->aceFlags
, ace
->flags
,
420 * Find 2 NFS4 who-special ACE property (non-copy!!!)
421 * match nonzero if "special" and who is equal
422 * return ace if found matching; otherwise NULL
424 static SMB_ACE4PROP_T
*smbacl4_find_equal_special(
426 SMB_ACE4PROP_T
*aceNew
)
428 SMB_ACL4_INT_T
*aclint
= get_validated_aclint(acl
);
429 SMB_ACE4_INT_T
*aceint
;
431 for(aceint
= aclint
->first
; aceint
!=NULL
; aceint
=(SMB_ACE4_INT_T
*)aceint
->next
) {
432 SMB_ACE4PROP_T
*ace
= &aceint
->prop
;
434 if (ace
->flags
== aceNew
->flags
&&
435 ace
->aceType
==aceNew
->aceType
&&
436 (ace
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)==
437 (aceNew
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
439 /* keep type safety; e.g. gid is an u.short */
440 if (ace
->flags
& SMB_ACE4_ID_SPECIAL
)
442 if (ace
->who
.special_id
==aceNew
->who
.special_id
)
445 if (ace
->aceFlags
& SMB_ACE4_IDENTIFIER_GROUP
)
447 if (ace
->who
.gid
==aceNew
->who
.gid
)
450 if (ace
->who
.uid
==aceNew
->who
.uid
)
460 static bool nfs4_map_sid(smbacl4_vfs_params
*params
, const DOM_SID
*src
,
463 static struct db_context
*mapping_db
= NULL
;
466 if (mapping_db
== NULL
) {
467 const char *dbname
= lp_parm_const_string(
468 -1, SMBACL4_PARAM_TYPE_NAME
, "sidmap", NULL
);
470 if (dbname
== NULL
) {
471 DEBUG(10, ("%s:sidmap not defined\n",
472 SMBACL4_PARAM_TYPE_NAME
));
477 mapping_db
= db_open(NULL
, dbname
, 0, TDB_DEFAULT
,
481 if (mapping_db
== NULL
) {
482 DEBUG(1, ("could not open sidmap: %s\n",
488 if (mapping_db
->fetch(mapping_db
, NULL
,
489 string_term_tdb_data(sid_string_tos(src
)),
491 DEBUG(10, ("could not find mapping for SID %s\n",
492 sid_string_dbg(src
)));
496 if ((data
.dptr
== NULL
) || (data
.dsize
<= 0)
497 || (data
.dptr
[data
.dsize
-1] != '\0')) {
498 DEBUG(5, ("invalid mapping for SID %s\n",
499 sid_string_dbg(src
)));
500 TALLOC_FREE(data
.dptr
);
504 if (!string_to_sid(dst
, (char *)data
.dptr
)) {
505 DEBUG(1, ("invalid mapping %s for SID %s\n",
506 (char *)data
.dptr
, sid_string_dbg(src
)));
507 TALLOC_FREE(data
.dptr
);
511 TALLOC_FREE(data
.dptr
);
516 static bool smbacl4_fill_ace4(
518 const char *filename
,
519 smbacl4_vfs_params
*params
,
522 SEC_ACE
*ace_nt
, /* input */
523 SMB_ACE4PROP_T
*ace_v4
/* output */
526 DEBUG(10, ("got ace for %s\n", sid_string_dbg(&ace_nt
->trustee
)));
528 memset(ace_v4
, 0, sizeof(SMB_ACE4PROP_T
));
529 ace_v4
->aceType
= ace_nt
->type
; /* only ACCESS|DENY supported right now */
530 ace_v4
->aceFlags
= ace_nt
->flags
& SEC_ACE_FLAG_VALID_INHERIT
;
531 ace_v4
->aceMask
= ace_nt
->access_mask
&
532 (STD_RIGHT_ALL_ACCESS
| SA_RIGHT_FILE_ALL_ACCESS
);
534 se_map_generic(&ace_v4
->aceMask
, &file_generic_mapping
);
536 if (ace_v4
->aceFlags
!=ace_nt
->flags
)
537 DEBUG(9, ("ace_v4->aceFlags(0x%x)!=ace_nt->flags(0x%x)\n",
538 ace_v4
->aceFlags
, ace_nt
->flags
));
540 if (ace_v4
->aceMask
!=ace_nt
->access_mask
)
541 DEBUG(9, ("ace_v4->aceMask(0x%x)!=ace_nt->access_mask(0x%x)\n",
542 ace_v4
->aceMask
, ace_nt
->access_mask
));
544 if (sid_equal(&ace_nt
->trustee
, &global_sid_World
)) {
545 ace_v4
->who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
546 ace_v4
->flags
|= SMB_ACE4_ID_SPECIAL
;
548 const char *dom
, *name
;
549 enum lsa_SidType type
;
554 sid_copy(&sid
, &ace_nt
->trustee
);
556 if (!lookup_sid(mem_ctx
, &sid
, &dom
, &name
, &type
)) {
560 if (!nfs4_map_sid(params
, &sid
, &mapped
)) {
561 DEBUG(1, ("nfs4_acls.c: file [%s]: SID %s "
562 "unknown\n", filename
, sid_string_dbg(&sid
)));
567 DEBUG(2, ("nfs4_acls.c: file [%s]: mapped SID %s "
568 "to %s\n", filename
, sid_string_dbg(&sid
), sid_string_dbg(&mapped
)));
570 if (!lookup_sid(mem_ctx
, &mapped
, &dom
,
572 DEBUG(1, ("nfs4_acls.c: file [%s]: SID %s "
573 "mapped from %s is unknown\n",
574 filename
, sid_string_dbg(&mapped
), sid_string_dbg(&sid
)));
579 sid_copy(&sid
, &mapped
);
582 if (type
== SID_NAME_USER
) {
583 if (!sid_to_uid(&sid
, &uid
)) {
584 DEBUG(1, ("nfs4_acls.c: file [%s]: could not "
585 "convert %s to uid\n", filename
,
586 sid_string_dbg(&sid
)));
590 if (params
->mode
==e_special
&& uid
==ownerUID
) {
591 ace_v4
->flags
|= SMB_ACE4_ID_SPECIAL
;
592 ace_v4
->who
.special_id
= SMB_ACE4_WHO_OWNER
;
594 ace_v4
->who
.uid
= uid
;
596 } else { /* else group? - TODO check it... */
597 if (!sid_to_gid(&sid
, &gid
)) {
598 DEBUG(1, ("nfs4_acls.c: file [%s]: could not "
599 "convert %s to gid\n", filename
,
600 sid_string_dbg(&sid
)));
604 ace_v4
->aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
606 if (params
->mode
==e_special
&& gid
==ownerGID
) {
607 ace_v4
->flags
|= SMB_ACE4_ID_SPECIAL
;
608 ace_v4
->who
.special_id
= SMB_ACE4_WHO_GROUP
;
610 ace_v4
->who
.gid
= gid
;
615 return True
; /* OK */
618 static int smbacl4_MergeIgnoreReject(
619 enum smbacl4_acedup_enum acedup
,
620 SMB4ACL_T
*acl
, /* may modify it */
621 SMB_ACE4PROP_T
*ace
, /* the "new" ACE */
627 SMB_ACE4PROP_T
*ace4found
= smbacl4_find_equal_special(acl
, ace
);
632 case e_merge
: /* "merge" flags */
634 ace4found
->aceFlags
|= ace
->aceFlags
;
635 ace4found
->aceMask
|= ace
->aceMask
;
637 case e_ignore
: /* leave out this record */
640 case e_reject
: /* do an error */
641 DEBUG(8, ("ACL rejected by duplicate nt ace#%d\n", i
));
642 errno
= EINVAL
; /* SHOULD be set on any _real_ error */
652 static SMB4ACL_T
*smbacl4_win2nfs4(
653 const char *filename
,
655 smbacl4_vfs_params
*pparams
,
662 TALLOC_CTX
*mem_ctx
= talloc_tos();
664 DEBUG(10, ("smbacl4_win2nfs4 invoked\n"));
666 acl
= smb_create_smb4acl();
670 for(i
=0; i
<dacl
->num_aces
; i
++) {
671 SMB_ACE4PROP_T ace_v4
;
672 bool addNewACE
= True
;
674 if (!smbacl4_fill_ace4(mem_ctx
, filename
, pparams
,
676 dacl
->aces
+ i
, &ace_v4
)) {
677 DEBUG(3, ("Could not fill ace for file %s, SID %s\n",
679 sid_string_dbg(&((dacl
->aces
+i
)->trustee
))));
683 if (pparams
->acedup
!=e_dontcare
) {
684 if (smbacl4_MergeIgnoreReject(pparams
->acedup
, acl
,
685 &ace_v4
, &addNewACE
, i
))
690 smb_add_ace4(acl
, &ace_v4
);
696 NTSTATUS
smb_set_nt_acl_nfs4(files_struct
*fsp
,
697 uint32 security_info_sent
,
699 set_nfs4acl_native_fn_t set_nfs4_native
)
701 smbacl4_vfs_params params
;
702 SMB4ACL_T
*acl
= NULL
;
705 SMB_STRUCT_STAT sbuf
;
706 bool need_chown
= False
;
707 uid_t newUID
= (uid_t
)-1;
708 gid_t newGID
= (gid_t
)-1;
710 DEBUG(10, ("smb_set_nt_acl_nfs4 invoked for %s\n", fsp
->fsp_name
));
712 if ((security_info_sent
& (DACL_SECURITY_INFORMATION
|
713 GROUP_SECURITY_INFORMATION
| OWNER_SECURITY_INFORMATION
)) == 0)
715 DEBUG(9, ("security_info_sent (0x%x) ignored\n",
716 security_info_sent
));
717 return NT_STATUS_OK
; /* won't show error - later to be refined... */
720 /* Special behaviours */
721 if (smbacl4_get_vfs_params(SMBACL4_PARAM_TYPE_NAME
, fsp
, ¶ms
))
722 return NT_STATUS_NO_MEMORY
;
724 if (smbacl4_fGetFileOwner(fsp
, &sbuf
))
725 return map_nt_error_from_unix(errno
);
727 if (params
.do_chown
) {
728 /* chown logic is a copy/paste from posix_acl.c:set_nt_acl */
729 NTSTATUS status
= unpack_nt_owners(SNUM(fsp
->conn
), &newUID
, &newGID
, security_info_sent
, psd
);
730 if (!NT_STATUS_IS_OK(status
)) {
731 DEBUG(8, ("unpack_nt_owners failed"));
734 if (((newUID
!= (uid_t
)-1) && (sbuf
.st_uid
!= newUID
)) ||
735 ((newGID
!= (gid_t
)-1) && (sbuf
.st_gid
!= newGID
))) {
739 if ((newUID
== (uid_t
)-1 || newUID
== current_user
.ut
.uid
)) {
740 if(try_chown(fsp
->conn
, fsp
->fsp_name
, newUID
, newGID
)) {
741 DEBUG(3,("chown %s, %u, %u failed. Error = %s.\n",
742 fsp
->fsp_name
, (unsigned int)newUID
, (unsigned int)newGID
,
744 return map_nt_error_from_unix(errno
);
747 DEBUG(10,("chown %s, %u, %u succeeded.\n",
748 fsp
->fsp_name
, (unsigned int)newUID
, (unsigned int)newGID
));
749 if (smbacl4_GetFileOwner(fsp
->conn
, fsp
->fsp_name
, &sbuf
))
750 return map_nt_error_from_unix(errno
);
752 } else { /* chown is needed, but _after_ changing acl */
753 sbuf
.st_uid
= newUID
; /* OWNER@ in case of e_special */
754 sbuf
.st_gid
= newGID
; /* GROUP@ in case of e_special */
759 if ((security_info_sent
& DACL_SECURITY_INFORMATION
)!=0 && psd
->dacl
!=NULL
)
761 acl
= smbacl4_win2nfs4(fsp
->fsp_name
, psd
->dacl
, ¶ms
, sbuf
.st_uid
, sbuf
.st_gid
);
763 return map_nt_error_from_unix(errno
);
765 smbacl4_dump_nfs4acl(10, acl
);
767 result
= set_nfs4_native(fsp
, acl
);
770 DEBUG(10, ("set_nfs4_native failed with %s\n", strerror(errno
)));
771 return map_nt_error_from_unix(errno
);
774 DEBUG(10, ("no dacl found; security_info_sent = 0x%x\n", security_info_sent
));
776 /* Any chown pending? */
778 DEBUG(3,("chown#2 %s. uid = %u, gid = %u.\n",
779 fsp
->fsp_name
, (unsigned int)newUID
, (unsigned int)newGID
));
780 if (try_chown(fsp
->conn
, fsp
->fsp_name
, newUID
, newGID
)) {
781 DEBUG(2,("chown#2 %s, %u, %u failed. Error = %s.\n",
782 fsp
->fsp_name
, (unsigned int)newUID
, (unsigned int)newGID
,
784 return map_nt_error_from_unix(errno
);
786 DEBUG(10,("chown#2 %s, %u, %u succeeded.\n",
787 fsp
->fsp_name
, (unsigned int)newUID
, (unsigned int)newGID
));
790 DEBUG(10, ("smb_set_nt_acl_nfs4 succeeded\n"));