ReactOS 0.4.16-dev-297-gc569aee
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 743 of file cacls.c.

744{
745 INT i;
746 LPTSTR pch;
748
749 /* Initialize the Console Standard Streams */
751
752 if (argc <= 1)
753 {
755 return 0;
756 }
757
758 // FIXME: Convert to proper parsing, with support for /?
759
760 /*
761 * parse command line options
762 */
763 for (i = 2; i < argc; i++)
764 {
765 if (lstrcmpi(argv[i], _T("/T")) == 0)
766 {
767 OptionT = TRUE;
768 }
769 else if (lstrcmpi(argv[i], _T("/E")) == 0)
770 {
771 OptionE = TRUE;
772 }
773 else if (lstrcmpi(argv[i], _T("/C")) == 0)
774 {
775 OptionC = TRUE;
776 }
777 else if (lstrcmpi(argv[i], _T("/G")) == 0)
778 {
779 if (i + 1 < argc)
780 {
781 pch = _tcschr(argv[++i], _T(':'));
782 if (pch != NULL)
783 {
784 OptionG = TRUE;
785 *pch = 0;
786 GUser = argv[i];
787 GPerm = pch + 1;
788 continue;
789 }
790 }
792 break;
793 }
794 else if (lstrcmpi(argv[i], _T("/R")) == 0)
795 {
796 if (i + 1 < argc)
797 {
798 RUser = argv[++i];
799 OptionR = TRUE;
800 continue;
801 }
803 break;
804 }
805 else if (lstrcmpi(argv[i], _T("/P")) == 0)
806 {
807 if (i + 1 < argc)
808 {
809 pch = _tcschr(argv[++i], _T(':'));
810 if (pch != NULL)
811 {
812 OptionP = TRUE;
813 *pch = 0;
814 PUser = argv[i];
815 PPerm = pch + 1;
816 continue;
817 }
818 }
820 break;
821 }
822 else if (lstrcmpi(argv[i], _T("/D")) == 0)
823 {
824 if (i + 1 < argc)
825 {
826 OptionD = TRUE;
827 DUser = argv[++i];
828 continue;
829 }
831 break;
832 }
833 else
834 {
836 break;
837 }
838 }
839
841 {
844 return 1;
845 }
846
847 /* /R is only valid with /E */
848 if (OptionR && !OptionE)
849 {
850 OptionR = FALSE;
851 }
852
854
855 if (OptionT)
856 {
858 }
859 else
860 {
862 }
863
864 return 0;
865}
static int argc
Definition: ServiceArgs.c:12
#define IDS_HELP
Definition: resource.h:3
#define ConInitStdStreams()
Definition: fc.c:13
#define StdOut
Definition: fc.c:14
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
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:405
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:589
static BOOL ChangeACLsOfFilesInCurDir(LPCTSTR pszFiles)
Definition: cacls.c:644
BOOL OptionG
Definition: cacls.c:24
LPCTSTR RUser
Definition: cacls.c:25
BOOL OptionT
Definition: cacls.c:23
#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
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 _tcschr
Definition: tchar.h:1406
#define pch(ap)
Definition: match.c:418
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
#define lstrcmpi
Definition: winbase.h:3898
CHAR * LPTSTR
Definition: xmlstorage.h:192

◆ AddBackslash()

static VOID AddBackslash ( LPTSTR  FilePath)
static

Definition at line 363 of file cacls.c.

364{
367 if (*pch != _T('\\'))
368 lstrcat(pch, _T("\\"));
369}
PCWSTR FilePath
GLenum GLsizei len
Definition: glext.h:6722
#define lstrlen
Definition: winbase.h:3901
#define lstrcat
Definition: winbase.h:3896
#define CharPrev
Definition: winuser.h:5753

Referenced by ChangeACLsOfFilesInCurDir(), and GetPathOfFile().

◆ ChangeACLsOfFiles()

static BOOL ChangeACLsOfFiles ( LPCTSTR  pszFiles)
static

Definition at line 589 of file cacls.c.

590{
592 HANDLE hFind;
593 WIN32_FIND_DATA FindData;
594 DWORD LastError;
595
596 /*
597 * get the file path
598 */
599 if (!GetPathOfFile(FilePath, pszFiles))
600 return FALSE;
601
602 /*
603 * search for files in current directory
604 */
605 hFind = FindFirstFile(pszFiles, &FindData);
606 if (hFind == INVALID_HANDLE_VALUE)
607 return FALSE;
608
609 do
610 {
611 if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
612 continue;
613
614 if (!ChangeFileACL(FilePath, FindData.cFileName))
615 {
616 LastError = GetLastError();
617 if (LastError == ERROR_ACCESS_DENIED)
618 {
619 PrintError(LastError);
620 if (!OptionC)
621 {
622 FindClose(hFind);
623 return FALSE;
624 }
625 }
626 else
627 break;
628 }
629 } while(FindNextFile(hFind, &FindData));
630
631 LastError = GetLastError();
632 FindClose(hFind);
633
634 if (LastError != ERROR_NO_MORE_FILES)
635 {
636 PrintError(LastError);
637 return FALSE;
638 }
639
640 return TRUE;
641}
static BOOL ChangeFileACL(LPCTSTR FilePath, LPCTSTR File)
Definition: cacls.c:551
static BOOL GetPathOfFile(LPTSTR FilePath, LPCTSTR pszFiles)
Definition: cacls.c:372
#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
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FindNextFile
Definition: winbase.h:3813
#define FindFirstFile
Definition: winbase.h:3807
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
char TCHAR
Definition: xmlstorage.h:189

Referenced by _tmain().

◆ ChangeACLsOfFilesInCurDir()

static BOOL ChangeACLsOfFilesInCurDir ( LPCTSTR  pszFiles)
static

Definition at line 644 of file cacls.c.

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

Referenced by _tmain(), and ChangeACLsOfFilesInCurDir().

◆ ChangeFileACL()

static BOOL ChangeFileACL ( LPCTSTR  FilePath,
LPCTSTR  File 
)
static

Definition at line 551 of file cacls.c.

552{
553 if (OptionG)
554 {
555 /* Grant specified user access rights. */
557 }
558
559 if (OptionP)
560 {
561 if (!OptionE)
562 {
563 /* Replace specified user's access rights. */
565 }
566 else
567 {
568 /* Edit ACL instead of replacing it. */
570 }
571 }
572
573 if (OptionD)
574 {
575 /* Deny specified user access. */
577 }
578
579 if (OptionR)
580 {
581 /* Revoke specified user's access rights. */
583 }
584
585 return TRUE;
586}
static BOOL DenyUserAccess(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User)
Definition: cacls.c:537
static BOOL GrantUserAccessRights(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
Definition: cacls.c:465
static BOOL ReplaceUserAccessRights(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
Definition: cacls.c:485
static BOOL EditUserAccessRights(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User, TCHAR Perm)
Definition: cacls.c:511
static BOOL RevokeUserAccessRights(LPCTSTR FilePath, LPCTSTR File, LPCTSTR User)
Definition: cacls.c:544
Definition: File.h:16

Referenced by ChangeACLsOfFiles(), and ChangeACLsOfFilesInCurDir().

◆ DenyUserAccess()

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

Definition at line 537 of file cacls.c.

538{
539 /* TODO & FIXME */
540 return FALSE;
541}

Referenced by ChangeFileACL().

◆ EditUserAccessRights()

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

Definition at line 511 of file cacls.c.

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

Referenced by ChangeFileACL().

◆ GetPathOfFile()

static BOOL GetPathOfFile ( LPTSTR  FilePath,
LPCTSTR  pszFiles 
)
static

Definition at line 372 of file cacls.c.

373{
374 TCHAR FullPath[MAX_PATH];
375 LPTSTR pch;
376 DWORD attrs;
377
378 lstrcpyn(FilePath, pszFiles, MAX_PATH);
379 pch = _tcsrchr(FilePath, _T('\\'));
380 if (pch != NULL)
381 {
382 *pch = 0;
383 if (!GetFullPathName(FilePath, MAX_PATH, FullPath, NULL))
384 {
386 return FALSE;
387 }
388 lstrcpyn(FilePath, FullPath, MAX_PATH);
389
391 if (attrs == 0xFFFFFFFF || !(attrs & FILE_ATTRIBUTE_DIRECTORY))
392 {
394 return FALSE;
395 }
396 }
397 else
399
401 return TRUE;
402}
#define _tcsrchr
Definition: utility.h:116
#define lstrcpyn
Definition: winbase.h:3900
#define GetFileAttributes
Definition: winbase.h:3840
#define GetFullPathName
Definition: winbase.h:3846
#define ERROR_DIRECTORY
Definition: winerror.h:295

Referenced by ChangeACLsOfFiles(), and PrintDaclsOfFiles().

◆ GrantUserAccessRights()

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

Definition at line 465 of file cacls.c.

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

Referenced by ChangeFileACL().

◆ PrintDaclsOfFiles()

static BOOL PrintDaclsOfFiles ( LPCTSTR  pszFiles)
static

Definition at line 405 of file cacls.c.

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

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: fc.c:15
#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:837
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449

Referenced by _tmain(), ChangeACLsOfFiles(), ChangeACLsOfFilesInCurDir(), GetPathOfFile(), 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;
112 LPTSTR Domain = NULL;
113 LPTSTR SidString = NULL;
114 DWORD 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 DWORD 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 = (DWORD)_tcslen(Domain) + _tcslen(Name);
199 }
200 else
201 {
202 LPTSTR DisplayString = (Name != NULL ? Name : SidString);
203
205 IndentAccess = (DWORD)_tcslen(DisplayString);
206 }
207
208 /* print the ACE Flags */
209 if (Ace->Header.AceFlags & CONTAINER_INHERIT_ACE)
210 {
211 IndentAccess += ConResPuts(StdOut, IDS_ABBR_CI);
212 }
213 if (Ace->Header.AceFlags & OBJECT_INHERIT_ACE)
214 {
215 IndentAccess += ConResPuts(StdOut, IDS_ABBR_OI);
216 }
217 if (Ace->Header.AceFlags & INHERIT_ONLY_ACE)
218 {
219 IndentAccess += 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, x2;
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 for (x2 = 0; x2 < IndentAccess; x2++)
309 {
310 ConPuts(StdOut, L" ");
311 }
312
313 ConResPuts(StdOut, AccessRights[x].uID);
314 }
315 }
316
317 ConPuts(StdOut, L"\n");
318 }
319 }
320
321 ConPuts(StdOut, L"\n");
322
323 /* free up all resources */
324 if (Name != NULL)
325 {
327 0,
328 Name);
329 }
330
331 if (SidString != NULL)
332 {
333 LocalFree((HLOCAL)SidString);
334 }
335
336 AceIndex++;
337 }
338
339 if (!Error)
340 Ret = TRUE;
341 }
342 else
343 {
345 }
346 }
347 }
348
350 0,
352 }
353 else
354 {
356 }
357
358 return Ret;
359}
struct NameRec_ * Name
Definition: cdprocs.h:460
#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 ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
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
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#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
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
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:35
struct _SECURITY_DESCRIPTOR * PSECURITY_DESCRIPTOR
Definition: security.c:98
unsigned int UINT
Definition: ndis.h:50
_In_ ACCESS_MASK AccessMask
Definition: exfuncs.h:186
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1605
_In_ BOOLEAN DaclPresent
Definition: rtlfuncs.h:1647
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1145
_In_ BOOLEAN _In_opt_ PACL _In_opt_ BOOLEAN DaclDefaulted
Definition: rtlfuncs.h:1650
#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 DWORD
Definition: nt_native.h:44
#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
#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:3892
VOID WINAPI MapGenericMask(PDWORD, PGENERIC_MAPPING)
#define GetFileSecurity
Definition: winbase.h:3842
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3710
#define ERROR_NO_SECURITY_ON_OBJECT
Definition: winerror.h:831
#define ERROR_NONE_MAPPED
Definition: winerror.h:814
_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
#define _tcslen
Definition: xmlstorage.h:198

Referenced by PrintDaclsOfFiles().

◆ ReplaceUserAccessRights()

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

Definition at line 485 of file cacls.c.

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

Referenced by ChangeFileACL().

◆ RevokeUserAccessRights()

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

Definition at line 544 of file cacls.c.

545{
546 /* TODO & FIXME */
547 return FALSE;
548}

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().