ReactOS 0.4.16-dev-2613-g9533ad7
cacls.c File Reference
#include "precomp.h"
Include dependency graph for cacls.c:

Go to the source code of this file.

Functions

static VOID PrintError (DWORD dwError)
 
static BOOL PrintFileDacl (IN LPTSTR FilePath, IN LPTSTR FileName)
 
static VOID AddBackslash (LPTSTR FilePath)
 
static BOOL GetPathOfFile (LPTSTR FilePath, LPCTSTR pszFiles)
 
static BOOL PrintDaclsOfFiles (LPCTSTR pszFiles)
 
static BOOL GrantUserAccessRights (LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
 
static BOOL ReplaceUserAccessRights (LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
 
static BOOL EditUserAccessRights (LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
 
static BOOL DenyUserAccess (LPCTSTR FilePath, LPCTSTR File, LPCTSTR User)
 
static BOOL RevokeUserAccessRights (LPCTSTR FilePath, LPCTSTR File, LPCTSTR User)
 
static BOOL ChangeFileACL (LPCTSTR FilePath, LPCTSTR File)
 
static BOOL ChangeACLsOfFiles (LPCTSTR pszFiles)
 
static BOOL ChangeACLsOfFilesInCurDir (LPCTSTR pszFiles)
 
int _tmain (int argc, const TCHAR *argv[])
 

Variables

BOOL OptionT = FALSE
 
BOOL OptionE = FALSE
 
BOOL OptionC = FALSE
 
BOOL OptionG = FALSE
 
BOOL OptionR = FALSE
 
BOOL OptionP = FALSE
 
BOOL OptionD = FALSE
 
LPCTSTR GUser
 
LPCTSTR GPerm
 
LPCTSTR RUser
 
LPCTSTR PUser
 
LPCTSTR PPerm
 
LPCTSTR DUser
 
static GENERIC_MAPPING FileGenericMapping
 

Function Documentation

◆ _tmain()

int _tmain ( int  argc,
const TCHAR argv[] 
)

Definition at line 735 of file cacls.c.

736{
737 INT i;
738 LPTSTR pch;
740
741 /* Initialize the Console Standard Streams */
743
744 if (argc <= 1)
745 {
747 return 0;
748 }
749
750 // FIXME: Convert to proper parsing, with support for /?
751
752 /*
753 * parse command line options
754 */
755 for (i = 2; i < argc; i++)
756 {
757 if (_tcsicmp(argv[i], _T("/T")) == 0)
758 {
759 OptionT = TRUE;
760 }
761 else if (_tcsicmp(argv[i], _T("/E")) == 0)
762 {
763 OptionE = TRUE;
764 }
765 else if (_tcsicmp(argv[i], _T("/C")) == 0)
766 {
767 OptionC = TRUE;
768 }
769 else if (_tcsicmp(argv[i], _T("/G")) == 0)
770 {
771 if (i + 1 < argc)
772 {
773 pch = _tcschr(argv[++i], _T(':'));
774 if (pch != NULL)
775 {
776 OptionG = TRUE;
777 *pch = 0;
778 GUser = argv[i];
779 GPerm = pch + 1;
780 continue;
781 }
782 }
784 break;
785 }
786 else if (_tcsicmp(argv[i], _T("/R")) == 0)
787 {
788 if (i + 1 < argc)
789 {
790 RUser = argv[++i];
791 OptionR = TRUE;
792 continue;
793 }
795 break;
796 }
797 else if (_tcsicmp(argv[i], _T("/P")) == 0)
798 {
799 if (i + 1 < argc)
800 {
801 pch = _tcschr(argv[++i], _T(':'));
802 if (pch != NULL)
803 {
804 OptionP = TRUE;
805 *pch = 0;
806 PUser = argv[i];
807 PPerm = pch + 1;
808 continue;
809 }
810 }
812 break;
813 }
814 else if (_tcsicmp(argv[i], _T("/D")) == 0)
815 {
816 if (i + 1 < argc)
817 {
818 OptionD = TRUE;
819 DUser = argv[++i];
820 continue;
821 }
823 break;
824 }
825 else
826 {
828 break;
829 }
830 }
831
833 {
836 return 1;
837 }
838
839 /* /R is only valid with /E */
840 if (OptionR && !OptionE)
841 {
842 OptionR = FALSE;
843 }
844
846
847 if (OptionT)
848 {
850 }
851 else
852 {
854 }
855
856 return 0;
857}
#define IDS_HELP
Definition: resource.h:3
LPCTSTR PUser
Definition: cacls.c:25
static VOID PrintError(DWORD dwError)
Definition: cacls.c:37
BOOL OptionR
Definition: cacls.c:24
LPCTSTR GUser
Definition: cacls.c:25
BOOL OptionP
Definition: cacls.c:24
BOOL OptionD
Definition: cacls.c:24
LPCTSTR PPerm
Definition: cacls.c:25
static BOOL PrintDaclsOfFiles(LPCTSTR pszFiles)
Definition: cacls.c:402
LPCTSTR DUser
Definition: cacls.c:25
BOOL OptionE
Definition: cacls.c:23
LPCTSTR GPerm
Definition: cacls.c:25
BOOL OptionC
Definition: cacls.c:23
static BOOL ChangeACLsOfFiles(LPCTSTR pszFiles)
Definition: cacls.c:585
static BOOL ChangeACLsOfFilesInCurDir(LPCTSTR pszFiles)
Definition: cacls.c:638
BOOL OptionG
Definition: cacls.c:24
LPCTSTR RUser
Definition: cacls.c:25
BOOL OptionT
Definition: cacls.c:23
#define ConInitStdStreams()
Definition: conutils_noros.h:5
#define StdOut
Definition: conutils_noros.h:6
void ConResPuts(FILE *fp, UINT nID)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
MonoAssembly int argc
Definition: metahost.c:107
unsigned int BOOL
Definition: ntddk_ex.h:94
@ InvalidParameter
Definition: gdiplustypes.h:28
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _tcsicmp
Definition: tchar.h:1425
#define _tcschr
Definition: tchar.h:1406
#define pch(ap)
Definition: match.c:418
#define argv
Definition: mplay32.c:18
LPSTR LPTSTR
Definition: ms-dtyp.idl:131
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22

◆ AddBackslash()

static VOID AddBackslash ( LPTSTR  FilePath)
static

Definition at line 359 of file cacls.c.

360{
361 /* Find the last backslash. If there is none, or if it doesn't
362 * terminate the string, then append a backslash. */
363 LPTSTR pch = _tcsrchr(FilePath, _T('\\'));
364 if (!pch || *(pch+1))
365 _tcscat(FilePath, _T("\\"));
366}
PCWSTR FilePath
#define _tcscat
Definition: tchar.h:622
#define _tcsrchr
Definition: tchar.h:1413

Referenced by ChangeACLsOfFilesInCurDir(), and GetPathOfFile().

◆ ChangeACLsOfFiles()

static BOOL ChangeACLsOfFiles ( LPCTSTR  pszFiles)
static

Definition at line 585 of file cacls.c.

586{
588 HANDLE hFind;
589 WIN32_FIND_DATA FindData;
590 DWORD LastError;
591
592 /*
593 * get the file path
594 */
595 if (!GetPathOfFile(FilePath, pszFiles))
596 return FALSE;
597
598 /*
599 * search for files in current directory
600 */
601 hFind = FindFirstFile(pszFiles, &FindData);
602 if (hFind == INVALID_HANDLE_VALUE)
603 return FALSE;
604 do
605 {
606 if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
607 continue;
608
609 if (!ChangeFileACL(FilePath, FindData.cFileName))
610 {
611 LastError = GetLastError();
612 if (LastError == ERROR_ACCESS_DENIED)
613 {
614 PrintError(LastError);
615 if (!OptionC)
616 {
617 FindClose(hFind);
618 return FALSE;
619 }
620 }
621 else
622 break;
623 }
624 } while (FindNextFile(hFind, &FindData));
625 LastError = GetLastError();
626 FindClose(hFind);
627
628 if (LastError != ERROR_NO_MORE_FILES)
629 {
630 PrintError(LastError);
631 return FALSE;
632 }
633
634 return TRUE;
635}
static BOOL ChangeFileACL(LPCTSTR FilePath, LPCTSTR File)
Definition: cacls.c:547
static BOOL GetPathOfFile(LPTSTR FilePath, LPCTSTR pszFiles)
Definition: cacls.c:369
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
unsigned long DWORD
Definition: ntddk_ex.h:95
char TCHAR
Definition: tchar.h:1402
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FindNextFile
Definition: winbase.h:3537
#define FindFirstFile
Definition: winbase.h:3531
#define ERROR_NO_MORE_FILES
Definition: winerror.h:243

Referenced by _tmain().

◆ ChangeACLsOfFilesInCurDir()

static BOOL ChangeACLsOfFilesInCurDir ( LPCTSTR  pszFiles)
static

Definition at line 638 of file cacls.c.

639{
640 HANDLE hFind;
641 WIN32_FIND_DATA FindData;
642 TCHAR szCurDir[MAX_PATH];
643 DWORD LastError;
644
645 /*
646 * get the file path (current directory)
647 */
648 GetCurrentDirectory(MAX_PATH, szCurDir);
649 AddBackslash(szCurDir);
650
651 /*
652 * search for files in current directory
653 */
654 hFind = FindFirstFile(pszFiles, &FindData);
655 if (hFind == INVALID_HANDLE_VALUE)
656 return FALSE;
657 do
658 {
659 if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
660 continue;
661
662 if (!ChangeFileACL(szCurDir, FindData.cFileName))
663 {
664 LastError = GetLastError();
665 if (LastError == ERROR_ACCESS_DENIED)
666 {
667 PrintError(LastError);
668 if (!OptionC)
669 {
670 FindClose(hFind);
671 return FALSE;
672 }
673 }
674 else
675 break;
676 }
677 } while (FindNextFile(hFind, &FindData));
678 LastError = GetLastError();
679 FindClose(hFind);
680
681 if (LastError != ERROR_NO_MORE_FILES)
682 {
683 PrintError(LastError);
684 return FALSE;
685 }
686
687 /*
688 * search for subdirectory in current directory
689 */
690 hFind = FindFirstFile(_T("*"), &FindData);
691 if (hFind == INVALID_HANDLE_VALUE)
692 return FALSE;
693 do
694 {
695 if (_tcscmp(FindData.cFileName, _T(".")) == 0 ||
696 _tcscmp(FindData.cFileName, _T("..")) == 0)
697 continue;
698
699 if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
700 {
701 GetCurrentDirectory(MAX_PATH, szCurDir);
702 if (SetCurrentDirectory(FindData.cFileName))
703 {
705 SetCurrentDirectory(szCurDir);
706 }
707 else
708 {
709 LastError = GetLastError();
710 if (LastError == ERROR_ACCESS_DENIED)
711 {
712 PrintError(LastError);
713 if (!OptionC)
714 {
715 FindClose(hFind);
716 return FALSE;
717 }
718 }
719 else
720 break;
721 }
722 }
723 } while (FindNextFile(hFind, &FindData));
724 LastError = GetLastError();
725 FindClose(hFind);
726
727 if (LastError != ERROR_NO_MORE_FILES)
728 {
729 PrintError(LastError);
730 return FALSE;
731 }
732 return TRUE;
733}
static VOID AddBackslash(LPTSTR FilePath)
Definition: cacls.c:359
#define _tcscmp
Definition: tchar.h:1424
#define SetCurrentDirectory
Definition: winbase.h:3652
#define GetCurrentDirectory
Definition: winbase.h:3554

Referenced by _tmain(), and ChangeACLsOfFilesInCurDir().

◆ ChangeFileACL()

static BOOL ChangeFileACL ( LPCTSTR  FilePath,
LPCTSTR  File 
)
static

Definition at line 547 of file cacls.c.

548{
549 if (OptionG)
550 {
551 /* Grant specified user access rights. */
553 }
554
555 if (OptionP)
556 {
557 if (!OptionE)
558 {
559 /* Replace specified user's access rights. */
561 }
562 else
563 {
564 /* Edit ACL instead of replacing it. */
566 }
567 }
568
569 if (OptionD)
570 {
571 /* Deny specified user access. */
573 }
574
575 if (OptionR)
576 {
577 /* Revoke specified user's access rights. */
579 }
580
581 return TRUE;
582}
static BOOL DenyUserAccess(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User)
Definition: cacls.c:533
static BOOL GrantUserAccessRights(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
Definition: cacls.c:461
static BOOL ReplaceUserAccessRights(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
Definition: cacls.c:481
static BOOL EditUserAccessRights(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
Definition: cacls.c:507
static BOOL RevokeUserAccessRights(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User)
Definition: cacls.c:540
Definition: File.h:16

Referenced by ChangeACLsOfFiles(), and ChangeACLsOfFilesInCurDir().

◆ DenyUserAccess()

static BOOL DenyUserAccess ( LPCTSTR  FilePath,
LPCTSTR  File,
LPCTSTR  User 
)
static

Definition at line 533 of file cacls.c.

534{
535 /* TODO & FIXME */
536 return FALSE;
537}

Referenced by ChangeFileACL().

◆ EditUserAccessRights()

static BOOL EditUserAccessRights ( LPCTSTR  FilePath,
LPCTSTR  File,
LPCTSTR  User,
TCHAR  Perm 
)
static

Definition at line 507 of file cacls.c.

512{
513 /* TODO & FIXME */
514 switch(Perm)
515 {
516 case _T('N'): // None
517 break;
518 case _T('R'): // Read
519 break;
520 case _T('W'): // Write
521 break;
522 case _T('C'): // Change (write)
523 break;
524 case _T('F'): // Full control
525 break;
526 default:
527 break;
528 }
529 return FALSE;
530}

Referenced by ChangeFileACL().

◆ GetPathOfFile()

static BOOL GetPathOfFile ( LPTSTR  FilePath,
LPCTSTR  pszFiles 
)
static

Definition at line 369 of file cacls.c.

370{
371 TCHAR FullPath[MAX_PATH];
372 LPTSTR pch;
373 DWORD attrs;
374
375 _tcsncpy(FilePath, pszFiles, MAX_PATH);
376 pch = _tcsrchr(FilePath, _T('\\'));
377 if (pch != NULL)
378 {
379 *pch = 0;
380 if (!GetFullPathName(FilePath, MAX_PATH, FullPath, NULL))
381 {
383 return FALSE;
384 }
385 _tcsncpy(FilePath, FullPath, MAX_PATH);
386
388 if (attrs == 0xFFFFFFFF || !(attrs & FILE_ATTRIBUTE_DIRECTORY))
389 {
391 return FALSE;
392 }
393 }
394 else
396
398 return TRUE;
399}
#define _tcsncpy
Definition: tchar.h:1410
#define GetFileAttributes
Definition: winbase.h:3564
#define GetFullPathName
Definition: winbase.h:3570
#define ERROR_DIRECTORY
Definition: winerror.h:416

Referenced by ChangeACLsOfFiles(), and PrintDaclsOfFiles().

◆ GrantUserAccessRights()

static BOOL GrantUserAccessRights ( LPCTSTR  FilePath,
LPCTSTR  File,
LPCTSTR  User,
TCHAR  Perm 
)
static

Definition at line 461 of file cacls.c.

462{
463 /* TODO & FIXME */
464 switch(Perm)
465 {
466 case _T('R'): // Read
467 break;
468 case _T('W'): // Write
469 break;
470 case _T('C'): // Change (write)
471 break;
472 case _T('F'): // Full control
473 break;
474 default:
475 break;
476 }
477 return FALSE;
478}

Referenced by ChangeFileACL().

◆ PrintDaclsOfFiles()

static BOOL PrintDaclsOfFiles ( LPCTSTR  pszFiles)
static

Definition at line 402 of file cacls.c.

403{
405 WIN32_FIND_DATA FindData;
406 HANDLE hFind;
407 DWORD LastError;
408
409 /*
410 * get the file path
411 */
412 if (!GetPathOfFile(FilePath, pszFiles))
413 return FALSE;
414
415 /*
416 * search for the files
417 */
418 hFind = FindFirstFile(pszFiles, &FindData);
419 if (hFind == INVALID_HANDLE_VALUE)
420 return FALSE;
421 do
422 {
423 if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
424 continue;
425
426 if (!PrintFileDacl(FilePath, FindData.cFileName))
427 {
428 LastError = GetLastError();
429 if (LastError == ERROR_ACCESS_DENIED)
430 {
431 PrintError(LastError);
432 if (!OptionC)
433 {
434 FindClose(hFind);
435 return FALSE;
436 }
437 }
438 else
439 {
440 break;
441 }
442 }
443 else
444 {
445 ConPuts(StdOut, L"\n");
446 }
447 } while (FindNextFile(hFind, &FindData));
448 LastError = GetLastError();
449 FindClose(hFind);
450
451 if (LastError != ERROR_NO_MORE_FILES)
452 {
453 PrintError(LastError);
454 return FALSE;
455 }
456
457 return TRUE;
458}
static BOOL PrintFileDacl(IN LPTSTR FilePath, IN LPTSTR FileName)
Definition: cacls.c:47
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: conutils_noros.h:8
#define L(x)
Definition: resources.c:13

Referenced by _tmain().

◆ PrintError()

static VOID PrintError ( DWORD  dwError)
static

Definition at line 37 of file cacls.c.

38{
39 if (dwError == ERROR_SUCCESS)
40 return;
41
43 NULL, dwError, LANG_USER_DEFAULT);
44}
#define StdErr
Definition: conutils_noros.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:835
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400

Referenced by _tmain(), ChangeACLsOfFiles(), ChangeACLsOfFilesInCurDir(), GetPathOfFile(), InterpretInteractive(), and PrintDaclsOfFiles().

◆ PrintFileDacl()

static BOOL PrintFileDacl ( IN LPTSTR  FilePath,
IN LPTSTR  FileName 
)
static

Definition at line 47 of file cacls.c.

49{
52 DWORD SDSize = 0;
53 TCHAR FullFileName[MAX_PATH + 1];
54 BOOL Error = FALSE, Ret = FALSE;
55
57 if (Length > MAX_PATH)
58 {
59 /* file name too long */
61 return FALSE;
62 }
63
64 _tcscpy(FullFileName, FilePath);
65 _tcscat(FullFileName, FileName);
66
67 /* find out how much memory we need */
68 if (!GetFileSecurity(FullFileName,
70 NULL,
71 0,
72 &SDSize) &&
74 {
75 return FALSE;
76 }
77
79 0,
80 SDSize);
82 {
83 if (GetFileSecurity(FullFileName,
86 SDSize,
87 &SDSize))
88 {
89 PACL Dacl;
92
95 &Dacl,
97 {
98 if (DaclPresent)
99 {
101 DWORD AceIndex = 0;
102
103 /* dump the ACL */
104 while (GetAce(Dacl,
105 AceIndex,
106 (PVOID*)&Ace))
107 {
108 SID_NAME_USE Use;
109 DWORD NameSize = 0;
110 DWORD DomainSize = 0;
111 LPTSTR Name = NULL;
113 LPTSTR SidString = NULL;
114 size_t IndentAccess;
115 DWORD AccessMask = Ace->Mask;
116 PSID Sid = (PSID)&Ace->SidStart;
117
118 /* attempt to translate the SID into a readable string */
120 Sid,
121 Name,
122 &NameSize,
123 Domain,
124 &DomainSize,
125 &Use))
126 {
127 if (GetLastError() == ERROR_NONE_MAPPED || NameSize == 0)
128 {
129 goto BuildSidString;
130 }
131 else
132 {
134 {
135 Error = TRUE;
136 break;
137 }
138
140 0,
141 (NameSize + DomainSize) * sizeof(TCHAR));
142 if (Name == NULL)
143 {
145 Error = TRUE;
146 break;
147 }
148
149 Domain = Name + NameSize;
150 Name[0] = _T('\0');
151 if (DomainSize != 0)
152 Domain[0] = _T('\0');
154 Sid,
155 Name,
156 &NameSize,
157 Domain,
158 &DomainSize,
159 &Use))
160 {
162 0,
163 Name);
164 Name = NULL;
165 goto BuildSidString;
166 }
167 }
168 }
169 else
170 {
171BuildSidString:
173 &SidString))
174 {
175 Error = TRUE;
176 break;
177 }
178 }
179
180 /* print the file name or space */
181 ConPrintf(StdOut, L"%s ", FullFileName);
182
183 /* attempt to map the SID to a user name */
184 if (AceIndex == 0)
185 {
186 size_t i = 0;
187
188 /* overwrite the full file name with spaces so we
189 only print the file name once */
190 while (FullFileName[i] != _T('\0'))
191 FullFileName[i++] = _T(' ');
192 }
193
194 /* print the domain and/or user if possible, or the SID string */
195 if (Name != NULL && Domain[0] != _T('\0'))
196 {
197 ConPrintf(StdOut, L"%s\\%s:", Domain, Name);
198 IndentAccess = _tcslen(Domain) + _tcslen(Name);
199 }
200 else
201 {
202 LPTSTR DisplayString = (Name != NULL ? Name : SidString);
203
205 IndentAccess = _tcslen(DisplayString);
206 }
207
208 /* print the ACE Flags */
209 if (Ace->Header.AceFlags & CONTAINER_INHERIT_ACE)
210 {
211 IndentAccess += (size_t)ConResPuts(StdOut, IDS_ABBR_CI);
212 }
213 if (Ace->Header.AceFlags & OBJECT_INHERIT_ACE)
214 {
215 IndentAccess += (size_t)ConResPuts(StdOut, IDS_ABBR_OI);
216 }
217 if (Ace->Header.AceFlags & INHERIT_ONLY_ACE)
218 {
219 IndentAccess += (size_t)ConResPuts(StdOut, IDS_ABBR_IO);
220 }
221
222 IndentAccess += 2;
223
224 /* print the access rights */
227 if (Ace->Header.AceType & ACCESS_DENIED_ACE_TYPE)
228 {
230 {
232 }
233 else
234 {
236 goto PrintSpecialAccess;
237 }
238 }
239 else
240 {
242 {
244 }
245 else if (!(Ace->Mask & (GENERIC_READ | GENERIC_EXECUTE)) &&
247 {
249 }
251 {
253 }
254 else if (AccessMask == FILE_GENERIC_WRITE)
255 {
257 }
258 else
259 {
260 DWORD x;
261 static const struct
262 {
263 DWORD Access;
264 UINT uID;
265 }
266 AccessRights[] =
267 {
294 };
295
297
298PrintSpecialAccess:
300
301 /* print the special access rights */
302 x = ARRAYSIZE(AccessRights);
303 while (x-- != 0)
304 {
305 if ((Ace->Mask & AccessRights[x].Access) == AccessRights[x].Access)
306 {
307 ConPrintf(StdOut, L"\n%s ", FullFileName);
308 ConPrintf(StdOut, L"%*s", IndentAccess, L"");
309 ConResPuts(StdOut, AccessRights[x].uID);
310 }
311 }
312
313 ConPuts(StdOut, L"\n");
314 }
315 }
316
317 ConPuts(StdOut, L"\n");
318
319 /* free up all resources */
320 if (Name != NULL)
321 {
323 0,
324 Name);
325 }
326
327 if (SidString != NULL)
328 {
329 LocalFree((HLOCAL)SidString);
330 }
331
332 AceIndex++;
333 }
334
335 if (!Error)
336 Ret = TRUE;
337 }
338 else
339 {
341 }
342 }
343 }
344
346 0,
348 }
349 else
350 {
352 }
353
354 return Ret;
355}
#define IDS_ALLOW
Definition: resource.h:12
#define IDS_ABBR_FULL
Definition: resource.h:7
#define IDS_ABBR_WRITE
Definition: resource.h:9
#define IDS_GENERIC_READ
Definition: resource.h:16
#define IDS_FILE_APPEND_DATA
Definition: resource.h:25
#define IDS_STANDARD_RIGHTS_ALL
Definition: resource.h:41
#define IDS_FILE_READ_EA
Definition: resource.h:26
#define IDS_FILE_READ_ATTRIBUTES
Definition: resource.h:30
#define IDS_READ_CONTROL
Definition: resource.h:39
#define IDS_ABBR_READ
Definition: resource.h:8
#define IDS_FILE_GENERIC_WRITE
Definition: resource.h:22
#define IDS_ABBR_OI
Definition: resource.h:5
#define IDS_GENERIC_EXECUTE
Definition: resource.h:18
#define IDS_GENERIC_WRITE
Definition: resource.h:17
#define IDS_DELETE
Definition: resource.h:40
#define IDS_SPECIFIC_RIGHTS_ALL
Definition: resource.h:34
#define IDS_FILE_READ_DATA
Definition: resource.h:23
#define IDS_FILE_EXECUTE
Definition: resource.h:28
#define IDS_FILE_GENERIC_EXECUTE
Definition: resource.h:20
#define IDS_SYNCHRONIZE
Definition: resource.h:36
#define IDS_WRITE_DAC
Definition: resource.h:38
#define IDS_FILE_DELETE_CHILD
Definition: resource.h:29
#define IDS_SPECIAL_ACCESS
Definition: resource.h:14
#define IDS_FILE_WRITE_EA
Definition: resource.h:27
#define IDS_FILE_WRITE_DATA
Definition: resource.h:24
#define IDS_MAXIMUM_ALLOWED
Definition: resource.h:32
#define IDS_WRITE_OWNER
Definition: resource.h:37
#define IDS_GENERIC_ALL
Definition: resource.h:19
#define IDS_FILE_WRITE_ATTRIBUTES
Definition: resource.h:31
#define IDS_ABBR_IO
Definition: resource.h:6
#define IDS_STANDARD_RIGHTS_REQUIRED
Definition: resource.h:35
#define IDS_ABBR_NONE
Definition: resource.h:11
#define IDS_FILE_GENERIC_READ
Definition: resource.h:21
#define IDS_DENY
Definition: resource.h:13
#define IDS_ACCESS_SYSTEM_SECURITY
Definition: resource.h:33
#define IDS_ABBR_CHANGE
Definition: resource.h:10
#define IDS_ABBR_CI
Definition: resource.h:4
VOID DisplayString(LPWSTR Msg)
Definition: misc.c:211
BOOL Error
Definition: chkdsk.c:66
static GENERIC_MAPPING FileGenericMapping
Definition: cacls.c:27
@ Ace
Definition: card.h:12
void ConPrintf(FILE *fp, LPCWSTR psz,...)
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
LPWSTR Name
Definition: desk.c:124
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL WINAPI GetAce(PACL pAcl, DWORD dwAceIndex, LPVOID *pAce)
Definition: security.c:1186
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define GENERIC_READ
Definition: compat.h:135
#define HeapFree(x, y, z)
Definition: compat.h:735
void WINAPI MapGenericMask(PDWORD access, PGENERIC_MAPPING mapping)
Definition: security.c:1445
unsigned int size_t
Definition: corecrt.h:203
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define _tcscpy
Definition: tchar.h:623
#define _tcslen
Definition: tchar.h:626
if(dx< 0)
Definition: linetemp.h:194
enum _SID_NAME_USE SID_NAME_USE
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
struct _SID * PSID
Definition: eventlog.c:37
struct _SECURITY_DESCRIPTOR * PSECURITY_DESCRIPTOR
Definition: rtl.c:119
unsigned int UINT
Definition: ndis.h:50
_In_ ACCESS_MASK AccessMask
Definition: exfuncs.h:186
_In_ ULONG Domain
Definition: haltypes.h:1814
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1625
_In_ BOOLEAN DaclPresent
Definition: rtlfuncs.h:1667
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1165
_In_ BOOLEAN _In_opt_ PACL _In_opt_ BOOLEAN DaclDefaulted
Definition: rtlfuncs.h:1670
#define SPECIFIC_RIGHTS_ALL
Definition: nt_native.h:71
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define WRITE_DAC
Definition: nt_native.h:59
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_GENERIC_EXECUTE
Definition: nt_native.h:668
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_DELETE_CHILD
Definition: nt_native.h:645
#define FILE_READ_EA
Definition: nt_native.h:638
#define FILE_EXECUTE
Definition: nt_native.h:642
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define GENERIC_ALL
Definition: nt_native.h:92
#define DELETE
Definition: nt_native.h:57
#define READ_CONTROL
Definition: nt_native.h:58
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define WRITE_OWNER
Definition: nt_native.h:60
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define FILE_WRITE_EA
Definition: nt_native.h:640
#define GENERIC_EXECUTE
Definition: nt_native.h:91
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_In_ UINT uID
Definition: shlwapi.h:156
#define ConvertSidToStringSid
Definition: sddl.h:160
BOOL WINAPI GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, LPBOOL lpbDaclPresent, PACL *pDacl, LPBOOL lpbDaclDefaulted)
Definition: sec.c:45
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define LookupAccountSid
Definition: winbase.h:3616
#define GetFileSecurity
Definition: winbase.h:3566
#define ERROR_NO_SECURITY_ON_OBJECT
Definition: winerror.h:1176
#define ERROR_NONE_MAPPED
Definition: winerror.h:1159
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:191
_In_ ULONG AceIndex
Definition: rtlfuncs.h:1879
#define CONTAINER_INHERIT_ACE
Definition: setypes.h:747
#define INHERIT_ONLY_ACE
Definition: setypes.h:749
#define DACL_SECURITY_INFORMATION
Definition: setypes.h:125
#define OBJECT_INHERIT_ACE
Definition: setypes.h:746
#define ACCESS_DENIED_ACE_TYPE
Definition: setypes.h:718

Referenced by PrintDaclsOfFiles().

◆ ReplaceUserAccessRights()

static BOOL ReplaceUserAccessRights ( LPCTSTR  FilePath,
LPCTSTR  File,
LPCTSTR  User,
TCHAR  Perm 
)
static

Definition at line 481 of file cacls.c.

486{
487 /* TODO & FIXME */
488 switch(Perm)
489 {
490 case _T('N'): // None
491 break;
492 case _T('R'): // Read
493 break;
494 case _T('W'): // Write
495 break;
496 case _T('C'): // Change (write)
497 break;
498 case _T('F'): // Full control
499 break;
500 default:
501 break;
502 }
503 return FALSE;
504}

Referenced by ChangeFileACL().

◆ RevokeUserAccessRights()

static BOOL RevokeUserAccessRights ( LPCTSTR  FilePath,
LPCTSTR  File,
LPCTSTR  User 
)
static

Definition at line 540 of file cacls.c.

541{
542 /* TODO & FIXME */
543 return FALSE;
544}

Referenced by ChangeFileACL().

Variable Documentation

◆ DUser

LPCTSTR DUser

Definition at line 25 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ FileGenericMapping

GENERIC_MAPPING FileGenericMapping
static
Initial value:

Definition at line 27 of file cacls.c.

Referenced by PrintFileDacl().

◆ GPerm

LPCTSTR GPerm

Definition at line 25 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ GUser

LPCTSTR GUser

Definition at line 25 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ OptionC

BOOL OptionC = FALSE

Definition at line 23 of file cacls.c.

Referenced by _tmain(), ChangeACLsOfFiles(), ChangeACLsOfFilesInCurDir(), and PrintDaclsOfFiles().

◆ OptionD

BOOL OptionD = FALSE

Definition at line 24 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ OptionE

BOOL OptionE = FALSE

Definition at line 23 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ OptionG

BOOL OptionG = FALSE

Definition at line 24 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ OptionP

BOOL OptionP = FALSE

Definition at line 24 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ OptionR

BOOL OptionR = FALSE

Definition at line 24 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ OptionT

BOOL OptionT = FALSE

Definition at line 23 of file cacls.c.

Referenced by _tmain().

◆ PPerm

LPCTSTR PPerm

Definition at line 25 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ PUser

LPCTSTR PUser

Definition at line 25 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().

◆ RUser

LPCTSTR RUser

Definition at line 25 of file cacls.c.

Referenced by _tmain(), and ChangeFileACL().