2000-02-18 03:38:33 +08:00
|
|
|
/* security.cc: NT security functions
|
|
|
|
|
2001-02-22 06:59:11 +08:00
|
|
|
Copyright 1997, 1998, 1999, 2000, 2001 Cygnus Solutions.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
Originaly written by Gunther Ebert, gunther.ebert@ixos-leipzig.de
|
2001-02-22 06:59:11 +08:00
|
|
|
Completely rewritten by Corinna Vinschen <corinna@vinschen.de>
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/acl.h>
|
|
|
|
#include <ctype.h>
|
2000-12-10 08:45:12 +08:00
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "cygerrno.h"
|
2001-03-05 14:28:25 +08:00
|
|
|
#include "perprocess.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "fhandler.h"
|
|
|
|
#include "path.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "sync.h"
|
|
|
|
#include "sigproc.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2000-11-15 08:13:09 +08:00
|
|
|
#include "cygheap.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "security.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
extern BOOL allow_ntea;
|
|
|
|
BOOL allow_ntsec = FALSE;
|
2000-12-20 03:52:57 +08:00
|
|
|
/* allow_smbntsec is handled exclusively in path.cc (path_conv::check).
|
|
|
|
It's defined here because of it's strong relationship to allow_ntsec.
|
|
|
|
The default is TRUE to reflect the old behaviour. */
|
|
|
|
BOOL allow_smbntsec = TRUE;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-06-17 03:36:07 +08:00
|
|
|
extern "C"
|
|
|
|
void
|
|
|
|
cygwin_set_impersonation_token (const HANDLE hToken)
|
|
|
|
{
|
|
|
|
debug_printf ("set_impersonation_token (%d)", hToken);
|
2000-11-16 05:04:02 +08:00
|
|
|
if (cygheap->user.token != hToken)
|
2000-06-17 03:36:07 +08:00
|
|
|
{
|
2000-11-16 05:04:02 +08:00
|
|
|
if (cygheap->user.token != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle (cygheap->user.token);
|
|
|
|
cygheap->user.token = hToken;
|
|
|
|
cygheap->user.impersonated = FALSE;
|
2000-06-17 03:36:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
HANDLE
|
|
|
|
cygwin_logon_user (const struct passwd *pw, const char *password)
|
|
|
|
{
|
|
|
|
if (os_being_run != winNT)
|
|
|
|
{
|
|
|
|
set_errno (ENOSYS);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
if (!pw)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *c, *nt_user, *nt_domain = NULL;
|
|
|
|
char usernamebuf[256];
|
|
|
|
HANDLE hToken;
|
|
|
|
|
|
|
|
strcpy (usernamebuf, pw->pw_name);
|
2001-03-02 19:41:09 +08:00
|
|
|
debug_printf ("pw_gecos = %x (%s)", pw->pw_gecos, pw->pw_gecos);
|
2000-06-17 03:36:07 +08:00
|
|
|
if (pw->pw_gecos)
|
|
|
|
{
|
|
|
|
if ((c = strstr (pw->pw_gecos, "U-")) != NULL &&
|
2000-09-03 12:16:35 +08:00
|
|
|
(c == pw->pw_gecos || c[-1] == ','))
|
|
|
|
{
|
|
|
|
usernamebuf[0] = '\0';
|
|
|
|
strncat (usernamebuf, c + 2, 255);
|
|
|
|
if ((c = strchr (usernamebuf, ',')) != NULL)
|
|
|
|
*c = '\0';
|
|
|
|
}
|
2000-06-17 03:36:07 +08:00
|
|
|
}
|
|
|
|
nt_user = usernamebuf;
|
|
|
|
if ((c = strchr (nt_user, '\\')) != NULL)
|
|
|
|
{
|
|
|
|
nt_domain = nt_user;
|
|
|
|
*c = '\0';
|
|
|
|
nt_user = c + 1;
|
|
|
|
}
|
2001-03-02 19:41:09 +08:00
|
|
|
debug_printf ("LogonUserA (%s, %s, %s, ...)", nt_user, nt_domain, password);
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!LogonUserA (nt_user, nt_domain, (char *) password,
|
2000-09-03 12:16:35 +08:00
|
|
|
LOGON32_LOGON_INTERACTIVE,
|
|
|
|
LOGON32_PROVIDER_DEFAULT,
|
|
|
|
&hToken)
|
2000-06-17 03:36:07 +08:00
|
|
|
|| !SetHandleInformation (hToken,
|
2000-09-03 12:16:35 +08:00
|
|
|
HANDLE_FLAG_INHERIT,
|
|
|
|
HANDLE_FLAG_INHERIT))
|
2000-06-17 03:36:07 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
debug_printf ("%d = logon_user(%s,...)", hToken, pw->pw_name);
|
|
|
|
return hToken;
|
|
|
|
}
|
|
|
|
|
2000-04-26 00:31:14 +08:00
|
|
|
/* read_sd reads a security descriptor from a file.
|
2000-02-18 03:38:33 +08:00
|
|
|
In case of error, -1 is returned and errno is set.
|
2000-05-02 17:38:32 +08:00
|
|
|
If sd_buf is too small, 0 is returned and sd_size
|
|
|
|
is set to the needed buffer size.
|
|
|
|
On success, 1 is returned.
|
|
|
|
|
|
|
|
GetFileSecurity() is used instead of BackupRead()
|
|
|
|
to avoid access denied errors if the caller has
|
|
|
|
not the permission to open that file for read.
|
|
|
|
|
|
|
|
Originally the function should return the size
|
|
|
|
of the SD on success. Unfortunately NT returns
|
|
|
|
0 in `len' on success, while W2K returns the
|
|
|
|
correct size!
|
2000-02-18 03:38:33 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
LONG
|
2000-04-26 00:31:14 +08:00
|
|
|
read_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, LPDWORD sd_size)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* Check parameters */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!sd_size)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-04-13 14:53:24 +08:00
|
|
|
debug_printf("file = %s", file);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-04-26 00:31:14 +08:00
|
|
|
DWORD len = 0;
|
2000-12-10 08:45:12 +08:00
|
|
|
const char *pfile = file;
|
|
|
|
char fbuf [PATH_MAX];
|
|
|
|
if (current_codepage == oem_cp)
|
|
|
|
{
|
|
|
|
DWORD fname_len = min (sizeof (fbuf) - 1, strlen (file));
|
|
|
|
bzero (fbuf, sizeof (fbuf));
|
|
|
|
OemToCharBuff(file, fbuf, fname_len);
|
|
|
|
pfile = fbuf;
|
|
|
|
}
|
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!GetFileSecurity (pfile,
|
2000-12-10 08:45:12 +08:00
|
|
|
OWNER_SECURITY_INFORMATION
|
2000-09-03 12:16:35 +08:00
|
|
|
| GROUP_SECURITY_INFORMATION
|
|
|
|
| DACL_SECURITY_INFORMATION,
|
|
|
|
sd_buf, *sd_size, &len))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2000-05-02 08:25:43 +08:00
|
|
|
debug_printf("file = %s: len=%d", file, len);
|
2000-04-26 00:31:14 +08:00
|
|
|
if (len > *sd_size)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-04-26 00:31:14 +08:00
|
|
|
*sd_size = len;
|
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-05-02 17:38:32 +08:00
|
|
|
return 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG
|
2000-04-26 00:31:14 +08:00
|
|
|
write_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, DWORD sd_size)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* Check parameters */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!sd_buf || !sd_size)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-10-22 18:13:30 +08:00
|
|
|
/* No need to be thread save. */
|
|
|
|
static BOOL first_time = TRUE;
|
|
|
|
if (first_time)
|
|
|
|
{
|
2001-04-21 04:36:13 +08:00
|
|
|
set_process_privilege (SE_RESTORE_NAME);
|
2000-10-22 18:13:30 +08:00
|
|
|
first_time = FALSE;
|
|
|
|
}
|
|
|
|
|
2000-04-26 00:31:14 +08:00
|
|
|
HANDLE fh;
|
|
|
|
fh = CreateFile (file,
|
2000-09-03 12:16:35 +08:00
|
|
|
WRITE_OWNER | WRITE_DAC,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
&sec_none_nih,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS,
|
|
|
|
NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-04-26 00:31:14 +08:00
|
|
|
if (fh == INVALID_HANDLE_VALUE)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPVOID context = NULL;
|
|
|
|
DWORD bytes_written = 0;
|
|
|
|
WIN32_STREAM_ID header;
|
|
|
|
|
|
|
|
memset (&header, 0, sizeof (header));
|
|
|
|
/* write new security info header */
|
|
|
|
header.dwStreamId = BACKUP_SECURITY_DATA;
|
|
|
|
header.dwStreamAttributes = STREAM_CONTAINS_SECURITY;
|
|
|
|
header.Size.HighPart = 0;
|
2000-04-26 00:31:14 +08:00
|
|
|
header.Size.LowPart = sd_size;
|
2000-02-18 03:38:33 +08:00
|
|
|
header.dwStreamNameSize = 0;
|
2000-04-26 00:31:14 +08:00
|
|
|
if (!BackupWrite (fh, (LPBYTE) &header,
|
2000-02-18 03:38:33 +08:00
|
|
|
3 * sizeof (DWORD) + sizeof (LARGE_INTEGER),
|
|
|
|
&bytes_written, FALSE, TRUE, &context))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
2000-04-26 00:31:14 +08:00
|
|
|
CloseHandle (fh);
|
2000-02-18 03:38:33 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write new security descriptor */
|
2000-04-26 00:31:14 +08:00
|
|
|
if (!BackupWrite (fh, (LPBYTE) sd_buf,
|
2000-02-18 03:38:33 +08:00
|
|
|
header.Size.LowPart + header.dwStreamNameSize,
|
|
|
|
&bytes_written, FALSE, TRUE, &context))
|
|
|
|
{
|
|
|
|
/* Samba returns ERROR_NOT_SUPPORTED.
|
2000-09-03 12:16:35 +08:00
|
|
|
FAT returns ERROR_INVALID_SECURITY_DESCR.
|
|
|
|
This shouldn't return as error, but better be ignored. */
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD ret = GetLastError ();
|
|
|
|
if (ret != ERROR_NOT_SUPPORTED && ret != ERROR_INVALID_SECURITY_DESCR)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
2000-04-26 00:31:14 +08:00
|
|
|
BackupWrite (fh, NULL, 0, &bytes_written, TRUE, TRUE, &context);
|
|
|
|
CloseHandle (fh);
|
2000-02-18 03:38:33 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* terminate the restore process */
|
2000-04-26 00:31:14 +08:00
|
|
|
BackupWrite (fh, NULL, 0, &bytes_written, TRUE, TRUE, &context);
|
|
|
|
CloseHandle (fh);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-03-17 03:35:18 +08:00
|
|
|
get_nt_attribute (const char *file, int *attribute,
|
2000-09-03 12:16:35 +08:00
|
|
|
uid_t *uidret, gid_t *gidret)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (os_being_run != winNT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
syscall_printf ("file: %s", file);
|
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
/* Yeah, sounds too much, but I've seen SDs of 2100 bytes!*/
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD sd_size = 4096;
|
|
|
|
char sd_buf[4096];
|
|
|
|
PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) sd_buf;
|
|
|
|
|
|
|
|
int ret;
|
2000-04-26 00:31:14 +08:00
|
|
|
if ((ret = read_sd (file, psd, &sd_size)) <= 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-04-26 00:31:14 +08:00
|
|
|
debug_printf ("read_sd %E");
|
2000-02-18 03:38:33 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
PSID owner_sid;
|
|
|
|
PSID group_sid;
|
|
|
|
BOOL dummy;
|
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!GetSecurityDescriptorOwner (psd, &owner_sid, &dummy))
|
2000-02-18 03:38:33 +08:00
|
|
|
debug_printf ("GetSecurityDescriptorOwner %E");
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!GetSecurityDescriptorGroup (psd, &group_sid, &dummy))
|
2000-02-18 03:38:33 +08:00
|
|
|
debug_printf ("GetSecurityDescriptorGroup %E");
|
|
|
|
|
|
|
|
PACL acl;
|
|
|
|
BOOL acl_exists;
|
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!GetSecurityDescriptorDacl (psd, &acl_exists, &acl, &dummy))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
debug_printf ("GetSecurityDescriptorDacl %E");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-03-17 03:35:18 +08:00
|
|
|
uid_t uid = get_uid_from_sid (owner_sid);
|
|
|
|
gid_t gid = get_gid_from_sid (group_sid);
|
|
|
|
if (uidret)
|
|
|
|
*uidret = uid;
|
|
|
|
if (gidret)
|
|
|
|
*gidret = gid;
|
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!attribute)
|
2000-03-17 03:35:18 +08:00
|
|
|
{
|
2000-05-25 04:09:43 +08:00
|
|
|
syscall_printf ("file: %s uid %d, gid %d", file, uid, gid);
|
2000-03-17 03:35:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL grp_member = is_grp_member (uid, gid);
|
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!acl_exists || !acl)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
*attribute |= S_IRWXU | S_IRWXG | S_IRWXO;
|
2000-03-17 03:35:18 +08:00
|
|
|
syscall_printf ("file: %s No ACL = %x, uid %d, gid %d",
|
2000-09-03 12:16:35 +08:00
|
|
|
file, *attribute, uid, gid);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ACCESS_ALLOWED_ACE *ace;
|
|
|
|
int allow = 0;
|
|
|
|
int deny = 0;
|
|
|
|
int *flags, *anti;
|
|
|
|
|
|
|
|
for (DWORD i = 0; i < acl->AceCount; ++i)
|
|
|
|
{
|
|
|
|
if (!GetAce (acl, i, (PVOID *) &ace))
|
2000-09-03 12:16:35 +08:00
|
|
|
continue;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (ace->Header.AceFlags & INHERIT_ONLY_ACE)
|
2000-09-03 12:16:35 +08:00
|
|
|
continue;
|
2000-02-18 03:38:33 +08:00
|
|
|
switch (ace->Header.AceType)
|
2000-09-03 12:16:35 +08:00
|
|
|
{
|
|
|
|
case ACCESS_ALLOWED_ACE_TYPE:
|
|
|
|
flags = &allow;
|
|
|
|
anti = &deny;
|
|
|
|
break;
|
|
|
|
case ACCESS_DENIED_ACE_TYPE:
|
|
|
|
flags = &deny;
|
|
|
|
anti = &allow;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
PSID ace_sid = (PSID) &ace->SidStart;
|
|
|
|
if (owner_sid && EqualSid (ace_sid, owner_sid))
|
2000-09-03 12:16:35 +08:00
|
|
|
{
|
|
|
|
if (ace->Mask & FILE_READ_DATA)
|
|
|
|
*flags |= S_IRUSR;
|
|
|
|
if (ace->Mask & FILE_WRITE_DATA)
|
|
|
|
*flags |= S_IWUSR;
|
|
|
|
if (ace->Mask & FILE_EXECUTE)
|
|
|
|
*flags |= S_IXUSR;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (group_sid && EqualSid (ace_sid, group_sid))
|
2000-09-03 12:16:35 +08:00
|
|
|
{
|
|
|
|
if (ace->Mask & FILE_READ_DATA)
|
|
|
|
*flags |= S_IRGRP
|
|
|
|
| ((grp_member && !(*anti & S_IRUSR)) ? S_IRUSR : 0);
|
|
|
|
if (ace->Mask & FILE_WRITE_DATA)
|
|
|
|
*flags |= S_IWGRP
|
|
|
|
| ((grp_member && !(*anti & S_IWUSR)) ? S_IWUSR : 0);
|
|
|
|
if (ace->Mask & FILE_EXECUTE)
|
|
|
|
*flags |= S_IXGRP
|
|
|
|
| ((grp_member && !(*anti & S_IXUSR)) ? S_IXUSR : 0);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (EqualSid (ace_sid, get_world_sid ()))
|
2000-09-03 12:16:35 +08:00
|
|
|
{
|
|
|
|
if (ace->Mask & FILE_READ_DATA)
|
|
|
|
*flags |= S_IROTH
|
|
|
|
| ((!(*anti & S_IRGRP)) ? S_IRGRP : 0)
|
|
|
|
| ((!(*anti & S_IRUSR)) ? S_IRUSR : 0);
|
|
|
|
if (ace->Mask & FILE_WRITE_DATA)
|
|
|
|
*flags |= S_IWOTH
|
|
|
|
| ((!(*anti & S_IWGRP)) ? S_IWGRP : 0)
|
|
|
|
| ((!(*anti & S_IWUSR)) ? S_IWUSR : 0);
|
|
|
|
if (ace->Mask & FILE_EXECUTE)
|
|
|
|
{
|
|
|
|
*flags |= S_IXOTH
|
|
|
|
| ((!(*anti & S_IXGRP)) ? S_IXGRP : 0)
|
|
|
|
| ((!(*anti & S_IXUSR)) ? S_IXUSR : 0);
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Sticky bit for directories according to linux rules. */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!(ace->Mask & FILE_DELETE_CHILD)
|
2000-09-03 12:16:35 +08:00
|
|
|
&& S_ISDIR(*attribute)
|
|
|
|
&& !(*anti & S_ISVTX))
|
|
|
|
*flags |= S_ISVTX;
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
*attribute &= ~(S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
|
|
|
|
*attribute |= allow;
|
|
|
|
*attribute &= ~deny;
|
2000-03-17 03:35:18 +08:00
|
|
|
syscall_printf ("file: %s %x, uid %d, gid %d", file, *attribute, uid, gid);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-04-26 00:31:14 +08:00
|
|
|
get_file_attribute (int use_ntsec, const char *file,
|
2000-09-03 12:16:35 +08:00
|
|
|
int *attribute, uid_t *uidret, gid_t *gidret)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-02-22 05:49:37 +08:00
|
|
|
int res;
|
|
|
|
|
2000-03-17 03:35:18 +08:00
|
|
|
if (use_ntsec && allow_ntsec)
|
2001-02-22 05:49:37 +08:00
|
|
|
{
|
|
|
|
res = get_nt_attribute (file, attribute, uidret, gidret);
|
|
|
|
if (attribute && (*attribute & S_IFLNK) == S_IFLNK)
|
|
|
|
*attribute |= S_IRWXU | S_IRWXG | S_IRWXO;
|
|
|
|
return res;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-03-17 03:35:18 +08:00
|
|
|
if (uidret)
|
|
|
|
*uidret = getuid ();
|
|
|
|
if (gidret)
|
|
|
|
*gidret = getgid ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!attribute)
|
2000-03-17 03:35:18 +08:00
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-02-22 05:49:37 +08:00
|
|
|
res = NTReadEA (file, ".UNIXATTR", (char *) attribute, sizeof (*attribute));
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
/* symlinks are everything for everyone!*/
|
2000-02-18 03:38:33 +08:00
|
|
|
if ((*attribute & S_IFLNK) == S_IFLNK)
|
|
|
|
*attribute |= S_IRWXU | S_IRWXG | S_IRWXO;
|
|
|
|
|
2000-03-17 03:35:18 +08:00
|
|
|
if (res <= 0)
|
|
|
|
set_errno (ENOSYS);
|
|
|
|
return res > 0 ? 0 : -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
BOOL
|
|
|
|
add_access_allowed_ace (PACL acl, int offset, DWORD attributes,
|
|
|
|
PSID sid, size_t &len_add, DWORD inherit)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!AddAccessAllowedAce (acl, ACL_REVISION, attributes, sid))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ACCESS_ALLOWED_ACE *ace;
|
|
|
|
if (GetAce(acl, offset, (PVOID *) &ace))
|
|
|
|
ace->Header.AceFlags |= inherit;
|
|
|
|
len_add += sizeof (ACCESS_DENIED_ACE) - sizeof (DWORD)
|
2000-09-03 12:16:35 +08:00
|
|
|
+ GetLengthSid (sid);
|
2000-02-18 03:38:33 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
BOOL
|
|
|
|
add_access_denied_ace (PACL acl, int offset, DWORD attributes,
|
|
|
|
PSID sid, size_t &len_add, DWORD inherit)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!AddAccessDeniedAce (acl, ACL_REVISION, attributes, sid))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ACCESS_DENIED_ACE *ace;
|
|
|
|
if (GetAce(acl, offset, (PVOID *) &ace))
|
|
|
|
ace->Header.AceFlags |= inherit;
|
|
|
|
len_add += sizeof (ACCESS_DENIED_ACE) - sizeof (DWORD)
|
2000-09-03 12:16:35 +08:00
|
|
|
+ GetLengthSid (sid);
|
2000-02-18 03:38:33 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PSECURITY_DESCRIPTOR
|
|
|
|
alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute,
|
|
|
|
PSECURITY_DESCRIPTOR sd_ret, DWORD *sd_size_ret)
|
|
|
|
{
|
|
|
|
BOOL dummy;
|
|
|
|
|
|
|
|
if (os_being_run != winNT)
|
|
|
|
return NULL;
|
|
|
|
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!sd_ret || !sd_size_ret)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Get SID and name of new owner. */
|
2000-02-18 03:38:33 +08:00
|
|
|
char owner[MAX_USER_NAME];
|
|
|
|
char *owner_sid_buf[MAX_SID_LEN];
|
|
|
|
PSID owner_sid = NULL;
|
|
|
|
struct passwd *pw = getpwuid (uid);
|
|
|
|
strcpy (owner, pw ? pw->pw_name : getlogin ());
|
|
|
|
owner_sid = (PSID) owner_sid_buf;
|
2001-01-28 13:51:15 +08:00
|
|
|
if ((!pw || !get_pw_sid (owner_sid, pw))
|
|
|
|
&& !lookup_name (owner, logsrv, owner_sid))
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
|
|
|
debug_printf ("owner: %s [%d]", owner,
|
2000-09-03 12:16:35 +08:00
|
|
|
*GetSidSubAuthority((PSID) owner_sid,
|
2000-02-18 03:38:33 +08:00
|
|
|
*GetSidSubAuthorityCount((PSID) owner_sid) - 1));
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Get SID and name of new group. */
|
2000-02-18 03:38:33 +08:00
|
|
|
char *group_sid_buf[MAX_SID_LEN];
|
|
|
|
PSID group_sid = NULL;
|
|
|
|
struct group *grp = getgrgid (gid);
|
|
|
|
if (grp)
|
|
|
|
{
|
|
|
|
group_sid = (PSID) group_sid_buf;
|
2001-01-28 13:51:15 +08:00
|
|
|
if ((!grp || !get_gr_sid (group_sid, grp))
|
|
|
|
&& !lookup_name (grp->gr_name, logsrv, group_sid))
|
2000-09-03 12:16:35 +08:00
|
|
|
return NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
debug_printf ("no group");
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Initialize local security descriptor. */
|
2000-02-18 03:38:33 +08:00
|
|
|
SECURITY_DESCRIPTOR sd;
|
|
|
|
PSECURITY_DESCRIPTOR psd = NULL;
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-12-20 20:42:43 +08:00
|
|
|
/*
|
2001-04-23 06:12:12 +08:00
|
|
|
* We set the SE_DACL_PROTECTED flag here to prevent the DACL from being
|
|
|
|
* modified by inheritable ACEs.
|
|
|
|
* This flag as well as the SetSecurityDescriptorControl call are available
|
|
|
|
* only since Win2K.
|
2000-12-20 20:42:43 +08:00
|
|
|
*/
|
|
|
|
static int win2KorHigher = -1;
|
|
|
|
if (win2KorHigher == -1)
|
|
|
|
{
|
|
|
|
DWORD version = GetVersion ();
|
|
|
|
win2KorHigher = (version & 0x80000000) || (version & 0xff) < 5 ? 0 : 1;
|
|
|
|
}
|
|
|
|
if (win2KorHigher > 0)
|
|
|
|
SetSecurityDescriptorControl (&sd, SE_DACL_PROTECTED, SE_DACL_PROTECTED);
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Create owner for local security descriptor. */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!SetSecurityDescriptorOwner(&sd, owner_sid, FALSE))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-10-23 16:02:38 +08:00
|
|
|
|
|
|
|
/* Create group for local security descriptor. */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (group_sid && !SetSecurityDescriptorGroup(&sd, group_sid, FALSE))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Initialize local access control list. */
|
2000-02-18 03:38:33 +08:00
|
|
|
char acl_buf[3072];
|
|
|
|
PACL acl = (PACL) acl_buf;
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!InitializeAcl (acl, 3072, ACL_REVISION))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/*
|
|
|
|
* VTX bit may only be set if executable for `other' is set.
|
|
|
|
* For correct handling under WinNT, FILE_DELETE_CHILD has to
|
|
|
|
* be (un)set in each ACE.
|
|
|
|
*/
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!(attribute & S_IXOTH))
|
2000-02-18 03:38:33 +08:00
|
|
|
attribute &= ~S_ISVTX;
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!(attribute & S_IFDIR))
|
2000-05-25 04:09:43 +08:00
|
|
|
attribute |= S_ISVTX;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* From here fill ACL. */
|
2000-02-18 03:38:33 +08:00
|
|
|
size_t acl_len = sizeof (ACL);
|
|
|
|
int ace_off = 0;
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Construct allow attribute for owner. */
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD owner_allow = (STANDARD_RIGHTS_ALL & ~DELETE)
|
2000-09-03 12:16:35 +08:00
|
|
|
| FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (attribute & S_IRUSR)
|
|
|
|
owner_allow |= FILE_GENERIC_READ;
|
|
|
|
if (attribute & S_IWUSR)
|
|
|
|
owner_allow |= FILE_GENERIC_WRITE | DELETE;
|
|
|
|
if (attribute & S_IXUSR)
|
|
|
|
owner_allow |= FILE_GENERIC_EXECUTE;
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!(attribute & S_ISVTX))
|
2000-02-18 03:38:33 +08:00
|
|
|
owner_allow |= FILE_DELETE_CHILD;
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Construct allow attribute for group. */
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD group_allow = STANDARD_RIGHTS_READ
|
2000-09-03 12:16:35 +08:00
|
|
|
| FILE_READ_ATTRIBUTES | FILE_READ_EA;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (attribute & S_IRGRP)
|
|
|
|
group_allow |= FILE_GENERIC_READ;
|
|
|
|
if (attribute & S_IWGRP)
|
2000-04-26 00:31:14 +08:00
|
|
|
group_allow |= STANDARD_RIGHTS_WRITE | FILE_GENERIC_WRITE | DELETE;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (attribute & S_IXGRP)
|
|
|
|
group_allow |= FILE_GENERIC_EXECUTE;
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!(attribute & S_ISVTX))
|
2000-02-18 03:38:33 +08:00
|
|
|
group_allow |= FILE_DELETE_CHILD;
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Construct allow attribute for everyone. */
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD other_allow = STANDARD_RIGHTS_READ
|
2000-09-03 12:16:35 +08:00
|
|
|
| FILE_READ_ATTRIBUTES | FILE_READ_EA;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (attribute & S_IROTH)
|
|
|
|
other_allow |= FILE_GENERIC_READ;
|
|
|
|
if (attribute & S_IWOTH)
|
2000-04-26 00:31:14 +08:00
|
|
|
other_allow |= STANDARD_RIGHTS_WRITE | FILE_GENERIC_WRITE | DELETE;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (attribute & S_IXOTH)
|
|
|
|
other_allow |= FILE_GENERIC_EXECUTE;
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!(attribute & S_ISVTX))
|
2000-02-18 03:38:33 +08:00
|
|
|
other_allow |= FILE_DELETE_CHILD;
|
2000-10-28 13:41:44 +08:00
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Construct deny attributes for owner and group. */
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD owner_deny = 0;
|
|
|
|
if (is_grp_member (uid, gid))
|
|
|
|
owner_deny = ~owner_allow & (group_allow | other_allow);
|
|
|
|
else
|
|
|
|
owner_deny = ~owner_allow & other_allow;
|
|
|
|
owner_deny &= ~(STANDARD_RIGHTS_READ
|
2000-09-03 12:16:35 +08:00
|
|
|
| FILE_READ_ATTRIBUTES | FILE_READ_EA
|
|
|
|
| FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA);
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD group_deny = ~group_allow & other_allow;
|
|
|
|
group_deny &= ~(STANDARD_RIGHTS_READ | FILE_READ_ATTRIBUTES | FILE_READ_EA);
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Construct appropriate inherit attribute. */
|
2000-05-25 04:09:43 +08:00
|
|
|
DWORD inherit = (attribute & S_IFDIR) ? INHERIT_ALL : DONT_INHERIT;
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Set deny ACE for owner. */
|
2000-02-18 03:38:33 +08:00
|
|
|
if (owner_deny
|
2001-01-28 13:51:15 +08:00
|
|
|
&& !add_access_denied_ace (acl, ace_off++, owner_deny,
|
2000-09-03 12:16:35 +08:00
|
|
|
owner_sid, acl_len, inherit))
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Set allow ACE for owner. */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!add_access_allowed_ace (acl, ace_off++, owner_allow,
|
2000-09-03 12:16:35 +08:00
|
|
|
owner_sid, acl_len, inherit))
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Set deny ACE for group. */
|
2000-02-18 03:38:33 +08:00
|
|
|
if (group_deny
|
2001-01-28 13:51:15 +08:00
|
|
|
&& !add_access_denied_ace (acl, ace_off++, group_deny,
|
2000-09-03 12:16:35 +08:00
|
|
|
group_sid, acl_len, inherit))
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Set allow ACE for group. */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!add_access_allowed_ace (acl, ace_off++, group_allow,
|
2000-09-03 12:16:35 +08:00
|
|
|
group_sid, acl_len, inherit))
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Get owner and group from current security descriptor. */
|
2000-02-18 03:38:33 +08:00
|
|
|
PSID cur_owner_sid = NULL;
|
|
|
|
PSID cur_group_sid = NULL;
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!GetSecurityDescriptorOwner (sd_ret, &cur_owner_sid, &dummy))
|
2000-02-18 03:38:33 +08:00
|
|
|
debug_printf ("GetSecurityDescriptorOwner %E");
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!GetSecurityDescriptorGroup (sd_ret, &cur_group_sid, &dummy))
|
2000-02-18 03:38:33 +08:00
|
|
|
debug_printf ("GetSecurityDescriptorGroup %E");
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Fill ACL with unrelated ACEs from current security descriptor. */
|
2000-02-18 03:38:33 +08:00
|
|
|
PACL oacl;
|
|
|
|
BOOL acl_exists;
|
|
|
|
ACCESS_ALLOWED_ACE *ace;
|
|
|
|
if (GetSecurityDescriptorDacl (sd_ret, &acl_exists, &oacl, &dummy)
|
|
|
|
&& acl_exists && oacl)
|
|
|
|
for (DWORD i = 0; i < oacl->AceCount; ++i)
|
|
|
|
if (GetAce (oacl, i, (PVOID *) &ace))
|
2000-09-03 12:16:35 +08:00
|
|
|
{
|
|
|
|
PSID ace_sid = (PSID) &ace->SidStart;
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Check for related ACEs. */
|
2000-09-03 12:16:35 +08:00
|
|
|
if ((cur_owner_sid && EqualSid (ace_sid, cur_owner_sid))
|
|
|
|
|| (owner_sid && EqualSid (ace_sid, owner_sid))
|
|
|
|
|| (cur_group_sid && EqualSid (ace_sid, cur_group_sid))
|
|
|
|
|| (group_sid && EqualSid (ace_sid, group_sid))
|
|
|
|
|| (EqualSid (ace_sid, get_world_sid ())))
|
|
|
|
continue;
|
2000-10-23 16:02:38 +08:00
|
|
|
/*
|
|
|
|
* Add unrelated ACCESS_DENIED_ACE to the beginning but
|
|
|
|
* behind the owner_deny, ACCESS_ALLOWED_ACE to the end
|
|
|
|
* but in front of the `everyone' ACE.
|
|
|
|
*/
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!AddAce(acl, ACL_REVISION,
|
2000-09-03 12:16:35 +08:00
|
|
|
ace->Header.AceType == ACCESS_DENIED_ACE_TYPE ?
|
|
|
|
(owner_deny ? 1 : 0) : MAXDWORD,
|
|
|
|
(LPVOID) ace, ace->Header.AceSize))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
acl_len += ace->Header.AceSize;
|
|
|
|
++ace_off;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Set allow ACE for everyone. */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!add_access_allowed_ace (acl, ace_off++, other_allow,
|
2000-09-03 12:16:35 +08:00
|
|
|
get_world_sid (), acl_len, inherit))
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Set AclSize to computed value. */
|
2000-02-18 03:38:33 +08:00
|
|
|
acl->AclSize = acl_len;
|
|
|
|
debug_printf ("ACL-Size: %d", acl_len);
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Create DACL for local security descriptor. */
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!SetSecurityDescriptorDacl (&sd, TRUE, acl, FALSE))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-10-23 16:02:38 +08:00
|
|
|
/* Make self relative security descriptor. */
|
2000-02-18 03:38:33 +08:00
|
|
|
*sd_size_ret = 0;
|
|
|
|
MakeSelfRelativeSD (&sd, sd_ret, sd_size_ret);
|
|
|
|
if (*sd_size_ret <= 0)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!MakeSelfRelativeSD (&sd, sd_ret, sd_size_ret))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
psd = sd_ret;
|
|
|
|
debug_printf ("Created SD-Size: %d", *sd_size_ret);
|
|
|
|
|
|
|
|
return psd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_nt_attribute (const char *file, uid_t uid, gid_t gid,
|
2000-09-03 12:16:35 +08:00
|
|
|
const char *logsrv, int attribute)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (os_being_run != winNT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
DWORD sd_size = 4096;
|
|
|
|
char sd_buf[4096];
|
|
|
|
PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) sd_buf;
|
|
|
|
|
|
|
|
int ret;
|
2000-04-26 00:31:14 +08:00
|
|
|
if ((ret = read_sd (file, psd, &sd_size)) <= 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-04-26 00:31:14 +08:00
|
|
|
debug_printf ("read_sd %E");
|
2000-02-18 03:38:33 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
sd_size = 4096;
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!(psd = alloc_sd (uid, gid, logsrv, attribute, psd, &sd_size)))
|
2000-02-18 03:38:33 +08:00
|
|
|
return -1;
|
|
|
|
|
2000-04-26 00:31:14 +08:00
|
|
|
return write_sd (file, psd, sd_size);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
set_file_attribute (int use_ntsec, const char *file,
|
2000-09-03 12:16:35 +08:00
|
|
|
uid_t uid, gid_t gid,
|
|
|
|
int attribute, const char *logsrv)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-01-28 13:51:15 +08:00
|
|
|
/* symlinks are anything for everyone!*/
|
2000-02-18 03:38:33 +08:00
|
|
|
if ((attribute & S_IFLNK) == S_IFLNK)
|
|
|
|
attribute |= S_IRWXU | S_IRWXG | S_IRWXO;
|
|
|
|
|
|
|
|
if (!use_ntsec || !allow_ntsec)
|
|
|
|
{
|
2001-01-28 13:51:15 +08:00
|
|
|
if (!NTWriteEA (file, ".UNIXATTR",
|
2000-09-03 12:16:35 +08:00
|
|
|
(char *) &attribute, sizeof (attribute)))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-03-17 03:35:18 +08:00
|
|
|
int ret = set_nt_attribute (file, uid, gid, logsrv, attribute);
|
2000-02-18 03:38:33 +08:00
|
|
|
syscall_printf ("%d = set_file_attribute (%s, %d, %d, %p)",
|
2000-03-17 03:35:18 +08:00
|
|
|
ret, file, uid, gid, attribute);
|
|
|
|
return ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
set_file_attribute (int use_ntsec, const char *file, int attribute)
|
|
|
|
{
|
|
|
|
return set_file_attribute (use_ntsec, file,
|
2000-09-03 12:16:35 +08:00
|
|
|
myself->uid, myself->gid,
|
2000-11-15 08:13:09 +08:00
|
|
|
attribute, cygheap->user.logsrv ());
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|