[SHELL/EXPERIMENTS]
[reactos.git] / drivers / filesystems / npfs / seinfo.c
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
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
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 TRUE,
84 IoGetFileObjectGenericMapping());
85 if (!NT_SUCCESS(Status)) return Status;
86
87 Status = ObLogSecurityDescriptor(TempSecurityDescriptor, &NewSecurityDescriptor, TRUE);
88 ExFreePool(TempSecurityDescriptor);
89
90 if (!NT_SUCCESS(Status)) return Status;
91
92 Fcb->SecurityDescriptor = NewSecurityDescriptor;
93 ObDereferenceSecurityDescriptor(OldSecurityDescriptor, 1);
94 return Status;
95 }
96
97 NTSTATUS
98 NTAPI
99 NpFsdQuerySecurityInfo(IN PDEVICE_OBJECT DeviceObject,
100 IN PIRP Irp)
101 {
102 NTSTATUS Status;
103 PAGED_CODE();
104
105 FsRtlEnterFileSystem();
106 NpAcquireExclusiveVcb();
107
108 Status = NpCommonQuerySecurityInfo(DeviceObject, Irp);
109
110 NpReleaseVcb();
111 FsRtlExitFileSystem();
112
113 if (Status != STATUS_PENDING)
114 {
115 Irp->IoStatus.Status = Status;
116 IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
117 }
118
119 return Status;
120 }
121
122 NTSTATUS
123 NTAPI
124 NpFsdSetSecurityInfo(IN PDEVICE_OBJECT DeviceObject,
125 IN PIRP Irp)
126 {
127 NTSTATUS Status;
128 PAGED_CODE();
129
130 FsRtlEnterFileSystem();
131 NpAcquireExclusiveVcb();
132
133 Status = NpCommonSetSecurityInfo(DeviceObject, Irp);
134
135 NpReleaseVcb();
136 FsRtlExitFileSystem();
137
138 if (Status != STATUS_PENDING)
139 {
140 Irp->IoStatus.Status = Status;
141 IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
142 }
143
144 return Status;
145 }
146
147 /* EOF */