From: Corinna Vinschen Date: Tue, 21 Aug 2007 17:38:27 +0000 (+0000) Subject: * uinfo.cc (pwdgrp::load): Use NT native functions. X-Git-Tag: gdb_6_7-2007-09-07-branchpoint~27 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=e1e4b104b6610b4e7bbf70d7759f0e08bfae6fa6;p=newlib-cygwin.git * uinfo.cc (pwdgrp::load): Use NT native functions. --- diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0db674fb9..4b0ce4eb1 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,7 @@ +2007-08-21 Corinna Vinschen + + * uinfo.cc (pwdgrp::load): Use NT native functions. + 2007-08-21 Corinna Vinschen * fhandler_disk_file.cc (fhandler_base::fstat_helper): Rewrite checking diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index 210b1d1f7..af6035c5b 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -508,9 +508,16 @@ pwdgrp::add_line (char *eptr) void pwdgrp::load (const char *posix_fname) { - const char *res; static const char failed[] = "failed"; static const char succeeded[] = "succeeded"; + const char *res = failed; + HANDLE fh = NULL; + LARGE_INTEGER off = { QuadPart:0LL }; + + NTSTATUS status; + OBJECT_ATTRIBUTES attr; + IO_STATUS_BLOCK io; + FILE_STANDARD_INFORMATION fsi; if (buf) free (buf); @@ -525,44 +532,54 @@ pwdgrp::load (const char *posix_fname) if (pc.error || !pc.exists () || pc.isdir ()) { paranoid_printf ("strange path_conv problem"); - res = failed; + goto out; } - else + status = NtOpenFile (&fh, FILE_READ_DATA, + pc.get_object_attr (attr, sec_none_nih), &io, + FILE_SHARE_VALID_FLAGS, 0); + if (!NT_SUCCESS (status)) { - HANDLE fh = CreateFile (pc.get_win32 (), GENERIC_READ, - FILE_SHARE_VALID_FLAGS, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, 0); - if (fh == INVALID_HANDLE_VALUE) - { - paranoid_printf ("%s CreateFile failed, %E"); - res = failed; - } - else - { - DWORD size = GetFileSize (fh, NULL), read_bytes; - buf = (char *) malloc (size + 1); - if (!ReadFile (fh, buf, size, &read_bytes, NULL)) - { - paranoid_printf ("ReadFile failed, %E"); - CloseHandle (fh); - if (buf) - free (buf); - buf = NULL; - res = failed; - } - else - { - CloseHandle (fh); - buf[read_bytes] = '\0'; - char *eptr = buf; - while ((eptr = add_line (eptr))) - continue; - debug_printf ("%s curr_lines %d", posix_fname, curr_lines); - res = succeeded; - } - } + paranoid_printf ("NtOpenFile(%S) failed, status %p", + pc.get_nt_native_path (), status); + goto out; } - + status = NtQueryInformationFile (fh, &io, &fsi, sizeof fsi, + FileStandardInformation); + if (!NT_SUCCESS (status)) + { + paranoid_printf ("NtQueryInformationFile(%S) failed, status %p", + pc.get_nt_native_path (), status); + goto out; + } + /* FIXME: Should we test for HighPart set? If so, the + passwd or group file is way beyond what we can handle. */ + /* FIXME 2: It's still ugly that we keep the file in memory. + Big organizations have naturally large passwd files. */ + buf = (char *) malloc (fsi.EndOfFile.LowPart + 1); + if (!buf) + { + paranoid_printf ("malloc (%d) failed", fsi.EndOfFile.LowPart); + goto out; + } + status = NtReadFile (fh, NULL, NULL, NULL, &io, buf, + fsi.EndOfFile.LowPart, &off, NULL); + if (!NT_SUCCESS (status)) + { + paranoid_printf ("NtReadFile(%S) failed, status %p", + pc.get_nt_native_path (), status); + free (buf); + goto out; + } + buf[fsi.EndOfFile.LowPart] = '\0'; + char *eptr = buf; + while ((eptr = add_line (eptr))) + continue; + debug_printf ("%s curr_lines %d", posix_fname, curr_lines); + res = succeeded; + +out: + if (fh) + NtClose (fh); debug_printf ("%s load %s", posix_fname, res); initialized = true; }