winutils.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <tchar.h>
  27. #include <strsafe.h>
  28. #include <lm.h>
  29. enum EXIT_CODE
  30. {
  31. /* Common success exit code shared among all utilities */
  32. SUCCESS = EXIT_SUCCESS,
  33. /* Generic failure exit code share among all utilities */
  34. FAILURE = EXIT_FAILURE,
  35. /* Failure code indicates the user does not privilege to create symlinks */
  36. SYMLINK_NO_PRIVILEGE = 2,
  37. };
  38. /*
  39. * The array of 12 months' three-letter abbreviations
  40. */
  41. extern const LPCWSTR MONTHS[];
  42. /*
  43. * The Unix masks
  44. * The Windows version of <sys/stat.h> does not contain all the POSIX flag/mask
  45. * definitions. The following masks are used in 'winutils' to represent POSIX
  46. * permission mode.
  47. *
  48. */
  49. enum UnixAclMask
  50. {
  51. UX_O_EXECUTE = 00001, // S_IXOTH
  52. UX_O_WRITE = 00002, // S_IWOTH
  53. UX_O_READ = 00004, // S_IROTH
  54. UX_G_EXECUTE = 00010, // S_IXGRP
  55. UX_G_WRITE = 00020, // S_IWGRP
  56. UX_G_READ = 00040, // S_IRGRP
  57. UX_U_EXECUTE = 00100, // S_IXUSR
  58. UX_U_WRITE = 00200, // S_IWUSR
  59. UX_U_READ = 00400, // S_IRUSR
  60. UX_DIRECTORY = 0040000, // S_IFDIR
  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(int argc, wchar_t *argv[]);
  78. void LsUsage(LPCWSTR program);
  79. int Chmod(int argc, wchar_t *argv[]);
  80. void ChmodUsage(LPCWSTR program);
  81. int Chown(int argc, wchar_t *argv[]);
  82. void ChownUsage(LPCWSTR program);
  83. int Groups(int argc, wchar_t *argv[]);
  84. void GroupsUsage(LPCWSTR program);
  85. int Hardlink(int argc, wchar_t *argv[]);
  86. void HardlinkUsage();
  87. int Task(int argc, wchar_t *argv[]);
  88. void TaskUsage();
  89. int Symlink(int argc, wchar_t *argv[]);
  90. void SymlinkUsage();
  91. int SystemInfo();
  92. void SystemInfoUsage();
  93. DWORD GetFileInformationByName(__in LPCWSTR pathName, __in BOOL followLink,
  94. __out LPBY_HANDLE_FILE_INFORMATION lpFileInformation);
  95. DWORD ConvertToLongPath(__in PCWSTR path, __deref_out PWSTR *newPath);
  96. DWORD GetSidFromAcctNameW(LPCWSTR acctName, PSID* ppSid);
  97. DWORD GetAccntNameFromSid(PSID pSid, LPWSTR *ppAcctName);
  98. void ReportErrorCode(LPCWSTR func, DWORD err);
  99. BOOL IsDirFileInfo(const BY_HANDLE_FILE_INFORMATION *fileInformation);
  100. DWORD FindFileOwnerAndPermission(
  101. __in LPCWSTR pathName,
  102. __out_opt LPWSTR *pOwnerName,
  103. __out_opt LPWSTR *pGroupName,
  104. __out_opt PINT pMask);
  105. DWORD DirectoryCheck(__in LPCWSTR pathName, __out LPBOOL result);
  106. DWORD SymbolicLinkCheck(__in LPCWSTR pathName, __out LPBOOL result);
  107. DWORD JunctionPointCheck(__in LPCWSTR pathName, __out LPBOOL result);
  108. DWORD ChangeFileModeByMask(__in LPCWSTR path, INT mode);
  109. DWORD GetLocalGroupsForUser(__in LPCWSTR user,
  110. __out LPLOCALGROUP_USERS_INFO_0 *groups, __out LPDWORD entries);
  111. BOOL EnablePrivilege(__in LPCWSTR privilegeName);