xref: /reactos/drivers/filesystems/npfs/seinfo.c (revision aa59e3ad)
1 /*
2  * PROJECT:     ReactOS Named Pipe FileSystem
3  * LICENSE:     BSD - See COPYING.ARM in the top level directory
4  * FILE:        drivers/filesystems/npfs/seinfo.c
5  * PURPOSE:     Pipes Security Information
6  * PROGRAMMERS: ReactOS Portable Systems Group
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "npfs.h"
12 
13 // File ID number for NPFS bugchecking support
14 #define NPFS_BUGCHECK_FILE_ID   (NPFS_BUGCHECK_SEINFO)
15 
16 /* FUNCTIONS ******************************************************************/
17 
18 NTSTATUS
19 NTAPI
NpCommonQuerySecurityInfo(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)20 NpCommonQuerySecurityInfo(IN PDEVICE_OBJECT DeviceObject,
21                           IN PIRP Irp)
22 {
23     NODE_TYPE_CODE NodeTypeCode;
24     PIO_STACK_LOCATION IoStack;
25     NTSTATUS Status;
26     PNP_FCB Fcb;
27     PNP_CCB Ccb;
28     ULONG NamedPipeEnd;
29     PAGED_CODE();
30 
31     IoStack = IoGetCurrentIrpStackLocation(Irp);
32 
33     NodeTypeCode = NpDecodeFileObject(IoStack->FileObject,
34                                       (PVOID*)&Fcb,
35                                       &Ccb,
36                                       &NamedPipeEnd);
37     if (!NodeTypeCode) return STATUS_PIPE_DISCONNECTED;
38     if (NodeTypeCode != NPFS_NTC_CCB) return STATUS_INVALID_PARAMETER;
39 
40     Status = SeQuerySecurityDescriptorInfo(&IoStack->Parameters.QuerySecurity.SecurityInformation,
41                                            Irp->UserBuffer,
42                                            &IoStack->Parameters.QuerySecurity.Length,
43                                            &Fcb->SecurityDescriptor);
44     if (Status == STATUS_BUFFER_TOO_SMALL)
45     {
46         Irp->IoStatus.Information = IoStack->Parameters.QuerySecurity.Length;
47         Status = STATUS_BUFFER_OVERFLOW;
48     }
49 
50     return Status;
51 }
52 
53 NTSTATUS
54 NTAPI
NpCommonSetSecurityInfo(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)55 NpCommonSetSecurityInfo(IN PDEVICE_OBJECT DeviceObject,
56                         IN PIRP Irp)
57 {
58     NODE_TYPE_CODE NodeTypeCode;
59     PIO_STACK_LOCATION IoStack;
60     NTSTATUS Status;
61     PNP_FCB Fcb;
62     PNP_CCB Ccb;
63     ULONG NamedPipeEnd;
64     PSECURITY_DESCRIPTOR OldSecurityDescriptor;
65     PSECURITY_DESCRIPTOR TempSecurityDescriptor;
66     PSECURITY_DESCRIPTOR NewSecurityDescriptor;
67     PAGED_CODE();
68 
69     IoStack = IoGetCurrentIrpStackLocation(Irp);
70 
71     NodeTypeCode = NpDecodeFileObject(IoStack->FileObject,
72                                       (PVOID*)&Fcb,
73                                       &Ccb,
74                                       &NamedPipeEnd);
75     if (!NodeTypeCode) return STATUS_PIPE_DISCONNECTED;
76     if (NodeTypeCode != NPFS_NTC_CCB) return STATUS_INVALID_PARAMETER;
77 
78     OldSecurityDescriptor = TempSecurityDescriptor = Fcb->SecurityDescriptor;
79     Status = SeSetSecurityDescriptorInfo(NULL,
80                                          &IoStack->Parameters.SetSecurity.SecurityInformation,
81                                          IoStack->Parameters.SetSecurity.SecurityDescriptor,
82                                          &TempSecurityDescriptor,
83                                          PagedPool,
84                                          IoGetFileObjectGenericMapping());
85     if (!NT_SUCCESS(Status)) return Status;
86 
87     Status = ObLogSecurityDescriptor(TempSecurityDescriptor, &NewSecurityDescriptor, 1);
88     ASSERT(TempSecurityDescriptor != OldSecurityDescriptor);
89     ExFreePoolWithTag(TempSecurityDescriptor, 0);
90 
91     if (!NT_SUCCESS(Status)) return Status;
92 
93     Fcb->SecurityDescriptor = NewSecurityDescriptor;
94     ObDereferenceSecurityDescriptor(OldSecurityDescriptor, 1);
95     return Status;
96 }
97 
98 NTSTATUS
99 NTAPI
NpFsdQuerySecurityInfo(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)100 NpFsdQuerySecurityInfo(IN PDEVICE_OBJECT DeviceObject,
101                        IN PIRP Irp)
102 {
103     NTSTATUS Status;
104     PAGED_CODE();
105 
106     FsRtlEnterFileSystem();
107     NpAcquireExclusiveVcb();
108 
109     Status = NpCommonQuerySecurityInfo(DeviceObject, Irp);
110 
111     NpReleaseVcb();
112     FsRtlExitFileSystem();
113 
114     if (Status != STATUS_PENDING)
115     {
116         Irp->IoStatus.Status = Status;
117         IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
118     }
119 
120     return Status;
121 }
122 
123 NTSTATUS
124 NTAPI
NpFsdSetSecurityInfo(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)125 NpFsdSetSecurityInfo(IN PDEVICE_OBJECT DeviceObject,
126                      IN PIRP Irp)
127 {
128     NTSTATUS Status;
129     PAGED_CODE();
130 
131     FsRtlEnterFileSystem();
132     NpAcquireExclusiveVcb();
133 
134     Status = NpCommonSetSecurityInfo(DeviceObject, Irp);
135 
136     NpReleaseVcb();
137     FsRtlExitFileSystem();
138 
139     if (Status != STATUS_PENDING)
140     {
141         Irp->IoStatus.Status = Status;
142         IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
143     }
144 
145     return Status;
146 }
147 
148 /* EOF */
149