青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Coder

HCP高性能計(jì)算架構(gòu),實(shí)現(xiàn),編譯器指令優(yōu)化,算法優(yōu)化, LLVM CLANG OpenCL CUDA OpenACC C++AMP OpenMP MPI

C++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
  98 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks
http://www.cnblogs.com/bluesky_blog/archive/2009/04/29.html
管理用戶權(quán)限可以實(shí)現(xiàn)以編程方式使用下列步驟:
  1. 打開與 LsaOpenPolicy() 的目標(biāo)計(jì)算機(jī)上的策略。 要授予的權(quán)限,打開 POLICY_CREATE_ACCOUNT 和 POLICY_LOOKUP_NAMES 訪問策略。 若要吊銷權(quán)限,打開 POLICY_LOOKUP_NAMES 訪問策略。
  2. 獲取一個(gè) SID (安全標(biāo)識(shí)符),表示用戶 / 組感興趣。 LookupAccountName() 和 LsaLookupNames() API 可以從一個(gè)帳戶名獲取 SID。
  3. 調(diào)用 LsaAddAccountRights() 向由提供的 SID 的用戶授予特權(quán)。
  4. 調(diào)用 LsaRemoveAccountRights() 撤消由提供的 SID 的用戶權(quán)限。
  5. 關(guān)閉該策略與 LsaClose()。
要成功授予和吊銷權(quán)限,調(diào)用方需要是目標(biāo)系統(tǒng)上的管理員。

LSA API LsaEnumerateAccountRights() 可確定已授予的權(quán)限的帳戶。

LSA API LsaEnumerateAccountsWithUserRight() 可確定哪些帳戶已被授予指定的權(quán)限。

MSTOOLS\SECURITY 目錄中 Windows 32 SDK 中提供的這些 LSA API 的文檔和頭文件。

在 Win32 SDK 的最新版本中, 郵件頭顯示在 mstools\samples\win32\winnt\security\include 目錄中且文檔處于正在 \security\lsasamp\lsaapi.hlp。

注意: 這些 LSA API 是當(dāng)前實(shí)現(xiàn)以 Unicode 格式僅。

本示例將授予特權(quán) SeServiceLogonRight 為 argv [1] 上指定的帳戶。

此示例是依賴于這些導(dǎo)入庫(kù)
advapi32.lib (對(duì)于 LsaXxx)
user32.lib (對(duì)于 wsprintf)
本示例將工作正確編譯 ANSI 或 Unicode。

示例代碼

  1/*++
  2You can use domain\account as argv[1]. For instance, mydomain\scott will
  3grant the privilege to the mydomain domain account scott.
  4The optional target machine is specified as argv[2], otherwise, the
  5account database is updated on the local machine.
  6The LSA APIs used by this sample are Unicode only.
  7Use LsaRemoveAccountRights() to remove account rights.
  8Scott Field (sfield)    12-Jul-95
  9--*/

 10#ifndef UNICODE
 11#define UNICODE
 12#endif // UNICODE
 13#include <windows.h>
 14#include <stdio.h>
 15#include "ntsecapi.h"
 16NTSTATUS
 17OpenPolicy(
 18LPWSTR ServerName,          // machine to open policy on (Unicode)
 19DWORD DesiredAccess,        // desired access to policy
 20PLSA_HANDLE PolicyHandle    // resultant policy handle
 21);
 22BOOL
 23GetAccountSid(
 24LPTSTR SystemName,          // where to lookup account
 25LPTSTR AccountName,         // account of interest
 26PSID *Sid                   // resultant buffer containing SID
 27);
 28NTSTATUS
 29SetPrivilegeOnAccount(
 30LSA_HANDLE PolicyHandle,    // open policy handle
 31PSID AccountSid,            // SID to grant privilege to
 32LPWSTR PrivilegeName,       // privilege to grant (Unicode)
 33BOOL bEnable                // enable or disable
 34);
 35void
 36InitLsaString(
 37PLSA_UNICODE_STRING LsaString, // destination
 38LPWSTR String                  // source (Unicode)
 39);
 40void
 41DisplayNtStatus(
 42LPSTR szAPI,                // pointer to function name (ANSI)
 43NTSTATUS Status             // NTSTATUS error value
 44);
 45void
 46DisplayWinError(
 47LPSTR szAPI,                // pointer to function name (ANSI)
 48DWORD WinError              // DWORD WinError
 49);
 50#define RTN_OK 0
 51#define RTN_USAGE 1
 52#define RTN_ERROR 13
 53//
 54// If you have the ddk, include ntstatus.h.
 55//
 56#ifndef STATUS_SUCCESS
 57#define STATUS_SUCCESS  ((NTSTATUS)0x00000000L)
 58#endif
 59int _cdecl
 60main(int argc, char *argv[])
 61{
 62LSA_HANDLE PolicyHandle;
 63WCHAR wComputerName[256]=L"";   // static machine name buffer
 64TCHAR AccountName[256];         // static account name buffer
 65PSID pSid;
 66NTSTATUS Status;
 67int iRetVal=RTN_ERROR;          // assume error from main
 68if(argc == 1)
 69{
 70fprintf(stderr,"Usage: %s <Account> [TargetMachine]\n",
 71argv[0]);
 72return RTN_USAGE;
 73}

 74//
 75// Pick up account name on argv[1].
 76// Assumes source is ANSI. Resultant string is ANSI or Unicode
 77//
 78wsprintf(AccountName, TEXT("%hS"), argv[1]);
 79//
 80// Pick up machine name on argv[2], if appropriate
 81// assumes source is ANSI. Resultant string is Unicode.
 82//
 83if(argc == 3) wsprintfW(wComputerName, L"%hS", argv[2]);
 84//
 85// Open the policy on the target machine.
 86//
 87if((Status=OpenPolicy(
 88wComputerName,      // target machine
 89POLICY_CREATE_ACCOUNT | POLICY_LOOKUP_NAMES,
 90&PolicyHandle       // resultant policy handle
 91)) != STATUS_SUCCESS) {
 92DisplayNtStatus("OpenPolicy", Status);
 93return RTN_ERROR;
 94}

 95//
 96// Obtain the SID of the user/group.
 97// Note that we could target a specific machine, but we don't.
 98// Specifying NULL for target machine searches for the SID in the
 99// following order: well-known, Built-in and local, primary domain,
100// trusted domains.
101//
102if(GetAccountSid(
103NULL,       // default lookup logic
104AccountName,// account to obtain SID
105&pSid       // buffer to allocate to contain resultant SID
106)) {
107//
108// We only grant the privilege if we succeeded in obtaining the
109// SID. We can actually add SIDs which cannot be looked up, but
110// looking up the SID is a good sanity check which is suitable for
111// most cases.
112//
113// Grant the SeServiceLogonRight to users represented by pSid.
114//
115if((Status=SetPrivilegeOnAccount(
116PolicyHandle,           // policy handle
117pSid,                   // SID to grant privilege
118L"SeServiceLogonRight"// Unicode privilege
119TRUE                    // enable the privilege
120)) == STATUS_SUCCESS)
121iRetVal=RTN_OK;
122else
123DisplayNtStatus("AddUserRightToAccount", Status);
124}

125else {
126//
127// Error obtaining SID.
128//
129DisplayWinError("GetAccountSid", GetLastError());
130}

131//
132// Close the policy handle.
133//
134LsaClose(PolicyHandle);
135//
136// Free memory allocated for SID.
137//
138if(pSid != NULL) HeapFree(GetProcessHeap(), 0, pSid);
139return iRetVal;
140}

141void
142InitLsaString(
143PLSA_UNICODE_STRING LsaString,
144LPWSTR String
145)
146{
147DWORD StringLength;
148if (String == NULL) {
149LsaString->Buffer = NULL;
150LsaString->Length = 0;
151LsaString->MaximumLength = 0;
152return;
153}

154StringLength = wcslen(String);
155LsaString->Buffer = String;
156LsaString->Length = (USHORT) StringLength * sizeof(WCHAR);
157LsaString->MaximumLength=(USHORT)(StringLength+1* sizeof(WCHAR);
158}

159NTSTATUS
160OpenPolicy(
161LPWSTR ServerName,
162DWORD DesiredAccess,
163PLSA_HANDLE PolicyHandle
164)
165{
166LSA_OBJECT_ATTRIBUTES ObjectAttributes;
167LSA_UNICODE_STRING ServerString;
168PLSA_UNICODE_STRING Server = NULL;
169//
170// Always initialize the object attributes to all zeroes.
171//
172ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
173if (ServerName != NULL) {
174//
175// Make a LSA_UNICODE_STRING out of the LPWSTR passed in
176//
177InitLsaString(&ServerString, ServerName);
178Server = &ServerString;
179}

180//
181// Attempt to open the policy.
182//
183return LsaOpenPolicy(
184Server,
185&ObjectAttributes,
186DesiredAccess,
187PolicyHandle
188);
189}

190/*++
191This function attempts to obtain a SID representing the supplied
192account on the supplied system.
193If the function succeeds, the return value is TRUE. A buffer is
194allocated which contains the SID representing the supplied account.
195This buffer should be freed when it is no longer needed by calling
196HeapFree(GetProcessHeap(), 0, buffer)
197If the function fails, the return value is FALSE. Call GetLastError()
198to obtain extended error information.
199Scott Field (sfield)    12-Jul-95
200--*/

201BOOL
202GetAccountSid(
203LPTSTR SystemName,
204LPTSTR AccountName,
205PSID *Sid
206)
207{
208LPTSTR ReferencedDomain=NULL;
209DWORD cbSid=128;    // initial allocation attempt
210DWORD cchReferencedDomain=16// initial allocation size
211SID_NAME_USE peUse;
212BOOL bSuccess=FALSE; // assume this function will fail
213__try {
214//
215// initial memory allocations
216//
217if((*Sid=HeapAlloc(
218GetProcessHeap(),
2190,
220cbSid
221)) == NULL) __leave;
222if((ReferencedDomain=(LPTSTR)HeapAlloc(
223GetProcessHeap(),
2240,
225cchReferencedDomain * sizeof(TCHAR)
226)) == NULL) __leave;
227//
228// Obtain the SID of the specified account on the specified system.
229//
230while(!LookupAccountName(
231SystemName,         // machine to lookup account on
232AccountName,        // account to lookup
233*Sid,               // SID of interest
234&cbSid,             // size of SID
235ReferencedDomain,   // domain account was found on
236&cchReferencedDomain,
237&peUse
238)) {
239if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
240//
241// reallocate memory
242//
243if((*Sid=HeapReAlloc(
244GetProcessHeap(),
2450,
246*Sid,
247cbSid
248)) == NULL) __leave;
249if((ReferencedDomain=(LPTSTR)HeapReAlloc(
250GetProcessHeap(),
2510,
252ReferencedDomain,
253cchReferencedDomain * sizeof(TCHAR)
254)) == NULL) __leave;
255}

256else __leave;
257}

258//
259// Indicate success.
260//
261bSuccess=TRUE;
262}
 // finally
263__finally {
264//
265// Cleanup and indicate failure, if appropriate.
266//
267HeapFree(GetProcessHeap(), 0, ReferencedDomain);
268if(!bSuccess) {
269if(*Sid != NULL) {
270HeapFree(GetProcessHeap(), 0*Sid);
271*Sid = NULL;
272}

273}

274}
 // finally
275return bSuccess;
276}

277NTSTATUS
278SetPrivilegeOnAccount(
279LSA_HANDLE PolicyHandle,    // open policy handle
280PSID AccountSid,            // SID to grant privilege to
281LPWSTR PrivilegeName,       // privilege to grant (Unicode)
282BOOL bEnable                // enable or disable
283)
284{
285LSA_UNICODE_STRING PrivilegeString;
286//
287// Create a LSA_UNICODE_STRING for the privilege name.
288//
289InitLsaString(&PrivilegeString, PrivilegeName);
290//
291// grant or revoke the privilege, accordingly
292//
293if(bEnable) {
294return LsaAddAccountRights(
295PolicyHandle,       // open policy handle
296AccountSid,         // target SID
297&PrivilegeString,   // privileges
2981                   // privilege count
299);
300}

301else {
302return LsaRemoveAccountRights(
303PolicyHandle,       // open policy handle
304AccountSid,         // target SID
305FALSE,              // do not disable all rights
306&PrivilegeString,   // privileges
3071                   // privilege count
308);
309}

310}

311void
312DisplayNtStatus(
313LPSTR szAPI,
314NTSTATUS Status
315)
316{
317//
318// Convert the NTSTATUS to Winerror. Then call DisplayWinError().
319//
320DisplayWinError(szAPI, LsaNtStatusToWinError(Status));
321}

322void
323DisplayWinError(
324LPSTR szAPI,
325DWORD WinError
326)
327{
328LPSTR MessageBuffer;
329DWORD dwBufferLength;
330//
331// TODO: Get this fprintf out of here!
332//
333fprintf(stderr,"%s error!\n", szAPI);
334if(dwBufferLength=FormatMessageA(
335FORMAT_MESSAGE_ALLOCATE_BUFFER |
336FORMAT_MESSAGE_FROM_SYSTEM,
337NULL,
338WinError,
339GetUserDefaultLangID(),
340(LPSTR) &MessageBuffer,
3410,
342NULL
343))
344{
345DWORD dwBytesWritten; // unused
346//
347// Output message string on stderr.
348//
349WriteFile(
350GetStdHandle(STD_ERROR_HANDLE),
351MessageBuffer,
352dwBufferLength,
353&dwBytesWritten,
354NULL
355);
356//
357// Free the buffer allocated by the system.
358//
359LocalFree(MessageBuffer);
360}

361}

362
363/*++
364This function enables system access on the account represented by the
365supplied SID. An example of such access is the SeLogonServiceRight.
366Note: to disable a given system access, simply remove the supplied
367access flag from the existing flag, and apply the result to the
368account.
369If the function succeeds, the return value is STATUS_SUCCESS.
370If the function fails, the return value is an NTSTATUS value.
371Scott Field (sfield)    14-Jul-95
372--*/

373NTSTATUS
374AddSystemAccessToAccount(
375LSA_HANDLE PolicyHandle,
376PSID AccountSid,
377ULONG NewAccess
378)
379{
380LSA_HANDLE AccountHandle;
381ULONG PreviousAccess;
382NTSTATUS Status;
383//
384// open the account object. If it doesn't exist, create a new one
385//
386if((Status=LsaOpenAccount(
387PolicyHandle,
388AccountSid,
389ACCOUNT_ADJUST_SYSTEM_ACCESS | ACCOUNT_VIEW,
390&AccountHandle
391)) == STATUS_OBJECT_NAME_NOT_FOUND)
392{
393Status=LsaCreateAccount(
394PolicyHandle,
395AccountSid,
396ACCOUNT_ADJUST_SYSTEM_ACCESS | ACCOUNT_VIEW,
397&AccountHandle
398);
399}

400//
401// if an error occurred opening or creating, return
402//
403if(Status != STATUS_SUCCESS) return Status;
404//
405// obtain current system access flags
406//
407if((Status=LsaGetSystemAccessAccount(
408AccountHandle,
409&PreviousAccess
410)) == STATUS_SUCCESS)
411{
412//
413// Add the specified access to the account
414//
415Status=LsaSetSystemAccessAccount(
416AccountHandle,
417PreviousAccess | NewAccess
418);
419}

420LsaClose(AccountHandle);
421return Status;
422}

423/*++
424This function grants a privilege to the account represented by the
425supplied SID. An example of such a privilege is the
426SeBackupPrivilege.
427Note: To revoke a privilege, use LsaRemovePrivilegesFromAccount.
428If the function succeeds, the return value is STATUS_SUCCESS.
429If the function fails, the return value is an NTSTATUS value.
430Scott Field (sfield)    13-Jul-95
431--*/

432NTSTATUS
433AddPrivilegeToAccount(
434LSA_HANDLE PolicyHandle,
435PSID AccountSid,
436LPWSTR PrivilegeName
437)
438{
439PRIVILEGE_SET ps;
440LUID_AND_ATTRIBUTES luidattr;
441LSA_HANDLE AccountHandle;
442LSA_UNICODE_STRING PrivilegeString;
443NTSTATUS Status;
444//
445// Create a LSA_UNICODE_STRING for the privilege name
446//
447InitLsaString(&PrivilegeString, PrivilegeName);
448//
449// obtain the LUID of the supplied privilege
450//
451if((Status=LsaLookupPrivilegeValue(
452PolicyHandle,
453&PrivilegeString,
454&luidattr.Luid
455)) != STATUS_SUCCESS) return Status;
456//
457// setup PRIVILEGE_SET
458//
459luidattr.Attributes=0;
460ps.PrivilegeCount=1;
461ps.Control=0;
462ps.Privilege[0]=luidattr;
463//
464// open the account object if it doesn't exist, create a new one
465//
466if((Status=LsaOpenAccount(
467PolicyHandle,
468AccountSid,
469ACCOUNT_ADJUST_PRIVILEGES,
470&AccountHandle
471)) == STATUS_OBJECT_NAME_NOT_FOUND)
472{
473Status=LsaCreateAccount(
474PolicyHandle,
475AccountSid,
476ACCOUNT_ADJUST_PRIVILEGES,
477&AccountHandle
478);
479}

480//
481// if an error occurred opening or creating, return
482//
483if(Status != STATUS_SUCCESS) return Status;
484//
485// add the privileges to the account
486//
487Status=LsaAddPrivilegesToAccount(
488AccountHandle,
489&ps
490);
491LsaClose(AccountHandle);
492return Status;
493}

494
495
posted on 2012-10-18 10:29 jackdong 閱讀(916) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Windows編程
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            宅男噜噜噜66一区二区| 久久综合色婷婷| 亚洲欧美日本伦理| 欧美日韩国产页| 美女日韩在线中文字幕| 久久久视频精品| 美日韩在线观看| 欧美成人一品| 国产精品va| 国产一区久久久| 91久久黄色| 亚洲永久免费| 久久综合九色综合欧美狠狠| 美女爽到呻吟久久久久| 国产欧美日韩在线播放| 欧美精品二区三区四区免费看视频| 欧美国产第二页| 欧美视频在线免费看| 久久综合久久综合久久| 亚洲免费一级电影| 亚洲天堂成人在线观看| 欧美国产日韩一区二区| 亚洲与欧洲av电影| 亚洲精品美女久久久久| 亚洲色诱最新| 久久久欧美精品| 亚洲乱码日产精品bd| 欧美一区二区三区精品电影| 久久中文在线| 中文一区二区| 欧美风情在线观看| 韩国福利一区| 一区二区三区免费网站| 免费不卡在线视频| 亚洲精品影院| 久久九九精品| 国产欧美另类| 亚洲一区欧美一区| 亚洲国产日韩综合一区| 亚洲乱码国产乱码精品精| 亚洲性视频网站| 欧美国产精品久久| 怡红院精品视频| 久久黄色级2电影| 一区二区三区高清不卡| 欧美黄色视屏| 在线观看亚洲| 免费成人美女女| 亚洲一级黄色| 欧美电影在线免费观看网站| 99视频热这里只有精品免费| 国产精品久久久久久妇女6080| 亚洲国产成人精品视频| 午夜精品久久久久| 亚洲精品社区| 久久一区二区三区国产精品| 一区二区三区日韩| 欧美日韩播放| 亚洲美女av电影| 欧美激情 亚洲a∨综合| 久久久亚洲国产天美传媒修理工| 国产精品一国产精品k频道56| 夜色激情一区二区| 亚洲精品欧美极品| 欧美在线播放一区| 激情综合色综合久久| 欧美精品 日韩| …久久精品99久久香蕉国产| 欧美激情视频在线播放| 久久精品九九| 免费观看在线综合| 国产精品久久久久91| 亚洲欧美国产一区二区三区| 91久久精品国产91久久| 欧美成人午夜剧场免费观看| 欧美日韩中文字幕| 亚洲精品一线二线三线无人区| 欧美激情一区在线观看| 欧美高清不卡在线| 国产精品99久久久久久宅男| 一区二区欧美在线观看| 国产免费成人| 免费高清在线一区| 欧美大片一区二区| 亚洲欧美不卡| 久久国产精品久久国产精品| 亚洲破处大片| 亚洲婷婷在线| 欧美一区2区视频在线观看 | 国产农村妇女精品| 久久精品亚洲国产奇米99| 亚洲福利精品| 欧美日韩国产精品专区| 欧美一区视频| 久久嫩草精品久久久久| 国内精品福利| 91久久精品国产91久久性色| 亚洲美女中文字幕| 国产日韩欧美二区| 亚洲激情国产精品| 国产欧美日韩视频一区二区| 欧美成人午夜激情在线| 国产精品成人免费| 欧美成人一区二区三区片免费| 欧美日韩视频一区二区三区| 久久日韩精品| 欧美午夜三级| 欧美国产日韩精品| 国产日产欧产精品推荐色| 欧美在线国产| 亚洲视频欧美在线| 欧美激情视频一区二区三区免费| 国产精品网站在线观看| 久久精品国产96久久久香蕉| 女女同性精品视频| 久久av资源网站| 亚洲在线成人精品| 国产精品亚洲综合色区韩国| 日韩午夜免费| 亚洲一区二区伦理| 欧美日韩精品一区二区天天拍小说| 久久精品国产成人| 亚洲三级电影在线观看| 国产曰批免费观看久久久| 国产亚洲精品自拍| 国产精品99久久久久久久久| 久久亚洲国产成人| 国产精品高潮呻吟久久| 国产精品捆绑调教| 国产精品视频最多的网站| 国产精品一区二区三区免费观看 | 伊人成人在线| 亚洲高清在线观看| 久久久久久亚洲精品中文字幕| 亚洲欧美日韩国产中文在线| 国产精品一区视频| 在线观看91久久久久久| 亚洲激情在线观看| 国产综合久久久久影院| 亚洲国产成人精品久久久国产成人一区| 欧美精品日韩www.p站| 亚洲影视中文字幕| 亚洲影视九九影院在线观看| 久久免费视频网站| 久久久www成人免费精品| 久久久xxx| 欧美一级二区| 国产精品v亚洲精品v日韩精品| 狂野欧美一区| 国产精品综合av一区二区国产馆| 亚洲精品久久久久久一区二区| 久久久久久久波多野高潮日日| 国产日韩欧美日韩| 久久亚洲影音av资源网| 久久久久天天天天| 欧美激情综合色| 欧美人与性禽动交情品| 99精品99| 亚洲性av在线| 亚洲人午夜精品| 亚洲日本中文字幕区| 欧美午夜国产| 玖玖精品视频| 欧美性大战久久久久久久蜜臀| 亚洲欧美视频在线观看视频| 亚洲欧美日韩精品在线| 亚洲国产欧美日韩精品| 欧美日韩国产首页在线观看| 午夜精品久久久久久99热| 久久国产精品久久w女人spa| 国产视频一区二区在线观看| 国产一区二区三区四区在线观看| 嫩草国产精品入口| 国产精品区一区| 亚洲视频你懂的| 久久久国产午夜精品| 在线观看视频免费一区二区三区| 欧美大色视频| 午夜精品区一区二区三| 欧美国产精品日韩| 亚洲午夜一级| 国产自产在线视频一区| 欧美大片在线观看一区| 午夜精品福利视频| 国产精品视频精品视频| 欧美一区二区三区精品| 久久久噜噜噜久久中文字免| 国产亚洲福利一区| 欧美精品免费观看二区| 亚洲高清在线视频| 欧美精品午夜视频| 久久精品99国产精品| 99精品视频免费观看| 免费在线播放第一区高清av| 午夜久久影院| av成人免费在线观看| 亚洲成人资源网| 国产一区二区三区精品久久久| 国产精品r级在线| 亚洲国产精品悠悠久久琪琪|