4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-21 16:26:12 +08:00

* uinfo.cc (pwdgrp::load): Regularize strace output. Add warning for

CreateFile failure.
This commit is contained in:
Christopher Faylor 2003-01-26 06:42:40 +00:00
parent 989c97fe14
commit 9a75162166
10 changed files with 126 additions and 118 deletions

View File

@ -1,3 +1,8 @@
2003-01-26 Christopher Faylor <cgf@redhat.com>
* uinfo.cc (pwdgrp::load): Regularize strace output. Add warning for
CreateFile failure.
2003-01-26 Christopher Faylor <cgf@redhat.com> 2003-01-26 Christopher Faylor <cgf@redhat.com>
* passwd.cc (pwdgrp::parse_passwd): Eliminate use of memset. The * passwd.cc (pwdgrp::parse_passwd): Eliminate use of memset. The

View File

@ -201,112 +201,112 @@ fhandler_dev_floppy::ioctl (unsigned int cmd, void *buf)
{ {
case HDIO_GETGEO: case HDIO_GETGEO:
{ {
debug_printf ("HDIO_GETGEO"); debug_printf ("HDIO_GETGEO");
if (!DeviceIoControl (get_handle (), if (!DeviceIoControl (get_handle (),
IOCTL_DISK_GET_DRIVE_GEOMETRY, IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL, 0, NULL, 0,
&di, sizeof (di), &di, sizeof (di),
&bytes_read, NULL)) &bytes_read, NULL))
{ {
__seterrno (); __seterrno ();
return -1; return -1;
} }
debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)", debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)",
di.Cylinders.LowPart, di.Cylinders.LowPart,
di.TracksPerCylinder, di.TracksPerCylinder,
di.SectorsPerTrack, di.SectorsPerTrack,
di.BytesPerSector); di.BytesPerSector);
if (DeviceIoControl (get_handle (), if (DeviceIoControl (get_handle (),
IOCTL_DISK_GET_PARTITION_INFO, IOCTL_DISK_GET_PARTITION_INFO,
NULL, 0, NULL, 0,
&pi, sizeof (pi), &pi, sizeof (pi),
&bytes_read, NULL)) &bytes_read, NULL))
{ {
debug_printf ("partition info: %ld (%ld)", debug_printf ("partition info: %ld (%ld)",
pi.StartingOffset.LowPart, pi.StartingOffset.LowPart,
pi.PartitionLength.LowPart); pi.PartitionLength.LowPart);
start = pi.StartingOffset.QuadPart >> 9ULL; start = pi.StartingOffset.QuadPart >> 9ULL;
} }
struct hd_geometry *geo = (struct hd_geometry *) buf; struct hd_geometry *geo = (struct hd_geometry *) buf;
geo->heads = di.TracksPerCylinder; geo->heads = di.TracksPerCylinder;
geo->sectors = di.SectorsPerTrack; geo->sectors = di.SectorsPerTrack;
geo->cylinders = di.Cylinders.LowPart; geo->cylinders = di.Cylinders.LowPart;
geo->start = start; geo->start = start;
return 0; return 0;
} }
case BLKGETSIZE: case BLKGETSIZE:
case BLKGETSIZE64: case BLKGETSIZE64:
{ {
debug_printf ("BLKGETSIZE"); debug_printf ("BLKGETSIZE");
if (!DeviceIoControl (get_handle (), if (!DeviceIoControl (get_handle (),
IOCTL_DISK_GET_DRIVE_GEOMETRY, IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL, 0, NULL, 0,
&di, sizeof (di), &di, sizeof (di),
&bytes_read, NULL)) &bytes_read, NULL))
{ {
__seterrno (); __seterrno ();
return -1; return -1;
} }
debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)", debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)",
di.Cylinders.LowPart, di.Cylinders.LowPart,
di.TracksPerCylinder, di.TracksPerCylinder,
di.SectorsPerTrack, di.SectorsPerTrack,
di.BytesPerSector); di.BytesPerSector);
if (DeviceIoControl (get_handle (), if (DeviceIoControl (get_handle (),
IOCTL_DISK_GET_PARTITION_INFO, IOCTL_DISK_GET_PARTITION_INFO,
NULL, 0, NULL, 0,
&pi, sizeof (pi), &pi, sizeof (pi),
&bytes_read, NULL)) &bytes_read, NULL))
{ {
debug_printf ("partition info: %ld (%ld)", debug_printf ("partition info: %ld (%ld)",
pi.StartingOffset.LowPart, pi.StartingOffset.LowPart,
pi.PartitionLength.LowPart); pi.PartitionLength.LowPart);
drive_size = pi.PartitionLength.QuadPart; drive_size = pi.PartitionLength.QuadPart;
} }
else else
{ {
drive_size = di.Cylinders.QuadPart * di.TracksPerCylinder * drive_size = di.Cylinders.QuadPart * di.TracksPerCylinder *
di.SectorsPerTrack * di.BytesPerSector; di.SectorsPerTrack * di.BytesPerSector;
} }
if (cmd == BLKGETSIZE) if (cmd == BLKGETSIZE)
*(long *)buf = drive_size >> 9UL; *(long *)buf = drive_size >> 9UL;
else else
*(__off64_t *)buf = drive_size; *(__off64_t *)buf = drive_size;
return 0; return 0;
} }
case BLKRRPART: case BLKRRPART:
{ {
debug_printf ("BLKRRPART"); debug_printf ("BLKRRPART");
if (!DeviceIoControl (get_handle (), if (!DeviceIoControl (get_handle (),
IOCTL_DISK_UPDATE_DRIVE_SIZE, IOCTL_DISK_UPDATE_DRIVE_SIZE,
NULL, 0, NULL, 0,
&di, sizeof (di), &di, sizeof (di),
&bytes_read, NULL)) &bytes_read, NULL))
{ {
__seterrno (); __seterrno ();
return -1; return -1;
} }
return 0; return 0;
} }
case BLKSSZGET: case BLKSSZGET:
{ {
debug_printf ("BLKSSZGET"); debug_printf ("BLKSSZGET");
if (!DeviceIoControl (get_handle (), if (!DeviceIoControl (get_handle (),
IOCTL_DISK_GET_DRIVE_GEOMETRY, IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL, 0, NULL, 0,
&di, sizeof (di), &di, sizeof (di),
&bytes_read, NULL)) &bytes_read, NULL))
{ {
__seterrno (); __seterrno ();
return -1; return -1;
} }
debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)", debug_printf ("disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)",
di.Cylinders.LowPart, di.Cylinders.LowPart,
di.TracksPerCylinder, di.TracksPerCylinder,
di.SectorsPerTrack, di.SectorsPerTrack,
di.BytesPerSector); di.BytesPerSector);
*(int *)buf = di.BytesPerSector; *(int *)buf = di.BytesPerSector;
return 0; return 0;
} }
default: default:
return fhandler_dev_raw::ioctl (cmd, buf); return fhandler_dev_raw::ioctl (cmd, buf);

View File

@ -1115,7 +1115,7 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
} }
ifr->ifr_flags = IFF_NOTRAILERS | IFF_UP | IFF_RUNNING; ifr->ifr_flags = IFF_NOTRAILERS | IFF_UP | IFF_RUNNING;
if (!strncmp(ifr->ifr_name, "lo", 2) if (!strncmp(ifr->ifr_name, "lo", 2)
|| ntohl (((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr) || ntohl (((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr)
== INADDR_LOOPBACK) == INADDR_LOOPBACK)
ifr->ifr_flags |= IFF_LOOPBACK; ifr->ifr_flags |= IFF_LOOPBACK;
else else

View File

@ -116,7 +116,7 @@ internal_getgrsid (cygsid &sid)
if (sid.string (sid_string)) if (sid.string (sid_string))
for (int i = 0; i < gr.curr_lines; i++) for (int i = 0; i < gr.curr_lines; i++)
if (!strcmp (sid_string, group_buf[i].gr_passwd)) if (!strcmp (sid_string, group_buf[i].gr_passwd))
return group_buf + i; return group_buf + i;
return NULL; return NULL;
} }
@ -244,9 +244,9 @@ internal_getgroups (int gidsetsize, __gid32_t *grouplist, cygsid * srchsid)
{ {
/* If impersonated, use impersonation token. */ /* If impersonated, use impersonation token. */
if (cygheap->user.issetuid ()) if (cygheap->user.issetuid ())
hToken = cygheap->user.token; hToken = cygheap->user.token;
else if (!OpenProcessToken (hMainProc, TOKEN_QUERY, &hToken)) else if (!OpenProcessToken (hMainProc, TOKEN_QUERY, &hToken))
hToken = NULL; hToken = NULL;
} }
if (hToken) if (hToken)
{ {
@ -261,7 +261,7 @@ internal_getgroups (int gidsetsize, __gid32_t *grouplist, cygsid * srchsid)
cygsid sid; cygsid sid;
if (srchsid) if (srchsid)
{ {
for (DWORD pg = 0; pg < groups->GroupCount; ++pg) for (DWORD pg = 0; pg < groups->GroupCount; ++pg)
if (*srchsid == groups->Groups[pg].Sid) if (*srchsid == groups->Groups[pg].Sid)
return 1; return 1;
@ -289,7 +289,7 @@ internal_getgroups (int gidsetsize, __gid32_t *grouplist, cygsid * srchsid)
else else
debug_printf ("%d = GetTokenInformation(NULL) %E", size); debug_printf ("%d = GetTokenInformation(NULL) %E", size);
if (hToken != cygheap->user.token) if (hToken != cygheap->user.token)
CloseHandle (hToken); CloseHandle (hToken);
if (cnt) if (cnt)
return cnt; return cnt;
} }

View File

@ -124,7 +124,7 @@ set_socket_inheritance (SOCKET sock)
SOCKET osock = sock; SOCKET osock = sock;
if (!DuplicateHandle (hMainProc, (HANDLE) sock, hMainProc, (HANDLE *) &sock, if (!DuplicateHandle (hMainProc, (HANDLE) sock, hMainProc, (HANDLE *) &sock,
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
system_printf ("DuplicateHandle failed %E"); system_printf ("DuplicateHandle failed %E");
else else
debug_printf ("DuplicateHandle succeeded osock %p, sock %p", osock, sock); debug_printf ("DuplicateHandle succeeded osock %p, sock %p", osock, sock);
@ -153,7 +153,7 @@ extern "C" unsigned short
htons (unsigned short x) htons (unsigned short x)
{ {
return ((((x & 0x000000ffU) << 8) | return ((((x & 0x000000ffU) << 8) |
((x & 0x0000ff00U) >> 8))); ((x & 0x0000ff00U) >> 8)));
} }
/* ntohs: standards? */ /* ntohs: standards? */

View File

@ -138,15 +138,15 @@ setacl (const char *file, int nentries, __aclent16_t *aclbufp)
*/ */
if (!(aclbufp[i].a_type & ACL_DEFAULT) if (!(aclbufp[i].a_type & ACL_DEFAULT)
&& aclbufp[i].a_type & (USER|GROUP|OTHER_OBJ) && aclbufp[i].a_type & (USER|GROUP|OTHER_OBJ)
&& (pos = searchace (aclbufp + i + 1, nentries - i - 1, && (pos = searchace (aclbufp + i + 1, nentries - i - 1,
aclbufp[i].a_type | ACL_DEFAULT, aclbufp[i].a_type | ACL_DEFAULT,
(aclbufp[i].a_type & (USER|GROUP)) (aclbufp[i].a_type & (USER|GROUP))
? aclbufp[i].a_id : -1)) >= 0 ? aclbufp[i].a_id : -1)) >= 0
&& aclbufp[i].a_perm == aclbufp[pos].a_perm) && aclbufp[i].a_perm == aclbufp[pos].a_perm)
{ {
inheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT; inheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
/* This invalidates the corresponding default entry. */ /* This invalidates the corresponding default entry. */
aclbufp[pos].a_type = USER|GROUP|ACL_DEFAULT; aclbufp[pos].a_type = USER|GROUP|ACL_DEFAULT;
} }
switch (aclbufp[i].a_type) switch (aclbufp[i].a_type)
{ {
@ -230,7 +230,7 @@ setacl (const char *file, int nentries, __aclent16_t *aclbufp)
static void static void
getace (__aclent16_t &acl, int type, int id, DWORD win_ace_mask, getace (__aclent16_t &acl, int type, int id, DWORD win_ace_mask,
DWORD win_ace_type) DWORD win_ace_type)
{ {
acl.a_type = type; acl.a_type = type;
acl.a_id = id; acl.a_id = id;
@ -405,7 +405,7 @@ getacl (const char *file, DWORD attr, int nentries, __aclent16_t *aclbufp)
lacl[0].a_perm = lacl[1].a_perm; lacl[0].a_perm = lacl[1].a_perm;
if (pos > nentries) if (pos > nentries)
{ {
set_errno (ENOSPC); set_errno (ENOSPC);
return -1; return -1;
} }
memcpy (aclbufp, lacl, pos * sizeof (__aclent16_t)); memcpy (aclbufp, lacl, pos * sizeof (__aclent16_t));

View File

@ -194,10 +194,10 @@ is_grp_member (__uid32_t uid, __gid32_t gid)
{ {
/* If gid == primary group of current user, return immediately. */ /* If gid == primary group of current user, return immediately. */
if (gid == myself->gid) if (gid == myself->gid)
return TRUE; return TRUE;
/* Calling getgroups only makes sense when reading the access token. */ /* Calling getgroups only makes sense when reading the access token. */
if (allow_ntsec) if (allow_ntsec)
{ {
__gid32_t grps[NGROUPS_MAX]; __gid32_t grps[NGROUPS_MAX];
int cnt = internal_getgroups (NGROUPS_MAX, grps); int cnt = internal_getgroups (NGROUPS_MAX, grps);
for (idx = 0; idx < cnt; ++idx) for (idx = 0; idx < cnt; ++idx)

View File

@ -1243,8 +1243,8 @@ get_attribute_from_acl (int * attribute, PACL acl, PSID owner_sid,
| ((!(*anti & S_IWUSR)) ? S_IWUSR : 0); | ((!(*anti & S_IWUSR)) ? S_IWUSR : 0);
if (ace->Mask & FILE_EXECUTE) if (ace->Mask & FILE_EXECUTE)
*flags |= ((!(*anti & S_IXOTH)) ? S_IXOTH : 0) *flags |= ((!(*anti & S_IXOTH)) ? S_IXOTH : 0)
| ((!(*anti & S_IXGRP)) ? S_IXGRP : 0) | ((!(*anti & S_IXGRP)) ? S_IXGRP : 0)
| ((!(*anti & S_IXUSR)) ? S_IXUSR : 0); | ((!(*anti & S_IXUSR)) ? S_IXUSR : 0);
if ((*attribute & S_IFDIR) && if ((*attribute & S_IFDIR) &&
(ace->Mask & (FILE_WRITE_DATA | FILE_EXECUTE | FILE_DELETE_CHILD)) (ace->Mask & (FILE_WRITE_DATA | FILE_EXECUTE | FILE_DELETE_CHILD))
== (FILE_WRITE_DATA | FILE_EXECUTE)) == (FILE_WRITE_DATA | FILE_EXECUTE))
@ -1374,7 +1374,7 @@ get_file_attribute (int use_ntsec, const char *file,
{ {
res = get_nt_attribute (file, attribute, uidret, gidret); res = get_nt_attribute (file, attribute, uidret, gidret);
if (res) if (res)
{ {
/* If reading the security descriptor failed, treat the file /* If reading the security descriptor failed, treat the file
as unreadable. */ as unreadable. */
*attribute &= ~(S_IRWXU | S_IRWXG | S_IRWXO); *attribute &= ~(S_IRWXU | S_IRWXG | S_IRWXO);

View File

@ -810,7 +810,7 @@ chown_worker (const char *name, unsigned fmode, __uid32_t uid, __gid32_t gid)
win32_path.get_win32 (), win32_path.get_win32 (),
(int *) &attrib); (int *) &attrib);
if (!res) if (!res)
res = set_file_attribute (win32_path.has_acls (), win32_path, uid, res = set_file_attribute (win32_path.has_acls (), win32_path, uid,
gid, attrib); gid, attrib);
if (res != 0 && (!win32_path.has_acls () || !allow_ntsec)) if (res != 0 && (!win32_path.has_acls () || !allow_ntsec))
{ {

View File

@ -107,7 +107,7 @@ uinfo_init ()
if (!child_proc_info) if (!child_proc_info)
internal_getlogin (cygheap->user); /* Set the cygheap->user. */ internal_getlogin (cygheap->user); /* Set the cygheap->user. */
else else
CloseHandle (cygheap->user.token); CloseHandle (cygheap->user.token);
cygheap->user.set_orig_sid (); /* Update the original sid */ cygheap->user.set_orig_sid (); /* Update the original sid */
cygheap->user.token = INVALID_HANDLE_VALUE; /* No token present */ cygheap->user.token = INVALID_HANDLE_VALUE; /* No token present */
} }
@ -469,7 +469,10 @@ pwdgrp::load (const char *posix_fname)
HANDLE fh = CreateFile (pc, GENERIC_READ, wincap.shared (), NULL, HANDLE fh = CreateFile (pc, GENERIC_READ, wincap.shared (), NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (fh == INVALID_HANDLE_VALUE) if (fh == INVALID_HANDLE_VALUE)
res = failed; {
paranoid_printf ("%s CreateFile failed, %E");
res = failed;
}
else else
{ {
DWORD size = GetFileSize (fh, NULL), read_bytes; DWORD size = GetFileSize (fh, NULL), read_bytes;
@ -497,7 +500,7 @@ pwdgrp::load (const char *posix_fname)
} }
} }
debug_printf ("load of %s %s", posix_fname, res); debug_printf ("%s load %s", posix_fname, res);
initialized = true; initialized = true;
return; return;
} }