winutils.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_REGULAR = 0100000, // S_IFREG
  61. UX_SYMLINK = 0120000, // S_IFLNK
  62. };
  63. /*
  64. * The WindowsAclMask and WinMasks contain the definitions used to establish
  65. * the mapping between Unix and Windows.
  66. */
  67. enum WindowsAclMask
  68. {
  69. WIN_READ, // The permission(s) that enable Unix read permission
  70. WIN_WRITE, // The permission(s) that enable Unix write permission
  71. WIN_EXECUTE, // The permission(s) that enbale Unix execute permission
  72. WIN_OWNER_SE, // The permissions that are always set for file owners
  73. WIN_ALL, // The permissions that all files on Windows should have
  74. WIN_MASKS_TOTAL
  75. };
  76. extern const ACCESS_MASK WinMasks[];
  77. int Ls(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  78. void LsUsage(LPCWSTR program);
  79. int Chmod(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  80. void ChmodUsage(LPCWSTR program);
  81. int Chown(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  82. void ChownUsage(LPCWSTR program);
  83. int Groups(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  84. void GroupsUsage(LPCWSTR program);
  85. int Hardlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  86. void HardlinkUsage();
  87. int Task(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  88. void TaskUsage();
  89. int Symlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  90. void SymlinkUsage();
  91. int Readlink(__in int argc, __in_ecount(argc) wchar_t *argv[]);
  92. void ReadlinkUsage();
  93. int SystemInfo();
  94. void SystemInfoUsage();
  95. DWORD GetFileInformationByName(__in LPCWSTR pathName, __in BOOL followLink,
  96. __out LPBY_HANDLE_FILE_INFORMATION lpFileInformation);
  97. DWORD CheckAccessForCurrentUser(
  98. __in PCWSTR pathName,
  99. __in ACCESS_MASK requestedAccess,
  100. __out BOOL *allowed);
  101. DWORD ConvertToLongPath(__in PCWSTR path, __deref_out PWSTR *newPath);
  102. DWORD GetSidFromAcctNameW(__in PCWSTR acctName, __out PSID* ppSid);
  103. DWORD GetAccntNameFromSid(__in PSID pSid, __out LPWSTR *ppAcctName);
  104. void ReportErrorCode(LPCWSTR func, DWORD err);
  105. BOOL IsDirFileInfo(const BY_HANDLE_FILE_INFORMATION *fileInformation);
  106. DWORD FindFileOwnerAndPermission(
  107. __in LPCWSTR pathName,
  108. __in BOOL followLink,
  109. __out_opt LPWSTR *pOwnerName,
  110. __out_opt LPWSTR *pGroupName,
  111. __out_opt PINT pMask);
  112. DWORD FindFileOwnerAndPermissionByHandle(
  113. __in HANDLE fileHandle,
  114. __out_opt LPWSTR *pOwnerName,
  115. __out_opt LPWSTR *pGroupName,
  116. __out_opt PINT pMask);
  117. DWORD DirectoryCheck(__in LPCWSTR pathName, __out LPBOOL result);
  118. DWORD SymbolicLinkCheck(__in LPCWSTR pathName, __out LPBOOL result);
  119. DWORD JunctionPointCheck(__in LPCWSTR pathName, __out LPBOOL result);
  120. DWORD ChangeFileModeByMask(__in LPCWSTR path, INT mode);
  121. DWORD GetLocalGroupsForUser(__in LPCWSTR user,
  122. __out LPLOCALGROUP_USERS_INFO_0 *groups, __out LPDWORD entries);
  123. BOOL EnablePrivilege(__in LPCWSTR privilegeName);
  124. void GetLibraryName(__in LPCVOID lpAddress, __out LPWSTR *filename);