00125 {
00126 PSECURITY_DESCRIPTOR SecurityDescriptor;
00127 PACL Acl;
00128 PSID
WorldSid,
CreatorSid;
00129 SID_IDENTIFIER_AUTHORITY WorldAuthority = SECURITY_WORLD_SID_AUTHORITY;
00130 ULONG OwnerAceLength, WorldAceLength;
00131 ULONG AclLength;
00132
NTSTATUS Status;
00133 PACCESS_ALLOWED_ACE OwnerAce;
00134 PACCESS_ALLOWED_ACE WorldAce;
00135
00136
WorldSid = malloc(
RtlLengthRequiredSid(1));
00137
if (
WorldSid ==
NULL) {
00138 printf(
"rtsetsec: GenerateDescriptor() couldn't malloc WorldSID\n");
00139
exit(1);
00140 }
00141
RtlInitializeSid(WorldSid, &WorldAuthority, 1);
00142 *(
RtlSubAuthoritySid(WorldSid, 0)) = SECURITY_WORLD_RID;
00143
if (!
RtlValidSid(WorldSid)) {
00144 printf(
"rtsetsec: GenerateDescriptor() created invalid World SID\n");
00145
exit(1);
00146 }
00147
00148
CreatorSid =
GetMySid();
00149
00150
00151
00152
00153
00154
00155 WorldAceLength =
SeLengthSid(WorldSid) -
00156
sizeof(ULONG) +
00157
sizeof(ACCESS_ALLOWED_ACE) ;
00158 WorldAce = malloc(WorldAceLength);
00159
if (WorldAce ==
NULL) {
00160 printf(
"rtsetsec: GenerateDescriptor() couldn't malloc WorldAce\n");
00161
exit(1);
00162 }
00163
00164 OwnerAceLength =
SeLengthSid(CreatorSid) -
00165
sizeof(ULONG) +
00166
sizeof(ACCESS_ALLOWED_ACE);
00167
00168 OwnerAce = malloc( OwnerAceLength );
00169
if (OwnerAce ==
NULL) {
00170 printf(
"rtsetsec: GenerateDescriptor() couldn't malloc OwnerAce\n");
00171
exit(1);
00172 }
00173
00174 AclLength = OwnerAceLength + WorldAceLength +
sizeof(ACL);
00175 Acl = malloc(AclLength);
00176
if (Acl ==
NULL) {
00177 printf(
"rtsetsec: GenerateDescriptor() couldn't malloc ACL\n");
00178
exit(1);
00179 }
00180
00181
Status =
RtlCreateAcl(Acl, AclLength, ACL_REVISION);
00182
if (!
NT_SUCCESS(Status)) {
00183 printf(
"rtsetsec: RtlCreateAcl failed status %08lx\n", Status);
00184
exit(1);
00185 }
00186
00187
00188
00189
00190
00191 WorldAce->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
00192 WorldAce->Header.AceSize = (
USHORT)WorldAceLength;
00193 WorldAce->Header.AceFlags = 0;
00194 WorldAce->Mask = KEY_READ;
00195
Status =
RtlCopySid(
SeLengthSid(WorldSid),
00196 &WorldAce->SidStart,
00197 WorldSid );
00198
if (!
NT_SUCCESS(Status)) {
00199 printf(
"rtsetsec: RtlCopySid failed status %08lx\n", Status);
00200
exit(1);
00201 }
00202
00203 OwnerAce->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
00204 OwnerAce->Header.AceSize = (
USHORT)OwnerAceLength;
00205 OwnerAce->Header.AceFlags = 0;
00206 OwnerAce->Mask = KEY_ALL_ACCESS;
00207
Status =
RtlCopySid(
SeLengthSid(CreatorSid),
00208 &OwnerAce->SidStart,
00209 CreatorSid );
00210
if (!
NT_SUCCESS(Status)) {
00211 printf(
"rtsetsec: RtlCopySid failed status %08lx\n", Status);
00212
exit(1);
00213 }
00214
00215 free(WorldSid);
00216
00217
00218
00219
00220
00221
Status =
RtlAddAce( Acl,
00222 ACL_REVISION,
00223 0,
00224 WorldAce,
00225 WorldAceLength );
00226
if (!
NT_SUCCESS(Status)) {
00227 printf(
"rtsetsec: RtlAddAce (world ace) failed status %08lx\n", Status);
00228
exit(1);
00229 }
00230
Status =
RtlAddAce( Acl,
00231 ACL_REVISION,
00232 0,
00233 OwnerAce,
00234 OwnerAceLength );
00235
if (!
NT_SUCCESS(Status)) {
00236 printf(
"rtsetsec: RtlAddAce (owner ace) failed status %08lx\n", Status);
00237
exit(1);
00238 }
00239
00240 free(OwnerAce);
00241 free(WorldAce);
00242
00243
00244
00245
00246
00247 SecurityDescriptor = malloc(
sizeof(SECURITY_DESCRIPTOR));
00248
Status =
RtlCreateSecurityDescriptor( SecurityDescriptor,
00249 SECURITY_DESCRIPTOR_REVISION );
00250
if (!
NT_SUCCESS(Status)) {
00251 printf(
"rtsetsec: RtlCreateSecurityDescriptor failed status %08lx\n",Status);
00252
exit(1);
00253 }
00254
00255
Status =
RtlSetDaclSecurityDescriptor( SecurityDescriptor,
00256 TRUE,
00257 Acl,
00258 FALSE );
00259
if (!
NT_SUCCESS(Status)) {
00260 printf(
"rtsetsec: RtlSetDaclSecurityDescriptor failed status %08lx\n",Status);
00261
exit(1);
00262 }
00263
00264
00265
00266
00267
00268
return(SecurityDescriptor);
00269
00270 }