SID(安全标识符)

creating a SID for the Everyone group.

 1 DWORD SidSize;
 2 PSID TheSID;
 3 LPTSTR p;
 4 
 5 SidSize = SECURITY_MAX_SID_SIZE;
 6 // Allocate enough memory for the largest possible SID.
 7 if(!(TheSID = LocalAlloc(LMEM_FIXED, SidSize)))
 8 {    
 9     fprintf(stderr, "Could not allocate memory.\n");
10     exit(1);
11 }
12 // Create a SID for the Everyone group on the local computer.
13 if(!CreateWellKnownSid(WinWorldSid, NULL, TheSID, &SidSize))
14 {
15     fprintf(stderr,
16             "CreateWellKnownSid Error %u",
17             GetLastError());
18 }
19 else
20 {
21     // Get the string version of the SID (S-1-1-0).
22     if(!(ConvertSidToStringSid(TheSID, &p)))
23     {
24         fprintf(stderr, 
25                 "Error during ConvertSidToStringSid.\n");
26         exit(1);
27     }
28 
29     // Use the string SID as needed.
30     // ...
31 
32     // When done, free the memory used.
33     LocalFree(p);
34     LocalFree(TheSID);
35 }
 1 typedef enum {
 2 
 3     WinNullSid                                  = 0,
 4     WinWorldSid                                 = 1,
 5     WinLocalSid                                 = 2,
 6     WinCreatorOwnerSid                          = 3,
 7     WinCreatorGroupSid                          = 4,
 8     WinCreatorOwnerServerSid                    = 5,
 9     WinCreatorGroupServerSid                    = 6,
10     WinNtAuthoritySid                           = 7,
11     WinDialupSid                                = 8,
12     WinNetworkSid                               = 9,
13     WinBatchSid                                 = 10,
14     WinInteractiveSid                           = 11,
15     WinServiceSid                               = 12,
16     WinAnonymousSid                             = 13,
17     WinProxySid                                 = 14,
18     WinEnterpriseControllersSid                 = 15,
19     WinSelfSid                                  = 16,
20     WinAuthenticatedUserSid                     = 17,
21     WinRestrictedCodeSid                        = 18,
22     WinTerminalServerSid                        = 19,
23     WinRemoteLogonIdSid                         = 20,
24     WinLogonIdsSid                              = 21,
25     WinLocalSystemSid                           = 22,
26     WinLocalServiceSid                          = 23,
27     WinNetworkServiceSid                        = 24,
28     WinBuiltinDomainSid                         = 25,
29     WinBuiltinAdministratorsSid                 = 26,
30     WinBuiltinUsersSid                          = 27,
31     WinBuiltinGuestsSid                         = 28,
32     WinBuiltinPowerUsersSid                     = 29,
33     WinBuiltinAccountOperatorsSid               = 30,
34     WinBuiltinSystemOperatorsSid                = 31,
35     WinBuiltinPrintOperatorsSid                 = 32,
36     WinBuiltinBackupOperatorsSid                = 33,
37     WinBuiltinReplicatorSid                     = 34,
38     WinBuiltinPreWindows2000CompatibleAccessSid = 35,
39     WinBuiltinRemoteDesktopUsersSid             = 36,
40     WinBuiltinNetworkConfigurationOperatorsSid  = 37,
41     WinAccountAdministratorSid                  = 38,
42     WinAccountGuestSid                          = 39,
43     WinAccountKrbtgtSid                         = 40,
44     WinAccountDomainAdminsSid                   = 41,
45     WinAccountDomainUsersSid                    = 42,
46     WinAccountDomainGuestsSid                   = 43,
47     WinAccountComputersSid                      = 44,
48     WinAccountControllersSid                    = 45,
49     WinAccountCertAdminsSid                     = 46,
50     WinAccountSchemaAdminsSid                   = 47,
51     WinAccountEnterpriseAdminsSid               = 48,
52     WinAccountPolicyAdminsSid                   = 49,
53     WinAccountRasAndIasServersSid               = 50,
54     WinNTLMAuthenticationSid                    = 51,
55     WinDigestAuthenticationSid                  = 52,
56     WinSChannelAuthenticationSid                = 53,
57     WinThisOrganizationSid                      = 54,
58     WinOtherOrganizationSid                     = 55,
59     WinBuiltinIncomingForestTrustBuildersSid    = 56,
60     WinBuiltinPerfMonitoringUsersSid            = 57,
61     WinBuiltinPerfLoggingUsersSid               = 58,
62     WinBuiltinAuthorizationAccessSid            = 59,
63     WinBuiltinTerminalServerLicenseServersSid   = 60,
64     WinBuiltinDCOMUsersSid                      = 61,
65     WinBuiltinIUsersSid                         = 62,
66     WinIUserSid                                 = 63,
67     WinBuiltinCryptoOperatorsSid                = 64,
68     WinUntrustedLabelSid                        = 65,
69     WinLowLabelSid                              = 66,
70     WinMediumLabelSid                           = 67,
71     WinHighLabelSid                             = 68,
72     WinSystemLabelSid                           = 69,
73     WinWriteRestrictedCodeSid                   = 70,
74     WinCreatorOwnerRightsSid                    = 71,
75     WinCacheablePrincipalsGroupSid              = 72,
76     WinNonCacheablePrincipalsGroupSid           = 73,
77     WinEnterpriseReadonlyControllersSid         = 74,
78     WinAccountReadonlyControllersSid            = 75,
79     WinBuiltinEventLogReadersGroup              = 76,
80     WinNewEnterpriseReadonlyControllersSid      = 77,
81     WinBuiltinCertSvcDComAccessGroup            = 78,
82     WinMediumPlusLabelSid                       = 79,
83     WinLocalLogonSid                            = 80,
84     WinConsoleLogonSid                            = 81,
85     WinThisOrganizationCertificateSid            = 82,
86 } WELL_KNOWN_SID_TYPE;

匹配一个SID与已知的SID是否匹配

1 BOOL IsWellKnownSid(
2   PSID pSid,
3   WELL_KNOWN_SID_TYPE WellKnownSidType
4 );

 

posted @ 2019-03-04 10:55  wuyuan2011woaini  阅读(647)  评论(0编辑  收藏  举报