winutils.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. #ifndef UNICODE
  18. #define UNICODE
  19. #endif
  20. #pragma once
  21. #include <stdio.h>
  22. #include <assert.h>
  23. #include <windows.h>
  24. #include <aclapi.h>
  25. #include <accctrl.h>
  26. #include <strsafe.h>
  27. #include <lm.h>
  28. enum EXIT_CODE
  29. {
  30. /* Common success exit code shared among all utilities */
  31. SUCCESS = EXIT_SUCCESS,
  32. /* Generic failure exit code share among all utilities */
  33. FAILURE = EXIT_FAILURE,
  34. /* Failure code indicates the user does not privilege to create symlinks */
  35. SYMLINK_NO_PRIVILEGE = 2,
  36. };
  37. /*
  38. * The array of 12 months' three-letter abbreviations
  39. */
  40. extern const LPCWSTR MONTHS[];
  41. /*
  42. * The Unix masks
  43. * The Windows version of <sys/stat.h> does not contain all the POSIX flag/mask
  44. * definitions. The following masks are used in 'winutils' to represent POSIX
  45. * permission mode.
  46. *
  47. */
  48. enum UnixAclMask
  49. {
  50. UX_O_EXECUTE = 00001, // S_IXOTH
  51. UX_O_WRITE = 00002, // S_IWOTH
  52. UX_O_READ = 00004, // S_IROTH
  53. UX_G_EXECUTE = 00010, // S_IXGRP
  54. UX_G_WRITE = 00020, // S_IWGRP
  55. UX_G_READ = 00040, // S_IRGRP
  56. UX_U_EXECUTE = 00100, // S_IXUSR
  57. UX_U_WRITE = 00200, // S_IWUSR
  58. UX_U_READ = 00400, // S_IRUSR
  59. UX_DIRECTORY = 0040000, // S_IFDIR
  60. UX_SYMLINK = 0120000, // S_IFLNK
  61. };
  62. /*
  63. * The WindowsAclMask and WinMasks contain the definitions used to establish
  64. * the mapping between Unix and Windows.
  65. */
  66. enum WindowsAclMask
  67. {
  68. WIN_READ, // The permission(s) that enable Unix read permission
  69. WIN_WRITE, // The permission(s) that enable Unix write permission
  70. WIN_EXECUTE, // The permission(s) that enbale Unix execute permission
  71. WIN_OWNER_SE, // The permissions that are always set for file owners
  72. WIN_ALL, // The permissions that all files on Windows should have
  73. WIN_MASKS_TOTAL
  74. };
  75. extern const ACCESS_MASK WinMasks[];
  76. int Ls(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  77. void LsUsage(LPCWSTR program);
  78. int Chmod(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  79. void ChmodUsage(LPCWSTR program);
  80. int Chown(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  81. void ChownUsage(LPCWSTR program);
  82. int Groups(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  83. void GroupsUsage(LPCWSTR program);
  84. int Hardlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  85. void HardlinkUsage();
  86. int Task(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  87. void TaskUsage();
  88. int Symlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  89. void SymlinkUsage();
  90. int Readlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  91. void ReadlinkUsage();
  92. int SystemInfo();
  93. void SystemInfoUsage();
  94. DWORD GetFileInformationByName(__in LPCWSTR pathName, __in BOOL followLink,
  95. __out LPBY_HANDLE_FILE_INFORMATION lpFileInformation);
  96. DWORD CheckAccessForCurrentUser(
  97. __in PCWSTR pathName,
  98. __in ACCESS_MASK requestedAccess,
  99. __out BOOL *allowed);
  100. DWORD ConvertToLongPath(__in PCWSTR path, __deref_out PWSTR *newPath);
  101. DWORD GetSidFromAcctNameW(__in PCWSTR acctName, __out PSID* ppSid);
  102. DWORD GetAccntNameFromSid(__in PSID pSid, __out LPWSTR *ppAcctName);
  103. void ReportErrorCode(LPCWSTR func, DWORD err);
  104. BOOL IsDirFileInfo(const BY_HANDLE_FILE_INFORMATION *fileInformation);
  105. DWORD FindFileOwnerAndPermission(
  106. __in LPCWSTR pathName,
  107. __out_opt LPWSTR *pOwnerName,
  108. __out_opt LPWSTR *pGroupName,
  109. __out_opt PINT pMask);
  110. DWORD DirectoryCheck(__in LPCWSTR pathName, __out LPBOOL result);
  111. DWORD SymbolicLinkCheck(__in LPCWSTR pathName, __out LPBOOL result);
  112. DWORD JunctionPointCheck(__in LPCWSTR pathName, __out LPBOOL result);
  113. DWORD ChangeFileModeByMask(__in LPCWSTR path, INT mode);
  114. DWORD GetLocalGroupsForUser(__in LPCWSTR user,
  115. __out LPLOCALGROUP_USERS_INFO_0 *groups, __out LPDWORD entries);
  116. BOOL EnablePrivilege(__in LPCWSTR privilegeName);