pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


test-qfif1.c
Posted by Anonymous on Thu 16th Nov 2023 15:13
raw | new post
view followups (newest first): test-qfif1.c by Anonymous

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <wchar.h>
  4. #include <errno.h>
  5. #include <locale.h>
  6. #include <w32api/windef.h>
  7. #include <w32api/winnt.h>
  8. #include <ddk/ntifs.h>
  9. #include <windows.h>
  10. #include <sys/cygwin.h>
  11.  
  12. int
  13. main (int argc, char **argv)
  14. {
  15.   WCHAR pathbuf[1024]; /* Should be big enough for this test */
  16.   WCHAR *path;
  17.   UNICODE_STRING upath;
  18.   OBJECT_ATTRIBUTES attr, attr2;
  19.   NTSTATUS status;
  20.   HANDLE h;
  21.   IO_STATUS_BLOCK io;
  22.   FILE_NETWORK_OPEN_INFORMATION fnoi;
  23.  
  24.   if (argc < 2)
  25.     {
  26.       fprintf (stderr, "Usage: %s path\n", argv[0]);
  27.       return 1;
  28.     }
  29.   setlocale (LC_ALL, "");
  30.   while (--argc > 0)
  31.     {
  32.       if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, *++argv, pathbuf + 6,
  33.                         1024 * sizeof (WCHAR)))
  34.         {
  35.           fprintf (stderr, "%s: Path conversion failed: %s\n",
  36.                    strerror (errno));
  37.           continue;
  38.         }
  39.       if (pathbuf[6] == L'\\' && pathbuf[7] == L'\\')
  40.         path = wcsncpy (pathbuf, L"\\??\\UNC", 7);
  41.       else
  42.         path = wcsncpy (pathbuf + 2, L"\\??\\", 4);
  43.  
  44.       RtlInitUnicodeString (&upath, path);
  45.       InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE,
  46.                                   NULL, NULL);
  47.       status = NtQueryFullAttributesFile (&attr, &fnoi);
  48.       if (!NT_SUCCESS (status))
  49.         printf ("NtQueryFullAttributesFile(%ls) by name failed,\n"
  50.                 "status code 0x%08lx\n", path, status);
  51.       else
  52.         printf ("NtQueryFullAttributesFile(%ls) by name works\n", path);
  53.  
  54.       status = NtOpenFile (&h, READ_CONTROL | FILE_READ_ATTRIBUTES, &attr, &io,
  55.                            FILE_SHARE_VALID_FLAGS, 0);
  56.       if (!NT_SUCCESS (status))
  57.         {
  58.           fprintf (stderr, "NtOpenFile(%ls) failed, status code 0x%08lx\n",
  59.                    path, status);
  60.           continue;
  61.         }
  62.  
  63.       RtlInitUnicodeString (&upath, L"");
  64.       InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, h, NULL);
  65.       status = NtQueryFullAttributesFile (&attr, &fnoi);
  66.       if (!NT_SUCCESS (status))
  67.         printf ("NtQueryFullAttributesFile(%ls) by handle failed,\n"
  68.                 "status code 0x%08lx\n", path, status);
  69.       else
  70.         printf ("NtQueryFullAttributesFile(%ls) by handle works\n", path);
  71.       NtClose (h);
  72.     }
  73.   return 0;
  74. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at