Skip to content

Commit 5026cc8

Browse files
committed
Cygwin: get_posix_access: Make mode_t parameter mandatory
Avoid the mistake fixed in the preceeding commit by passing the mode_t argument by reference. This also affects a couple other functions calling get_posix_access in turn. Fixes: bc444e5 ("Reapply POSIX ACL changes.") Signed-off-by: Corinna Vinschen <[email protected]>
1 parent b66979e commit 5026cc8

File tree

8 files changed

+31
-36
lines changed

8 files changed

+31
-36
lines changed

winsup/cygwin/fhandler/disk_file.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,16 @@ fhandler_base::fstat_helper (struct stat *buf)
464464
else if (pc.issymlink ())
465465
{
466466
buf->st_size = pc.get_symlink_length ();
467+
get_file_attribute (h, pc, buf->st_mode,
468+
&buf->st_uid, &buf->st_gid);
467469
/* symlinks are everything for everyone! */
468470
buf->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
469-
get_file_attribute (h, pc, NULL,
470-
&buf->st_uid, &buf->st_gid);
471471
goto done;
472472
}
473473
else if (pc.issocket ())
474474
buf->st_mode = S_IFSOCK;
475475

476-
if (!get_file_attribute (h, pc, &buf->st_mode, &buf->st_uid, &buf->st_gid))
476+
if (!get_file_attribute (h, pc, buf->st_mode, &buf->st_uid, &buf->st_gid))
477477
{
478478
/* If read-only attribute is set, modify ntsec return value */
479479
if (::has_attribute (attributes, FILE_ATTRIBUTE_READONLY)
@@ -769,7 +769,7 @@ fhandler_disk_file::fchmod (mode_t mode)
769769
if (!get_file_sd (get_handle (), pc, sd, false))
770770
{
771771
aclp = (aclent_t *) tp.c_get ();
772-
if ((nentries = get_posix_access (sd, &attr, &uid, &gid,
772+
if ((nentries = get_posix_access (sd, attr, &uid, &gid,
773773
aclp, MAX_ACL_ENTRIES,
774774
&standard_acl)) >= 0)
775775
{
@@ -879,7 +879,7 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
879879
goto out;
880880

881881
aclp = (aclent_t *) tp.c_get ();
882-
if ((nentries = get_posix_access (sd, &attr, &old_uid, &old_gid,
882+
if ((nentries = get_posix_access (sd, attr, &old_uid, &old_gid,
883883
aclp, MAX_ACL_ENTRIES)) < 0)
884884
goto out;
885885

winsup/cygwin/fhandler/mqueue.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fhandler_mqueue::mqinfo_open (int flags)
251251
__seterrno_from_nt_status (status);
252252
return NULL;
253253
}
254-
if (get_file_attribute (get_handle (), pc, &mode, NULL, NULL))
254+
if (get_file_attribute (get_handle (), pc, mode, NULL, NULL))
255255
mode = STD_RBITS | STD_WBITS;
256256

257257
return _mqinfo (fsi.EndOfFile.QuadPart, mode, flags, true);

winsup/cygwin/fhandler/procsys.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fhandler_procsys::exists (struct stat *buf)
8686
{
8787
/* If requested, check permissions. */
8888
if (buf)
89-
get_object_attribute (h, &buf->st_uid, &buf->st_gid, &buf->st_mode);
89+
get_object_attribute (h, &buf->st_uid, &buf->st_gid, buf->st_mode);
9090
NtClose (h);
9191
return virt_symlink;
9292
}
@@ -99,7 +99,7 @@ fhandler_procsys::exists (struct stat *buf)
9999
{
100100
/* If requested, check permissions. */
101101
if (buf)
102-
get_object_attribute (h, &buf->st_uid, &buf->st_gid, &buf->st_mode);
102+
get_object_attribute (h, &buf->st_uid, &buf->st_gid, buf->st_mode);
103103
NtClose (h);
104104
return virt_directory;
105105
}
@@ -164,7 +164,7 @@ fhandler_procsys::exists (struct stat *buf)
164164
/* If requested, check permissions. If this is a parent handle from
165165
the above desperate parent check, skip. */
166166
if (buf && !desperate_parent_check)
167-
get_object_attribute (h, &buf->st_uid, &buf->st_gid, &buf->st_mode);
167+
get_object_attribute (h, &buf->st_uid, &buf->st_gid, buf->st_mode);
168168

169169
/* Check for the device type. */
170170
status = NtQueryVolumeInformationFile (h, &io, &ffdi, sizeof ffdi,

winsup/cygwin/fhandler/pty.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ fhandler_pty_slave::fstat (struct stat *st)
17941794
st->st_mode = S_IFCHR;
17951795
if (!input_available_event
17961796
|| get_object_attribute (input_available_event, &st->st_uid, &st->st_gid,
1797-
&st->st_mode))
1797+
st->st_mode))
17981798
{
17991799
/* If we can't access the ACL, or if the tty doesn't actually exist,
18001800
then fake uid and gid to strict, system-like values. */
@@ -1840,7 +1840,7 @@ fhandler_pty_slave::facl (int cmd, int nentries, aclent_t *aclbufp)
18401840
if (!input_available_event
18411841
|| get_object_sd (input_available_event, sd))
18421842
{
1843-
res = get_posix_access (NULL, &attr, NULL, NULL, aclbufp, nentries);
1843+
res = get_posix_access (NULL, attr, NULL, NULL, aclbufp, nentries);
18441844
if (aclbufp && res == MIN_ACL_ENTRIES)
18451845
{
18461846
aclbufp[0].a_perm = S_IROTH | S_IWOTH;
@@ -1850,9 +1850,9 @@ fhandler_pty_slave::facl (int cmd, int nentries, aclent_t *aclbufp)
18501850
break;
18511851
}
18521852
if (cmd == GETACL)
1853-
res = get_posix_access (sd, &attr, NULL, NULL, aclbufp, nentries);
1853+
res = get_posix_access (sd, attr, NULL, NULL, aclbufp, nentries);
18541854
else
1855-
res = get_posix_access (sd, &attr, NULL, NULL, NULL, 0);
1855+
res = get_posix_access (sd, attr, NULL, NULL, NULL, 0);
18561856
break;
18571857
default:
18581858
set_errno (EINVAL);
@@ -1936,7 +1936,7 @@ fhandler_pty_slave::fchmod (mode_t mode)
19361936
}
19371937
sd.malloc (sizeof (SECURITY_DESCRIPTOR));
19381938
RtlCreateSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
1939-
if (!get_object_attribute (input_available_event, &uid, &gid, &orig_mode)
1939+
if (!get_object_attribute (input_available_event, &uid, &gid, orig_mode)
19401940
&& !create_object_sd_from_attribute (uid, gid, S_IFCHR | mode, sd))
19411941
ret = fch_set_sd (sd, false);
19421942
errout:
@@ -1965,7 +1965,7 @@ fhandler_pty_slave::fchown (uid_t uid, gid_t gid)
19651965
}
19661966
sd.malloc (sizeof (SECURITY_DESCRIPTOR));
19671967
RtlCreateSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
1968-
if (!get_object_attribute (input_available_event, &o_uid, &o_gid, &mode))
1968+
if (!get_object_attribute (input_available_event, &o_uid, &o_gid, mode))
19691969
{
19701970
if (uid == ILLEGAL_UID)
19711971
uid = o_uid;

winsup/cygwin/fhandler/registry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ fhandler_registry::fstat (struct stat *buf)
552552
}
553553
uid_t uid;
554554
gid_t gid;
555-
if (get_reg_attribute (hKey, &buf->st_mode, &uid, &gid) == 0)
555+
if (get_reg_attribute (hKey, buf->st_mode, &uid, &gid) == 0)
556556
{
557557
buf->st_uid = uid;
558558
buf->st_gid = gid;

winsup/cygwin/local_includes/security.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,17 @@ legal_sid_type (SID_NAME_USE type)
411411

412412
class path_conv;
413413
/* File manipulation */
414-
int get_file_attribute (HANDLE, path_conv &, mode_t *,
414+
int get_file_attribute (HANDLE, path_conv &, mode_t &,
415415
uid_t *, gid_t *);
416416
int set_created_file_access (HANDLE, path_conv &, mode_t);
417417
int get_object_sd (HANDLE, security_descriptor &);
418-
int get_object_attribute (HANDLE, uid_t *, gid_t *, mode_t *);
418+
int get_object_attribute (HANDLE, uid_t *, gid_t *, mode_t &);
419419
int set_object_attribute (HANDLE, uid_t, gid_t, mode_t);
420420
int create_object_sd_from_attribute (uid_t, gid_t, mode_t,
421421
security_descriptor &);
422422
int set_object_sd (HANDLE, security_descriptor &, bool);
423423

424-
int get_reg_attribute (HKEY hkey, mode_t *, uid_t *, gid_t *);
424+
int get_reg_attribute (HKEY hkey, mode_t &, uid_t *, gid_t *);
425425
LONG get_file_sd (HANDLE fh, path_conv &, security_descriptor &, bool);
426426
LONG set_file_sd (HANDLE fh, path_conv &, security_descriptor &, bool);
427427
bool add_access_allowed_ace (PACL, DWORD, PSID, size_t &, DWORD);
@@ -441,7 +441,7 @@ struct acl;
441441
int searchace (struct acl *, int, int, uid_t id = ILLEGAL_UID);
442442
PSECURITY_DESCRIPTOR set_posix_access (mode_t, uid_t, gid_t, struct acl *, int,
443443
security_descriptor &, bool);
444-
int get_posix_access (PSECURITY_DESCRIPTOR, mode_t *, uid_t *, gid_t *,
444+
int get_posix_access (PSECURITY_DESCRIPTOR, mode_t &, uid_t *, gid_t *,
445445
struct acl *, int, bool * = NULL);
446446
int getacl (HANDLE, path_conv &, int, struct acl *);
447447
int setacl (HANDLE, path_conv &, int, struct acl *, bool &);

winsup/cygwin/sec/acl.cc

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ setacl (HANDLE handle, path_conv &pc, int nentries, aclent_t *aclbufp,
577577

578578
if (get_file_sd (handle, pc, sd, false))
579579
return -1;
580-
if (get_posix_access (sd, &attr, &uid, &gid, NULL, 0) < 0)
580+
if (get_posix_access (sd, attr, &uid, &gid, NULL, 0) < 0)
581581
return -1;
582582
if (!set_posix_access (attr, uid, gid, aclbufp, nentries,
583583
sd_ret, pc.fs_is_samba ()))
@@ -644,7 +644,7 @@ getace (aclent_t &acl, int type, int id, DWORD win_ace_mask,
644644
stock POSIX perms even if Administrators and SYSTEM is in the ACE. */
645645
int
646646
get_posix_access (PSECURITY_DESCRIPTOR psd,
647-
mode_t *attr_ret, uid_t *uid_ret, gid_t *gid_ret,
647+
mode_t &attr_ret, uid_t *uid_ret, gid_t *gid_ret,
648648
aclent_t *aclbufp, int nentries, bool *std_acl)
649649
{
650650
tmp_pathbuf tp;
@@ -689,8 +689,7 @@ get_posix_access (PSECURITY_DESCRIPTOR psd,
689689
unreadable. */
690690
if (!psd)
691691
{
692-
if (attr_ret)
693-
*attr_ret &= S_IFMT;
692+
attr_ret &= S_IFMT;
694693
if (uid_ret)
695694
*uid_ret = ACL_UNDEFINED_ID;
696695
if (gid_ret)
@@ -732,11 +731,8 @@ get_posix_access (PSECURITY_DESCRIPTOR psd,
732731
/* Set uidret, gidret, and initalize attributes. */
733732
uid = owner_sid.get_uid (&cldap);
734733
gid = group_sid.get_gid (&cldap);
735-
if (attr_ret)
736-
{
737-
attr = *attr_ret & S_IFMT;
738-
just_created = *attr_ret & S_JUSTCREATED;
739-
}
734+
attr = attr_ret & S_IFMT;
735+
just_created = attr_ret & S_JUSTCREATED;
740736
/* Remember the fact that owner and group are the same account. */
741737
owner_eq_group = owner_sid == group_sid;
742738

@@ -1174,8 +1170,7 @@ get_posix_access (PSECURITY_DESCRIPTOR psd,
11741170
*uid_ret = uid;
11751171
if (gid_ret)
11761172
*gid_ret = gid;
1177-
if (attr_ret)
1178-
*attr_ret = attr;
1173+
attr_ret = attr;
11791174
if (aclbufp)
11801175
{
11811176
if (pos > nentries)
@@ -1201,7 +1196,7 @@ getacl (HANDLE handle, path_conv &pc, int nentries, aclent_t *aclbufp)
12011196

12021197
if (get_file_sd (handle, pc, sd, false))
12031198
return -1;
1204-
int pos = get_posix_access (sd, &attr, NULL, NULL, aclbufp, nentries);
1199+
int pos = get_posix_access (sd, attr, NULL, NULL, aclbufp, nentries);
12051200
syscall_printf ("%R = getacl(%S)", pos, pc.get_nt_native_path ());
12061201
return pos;
12071202
}

winsup/cygwin/sec/base.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ get_reg_sd (HANDLE handle, security_descriptor &sd_ret)
276276
}
277277

278278
int
279-
get_reg_attribute (HKEY hkey, mode_t *attribute, uid_t *uidret,
279+
get_reg_attribute (HKEY hkey, mode_t &attribute, uid_t *uidret,
280280
gid_t *gidret)
281281
{
282282
security_descriptor sd;
@@ -292,7 +292,7 @@ get_reg_attribute (HKEY hkey, mode_t *attribute, uid_t *uidret,
292292

293293
int
294294
get_file_attribute (HANDLE handle, path_conv &pc,
295-
mode_t *attribute, uid_t *uidret, gid_t *gidret)
295+
mode_t &attribute, uid_t *uidret, gid_t *gidret)
296296
{
297297
if (pc.has_acls ())
298298
{
@@ -399,7 +399,7 @@ get_object_sd (HANDLE handle, security_descriptor &sd)
399399

400400
int
401401
get_object_attribute (HANDLE handle, uid_t *uidret, gid_t *gidret,
402-
mode_t *attribute)
402+
mode_t &attribute)
403403
{
404404
security_descriptor sd;
405405

@@ -462,7 +462,7 @@ set_created_file_access (HANDLE handle, path_conv &pc, mode_t attr)
462462
attr |= S_IFDIR;
463463
attr_rd = attr;
464464
aclp = (aclent_t *) tp.c_get ();
465-
if ((nentries = get_posix_access (sd, &attr_rd, &uid, &gid, aclp,
465+
if ((nentries = get_posix_access (sd, attr_rd, &uid, &gid, aclp,
466466
MAX_ACL_ENTRIES, &std_acl)) >= 0)
467467
{
468468
if (S_ISLNK (attr))

0 commit comments

Comments
 (0)